1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
7 * This file is distributed under the University of Illinois Open Source
8 * License. See LICENSE.TXT for details.
13 This is technically a rewriter, but it actually only generates data about code.
17 Checks for all function declarations for whether they are used or not. This information
18 should be output to files and in a second pass it should be checked (by another tool)
19 which functions are never used.
28 : public loplugin::FilteringRewritePlugin
< UnusedCode
>
31 explicit UnusedCode( CompilerInstance
& compiler
, Rewriter
& rewriter
);
32 virtual void run() override
;
33 bool VisitFunctionDecl( const FunctionDecl
* declaration
);
36 UnusedCode::UnusedCode( CompilerInstance
& compiler
, Rewriter
& rewriter
)
37 : FilteringRewritePlugin( compiler
, rewriter
)
41 void UnusedCode::run()
43 TraverseDecl( compiler
.getASTContext().getTranslationUnitDecl());
46 bool UnusedCode::VisitFunctionDecl( const FunctionDecl
* declaration
)
48 if( ignoreLocation( declaration
))
50 bool isUsed
= declaration
->isUsed();
51 if( const CXXMethodDecl
* cxxmethod
= dyn_cast
< CXXMethodDecl
>( declaration
))
53 if( !isUsed
&& cxxmethod
->isVirtual())
54 { // Virtual methods are used also if a method they override is used.
55 for( CXXMethodDecl::method_iterator it
= cxxmethod
->begin_overridden_methods();
56 it
!= cxxmethod
->end_overridden_methods();
67 // Fully qualified name: declaration->getQualifiedNameAsString()
69 // The main source file compiled: compiler.getSourceManager().getFileEntryForID( compiler.getSourceManager().getMainFileID())->getName()
73 static Plugin::Registration
< UnusedCode
> X( "unusedcode" );
77 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */