forked from qt-creator/qt-creator
Cleanup Postfix operators.
This commit is contained in:
@@ -208,8 +208,8 @@ bool ResolveExpression::visit(PostfixExpressionAST *ast)
|
|||||||
{
|
{
|
||||||
accept(ast->base_expression);
|
accept(ast->base_expression);
|
||||||
|
|
||||||
for (PostfixAST *fx = ast->postfix_expressions; fx; fx = fx->next) {
|
for (PostfixListAST *it = ast->postfix_expressions; it; it = it->next) {
|
||||||
accept(fx);
|
accept(it->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@@ -318,10 +318,11 @@ protected:
|
|||||||
virtual bool visit(PostfixExpressionAST *ast)
|
virtual bool visit(PostfixExpressionAST *ast)
|
||||||
{
|
{
|
||||||
accept(ast->base_expression);
|
accept(ast->base_expression);
|
||||||
for (PostfixAST *it = ast->postfix_expressions; it; it = it->next) {
|
for (PostfixListAST *it = ast->postfix_expressions; it; it = it->next) {
|
||||||
if (it->asMemberAccess() != 0)
|
PostfixAST *fx = it->value;
|
||||||
|
if (fx->asMemberAccess() != 0)
|
||||||
continue; // skip members
|
continue; // skip members
|
||||||
accept(it);
|
accept(fx);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -1331,10 +1331,8 @@ unsigned PostfixExpressionAST::firstToken() const
|
|||||||
|
|
||||||
unsigned PostfixExpressionAST::lastToken() const
|
unsigned PostfixExpressionAST::lastToken() const
|
||||||
{
|
{
|
||||||
for (PostfixAST *it = postfix_expressions; it; it = it->next) {
|
if (postfix_expressions)
|
||||||
if (! it->next)
|
return postfix_expressions->lastToken();
|
||||||
return it->lastToken();
|
|
||||||
}
|
|
||||||
return base_expression->lastToken();
|
return base_expression->lastToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -66,6 +66,10 @@ public:
|
|||||||
: value(_Tp()), next(0)
|
: value(_Tp()), next(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
List(const _Tp &value)
|
||||||
|
: value(value), next(0)
|
||||||
|
{ }
|
||||||
|
|
||||||
unsigned firstToken() const
|
unsigned firstToken() const
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
@@ -1459,12 +1463,8 @@ protected:
|
|||||||
|
|
||||||
class CPLUSPLUS_EXPORT PostfixAST: public AST
|
class CPLUSPLUS_EXPORT PostfixAST: public AST
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
PostfixAST *next;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual PostfixAST *asPostfix() { return this; }
|
virtual PostfixAST *asPostfix() { return this; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT CallAST: public PostfixAST
|
class CPLUSPLUS_EXPORT CallAST: public PostfixAST
|
||||||
@@ -1592,7 +1592,7 @@ class CPLUSPLUS_EXPORT PostfixExpressionAST: public ExpressionAST
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ExpressionAST *base_expression;
|
ExpressionAST *base_expression;
|
||||||
PostfixAST *postfix_expressions;
|
PostfixListAST *postfix_expressions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual PostfixExpressionAST *asPostfixExpression() { return this; }
|
virtual PostfixExpressionAST *asPostfixExpression() { return this; }
|
||||||
|
@@ -662,8 +662,7 @@ void PostfixExpressionAST::accept0(ASTVisitor *visitor)
|
|||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(base_expression, visitor);
|
accept(base_expression, visitor);
|
||||||
for (PostfixAST *it = postfix_expressions; it; it = it->next)
|
accept(postfix_expressions, visitor);
|
||||||
accept(it, visitor);
|
|
||||||
}
|
}
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
}
|
}
|
||||||
|
@@ -199,6 +199,7 @@ typedef List<BaseSpecifierAST *> BaseSpecifierListAST;
|
|||||||
typedef List<EnumeratorAST *> EnumeratorListAST;
|
typedef List<EnumeratorAST *> EnumeratorListAST;
|
||||||
typedef List<MemInitializerAST *> MemInitializerListAST;
|
typedef List<MemInitializerAST *> MemInitializerListAST;
|
||||||
typedef List<NewArrayDeclaratorAST *> NewArrayDeclaratorListAST;
|
typedef List<NewArrayDeclaratorAST *> NewArrayDeclaratorListAST;
|
||||||
|
typedef List<PostfixAST *> PostfixListAST;
|
||||||
|
|
||||||
typedef List<NameAST *> ObjCIdentifierListAST;
|
typedef List<NameAST *> ObjCIdentifierListAST;
|
||||||
typedef List<ObjCMessageArgumentAST *> ObjCMessageArgumentListAST;
|
typedef List<ObjCMessageArgumentAST *> ObjCMessageArgumentListAST;
|
||||||
|
@@ -251,8 +251,8 @@ bool CheckExpression::visit(TypeConstructorCallAST *ast)
|
|||||||
bool CheckExpression::visit(PostfixExpressionAST *ast)
|
bool CheckExpression::visit(PostfixExpressionAST *ast)
|
||||||
{
|
{
|
||||||
FullySpecifiedType exprTy = semantic()->check(ast->base_expression, _scope);
|
FullySpecifiedType exprTy = semantic()->check(ast->base_expression, _scope);
|
||||||
for (PostfixAST *fx = ast->postfix_expressions; fx; fx = fx->next) {
|
for (PostfixListAST *it = ast->postfix_expressions; it; it = it->next) {
|
||||||
accept(fx); // ### not exactly.
|
accept(it->value); // ### not exactly.
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -3599,7 +3599,7 @@ bool Parser::parsePostfixExpression(ExpressionAST *&node)
|
|||||||
{
|
{
|
||||||
DEBUG_THIS_RULE();
|
DEBUG_THIS_RULE();
|
||||||
if (parseCorePostfixExpression(node)) {
|
if (parseCorePostfixExpression(node)) {
|
||||||
PostfixAST *postfix_expressions = 0,
|
PostfixListAST *postfix_expressions = 0,
|
||||||
**postfix_ptr = &postfix_expressions;
|
**postfix_ptr = &postfix_expressions;
|
||||||
while (LA()) {
|
while (LA()) {
|
||||||
if (LA() == T_LPAREN) {
|
if (LA() == T_LPAREN) {
|
||||||
@@ -3607,19 +3607,19 @@ bool Parser::parsePostfixExpression(ExpressionAST *&node)
|
|||||||
ast->lparen_token = consumeToken();
|
ast->lparen_token = consumeToken();
|
||||||
parseExpressionList(ast->expression_list);
|
parseExpressionList(ast->expression_list);
|
||||||
match(T_RPAREN, &ast->rparen_token);
|
match(T_RPAREN, &ast->rparen_token);
|
||||||
*postfix_ptr = ast;
|
*postfix_ptr = new (_pool) PostfixListAST(ast);
|
||||||
postfix_ptr = &(*postfix_ptr)->next;
|
postfix_ptr = &(*postfix_ptr)->next;
|
||||||
} else if (LA() == T_LBRACKET) {
|
} else if (LA() == T_LBRACKET) {
|
||||||
ArrayAccessAST *ast = new (_pool) ArrayAccessAST;
|
ArrayAccessAST *ast = new (_pool) ArrayAccessAST;
|
||||||
ast->lbracket_token = consumeToken();
|
ast->lbracket_token = consumeToken();
|
||||||
parseExpression(ast->expression);
|
parseExpression(ast->expression);
|
||||||
match(T_RBRACKET, &ast->rbracket_token);
|
match(T_RBRACKET, &ast->rbracket_token);
|
||||||
*postfix_ptr = ast;
|
*postfix_ptr = new (_pool) PostfixListAST(ast);
|
||||||
postfix_ptr = &(*postfix_ptr)->next;
|
postfix_ptr = &(*postfix_ptr)->next;
|
||||||
} else if (LA() == T_PLUS_PLUS || LA() == T_MINUS_MINUS) {
|
} else if (LA() == T_PLUS_PLUS || LA() == T_MINUS_MINUS) {
|
||||||
PostIncrDecrAST *ast = new (_pool) PostIncrDecrAST;
|
PostIncrDecrAST *ast = new (_pool) PostIncrDecrAST;
|
||||||
ast->incr_decr_token = consumeToken();
|
ast->incr_decr_token = consumeToken();
|
||||||
*postfix_ptr = ast;
|
*postfix_ptr = new (_pool) PostfixListAST(ast);
|
||||||
postfix_ptr = &(*postfix_ptr)->next;
|
postfix_ptr = &(*postfix_ptr)->next;
|
||||||
} else if (LA() == T_DOT || LA() == T_ARROW) {
|
} else if (LA() == T_DOT || LA() == T_ARROW) {
|
||||||
MemberAccessAST *ast = new (_pool) MemberAccessAST;
|
MemberAccessAST *ast = new (_pool) MemberAccessAST;
|
||||||
@@ -3629,7 +3629,7 @@ bool Parser::parsePostfixExpression(ExpressionAST *&node)
|
|||||||
if (! parseNameId(ast->member_name))
|
if (! parseNameId(ast->member_name))
|
||||||
_translationUnit->error(cursor(), "expected unqualified-id before token `%s'",
|
_translationUnit->error(cursor(), "expected unqualified-id before token `%s'",
|
||||||
tok().spell());
|
tok().spell());
|
||||||
*postfix_ptr = ast;
|
*postfix_ptr = new (_pool) PostfixListAST(ast);
|
||||||
postfix_ptr = &(*postfix_ptr)->next;
|
postfix_ptr = &(*postfix_ptr)->next;
|
||||||
} else break;
|
} else break;
|
||||||
} // while
|
} // while
|
||||||
|
@@ -574,7 +574,7 @@ void tst_AST::normal_array_access()
|
|||||||
|
|
||||||
{
|
{
|
||||||
QVERIFY(postfixExpr->postfix_expressions && !postfixExpr->postfix_expressions->next);
|
QVERIFY(postfixExpr->postfix_expressions && !postfixExpr->postfix_expressions->next);
|
||||||
ArrayAccessAST *rhs = postfixExpr->postfix_expressions->asArrayAccess();
|
ArrayAccessAST *rhs = postfixExpr->postfix_expressions->value->asArrayAccess();
|
||||||
QVERIFY(rhs && rhs->expression);
|
QVERIFY(rhs && rhs->expression);
|
||||||
SimpleNameAST *b = rhs->expression->asSimpleName();
|
SimpleNameAST *b = rhs->expression->asSimpleName();
|
||||||
QVERIFY(b);
|
QVERIFY(b);
|
||||||
@@ -620,7 +620,7 @@ void tst_AST::array_access_with_nested_expression()
|
|||||||
|
|
||||||
{
|
{
|
||||||
QVERIFY(postfixExpr->postfix_expressions && !postfixExpr->postfix_expressions->next);
|
QVERIFY(postfixExpr->postfix_expressions && !postfixExpr->postfix_expressions->next);
|
||||||
ArrayAccessAST *rhs = postfixExpr->postfix_expressions->asArrayAccess();
|
ArrayAccessAST *rhs = postfixExpr->postfix_expressions->value->asArrayAccess();
|
||||||
QVERIFY(rhs && rhs->expression);
|
QVERIFY(rhs && rhs->expression);
|
||||||
SimpleNameAST *b = rhs->expression->asSimpleName();
|
SimpleNameAST *b = rhs->expression->asSimpleName();
|
||||||
QVERIFY(b);
|
QVERIFY(b);
|
||||||
|
Reference in New Issue
Block a user