rewriter plugin for removing forward rtl string declarations
Change-Id: I12bf38985ae62756973c05aacf762ae3c405ac9b
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "bodynotinblock.hxx"
|
||||
#include "lclstaticfix.hxx"
|
||||
#include "postfixincrementfix.hxx"
|
||||
#include "removeforwardstringdecl.hxx"
|
||||
#include "sallogareas.hxx"
|
||||
#include "unusedvariablecheck.hxx"
|
||||
|
||||
@@ -192,6 +193,7 @@ class PluginHandler
|
||||
, bodyNotInBlock( context )
|
||||
, lclStaticFix( context, rewriter )
|
||||
, postfixIncrementFix( context, rewriter )
|
||||
, removeForwardStringDecl( context, rewriter )
|
||||
, salLogAreas( context )
|
||||
, unusedVariableCheck( context )
|
||||
{
|
||||
@@ -204,6 +206,8 @@ class PluginHandler
|
||||
lclStaticFix.run();
|
||||
else if( isArg( "postfixincrementfix" ))
|
||||
postfixIncrementFix.run();
|
||||
else if( isArg( "removeforwardstringdecl" ))
|
||||
removeForwardStringDecl.run();
|
||||
else if( args.empty())
|
||||
{
|
||||
bodyNotInBlock.run();
|
||||
@@ -292,6 +296,7 @@ class PluginHandler
|
||||
BodyNotInBlock bodyNotInBlock;
|
||||
LclStaticFix lclStaticFix;
|
||||
PostfixIncrementFix postfixIncrementFix;
|
||||
RemoveForwardStringDecl removeForwardStringDecl;
|
||||
SalLogAreas salLogAreas;
|
||||
UnusedVariableCheck unusedVariableCheck;
|
||||
};
|
||||
|
76
compilerplugins/clang/removeforwardstringdecl.cxx
Normal file
76
compilerplugins/clang/removeforwardstringdecl.cxx
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* Based on LLVM/Clang.
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "removeforwardstringdecl.hxx"
|
||||
|
||||
#include <clang/AST/ASTContext.h>
|
||||
#include <clang/Basic/SourceManager.h>
|
||||
|
||||
/*
|
||||
This is a rewriter.
|
||||
|
||||
Remove all forward declarations of rtl strings. I.e. 'namespace rtl { class OUString; }' etc.
|
||||
*/
|
||||
|
||||
namespace loplugin
|
||||
{
|
||||
|
||||
RemoveForwardStringDecl::RemoveForwardStringDecl( ASTContext& context, Rewriter& rewriter )
|
||||
: RewritePlugin( context, rewriter )
|
||||
{
|
||||
}
|
||||
|
||||
void RemoveForwardStringDecl::run()
|
||||
{
|
||||
TraverseDecl( context.getTranslationUnitDecl());
|
||||
}
|
||||
|
||||
bool RemoveForwardStringDecl::VisitNamespaceDecl( NamespaceDecl* declaration )
|
||||
{
|
||||
if( ignoreLocation( declaration ))
|
||||
return true;
|
||||
if( declaration->getQualifiedNameAsString() != "rtl" )
|
||||
return true;
|
||||
bool canRemove = true;
|
||||
for( NamespaceDecl::decl_iterator it = declaration->decls_begin();
|
||||
it != declaration->decls_end();
|
||||
++it )
|
||||
{
|
||||
if( *it != NULL )
|
||||
{
|
||||
if( !tryRemoveStringForwardDecl( *it ))
|
||||
canRemove = false;
|
||||
}
|
||||
}
|
||||
if( canRemove ) // contained only forward decls that we removed
|
||||
removeText( declaration->getSourceRange(), RemoveLineIfEmpty );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RemoveForwardStringDecl::tryRemoveStringForwardDecl( const Decl* decl )
|
||||
{
|
||||
const CXXRecordDecl* classdecl = dyn_cast< CXXRecordDecl >( decl );
|
||||
if( classdecl == NULL )
|
||||
return false;
|
||||
if( !classdecl->isFreeStanding() || classdecl->isCompleteDefinition())
|
||||
return false; // not a simple forward declaration
|
||||
if( classdecl->getName() == "OString" || classdecl->getName() == "OUString"
|
||||
|| classdecl->getName() == "OStringBuffer" || classdecl->getName() == "OUStringBuffer"
|
||||
|| classdecl->getName() == "OStringHash" || classdecl->getName() == "OUStringHash"
|
||||
|| classdecl->getName() == "OStringLiteral" || classdecl->getName() == "OUStringLiteral" )
|
||||
{
|
||||
removeText( SourceRange( classdecl->getOuterLocStart(), classdecl->getLocEnd()),
|
||||
RemoveLineIfEmpty | RemoveWholeStatement );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
34
compilerplugins/clang/removeforwardstringdecl.hxx
Normal file
34
compilerplugins/clang/removeforwardstringdecl.hxx
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* Based on LLVM/Clang.
|
||||
*
|
||||
* This file is distributed under the University of Illinois Open Source
|
||||
* License. See LICENSE.TXT for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef REMOVEFORWARDSTRINGDECL_H
|
||||
#define REMOVEFORWARDSTRINGDECL_H
|
||||
|
||||
#include "plugin.hxx"
|
||||
|
||||
namespace loplugin
|
||||
{
|
||||
|
||||
class RemoveForwardStringDecl
|
||||
: public RecursiveASTVisitor< RemoveForwardStringDecl >
|
||||
, public RewritePlugin
|
||||
{
|
||||
public:
|
||||
explicit RemoveForwardStringDecl( ASTContext& context, Rewriter& rewriter );
|
||||
void run();
|
||||
bool VisitNamespaceDecl( NamespaceDecl* declaration );
|
||||
private:
|
||||
bool tryRemoveStringForwardDecl( const Decl* decl );
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // REMOVEFORWARDSTRINGDECL_H
|
||||
|
Reference in New Issue
Block a user