Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: src/preparser.h

Issue 5295004: Preparser extracted into separate files that can be compiled to a library. (Closed)
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 typedef int SourceElements; 69 typedef int SourceElements;
70 typedef int Expression; 70 typedef int Expression;
71 typedef int Statement; 71 typedef int Statement;
72 typedef int Identifier; 72 typedef int Identifier;
73 typedef int Arguments; 73 typedef int Arguments;
74 74
75 75
76 class PreParser { 76 class PreParser {
77 public: 77 public:
78 enum PreParseResult {
79 kPreParseStackOverflow,
80 kPreParseSuccess
81 };
82
78 PreParser() : scope_(NULL), allow_lazy_(true) { } 83 PreParser() : scope_(NULL), allow_lazy_(true) { }
fschneider 2010/11/29 12:27:35 stack_limit_ and stack_overflow_ should be initial
Lasse Reichstein 2010/11/29 13:06:40 Not really. In fact, allow_lazy_ shouldn't be init
79 ~PreParser() { } 84 ~PreParser() { }
80 85
81 // Pre-parse the program from the character stream; returns true on 86 // Pre-parse the program from the character stream; returns true on
82 // success (even if parsing failed, the pre-parse data successfully 87 // success (even if parsing failed, the pre-parse data successfully
83 // captured the syntax error), and false if a stack-overflow happened 88 // captured the syntax error), and false if a stack-overflow happened
84 // during parsing. 89 // during parsing.
85 bool PreParseProgram(i::JavaScriptScanner* scanner, 90 PreParseResult PreParseProgram(i::JavaScriptScanner* scanner,
86 i::ParserRecorder* log, 91 i::ParserRecorder* log,
87 bool allow_lazy) { 92 bool allow_lazy,
93 uintptr_t stack_limit) {
88 allow_lazy_ = allow_lazy; 94 allow_lazy_ = allow_lazy;
89 scanner_ = scanner; 95 scanner_ = scanner;
90 log_ = log; 96 log_ = log;
97 stack_limit_ = stack_limit;
98 stack_overflow_ = false;
91 Scope top_scope(&scope_, kTopLevelScope); 99 Scope top_scope(&scope_, kTopLevelScope);
92 bool ok = true; 100 bool ok = true;
93 ParseSourceElements(i::Token::EOS, &ok); 101 ParseSourceElements(i::Token::EOS, &ok);
94 bool stack_overflow = scanner_->stack_overflow(); 102 if (!ok && !stack_overflow_) {
95 if (!ok && !stack_overflow) {
96 ReportUnexpectedToken(scanner_->current_token()); 103 ReportUnexpectedToken(scanner_->current_token());
97 } 104 }
98 return !stack_overflow; 105 return stack_overflow_ ? kPreParseStackOverflow : kPreParseSuccess;
99 } 106 }
100 107
101 private: 108 private:
102 enum ScopeType { 109 enum ScopeType {
103 kTopLevelScope, 110 kTopLevelScope,
104 kFunctionScope 111 kFunctionScope
105 }; 112 };
106 113
107 class Scope { 114 class Scope {
108 public: 115 public:
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 Expression ParseFunctionLiteral(bool* ok); 202 Expression ParseFunctionLiteral(bool* ok);
196 203
197 Identifier ParseIdentifier(bool* ok); 204 Identifier ParseIdentifier(bool* ok);
198 Identifier ParseIdentifierName(bool* ok); 205 Identifier ParseIdentifierName(bool* ok);
199 Identifier ParseIdentifierOrGetOrSet(bool* is_get, bool* is_set, bool* ok); 206 Identifier ParseIdentifierOrGetOrSet(bool* is_get, bool* is_set, bool* ok);
200 207
201 Identifier GetIdentifierSymbol(); 208 Identifier GetIdentifierSymbol();
202 unsigned int HexDigitValue(char digit); 209 unsigned int HexDigitValue(char digit);
203 Expression GetStringSymbol(); 210 Expression GetStringSymbol();
204 211
205 212 i::Token::Value peek() {
206 i::Token::Value peek() { return scanner_->peek(); } 213 if (stack_overflow_) return i::Token::ILLEGAL;
207 i::Token::Value Next() { 214 return scanner_->peek();
208 i::Token::Value next = scanner_->Next();
209 return next;
210 } 215 }
211 216
212 void Consume(i::Token::Value token) { 217 i::Token::Value Next() {
213 Next(); 218 if (stack_overflow_) return i::Token::ILLEGAL;
219 {
220 int marker;
221 if (reinterpret_cast<uintptr_t>(&marker) < stack_limit_) {
222 // Further calls to peek/Next will return illegal token.
223 // The current one will still be returned. It might already
224 // have been seen using peek.
225 stack_overflow_ = true;
226 }
227 }
228 return scanner_->Next();
214 } 229 }
215 230
231 void Consume(i::Token::Value token) { Next(); }
232
216 void Expect(i::Token::Value token, bool* ok) { 233 void Expect(i::Token::Value token, bool* ok) {
217 if (Next() != token) { 234 if (Next() != token) {
218 *ok = false; 235 *ok = false;
219 } 236 }
220 } 237 }
221 238
222 bool Check(i::Token::Value token) { 239 bool Check(i::Token::Value token) {
223 i::Token::Value next = peek(); 240 i::Token::Value next = peek();
224 if (next == token) { 241 if (next == token) {
225 Consume(next); 242 Consume(next);
226 return true; 243 return true;
227 } 244 }
228 return false; 245 return false;
229 } 246 }
230 void ExpectSemicolon(bool* ok); 247 void ExpectSemicolon(bool* ok);
231 248
232 static int Precedence(i::Token::Value tok, bool accept_IN); 249 static int Precedence(i::Token::Value tok, bool accept_IN);
233 250
234 i::JavaScriptScanner* scanner_; 251 i::JavaScriptScanner* scanner_;
235 i::ParserRecorder* log_; 252 i::ParserRecorder* log_;
236 Scope* scope_; 253 Scope* scope_;
254 uintptr_t stack_limit_;
255 bool stack_overflow_;
237 bool allow_lazy_; 256 bool allow_lazy_;
238 }; 257 };
239 } } // v8::preparser 258 } } // v8::preparser
240 259
241 #endif // V8_PREPARSER_H 260 #endif // V8_PREPARSER_H
OLDNEW
« include/v8-preparser.h ('K') | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698