Commit ed02e7ee authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Merge branch 'master' of git@scm.dev.nokia.troll.no:creator/mainline

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