diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2012-10-15 17:34:13 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2012-10-15 23:33:07 +0200 |
commit | 2e3642e66bfeddd3dbb9c91637059e32b444ac52 (patch) | |
tree | ac875a2499958cc9b8f8c6fcba6d021bd41aabfd /compilerplugins/clang/plugin.cxx | |
parent | 6c997887a37d7b84745f3a66393d66b65739246d (diff) |
convenience functions for source rewriters
Change-Id: I36e2b49bc615db0b12b03ffa755fa51acc6830a0
Diffstat (limited to 'compilerplugins/clang/plugin.cxx')
-rw-r--r-- | compilerplugins/clang/plugin.cxx | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index 115193c14137..853cf74a8526 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -52,6 +52,92 @@ bool Plugin::ignoreLocation( SourceLocation loc ) return context.getSourceManager().isInSystemHeader( context.getSourceManager().getExpansionLoc( loc )); } + +RewritePlugin::RewritePlugin( ASTContext& context, Rewriter& rewriter ) + : Plugin( context ) + , rewriter( rewriter ) + { + } + +bool RewritePlugin::insertText( SourceLocation Loc, StringRef Str, bool InsertAfter, bool indentNewLines ) + { + if( rewriter.InsertText( Loc, Str, InsertAfter, indentNewLines )) + return reportEditFailure( Loc ); + return true; + } + +bool RewritePlugin::insertTextAfter( SourceLocation Loc, StringRef Str ) + { + if( rewriter.InsertTextAfter( Loc, Str )) + return reportEditFailure( Loc ); + return true; + } + +bool RewritePlugin::insertTextAfterToken( SourceLocation Loc, StringRef Str ) + { + if( rewriter.InsertTextAfterToken( Loc, Str )) + return reportEditFailure( Loc ); + return true; + } + +bool RewritePlugin::insertTextBefore( SourceLocation Loc, StringRef Str ) + { + if( rewriter.InsertTextBefore( Loc, Str )) + return reportEditFailure( Loc ); + return true; + } + +bool RewritePlugin::removeText( SourceLocation Start, unsigned Length, RewriteOptions opts ) + { + if( rewriter.RemoveText( Start, Length, opts )) + return reportEditFailure( Start ); + return true; + } + +bool RewritePlugin::removeText( CharSourceRange range, RewriteOptions opts ) + { + if( rewriter.RemoveText( range, opts )) + return reportEditFailure( range.getBegin()); + return true; + } + +bool RewritePlugin::removeText( SourceRange range, RewriteOptions opts ) + { + if( rewriter.RemoveText( range, opts )) + return reportEditFailure( range.getBegin()); + return true; + } + +bool RewritePlugin::replaceText( SourceLocation Start, unsigned OrigLength, StringRef NewStr ) + { + if( rewriter.ReplaceText( Start, OrigLength, NewStr )) + return reportEditFailure( Start ); + return true; + } + +bool RewritePlugin::replaceText( SourceRange range, StringRef NewStr ) + { + if( rewriter.ReplaceText( range, NewStr )) + return reportEditFailure( range.getBegin()); + return true; + } + +bool RewritePlugin::replaceText( SourceRange range, SourceRange replacementRange ) + { + if( rewriter.ReplaceText( range, replacementRange )) + return reportEditFailure( range.getBegin()); + return true; + } + +bool RewritePlugin::reportEditFailure( SourceLocation loc ) + { + DiagnosticsEngine& diag = context.getDiagnostics(); + diag.Report( loc, diag.getCustomDiagID( DiagnosticsEngine::Warning, + "cannot perform source modification (macro expansion involved?) [loplugin]" )); + return false; + } + + /** Class that manages all LO modules. */ |