OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PARSING_PREPARSER_H | 5 #ifndef V8_PARSING_PREPARSER_H |
6 #define V8_PARSING_PREPARSER_H | 6 #define V8_PARSING_PREPARSER_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 static PreParserIdentifier Yield() { | 49 static PreParserIdentifier Yield() { |
50 return PreParserIdentifier(kYieldIdentifier); | 50 return PreParserIdentifier(kYieldIdentifier); |
51 } | 51 } |
52 static PreParserIdentifier Prototype() { | 52 static PreParserIdentifier Prototype() { |
53 return PreParserIdentifier(kPrototypeIdentifier); | 53 return PreParserIdentifier(kPrototypeIdentifier); |
54 } | 54 } |
55 static PreParserIdentifier Constructor() { | 55 static PreParserIdentifier Constructor() { |
56 return PreParserIdentifier(kConstructorIdentifier); | 56 return PreParserIdentifier(kConstructorIdentifier); |
57 } | 57 } |
| 58 static PreParserIdentifier Enum() { |
| 59 return PreParserIdentifier(kEnumIdentifier); |
| 60 } |
| 61 static PreParserIdentifier Await() { |
| 62 return PreParserIdentifier(kAwaitIdentifier); |
| 63 } |
58 bool IsEval() const { return type_ == kEvalIdentifier; } | 64 bool IsEval() const { return type_ == kEvalIdentifier; } |
59 bool IsArguments() const { return type_ == kArgumentsIdentifier; } | 65 bool IsArguments() const { return type_ == kArgumentsIdentifier; } |
60 bool IsEvalOrArguments() const { return IsEval() || IsArguments(); } | 66 bool IsEvalOrArguments() const { return IsEval() || IsArguments(); } |
61 bool IsUndefined() const { return type_ == kUndefinedIdentifier; } | 67 bool IsUndefined() const { return type_ == kUndefinedIdentifier; } |
62 bool IsLet() const { return type_ == kLetIdentifier; } | 68 bool IsLet() const { return type_ == kLetIdentifier; } |
63 bool IsStatic() const { return type_ == kStaticIdentifier; } | 69 bool IsStatic() const { return type_ == kStaticIdentifier; } |
64 bool IsYield() const { return type_ == kYieldIdentifier; } | 70 bool IsYield() const { return type_ == kYieldIdentifier; } |
65 bool IsPrototype() const { return type_ == kPrototypeIdentifier; } | 71 bool IsPrototype() const { return type_ == kPrototypeIdentifier; } |
66 bool IsConstructor() const { return type_ == kConstructorIdentifier; } | 72 bool IsConstructor() const { return type_ == kConstructorIdentifier; } |
67 bool IsFutureReserved() const { return type_ == kFutureReservedIdentifier; } | 73 bool IsEnum() const { return type_ == kEnumIdentifier; } |
| 74 bool IsAwait() const { return type_ == kAwaitIdentifier; } |
68 bool IsFutureStrictReserved() const { | 75 bool IsFutureStrictReserved() const { |
69 return type_ == kFutureStrictReservedIdentifier || | 76 return type_ == kFutureStrictReservedIdentifier || |
70 type_ == kLetIdentifier || type_ == kStaticIdentifier || | 77 type_ == kLetIdentifier || type_ == kStaticIdentifier || |
71 type_ == kYieldIdentifier; | 78 type_ == kYieldIdentifier; |
72 } | 79 } |
73 | 80 |
74 // Allow identifier->name()[->length()] to work. The preparser | 81 // Allow identifier->name()[->length()] to work. The preparser |
75 // does not need the actual positions/lengths of the identifiers. | 82 // does not need the actual positions/lengths of the identifiers. |
76 const PreParserIdentifier* operator->() const { return this; } | 83 const PreParserIdentifier* operator->() const { return this; } |
77 const PreParserIdentifier raw_name() const { return *this; } | 84 const PreParserIdentifier raw_name() const { return *this; } |
78 | 85 |
79 int position() const { return 0; } | 86 int position() const { return 0; } |
80 int length() const { return 0; } | 87 int length() const { return 0; } |
81 | 88 |
82 private: | 89 private: |
83 enum Type { | 90 enum Type { |
84 kUnknownIdentifier, | 91 kUnknownIdentifier, |
85 kFutureReservedIdentifier, | 92 kFutureReservedIdentifier, |
86 kFutureStrictReservedIdentifier, | 93 kFutureStrictReservedIdentifier, |
87 kLetIdentifier, | 94 kLetIdentifier, |
88 kStaticIdentifier, | 95 kStaticIdentifier, |
89 kYieldIdentifier, | 96 kYieldIdentifier, |
90 kEvalIdentifier, | 97 kEvalIdentifier, |
91 kArgumentsIdentifier, | 98 kArgumentsIdentifier, |
92 kUndefinedIdentifier, | 99 kUndefinedIdentifier, |
93 kPrototypeIdentifier, | 100 kPrototypeIdentifier, |
94 kConstructorIdentifier | 101 kConstructorIdentifier, |
| 102 kEnumIdentifier, |
| 103 kAwaitIdentifier |
95 }; | 104 }; |
96 | 105 |
97 explicit PreParserIdentifier(Type type) : type_(type) {} | 106 explicit PreParserIdentifier(Type type) : type_(type) {} |
98 Type type_; | 107 Type type_; |
99 | 108 |
100 friend class PreParserExpression; | 109 friend class PreParserExpression; |
101 }; | 110 }; |
102 | 111 |
103 | 112 |
104 class PreParserExpression { | 113 class PreParserExpression { |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 | 971 |
963 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, | 972 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, |
964 ParserRecorder* log, uintptr_t stack_limit) | 973 ParserRecorder* log, uintptr_t stack_limit) |
965 : ParserBase<PreParserTraits>(zone, scanner, stack_limit, NULL, | 974 : ParserBase<PreParserTraits>(zone, scanner, stack_limit, NULL, |
966 ast_value_factory, log, this) {} | 975 ast_value_factory, log, this) {} |
967 | 976 |
968 // Pre-parse the program from the character stream; returns true on | 977 // Pre-parse the program from the character stream; returns true on |
969 // success (even if parsing failed, the pre-parse data successfully | 978 // success (even if parsing failed, the pre-parse data successfully |
970 // captured the syntax error), and false if a stack-overflow happened | 979 // captured the syntax error), and false if a stack-overflow happened |
971 // during parsing. | 980 // during parsing. |
972 PreParseResult PreParseProgram(int* materialized_literals = 0) { | 981 PreParseResult PreParseProgram(int* materialized_literals = 0, |
| 982 bool is_module = false) { |
973 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); | 983 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); |
974 PreParserFactory factory(NULL); | 984 PreParserFactory factory(NULL); |
975 FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction, | 985 FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction, |
976 &factory); | 986 &factory); |
977 bool ok = true; | 987 bool ok = true; |
978 int start_position = scanner()->peek_location().beg_pos; | 988 int start_position = scanner()->peek_location().beg_pos; |
| 989 parsing_module_ = is_module; |
979 ParseStatementList(Token::EOS, &ok); | 990 ParseStatementList(Token::EOS, &ok); |
980 if (stack_overflow()) return kPreParseStackOverflow; | 991 if (stack_overflow()) return kPreParseStackOverflow; |
981 if (!ok) { | 992 if (!ok) { |
982 ReportUnexpectedToken(scanner()->current_token()); | 993 ReportUnexpectedToken(scanner()->current_token()); |
983 } else if (is_strict(scope_->language_mode())) { | 994 } else if (is_strict(scope_->language_mode())) { |
984 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, | 995 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, |
985 &ok); | 996 &ok); |
986 } | 997 } |
987 if (materialized_literals) { | 998 if (materialized_literals) { |
988 *materialized_literals = function_state_->materialized_literal_count(); | 999 *materialized_literals = function_state_->materialized_literal_count(); |
989 } | 1000 } |
990 return kPreParseSuccess; | 1001 return kPreParseSuccess; |
991 } | 1002 } |
992 | 1003 |
993 // Parses a single function literal, from the opening parentheses before | 1004 // Parses a single function literal, from the opening parentheses before |
994 // parameters to the closing brace after the body. | 1005 // parameters to the closing brace after the body. |
995 // Returns a FunctionEntry describing the body of the function in enough | 1006 // Returns a FunctionEntry describing the body of the function in enough |
996 // detail that it can be lazily compiled. | 1007 // detail that it can be lazily compiled. |
997 // The scanner is expected to have matched the "function" or "function*" | 1008 // The scanner is expected to have matched the "function" or "function*" |
998 // keyword and parameters, and have consumed the initial '{'. | 1009 // keyword and parameters, and have consumed the initial '{'. |
999 // At return, unless an error occurred, the scanner is positioned before the | 1010 // At return, unless an error occurred, the scanner is positioned before the |
1000 // the final '}'. | 1011 // the final '}'. |
1001 PreParseResult PreParseLazyFunction( | 1012 PreParseResult PreParseLazyFunction( |
1002 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, | 1013 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, |
1003 ParserRecorder* log, Scanner::BookmarkScope* bookmark = nullptr); | 1014 bool parsing_module, ParserRecorder* log, |
| 1015 Scanner::BookmarkScope* bookmark = nullptr); |
1004 | 1016 |
1005 private: | 1017 private: |
1006 friend class PreParserTraits; | 1018 friend class PreParserTraits; |
1007 | 1019 |
1008 static const int kLazyParseTrialLimit = 200; | 1020 static const int kLazyParseTrialLimit = 200; |
1009 | 1021 |
1010 // These types form an algebra over syntactic categories that is just | 1022 // These types form an algebra over syntactic categories that is just |
1011 // rich enough to let us recognize and propagate the constructs that | 1023 // rich enough to let us recognize and propagate the constructs that |
1012 // are either being counted in the preparser data, or is important | 1024 // are either being counted in the preparser data, or is important |
1013 // to throw the correct syntax error exceptions. | 1025 // to throw the correct syntax error exceptions. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 const PreParserFormalParameters& parameters, FunctionKind kind, | 1174 const PreParserFormalParameters& parameters, FunctionKind kind, |
1163 FunctionLiteral::FunctionType function_type, bool* ok) { | 1175 FunctionLiteral::FunctionType function_type, bool* ok) { |
1164 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, | 1176 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, |
1165 kind, function_type, ok); | 1177 kind, function_type, ok); |
1166 } | 1178 } |
1167 | 1179 |
1168 } // namespace internal | 1180 } // namespace internal |
1169 } // namespace v8 | 1181 } // namespace v8 |
1170 | 1182 |
1171 #endif // V8_PARSING_PREPARSER_H | 1183 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |