Fixed parsing of ctor-initializers and added a manual test for the AST matchers

This commit is contained in:
Roberto Raggi
2009-11-13 12:36:51 +01:00
parent 28ab85b137
commit baffd97efb
11 changed files with 63 additions and 49 deletions

View File

@@ -983,8 +983,8 @@ unsigned MemInitializerAST::lastToken() const
{
if (rparen_token)
return rparen_token + 1;
else if (expression)
return expression->lastToken();
else if (expression_list)
return expression_list->lastToken();
else if (lparen_token)
return lparen_token + 1;
return name->lastToken();

View File

@@ -1187,7 +1187,7 @@ class CPLUSPLUS_EXPORT MemInitializerAST: public AST
public:
NameAST *name;
unsigned lparen_token;
ExpressionAST *expression;
ExpressionListAST *expression_list;
unsigned rparen_token;
public:

View File

@@ -31,6 +31,7 @@
#include "ASTMatcher.h"
#include "Control.h"
#include "TranslationUnit.h"
#include "Literals.h"
using namespace CPlusPlus;
@@ -54,7 +55,7 @@ bool ASTMatcher::matchToken(unsigned tokenIndex, unsigned patternTokenIndex) con
if (token.f.kind != otherToken.f.kind)
return false;
else if (token.is(T_IDENTIFIER)) {
if (token.identifier != otherToken.identifier)
if (! token.identifier->isEqualTo(otherToken.identifier))
return false;
}
return true;
@@ -636,7 +637,7 @@ bool ASTMatcher::match(MemInitializerAST *node, MemInitializerAST *pattern)
return false;
if (! matchToken(node->lparen_token, pattern->lparen_token))
return false;
if (! AST::match(node->expression, pattern->expression, this))
if (! AST::match(node->expression_list, pattern->expression_list, this))
return false;
if (! matchToken(node->rparen_token, pattern->rparen_token))
return false;

View File

@@ -420,7 +420,7 @@ void MemInitializerAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(name, visitor);
accept(expression, visitor);
accept(expression_list, visitor);
}
visitor->endVisit(this);
}

View File

@@ -356,7 +356,9 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast)
bool CheckDeclaration::visit(MemInitializerAST *ast)
{
(void) semantic()->check(ast->name, _scope);
FullySpecifiedType ty = semantic()->check(ast->expression, _scope);
for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
FullySpecifiedType ty = semantic()->check(it->value, _scope);
}
return false;
}

View File

@@ -1849,7 +1849,7 @@ bool Parser::parseMemInitializer(MemInitializerListAST *&node)
MemInitializerAST *ast = new (_pool) MemInitializerAST;
ast->name = name;
ast->lparen_token = consumeToken();
parseExpression(ast->expression);
parseExpressionList(ast->expression_list);
if (LA() == T_RPAREN)
ast->rparen_token = consumeToken();
@@ -1896,7 +1896,7 @@ bool Parser::parseExpressionList(ExpressionListAST *&node)
while (LA() == T_COMMA) {
consumeToken(); // consume T_COMMA
if (parseExpression(expression)) {
if (parseAssignmentExpression(expression)) {
*expression_list_ptr = new (_pool) ExpressionListAST;
(*expression_list_ptr)->value = expression;
expression_list_ptr = &(*expression_list_ptr)->next;