new loplugin:unuseddefaultparams
Change-Id: I2c3e7d66be9e3883ea2801ff394948cc580d1e44
This commit is contained in:
215
compilerplugins/clang/unuseddefaultparams.cxx
Normal file
215
compilerplugins/clang/unuseddefaultparams.cxx
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This file is part of the LibreOffice project.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <set>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "plugin.hxx"
|
||||||
|
#include "compat.hxx"
|
||||||
|
|
||||||
|
/*
|
||||||
|
Find methods with default params, where the callers never specify the default param i.e.
|
||||||
|
might as well remove it.
|
||||||
|
|
||||||
|
The process goes something like this:
|
||||||
|
$ make check
|
||||||
|
$ make FORCE_COMPILE_ALL=1 COMPILER_PLUGIN_TOOL='unusedmethods' check
|
||||||
|
$ ./compilerplugins/clang/unuseddefaultparams.py unuseddefaultparams.log
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct MyFuncInfo
|
||||||
|
{
|
||||||
|
std::string access;
|
||||||
|
std::string returnType;
|
||||||
|
std::string nameAndParams;
|
||||||
|
std::string sourceLocation;
|
||||||
|
};
|
||||||
|
bool operator < (const MyFuncInfo &lhs, const MyFuncInfo &rhs)
|
||||||
|
{
|
||||||
|
return lhs.sourceLocation < rhs.sourceLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// try to limit the voluminous output a little
|
||||||
|
static std::set<MyFuncInfo> callSet;
|
||||||
|
static std::set<MyFuncInfo> definitionSet;
|
||||||
|
|
||||||
|
class UnusedDefaultParams:
|
||||||
|
public RecursiveASTVisitor<UnusedDefaultParams>, public loplugin::Plugin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit UnusedDefaultParams(InstantiationData const & data): Plugin(data) {}
|
||||||
|
|
||||||
|
virtual void run() override
|
||||||
|
{
|
||||||
|
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
|
||||||
|
|
||||||
|
// dump all our output in one write call - this is to try and limit IO "crosstalk" between multiple processes
|
||||||
|
// writing to the same logfile
|
||||||
|
|
||||||
|
std::string output;
|
||||||
|
for (const MyFuncInfo & s : definitionSet)
|
||||||
|
output += "defn:\t" + s.access + "\t" + s.returnType + "\t" + s.nameAndParams + "\t" + s.sourceLocation + "\n";
|
||||||
|
for (const MyFuncInfo & s : callSet)
|
||||||
|
output += "call:\t" + s.returnType + "\t" + s.nameAndParams + "\n";
|
||||||
|
ofstream myfile;
|
||||||
|
myfile.open( SRCDIR "/unuseddefaultparams.log", ios::app | ios::out);
|
||||||
|
myfile << output;
|
||||||
|
myfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VisitCallExpr(CallExpr * callExpr);
|
||||||
|
bool VisitFunctionDecl( const FunctionDecl* functionDecl );
|
||||||
|
private:
|
||||||
|
MyFuncInfo niceName(const FunctionDecl* functionDecl);
|
||||||
|
};
|
||||||
|
|
||||||
|
MyFuncInfo UnusedDefaultParams::niceName(const FunctionDecl* functionDecl)
|
||||||
|
{
|
||||||
|
if (functionDecl->getInstantiatedFromMemberFunction())
|
||||||
|
functionDecl = functionDecl->getInstantiatedFromMemberFunction();
|
||||||
|
else if (functionDecl->getClassScopeSpecializationPattern())
|
||||||
|
functionDecl = functionDecl->getClassScopeSpecializationPattern();
|
||||||
|
// workaround clang-3.5 issue
|
||||||
|
#if __clang_major__ > 3 || ( __clang_major__ == 3 && __clang_minor__ >= 6 )
|
||||||
|
else if (functionDecl->getTemplateInstantiationPattern())
|
||||||
|
functionDecl = functionDecl->getTemplateInstantiationPattern();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
MyFuncInfo aInfo;
|
||||||
|
switch (functionDecl->getAccess())
|
||||||
|
{
|
||||||
|
case AS_public: aInfo.access = "public"; break;
|
||||||
|
case AS_private: aInfo.access = "private"; break;
|
||||||
|
case AS_protected: aInfo.access = "protected"; break;
|
||||||
|
default: aInfo.access = "unknown"; break;
|
||||||
|
}
|
||||||
|
aInfo.returnType = compat::getReturnType(*functionDecl).getCanonicalType().getAsString();
|
||||||
|
|
||||||
|
if (isa<CXXMethodDecl>(functionDecl)) {
|
||||||
|
const CXXRecordDecl* recordDecl = dyn_cast<CXXMethodDecl>(functionDecl)->getParent();
|
||||||
|
aInfo.nameAndParams += recordDecl->getQualifiedNameAsString();
|
||||||
|
aInfo.nameAndParams += "::";
|
||||||
|
}
|
||||||
|
aInfo.nameAndParams += functionDecl->getNameAsString() + "(";
|
||||||
|
bool bFirst = true;
|
||||||
|
for (const ParmVarDecl *pParmVarDecl : functionDecl->params()) {
|
||||||
|
if (bFirst)
|
||||||
|
bFirst = false;
|
||||||
|
else
|
||||||
|
aInfo.nameAndParams += ",";
|
||||||
|
aInfo.nameAndParams += pParmVarDecl->getType().getCanonicalType().getAsString();
|
||||||
|
}
|
||||||
|
aInfo.nameAndParams += ")";
|
||||||
|
if (isa<CXXMethodDecl>(functionDecl) && dyn_cast<CXXMethodDecl>(functionDecl)->isConst()) {
|
||||||
|
aInfo.nameAndParams += " const";
|
||||||
|
}
|
||||||
|
|
||||||
|
SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( functionDecl->getLocation() );
|
||||||
|
StringRef name = compiler.getSourceManager().getFilename(expansionLoc);
|
||||||
|
aInfo.sourceLocation = std::string(name.substr(strlen(SRCDIR)+1)) + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc));
|
||||||
|
|
||||||
|
return aInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UnusedDefaultParams::VisitCallExpr(CallExpr * callExpr) {
|
||||||
|
if (ignoreLocation(callExpr)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (callExpr->getDirectCallee() == nullptr) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const FunctionDecl* functionDecl = callExpr->getDirectCallee()->getCanonicalDecl();
|
||||||
|
auto n = functionDecl->getNumParams();
|
||||||
|
if (n == 0 || !functionDecl->getParamDecl(n - 1)->hasDefaultArg()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// method overrides don't always specify the same default params (althogh they probably should)
|
||||||
|
// so we need to work our way up to the root method
|
||||||
|
while (isa<CXXMethodDecl>(functionDecl)) {
|
||||||
|
const CXXMethodDecl* methodDecl = dyn_cast<CXXMethodDecl>(functionDecl);
|
||||||
|
if (methodDecl->size_overridden_methods()==0)
|
||||||
|
break;
|
||||||
|
functionDecl = *methodDecl->begin_overridden_methods();
|
||||||
|
}
|
||||||
|
assert(callExpr->getNumArgs() <= n); // can be < in template code
|
||||||
|
for (unsigned i = callExpr->getNumArgs(); i != 0;) {
|
||||||
|
--i;
|
||||||
|
Expr* arg = callExpr->getArg(i);
|
||||||
|
if (arg->isDefaultArgument()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// ignore this, it seems to trigger an infinite recursion
|
||||||
|
if (isa<UnaryExprOrTypeTraitExpr>(arg))
|
||||||
|
break;
|
||||||
|
const ParmVarDecl* parmVarDecl = functionDecl->getParamDecl(i);
|
||||||
|
if (!parmVarDecl->hasDefaultArg()
|
||||||
|
|| parmVarDecl->hasUninstantiatedDefaultArg())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const Expr* defaultArgExpr = parmVarDecl->getDefaultArg();
|
||||||
|
if (!defaultArgExpr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
MyFuncInfo funcInfo = niceName(functionDecl);
|
||||||
|
callSet.insert(funcInfo);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UnusedDefaultParams::VisitFunctionDecl( const FunctionDecl* functionDecl )
|
||||||
|
{
|
||||||
|
functionDecl = functionDecl->getCanonicalDecl();
|
||||||
|
if( !functionDecl || !functionDecl->getLocation().isValid() || ignoreLocation( functionDecl )) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const CXXMethodDecl* methodDecl = dyn_cast_or_null<CXXMethodDecl>(functionDecl);
|
||||||
|
|
||||||
|
// ignore method overrides, since the call will show up as being directed to the root method
|
||||||
|
if (methodDecl && (methodDecl->size_overridden_methods() != 0 || methodDecl->hasAttr<OverrideAttr>())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// ignore stuff that forms part of the stable URE interface
|
||||||
|
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(
|
||||||
|
functionDecl->getNameInfo().getLoc()))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (isa<CXXDestructorDecl>(functionDecl)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (isa<CXXConstructorDecl>(functionDecl)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (functionDecl->isDeleted()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
auto n = functionDecl->getNumParams();
|
||||||
|
if (n == 0 || !functionDecl->getParamDecl(n - 1)->hasDefaultArg()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( functionDecl->getLocation().isValid() )
|
||||||
|
{
|
||||||
|
MyFuncInfo funcInfo = niceName(functionDecl);
|
||||||
|
definitionSet.insert(funcInfo);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
loplugin::Plugin::Registration< UnusedDefaultParams > X("unuseddefaultparams", true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
78
compilerplugins/clang/unuseddefaultparams.py
Executable file
78
compilerplugins/clang/unuseddefaultparams.py
Executable file
@@ -0,0 +1,78 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
import io
|
||||||
|
|
||||||
|
definitionSet = set()
|
||||||
|
definitionToSourceLocationMap = dict()
|
||||||
|
callSet = set()
|
||||||
|
|
||||||
|
# things we need to exclude for reasons like :
|
||||||
|
# - it's a weird template thingy that confuses the plugin
|
||||||
|
exclusionSet = set()
|
||||||
|
|
||||||
|
# clang does not always use exactly the same numbers in the type-parameter vars it generates
|
||||||
|
# so I need to substitute them to ensure we can match correctly.
|
||||||
|
normalizeTypeParamsRegex = re.compile(r"type-parameter-\d+-\d+")
|
||||||
|
def normalizeTypeParams( line ):
|
||||||
|
return normalizeTypeParamsRegex.sub("type-parameter-?-?", line)
|
||||||
|
|
||||||
|
# The parsing here is designed to avoid grabbing stuff which is mixed in from gbuild.
|
||||||
|
# I have not yet found a way of suppressing the gbuild output.
|
||||||
|
with io.open(sys.argv[1], "rb", buffering=1024*1024) as txt:
|
||||||
|
for line in txt:
|
||||||
|
if line.startswith("defn:\t"):
|
||||||
|
idx1 = line.find("\t",6)
|
||||||
|
idx2 = line.find("\t",idx1+1)
|
||||||
|
idx3 = line.find("\t",idx2+1)
|
||||||
|
access = line[6:idx1]
|
||||||
|
returnType = line[idx1+1:idx2]
|
||||||
|
nameAndParams = line[idx2+1:idx3]
|
||||||
|
sourceLocation = line[idx3+1:].strip()
|
||||||
|
funcInfo = (normalizeTypeParams(returnType), normalizeTypeParams(nameAndParams))
|
||||||
|
definitionSet.add(funcInfo)
|
||||||
|
definitionToSourceLocationMap[funcInfo] = sourceLocation
|
||||||
|
elif line.startswith("call:\t"):
|
||||||
|
idx1 = line.find("\t",6)
|
||||||
|
returnType = line[6:idx1]
|
||||||
|
nameAndParams = line[idx1+1:].strip()
|
||||||
|
callSet.add((normalizeTypeParams(returnType), normalizeTypeParams(nameAndParams)))
|
||||||
|
|
||||||
|
# Invert the definitionToSourceLocationMap.
|
||||||
|
# If we see more than one method at the same sourceLocation, it's being autogenerated as part of a template
|
||||||
|
# and we should just ignore it.
|
||||||
|
sourceLocationToDefinitionMap = {}
|
||||||
|
for k, v in definitionToSourceLocationMap.iteritems():
|
||||||
|
sourceLocationToDefinitionMap[v] = sourceLocationToDefinitionMap.get(v, [])
|
||||||
|
sourceLocationToDefinitionMap[v].append(k)
|
||||||
|
for k, definitions in sourceLocationToDefinitionMap.iteritems():
|
||||||
|
if len(definitions) > 1:
|
||||||
|
for d in definitions:
|
||||||
|
definitionSet.remove(d)
|
||||||
|
|
||||||
|
|
||||||
|
tmp1set = set()
|
||||||
|
for d in definitionSet:
|
||||||
|
clazz = d[0] + " " + d[1]
|
||||||
|
if clazz in exclusionSet:
|
||||||
|
continue
|
||||||
|
if d in callSet:
|
||||||
|
continue
|
||||||
|
tmp1set.add((clazz, definitionToSourceLocationMap[d]))
|
||||||
|
|
||||||
|
# sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
|
||||||
|
def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
|
||||||
|
return [int(text) if text.isdigit() else text.lower()
|
||||||
|
for text in re.split(_nsre, s)]
|
||||||
|
|
||||||
|
# sort results by name and line number
|
||||||
|
tmp1list = sorted(tmp1set, key=lambda v: natural_sort_key(v[1]))
|
||||||
|
|
||||||
|
# print out the results
|
||||||
|
with open("unused.defaultparams", "wt") as f:
|
||||||
|
for t in tmp1list:
|
||||||
|
f.write(t[1] + "\n")
|
||||||
|
f.write(" " + t[0] + "\n")
|
||||||
|
|
||||||
|
|
@@ -47,17 +47,16 @@ struct MyFieldInfo
|
|||||||
std::string fieldName;
|
std::string fieldName;
|
||||||
std::string fieldType;
|
std::string fieldType;
|
||||||
std::string sourceLocation;
|
std::string sourceLocation;
|
||||||
|
|
||||||
bool operator < (const MyFieldInfo &other) const
|
|
||||||
{
|
|
||||||
if (parentClass < other.parentClass)
|
|
||||||
return true;
|
|
||||||
else if (parentClass == other.parentClass)
|
|
||||||
return fieldName < other.fieldName;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
bool operator < (const MyFieldInfo &lhs, const MyFieldInfo &rhs)
|
||||||
|
{
|
||||||
|
if (lhs.parentClass < rhs.parentClass)
|
||||||
|
return true;
|
||||||
|
else if (lhs.parentClass == rhs.parentClass)
|
||||||
|
return lhs.fieldName < rhs.fieldName;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// try to limit the voluminous output a little
|
// try to limit the voluminous output a little
|
||||||
|
@@ -52,17 +52,11 @@ struct MyFuncInfo
|
|||||||
std::string nameAndParams;
|
std::string nameAndParams;
|
||||||
std::string sourceLocation;
|
std::string sourceLocation;
|
||||||
|
|
||||||
bool operator < (const MyFuncInfo &other) const
|
|
||||||
{
|
|
||||||
if (returnType < other.returnType)
|
|
||||||
return true;
|
|
||||||
else if (returnType == other.returnType)
|
|
||||||
return nameAndParams < other.nameAndParams;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
bool operator < (const MyFuncInfo &lhs, const MyFuncInfo &rhs)
|
||||||
|
{
|
||||||
|
return lhs.sourceLocation < rhs.sourceLocation;
|
||||||
|
}
|
||||||
|
|
||||||
// try to limit the voluminous output a little
|
// try to limit the voluminous output a little
|
||||||
|
|
||||||
|
@@ -229,9 +229,7 @@ protected:
|
|||||||
|
|
||||||
/// export an element with string content
|
/// export an element with string content
|
||||||
void ExportElement(enum ::xmloff::token::XMLTokenEnum eElement, /// element token
|
void ExportElement(enum ::xmloff::token::XMLTokenEnum eElement, /// element token
|
||||||
const OUString& sContent, /// element content
|
const OUString& sContent); /// element content
|
||||||
bool bAddSpace = false); /// add blanks around
|
|
||||||
/// element?
|
|
||||||
|
|
||||||
/// export a macro (as used in the macro field)
|
/// export a macro (as used in the macro field)
|
||||||
void ExportMacro( const css::uno::Reference< css::beans::XPropertySet> & rPropSet,
|
void ExportMacro( const css::uno::Reference< css::beans::XPropertySet> & rPropSet,
|
||||||
@@ -278,16 +276,14 @@ protected:
|
|||||||
void ProcessString(
|
void ProcessString(
|
||||||
enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
|
enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
|
||||||
const OUString& sValue, /// attribute value
|
const OUString& sValue, /// attribute value
|
||||||
const OUString& sDefault, /// default value; omit if equal
|
const OUString& sDefault); /// default value; omit if equal
|
||||||
sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
|
|
||||||
|
|
||||||
/// export a string attribute, omit if default
|
/// export a string attribute, omit if default
|
||||||
void ProcessString(
|
void ProcessString(
|
||||||
enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
|
enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
|
||||||
sal_uInt16 nValuePrefix,
|
sal_uInt16 nValuePrefix,
|
||||||
const OUString& sValue, /// attribute value
|
const OUString& sValue, /// attribute value
|
||||||
const OUString& sDefault, /// default value; omit if equal
|
const OUString& sDefault); /// default value; omit if equal
|
||||||
sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
|
|
||||||
|
|
||||||
/// export a string attribute
|
/// export a string attribute
|
||||||
void ProcessString(
|
void ProcessString(
|
||||||
@@ -300,8 +296,7 @@ protected:
|
|||||||
void ProcessString(
|
void ProcessString(
|
||||||
enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
|
enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text)
|
||||||
enum ::xmloff::token::XMLTokenEnum eValue, /// attribute value token
|
enum ::xmloff::token::XMLTokenEnum eValue, /// attribute value token
|
||||||
enum ::xmloff::token::XMLTokenEnum eDefault, /// default value token
|
enum ::xmloff::token::XMLTokenEnum eDefault); /// default value token
|
||||||
sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
|
|
||||||
|
|
||||||
/// export a string as a sequence of paragraphs
|
/// export a string as a sequence of paragraphs
|
||||||
void ProcessParagraphSequence(
|
void ProcessParagraphSequence(
|
||||||
@@ -314,8 +309,7 @@ protected:
|
|||||||
|
|
||||||
/// export display attribute (value, formula, none)
|
/// export display attribute (value, formula, none)
|
||||||
void ProcessDisplay(bool bIsVisible, /// is visible?
|
void ProcessDisplay(bool bIsVisible, /// is visible?
|
||||||
bool bIsCommand, /// is show command/show name?
|
bool bIsCommand); /// is show command/show name?
|
||||||
bool bDefault = true); /// omit, if default
|
|
||||||
|
|
||||||
/// export all data-style related attributes
|
/// export all data-style related attributes
|
||||||
void ProcessValueAndType(
|
void ProcessValueAndType(
|
||||||
@@ -345,21 +339,18 @@ protected:
|
|||||||
sal_Int32 nMinutes, /// date/time value in minutes
|
sal_Int32 nMinutes, /// date/time value in minutes
|
||||||
bool bIsDate, /// export as date?
|
bool bIsDate, /// export as date?
|
||||||
bool bIsDuration, /// export as duration?
|
bool bIsDuration, /// export as duration?
|
||||||
bool bOmitDurationIfZero, /// omit zero-length durations
|
bool bOmitDurationIfZero); /// omit zero-length durations
|
||||||
sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
|
|
||||||
|
|
||||||
/// export times, dates and durations according to ISO 8601
|
/// export times, dates and durations according to ISO 8601
|
||||||
void ProcessDateTime(
|
void ProcessDateTime(
|
||||||
enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
|
enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
|
||||||
const css::util::DateTime& rTime, /// date/time value
|
const css::util::DateTime& rTime, /// date/time value
|
||||||
bool bIsDate, /// export as date (rather than date/time)?
|
bool bIsDate); /// export as date (rather than date/time)?
|
||||||
sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
|
|
||||||
|
|
||||||
/// export time or dateTime
|
/// export time or dateTime
|
||||||
void ProcessTimeOrDateTime(
|
void ProcessTimeOrDateTime(
|
||||||
enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
|
enum ::xmloff::token::XMLTokenEnum eXMLName, /// attribute token
|
||||||
const css::util::DateTime& rTime, /// date/time value
|
const css::util::DateTime& rTime); /// date/time value
|
||||||
sal_uInt16 nPrefix = XML_NAMESPACE_TEXT); /// attribute name prefix
|
|
||||||
|
|
||||||
/// export all attributes for bibliography data fields
|
/// export all attributes for bibliography data fields
|
||||||
void ProcessBibliographyData(
|
void ProcessBibliographyData(
|
||||||
|
@@ -237,9 +237,9 @@ public:
|
|||||||
void addPosition( css::uno::Reference< css::drawing::XShape > xShape );
|
void addPosition( css::uno::Reference< css::drawing::XShape > xShape );
|
||||||
/// add svg size as attribute for current element
|
/// add svg size as attribute for current element
|
||||||
void addSize( const css::awt::Size & rSize, bool bIsOOoNamespace = false );
|
void addSize( const css::awt::Size & rSize, bool bIsOOoNamespace = false );
|
||||||
void addSize( css::uno::Reference< css::drawing::XShape > xShape, bool bIsOOoNamespace = false );
|
void addSize( css::uno::Reference< css::drawing::XShape > xShape );
|
||||||
/// exports a string as a paragraph element
|
/// exports a string as a paragraph element
|
||||||
void exportText( const OUString& rText, bool bConvertTabsLFs = false );
|
void exportText( const OUString& rText );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SvXMLExport& mrExport;
|
SvXMLExport& mrExport;
|
||||||
@@ -3476,10 +3476,10 @@ void SchXMLExportHelper_Impl::addSize( const awt::Size & rSize, bool bIsOOoNames
|
|||||||
mrExport.AddAttribute( bIsOOoNamespace ? XML_NAMESPACE_CHART_EXT : XML_NAMESPACE_SVG, XML_HEIGHT, msString );
|
mrExport.AddAttribute( bIsOOoNamespace ? XML_NAMESPACE_CHART_EXT : XML_NAMESPACE_SVG, XML_HEIGHT, msString );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SchXMLExportHelper_Impl::addSize( Reference< drawing::XShape > xShape, bool bIsOOoNamespace )
|
void SchXMLExportHelper_Impl::addSize( Reference< drawing::XShape > xShape )
|
||||||
{
|
{
|
||||||
if( xShape.is())
|
if( xShape.is())
|
||||||
addSize( xShape->getSize(), bIsOOoNamespace );
|
addSize( xShape->getSize() );
|
||||||
}
|
}
|
||||||
|
|
||||||
awt::Size SchXMLExportHelper_Impl::getPageSize( const Reference< chart2::XChartDocument > & xChartDoc )
|
awt::Size SchXMLExportHelper_Impl::getPageSize( const Reference< chart2::XChartDocument > & xChartDoc )
|
||||||
@@ -3510,9 +3510,9 @@ void SchXMLExportHelper_Impl::AddAutoStyleAttribute( const std::vector< XMLPrope
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SchXMLExportHelper_Impl::exportText( const OUString& rText, bool bConvertTabsLFs )
|
void SchXMLExportHelper_Impl::exportText( const OUString& rText )
|
||||||
{
|
{
|
||||||
SchXMLTools::exportText( mrExport, rText, bConvertTabsLFs );
|
SchXMLTools::exportText( mrExport, rText, false/*bConvertTabsLFs*/ );
|
||||||
}
|
}
|
||||||
|
|
||||||
// class SchXMLExport
|
// class SchXMLExport
|
||||||
|
@@ -179,15 +179,10 @@ void lcl_resetSymbolSizeForPointsIfNecessary( const uno::Reference< beans::XProp
|
|||||||
|
|
||||||
void lcl_insertErrorBarLSequencesToMap(
|
void lcl_insertErrorBarLSequencesToMap(
|
||||||
tSchXMLLSequencesPerIndex & rInOutMap,
|
tSchXMLLSequencesPerIndex & rInOutMap,
|
||||||
const uno::Reference< beans::XPropertySet > & xSeriesProp,
|
const uno::Reference< beans::XPropertySet > & xSeriesProp )
|
||||||
bool bYError = true )
|
|
||||||
{
|
{
|
||||||
Reference< chart2::data::XDataSource > xErrorBarSource;
|
Reference< chart2::data::XDataSource > xErrorBarSource;
|
||||||
const OUString aPropName(
|
if( ( xSeriesProp->getPropertyValue( "ErrorBarY" ) >>= xErrorBarSource ) &&
|
||||||
bYError
|
|
||||||
? OUString( "ErrorBarY" )
|
|
||||||
: OUString( "ErrorBarX" ));
|
|
||||||
if( ( xSeriesProp->getPropertyValue( aPropName ) >>= xErrorBarSource ) &&
|
|
||||||
xErrorBarSource.is() )
|
xErrorBarSource.is() )
|
||||||
{
|
{
|
||||||
Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSequences(
|
Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSequences(
|
||||||
|
@@ -113,7 +113,7 @@ bool FormCellBindingHelper::livesInSpreadsheetDocument( const Reference< XProper
|
|||||||
return xDocument.is();
|
return xDocument.is();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FormCellBindingHelper::convertStringAddress( const OUString& _rAddressDescription, CellAddress& /* [out] */ _rAddress, sal_Int16 /*_nAssumeSheet*/ ) const
|
bool FormCellBindingHelper::convertStringAddress( const OUString& _rAddressDescription, CellAddress& /* [out] */ _rAddress ) const
|
||||||
{
|
{
|
||||||
Any aAddress;
|
Any aAddress;
|
||||||
return doConvertAddressRepresentations(
|
return doConvertAddressRepresentations(
|
||||||
|
@@ -183,8 +183,7 @@ namespace xmloff
|
|||||||
*/
|
*/
|
||||||
bool convertStringAddress(
|
bool convertStringAddress(
|
||||||
const OUString& _rAddressDescription,
|
const OUString& _rAddressDescription,
|
||||||
css::table::CellAddress& /* [out] */ _rAddress,
|
css::table::CellAddress& /* [out] */ _rAddress
|
||||||
sal_Int16 _nAssumeSheet = -1
|
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
/** creates an address range object from a string representation of a cell range address
|
/** creates an address range object from a string representation of a cell range address
|
||||||
|
@@ -473,10 +473,10 @@ namespace xmloff
|
|||||||
|
|
||||||
void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const sal_Char* _pAttributeName,
|
void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const sal_Char* _pAttributeName,
|
||||||
const OUString& _rPropertyName,
|
const OUString& _rPropertyName,
|
||||||
const sal_Unicode _aQuoteCharacter, const sal_Unicode _aListSeparator)
|
const sal_Unicode _aQuoteCharacter)
|
||||||
{
|
{
|
||||||
|
const sal_Unicode _aListSeparator = ',';
|
||||||
DBG_CHECK_PROPERTY( _rPropertyName, Sequence< OUString > );
|
DBG_CHECK_PROPERTY( _rPropertyName, Sequence< OUString > );
|
||||||
OSL_ENSURE(_aListSeparator != 0, "OPropertyExport::exportStringSequenceAttribute: invalid separator character!");
|
|
||||||
|
|
||||||
Sequence< OUString > aItems;
|
Sequence< OUString > aItems;
|
||||||
m_xProps->getPropertyValue( _rPropertyName ) >>= aItems;
|
m_xProps->getPropertyValue( _rPropertyName ) >>= aItems;
|
||||||
|
@@ -298,15 +298,12 @@ namespace xmloff
|
|||||||
the name of the property to ask the object for
|
the name of the property to ask the object for
|
||||||
@param _aQuoteCharacter
|
@param _aQuoteCharacter
|
||||||
the character to use to quote the sequence elements with. May be 0, in this case no quoting happens
|
the character to use to quote the sequence elements with. May be 0, in this case no quoting happens
|
||||||
@param _aListSeparator
|
|
||||||
the character to use to separate the list entries
|
|
||||||
*/
|
*/
|
||||||
void exportStringSequenceAttribute(
|
void exportStringSequenceAttribute(
|
||||||
const sal_uInt16 _nAttributeNamespaceKey,
|
const sal_uInt16 _nAttributeNamespaceKey,
|
||||||
const sal_Char* _pAttributeName,
|
const sal_Char* _pAttributeName,
|
||||||
const OUString& _rPropertyName,
|
const OUString& _rPropertyName,
|
||||||
const sal_Unicode _aQuoteCharacter = '"',
|
const sal_Unicode _aQuoteCharacter = '"');
|
||||||
const sal_Unicode _aListSeparator = ',');
|
|
||||||
|
|
||||||
/** determines whether the given property is to be exported
|
/** determines whether the given property is to be exported
|
||||||
|
|
||||||
|
@@ -2227,8 +2227,7 @@ void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName,
|
void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName,
|
||||||
const OUString& sContent,
|
const OUString& sContent)
|
||||||
bool bAddSpace)
|
|
||||||
{
|
{
|
||||||
DBG_ASSERT(eElementName != XML_TOKEN_INVALID, "invalid element name!");
|
DBG_ASSERT(eElementName != XML_TOKEN_INVALID, "invalid element name!");
|
||||||
if (eElementName != XML_TOKEN_INVALID)
|
if (eElementName != XML_TOKEN_INVALID)
|
||||||
@@ -2239,7 +2238,7 @@ void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName,
|
|||||||
if (SvtSaveOptions().GetODFDefaultVersion() > SvtSaveOptions::ODFVER_012)
|
if (SvtSaveOptions().GetODFDefaultVersion() > SvtSaveOptions::ODFVER_012)
|
||||||
{
|
{
|
||||||
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_LO_EXT,
|
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_LO_EXT,
|
||||||
eElementName, bAddSpace, bAddSpace );
|
eElementName, false, false );
|
||||||
// export content
|
// export content
|
||||||
GetExport().Characters(sContent);
|
GetExport().Characters(sContent);
|
||||||
}
|
}
|
||||||
@@ -2247,7 +2246,7 @@ void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
|
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
|
||||||
eElementName, bAddSpace, bAddSpace );
|
eElementName, false, false );
|
||||||
// export content
|
// export content
|
||||||
GetExport().Characters(sContent);
|
GetExport().Characters(sContent);
|
||||||
}
|
}
|
||||||
@@ -2426,8 +2425,7 @@ void XMLTextFieldExport::ProcessValueAndType(
|
|||||||
|
|
||||||
/// process display related properties
|
/// process display related properties
|
||||||
void XMLTextFieldExport::ProcessDisplay(bool bIsVisible,
|
void XMLTextFieldExport::ProcessDisplay(bool bIsVisible,
|
||||||
bool bIsCommand,
|
bool bIsCommand)
|
||||||
bool bValueDefault)
|
|
||||||
{
|
{
|
||||||
enum XMLTokenEnum eValue;
|
enum XMLTokenEnum eValue;
|
||||||
|
|
||||||
@@ -2441,7 +2439,7 @@ void XMLTextFieldExport::ProcessDisplay(bool bIsVisible,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// omit attribute if default
|
// omit attribute if default
|
||||||
if (!bValueDefault || (eValue != XML_VALUE))
|
if (eValue != XML_VALUE)
|
||||||
{
|
{
|
||||||
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_DISPLAY, eValue);
|
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_DISPLAY, eValue);
|
||||||
}
|
}
|
||||||
@@ -2497,12 +2495,11 @@ void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
|
|||||||
/// export a string attribute
|
/// export a string attribute
|
||||||
void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
|
void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
|
||||||
const OUString& sValue,
|
const OUString& sValue,
|
||||||
const OUString& sDefault,
|
const OUString& sDefault)
|
||||||
sal_uInt16 nPrefix)
|
|
||||||
{
|
{
|
||||||
if (sValue != sDefault)
|
if (sValue != sDefault)
|
||||||
{
|
{
|
||||||
ProcessString(eName, sValue, false, nPrefix);
|
ProcessString(eName, sValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2510,12 +2507,11 @@ void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
|
|||||||
void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
|
void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
|
||||||
sal_uInt16 nValuePrefix,
|
sal_uInt16 nValuePrefix,
|
||||||
const OUString& sValue,
|
const OUString& sValue,
|
||||||
const OUString& sDefault,
|
const OUString& sDefault)
|
||||||
sal_uInt16 nPrefix)
|
|
||||||
{
|
{
|
||||||
if (sValue != sDefault)
|
if (sValue != sDefault)
|
||||||
{
|
{
|
||||||
ProcessString(eName, nValuePrefix, sValue, false, nPrefix);
|
ProcessString(eName, nValuePrefix, sValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2544,11 +2540,10 @@ void XMLTextFieldExport::ProcessString(
|
|||||||
void XMLTextFieldExport::ProcessString(
|
void XMLTextFieldExport::ProcessString(
|
||||||
enum XMLTokenEnum eName,
|
enum XMLTokenEnum eName,
|
||||||
enum XMLTokenEnum eValue,
|
enum XMLTokenEnum eValue,
|
||||||
enum XMLTokenEnum eDefault,
|
enum XMLTokenEnum eDefault)
|
||||||
sal_uInt16 nPrefix)
|
|
||||||
{
|
{
|
||||||
if ( eValue != eDefault )
|
if ( eValue != eDefault )
|
||||||
ProcessString( eName, eValue, false, nPrefix);
|
ProcessString( eName, eValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2650,8 +2645,7 @@ void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
|
|||||||
/// export a date or time
|
/// export a date or time
|
||||||
void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
|
void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
|
||||||
const util::DateTime& rTime,
|
const util::DateTime& rTime,
|
||||||
bool bIsDate,
|
bool bIsDate)
|
||||||
sal_uInt16 nPrefix)
|
|
||||||
{
|
{
|
||||||
OUStringBuffer aBuffer;
|
OUStringBuffer aBuffer;
|
||||||
|
|
||||||
@@ -2670,7 +2664,7 @@ void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
|
|||||||
::sax::Converter::convertDateTime(aBuffer, aDateTime, nullptr);
|
::sax::Converter::convertDateTime(aBuffer, aDateTime, nullptr);
|
||||||
|
|
||||||
// output attribute
|
// output attribute
|
||||||
ProcessString(eName, aBuffer.makeStringAndClear(), true, nPrefix);
|
ProcessString(eName, aBuffer.makeStringAndClear(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// export a date, time, or duration
|
/// export a date, time, or duration
|
||||||
@@ -2678,21 +2672,19 @@ void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
|
|||||||
sal_Int32 nMinutes,
|
sal_Int32 nMinutes,
|
||||||
bool bIsDate,
|
bool bIsDate,
|
||||||
bool bIsDuration,
|
bool bIsDuration,
|
||||||
bool bOmitDurationIfZero,
|
bool bOmitDurationIfZero)
|
||||||
sal_uInt16 nPrefix)
|
|
||||||
{
|
{
|
||||||
// handle bOmitDurationIfZero here, because we can precisely compare ints
|
// handle bOmitDurationIfZero here, because we can precisely compare ints
|
||||||
if (!(bIsDuration && bOmitDurationIfZero && (nMinutes==0)))
|
if (!(bIsDuration && bOmitDurationIfZero && (nMinutes==0)))
|
||||||
{
|
{
|
||||||
ProcessDateTime(eName, (double)nMinutes / (double)(24*60),
|
ProcessDateTime(eName, (double)nMinutes / (double)(24*60),
|
||||||
bIsDate, bIsDuration, bOmitDurationIfZero, nPrefix);
|
bIsDate, bIsDuration, bOmitDurationIfZero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// export a time or dateTime
|
/// export a time or dateTime
|
||||||
void XMLTextFieldExport::ProcessTimeOrDateTime(enum XMLTokenEnum eName,
|
void XMLTextFieldExport::ProcessTimeOrDateTime(enum XMLTokenEnum eName,
|
||||||
const util::DateTime& rTime,
|
const util::DateTime& rTime)
|
||||||
sal_uInt16 nPrefix)
|
|
||||||
{
|
{
|
||||||
OUStringBuffer aBuffer;
|
OUStringBuffer aBuffer;
|
||||||
|
|
||||||
@@ -2700,7 +2692,7 @@ void XMLTextFieldExport::ProcessTimeOrDateTime(enum XMLTokenEnum eName,
|
|||||||
::sax::Converter::convertTimeOrDateTime(aBuffer, rTime, nullptr);
|
::sax::Converter::convertTimeOrDateTime(aBuffer, rTime, nullptr);
|
||||||
|
|
||||||
// output attribute
|
// output attribute
|
||||||
ProcessString(eName, aBuffer.makeStringAndClear(), true, nPrefix);
|
ProcessString(eName, aBuffer.makeStringAndClear(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -43,16 +43,13 @@ namespace xmlscript
|
|||||||
|
|
||||||
@param xRoot
|
@param xRoot
|
||||||
initial object being called for root context
|
initial object being called for root context
|
||||||
@param bSingleThreadedUse
|
|
||||||
flag whether context management is synchronized.
|
|
||||||
@return
|
@return
|
||||||
document handler for parser
|
document handler for parser
|
||||||
*/
|
*/
|
||||||
css::uno::Reference< css::xml::sax::XDocumentHandler >
|
css::uno::Reference< css::xml::sax::XDocumentHandler >
|
||||||
SAL_CALL createDocumentHandler(
|
SAL_CALL createDocumentHandler(
|
||||||
css::uno::Reference<
|
css::uno::Reference<
|
||||||
css::xml::input::XRoot > const & xRoot,
|
css::xml::input::XRoot > const & xRoot );
|
||||||
bool bSingleThreadedUse = true );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -789,14 +789,13 @@ OUString ExtendedAttributes::getValueByUidName(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Reference< xml::sax::XDocumentHandler > SAL_CALL createDocumentHandler(
|
Reference< xml::sax::XDocumentHandler > SAL_CALL createDocumentHandler(
|
||||||
Reference< xml::input::XRoot > const & xRoot,
|
Reference< xml::input::XRoot > const & xRoot )
|
||||||
bool bSingleThreadedUse )
|
|
||||||
{
|
{
|
||||||
SAL_WARN_IF( !xRoot.is(), "xmlscript.xmlhelper", "xRoot is NULL" );
|
SAL_WARN_IF( !xRoot.is(), "xmlscript.xmlhelper", "xRoot is NULL" );
|
||||||
if (xRoot.is())
|
if (xRoot.is())
|
||||||
{
|
{
|
||||||
return static_cast< xml::sax::XDocumentHandler * >(
|
return static_cast< xml::sax::XDocumentHandler * >(
|
||||||
new DocumentHandlerImpl( xRoot, bSingleThreadedUse ) );
|
new DocumentHandlerImpl( xRoot, true /* mt use */ ) );
|
||||||
}
|
}
|
||||||
return Reference< xml::sax::XDocumentHandler >();
|
return Reference< xml::sax::XDocumentHandler >();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user