1
// Copyright 2011 the V8 project authors. All rights reserved.
1
// Copyright 2012 the V8 project authors. All rights reserved.
2
2
// Redistribution and use in source and binary forms, with or without
3
3
// modification, are permitted provided that the following conditions are
66
67
int AddAsciiSymbol(i::Vector<const char> key, int value);
67
int AddUC16Symbol(i::Vector<const uint16_t> key, int value);
68
int AddUtf16Symbol(i::Vector<const uint16_t> key, int value);
68
69
// Add a a number literal by converting it (if necessary)
69
70
// to the string that ToString(ToNumber(literal)) would generate.
70
71
// and then adding that string with AddAsciiSymbol.
115
PreParser(i::Scanner* scanner,
116
i::ParserRecorder* log,
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()) { }
115
136
// Pre-parse the program from the character stream; returns true on
116
137
// success (even if parsing failed, the pre-parse data successfully
117
138
// captured the syntax error), and false if a stack-overflow happened
118
139
// during parsing.
119
static PreParseResult PreParseProgram(i::JavaScriptScanner* scanner,
140
static PreParseResult PreParseProgram(i::Scanner* scanner,
120
141
i::ParserRecorder* log,
122
143
uintptr_t stack_limit) {
123
return PreParser(scanner, log, stack_limit, allow_lazy).PreParse();
144
bool allow_lazy = (flags & i::kAllowLazy) != 0;
145
bool allow_natives_syntax = (flags & i::kAllowNativesSyntax) != 0;
146
bool allow_modules = (flags & i::kAllowModules) != 0;
147
return PreParser(scanner, log, stack_limit, allow_lazy,
148
allow_natives_syntax, allow_modules).PreParse();
151
// Parses a single function literal, from the opening parentheses before
152
// parameters to the closing brace after the body.
153
// Returns a FunctionEntry describing the body of the function in enough
154
// detail that it can be lazily compiled.
155
// The scanner is expected to have matched the "function" keyword and
156
// parameters, and have consumed the initial '{'.
157
// At return, unless an error occurred, the scanner is positioned before the
159
PreParseResult PreParseLazyFunction(i::LanguageMode mode,
160
i::ParserRecorder* log);
127
163
// Used to detect duplicates in object literals. Each of the values
128
164
// kGetterProperty, kSetterProperty and kValueProperty represents
418
461
int expected_properties() { return expected_properties_; }
419
462
int materialized_literal_count() { return materialized_literal_count_; }
420
463
bool IsInsideWith() { return with_nesting_count_ != 0; }
421
bool is_strict() { return strict_; }
422
void set_strict() { strict_ = true; }
423
void EnterWith() { with_nesting_count_++; }
424
void LeaveWith() { with_nesting_count_--; }
464
bool is_classic_mode() {
465
return language_mode_ == i::CLASSIC_MODE;
467
i::LanguageMode language_mode() {
468
return language_mode_;
470
void set_language_mode(i::LanguageMode language_mode) {
471
language_mode_ = language_mode;
476
explicit InsideWith(Scope* scope) : scope_(scope) {
477
scope->with_nesting_count_++;
480
~InsideWith() { scope_->with_nesting_count_--; }
484
DISALLOW_COPY_AND_ASSIGN(InsideWith);
427
488
Scope** const variable_;
430
491
int materialized_literal_count_;
431
492
int expected_properties_;
432
493
int with_nesting_count_;
494
i::LanguageMode language_mode_;
436
// Private constructor only used in PreParseProgram.
437
PreParser(i::JavaScriptScanner* scanner,
438
i::ParserRecorder* log,
439
uintptr_t stack_limit,
444
stack_limit_(stack_limit),
445
strict_mode_violation_location_(i::Scanner::Location::invalid()),
446
strict_mode_violation_type_(NULL),
447
stack_overflow_(false),
449
parenthesized_function_(false),
450
harmony_block_scoping_(scanner->HarmonyBlockScoping()) { }
452
497
// Preparse the program. Only called in PreParseProgram after creating
454
499
PreParseResult PreParse() {
459
504
if (stack_overflow_) return kPreParseStackOverflow;
461
506
ReportUnexpectedToken(scanner_->current_token());
462
} else if (scope_->is_strict()) {
507
} else if (!scope_->is_classic_mode()) {
463
508
CheckOctalLiteral(start_position, scanner_->location().end_pos, &ok);
465
510
return kPreParseSuccess;
493
538
Statement ParseVariableStatement(VariableDeclarationContext var_context,
495
540
Statement ParseVariableDeclarations(VariableDeclarationContext var_context,
541
VariableDeclarationProperties* decl_props,
498
544
Statement ParseExpressionOrLabelledStatement(bool* ok);
563
610
bool peek_any_identifier();
565
void set_strict_mode() {
566
scope_->set_strict();
569
bool strict_mode() { return scope_->is_strict(); }
612
void set_language_mode(i::LanguageMode language_mode) {
613
scope_->set_language_mode(language_mode);
616
bool is_classic_mode() {
617
return scope_->language_mode() == i::CLASSIC_MODE;
620
bool is_extended_mode() {
621
return scope_->language_mode() == i::EXTENDED_MODE;
624
i::LanguageMode language_mode() { return scope_->language_mode(); }
571
626
void Consume(i::Token::Value token) { Next(); }