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 RecursiveASTVisitor
< UnusedCode
>
29 , public RewritePlugin
32 explicit UnusedCode( CompilerInstance
& compiler
, Rewriter
& rewriter
);
33 virtual void run() override
;
34 bool VisitFunctionDecl( const FunctionDecl
* declaration
);
37 UnusedCode::UnusedCode( CompilerInstance
& compiler
, Rewriter
& rewriter
)
38 : RewritePlugin( compiler
, rewriter
)
42 void UnusedCode::run()
44 TraverseDecl( compiler
.getASTContext().getTranslationUnitDecl());
47 bool UnusedCode::VisitFunctionDecl( const FunctionDecl
* declaration
)
49 if( ignoreLocation( declaration
))
51 bool isUsed
= declaration
->isUsed();
52 if( const CXXMethodDecl
* cxxmethod
= dyn_cast
< CXXMethodDecl
>( declaration
))
54 if( !isUsed
&& cxxmethod
->isVirtual())
55 { // Virtual methods are used also if a method they override is used.
56 for( CXXMethodDecl::method_iterator it
= cxxmethod
->begin_overridden_methods();
57 it
!= cxxmethod
->end_overridden_methods();
68 // Fully qualified name: declaration->getQualifiedNameAsString()
70 // The main source file compiled: compiler.getSourceManager().getFileEntryForID( compiler.getSourceManager().getMainFileID())->getName()
74 static Plugin::Registration
< UnusedCode
> X( "unusedcode" );
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */