Also match the identifiers and the token types.

This commit is contained in:
Roberto Raggi
2009-11-13 11:54:22 +01:00
parent f8beeea6dd
commit 5644775d2f
3 changed files with 280 additions and 252 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -65,6 +65,8 @@ public:
void getTokenEndPosition(unsigned index, unsigned *line, unsigned *column) const;
bool matchToken(unsigned index, unsigned otherIndex) const;
virtual bool match(AccessDeclarationAST *node, AccessDeclarationAST *pattern);
virtual bool match(ArrayAccessAST *node, ArrayAccessAST *pattern);
virtual bool match(ArrayDeclaratorAST *node, ArrayDeclaratorAST *pattern);

View File

@@ -387,6 +387,19 @@ public:
<< endl
<< "void ASTMatcher::getTokenEndPosition(unsigned index, unsigned *line, unsigned *column) const" << endl
<< "{ getPosition(tokenAt(index).end(), line, column); }" << endl
<< endl
<< "bool ASTMatcher::matchToken(unsigned index, unsigned otherIndex) const" << endl
<< "{" << endl
<< " const Token &token = tokenAt(index);" << endl
<< " const Token &otherToken = tokenAt(otherIndex);" << endl
<< " if (token.f.kind != otherToken.f.kind)" << endl
<< " return false;" << endl
<< " else if (token.is(T_IDENTIFIER)) {" << endl
<< " if (token.identifier != otherToken.identifier)" << endl
<< " return false;" << endl
<< " }" << endl
<< " return true;" << endl
<< "}" << endl
<< endl;
accept(ast);
@@ -425,7 +438,7 @@ protected:
if (member->type().isUnsigned() && memberName.endsWith("_token")) {
// nothing to do. The member is a token.
*out << " if (node->" << memberName << " != pattern->" << memberName << ")" << endl
*out << " if (! matchToken(node->" << memberName << ", pattern->" << memberName << "))" << endl
<< " return false;" << endl;
} else if (PointerType *ptrTy = member->type()->asPointerType()) {