Try to get the type from a qualified-id.

This commit is contained in:
Roberto Raggi
2010-02-02 15:01:42 +01:00
parent 2443a4b365
commit fac977a5bd
5 changed files with 47 additions and 11 deletions

View File

@@ -47,7 +47,7 @@ Check::~Check()
{ {
} }
const Interpreter::Value *Check::operator()(AST::ExpressionNode *ast, const Interpreter::ObjectValue *scope) const Interpreter::Value *Check::operator()(AST::Node *ast, const Interpreter::ObjectValue *scope)
{ {
const Interpreter::ObjectValue *previousScope = switchScope(scope); const Interpreter::ObjectValue *previousScope = switchScope(scope);
const Interpreter::Value *result = check(ast); const Interpreter::Value *result = check(ast);
@@ -55,7 +55,7 @@ const Interpreter::Value *Check::operator()(AST::ExpressionNode *ast, const Inte
return result; return result;
} }
const Interpreter::Value *Check::check(AST::ExpressionNode *ast) const Interpreter::Value *Check::check(AST::Node *ast)
{ {
const Value *previousResult = switchResult(0); const Value *previousResult = switchResult(0);
accept(ast); accept(ast);
@@ -151,8 +151,31 @@ bool Check::visit(AST::UiArrayMemberList *)
return false; return false;
} }
bool Check::visit(AST::UiQualifiedId *) bool Check::visit(AST::UiQualifiedId *ast)
{ {
if (! ast->name)
return false;
const Value *value = _scope->lookup(ast->name->asString());
if (! ast->next) {
_result = value;
} else {
const ObjectValue *base = value_cast<const ObjectValue *>(value);
for (AST::UiQualifiedId *it = ast->next; base && it; it = it->next) {
NameId *name = it->name;
if (! name)
break;
const Value *value = base->property(name->asString());
if (! it->next)
_result = value;
else
base = value_cast<const ObjectValue *>(value);
}
}
return false; return false;
} }

View File

@@ -48,11 +48,11 @@ public:
Check(Interpreter::Engine *engine); Check(Interpreter::Engine *engine);
virtual ~Check(); virtual ~Check();
const Interpreter::Value *operator()(AST::ExpressionNode *ast, const Interpreter::ObjectValue *scope); const Interpreter::Value *operator()(AST::Node *ast, const Interpreter::ObjectValue *scope);
const Interpreter::Value *check(AST::ExpressionNode *ast);
protected: protected:
void accept(AST::Node *node); void accept(AST::Node *node);
const Interpreter::Value *check(AST::Node *ast);
Interpreter::Engine *switchEngine(Interpreter::Engine *engine); Interpreter::Engine *switchEngine(Interpreter::Engine *engine);
const Interpreter::Value *switchResult(const Interpreter::Value *result); const Interpreter::Value *switchResult(const Interpreter::Value *result);

View File

@@ -142,11 +142,13 @@ void QmlHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
return; return;
const SemanticInfo semanticInfo = edit->semanticInfo(); const SemanticInfo semanticInfo = edit->semanticInfo();
const Snapshot snapshot = semanticInfo.snapshot;
Document::Ptr qmlDocument = semanticInfo.document; if (semanticInfo.revision() != edit->documentRevision())
if (qmlDocument.isNull())
return; return;
const Snapshot snapshot = semanticInfo.snapshot;
const Document::Ptr qmlDocument = semanticInfo.document;
if (m_helpEngineNeedsSetup && m_helpEngine->registeredDocumentations().count() > 0) { if (m_helpEngineNeedsSetup && m_helpEngine->registeredDocumentations().count() > 0) {
m_helpEngine->setupData(); m_helpEngine->setupData();
m_helpEngineNeedsSetup = false; m_helpEngineNeedsSetup = false;
@@ -169,10 +171,10 @@ void QmlHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
AST::UiObjectMember *declaringMember = semanticInfo.declaringMember(pos); AST::UiObjectMember *declaringMember = semanticInfo.declaringMember(pos);
Interpreter::Engine interp; Interpreter::Engine interp;
Interpreter::ObjectValue *scope = Bind::scopeChainAt(qmlDocument, snapshot, &interp, declaringMember); const Interpreter::ObjectValue *scope = Bind::scopeChainAt(qmlDocument, snapshot, &interp, declaringMember);
Check check(&interp); Check check(&interp);
const Interpreter::Value *value = check(node->expressionCast(), scope); const Interpreter::Value *value = check(node, scope);
QStringList baseClasses; QStringList baseClasses;
m_toolTip = prettyPrint(value, &interp, &baseClasses); m_toolTip = prettyPrint(value, &interp, &baseClasses);

View File

@@ -567,6 +567,16 @@ QmlJSTextEditor::~QmlJSTextEditor()
{ {
} }
SemanticInfo QmlJSTextEditor::semanticInfo() const
{
return m_semanticInfo;
}
int QmlJSTextEditor::documentRevision() const
{
return document()->revision();
}
Core::IEditor *QmlJSEditorEditable::duplicate(QWidget *parent) Core::IEditor *QmlJSEditorEditable::duplicate(QWidget *parent)
{ {
QmlJSTextEditor *newEditor = new QmlJSTextEditor(parent); QmlJSTextEditor *newEditor = new QmlJSTextEditor(parent);

View File

@@ -131,7 +131,8 @@ public:
virtual void unCommentSelection(); virtual void unCommentSelection();
SemanticInfo semanticInfo() const { return m_semanticInfo; } SemanticInfo semanticInfo() const;
int documentRevision() const;
public slots: public slots:
virtual void setFontSettings(const TextEditor::FontSettings &); virtual void setFontSettings(const TextEditor::FontSettings &);