bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / store / removeforwardstringdecl.cxx
blobe7a546a8f5d39d54cc2196bc25a22f23ee19d458
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * Based on LLVM/Clang.
7 * This file is distributed under the University of Illinois Open Source
8 * License. See LICENSE.TXT for details.
12 #include "removeforwardstringdecl.hxx"
15 This is a rewriter.
17 Remove all forward declarations of rtl strings. I.e. 'namespace rtl { class OUString; }' etc.
20 namespace loplugin
23 RemoveForwardStringDecl::RemoveForwardStringDecl( CompilerInstance& compiler, Rewriter& rewriter )
24 : FilteringRewritePlugin( compiler, rewriter )
28 void RemoveForwardStringDecl::run()
30 TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
33 bool RemoveForwardStringDecl::VisitNamespaceDecl( const NamespaceDecl* declaration )
35 if( ignoreLocation( declaration ))
36 return true;
37 if( declaration->getQualifiedNameAsString() != "rtl" )
38 return true;
39 bool canRemove = true;
40 for( NamespaceDecl::decl_iterator it = declaration->decls_begin();
41 it != declaration->decls_end();
42 ++it )
44 if( *it != NULL )
46 if( !tryRemoveStringForwardDecl( *it ))
47 canRemove = false;
50 if( canRemove ) // contained only forward decls that we removed
51 removeText( declaration->getSourceRange(), RemoveLineIfEmpty );
52 return true;
55 bool RemoveForwardStringDecl::tryRemoveStringForwardDecl( const Decl* decl )
57 const CXXRecordDecl* classdecl = dyn_cast< CXXRecordDecl >( decl );
58 if( classdecl == NULL )
59 return false;
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 );
69 return true;
71 return false;
74 static Plugin::Registration< RemoveForwardStringDecl > X( "removeforwardstringdecl" );
76 } // namespace
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */