[cfe-commits] [PATCH] Compatibility macro detection for the -Wimplicit-fallthrough diagnostic.
Richard Smith
reviews at llvm-reviews.chandlerc.com
Thu Sep 27 13:30:48 PDT 2012
================
Comment at: tools/clang/lib/Sema/AnalysisBasedWarnings.cpp:748
@@ +747,3 @@
+ Tokens.push_back(T);
+ T.setFlag(Token::DisableExpand);
+ Tokens.push_back(T);
----------------
Alexander Kornienko wrote:
> This hack is used to pass to information, that we need hasLeadingSpace check, to MacroDefinitionEquals.
> Is there a better way to do this?
Don't do it at all -- whitespace is permitted between the two '[' tokens which introduce an attribute.
================
Comment at: tools/clang/lib/Sema/AnalysisBasedWarnings.cpp:743
@@ +742,3 @@
+ SourceLocation L) {
+ llvm::SmallVector<Token, 8> Tokens;
+ Token T;
----------------
Instead of building and comparing Tokens, how about a separate data structure to represent what you're matching? Something like...
class TokenValue {
tok::TokenKind Kind;
IdentifierInfo *II;
public:
TokenValue(tok::TokenKind Kind) : Kind(Kind), II(0) {}
TokenValue(IdentifierInfo *II) : Kind(tok::identifier), II(II) {}
bool operator==(const Token &Tok) const {
return Tok.getKind() == Kind &&
(!II || II == Tok.getIdentifierInfo());
};
TokenValue ClangFallthroughTokens[] = {
tok::l_square, tok::l_square, PP.getIdentifierInfo("clang"),
tok::coloncolon, PP.getIdentifierInfo("fallthrough"),
tok::r_square, tok::r_square
};
// ...
static bool MacroDefinitionEquals(const MacroInfo *MI, llvm::ArrayRef<TokenValue> Tokens) {
return Tokens.size() == MI->getNumTokens() &&
std::equal(Tokens.begin(), Tokens.end(), MI->tokens_begin());
}
http://llvm-reviews.chandlerc.com/D50
More information about the cfe-commits
mailing list