summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-11-10 15:30:16 +0100
committerRoberto Raggi <roberto.raggi@nokia.com>2009-11-10 16:20:13 +0100
commit4fc2ccf0c5af6d93b1edca95518043b84e342c67 (patch)
treecc2010cdaa07a3cdbf619de19edc8e9646339605
parent1fb33e9fad0d65fb2259fb603f61bc255f19b70f (diff)
downloadqt-creator-4fc2ccf0c5af6d93b1edca95518043b84e342c67.tar.gz
Cleanup ptr operators.
-rw-r--r--src/libs/cplusplus/FindUsages.cpp5
-rw-r--r--src/shared/cplusplus/AST.cpp20
-rw-r--r--src/shared/cplusplus/AST.h10
-rw-r--r--src/shared/cplusplus/ASTVisit.cpp9
-rw-r--r--src/shared/cplusplus/ASTfwd.h1
-rw-r--r--src/shared/cplusplus/CheckDeclarator.cpp14
-rw-r--r--src/shared/cplusplus/CheckDeclarator.h14
-rw-r--r--src/shared/cplusplus/Parser.cpp20
-rw-r--r--src/shared/cplusplus/Parser.h2
-rw-r--r--src/shared/cplusplus/Semantic.cpp2
-rw-r--r--src/shared/cplusplus/Semantic.h2
-rw-r--r--tests/auto/cplusplus/ast/tst_ast.cpp4
12 files changed, 49 insertions, 54 deletions
diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp
index 5d7f34132a..659d25b25a 100644
--- a/src/libs/cplusplus/FindUsages.cpp
+++ b/src/libs/cplusplus/FindUsages.cpp
@@ -409,8 +409,9 @@ bool FindUsages::visit(ParameterDeclarationAST *ast)
for (SpecifierAST *attr = declarator->attributes; attr; attr = attr->next)
accept(attr);
- for (PtrOperatorAST *ptr_op = declarator->ptr_operators; ptr_op; ptr_op = ptr_op->next)
- accept(ptr_op);
+ for (PtrOperatorListAST *it = declarator->ptr_operators; it; it = it->next) {
+ accept(it->value);
+ }
if (! _inSimpleDeclaration) // visit the core declarator only if we are not in simple-declaration.
accept(declarator->core_declarator);
diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp
index 03531c481a..8785ad6f09 100644
--- a/src/shared/cplusplus/AST.cpp
+++ b/src/shared/cplusplus/AST.cpp
@@ -483,10 +483,8 @@ unsigned ConversionFunctionIdAST::firstToken() const
unsigned ConversionFunctionIdAST::lastToken() const
{
- for (PtrOperatorAST *it = ptr_operators; it; it = it->next) {
- if (! it->next)
- return it->lastToken();
- }
+ if (ptr_operators)
+ return ptr_operators->lastToken();
for (SpecifierAST *it = type_specifier; it; it = it->next) {
if (! it->next)
@@ -566,10 +564,8 @@ unsigned DeclaratorAST::lastToken() const
if (core_declarator)
return core_declarator->lastToken();
- for (PtrOperatorAST *it = ptr_operators; it; it = it->next) {
- if (! it->next)
- return it->lastToken();
- }
+ if (ptr_operators)
+ return ptr_operators->lastToken();
for (SpecifierAST *it = attributes; it; it = it->next) {
if (! it->next)
@@ -1176,12 +1172,10 @@ unsigned NewTypeIdAST::lastToken() const
if (new_array_declarators)
return new_array_declarators->lastToken();
- for (PtrOperatorAST *it = ptr_operators; it; it = it->next) {
- if (it->next)
- return it->lastToken();
- }
+ else if (ptr_operators)
+ return ptr_operators->lastToken();
- if (type_specifier)
+ else if (type_specifier)
return type_specifier->lastToken();
// ### assert?
diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h
index 2e858bd5f5..e4a61e332b 100644
--- a/src/shared/cplusplus/AST.h
+++ b/src/shared/cplusplus/AST.h
@@ -371,7 +371,7 @@ class CPLUSPLUS_EXPORT DeclaratorAST: public AST
{
public:
SpecifierAST *attributes;
- PtrOperatorAST *ptr_operators;
+ PtrOperatorListAST *ptr_operators;
CoreDeclaratorAST *core_declarator;
PostfixDeclaratorListAST *postfix_declarators;
SpecifierAST *post_attributes;
@@ -1198,7 +1198,7 @@ class CPLUSPLUS_EXPORT ConversionFunctionIdAST: public NameAST
public:
unsigned operator_token;
SpecifierAST *type_specifier;
- PtrOperatorAST *ptr_operators;
+ PtrOperatorListAST *ptr_operators;
public:
virtual ConversionFunctionIdAST *asConversionFunctionId() { return this; }
@@ -1379,7 +1379,7 @@ class CPLUSPLUS_EXPORT NewTypeIdAST: public AST
{
public:
SpecifierAST *type_specifier;
- PtrOperatorAST *ptr_operators;
+ PtrOperatorListAST *ptr_operators;
NewArrayDeclaratorListAST *new_array_declarators;
public:
@@ -1592,11 +1592,7 @@ protected:
class CPLUSPLUS_EXPORT PtrOperatorAST: public AST
{
public:
- PtrOperatorAST *next;
-
-public:
virtual PtrOperatorAST *asPtrOperator() { return this; }
-
};
class CPLUSPLUS_EXPORT PointerToMemberAST: public PtrOperatorAST
diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp
index 7469388d4c..f6d1d9184f 100644
--- a/src/shared/cplusplus/ASTVisit.cpp
+++ b/src/shared/cplusplus/ASTVisit.cpp
@@ -69,8 +69,7 @@ void DeclaratorAST::accept0(ASTVisitor *visitor)
if (visitor->visit(this)) {
for (SpecifierAST *it = attributes; it; it = it->next)
accept(it, visitor);
- for (PtrOperatorAST *it = ptr_operators; it; it = it->next)
- accept(it, visitor);
+ accept(ptr_operators, visitor);
accept(core_declarator, visitor);
accept(postfix_declarators, visitor);
for (SpecifierAST *it = post_attributes; it; it = it->next)
@@ -472,8 +471,7 @@ void ConversionFunctionIdAST::accept0(ASTVisitor *visitor)
if (visitor->visit(this)) {
for (SpecifierAST *it = type_specifier; it; it = it->next)
accept(it, visitor);
- for (PtrOperatorAST *it = ptr_operators; it; it = it->next)
- accept(it, visitor);
+ accept(ptr_operators, visitor);
}
visitor->endVisit(this);
}
@@ -560,8 +558,7 @@ void NewTypeIdAST::accept0(ASTVisitor *visitor)
if (visitor->visit(this)) {
for (SpecifierAST *it = type_specifier; it; it = it->next)
accept(it, visitor);
- for (PtrOperatorAST *it = ptr_operators; it; it = it->next)
- accept(it, visitor);
+ accept(ptr_operators, visitor);
accept(new_array_declarators, visitor);
}
visitor->endVisit(this);
diff --git a/src/shared/cplusplus/ASTfwd.h b/src/shared/cplusplus/ASTfwd.h
index 4c04800c18..483708356b 100644
--- a/src/shared/cplusplus/ASTfwd.h
+++ b/src/shared/cplusplus/ASTfwd.h
@@ -204,6 +204,7 @@ typedef List<PostfixDeclaratorAST *> PostfixDeclaratorListAST;
typedef List<AttributeAST *> AttributeListAST;
typedef List<NestedNameSpecifierAST *> NestedNameSpecifierListAST;
typedef List<CatchClauseAST *> CatchClauseListAST;
+typedef List<PtrOperatorAST *> PtrOperatorListAST;
typedef List<NameAST *> ObjCIdentifierListAST;
typedef List<ObjCMessageArgumentAST *> ObjCMessageArgumentListAST;
diff --git a/src/shared/cplusplus/CheckDeclarator.cpp b/src/shared/cplusplus/CheckDeclarator.cpp
index be1319d5c8..0874c1bfa1 100644
--- a/src/shared/cplusplus/CheckDeclarator.cpp
+++ b/src/shared/cplusplus/CheckDeclarator.cpp
@@ -68,9 +68,9 @@ CheckDeclarator::~CheckDeclarator()
{ }
FullySpecifiedType CheckDeclarator::check(DeclaratorAST *declarator,
- FullySpecifiedType type,
- Scope *scope,
- Name **name)
+ const FullySpecifiedType &type,
+ Scope *scope,
+ Name **name)
{
FullySpecifiedType previousType = switchFullySpecifiedType(type);
Scope *previousScope = switchScope(scope);
@@ -83,9 +83,9 @@ FullySpecifiedType CheckDeclarator::check(DeclaratorAST *declarator,
return switchFullySpecifiedType(previousType);
}
-FullySpecifiedType CheckDeclarator::check(PtrOperatorAST *ptrOperators,
- FullySpecifiedType type,
- Scope *scope)
+FullySpecifiedType CheckDeclarator::check(PtrOperatorListAST *ptrOperators,
+ const FullySpecifiedType &type,
+ Scope *scope)
{
FullySpecifiedType previousType = switchFullySpecifiedType(type);
Scope *previousScope = switchScope(scope);
@@ -110,7 +110,7 @@ DeclaratorAST *CheckDeclarator::switchDeclarator(DeclaratorAST *declarator)
return previousDeclarator;
}
-FullySpecifiedType CheckDeclarator::switchFullySpecifiedType(FullySpecifiedType type)
+FullySpecifiedType CheckDeclarator::switchFullySpecifiedType(const FullySpecifiedType &type)
{
FullySpecifiedType previousType = _fullySpecifiedType;
_fullySpecifiedType = type;
diff --git a/src/shared/cplusplus/CheckDeclarator.h b/src/shared/cplusplus/CheckDeclarator.h
index b676abfacd..c24d4a5c38 100644
--- a/src/shared/cplusplus/CheckDeclarator.h
+++ b/src/shared/cplusplus/CheckDeclarator.h
@@ -63,20 +63,20 @@ public:
virtual ~CheckDeclarator();
FullySpecifiedType check(DeclaratorAST *declarator,
- FullySpecifiedType type,
- Scope *scope,
- Name **name);
+ const FullySpecifiedType &type,
+ Scope *scope,
+ Name **name);
- FullySpecifiedType check(PtrOperatorAST *ptrOperators,
- FullySpecifiedType type,
- Scope *scope);
+ FullySpecifiedType check(PtrOperatorListAST *ptrOperators,
+ const FullySpecifiedType &type,
+ Scope *scope);
FullySpecifiedType check(ObjCMethodPrototypeAST *methodPrototype,
Scope *scope);
protected:
DeclaratorAST *switchDeclarator(DeclaratorAST *declarator);
- FullySpecifiedType switchFullySpecifiedType(FullySpecifiedType type);
+ FullySpecifiedType switchFullySpecifiedType(const FullySpecifiedType &type);
Scope *switchScope(Scope *scope);
Name **switchName(Name **name);
diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp
index 394074e594..27de8b6c6a 100644
--- a/src/shared/cplusplus/Parser.cpp
+++ b/src/shared/cplusplus/Parser.cpp
@@ -661,7 +661,7 @@ bool Parser::parseConversionFunctionId(NameAST *&node)
if (! parseTypeSpecifier(type_specifier)) {
return false;
}
- PtrOperatorAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators;
+ PtrOperatorListAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators;
while (parsePtrOperator(*ptr_operators_tail))
ptr_operators_tail = &(*ptr_operators_tail)->next;
@@ -956,19 +956,19 @@ bool Parser::parseCvQualifiers(SpecifierAST *&node)
return start != cursor();
}
-bool Parser::parsePtrOperator(PtrOperatorAST *&node)
+bool Parser::parsePtrOperator(PtrOperatorListAST *&node)
{
DEBUG_THIS_RULE();
if (LA() == T_AMPER) {
ReferenceAST *ast = new (_pool) ReferenceAST;
ast->amp_token = consumeToken();
- node = ast;
+ node = new (_pool) PtrOperatorListAST(ast);
return true;
} else if (LA() == T_STAR) {
PointerAST *ast = new (_pool) PointerAST;
ast->star_token = consumeToken();
parseCvQualifiers(ast->cv_qualifier_seq);
- node = ast;
+ node = new (_pool) PtrOperatorListAST(ast);
return true;
} else if (LA() == T_COLON_COLON || LA() == T_IDENTIFIER) {
unsigned scope_or_identifier_token = cursor();
@@ -985,7 +985,7 @@ bool Parser::parsePtrOperator(PtrOperatorAST *&node)
ast->nested_name_specifier = nested_name_specifiers;
ast->star_token = consumeToken();
parseCvQualifiers(ast->cv_qualifier_seq);
- node = ast;
+ node = new (_pool) PtrOperatorListAST(ast);
return true;
}
rewind(scope_or_identifier_token);
@@ -1082,7 +1082,7 @@ bool Parser::parseCoreDeclarator(DeclaratorAST *&node)
attribute_ptr = &(*attribute_ptr)->next;
}
- PtrOperatorAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators;
+ PtrOperatorListAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators;
while (parsePtrOperator(*ptr_operators_tail))
ptr_operators_tail = &(*ptr_operators_tail)->next;
@@ -1219,7 +1219,8 @@ bool Parser::parseDeclarator(DeclaratorAST *&node, bool stopAtCppInitializer)
bool Parser::parseAbstractCoreDeclarator(DeclaratorAST *&node)
{
DEBUG_THIS_RULE();
- PtrOperatorAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators;
+
+ PtrOperatorListAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators;
while (parsePtrOperator(*ptr_operators_tail))
ptr_operators_tail = &(*ptr_operators_tail)->next;
@@ -3799,12 +3800,15 @@ bool Parser::parseNewTypeId(NewTypeIdAST *&node)
NewTypeIdAST *ast = new (_pool) NewTypeIdAST;
ast->type_specifier = typeSpec;
- PtrOperatorAST **ptrop_it = &ast->ptr_operators;
+
+ PtrOperatorListAST **ptrop_it = &ast->ptr_operators;
while (parsePtrOperator(*ptrop_it))
ptrop_it = &(*ptrop_it)->next;
+
NewArrayDeclaratorListAST **it = &ast->new_array_declarators;
while (parseNewArrayDeclarator(*it))
it = &(*it)->next;
+
node = ast;
return true;
}
diff --git a/src/shared/cplusplus/Parser.h b/src/shared/cplusplus/Parser.h
index 15f768b3cf..6ac28e58a7 100644
--- a/src/shared/cplusplus/Parser.h
+++ b/src/shared/cplusplus/Parser.h
@@ -165,7 +165,7 @@ public:
bool parsePostfixExpressionInternal(ExpressionAST *&node);
bool parsePrimaryExpression(ExpressionAST *&node);
bool parseNestedExpression(ExpressionAST *&node);
- bool parsePtrOperator(PtrOperatorAST *&node);
+ bool parsePtrOperator(PtrOperatorListAST *&node);
bool parseRelationalExpression(ExpressionAST *&node);
bool parseShiftExpression(ExpressionAST *&node);
bool parseStatement(StatementAST *&node);
diff --git a/src/shared/cplusplus/Semantic.cpp b/src/shared/cplusplus/Semantic.cpp
index c2dfa42ff7..8c01a3ee80 100644
--- a/src/shared/cplusplus/Semantic.cpp
+++ b/src/shared/cplusplus/Semantic.cpp
@@ -130,7 +130,7 @@ FullySpecifiedType Semantic::check(DeclaratorAST *declarator, FullySpecifiedType
Scope *scope, Name **name)
{ return d->checkDeclarator->check(declarator, type, scope, name); }
-FullySpecifiedType Semantic::check(PtrOperatorAST *ptrOperators, FullySpecifiedType type,
+FullySpecifiedType Semantic::check(PtrOperatorListAST *ptrOperators, FullySpecifiedType type,
Scope *scope)
{ return d->checkDeclarator->check(ptrOperators, type, scope); }
diff --git a/src/shared/cplusplus/Semantic.h b/src/shared/cplusplus/Semantic.h
index b42b13efed..3e2d8c4bac 100644
--- a/src/shared/cplusplus/Semantic.h
+++ b/src/shared/cplusplus/Semantic.h
@@ -71,7 +71,7 @@ public:
FullySpecifiedType check(DeclaratorAST *declarator, FullySpecifiedType type,
Scope *scope, Name **name = 0); // ### ugly
- FullySpecifiedType check(PtrOperatorAST *ptrOperators, FullySpecifiedType type,
+ FullySpecifiedType check(PtrOperatorListAST *ptrOperators, FullySpecifiedType type,
Scope *scope);
FullySpecifiedType check(ObjCMethodPrototypeAST *methodPrototype, Scope *scope);
diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp
index 9dc3d872a7..e2fe27e8e5 100644
--- a/tests/auto/cplusplus/ast/tst_ast.cpp
+++ b/tests/auto/cplusplus/ast/tst_ast.cpp
@@ -668,7 +668,9 @@ void tst_AST::objc_msg_send_expression()
QVERIFY(declarator);
QVERIFY(!declarator->attributes);
- QVERIFY(declarator->ptr_operators && !declarator->ptr_operators->next && declarator->ptr_operators->asPointer() && !declarator->ptr_operators->asPointer()->cv_qualifier_seq);
+ QVERIFY(declarator->ptr_operators && !declarator->ptr_operators->next
+ && declarator->ptr_operators->value->asPointer()
+ && ! declarator->ptr_operators->value->asPointer()->cv_qualifier_seq);
QVERIFY(declarator->core_declarator && declarator->core_declarator->asDeclaratorId());
NameAST *objNameId = declarator->core_declarator->asDeclaratorId()->name;