bump product version to 5.0.4.1
[LibreOffice.git] / compilerplugins / clang / store / removeforwardstringdecl.cxx
blobc70d7a8e2eb27cd44de872ce85d0dbf0ab4806ea
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 : RewritePlugin( 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: */