summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/qmljscheck.cpp
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-11-24 15:12:11 +0100
committerChristian Kamm <christian.d.kamm@nokia.com>2010-11-25 15:06:45 +0100
commit124358d25804c474b8c68405193dec59b335df46 (patch)
tree5d2103c40c78e05848912de7942d5da792de78b8 /src/libs/qmljs/qmljscheck.cpp
parent05831a8ea5169e407cca6de1f207225e1a710ff1 (diff)
downloadqt-creator-124358d25804c474b8c68405193dec59b335df46.tar.gz
QmlJS: Enhance check pass to do lookup... and disable it.
It still generates too many false-negatives for now. Will be enabled once the remaining lookup failures have been fixed. Reviewed-by: Erik Verbruggen
Diffstat (limited to 'src/libs/qmljs/qmljscheck.cpp')
-rw-r--r--src/libs/qmljs/qmljscheck.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp
index 3cbe72b94b..9ac19d8ed0 100644
--- a/src/libs/qmljs/qmljscheck.cpp
+++ b/src/libs/qmljs/qmljscheck.cpp
@@ -197,6 +197,7 @@ Check::Check(Document::Ptr doc, const Snapshot &snapshot, const Context *linkedC
, _context(*linkedContextNoScope)
, _scopeBuilder(&_context, doc, snapshot)
, _ignoreTypeErrors(false)
+ , _lastValue(0)
{
}
@@ -321,6 +322,63 @@ bool Check::visit(UiArrayBinding *ast)
return true;
}
+bool Check::visit(IdentifierExpression *ast)
+{
+ // currently disabled: too many false negatives
+ return true;
+
+ _lastValue = 0;
+ if (ast->name) {
+ Evaluate evaluator(&_context);
+ _lastValue = evaluator.reference(ast);
+ if (!_lastValue)
+ error(ast->identifierToken, tr("unknown identifier"));
+ if (const Reference *ref = value_cast<const Reference *>(_lastValue)) {
+ _lastValue = _context.lookupReference(ref);
+ if (!_lastValue)
+ error(ast->identifierToken, tr("could not resolve"));
+ }
+ }
+ return false;
+}
+
+bool Check::visit(FieldMemberExpression *ast)
+{
+ // currently disabled: too many false negatives
+ return true;
+
+ Node::accept(ast->base, this);
+ if (!_lastValue)
+ return false;
+ const ObjectValue *obj = _lastValue->asObjectValue();
+ if (!obj) {
+ error(locationFromRange(ast->base->firstSourceLocation(), ast->base->lastSourceLocation()),
+ tr("does not have members"));
+ }
+ if (!obj || !ast->name) {
+ _lastValue = 0;
+ return false;
+ }
+ _lastValue = obj->lookupMember(ast->name->asString(), &_context);
+ if (!_lastValue)
+ error(ast->identifierToken, tr("unknown member"));
+ return false;
+}
+
+bool Check::visit(FunctionDeclaration *ast)
+{
+ return visit(static_cast<FunctionExpression *>(ast));
+}
+
+bool Check::visit(FunctionExpression *ast)
+{
+ Node::accept(ast->formals, this);
+ _scopeBuilder.push(ast);
+ Node::accept(ast->body, this);
+ _scopeBuilder.pop();
+ return false;
+}
+
/// When something is changed here, also change ReadingContext::lookupProperty in
/// texttomodelmerger.cpp
/// ### Maybe put this into the context as a helper method.