summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-09-02 11:59:01 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2010-09-02 12:51:01 +0200
commitc12866a467459f51e33252d5629edb8fbcd2201a (patch)
treee6f467fb02f751bed515d4348f7aa97119467af5 /src/shared
parent8b2eeb9c5f7f909a7067270854619af708e25e22 (diff)
downloadqt-creator-c12866a467459f51e33252d5629edb8fbcd2201a.tar.gz
Merge CPlusPlus::NameId and CPlusPlus::Identifier.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/cplusplus/Bind.cpp22
-rw-r--r--src/shared/cplusplus/CPlusPlusForwardDeclarations.h2
-rw-r--r--src/shared/cplusplus/Control.cpp20
-rw-r--r--src/shared/cplusplus/Control.h3
-rw-r--r--src/shared/cplusplus/Literals.cpp18
-rw-r--r--src/shared/cplusplus/Literals.h16
-rw-r--r--src/shared/cplusplus/Name.h2
-rw-r--r--src/shared/cplusplus/NameVisitor.h2
-rw-r--r--src/shared/cplusplus/Names.cpp26
-rw-r--r--src/shared/cplusplus/Names.h20
-rw-r--r--src/shared/cplusplus/Scope.cpp21
-rw-r--r--src/shared/cplusplus/Scope.h1
-rw-r--r--src/shared/cplusplus/Symbol.cpp2
13 files changed, 47 insertions, 108 deletions
diff --git a/src/shared/cplusplus/Bind.cpp b/src/shared/cplusplus/Bind.cpp
index 6aa04592aa..d7ab4d3853 100644
--- a/src/shared/cplusplus/Bind.cpp
+++ b/src/shared/cplusplus/Bind.cpp
@@ -303,7 +303,7 @@ const Name *Bind::objCSelectorArgument(ObjCSelectorArgumentAST *ast, bool *hasAr
if (ast->colon_token)
*hasArg = true;
- return control()->nameId(identifier(ast->name_token));
+ return identifier(ast->name_token);
}
bool Bind::visit(AttributeAST *ast)
@@ -468,7 +468,7 @@ void Bind::enumerator(EnumeratorAST *ast, Enum *symbol)
ExpressionTy expression = this->expression(ast->expression);
if (ast->identifier_token) {
- const Name *name = control()->nameId(identifier(ast->identifier_token));
+ const Name *name = identifier(ast->identifier_token);
Declaration *e = control()->newDeclaration(ast->identifier_token, name);
e->setType(control()->integerType(IntegerType::Int)); // ### introduce IntegerType::Enumerator
symbol->addMember(e);
@@ -1143,20 +1143,20 @@ bool Bind::visit(QtMemberDeclarationAST *ast)
const Name *name = 0;
if (tokenKind(ast->q_token) == T_Q_D)
- name = control()->nameId(control()->identifier("d"));
+ name = control()->identifier("d");
else
- name = control()->nameId(control()->identifier("q"));
+ name = control()->identifier("q");
FullySpecifiedType declTy = this->expression(ast->type_id);
if (tokenKind(ast->q_token) == T_Q_D) {
if (NamedType *namedTy = declTy->asNamedType()) {
- if (const NameId *nameId = namedTy->name()->asNameId()) {
+ if (const Identifier *nameId = namedTy->name()->asNameId()) {
std::string privateClass;
privateClass += nameId->identifier()->chars();
privateClass += "Private";
- const Name *privName = control()->nameId(control()->identifier(privateClass.c_str(), privateClass.size()));
+ const Name *privName = control()->identifier(privateClass.c_str(), privateClass.size());
declTy.setType(control()->namedType(privName));
}
}
@@ -1987,7 +1987,7 @@ bool Bind::visit(NamespaceAST *ast)
const Name *namespaceName = 0;
if (ast->identifier_token) {
sourceLocation = ast->identifier_token;
- namespaceName = control()->nameId(identifier(ast->identifier_token));
+ namespaceName = identifier(ast->identifier_token);
}
Namespace *ns = control()->newNamespace(sourceLocation, namespaceName);
@@ -2008,7 +2008,7 @@ bool Bind::visit(NamespaceAliasDefinitionAST *ast)
const Name *name = 0;
if (ast->namespace_name_token) {
sourceLocation = ast->namespace_name_token;
- name = control()->nameId(identifier(ast->namespace_name_token));
+ name = identifier(ast->namespace_name_token);
}
NamespaceAlias *namespaceAlias = control()->newNamespaceAlias(sourceLocation, name);
@@ -2444,14 +2444,16 @@ bool Bind::visit(ConversionFunctionIdAST *ast)
bool Bind::visit(SimpleNameAST *ast)
{
const Identifier *id = identifier(ast->identifier_token);
- ast->name = _name = control()->nameId(id);
+ _name = id;
+ ast->name = _name;
return false;
}
bool Bind::visit(DestructorNameAST *ast)
{
const Identifier *id = identifier(ast->identifier_token);
- ast->name = _name = control()->destructorNameId(id);
+ _name = control()->destructorNameId(id);
+ ast->name = _name;
return false;
}
diff --git a/src/shared/cplusplus/CPlusPlusForwardDeclarations.h b/src/shared/cplusplus/CPlusPlusForwardDeclarations.h
index 980d5c7dbf..2e42a89afc 100644
--- a/src/shared/cplusplus/CPlusPlusForwardDeclarations.h
+++ b/src/shared/cplusplus/CPlusPlusForwardDeclarations.h
@@ -83,7 +83,7 @@ class SymbolTable;
// names
class NameVisitor;
class Name;
-class NameId;
+class Identifier;
class TemplateNameId;
class DestructorNameId;
class OperatorNameId;
diff --git a/src/shared/cplusplus/Control.cpp b/src/shared/cplusplus/Control.cpp
index 050171eb6a..14e302a039 100644
--- a/src/shared/cplusplus/Control.cpp
+++ b/src/shared/cplusplus/Control.cpp
@@ -129,14 +129,6 @@ template <> struct Compare<ArrayType>
}
};
-template <> struct Compare<NameId>
-{
- bool operator()(const NameId &name, const NameId &otherName) const
- {
- return name.identifier() < otherName.identifier();
- }
-};
-
template <> struct Compare<DestructorNameId>
{
bool operator()(const DestructorNameId &name, const DestructorNameId &otherName) const
@@ -256,14 +248,6 @@ public:
delete_array_entries(symbols);
}
- const NameId *findOrInsertNameId(const Identifier *id)
- {
- if (! id)
- return 0;
-
- return nameIds.intern(NameId(id));
- }
-
template <typename _Iterator>
const TemplateNameId *findOrInsertTemplateNameId(const Identifier *id, _Iterator first, _Iterator last)
{
@@ -498,7 +482,6 @@ public:
// ### replace std::map with lookup tables. ASAP!
// names
- Table<NameId> nameIds;
Table<DestructorNameId> destructorNameIds;
Table<OperatorNameId> operatorNameIds;
Table<ConversionNameId> conversionNameIds;
@@ -616,9 +599,6 @@ const NumericLiteral *Control::numericLiteral(const char *chars)
return numericLiteral(chars, length);
}
-const NameId *Control::nameId(const Identifier *id)
-{ return d->findOrInsertNameId(id); }
-
const TemplateNameId *Control::templateNameId(const Identifier *id,
const FullySpecifiedType *const args,
unsigned argv)
diff --git a/src/shared/cplusplus/Control.h b/src/shared/cplusplus/Control.h
index 034e4d583c..78839fb1e5 100644
--- a/src/shared/cplusplus/Control.h
+++ b/src/shared/cplusplus/Control.h
@@ -65,9 +65,6 @@ public:
DiagnosticClient *diagnosticClient() const;
void setDiagnosticClient(DiagnosticClient *diagnosticClient);
- /// Returns the canonical name id.
- const NameId *nameId(const Identifier *id);
-
/// Returns the canonical template name id.
const TemplateNameId *templateNameId(const Identifier *id,
const FullySpecifiedType *const args = 0,
diff --git a/src/shared/cplusplus/Literals.cpp b/src/shared/cplusplus/Literals.cpp
index d56f937c48..9d1bf65225 100644
--- a/src/shared/cplusplus/Literals.cpp
+++ b/src/shared/cplusplus/Literals.cpp
@@ -47,6 +47,7 @@
// THE SOFTWARE.
#include "Literals.h"
+#include "NameVisitor.h"
#include <cstring>
#include <algorithm>
#include <iostream>
@@ -69,7 +70,7 @@ Literal::Literal(const char *chars, unsigned size)
Literal::~Literal()
{ delete[] _chars; }
-bool Literal::isEqualTo(const Literal *other) const
+bool Literal::equalTo(const Literal *other) const
{
if (! other)
return false;
@@ -212,3 +213,18 @@ Identifier::Identifier(const char *chars, unsigned size)
Identifier::~Identifier()
{ }
+void Identifier::accept0(NameVisitor *visitor) const
+{ visitor->visit(this); }
+
+bool Identifier::isEqualTo(const Name *other) const
+{
+ if (this == other)
+ return true;
+
+ else if (other) {
+ if (const Identifier *nameId = other->asNameId()) {
+ return equalTo(nameId);
+ }
+ }
+ return false;
+}
diff --git a/src/shared/cplusplus/Literals.h b/src/shared/cplusplus/Literals.h
index afe9bae2e1..6c1e958b6c 100644
--- a/src/shared/cplusplus/Literals.h
+++ b/src/shared/cplusplus/Literals.h
@@ -51,7 +51,7 @@
#include "CPlusPlusForwardDeclarations.h"
#include "Token.h"
-
+#include "Name.h"
namespace CPlusPlus {
@@ -78,7 +78,7 @@ public:
unsigned hashCode() const;
static unsigned hashCode(const char *chars, unsigned size);
- bool isEqualTo(const Literal *other) const;
+ bool equalTo(const Literal *other) const;
private:
char *_chars;
@@ -126,11 +126,21 @@ private:
};
};
-class CPLUSPLUS_EXPORT Identifier: public Literal
+class CPLUSPLUS_EXPORT Identifier: public Literal, public Name
{
public:
Identifier(const char *chars, unsigned size);
virtual ~Identifier();
+
+ virtual const Identifier *identifier() const { return this; }
+
+ virtual bool isEqualTo(const Name *other) const;
+
+ virtual const Identifier *asNameId() const
+ { return this; }
+
+protected:
+ virtual void accept0(NameVisitor *visitor) const;
};
} // end of namespace CPlusPlus
diff --git a/src/shared/cplusplus/Name.h b/src/shared/cplusplus/Name.h
index 152e035382..a5638fcac7 100644
--- a/src/shared/cplusplus/Name.h
+++ b/src/shared/cplusplus/Name.h
@@ -70,7 +70,7 @@ public:
bool isQualifiedNameId() const;
bool isSelectorNameId() const;
- virtual const NameId *asNameId() const { return 0; }
+ virtual const Identifier *asNameId() const { return 0; }
virtual const TemplateNameId *asTemplateNameId() const { return 0; }
virtual const DestructorNameId *asDestructorNameId() const { return 0; }
virtual const OperatorNameId *asOperatorNameId() const { return 0; }
diff --git a/src/shared/cplusplus/NameVisitor.h b/src/shared/cplusplus/NameVisitor.h
index 5cb046af8e..3a67c1846d 100644
--- a/src/shared/cplusplus/NameVisitor.h
+++ b/src/shared/cplusplus/NameVisitor.h
@@ -68,7 +68,7 @@ public:
virtual bool preVisit(const Name *) { return true; }
virtual void postVisit(const Name *) {}
- virtual void visit(const NameId *) {}
+ virtual void visit(const Identifier *) {}
virtual void visit(const TemplateNameId *) {}
virtual void visit(const DestructorNameId *) {}
virtual void visit(const OperatorNameId *) {}
diff --git a/src/shared/cplusplus/Names.cpp b/src/shared/cplusplus/Names.cpp
index c4cdafb4f3..63ff03f38c 100644
--- a/src/shared/cplusplus/Names.cpp
+++ b/src/shared/cplusplus/Names.cpp
@@ -90,32 +90,6 @@ bool QualifiedNameId::isEqualTo(const Name *other) const
return false;
}
-NameId::NameId(const Identifier *identifier)
- : _identifier(identifier)
-{ }
-
-NameId::~NameId()
-{ }
-
-void NameId::accept0(NameVisitor *visitor) const
-{ visitor->visit(this); }
-
-const Identifier *NameId::identifier() const
-{ return _identifier; }
-
-bool NameId::isEqualTo(const Name *other) const
-{
- if (other) {
- const NameId *nameId = other->asNameId();
- if (! nameId)
- return false;
- const Identifier *l = identifier();
- const Identifier *r = nameId->identifier();
- return l->isEqualTo(r);
- }
- return false;
-}
-
DestructorNameId::DestructorNameId(const Identifier *identifier)
: _identifier(identifier)
{ }
diff --git a/src/shared/cplusplus/Names.h b/src/shared/cplusplus/Names.h
index 050632a8b4..3a894a351e 100644
--- a/src/shared/cplusplus/Names.h
+++ b/src/shared/cplusplus/Names.h
@@ -82,26 +82,6 @@ private:
const Name *_name;
};
-class CPLUSPLUS_EXPORT NameId: public Name
-{
-public:
- NameId(const Identifier *identifier);
- virtual ~NameId();
-
- virtual const Identifier *identifier() const;
-
- virtual bool isEqualTo(const Name *other) const;
-
- virtual const NameId *asNameId() const
- { return this; }
-
-protected:
- virtual void accept0(NameVisitor *visitor) const;
-
-private:
- const Identifier *_identifier;
-};
-
class CPLUSPLUS_EXPORT DestructorNameId: public Name
{
public:
diff --git a/src/shared/cplusplus/Scope.cpp b/src/shared/cplusplus/Scope.cpp
index 72d2b774aa..bc5eeb90bb 100644
--- a/src/shared/cplusplus/Scope.cpp
+++ b/src/shared/cplusplus/Scope.cpp
@@ -94,7 +94,6 @@ public:
/// Returns the last Symbol in the scope.
iterator lastSymbol() const;
- Symbol *lookat(const Name *name) const;
Symbol *lookat(const Identifier *id) const;
Symbol *lookat(int operatorId) const;
@@ -157,21 +156,6 @@ void SymbolTable::enterSymbol(Symbol *symbol)
}
}
-Symbol *SymbolTable::lookat(const Name *name) const
-{
- if (! name)
- return 0;
-
- else if (const OperatorNameId *opId = name->asOperatorNameId())
- return lookat(opId->kind());
-
- else if (const Identifier *id = name->identifier())
- return lookat(id);
-
- else
- return 0;
-}
-
Symbol *SymbolTable::lookat(const Identifier *id) const
{
if (! _hash || ! id)
@@ -183,7 +167,7 @@ Symbol *SymbolTable::lookat(const Identifier *id) const
const Name *identity = symbol->unqualifiedName();
if (! identity) {
continue;
- } else if (const NameId *nameId = identity->asNameId()) {
+ } else if (const Identifier *nameId = identity->asNameId()) {
if (nameId->identifier()->isEqualTo(id))
break;
} else if (const TemplateNameId *t = identity->asTemplateNameId()) {
@@ -303,9 +287,6 @@ Scope::iterator Scope::firstMember() const
Scope::iterator Scope::lastMember() const
{ return _members ? _members->lastSymbol() : 0; }
-Symbol *Scope::find(const Name *name) const
-{ return _members ? _members->lookat(name) : 0; }
-
Symbol *Scope::find(const Identifier *id) const
{ return _members ? _members->lookat(id) : 0; }
diff --git a/src/shared/cplusplus/Scope.h b/src/shared/cplusplus/Scope.h
index c3a1cb23e7..47114111ba 100644
--- a/src/shared/cplusplus/Scope.h
+++ b/src/shared/cplusplus/Scope.h
@@ -80,7 +80,6 @@ public:
/// Returns the last Symbol in the scope.
iterator lastMember() const;
- Symbol *find(const Name *name) const;
Symbol *find(const Identifier *id) const;
Symbol *find(int operatorId) const;
diff --git a/src/shared/cplusplus/Symbol.cpp b/src/shared/cplusplus/Symbol.cpp
index 4bc78da935..5d46bc774a 100644
--- a/src/shared/cplusplus/Symbol.cpp
+++ b/src/shared/cplusplus/Symbol.cpp
@@ -85,7 +85,7 @@ protected:
return previousValue;
}
- virtual void visit(const NameId *name)
+ virtual void visit(const Identifier *name)
{ _value = name->identifier()->hashCode(); }
virtual void visit(const TemplateNameId *name)