From a34f11737ff29c383ab87b58258213a2ec92d74b Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Wed, 16 May 2012 19:00:31 +0200 Subject: Simplified the compiler. --- qv4codegen_p.h | 62 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 32 deletions(-) (limited to 'qv4codegen_p.h') diff --git a/qv4codegen_p.h b/qv4codegen_p.h index c44341306a..f8780016dd 100644 --- a/qv4codegen_p.h +++ b/qv4codegen_p.h @@ -15,7 +15,7 @@ class Codegen: protected AST::Visitor public: Codegen(); - void operator()(AST::Program *ast, IR::Module *module); + IR::Function *operator()(AST::Program *ast, IR::Module *module); protected: enum Format { ex, cx, nx }; @@ -55,19 +55,24 @@ protected: struct Environment { Environment *parent; - QHash members; - int count; + QHash members; + QVector vars; + int maxNumberOfArguments; + bool hasDirectEval; + bool hasNestedFunctions; - Environment(Environment *parent = 0) + Environment(Environment *parent) : parent(parent) - , count(0) {} + , maxNumberOfArguments(0) + , hasDirectEval(false) + , hasNestedFunctions(false) {} - int findMember(const QStringRef &name) const + int findMember(const QString &name) const { return members.value(name, -1); } - bool lookupMember(const QStringRef &name, Environment **scope, int *index, int *distance) + bool lookupMember(const QString &name, Environment **scope, int *index, int *distance) { Environment *it = this; *distance = 0; @@ -82,36 +87,25 @@ protected: return false; } - void enter(const QStringRef &name) + void enter(const QString &name) { - int idx = members.value(name, -1); - if (idx == -1) - members.insert(name, count++); + if (! name.isEmpty()) { + int idx = members.value(name, -1); + if (idx == -1) { + members.insert(name, vars.count()); + vars.append(name); + } + } } }; - Environment *newEnvironment() - { - Environment *scope = new Environment(_env); - return scope; - } - - Environment *changeEnvironment(Environment *env) + Environment *newEnvironment(AST::Node *node, Environment *parent) { - qSwap(_env, env); + Environment *env = new Environment(parent); + _envMap.insert(node, env); return env; } - struct Scope { - Codegen *cg; - Environment *previous; - inline Scope(Codegen *cg, Environment *env): cg(cg) { previous = cg->changeEnvironment(env); } - inline ~Scope() { cg->changeEnvironment(previous); } - - private: - Q_DISABLE_COPY(Scope) - }; - struct UiMember { }; @@ -126,6 +120,9 @@ protected: : breakBlock(breakBlock), continueBlock(continueBlock) {} }; + void enterEnvironment(AST::Node *node); + void leaveEnvironment(); + IR::Expr *member(IR::Expr *base, const QString *name); IR::Expr *subscript(IR::Expr *base, IR::Expr *index); IR::Expr *argument(IR::Expr *expr); @@ -134,7 +131,8 @@ protected: void move(IR::Expr *target, IR::Expr *source, IR::AluOp op = IR::OpInvalid); void linearize(IR::Function *function); - void defineFunction(AST::FunctionExpression *ast, bool isDeclaration = false); + IR::Function *defineFunction(const QString &name, AST::Node *ast, AST::FormalParameterList *formals, + AST::SourceElements *body, bool isDeclaration = false); int indexOfLocal(const QStringRef &string) const; int indexOfArgument(const QStringRef &string) const; @@ -284,10 +282,10 @@ private: IR::BasicBlock *_block; IR::BasicBlock *_exitBlock; unsigned _returnAddress; - QVector _allEnvironments; Environment *_env; + QHash _envMap; - struct ScanFunctionBody; + class ScanFunctions; }; } // end of namespace QQmlJS -- cgit v1.2.3