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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 bool default_export, bool* ok); | 279 bool default_export, bool* ok); |
280 Statement* ParseNativeDeclaration(bool* ok); | 280 Statement* ParseNativeDeclaration(bool* ok); |
281 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, | 281 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, |
282 ZoneList<const AstRawString*>* names, | 282 ZoneList<const AstRawString*>* names, |
283 bool* ok); | 283 bool* ok); |
284 void DeclareAndInitializeVariables( | 284 void DeclareAndInitializeVariables( |
285 Block* block, const DeclarationDescriptor* declaration_descriptor, | 285 Block* block, const DeclarationDescriptor* declaration_descriptor, |
286 const DeclarationParsingResult::Declaration* declaration, | 286 const DeclarationParsingResult::Declaration* declaration, |
287 ZoneList<const AstRawString*>* names, bool* ok); | 287 ZoneList<const AstRawString*>* names, bool* ok); |
288 | 288 |
289 Block* ParseVariableStatement(VariableDeclarationContext var_context, | |
290 ZoneList<const AstRawString*>* names, | |
291 bool* ok); | |
292 DoExpression* ParseDoExpression(bool* ok); | 289 DoExpression* ParseDoExpression(bool* ok); |
293 Expression* ParseYieldStarExpression(bool* ok); | 290 Expression* ParseYieldStarExpression(bool* ok); |
294 | 291 |
295 class PatternRewriter final : public AstVisitor<PatternRewriter> { | 292 class PatternRewriter final : public AstVisitor<PatternRewriter> { |
296 public: | 293 public: |
297 static void DeclareAndInitializeVariables( | 294 static void DeclareAndInitializeVariables( |
298 Parser* parser, Block* block, | 295 Parser* parser, Block* block, |
299 const DeclarationDescriptor* declaration_descriptor, | 296 const DeclarationDescriptor* declaration_descriptor, |
300 const DeclarationParsingResult::Declaration* declaration, | 297 const DeclarationParsingResult::Declaration* declaration, |
301 ZoneList<const AstRawString*>* names, bool* ok); | 298 ZoneList<const AstRawString*>* names, bool* ok); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 Statement* ParseSwitchStatement(ZoneList<const AstRawString*>* labels, | 385 Statement* ParseSwitchStatement(ZoneList<const AstRawString*>* labels, |
389 bool* ok); | 386 bool* ok); |
390 DoWhileStatement* ParseDoWhileStatement(ZoneList<const AstRawString*>* labels, | 387 DoWhileStatement* ParseDoWhileStatement(ZoneList<const AstRawString*>* labels, |
391 bool* ok); | 388 bool* ok); |
392 WhileStatement* ParseWhileStatement(ZoneList<const AstRawString*>* labels, | 389 WhileStatement* ParseWhileStatement(ZoneList<const AstRawString*>* labels, |
393 bool* ok); | 390 bool* ok); |
394 Statement* ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok); | 391 Statement* ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok); |
395 Statement* ParseThrowStatement(bool* ok); | 392 Statement* ParseThrowStatement(bool* ok); |
396 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); | 393 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); |
397 TryStatement* ParseTryStatement(bool* ok); | 394 TryStatement* ParseTryStatement(bool* ok); |
398 DebuggerStatement* ParseDebuggerStatement(bool* ok); | |
399 // Parse a SubStatement in strict mode, or with an extra block scope in | |
400 // sloppy mode to handle | |
401 // ES#sec-functiondeclarations-in-ifstatement-statement-clauses | |
402 // The legacy parameter indicates whether function declarations are | |
403 // banned by the ES2015 specification in this location, and they are being | |
404 // permitted here to match previous V8 behavior. | |
405 Statement* ParseScopedStatement(ZoneList<const AstRawString*>* labels, | |
406 bool legacy, bool* ok); | |
407 | 395 |
408 // !%_IsJSReceiver(result = iterator.next()) && | 396 // !%_IsJSReceiver(result = iterator.next()) && |
409 // %ThrowIteratorResultNotAnObject(result) | 397 // %ThrowIteratorResultNotAnObject(result) |
410 Expression* BuildIteratorNextResult(Expression* iterator, Variable* result, | 398 Expression* BuildIteratorNextResult(Expression* iterator, Variable* result, |
411 int pos); | 399 int pos); |
412 | 400 |
413 Expression* GetIterator(Expression* iterable, int pos); | 401 Expression* GetIterator(Expression* iterable, int pos); |
414 | 402 |
415 // Initialize the components of a for-in / for-of statement. | 403 // Initialize the components of a for-in / for-of statement. |
416 Statement* InitializeForEachStatement(ForEachStatement* stmt, | 404 Statement* InitializeForEachStatement(ForEachStatement* stmt, |
(...skipping 18 matching lines...) Expand all Loading... |
435 const AstRawString* name, Scanner::Location function_name_location, | 423 const AstRawString* name, Scanner::Location function_name_location, |
436 FunctionNameValidity function_name_validity, FunctionKind kind, | 424 FunctionNameValidity function_name_validity, FunctionKind kind, |
437 int function_token_position, FunctionLiteral::FunctionType type, | 425 int function_token_position, FunctionLiteral::FunctionType type, |
438 LanguageMode language_mode, bool* ok); | 426 LanguageMode language_mode, bool* ok); |
439 | 427 |
440 Expression* ParseClassLiteral(const AstRawString* name, | 428 Expression* ParseClassLiteral(const AstRawString* name, |
441 Scanner::Location class_name_location, | 429 Scanner::Location class_name_location, |
442 bool name_is_strict_reserved, int pos, | 430 bool name_is_strict_reserved, int pos, |
443 bool* ok); | 431 bool* ok); |
444 | 432 |
445 // Magical syntax support. | |
446 Expression* ParseV8Intrinsic(bool* ok); | |
447 | |
448 // Get odd-ball literals. | 433 // Get odd-ball literals. |
449 Literal* GetLiteralUndefined(int position); | 434 Literal* GetLiteralUndefined(int position); |
450 | 435 |
451 // Check if the scope has conflicting var/let declarations from different | 436 // Check if the scope has conflicting var/let declarations from different |
452 // scopes. This covers for example | 437 // scopes. This covers for example |
453 // | 438 // |
454 // function f() { { { var x; } let x; } } | 439 // function f() { { { var x; } let x; } } |
455 // function g() { { var x; let x; } } | 440 // function g() { { var x; let x; } } |
456 // | 441 // |
457 // The var declarations are hoisted to the function scope, but originate from | 442 // The var declarations are hoisted to the function scope, but originate from |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 } | 922 } |
938 V8_INLINE ZoneList<Statement*>* NewStatementList(int size) const { | 923 V8_INLINE ZoneList<Statement*>* NewStatementList(int size) const { |
939 return new (zone()) ZoneList<Statement*>(size, zone()); | 924 return new (zone()) ZoneList<Statement*>(size, zone()); |
940 } | 925 } |
941 | 926 |
942 V8_INLINE Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity, | 927 V8_INLINE Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity, |
943 bool ignore_completion_value, int pos) { | 928 bool ignore_completion_value, int pos) { |
944 return factory()->NewBlock(labels, capacity, ignore_completion_value, pos); | 929 return factory()->NewBlock(labels, capacity, ignore_completion_value, pos); |
945 } | 930 } |
946 | 931 |
| 932 V8_INLINE Expression* NewV8Intrinsic(const AstRawString* name, |
| 933 ZoneList<Expression*>* args, int pos, |
| 934 bool* ok); |
| 935 |
947 V8_INLINE void AddParameterInitializationBlock( | 936 V8_INLINE void AddParameterInitializationBlock( |
948 const ParserFormalParameters& parameters, ZoneList<Statement*>* body, | 937 const ParserFormalParameters& parameters, ZoneList<Statement*>* body, |
949 bool is_async, bool* ok) { | 938 bool is_async, bool* ok) { |
950 if (parameters.is_simple) return; | 939 if (parameters.is_simple) return; |
951 auto* init_block = BuildParameterInitializationBlock(parameters, ok); | 940 auto* init_block = BuildParameterInitializationBlock(parameters, ok); |
952 if (!*ok) return; | 941 if (!*ok) return; |
953 if (is_async) { | 942 if (is_async) { |
954 init_block = BuildRejectPromiseOnException(init_block, ok); | 943 init_block = BuildRejectPromiseOnException(init_block, ok); |
955 if (!*ok) return; | 944 if (!*ok) return; |
956 } | 945 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 | 1013 |
1025 V8_INLINE ZoneList<typename ExpressionClassifier::Error>* | 1014 V8_INLINE ZoneList<typename ExpressionClassifier::Error>* |
1026 GetReportedErrorList() const { | 1015 GetReportedErrorList() const { |
1027 return function_state_->GetReportedErrorList(); | 1016 return function_state_->GetReportedErrorList(); |
1028 } | 1017 } |
1029 | 1018 |
1030 V8_INLINE ZoneList<Expression*>* GetNonPatternList() const { | 1019 V8_INLINE ZoneList<Expression*>* GetNonPatternList() const { |
1031 return function_state_->non_patterns_to_rewrite(); | 1020 return function_state_->non_patterns_to_rewrite(); |
1032 } | 1021 } |
1033 | 1022 |
| 1023 V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { |
| 1024 ++use_counts_[feature]; |
| 1025 } |
| 1026 |
1034 // Parser's private field members. | 1027 // Parser's private field members. |
1035 | 1028 |
1036 Scanner scanner_; | 1029 Scanner scanner_; |
1037 PreParser* reusable_preparser_; | 1030 PreParser* reusable_preparser_; |
1038 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 1031 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
1039 | 1032 |
1040 friend class ParserTarget; | 1033 friend class ParserTarget; |
1041 friend class ParserTargetScope; | 1034 friend class ParserTargetScope; |
1042 ParserTarget* target_stack_; // for break, continue statements | 1035 ParserTarget* target_stack_; // for break, continue statements |
1043 | 1036 |
(...skipping 12 matching lines...) Expand all Loading... |
1056 | 1049 |
1057 #ifdef DEBUG | 1050 #ifdef DEBUG |
1058 void Print(AstNode* node); | 1051 void Print(AstNode* node); |
1059 #endif // DEBUG | 1052 #endif // DEBUG |
1060 }; | 1053 }; |
1061 | 1054 |
1062 } // namespace internal | 1055 } // namespace internal |
1063 } // namespace v8 | 1056 } // namespace v8 |
1064 | 1057 |
1065 #endif // V8_PARSING_PARSER_H_ | 1058 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |