Changeset 116372 in webkit for trunk/Source/JavaScriptCore/parser/Parser.h
- Timestamp:
- May 7, 2012, 4:35:52 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Parser.h
r115217 r116372 131 131 132 132 struct Scope { 133 Scope(const JSGlobalData* globalData, ScopeFlags scopeFlags)133 Scope(const JSGlobalData* globalData, bool isFunction, bool strictMode) 134 134 : m_globalData(globalData) 135 , m_scopeFlags(scopeFlags) 135 , m_shadowsArguments(false) 136 , m_usesEval(false) 137 , m_needsFullActivation(false) 138 , m_allowsNewDecls(true) 139 , m_strictMode(strictMode) 140 , m_isFunction(isFunction) 141 , m_isFunctionBoundary(false) 136 142 , m_isValidStrictMode(true) 137 143 , m_loopDepth(0) 138 144 , m_switchDepth(0) 139 145 { 140 ASSERT(!(scopeFlags & ~AllScopeModeFlags));141 146 } 142 147 143 148 Scope(const Scope& rhs) 144 149 : m_globalData(rhs.m_globalData) 145 , m_scopeFlags(rhs.m_scopeFlags) 150 , m_shadowsArguments(rhs.m_shadowsArguments) 151 , m_usesEval(rhs.m_usesEval) 152 , m_needsFullActivation(rhs.m_needsFullActivation) 153 , m_allowsNewDecls(rhs.m_allowsNewDecls) 154 , m_strictMode(rhs.m_strictMode) 155 , m_isFunction(rhs.m_isFunction) 156 , m_isFunctionBoundary(rhs.m_isFunctionBoundary) 146 157 , m_isValidStrictMode(rhs.m_isValidStrictMode) 147 158 , m_loopDepth(rhs.m_loopDepth) … … 157 168 } 158 169 } 159 160 ALWAYS_INLINE ScopeFlags scopeFlags() const { return m_scopeFlags; }161 ALWAYS_INLINE ScopeFlags modeFlags() const { return m_scopeFlags & AllScopeModeFlags; }162 ALWAYS_INLINE ScopeFlags usesFlags() const { return m_scopeFlags & AllScopeUsesFlags; }163 ALWAYS_INLINE void setFlags(ScopeFlags scopeFlags) { m_scopeFlags |= scopeFlags; }164 165 ALWAYS_INLINE bool usesEval() const { return m_scopeFlags & UsesEvalFlag; }166 ALWAYS_INLINE bool strictMode() const { return m_scopeFlags & StrictModeFlag; }167 ALWAYS_INLINE bool shadowsArguments() const { return m_scopeFlags & ShadowsArgumentsFlag; }168 ALWAYS_INLINE bool isFunction() const { return m_scopeFlags & FunctionModeFlag; }169 ALWAYS_INLINE bool isBlockScope() const { return m_scopeFlags & BlockScopeFlag; }170 ALWAYS_INLINE bool isFunctionBoundary() const { return isFunction() && !isBlockScope(); }171 172 ALWAYS_INLINE bool allowsNewDecls() const { return !isBlockScope(); }173 174 ALWAYS_INLINE bool isValidStrictMode() const { return m_isValidStrictMode; }175 170 176 171 void startSwitch() { m_switchDepth++; } … … 207 202 } 208 203 204 void setIsFunction() 205 { 206 m_isFunction = true; 207 m_isFunctionBoundary = true; 208 } 209 bool isFunction() { return m_isFunction; } 210 bool isFunctionBoundary() { return m_isFunctionBoundary; } 211 209 212 bool declareVariable(const Identifier* ident) 210 213 { … … 217 220 void declareWrite(const Identifier* ident) 218 221 { 219 ASSERT( strictMode());222 ASSERT(m_strictMode); 220 223 m_writtenVariables.add(ident->impl()); 221 224 } 225 226 void preventNewDecls() { m_allowsNewDecls = false; } 227 bool allowsNewDecls() const { return m_allowsNewDecls; } 222 228 223 229 bool declareParameter(const Identifier* ident) … … 227 233 m_isValidStrictMode = m_isValidStrictMode && isValidStrictMode; 228 234 if (isArguments) 229 setFlags(ShadowsArgumentsFlag);235 m_shadowsArguments = true; 230 236 return isValidStrictMode; 231 237 } 232 238 233 void useVariable(const Identifier* ident) 234 { 239 void useVariable(const Identifier* ident, bool isEval) 240 { 241 m_usesEval |= isEval; 235 242 m_usedVariables.add(ident->ustring().impl()); 236 243 } 237 244 245 void setNeedsFullActivation() { m_needsFullActivation = true; } 246 238 247 bool collectFreeVariables(Scope* nestedScope, bool shouldTrackClosedVariables) 239 248 { 240 setFlags(nestedScope->usesFlags()); 249 if (nestedScope->m_usesEval) 250 m_usesEval = true; 241 251 IdentifierSet::iterator end = nestedScope->m_usedVariables.end(); 242 252 for (IdentifierSet::iterator ptr = nestedScope->m_usedVariables.begin(); ptr != end; ++ptr) { … … 270 280 void getCapturedVariables(IdentifierSet& capturedVariables) 271 281 { 272 if ( usesEval()) {282 if (m_needsFullActivation || m_usesEval) { 273 283 capturedVariables.swap(m_declaredVariables); 274 284 return; … … 280 290 } 281 291 } 292 void setStrictMode() { m_strictMode = true; } 293 bool strictMode() const { return m_strictMode; } 294 bool isValidStrictMode() const { return m_isValidStrictMode; } 295 bool shadowsArguments() const { return m_shadowsArguments; } 296 282 297 void copyCapturedVariablesToVector(const IdentifierSet& capturedVariables, Vector<RefPtr<StringImpl> >& vector) 283 298 { … … 293 308 void saveFunctionInfo(SourceProviderCacheItem* info) 294 309 { 295 ASSERT(isFunction()); 296 info->scopeFlags = m_scopeFlags; 310 ASSERT(m_isFunction); 311 info->usesEval = m_usesEval; 312 info->strictMode = m_strictMode; 313 info->needsFullActivation = m_needsFullActivation; 297 314 copyCapturedVariablesToVector(m_writtenVariables, info->writtenVariables); 298 315 copyCapturedVariablesToVector(m_usedVariables, info->usedVariables); … … 301 318 void restoreFunctionInfo(const SourceProviderCacheItem* info) 302 319 { 303 ASSERT(isFunction()); 304 m_scopeFlags |= info->scopeFlags; 320 ASSERT(m_isFunction); 321 m_usesEval = info->usesEval; 322 m_strictMode = info->strictMode; 323 m_needsFullActivation = info->needsFullActivation; 305 324 unsigned size = info->usedVariables.size(); 306 325 for (unsigned i = 0; i < size; ++i) … … 313 332 private: 314 333 const JSGlobalData* m_globalData; 315 ScopeFlags m_scopeFlags; 334 bool m_shadowsArguments : 1; 335 bool m_usesEval : 1; 336 bool m_needsFullActivation : 1; 337 bool m_allowsNewDecls : 1; 338 bool m_strictMode : 1; 339 bool m_isFunction : 1; 340 bool m_isFunctionBoundary : 1; 316 341 bool m_isValidStrictMode : 1; 317 342 int m_loopDepth; … … 403 428 }; 404 429 405 ALWAYS_INLINEScopeRef currentScope()430 ScopeRef currentScope() 406 431 { 407 432 return ScopeRef(&m_scopeStack, m_scopeStack.size() - 1); 408 433 } 409 434 410 ScopeRef pushScope(ScopeFlags scopeFlags) 411 { 412 m_scopeStack.append(Scope(m_globalData, scopeFlags)); 435 ScopeRef pushScope() 436 { 437 bool isFunction = false; 438 bool isStrict = false; 439 if (!m_scopeStack.isEmpty()) { 440 isStrict = m_scopeStack.last().strictMode(); 441 isFunction = m_scopeStack.last().isFunction(); 442 } 443 m_scopeStack.append(Scope(m_globalData, isFunction, isStrict)); 413 444 return currentScope(); 414 445 } … … 462 493 463 494 void didFinishParsing(SourceElements*, ParserArenaData<DeclarationStacks::VarStack>*, 464 ParserArenaData<DeclarationStacks::FunctionStack>*, ScopeFlags,495 ParserArenaData<DeclarationStacks::FunctionStack>*, CodeFeatures, 465 496 int, int, IdentifierSet&); 466 497 … … 793 824 } 794 825 795 ALWAYS_INLINE void startLoop() { currentScope()->startLoop(); } 796 ALWAYS_INLINE void endLoop() { currentScope()->endLoop(); } 797 ALWAYS_INLINE void startSwitch() { currentScope()->startSwitch(); } 798 ALWAYS_INLINE void endSwitch() { currentScope()->endSwitch(); } 799 ALWAYS_INLINE bool strictMode() { return currentScope()->strictMode(); } 800 ALWAYS_INLINE bool isValidStrictMode() { return currentScope()->isValidStrictMode(); } 801 ALWAYS_INLINE bool declareParameter(const Identifier* ident) { return currentScope()->declareParameter(ident); } 826 void startLoop() { currentScope()->startLoop(); } 827 void endLoop() { currentScope()->endLoop(); } 828 void startSwitch() { currentScope()->startSwitch(); } 829 void endSwitch() { currentScope()->endSwitch(); } 830 void setStrictMode() { currentScope()->setStrictMode(); } 831 bool strictMode() { return currentScope()->strictMode(); } 832 bool isValidStrictMode() { return currentScope()->isValidStrictMode(); } 833 bool declareParameter(const Identifier* ident) { return currentScope()->declareParameter(ident); } 802 834 bool breakIsValid() 803 835 { … … 918 950 ParserArenaData<DeclarationStacks::FunctionStack>* m_funcDeclarations; 919 951 IdentifierSet m_capturedVariables; 920 ScopeFlags m_scopeFlags;952 CodeFeatures m_features; 921 953 int m_numConstants; 922 954 … … 979 1011 m_capturedVariables, 980 1012 *m_source, 981 m_ scopeFlags,1013 m_features, 982 1014 m_numConstants); 983 1015 result->setLoc(m_source->firstLine(), m_lastLine);
Note:
See TracChangeset
for help on using the changeset viewer.