#include <QtCore/QStack>
#include <private/qqmljsast_p.h>
#include <qmljs_runtime.h>
+#include <qmljs_environment.h>
#include <cmath>
#include <iostream>
#include <cassert>
inline void enterEnvironment(Node *node)
{
Environment *e = _cg->newEnvironment(node, _env);
+ e->isStrict = _cg->_context->strictMode;
_envStack.append(e);
_env = e;
}
|| name == QLatin1String("public")
|| name == QLatin1String("static")
|| name == QLatin1String("yield")) {
- // TODO: error!
- qDebug("TODO: give a proper error message @%u:%u", loc.startLine, loc.startColumn);
+ _cg->throwSyntaxError(loc, "Unexpected strict mode reserved word");
}
}
}
QStack<Environment *> _envStack;
};
-Codegen::Codegen(Debugging::Debugger *debugger)
+Codegen::Codegen(VM::ExecutionContext *context)
: _module(0)
, _function(0)
, _block(0)
, _loop(0)
, _labelledStatement(0)
, _tryCleanup(0)
- , _debugger(debugger)
+ , _context(context)
+ , _debugger(context->engine->debugger)
{
}
case QSOperator::Assign:
if (! (left->asTemp() || left->asName() || left->asSubscript() || left->asMember())) {
- assert(!"syntax error");
+ throwSyntaxError(ast->lastSourceLocation(), "syntax error");
}
if (_expr.accept(nx)) {
case QSOperator::InplaceURightShift:
case QSOperator::InplaceXor: {
if (! (left->asTemp() || left->asName() || left->asSubscript() || left->asMember())) {
- assert(!"syntax error");
+ throwSyntaxError(ast->lastSourceLocation(), "syntax error");
}
if (_expr.accept(nx)) {
return false;
}
}
- assert(!"throw syntax error");
+ throwSyntaxError(ast->lastSourceLocation(), QString("Undefined label '") + ast->label.toString() + QString("'"));
}
return false;
return false;
}
}
- assert(!"throw syntax error");
+ throwSyntaxError(ast->lastSourceLocation(), QString("Undefined label '") + ast->label.toString() + QString("'"));
}
return false;
}
assert(!"not implemented");
return false;
}
+
+void Codegen::throwSyntaxError(const SourceLocation &loc, const QString &detail)
+{
+ VM::DiagnosticMessage *msg = new VM::DiagnosticMessage;
+ msg->offset = loc.begin();
+ msg->startLine = loc.startLine;
+ msg->startColumn = loc.startColumn;
+ msg->message = new VM::String(detail);
+ _context->throwSyntaxError(msg);
+}
class UiParameterList;
}
+namespace VM {
+struct ExecutionContext;
+}
+
namespace Debugging {
class Debugger;
} // namespace Debugging
class Codegen: protected AST::Visitor
{
public:
- Codegen(Debugging::Debugger *debugger);
+ Codegen(VM::ExecutionContext *ctx);
enum Mode {
GlobalCode,
virtual bool visit(AST::UiScriptBinding *ast);
virtual bool visit(AST::UiSourceElement *ast);
+ void throwSyntaxError(const AST::SourceLocation &loc, const QString &detail);
+
private:
Result _expr;
QString _property;
TryCleanup *_tryCleanup;
QHash<AST::Node *, Environment *> _envMap;
QHash<AST::FunctionExpression *, int> _functionMap;
+ VM::ExecutionContext *_context;
Debugging::Debugger *_debugger;
class ScanFunctions;