diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-11 09:43:24 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-11 09:43:24 +0200 |
commit | 1b914638db989aaa98631a1c1e02c7b2d44805d8 (patch) | |
tree | 87f4fd2c7b38db320079a5de8877890d2ca3c485 /Source/JavaScriptCore/parser/Parser.h | |
parent | 2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 (diff) | |
download | qtwebkit-1b914638db989aaa98631a1c1e02c7b2d44805d8.tar.gz |
Imported WebKit commit 9a52e27980f47e8b0d8f8b7cc0fd7b5741bceb92 (http://svn.webkit.org/repository/webkit/trunk@116736)
New snapshot to include QDeclarative* -> QQml* build fixes
Diffstat (limited to 'Source/JavaScriptCore/parser/Parser.h')
-rw-r--r-- | Source/JavaScriptCore/parser/Parser.h | 118 |
1 files changed, 75 insertions, 43 deletions
diff --git a/Source/JavaScriptCore/parser/Parser.h b/Source/JavaScriptCore/parser/Parser.h index c0b13c53a..c2a11d665 100644 --- a/Source/JavaScriptCore/parser/Parser.h +++ b/Source/JavaScriptCore/parser/Parser.h @@ -130,19 +130,30 @@ struct ScopeLabelInfo { }; struct Scope { - Scope(const JSGlobalData* globalData, ScopeFlags scopeFlags) + Scope(const JSGlobalData* globalData, bool isFunction, bool strictMode) : m_globalData(globalData) - , m_scopeFlags(scopeFlags) + , m_shadowsArguments(false) + , m_usesEval(false) + , m_needsFullActivation(false) + , m_allowsNewDecls(true) + , m_strictMode(strictMode) + , m_isFunction(isFunction) + , m_isFunctionBoundary(false) , m_isValidStrictMode(true) , m_loopDepth(0) , m_switchDepth(0) { - ASSERT(!(scopeFlags & ~AllScopeModeFlags)); } Scope(const Scope& rhs) : m_globalData(rhs.m_globalData) - , m_scopeFlags(rhs.m_scopeFlags) + , m_shadowsArguments(rhs.m_shadowsArguments) + , m_usesEval(rhs.m_usesEval) + , m_needsFullActivation(rhs.m_needsFullActivation) + , m_allowsNewDecls(rhs.m_allowsNewDecls) + , m_strictMode(rhs.m_strictMode) + , m_isFunction(rhs.m_isFunction) + , m_isFunctionBoundary(rhs.m_isFunctionBoundary) , m_isValidStrictMode(rhs.m_isValidStrictMode) , m_loopDepth(rhs.m_loopDepth) , m_switchDepth(rhs.m_switchDepth) @@ -157,22 +168,6 @@ struct Scope { } } - ALWAYS_INLINE ScopeFlags scopeFlags() const { return m_scopeFlags; } - ALWAYS_INLINE ScopeFlags modeFlags() const { return m_scopeFlags & AllScopeModeFlags; } - ALWAYS_INLINE ScopeFlags usesFlags() const { return m_scopeFlags & AllScopeUsesFlags; } - ALWAYS_INLINE void setFlags(ScopeFlags scopeFlags) { m_scopeFlags |= scopeFlags; } - - ALWAYS_INLINE bool usesEval() const { return m_scopeFlags & UsesEvalFlag; } - ALWAYS_INLINE bool strictMode() const { return m_scopeFlags & StrictModeFlag; } - ALWAYS_INLINE bool shadowsArguments() const { return m_scopeFlags & ShadowsArgumentsFlag; } - ALWAYS_INLINE bool isFunction() const { return m_scopeFlags & FunctionModeFlag; } - ALWAYS_INLINE bool isBlockScope() const { return m_scopeFlags & BlockScopeFlag; } - ALWAYS_INLINE bool isFunctionBoundary() const { return isFunction() && !isBlockScope(); } - - ALWAYS_INLINE bool allowsNewDecls() const { return !isBlockScope(); } - - ALWAYS_INLINE bool isValidStrictMode() const { return m_isValidStrictMode; } - void startSwitch() { m_switchDepth++; } void endSwitch() { m_switchDepth--; } void startLoop() { m_loopDepth++; } @@ -206,6 +201,14 @@ struct Scope { return 0; } + void setIsFunction() + { + m_isFunction = true; + m_isFunctionBoundary = true; + } + bool isFunction() { return m_isFunction; } + bool isFunctionBoundary() { return m_isFunctionBoundary; } + bool declareVariable(const Identifier* ident) { bool isValidStrictMode = m_globalData->propertyNames->eval != *ident && m_globalData->propertyNames->arguments != *ident; @@ -216,28 +219,35 @@ struct Scope { void declareWrite(const Identifier* ident) { - ASSERT(strictMode()); + ASSERT(m_strictMode); m_writtenVariables.add(ident->impl()); } + void preventNewDecls() { m_allowsNewDecls = false; } + bool allowsNewDecls() const { return m_allowsNewDecls; } + bool declareParameter(const Identifier* ident) { bool isArguments = m_globalData->propertyNames->arguments == *ident; bool isValidStrictMode = m_declaredVariables.add(ident->ustring().impl()).isNewEntry && m_globalData->propertyNames->eval != *ident && !isArguments; m_isValidStrictMode = m_isValidStrictMode && isValidStrictMode; if (isArguments) - setFlags(ShadowsArgumentsFlag); + m_shadowsArguments = true; return isValidStrictMode; } - void useVariable(const Identifier* ident) + void useVariable(const Identifier* ident, bool isEval) { + m_usesEval |= isEval; m_usedVariables.add(ident->ustring().impl()); } + void setNeedsFullActivation() { m_needsFullActivation = true; } + bool collectFreeVariables(Scope* nestedScope, bool shouldTrackClosedVariables) { - setFlags(nestedScope->usesFlags()); + if (nestedScope->m_usesEval) + m_usesEval = true; IdentifierSet::iterator end = nestedScope->m_usedVariables.end(); for (IdentifierSet::iterator ptr = nestedScope->m_usedVariables.begin(); ptr != end; ++ptr) { if (nestedScope->m_declaredVariables.contains(*ptr)) @@ -269,7 +279,7 @@ struct Scope { void getCapturedVariables(IdentifierSet& capturedVariables) { - if (usesEval()) { + if (m_needsFullActivation || m_usesEval) { capturedVariables.swap(m_declaredVariables); return; } @@ -279,6 +289,11 @@ struct Scope { capturedVariables.add(*ptr); } } + void setStrictMode() { m_strictMode = true; } + bool strictMode() const { return m_strictMode; } + bool isValidStrictMode() const { return m_isValidStrictMode; } + bool shadowsArguments() const { return m_shadowsArguments; } + void copyCapturedVariablesToVector(const IdentifierSet& capturedVariables, Vector<RefPtr<StringImpl> >& vector) { IdentifierSet::iterator end = capturedVariables.end(); @@ -292,16 +307,20 @@ struct Scope { void saveFunctionInfo(SourceProviderCacheItem* info) { - ASSERT(isFunction()); - info->scopeFlags = m_scopeFlags; + ASSERT(m_isFunction); + info->usesEval = m_usesEval; + info->strictMode = m_strictMode; + info->needsFullActivation = m_needsFullActivation; copyCapturedVariablesToVector(m_writtenVariables, info->writtenVariables); copyCapturedVariablesToVector(m_usedVariables, info->usedVariables); } void restoreFunctionInfo(const SourceProviderCacheItem* info) { - ASSERT(isFunction()); - m_scopeFlags |= info->scopeFlags; + ASSERT(m_isFunction); + m_usesEval = info->usesEval; + m_strictMode = info->strictMode; + m_needsFullActivation = info->needsFullActivation; unsigned size = info->usedVariables.size(); for (unsigned i = 0; i < size; ++i) m_usedVariables.add(info->usedVariables[i]); @@ -312,7 +331,13 @@ struct Scope { private: const JSGlobalData* m_globalData; - ScopeFlags m_scopeFlags; + bool m_shadowsArguments : 1; + bool m_usesEval : 1; + bool m_needsFullActivation : 1; + bool m_allowsNewDecls : 1; + bool m_strictMode : 1; + bool m_isFunction : 1; + bool m_isFunctionBoundary : 1; bool m_isValidStrictMode : 1; int m_loopDepth; int m_switchDepth; @@ -402,14 +427,20 @@ private: Parser* m_parser; }; - ALWAYS_INLINE ScopeRef currentScope() + ScopeRef currentScope() { return ScopeRef(&m_scopeStack, m_scopeStack.size() - 1); } - ScopeRef pushScope(ScopeFlags scopeFlags) + ScopeRef pushScope() { - m_scopeStack.append(Scope(m_globalData, scopeFlags)); + bool isFunction = false; + bool isStrict = false; + if (!m_scopeStack.isEmpty()) { + isStrict = m_scopeStack.last().strictMode(); + isFunction = m_scopeStack.last().isFunction(); + } + m_scopeStack.append(Scope(m_globalData, isFunction, isStrict)); return currentScope(); } @@ -461,7 +492,7 @@ private: UString parseInner(); void didFinishParsing(SourceElements*, ParserArenaData<DeclarationStacks::VarStack>*, - ParserArenaData<DeclarationStacks::FunctionStack>*, ScopeFlags, + ParserArenaData<DeclarationStacks::FunctionStack>*, CodeFeatures, int, int, IdentifierSet&); // Used to determine type of error to report. @@ -792,13 +823,14 @@ private: m_errorMessage = UString(msg); } - ALWAYS_INLINE void startLoop() { currentScope()->startLoop(); } - ALWAYS_INLINE void endLoop() { currentScope()->endLoop(); } - ALWAYS_INLINE void startSwitch() { currentScope()->startSwitch(); } - ALWAYS_INLINE void endSwitch() { currentScope()->endSwitch(); } - ALWAYS_INLINE bool strictMode() { return currentScope()->strictMode(); } - ALWAYS_INLINE bool isValidStrictMode() { return currentScope()->isValidStrictMode(); } - ALWAYS_INLINE bool declareParameter(const Identifier* ident) { return currentScope()->declareParameter(ident); } + void startLoop() { currentScope()->startLoop(); } + void endLoop() { currentScope()->endLoop(); } + void startSwitch() { currentScope()->startSwitch(); } + void endSwitch() { currentScope()->endSwitch(); } + void setStrictMode() { currentScope()->setStrictMode(); } + bool strictMode() { return currentScope()->strictMode(); } + bool isValidStrictMode() { return currentScope()->isValidStrictMode(); } + bool declareParameter(const Identifier* ident) { return currentScope()->declareParameter(ident); } bool breakIsValid() { ScopeRef current = currentScope(); @@ -917,7 +949,7 @@ private: ParserArenaData<DeclarationStacks::VarStack>* m_varDeclarations; ParserArenaData<DeclarationStacks::FunctionStack>* m_funcDeclarations; IdentifierSet m_capturedVariables; - ScopeFlags m_scopeFlags; + CodeFeatures m_features; int m_numConstants; struct DepthManager { @@ -978,7 +1010,7 @@ PassRefPtr<ParsedNode> Parser<LexerType>::parse(JSGlobalObject* lexicalGlobalObj m_funcDeclarations ? &m_funcDeclarations->data : 0, m_capturedVariables, *m_source, - m_scopeFlags, + m_features, m_numConstants); result->setLoc(m_source->firstLine(), m_lastLine); } else if (lexicalGlobalObject) { |