| 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_PARSER_H_ | 5 #ifndef V8_PARSING_PARSER_H_ |
| 6 #define V8_PARSING_PARSER_H_ | 6 #define V8_PARSING_PARSER_H_ |
| 7 | 7 |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 #include "src/parsing/parser-base.h" | 10 #include "src/parsing/parser-base.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 typedef AstNodeFactory Factory; | 168 typedef AstNodeFactory Factory; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 // TODO(nikolaos): The traits methods should not need to call methods | 171 // TODO(nikolaos): The traits methods should not need to call methods |
| 172 // of the implementation object. | 172 // of the implementation object. |
| 173 Parser* delegate() { return reinterpret_cast<Parser*>(this); } | 173 Parser* delegate() { return reinterpret_cast<Parser*>(this); } |
| 174 const Parser* delegate() const { | 174 const Parser* delegate() const { |
| 175 return reinterpret_cast<const Parser*>(this); | 175 return reinterpret_cast<const Parser*>(this); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Producing data during the recursive descent. | |
| 179 const AstRawString* GetSymbol(Scanner* scanner) const; | |
| 180 const AstRawString* GetNextSymbol(Scanner* scanner) const; | |
| 181 const AstRawString* GetNumberAsSymbol(Scanner* scanner) const; | |
| 182 | |
| 183 Expression* ThisExpression(int pos = kNoSourcePosition); | |
| 184 Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos); | |
| 185 Expression* NewSuperCallReference(AstNodeFactory* factory, int pos); | |
| 186 Expression* NewTargetExpression(int pos); | |
| 187 Expression* FunctionSentExpression(AstNodeFactory* factory, int pos) const; | |
| 188 Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner, | |
| 189 AstNodeFactory* factory) const; | |
| 190 Expression* ExpressionFromIdentifier(const AstRawString* name, | |
| 191 int start_position, int end_position, | |
| 192 InferName = InferName::kYes); | |
| 193 Expression* ExpressionFromString(int pos, Scanner* scanner, | |
| 194 AstNodeFactory* factory) const; | |
| 195 Expression* GetIterator(Expression* iterable, AstNodeFactory* factory, | |
| 196 int pos); | |
| 197 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, | |
| 198 Zone* zone) const { | |
| 199 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); | |
| 200 } | |
| 201 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, | |
| 202 Zone* zone) const { | |
| 203 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | |
| 204 } | |
| 205 ZoneList<v8::internal::Statement*>* NewStatementList(int size, | |
| 206 Zone* zone) const { | |
| 207 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); | |
| 208 } | |
| 209 | |
| 210 V8_INLINE void AddParameterInitializationBlock( | 178 V8_INLINE void AddParameterInitializationBlock( |
| 211 const ParserFormalParameters& parameters, | 179 const ParserFormalParameters& parameters, |
| 212 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); | 180 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); |
| 213 | 181 |
| 214 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, | 182 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, |
| 215 Expression* pattern, | 183 Expression* pattern, |
| 216 Expression* initializer, | 184 Expression* initializer, |
| 217 int initializer_end_position, bool is_rest); | 185 int initializer_end_position, bool is_rest); |
| 218 V8_INLINE void DeclareFormalParameter( | 186 V8_INLINE void DeclareFormalParameter( |
| 219 DeclarationScope* scope, | 187 DeclarationScope* scope, |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 // banned by the ES2015 specification in this location, and they are being | 504 // banned by the ES2015 specification in this location, and they are being |
| 537 // permitted here to match previous V8 behavior. | 505 // permitted here to match previous V8 behavior. |
| 538 Statement* ParseScopedStatement(ZoneList<const AstRawString*>* labels, | 506 Statement* ParseScopedStatement(ZoneList<const AstRawString*>* labels, |
| 539 bool legacy, bool* ok); | 507 bool legacy, bool* ok); |
| 540 | 508 |
| 541 // !%_IsJSReceiver(result = iterator.next()) && | 509 // !%_IsJSReceiver(result = iterator.next()) && |
| 542 // %ThrowIteratorResultNotAnObject(result) | 510 // %ThrowIteratorResultNotAnObject(result) |
| 543 Expression* BuildIteratorNextResult(Expression* iterator, Variable* result, | 511 Expression* BuildIteratorNextResult(Expression* iterator, Variable* result, |
| 544 int pos); | 512 int pos); |
| 545 | 513 |
| 514 Expression* GetIterator(Expression* iterable, int pos); |
| 546 | 515 |
| 547 // Initialize the components of a for-in / for-of statement. | 516 // Initialize the components of a for-in / for-of statement. |
| 548 Statement* InitializeForEachStatement(ForEachStatement* stmt, | 517 Statement* InitializeForEachStatement(ForEachStatement* stmt, |
| 549 Expression* each, Expression* subject, | 518 Expression* each, Expression* subject, |
| 550 Statement* body, int each_keyword_pos); | 519 Statement* body, int each_keyword_pos); |
| 551 Statement* InitializeForOfStatement(ForOfStatement* stmt, Expression* each, | 520 Statement* InitializeForOfStatement(ForOfStatement* stmt, Expression* each, |
| 552 Expression* iterable, Statement* body, | 521 Expression* iterable, Statement* body, |
| 553 bool finalize, | 522 bool finalize, |
| 554 int next_result_pos = kNoSourcePosition); | 523 int next_result_pos = kNoSourcePosition); |
| 555 Statement* DesugarLexicalBindingsInForStatement( | 524 Statement* DesugarLexicalBindingsInForStatement( |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 // Non-NULL empty string. | 939 // Non-NULL empty string. |
| 971 V8_INLINE const AstRawString* EmptyIdentifierString() const { | 940 V8_INLINE const AstRawString* EmptyIdentifierString() const { |
| 972 return ast_value_factory()->empty_string(); | 941 return ast_value_factory()->empty_string(); |
| 973 } | 942 } |
| 974 | 943 |
| 975 // Odd-ball literal creators. | 944 // Odd-ball literal creators. |
| 976 V8_INLINE Literal* GetLiteralTheHole(int position) { | 945 V8_INLINE Literal* GetLiteralTheHole(int position) { |
| 977 return factory()->NewTheHoleLiteral(kNoSourcePosition); | 946 return factory()->NewTheHoleLiteral(kNoSourcePosition); |
| 978 } | 947 } |
| 979 | 948 |
| 949 // Producing data during the recursive descent. |
| 950 V8_INLINE const AstRawString* GetSymbol() const { |
| 951 const AstRawString* result = scanner()->CurrentSymbol(ast_value_factory()); |
| 952 DCHECK(result != NULL); |
| 953 return result; |
| 954 } |
| 955 |
| 956 V8_INLINE const AstRawString* GetNextSymbol() const { |
| 957 return scanner()->NextSymbol(ast_value_factory()); |
| 958 } |
| 959 |
| 960 V8_INLINE const AstRawString* GetNumberAsSymbol() const { |
| 961 double double_value = scanner()->DoubleValue(); |
| 962 char array[100]; |
| 963 const char* string = DoubleToCString(double_value, ArrayVector(array)); |
| 964 return ast_value_factory()->GetOneByteString(string); |
| 965 } |
| 966 |
| 967 V8_INLINE Expression* ThisExpression(int pos = kNoSourcePosition) { |
| 968 return NewUnresolved(ast_value_factory()->this_string(), pos, pos + 4, |
| 969 Variable::THIS); |
| 970 } |
| 971 |
| 972 Expression* NewSuperPropertyReference(int pos); |
| 973 Expression* NewSuperCallReference(int pos); |
| 974 Expression* NewTargetExpression(int pos); |
| 975 Expression* FunctionSentExpression(int pos); |
| 976 |
| 977 Literal* ExpressionFromLiteral(Token::Value token, int pos); |
| 978 |
| 979 V8_INLINE Expression* ExpressionFromIdentifier( |
| 980 const AstRawString* name, int start_position, int end_position, |
| 981 InferName infer = InferName::kYes) { |
| 982 if (infer == InferName::kYes && fni_ != NULL) { |
| 983 fni_->PushVariableName(name); |
| 984 } |
| 985 return NewUnresolved(name, start_position, end_position); |
| 986 } |
| 987 |
| 988 V8_INLINE Expression* ExpressionFromString(int pos) { |
| 989 const AstRawString* symbol = GetSymbol(); |
| 990 if (fni_ != NULL) fni_->PushLiteralName(symbol); |
| 991 return factory()->NewStringLiteral(symbol, pos); |
| 992 } |
| 993 |
| 994 V8_INLINE ZoneList<v8::internal::Expression*>* NewExpressionList( |
| 995 int size) const { |
| 996 return new (zone()) ZoneList<v8::internal::Expression*>(size, zone()); |
| 997 } |
| 998 V8_INLINE ZoneList<ObjectLiteral::Property*>* NewPropertyList( |
| 999 int size) const { |
| 1000 return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone()); |
| 1001 } |
| 1002 V8_INLINE ZoneList<v8::internal::Statement*>* NewStatementList( |
| 1003 int size) const { |
| 1004 return new (zone()) ZoneList<v8::internal::Statement*>(size, zone()); |
| 1005 } |
| 1006 |
| 980 // Parser's private field members. | 1007 // Parser's private field members. |
| 981 | 1008 |
| 982 Scanner scanner_; | 1009 Scanner scanner_; |
| 983 PreParser* reusable_preparser_; | 1010 PreParser* reusable_preparser_; |
| 984 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 1011 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
| 985 Target* target_stack_; // for break, continue statements | 1012 Target* target_stack_; // for break, continue statements |
| 986 ScriptCompiler::CompileOptions compile_options_; | 1013 ScriptCompiler::CompileOptions compile_options_; |
| 987 ParseData* cached_parse_data_; | 1014 ParseData* cached_parse_data_; |
| 988 | 1015 |
| 989 PendingCompilationErrorHandler pending_error_handler_; | 1016 PendingCompilationErrorHandler pending_error_handler_; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 if (init_block != nullptr) { | 1111 if (init_block != nullptr) { |
| 1085 body->Add(init_block, delegate()->zone()); | 1112 body->Add(init_block, delegate()->zone()); |
| 1086 } | 1113 } |
| 1087 } | 1114 } |
| 1088 } | 1115 } |
| 1089 | 1116 |
| 1090 } // namespace internal | 1117 } // namespace internal |
| 1091 } // namespace v8 | 1118 } // namespace v8 |
| 1092 | 1119 |
| 1093 #endif // V8_PARSING_PARSER_H_ | 1120 #endif // V8_PARSING_PARSER_H_ |
| OLD | NEW |