summaryrefslogtreecommitdiff
path: root/src/shared/cplusplus
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/cplusplus')
-rw-r--r--src/shared/cplusplus/AST.cpp139
-rw-r--r--src/shared/cplusplus/AST.h13
-rw-r--r--src/shared/cplusplus/ASTVisit.cpp56
-rw-r--r--src/shared/cplusplus/CheckExpression.cpp2
-rw-r--r--src/shared/cplusplus/Parser.cpp2
5 files changed, 96 insertions, 116 deletions
diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp
index 825c7506b9..45292dcc4a 100644
--- a/src/shared/cplusplus/AST.cpp
+++ b/src/shared/cplusplus/AST.cpp
@@ -100,16 +100,13 @@ unsigned AttributeAST::lastToken() const
if (rparen_token)
return rparen_token + 1;
- for (ExpressionListAST *it = expression_list; it->value && it->next; it = it->next) {
- if (! it->next && it->value) {
- return it->value->lastToken();
- }
- }
+ else if (expression_list)
+ return expression_list->lastToken();
- if (tag_token)
+ else if (tag_token)
return tag_token + 1;
- if (lparen_token)
+ else if (lparen_token)
return lparen_token + 1;
return identifier_token + 1;
@@ -172,10 +169,8 @@ unsigned ArrayInitializerAST::lastToken() const
if (rbrace_token)
return rbrace_token + 1;
- for (ExpressionListAST *it = expression_list; it; it = it->next) {
- if (! it->next && it->value)
- return it->value->lastToken();
- }
+ else if (expression_list)
+ return expression_list->lastToken();
return lbrace_token + 1;
}
@@ -302,10 +297,10 @@ unsigned CallAST::lastToken() const
{
if (rparen_token)
return rparen_token + 1;
- for (ExpressionListAST *it = expression_list; it; it = it->next) {
- if (! it->next && it->value)
- return it->value->lastToken();
- }
+
+ else if (expression_list)
+ return expression_list->lastToken();
+
return lparen_token + 1;
}
@@ -374,12 +369,10 @@ unsigned ClassSpecifierAST::lastToken() const
if (rbrace_token)
return rbrace_token + 1;
- for (DeclarationListAST *it = member_specifiers; it; it = it->next) {
- if (! it->next)
- return it->lastToken();
- }
+ else if (member_specifiers)
+ return member_specifiers->lastToken();
- if (lbrace_token)
+ else if (lbrace_token)
return lbrace_token + 1;
else if (base_clause_list)
@@ -416,8 +409,8 @@ unsigned CompoundStatementAST::lastToken() const
unsigned ConditionAST::firstToken() const
{
- if (type_specifier)
- return type_specifier->firstToken();
+ if (type_specifiers)
+ return type_specifiers->firstToken();
return declarator->firstToken();
}
@@ -427,8 +420,8 @@ unsigned ConditionAST::lastToken() const
if (declarator)
return declarator->lastToken();
- else if (type_specifier)
- return type_specifier->lastToken();
+ else if (type_specifiers)
+ return type_specifiers->lastToken();
// ### assert?
return 0;
@@ -738,13 +731,12 @@ unsigned ExceptionSpecificationAST::lastToken() const
if (rparen_token)
return rparen_token + 1;
- for (ExpressionListAST *it = type_ids; it; it = it->next) {
- if (! it->next && it->value)
- return it->value->lastToken();
- }
+ else if (type_ids)
+ return type_ids->lastToken();
- if (dot_dot_dot_token)
+ else if (dot_dot_dot_token)
return dot_dot_dot_token + 1;
+
else if (lparen_token)
return lparen_token + 1;
@@ -942,10 +934,8 @@ unsigned LinkageBodyAST::lastToken() const
if (rbrace_token)
return rbrace_token + 1;
- for (DeclarationListAST *it = declarations; it; it = it->next) {
- if (! it->next)
- return it->lastToken();
- }
+ else if (declarations)
+ return declarations->lastToken();
return lbrace_token + 1;
}
@@ -1457,12 +1447,16 @@ unsigned SwitchStatementAST::lastToken() const
{
if (statement)
return statement->lastToken();
+
else if (rparen_token)
return rparen_token + 1;
+
else if (condition)
return condition->lastToken();
+
else if (lparen_token)
return lparen_token + 1;
+
return switch_token + 1;
}
@@ -1470,6 +1464,7 @@ unsigned TemplateDeclarationAST::firstToken() const
{
if (export_token)
return export_token;
+
return template_token;
}
@@ -1477,21 +1472,23 @@ unsigned TemplateDeclarationAST::lastToken() const
{
if (declaration)
return declaration->lastToken();
+
else if (greater_token)
return greater_token + 1;
- for (DeclarationListAST *it = template_parameters; it; it = it->next) {
- if (! it->next)
- return it->lastToken();
- }
+ else if (template_parameters)
+ return template_parameters->lastToken();
- if (less_token)
+ else if (less_token)
return less_token + 1;
+
else if (template_token)
return template_token + 1;
+
else if (export_token)
return export_token + 1;
+ // ### assert(0);
return 0;
}
@@ -1506,12 +1503,10 @@ unsigned TemplateIdAST::lastToken() const
if (greater_token)
return greater_token + 1;
- for (TemplateArgumentListAST *it = template_arguments; it; it = it->next) {
- if (! it->next && it->value)
- return it->value->lastToken();
- }
+ else if (template_arguments)
+ return template_arguments->lastToken();
- if (less_token)
+ else if (less_token)
return less_token + 1;
return identifier_token + 1;
@@ -1527,21 +1522,23 @@ unsigned TemplateTypeParameterAST::lastToken() const
{
if (type_id)
return type_id->lastToken();
+
else if (equal_token)
return equal_token + 1;
+
else if (name)
return name->lastToken();
+
else if (class_token)
return class_token + 1;
+
else if (greater_token)
return greater_token + 1;
- for (DeclarationListAST *it = template_parameters; it; it = it->next) {
- if (! it->next)
- return it->value->lastToken();
- }
+ else if (template_parameters)
+ return template_parameters->lastToken();
- if (less_token)
+ else if (less_token)
return less_token + 1;
return template_token + 1;
@@ -1571,7 +1568,6 @@ unsigned ThrowExpressionAST::lastToken() const
return throw_token + 1;
}
-
unsigned TranslationUnitAST::firstToken() const
{
return declarations->firstToken();
@@ -1579,14 +1575,13 @@ unsigned TranslationUnitAST::firstToken() const
unsigned TranslationUnitAST::lastToken() const
{
- for (DeclarationListAST *it = declarations; it; it = it->next) {
- if (! it->next)
- return it->lastToken();
- }
+ if (declarations)
+ return declarations->lastToken();
+
+ // ### assert(0);
return 0;
}
-
unsigned TryBlockStatementAST::firstToken() const
{
return try_token;
@@ -1674,13 +1669,12 @@ unsigned TypenameCallExpressionAST::lastToken() const
if (rparen_token)
return rparen_token + 1;
- for (ExpressionListAST *it = expression_list; it; it = it->next) {
- if (! it->next)
- return it->lastToken();
- }
+ else if (expression_list)
+ return expression_list->lastToken();
- if (lparen_token)
+ else if (lparen_token)
return lparen_token + 1;
+
else if (name)
return name->lastToken();
@@ -1761,12 +1755,16 @@ unsigned WhileStatementAST::lastToken() const
{
if (statement)
return statement->lastToken();
+
else if (rparen_token)
return rparen_token + 1;
+
else if (condition)
return condition->lastToken();
+
else if (lparen_token)
return lparen_token + 1;
+
return while_token + 1;
}
@@ -1775,6 +1773,7 @@ unsigned ObjCClassForwardDeclarationAST::firstToken() const
{
if (attributes)
return attributes->firstToken();
+
return class_token;
}
@@ -1783,10 +1782,8 @@ unsigned ObjCClassForwardDeclarationAST::lastToken() const
if (semicolon_token)
return semicolon_token + 1;
- for (ObjCIdentifierListAST *it = identifier_list; it; it = it->next) {
- if (! it->next && it->value)
- return it->value->lastToken();
- }
+ else if (identifier_list)
+ return identifier_list->lastToken();
return class_token + 1;
}
@@ -1795,6 +1792,7 @@ unsigned ObjCProtocolForwardDeclarationAST::firstToken() const
{
if (attributes)
return attributes->firstToken();
+
return protocol_token;
}
@@ -1803,10 +1801,8 @@ unsigned ObjCProtocolForwardDeclarationAST::lastToken() const
if (semicolon_token)
return semicolon_token + 1;
- for (ObjCIdentifierListAST *it = identifier_list; it; it = it->next) {
- if (! it->next && it->value)
- return it->value->lastToken();
- }
+ else if (identifier_list)
+ return identifier_list->lastToken();
return protocol_token + 1;
}
@@ -1880,12 +1876,11 @@ unsigned ObjCProtocolRefsAST::firstToken() const
unsigned ObjCProtocolRefsAST::lastToken() const
{
- if (greater_token) return greater_token + 1;
+ if (greater_token)
+ return greater_token + 1;
- for (ObjCIdentifierListAST *it = identifier_list; it; it = it->next) {
- if (! it->next && it->value)
- return it->value->lastToken();
- }
+ else if (identifier_list)
+ return identifier_list->lastToken();
return less_token + 1;
}
diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h
index c8cb6694af..46718574d6 100644
--- a/src/shared/cplusplus/AST.h
+++ b/src/shared/cplusplus/AST.h
@@ -81,15 +81,18 @@ public:
unsigned lastToken() const
{
- unsigned token = 0;
+ _Tp lastValue = 0;
for (const List *it = this; it; it = it->next) {
if (it->value)
- token = it->value->lastToken();
+ lastValue = it->value;
}
- // assert(token != 0);
- return token;
+ if (lastValue)
+ return lastValue->lastToken();
+
+ // ### assert(0);
+ return 0;
}
_Tp value;
@@ -616,7 +619,7 @@ protected:
class CPLUSPLUS_EXPORT ConditionAST: public ExpressionAST
{
public:
- SpecifierListAST *type_specifier;
+ SpecifierListAST *type_specifiers;
DeclaratorAST *declarator;
public:
diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp
index 4e4ee1ffca..c939a654f9 100644
--- a/src/shared/cplusplus/ASTVisit.cpp
+++ b/src/shared/cplusplus/ASTVisit.cpp
@@ -50,8 +50,7 @@ void AttributeSpecifierAST::accept0(ASTVisitor *visitor)
void AttributeAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (ExpressionListAST *it = expression_list; it; it = it->next)
- accept(it, visitor);
+ accept(expression_list, visitor);
}
visitor->endVisit(this);
}
@@ -173,8 +172,7 @@ void CaseStatementAST::accept0(ASTVisitor *visitor)
void CompoundStatementAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (StatementListAST *it = statements; it; it = it->next)
- accept(it, visitor);
+ accept(statements, visitor);
}
visitor->endVisit(this);
}
@@ -182,7 +180,7 @@ void CompoundStatementAST::accept0(ASTVisitor *visitor)
void ConditionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- accept(type_specifier, visitor);
+ accept(type_specifiers, visitor);
accept(declarator, visitor);
}
visitor->endVisit(this);
@@ -320,8 +318,7 @@ void ExceptionDeclarationAST::accept0(ASTVisitor *visitor)
void ExceptionSpecificationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (ExpressionListAST *it = type_ids; it; it = it->next)
- accept(it, visitor);
+ accept(type_ids, visitor);
}
visitor->endVisit(this);
}
@@ -390,8 +387,7 @@ void IfStatementAST::accept0(ASTVisitor *visitor)
void ArrayInitializerAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (ExpressionListAST *it = expression_list; it; it = it->next)
- accept(it, visitor);
+ accept(expression_list, visitor);
}
visitor->endVisit(this);
}
@@ -407,8 +403,7 @@ void LabeledStatementAST::accept0(ASTVisitor *visitor)
void LinkageBodyAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (DeclarationListAST *it = declarations; it; it = it->next)
- accept(it, visitor);
+ accept(declarations, visitor);
}
visitor->endVisit(this);
}
@@ -481,8 +476,7 @@ void DestructorNameAST::accept0(ASTVisitor *visitor)
void TemplateIdAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (TemplateArgumentListAST *it = template_arguments; it; it = it->next)
- accept(it, visitor);
+ accept(template_arguments, visitor);
}
visitor->endVisit(this);
}
@@ -507,8 +501,7 @@ void NamespaceAliasDefinitionAST::accept0(ASTVisitor *visitor)
void NewPlacementAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (ExpressionListAST *it = expression_list; it; it = it->next)
- accept(it, visitor);
+ accept(expression_list, visitor);
}
visitor->endVisit(this);
}
@@ -570,8 +563,7 @@ void ParameterDeclarationAST::accept0(ASTVisitor *visitor)
void ParameterDeclarationClauseAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (DeclarationListAST *it = parameter_declarations; it; it = it->next)
- accept(it, visitor);
+ accept(parameter_declarations, visitor);
}
visitor->endVisit(this);
}
@@ -579,8 +571,7 @@ void ParameterDeclarationClauseAST::accept0(ASTVisitor *visitor)
void CallAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (ExpressionListAST *it = expression_list; it; it = it->next)
- accept(it, visitor);
+ accept(expression_list, visitor);
}
visitor->endVisit(this);
}
@@ -620,8 +611,7 @@ void TypenameCallExpressionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(name, visitor);
- for (ExpressionListAST *it = expression_list; it; it = it->next)
- accept(it, visitor);
+ accept(expression_list, visitor);
}
visitor->endVisit(this);
}
@@ -753,8 +743,7 @@ void SwitchStatementAST::accept0(ASTVisitor *visitor)
void TemplateDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (DeclarationListAST *it = template_parameters; it; it = it->next)
- accept(it, visitor);
+ accept(template_parameters, visitor);
accept(declaration, visitor);
}
visitor->endVisit(this);
@@ -771,8 +760,7 @@ void ThrowExpressionAST::accept0(ASTVisitor *visitor)
void TranslationUnitAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (DeclarationListAST *it = declarations; it; it = it->next)
- accept(it, visitor);
+ accept(declarations, visitor);
}
visitor->endVisit(this);
}
@@ -816,8 +804,7 @@ void TypenameTypeParameterAST::accept0(ASTVisitor *visitor)
void TemplateTypeParameterAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (DeclarationListAST *it = template_parameters; it; it = it->next)
- accept(it, visitor);
+ accept(template_parameters, visitor);
accept(name, visitor);
accept(type_id, visitor);
}
@@ -921,8 +908,7 @@ void ObjCMessageExpressionAST::accept0(ASTVisitor *visitor)
if (visitor->visit(this)) {
accept(receiver_expression, visitor);
accept(selector, visitor);
- for (ObjCMessageArgumentListAST *it = argument_list; it; it = it->next)
- accept(it, visitor);
+ accept(argument_list, visitor);
}
visitor->endVisit(this);
}
@@ -967,8 +953,7 @@ void ObjCSelectorArgumentAST::accept0(ASTVisitor *visitor)
void ObjCSelectorWithArgumentsAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (ObjCSelectorArgumentListAST *it = selector_arguments; it; it = it->next)
- accept(it, visitor);
+ accept(selector_arguments, visitor);
}
visitor->endVisit(this);
}
@@ -984,8 +969,7 @@ void ObjCSelectorExpressionAST::accept0(ASTVisitor *visitor)
void ObjCInstanceVariablesDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (DeclarationListAST *it = instance_variables; it; it = it->next)
- accept(it, visitor);
+ accept(instance_variables, visitor);
}
visitor->endVisit(this);
}
@@ -1054,8 +1038,7 @@ void ObjCSynthesizedPropertyAST::accept0(ASTVisitor *visitor)
void ObjCSynthesizedPropertiesDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (ObjCSynthesizedPropertyListAST *it = property_identifiers; it; it = it->next)
- accept(it, visitor);
+ accept(property_identifiers, visitor);
}
visitor->endVisit(this);
}
@@ -1063,8 +1046,7 @@ void ObjCSynthesizedPropertiesDeclarationAST::accept0(ASTVisitor *visitor)
void ObjCDynamicPropertiesDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
- for (ObjCIdentifierListAST *it = property_identifiers; it; it = it->next)
- accept(it, visitor);
+ accept(property_identifiers, visitor);
}
visitor->endVisit(this);
}
diff --git a/src/shared/cplusplus/CheckExpression.cpp b/src/shared/cplusplus/CheckExpression.cpp
index 25de7e62c6..0e6fb0dfd6 100644
--- a/src/shared/cplusplus/CheckExpression.cpp
+++ b/src/shared/cplusplus/CheckExpression.cpp
@@ -119,7 +119,7 @@ bool CheckExpression::visit(CastExpressionAST *ast)
bool CheckExpression::visit(ConditionAST *ast)
{
- FullySpecifiedType typeSpecTy = semantic()->check(ast->type_specifier, _scope);
+ FullySpecifiedType typeSpecTy = semantic()->check(ast->type_specifiers, _scope);
Name *name = 0;
FullySpecifiedType declTy = semantic()->check(ast->declarator, typeSpecTy.qualifiedType(),
_scope, &name);
diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp
index 5af2ae9a1c..7052567d0d 100644
--- a/src/shared/cplusplus/Parser.cpp
+++ b/src/shared/cplusplus/Parser.cpp
@@ -2274,7 +2274,7 @@ bool Parser::parseCondition(ExpressionAST *&node)
if (parseInitDeclarator(declarator, /*acceptStructDeclarator=*/false)) {
if (declarator->initializer) {
ConditionAST *ast = new (_pool) ConditionAST;
- ast->type_specifier = type_specifier;
+ ast->type_specifiers = type_specifier;
ast->declarator = declarator;
node = ast;
blockErrors(blocked);