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.
12 #include "removeforwardstringdecl.hxx"
17 Remove all forward declarations of rtl strings. I.e. 'namespace rtl { class OUString; }' etc.
23 RemoveForwardStringDecl::RemoveForwardStringDecl( CompilerInstance
& compiler
, Rewriter
& rewriter
)
24 : RewritePlugin( compiler
, rewriter
)
28 void RemoveForwardStringDecl::run()
30 TraverseDecl( compiler
.getASTContext().getTranslationUnitDecl());
33 bool RemoveForwardStringDecl::VisitNamespaceDecl( const NamespaceDecl
* declaration
)
35 if( ignoreLocation( declaration
))
37 if( declaration
->getQualifiedNameAsString() != "rtl" )
39 bool canRemove
= true;
40 for( NamespaceDecl::decl_iterator it
= declaration
->decls_begin();
41 it
!= declaration
->decls_end();
46 if( !tryRemoveStringForwardDecl( *it
))
50 if( canRemove
) // contained only forward decls that we removed
51 removeText( declaration
->getSourceRange(), RemoveLineIfEmpty
);
55 bool RemoveForwardStringDecl::tryRemoveStringForwardDecl( const Decl
* decl
)
57 const CXXRecordDecl
* classdecl
= dyn_cast
< CXXRecordDecl
>( decl
);
58 if( classdecl
== NULL
)
60 if( !classdecl
->isFreeStanding() || classdecl
->isCompleteDefinition())
61 return false; // not a simple forward declaration
62 if( classdecl
->getName() == "OString" || classdecl
->getName() == "OUString"
63 || classdecl
->getName() == "OStringBuffer" || classdecl
->getName() == "OUStringBuffer"
64 || classdecl
->getName() == "OStringHash" || classdecl
->getName() == "OUStringHash"
65 || classdecl
->getName() == "OStringLiteral" || classdecl
->getName() == "OUStringLiteral" )
67 removeText( SourceRange( classdecl
->getOuterLocStart(), classdecl
->getLocEnd()),
68 RemoveLineIfEmpty
| RemoveWholeStatement
);
74 static Plugin::Registration
< RemoveForwardStringDecl
> X( "removeforwardstringdecl" );
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */