[PATCH] Initial version of clang-tidy check to use override instead of virual.
Alexander Kornienko
alexfh at google.com
Thu May 15 06:13:29 PDT 2014
================
Comment at: clang-tidy/misc/UseOverride.cpp:96
@@ +95,3 @@
+ InsertLoc = Tokens[Tokens.size() - 2].getLocation();
+ } else if (TokenText.back() == "ABSTRACT") {
+ InsertLoc = Tokens.back().getLocation();
----------------
Instead of special-casing this macro, you could find if the identifier is a macro, and see what it expands to using something similar to this:
IdentifierInfo *II = PP.getIdentifierInfo(Token.back());
if (II.hadMacroDefinition()) {
if (const DefMacroDirective *Def = PP.getMacroDirectiveHistory(II)->findDirectiveAtLoc(...)->getDirective()) {
<compare Def->getInfo()->tokens_{begin,end}() with {'=', '0'}>
...
================
Comment at: clang-tidy/misc/UseOverride.cpp:41
@@ +40,3 @@
+
+ // Re-lex the tokens to get precise locations to insert 'override' and remove
+ // 'virtual'.
----------------
Daniel Jasper wrote:
> Alexander Kornienko wrote:
> > Can you adapt FindToken from google/GoogleTidyModule.cpp to be usable here (and move it to a common place)? (Or maybe convert it to ParseTokens or something similar.)
> Only partially as I need to lex all the tokens of the function definition (to scan backwards for "= 0"). I guess we could pull out abstraction here, but I am not exactly sure what that should be.
We could at least pull out something like this:
vector<Token> ParseTokens(SourceLocation From, SourceLocation To, <SourceManager and whatever else is needed>);
To be more generic "To" could be replaced by a predicate, though this may be too generic ;)
http://reviews.llvm.org/D3688
More information about the cfe-commits
mailing list