Commit a1ec4e2a authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Introduced Name::identifier().

Name::identifier() returns the identifier used to declare the name.
parent 6ec0b259
......@@ -82,11 +82,11 @@ LookupContext::LookupContext(Control *control)
LookupContext::LookupContext(Symbol *symbol,
Document::Ptr expressionDocument,
Document::Ptr thisDocument,
const Snapshot &documents)
const Snapshot &snapshot)
: _symbol(symbol),
_expressionDocument(expressionDocument),
_thisDocument(thisDocument),
_documents(documents)
_snapshot(snapshot)
{
_control = _expressionDocument->control();
_visibleScopes = buildVisibleScopes();
......@@ -95,9 +95,6 @@ LookupContext::LookupContext(Symbol *symbol,
bool LookupContext::isValid() const
{ return _control != 0; }
LookupContext::operator bool() const
{ return _control != 0; }
Control *LookupContext::control() const
{ return _control; }
......@@ -111,20 +108,10 @@ Document::Ptr LookupContext::thisDocument() const
{ return _thisDocument; }
Document::Ptr LookupContext::document(const QString &fileName) const
{ return _documents.value(fileName); }
{ return _snapshot.value(fileName); }
Identifier *LookupContext::identifier(Name *name) const
{
if (NameId *nameId = name->asNameId())
return nameId->identifier();
else if (TemplateNameId *templId = name->asTemplateNameId())
return templId->identifier();
else if (DestructorNameId *dtorId = name->asDestructorNameId())
return dtorId->identifier();
else if (QualifiedNameId *q = name->asQualifiedNameId())
return identifier(q->unqualifiedNameId());
return 0;
}
Snapshot LookupContext::snapshot() const
{ return _snapshot; }
bool LookupContext::maybeValidSymbol(Symbol *symbol,
ResolveMode mode,
......@@ -257,6 +244,14 @@ QList<Symbol *> LookupContext::resolve(Name *name, const QList<Scope *> &visible
return candidates;
}
Identifier *LookupContext::identifier(const Name *name) const
{
if (name)
return name->identifier();
return 0;
}
void LookupContext::buildVisibleScopes_helper(Document::Ptr doc, QList<Scope *> *scopes,
QSet<QString> *processed)
{
......@@ -267,7 +262,7 @@ void LookupContext::buildVisibleScopes_helper(Document::Ptr doc, QList<Scope *>
scopes->append(doc->globalSymbols());
foreach (const Document::Include &incl, doc->includes()) {
buildVisibleScopes_helper(_documents.value(incl.fileName()),
buildVisibleScopes_helper(_snapshot.value(incl.fileName()),
scopes, processed);
}
}
......
......@@ -43,16 +43,16 @@ public:
LookupContext(Symbol *symbol,
Document::Ptr expressionDocument,
Document::Ptr thisDocument,
const Snapshot &documents);
const Snapshot &snapshot);
bool isValid() const;
operator bool() const;
Control *control() const;
Symbol *symbol() const;
Document::Ptr expressionDocument() const;
Document::Ptr thisDocument() const;
Document::Ptr document(const QString &fileName) const;
Snapshot snapshot() const;
QList<Symbol *> resolve(Name *name) const
{ return resolve(name, visibleScopes()); }
......@@ -66,9 +66,6 @@ public:
QList<Symbol *> resolveClassOrNamespace(Name *name) const
{ return resolveClassOrNamespace(name, visibleScopes()); }
Snapshot snapshot() const
{ return _documents; }
enum ResolveMode {
ResolveSymbol = 0x01,
ResolveClass = 0x02,
......@@ -77,8 +74,6 @@ public:
ResolveAll = ResolveSymbol | ResolveClassOrNamespace
};
Identifier *identifier(Name *name) const;
QList<Symbol *> resolve(Name *name, const QList<Scope *> &visibleScopes,
ResolveMode mode = ResolveAll) const;
......@@ -120,6 +115,8 @@ public:
QList<Scope *> *expandedScopes) const;
private:
Identifier *identifier(const Name *name) const;
QList<Scope *> buildVisibleScopes();
void buildVisibleScopes_helper(Document::Ptr doc, QList<Scope *> *scopes,
......@@ -144,7 +141,7 @@ private:
Document::Ptr _thisDocument;
// All documents.
Snapshot _documents;
Snapshot _snapshot;
// Visible scopes.
QList<Scope *> _visibleScopes;
......
......@@ -63,6 +63,8 @@ public:
Name();
virtual ~Name();
virtual Identifier *identifier() const = 0;
bool isNameId() const;
bool isTemplateNameId() const;
bool isDestructorNameId() const;
......
......@@ -73,6 +73,14 @@ QualifiedNameId::~QualifiedNameId()
void QualifiedNameId::accept0(NameVisitor *visitor)
{ visitor->visit(this); }
Identifier *QualifiedNameId::identifier() const
{
if (Name *u = unqualifiedNameId())
return u->identifier();
return 0;
}
unsigned QualifiedNameId::nameCount() const
{ return _nameCount; }
......@@ -225,6 +233,9 @@ void OperatorNameId::accept0(NameVisitor *visitor)
int OperatorNameId::kind() const
{ return _kind; }
Identifier *OperatorNameId::identifier() const
{ return 0; }
bool OperatorNameId::isEqualTo(const Name *other) const
{
const OperatorNameId *o = other->asOperatorNameId();
......@@ -246,6 +257,9 @@ void ConversionNameId::accept0(NameVisitor *visitor)
FullySpecifiedType ConversionNameId::type() const
{ return _type; }
Identifier *ConversionNameId::identifier() const
{ return 0; }
bool ConversionNameId::isEqualTo(const Name *other) const
{
const ConversionNameId *c = other->asConversionNameId();
......
......@@ -64,6 +64,8 @@ public:
bool isGlobal = false);
virtual ~QualifiedNameId();
virtual Identifier *identifier() const;
unsigned nameCount() const;
Name *nameAt(unsigned index) const;
Name *const *names() const;
......@@ -94,7 +96,7 @@ public:
NameId(Identifier *identifier);
virtual ~NameId();
Identifier *identifier() const;
virtual Identifier *identifier() const;
virtual bool isEqualTo(const Name *other) const;
......@@ -117,7 +119,7 @@ public:
DestructorNameId(Identifier *identifier);
virtual ~DestructorNameId();
Identifier *identifier() const;
virtual Identifier *identifier() const;
virtual bool isEqualTo(const Name *other) const;
......@@ -142,7 +144,7 @@ public:
unsigned templateArgumentCount);
virtual ~TemplateNameId();
Identifier *identifier() const;
virtual Identifier *identifier() const;
// ### find a better name
unsigned templateArgumentCount() const;
......@@ -229,6 +231,7 @@ public:
int kind() const;
virtual Identifier *identifier() const;
virtual bool isEqualTo(const Name *other) const;
virtual const OperatorNameId *asOperatorNameId() const
......@@ -252,6 +255,7 @@ public:
FullySpecifiedType type() const;
virtual Identifier *identifier() const;
virtual bool isEqualTo(const Name *other) const;
virtual const ConversionNameId *asConversionNameId() const
......
......@@ -296,6 +296,14 @@ void Symbol::setName(Name *name)
}
}
Identifier *Symbol::identifier() const
{
if (_name)
return _name->identifier();
return 0;
}
Scope *Symbol::scope() const
{ return _scope; }
......
......@@ -125,6 +125,9 @@ public:
/// Sets this Symbol's name.
void setName(Name *name); // ### dangerous
/// Returns this Symbol's (optional) identifier
Identifier *identifier() const;
/// Returns this Symbol's storage class specifier.
int storage() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment