Changeset 67769 in webkit for trunk/JavaScriptCore/parser
- Timestamp:
- Sep 17, 2010, 6:06:59 PM (15 years ago)
- Location:
- trunk/JavaScriptCore/parser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/JSParser.cpp
r67583 r67769 68 68 class JSParser { 69 69 public: 70 JSParser(Lexer*, JSGlobalData*, SourceProvider*);70 JSParser(Lexer*, JSGlobalData*, FunctionParameters*, SourceProvider*); 71 71 bool parseProgram(); 72 72 private: … … 162 162 template <class TreeBuilder> ALWAYS_INLINE TreeConstDeclList parseConstDeclarationList(TreeBuilder& context); 163 163 enum FunctionRequirements { FunctionNoRequirements, FunctionNeedsName }; 164 template <FunctionRequirements, class TreeBuilder> bool parseFunctionInfo(TreeBuilder&, const Identifier*&, TreeFormalParameterList&, TreeFunctionBody&, int& openBrace, int& closeBrace, int& bodyStartLine);164 template <FunctionRequirements, bool nameIsInContainingScope, class TreeBuilder> bool parseFunctionInfo(TreeBuilder&, const Identifier*&, TreeFormalParameterList&, TreeFunctionBody&, int& openBrace, int& closeBrace, int& bodyStartLine); 165 165 ALWAYS_INLINE int isBinaryOperator(JSTokenType token); 166 166 bool allowAutomaticSemicolon(); … … 204 204 Scope() 205 205 : m_usesEval(false) 206 , m_needsFullActivation(false) 206 207 { 207 208 } … … 218 219 } 219 220 220 void collectFreeVariables(Scope* nestedScope, bool shouldTrackCapturedVariables) 221 void needsFullActivation() { m_needsFullActivation = true; } 222 223 void collectFreeVariables(Scope* nestedScope, bool shouldTrackClosedVariables) 221 224 { 222 225 if (nestedScope->m_usesEval) … … 227 230 continue; 228 231 m_usedVariables.add(*ptr); 229 if (shouldTrackC apturedVariables)230 m_c apturedVariables.add(*ptr);232 if (shouldTrackClosedVariables) 233 m_closedVariables.add(*ptr); 231 234 } 232 235 } 233 236 234 IdentifierSet& capturedVariables() { return m_capturedVariables; } 237 void getCapturedVariables(IdentifierSet& capturedVariables) 238 { 239 if (m_needsFullActivation || m_usesEval) { 240 capturedVariables.swap(m_declaredVariables); 241 return; 242 } 243 for (IdentifierSet::iterator ptr = m_closedVariables.begin(); ptr != m_closedVariables.end(); ++ptr) { 244 if (!m_declaredVariables.contains(*ptr)) 245 continue; 246 capturedVariables.add(*ptr); 247 } 248 } 235 249 private: 236 250 bool m_usesEval; 251 bool m_needsFullActivation; 237 252 IdentifierSet m_declaredVariables; 238 253 IdentifierSet m_usedVariables; 239 IdentifierSet m_c apturedVariables;254 IdentifierSet m_closedVariables; 240 255 }; 241 256 … … 266 281 } 267 282 268 void popScope(ScopeRef scope, bool shouldTrackC apturedVariables)283 void popScope(ScopeRef scope, bool shouldTrackClosedVariables) 269 284 { 270 285 ASSERT_UNUSED(scope, scope.index() == m_scopeStack.size() - 1); 271 286 ASSERT(m_scopeStack.size() > 1); 272 m_scopeStack[m_scopeStack.size() - 2].collectFreeVariables(&m_scopeStack.last(), shouldTrackC apturedVariables);287 m_scopeStack[m_scopeStack.size() - 2].collectFreeVariables(&m_scopeStack.last(), shouldTrackClosedVariables); 273 288 m_scopeStack.removeLast(); 274 289 } … … 277 292 }; 278 293 279 int jsParse(JSGlobalData* globalData, const SourceCode* source)280 { 281 JSParser parser(globalData->lexer, globalData, source->provider());294 int jsParse(JSGlobalData* globalData, FunctionParameters* parameters, const SourceCode* source) 295 { 296 JSParser parser(globalData->lexer, globalData, parameters, source->provider()); 282 297 return parser.parseProgram(); 283 298 } 284 299 285 JSParser::JSParser(Lexer* lexer, JSGlobalData* globalData, SourceProvider* provider)300 JSParser::JSParser(Lexer* lexer, JSGlobalData* globalData, FunctionParameters* parameters, SourceProvider* provider) 286 301 : m_lexer(lexer) 287 302 , m_endAddress(0) … … 299 314 next(); 300 315 m_lexer->setLastLineNumber(tokenLine()); 316 ScopeRef scope = pushScope(); 317 if (parameters) { 318 for (unsigned i = 0; i < parameters->size(); i++) 319 scope->declareVariable(¶meters->at(i)); 320 } 301 321 } 302 322 … … 304 324 { 305 325 ASTBuilder context(m_globalData, m_lexer); 306 ScopeRef scope = pushScope();326 ScopeRef scope = currentScope(); 307 327 SourceElements* sourceElements = parseSourceElements<ASTBuilder>(context); 308 328 if (!sourceElements || !consume(EOFTOK)) 309 329 return true; 330 IdentifierSet capturedVariables; 331 scope->getCapturedVariables(capturedVariables); 310 332 m_globalData->parser->didFinishParsing(sourceElements, context.varDeclarations(), context.funcDeclarations(), context.features(), 311 m_lastLine, context.numConstants(), scope->capturedVariables());333 m_lastLine, context.numConstants(), capturedVariables); 312 334 return false; 313 335 } … … 631 653 { 632 654 ASSERT(match(WITH)); 655 currentScope()->needsFullActivation(); 633 656 int startLine = tokenLine(); 634 657 next(); … … 729 752 730 753 if (match(CATCH)) { 754 currentScope()->needsFullActivation(); 731 755 next(); 732 756 consumeOrFail(OPENPAREN); … … 864 888 } 865 889 866 template <JSParser::FunctionRequirements requirements, class TreeBuilder> bool JSParser::parseFunctionInfo(TreeBuilder& context, const Identifier*& name, TreeFormalParameterList& parameters, TreeFunctionBody& body, int& openBracePos, int& closeBracePos, int& bodyStartLine)890 template <JSParser::FunctionRequirements requirements, bool nameIsInContainingScope, class TreeBuilder> bool JSParser::parseFunctionInfo(TreeBuilder& context, const Identifier*& name, TreeFormalParameterList& parameters, TreeFunctionBody& body, int& openBracePos, int& closeBracePos, int& bodyStartLine) 867 891 { 868 892 ScopeRef functionScope = pushScope(); … … 870 894 name = m_token.m_data.ident; 871 895 next(); 872 functionScope->declareVariable(name); 896 if (!nameIsInContainingScope) 897 functionScope->declareVariable(name); 873 898 } else if (requirements == FunctionNeedsName) 874 899 return false; … … 907 932 int closeBracePos = 0; 908 933 int bodyStartLine = 0; 909 failIfFalse( parseFunctionInfo<FunctionNeedsName>(context, name, parameters, body, openBracePos, closeBracePos, bodyStartLine));934 failIfFalse((parseFunctionInfo<FunctionNeedsName, true>(context, name, parameters, body, openBracePos, closeBracePos, bodyStartLine))); 910 935 failIfFalse(name); 911 936 currentScope()->declareVariable(name); … … 1200 1225 else 1201 1226 fail(); 1202 failIfFalse( parseFunctionInfo<FunctionNeedsName>(context, accessorName, parameters, body, openBracePos, closeBracePos, bodyStartLine));1227 failIfFalse((parseFunctionInfo<FunctionNeedsName, false>(context, accessorName, parameters, body, openBracePos, closeBracePos, bodyStartLine))); 1203 1228 return context.template createGetterOrSetterProperty<complete>(type, accessorName, parameters, body, openBracePos, closeBracePos, bodyStartLine, m_lastLine); 1204 1229 } … … 1452 1477 int bodyStartLine = 0; 1453 1478 next(); 1454 failIfFalse( parseFunctionInfo<FunctionNoRequirements>(context, name, parameters, body, openBracePos, closeBracePos, bodyStartLine));1479 failIfFalse((parseFunctionInfo<FunctionNoRequirements, false>(context, name, parameters, body, openBracePos, closeBracePos, bodyStartLine))); 1455 1480 base = context.createFunctionExpr(name, body, parameters, openBracePos, closeBracePos, bodyStartLine, m_lastLine); 1456 1481 } else -
trunk/JavaScriptCore/parser/JSParser.h
r63566 r67769 29 29 namespace JSC { 30 30 31 class FunctionParameters; 31 32 class Identifier; 32 33 class JSGlobalData; … … 155 156 }; 156 157 157 int jsParse(JSGlobalData*, const SourceCode*);158 int jsParse(JSGlobalData*, FunctionParameters*, const SourceCode*); 158 159 } 159 160 #endif // JSParser_h -
trunk/JavaScriptCore/parser/Parser.cpp
r67583 r67769 36 36 namespace JSC { 37 37 38 void Parser::parse(JSGlobalData* globalData, int* errLine, UString* errMsg)38 void Parser::parse(JSGlobalData* globalData, FunctionParameters* parameters, int* errLine, UString* errMsg) 39 39 { 40 40 m_sourceElements = 0; … … 54 54 lexer.setCode(*m_source, m_arena); 55 55 56 int parseError = jsParse(globalData, m_source);56 int parseError = jsParse(globalData, parameters, m_source); 57 57 int lineNumber = lexer.lineNumber(); 58 58 bool lexError = lexer.sawError(); -
trunk/JavaScriptCore/parser/Parser.h
r67583 r67769 49 49 public: 50 50 template <class ParsedNode> 51 PassRefPtr<ParsedNode> parse(JSGlobalData* globalData, JSGlobalObject* lexicalGlobalObject, Debugger*, ExecState*, const SourceCode& source, JSObject** exception);51 PassRefPtr<ParsedNode> parse(JSGlobalData* globalData, JSGlobalObject* lexicalGlobalObject, Debugger*, ExecState*, const SourceCode& source, FunctionParameters*, JSObject** exception); 52 52 53 53 void didFinishParsing(SourceElements*, ParserArenaData<DeclarationStacks::VarStack>*, … … 58 58 59 59 private: 60 void parse(JSGlobalData*, int* errLine, UString* errMsg);60 void parse(JSGlobalData*, FunctionParameters*, int* errLine, UString* errMsg); 61 61 62 62 // Used to determine type of error to report. … … 76 76 77 77 template <class ParsedNode> 78 PassRefPtr<ParsedNode> Parser::parse(JSGlobalData* globalData, JSGlobalObject* lexicalGlobalObject, Debugger* debugger, ExecState* debuggerExecState, const SourceCode& source, JSObject** exception)78 PassRefPtr<ParsedNode> Parser::parse(JSGlobalData* globalData, JSGlobalObject* lexicalGlobalObject, Debugger* debugger, ExecState* debuggerExecState, const SourceCode& source, FunctionParameters* parameters, JSObject** exception) 79 79 { 80 80 ASSERT(exception && !*exception); … … 85 85 if (ParsedNode::scopeIsFunction) 86 86 globalData->lexer->setIsReparsing(); 87 parse(globalData, &errLine, &errMsg);87 parse(globalData, parameters, &errLine, &errMsg); 88 88 89 89 RefPtr<ParsedNode> result;
Note:
See TracChangeset
for help on using the changeset viewer.