Commit 6dcc675e authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Guess the type of a global variable by looking at its initializer.

parent a8bc5a4b
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "parser/qmljsast_p.h" #include "parser/qmljsast_p.h"
#include "qmljsbind.h" #include "qmljsbind.h"
#include "qmljslink.h" #include "qmljslink.h"
#include "qmljscheck.h"
#include "qmljsmetatypesystem.h" #include "qmljsmetatypesystem.h"
#include <QtCore/QDir> #include <QtCore/QDir>
...@@ -126,7 +127,8 @@ class ProcessSourceElements: protected AST::Visitor ...@@ -126,7 +127,8 @@ class ProcessSourceElements: protected AST::Visitor
public: public:
ProcessSourceElements(Interpreter::Engine *interp) ProcessSourceElements(Interpreter::Engine *interp)
: _interp(interp) : _interp(interp),
typeOfExpression(interp)
{ {
} }
...@@ -149,11 +151,19 @@ protected: ...@@ -149,11 +151,19 @@ protected:
virtual bool visit(VariableDeclaration *ast) virtual bool visit(VariableDeclaration *ast)
{ {
if (ast->name) if (ast->name) {
_interp->globalObject()->setProperty(ast->name->asString(), _interp->undefinedValue()); const Value *value = _interp->undefinedValue();
if (ast->expression)
value = typeOfExpression(ast->expression, _interp->globalObject());
_interp->globalObject()->setProperty(ast->name->asString(), value);
}
return false; return false;
} }
Check typeOfExpression;
}; };
} // end of anonymous namespace } // end of anonymous namespace
......
...@@ -286,13 +286,19 @@ bool Check::visit(AST::FieldMemberExpression *ast) ...@@ -286,13 +286,19 @@ bool Check::visit(AST::FieldMemberExpression *ast)
return false; return false;
} }
bool Check::visit(AST::NewMemberExpression *) bool Check::visit(AST::NewMemberExpression *ast)
{ {
if (const FunctionValue *ctor = value_cast<const FunctionValue *>(check(ast->base))) {
_result = ctor->construct();
}
return false; return false;
} }
bool Check::visit(AST::NewExpression *) bool Check::visit(AST::NewExpression *ast)
{ {
if (const FunctionValue *ctor = value_cast<const FunctionValue *>(check(ast->expression))) {
_result = ctor->construct();
}
return false; return false;
} }
......
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