================
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
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to