2012-10-15 15:36:25 +02:00
|
|
|
/*
|
|
|
|
* 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 "lclstaticfix.hxx"
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is a rewriter.
|
|
|
|
|
|
|
|
Check all lcl_ functions and prepend static if needed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace loplugin
|
|
|
|
{
|
|
|
|
|
2013-03-28 18:07:09 +01:00
|
|
|
LclStaticFix::LclStaticFix( CompilerInstance& compiler, Rewriter& rewriter )
|
|
|
|
: RewritePlugin( compiler, rewriter )
|
2012-10-15 15:36:25 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LclStaticFix::run()
|
|
|
|
{
|
2013-03-28 18:07:09 +01:00
|
|
|
TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
|
2012-10-15 15:36:25 +02:00
|
|
|
}
|
|
|
|
|
2013-05-02 18:17:32 +02:00
|
|
|
bool LclStaticFix::VisitFunctionDecl( const FunctionDecl* declaration )
|
2012-10-15 15:36:25 +02:00
|
|
|
{
|
2013-01-03 20:15:21 +01:00
|
|
|
if( ignoreLocation( declaration ))
|
2012-10-15 15:36:25 +02:00
|
|
|
return true;
|
|
|
|
if( declaration->isCXXClassMember())
|
|
|
|
return true;
|
|
|
|
if( declaration->getStorageClass() == SC_Static )
|
|
|
|
return true;
|
|
|
|
string name = declaration->getQualifiedNameAsString();
|
|
|
|
if( name.find( "::" ) != string::npos )
|
|
|
|
return true;
|
|
|
|
if( name.compare( 0, 4, "lcl_" ) != 0 )
|
|
|
|
return true;
|
2012-10-15 17:34:13 +02:00
|
|
|
insertText( declaration->getLocStart(), "static " );
|
2012-10-15 15:36:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-02 17:45:18 +01:00
|
|
|
static Plugin::Registration< LclStaticFix > X( "lclstaticfix" );
|
|
|
|
|
2012-10-15 15:36:25 +02:00
|
|
|
} // namespace
|