summaryrefslogtreecommitdiff
path: root/src/shared/cplusplus
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-07-20 12:54:49 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2010-07-20 12:55:08 +0200
commit893e647306ab121567553d5fe1adbbdae041aed7 (patch)
treecfb2911183e5f167a1859954090c911b99d4ebdf /src/shared/cplusplus
parenta97bede3416d1feaa2d9f07dd4d4ca1ba85cbdb7 (diff)
downloadqt-creator-893e647306ab121567553d5fe1adbbdae041aed7.tar.gz
Use the location of the unqualified name id.
Diffstat (limited to 'src/shared/cplusplus')
-rw-r--r--src/shared/cplusplus/CheckDeclaration.cpp26
-rw-r--r--src/shared/cplusplus/CheckDeclaration.h2
-rw-r--r--src/shared/cplusplus/Semantic.cpp34
-rw-r--r--src/shared/cplusplus/Semantic.h4
4 files changed, 47 insertions, 19 deletions
diff --git a/src/shared/cplusplus/CheckDeclaration.cpp b/src/shared/cplusplus/CheckDeclaration.cpp
index d0e5600523..98e8616f70 100644
--- a/src/shared/cplusplus/CheckDeclaration.cpp
+++ b/src/shared/cplusplus/CheckDeclaration.cpp
@@ -131,18 +131,6 @@ void CheckDeclaration::checkFunctionArguments(Function *fun)
}
}
-unsigned CheckDeclaration::locationOfDeclaratorId(DeclaratorAST *declarator) const
-{
- if (declarator && declarator->core_declarator) {
- if (DeclaratorIdAST *declaratorId = declarator->core_declarator->asDeclaratorId())
- return declaratorId->firstToken();
- else if (NestedDeclaratorAST *nested = declarator->core_declarator->asNestedDeclarator())
- return locationOfDeclaratorId(nested->declarator);
- }
-
- return 0;
-}
-
bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
{
FullySpecifiedType ty = semantic()->check(ast->decl_specifier_list, _scope);
@@ -198,7 +186,7 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
FullySpecifiedType declTy = semantic()->check(it->value, qualTy,
_scope, &name);
- unsigned location = locationOfDeclaratorId(it->value);
+ unsigned location = semantic()->location(it->value);
if (! location) {
if (it->value)
location = it->value->firstToken();
@@ -310,7 +298,7 @@ bool CheckDeclaration::visit(ExceptionDeclarationAST *ast)
FullySpecifiedType declTy = semantic()->check(ast->declarator, qualTy,
_scope, &name);
- unsigned location = locationOfDeclaratorId(ast->declarator);
+ unsigned location = semantic()->location(ast->declarator);
if (! location) {
if (ast->declarator)
location = ast->declarator->firstToken();
@@ -351,8 +339,12 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast)
fun->setUnavailable(true);
fun->members()->setStartOffset(funStartOffset);
fun->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end());
- if (ast->declarator)
- fun->setSourceLocation(ast->declarator->firstToken(), translationUnit());
+ if (ast->declarator) {
+ unsigned loc = semantic()->location(ast->declarator);
+ if (! loc)
+ loc = ast->declarator->firstToken();
+ fun->setSourceLocation(loc, translationUnit());
+ }
fun->setName(name);
fun->setTemplateParameters(_templateParameters);
fun->setVisibility(semantic()->currentVisibility());
@@ -450,7 +442,7 @@ bool CheckDeclaration::visit(NamespaceAliasDefinitionAST *ast)
bool CheckDeclaration::visit(ParameterDeclarationAST *ast)
{
- unsigned sourceLocation = locationOfDeclaratorId(ast->declarator);
+ unsigned sourceLocation = semantic()->location(ast->declarator);
if (! sourceLocation) {
if (ast->declarator)
sourceLocation = ast->declarator->firstToken();
diff --git a/src/shared/cplusplus/CheckDeclaration.h b/src/shared/cplusplus/CheckDeclaration.h
index acd71c557b..90690d2720 100644
--- a/src/shared/cplusplus/CheckDeclaration.h
+++ b/src/shared/cplusplus/CheckDeclaration.h
@@ -73,8 +73,6 @@ protected:
using ASTVisitor::visit;
- unsigned locationOfDeclaratorId(DeclaratorAST *declarator) const;
-
virtual bool visit(SimpleDeclarationAST *ast);
virtual bool visit(EmptyDeclarationAST *ast);
virtual bool visit(AccessDeclarationAST *ast);
diff --git a/src/shared/cplusplus/Semantic.cpp b/src/shared/cplusplus/Semantic.cpp
index be08ebdf7a..019852cc78 100644
--- a/src/shared/cplusplus/Semantic.cpp
+++ b/src/shared/cplusplus/Semantic.cpp
@@ -316,4 +316,38 @@ int Semantic::visibilityForClassKey(int tokenKind) const
}
}
+unsigned Semantic::location(DeclaratorAST *ast) const
+{
+ if (! ast)
+ return 0;
+
+ else if (CPlusPlus::CoreDeclaratorAST *core = ast->core_declarator)
+ return location(core);
+
+ return ast->firstToken();
+}
+
+unsigned Semantic::location(CoreDeclaratorAST *ast) const
+{
+ if (! ast)
+ return 0;
+
+ else if (CPlusPlus::DeclaratorIdAST *declaratorId = ast->asDeclaratorId())
+ return location(declaratorId->name);
+ else if (CPlusPlus::NestedDeclaratorAST *nested = ast->asNestedDeclarator())
+ return location(nested->declarator);
+
+ return ast->firstToken();
+}
+
+unsigned Semantic::location(NameAST *ast) const
+{
+ if (! ast)
+ return 0;
+
+ else if (CPlusPlus::QualifiedNameAST *qualifiedName = ast->asQualifiedName())
+ return location(qualifiedName->unqualified_name);
+
+ return ast->firstToken();
+}
diff --git a/src/shared/cplusplus/Semantic.h b/src/shared/cplusplus/Semantic.h
index cc6e345483..69d5dce0b6 100644
--- a/src/shared/cplusplus/Semantic.h
+++ b/src/shared/cplusplus/Semantic.h
@@ -132,6 +132,10 @@ public:
int visibilityForObjCAccessSpecifier(int tokenKind) const;
bool isObjCClassMethod(int tokenKind) const;
+ unsigned location(DeclaratorAST *ast) const;
+ unsigned location(CoreDeclaratorAST *ast) const;
+ unsigned location(NameAST *ast) const;
+
private:
class Data;
friend class Data;