diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-03-12 14:11:15 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-03-12 14:11:15 +0100 |
commit | dd91e772430dc294e3bf478c119ef8d43c0a3358 (patch) | |
tree | 6f33ce4d5872a5691e0291eb45bf6ab373a5f567 /Source/JavaScriptCore/parser/Nodes.h | |
parent | ad0d549d4cc13433f77c1ac8f0ab379c83d93f28 (diff) | |
download | qtwebkit-dd91e772430dc294e3bf478c119ef8d43c0a3358.tar.gz |
Imported WebKit commit 3db4eb1820ac8fb03065d7ea73a4d9db1e8fea1a (http://svn.webkit.org/repository/webkit/trunk@110422)
This includes build fixes for the latest qtbase/qtdeclarative as well as the final QML2 API.
Diffstat (limited to 'Source/JavaScriptCore/parser/Nodes.h')
-rw-r--r-- | Source/JavaScriptCore/parser/Nodes.h | 139 |
1 files changed, 78 insertions, 61 deletions
diff --git a/Source/JavaScriptCore/parser/Nodes.h b/Source/JavaScriptCore/parser/Nodes.h index 0373766b5..f752b91e9 100644 --- a/Source/JavaScriptCore/parser/Nodes.h +++ b/Source/JavaScriptCore/parser/Nodes.h @@ -47,19 +47,31 @@ namespace JSC { class ScopeChainNode; class ScopeNode; - typedef unsigned CodeFeatures; - - const CodeFeatures NoFeatures = 0; - const CodeFeatures EvalFeature = 1 << 0; - const CodeFeatures ArgumentsFeature = 1 << 1; - const CodeFeatures WithFeature = 1 << 2; - const CodeFeatures CatchFeature = 1 << 3; - const CodeFeatures ThisFeature = 1 << 4; - const CodeFeatures StrictModeFeature = 1 << 5; - const CodeFeatures ShadowsArgumentsFeature = 1 << 6; + typedef unsigned short ScopeFlags; + + const ScopeFlags NoScopeFlags = 0; + + // Some scope flags propagate down the parse tree from parent scopes, like + // strict mode. They are modal to an entire set of nested scopes. + const ScopeFlags StrictModeFlag = 1 << 0; + const ScopeFlags FunctionModeFlag = 1 << 1; + const ScopeFlags AllScopeModeFlags = StrictModeFlag | FunctionModeFlag; + + // Some scope flags refer only to a specific scope, and don't propagate down + // or up. + const ScopeFlags BlockScopeFlag = 1 << 4; + const ScopeFlags AllScopeKindFlags = BlockScopeFlag; + + // Other flags reflect uses within nested scopes, and so propagate up + // from the leaves. + const ScopeFlags UsesEvalFlag = 1 << 8; + const ScopeFlags UsesArgumentsFlag = 1 << 9; + const ScopeFlags UsesWithFlag = 1 << 10; + const ScopeFlags UsesCatchFlag = 1 << 11; + const ScopeFlags UsesThisFlag = 1 << 12; + const ScopeFlags ShadowsArgumentsFlag = 1 << 13; + const ScopeFlags AllScopeUsesFlags = UsesEvalFlag | UsesArgumentsFlag | UsesWithFlag | UsesCatchFlag | UsesThisFlag | ShadowsArgumentsFlag; - const CodeFeatures AllFeatures = EvalFeature | ArgumentsFeature | WithFeature | CatchFeature | ThisFeature | StrictModeFeature | ShadowsArgumentsFeature; - enum Operator { OpEqual, OpPlusEq, @@ -793,11 +805,20 @@ namespace JSC { NegateNode(int, ExpressionNode*); }; - class BitwiseNotNode : public UnaryOpNode { + class BitwiseNotNode : public ExpressionNode { public: BitwiseNotNode(int, ExpressionNode*); - }; + protected: + ExpressionNode* expr() { return m_expr; } + const ExpressionNode* expr() const { return m_expr; } + + private: + virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); + + ExpressionNode* m_expr; + }; + class LogicalNotNode : public UnaryOpNode { public: LogicalNotNode(int, ExpressionNode*); @@ -1369,62 +1390,53 @@ namespace JSC { ParameterNode* m_next; }; - struct ScopeNodeData { - WTF_MAKE_FAST_ALLOCATED; + class ScopeNode : public StatementNode, public ParserArenaRefCounted { public: typedef DeclarationStacks::VarStack VarStack; typedef DeclarationStacks::FunctionStack FunctionStack; - ScopeNodeData(ParserArena&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, int numConstants); + ScopeNode(JSGlobalData*, int, ScopeFlags); + ScopeNode(JSGlobalData*, int, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, ScopeFlags, int numConstants); - ParserArena m_arena; - VarStack m_varStack; - FunctionStack m_functionStack; - int m_numConstants; - SourceElements* m_statements; - IdentifierSet m_capturedVariables; - }; + using ParserArenaRefCounted::operator new; - class ScopeNode : public StatementNode, public ParserArenaRefCounted { - public: - typedef DeclarationStacks::VarStack VarStack; - typedef DeclarationStacks::FunctionStack FunctionStack; + void destroyData() + { + m_arena.reset(); + m_varStack.clear(); + m_functionStack.clear(); + m_statements = 0; + m_capturedVariables.clear(); + } - ScopeNode(JSGlobalData*, int, bool inStrictContext); - ScopeNode(JSGlobalData*, int, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, CodeFeatures, int numConstants); + bool hasCapturedVariables() const { return !!m_capturedVariables.size(); } + size_t capturedVariableCount() const { return m_capturedVariables.size(); } + bool captures(const Identifier& ident) { return m_capturedVariables.contains(ident.impl()); } - using ParserArenaRefCounted::operator new; + void addScopeFlags(ScopeFlags scopeFlags) { m_scopeFlags |= scopeFlags; } + ScopeFlags scopeFlags() const { return m_scopeFlags; } - ScopeNodeData* data() const { return m_data.get(); } - void destroyData() { m_data.clear(); } + bool isStrictMode() const { return m_scopeFlags & StrictModeFlag; } + bool usesEval() const { return m_scopeFlags & UsesEvalFlag; } + bool usesArguments() const { return (m_scopeFlags & UsesArgumentsFlag) && !(m_scopeFlags & ShadowsArgumentsFlag); } + void setUsesArguments() { m_scopeFlags |= UsesArgumentsFlag; } + bool usesThis() const { return m_scopeFlags & UsesThisFlag; } + + bool needsActivationForMoreThanVariables() const { return m_scopeFlags & (UsesEvalFlag | UsesWithFlag | UsesCatchFlag); } + bool needsActivation() const { return hasCapturedVariables() || needsActivationForMoreThanVariables(); } const SourceCode& source() const { return m_source; } const UString& sourceURL() const { return m_source.provider()->url(); } intptr_t sourceID() const { return m_source.provider()->asID(); } - void setFeatures(CodeFeatures features) { m_features = features; } - CodeFeatures features() { return m_features; } - - bool usesEval() const { return m_features & EvalFeature; } - bool usesArguments() const { return (m_features & ArgumentsFeature) && !(m_features & ShadowsArgumentsFeature); } - bool isStrictMode() const { return m_features & StrictModeFeature; } - void setUsesArguments() { m_features |= ArgumentsFeature; } - bool usesThis() const { return m_features & ThisFeature; } - bool needsActivationForMoreThanVariables() const { ASSERT(m_data); return m_features & (EvalFeature | WithFeature | CatchFeature); } - bool needsActivation() const { ASSERT(m_data); return (hasCapturedVariables()) || (m_features & (EvalFeature | WithFeature | CatchFeature)); } - bool hasCapturedVariables() const { return !!m_data->m_capturedVariables.size(); } - size_t capturedVariableCount() const { return m_data->m_capturedVariables.size(); } - bool captures(const Identifier& ident) { return m_data->m_capturedVariables.contains(ident.impl()); } - - VarStack& varStack() { ASSERT(m_data); return m_data->m_varStack; } - FunctionStack& functionStack() { ASSERT(m_data); return m_data->m_functionStack; } + VarStack& varStack() { return m_varStack; } + FunctionStack& functionStack() { return m_functionStack; } int neededConstants() { - ASSERT(m_data); // We may need 2 more constants than the count given by the parser, // because of the various uses of jsUndefined() and jsNull(). - return m_data->m_numConstants + 2; + return m_numConstants + 2; } StatementNode* singleStatement() const; @@ -1433,22 +1445,27 @@ namespace JSC { protected: void setSource(const SourceCode& source) { m_source = source; } + ParserArena m_arena; private: - OwnPtr<ScopeNodeData> m_data; - CodeFeatures m_features; + ScopeFlags m_scopeFlags; SourceCode m_source; + VarStack m_varStack; + FunctionStack m_functionStack; + int m_numConstants; + SourceElements* m_statements; + IdentifierSet m_capturedVariables; }; class ProgramNode : public ScopeNode { public: static const bool isFunctionNode = false; - static PassRefPtr<ProgramNode> create(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); + static PassRefPtr<ProgramNode> create(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, ScopeFlags, int numConstants); static const bool scopeIsFunction = false; private: - ProgramNode(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); + ProgramNode(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, ScopeFlags, int numConstants); virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); }; @@ -1456,12 +1473,12 @@ namespace JSC { class EvalNode : public ScopeNode { public: static const bool isFunctionNode = false; - static PassRefPtr<EvalNode> create(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); + static PassRefPtr<EvalNode> create(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, ScopeFlags, int numConstants); static const bool scopeIsFunction = false; private: - EvalNode(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); + EvalNode(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, ScopeFlags, int numConstants); virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0); }; @@ -1478,8 +1495,8 @@ namespace JSC { class FunctionBodyNode : public ScopeNode { public: static const bool isFunctionNode = true; - static FunctionBodyNode* create(JSGlobalData*, int, bool isStrictMode); - static PassRefPtr<FunctionBodyNode> create(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); + static FunctionBodyNode* create(JSGlobalData*, int, ScopeFlags); + static PassRefPtr<FunctionBodyNode> create(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, ScopeFlags, int numConstants); FunctionParameters* parameters() const { return m_parameters.get(); } size_t parameterCount() const { return m_parameters->size(); } @@ -1496,8 +1513,8 @@ namespace JSC { static const bool scopeIsFunction = true; private: - FunctionBodyNode(JSGlobalData*, int, bool inStrictContext); - FunctionBodyNode(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants); + FunctionBodyNode(JSGlobalData*, int, ScopeFlags); + FunctionBodyNode(JSGlobalData*, int, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, ScopeFlags, int numConstants); Identifier m_ident; Identifier m_inferredName; |