28 #ifndef V8_PREPARSER_H
29 #define V8_PREPARSER_H
58 namespace i = v8::internal;
63 : unicode_constants_(constants),
87 static bool Match(
void* first,
void* second);
96 static const int kBufferSize = 100;
103 char number_buffer_[kBufferSize];
117 uintptr_t stack_limit,
119 bool allow_natives_syntax,
124 stack_limit_(stack_limit),
125 strict_mode_violation_location_(i::Scanner::Location::invalid()),
126 strict_mode_violation_type_(
NULL),
127 stack_overflow_(
false),
128 allow_lazy_(allow_lazy),
129 allow_modules_(allow_modules),
130 allow_natives_syntax_(allow_natives_syntax),
131 parenthesized_function_(
false),
132 harmony_scoping_(scanner->HarmonyScoping()) { }
143 uintptr_t stack_limit) {
147 return PreParser(scanner, log, stack_limit, allow_lazy,
148 allow_natives_syntax, allow_modules).PreParse();
185 bool HasConflict(
int type1,
int type2) {
return (type1 & type2) != 0; }
186 bool IsDataDataConflict(
int type1,
int type2) {
187 return ((type1 & type2) & kValueFlag) != 0;
189 bool IsDataAccessorConflict(
int type1,
int type2) {
190 return ((type1 ^ type2) & kValueFlag) != 0;
192 bool IsAccessorAccessorConflict(
int type1,
int type2) {
193 return ((type1 | type2) & kValueFlag) == 0;
197 void CheckDuplicate(DuplicateFinder* finder,
212 enum VariableDeclarationContext {
219 enum VariableDeclarationProperties {
228 static Identifier Default() {
229 return Identifier(kUnknownIdentifier);
231 static Identifier Eval() {
232 return Identifier(kEvalIdentifier);
234 static Identifier Arguments() {
235 return Identifier(kArgumentsIdentifier);
237 static Identifier FutureReserved() {
238 return Identifier(kFutureReservedIdentifier);
240 static Identifier FutureStrictReserved() {
241 return Identifier(kFutureStrictReservedIdentifier);
243 bool IsEval() {
return type_ == kEvalIdentifier; }
244 bool IsArguments() {
return type_ == kArgumentsIdentifier; }
245 bool IsEvalOrArguments() {
return type_ >= kEvalIdentifier; }
246 bool IsFutureReserved() {
return type_ == kFutureReservedIdentifier; }
247 bool IsFutureStrictReserved() {
248 return type_ == kFutureStrictReservedIdentifier;
250 bool IsValidStrictVariable() {
return type_ == kUnknownIdentifier; }
255 kFutureReservedIdentifier,
256 kFutureStrictReservedIdentifier,
260 explicit Identifier(Type
type) :
type_(type) { }
263 friend class Expression;
275 static Expression Default() {
276 return Expression(kUnknownExpression);
279 static Expression FromIdentifier(Identifier
id) {
280 return Expression(kIdentifierFlag | (
id.
type_ << kIdentifierShift));
283 static Expression StringLiteral() {
284 return Expression(kUnknownStringLiteral);
287 static Expression UseStrictStringLiteral() {
288 return Expression(kUseStrictString);
291 static Expression This() {
292 return Expression(kThisExpression);
295 static Expression ThisProperty() {
296 return Expression(kThisPropertyExpression);
299 static Expression StrictFunction() {
300 return Expression(kStrictFunctionExpression);
303 bool IsIdentifier() {
304 return (code_ & kIdentifierFlag) != 0;
308 PreParser::Identifier AsIdentifier() {
309 return PreParser::Identifier(
310 static_cast<PreParser::Identifier::Type>(code_ >> kIdentifierShift));
313 bool IsParenthesized() {
315 return (code_ & 7) > 4;
318 bool IsRawIdentifier() {
319 return !IsParenthesized() && IsIdentifier();
322 bool IsStringLiteral() {
return (code_ & kStringLiteralFlag) != 0; }
324 bool IsRawStringLiteral() {
325 return !IsParenthesized() && IsStringLiteral();
328 bool IsUseStrictLiteral() {
329 return (code_ & kStringLiteralMask) == kUseStrictString;
333 return code_ == kThisExpression;
336 bool IsThisProperty() {
337 return code_ == kThisPropertyExpression;
340 bool IsStrictFunction() {
341 return code_ == kStrictFunctionExpression;
344 Expression Parenthesize() {
345 int type = code_ & 3;
350 return Expression(code_ | kParentesizedExpressionFlag);
366 kUnknownExpression = 0,
369 kIdentifierShift = 3,
371 kStringLiteralFlag = 2,
372 kUnknownStringLiteral = kStringLiteralFlag,
373 kUseStrictString = kStringLiteralFlag | 8,
374 kStringLiteralMask = kUseStrictString,
376 kParentesizedExpressionFlag = 4,
380 kThisPropertyExpression = 8,
381 kStrictFunctionExpression = 12
384 explicit Expression(
int expression_code) : code_(expression_code) { }
391 static Statement Default() {
392 return Statement(kUnknownStatement);
395 static Statement FunctionDeclaration() {
396 return Statement(kFunctionDeclaration);
402 static Statement ExpressionStatement(Expression expression) {
403 if (!expression.IsParenthesized()) {
404 if (expression.IsUseStrictLiteral()) {
405 return Statement(kUseStrictExpressionStatement);
407 if (expression.IsStringLiteral()) {
408 return Statement(kStringLiteralExpressionStatement);
414 bool IsStringLiteral() {
415 return code_ != kUnknownStatement;
418 bool IsUseStrictLiteral() {
419 return code_ == kUseStrictExpressionStatement;
422 bool IsFunctionDeclaration() {
423 return code_ == kFunctionDeclaration;
429 kStringLiteralExpressionStatement,
430 kUseStrictExpressionStatement,
434 explicit Statement(Type code) : code_(code) {}
438 enum SourceElements {
439 kUnknownSourceElements
442 typedef int Arguments;
446 Scope(Scope** variable, ScopeType
type)
447 : variable_(variable),
450 materialized_literal_count_(0),
451 expected_properties_(0),
452 with_nesting_count_(0),
457 ~Scope() { *variable_ = prev_; }
458 void NextMaterializedLiteralIndex() { materialized_literal_count_++; }
459 void AddProperty() { expected_properties_++; }
461 int expected_properties() {
return expected_properties_; }
462 int materialized_literal_count() {
return materialized_literal_count_; }
463 bool IsInsideWith() {
return with_nesting_count_ != 0; }
464 bool is_classic_mode() {
468 return language_mode_;
471 language_mode_ = language_mode;
477 scope->with_nesting_count_++;
488 Scope**
const variable_;
490 const ScopeType
type_;
491 int materialized_literal_count_;
492 int expected_properties_;
493 int with_nesting_count_;
500 Scope top_scope(&scope_, kTopLevelScope);
503 ParseSourceElements(i::Token::EOS, &ok);
507 }
else if (!scope_->is_classic_mode()) {
515 void ReportMessageAt(i::Scanner::Location location,
517 const char* name_opt) {
518 log_->
LogMessage(location.beg_pos, location.end_pos, type, name_opt);
520 void ReportMessageAt(
int start_pos,
523 const char* name_opt) {
524 log_->
LogMessage(start_pos, end_pos, type, name_opt);
527 void CheckOctalLiteral(
int beg_pos,
int end_pos,
bool* ok);
533 Statement ParseSourceElement(
bool* ok);
534 SourceElements ParseSourceElements(
int end_token,
bool* ok);
535 Statement ParseStatement(
bool* ok);
536 Statement ParseFunctionDeclaration(
bool* ok);
537 Statement ParseBlock(
bool* ok);
538 Statement ParseVariableStatement(VariableDeclarationContext var_context,
540 Statement ParseVariableDeclarations(VariableDeclarationContext var_context,
541 VariableDeclarationProperties* decl_props,
544 Statement ParseExpressionOrLabelledStatement(
bool* ok);
545 Statement ParseIfStatement(
bool* ok);
546 Statement ParseContinueStatement(
bool* ok);
547 Statement ParseBreakStatement(
bool* ok);
548 Statement ParseReturnStatement(
bool* ok);
549 Statement ParseWithStatement(
bool* ok);
550 Statement ParseSwitchStatement(
bool* ok);
551 Statement ParseDoWhileStatement(
bool* ok);
552 Statement ParseWhileStatement(
bool* ok);
553 Statement ParseForStatement(
bool* ok);
554 Statement ParseThrowStatement(
bool* ok);
555 Statement ParseTryStatement(
bool* ok);
556 Statement ParseDebuggerStatement(
bool* ok);
558 Expression ParseExpression(
bool accept_IN,
bool* ok);
559 Expression ParseAssignmentExpression(
bool accept_IN,
bool* ok);
560 Expression ParseConditionalExpression(
bool accept_IN,
bool* ok);
561 Expression ParseBinaryExpression(
int prec,
bool accept_IN,
bool* ok);
562 Expression ParseUnaryExpression(
bool* ok);
563 Expression ParsePostfixExpression(
bool* ok);
564 Expression ParseLeftHandSideExpression(
bool* ok);
565 Expression ParseNewExpression(
bool* ok);
566 Expression ParseMemberExpression(
bool* ok);
567 Expression ParseMemberWithNewPrefixesExpression(
unsigned new_count,
bool* ok);
568 Expression ParsePrimaryExpression(
bool* ok);
569 Expression ParseArrayLiteral(
bool* ok);
570 Expression ParseObjectLiteral(
bool* ok);
571 Expression ParseRegExpLiteral(
bool seen_equal,
bool* ok);
572 Expression ParseV8Intrinsic(
bool* ok);
574 Arguments ParseArguments(
bool* ok);
575 Expression ParseFunctionLiteral(
bool* ok);
576 void ParseLazyFunctionLiteralBody(
bool* ok);
578 Identifier ParseIdentifier(
bool* ok);
579 Identifier ParseIdentifierName(
bool* ok);
580 Identifier ParseIdentifierNameOrGetOrSet(
bool* is_get,
587 Identifier GetIdentifierSymbol();
589 Expression GetStringSymbol();
592 if (stack_overflow_)
return i::Token::ILLEGAL;
593 return scanner_->
peek();
597 if (stack_overflow_)
return i::Token::ILLEGAL;
600 if (reinterpret_cast<uintptr_t>(&marker) < stack_limit_) {
604 stack_overflow_ =
true;
607 return scanner_->
Next();
610 bool peek_any_identifier();
613 scope_->set_language_mode(language_mode);
616 bool is_classic_mode() {
620 bool is_extended_mode() {
629 if (Next() != token) {
642 void ExpectSemicolon(
bool* ok);
646 void SetStrictModeViolation(i::Scanner::Location,
650 void CheckDelayedStrictModeViolation(
int beg_pos,
int end_pos,
bool* ok);
652 void StrictModeIdentifierViolation(i::Scanner::Location,
653 const char* eval_args_type,
654 Identifier identifier,
660 uintptr_t stack_limit_;
661 i::Scanner::Location strict_mode_violation_location_;
662 const char* strict_mode_violation_type_;
663 bool stack_overflow_;
666 bool allow_natives_syntax_;
667 bool parenthesized_function_;
668 bool harmony_scoping_;
672 #endif // V8_PREPARSER_H
DuplicateFinder(i::UnicodeCache *constants)
int AddNumber(i::Vector< const char > key, int value)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
int AddUtf16Symbol(i::Vector< const uint16_t > key, int value)
int AddAsciiSymbol(i::Vector< const char > key, int value)
PreParseResult PreParseLazyFunction(i::LanguageMode mode, i::ParserRecorder *log)
Location location() const
static PreParseResult PreParseProgram(i::Scanner *scanner, i::ParserRecorder *log, int flags, uintptr_t stack_limit)
Token::Value peek() const
Token::Value current_token()
PreParser(i::Scanner *scanner, i::ParserRecorder *log, uintptr_t stack_limit, bool allow_lazy, bool allow_natives_syntax, bool allow_modules)
virtual void LogMessage(int start, int end, const char *message, const char *argument_opt)=0
Location peek_location() const