| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.parser; | 8 library engine.parser; |
| 9 | 9 |
| 10 import "dart:math" as math; | 10 import "dart:math" as math; |
| 11 import 'dart:collection'; | 11 import 'dart:collection'; |
| 12 | 12 |
| 13 import 'ast.dart'; | 13 import 'ast.dart'; |
| 14 import 'engine.dart' show AnalysisEngine, AnalysisOptionsImpl; | 14 import 'engine.dart' show AnalysisEngine, AnalysisOptionsImpl; |
| 15 import 'error.dart'; | 15 import 'error.dart'; |
| 16 import 'instrumentation.dart'; | |
| 17 import 'java_core.dart'; | 16 import 'java_core.dart'; |
| 18 import 'java_engine.dart'; | 17 import 'java_engine.dart'; |
| 19 import 'scanner.dart'; | 18 import 'scanner.dart'; |
| 20 import 'source.dart'; | 19 import 'source.dart'; |
| 21 import 'utilities_collection.dart' show TokenMap; | 20 import 'utilities_collection.dart' show TokenMap; |
| 22 import 'utilities_dart.dart'; | 21 import 'utilities_dart.dart'; |
| 23 | 22 |
| 24 Map<String, MethodTrampoline> methodTable_Parser = <String, MethodTrampoline>{ | 23 Map<String, MethodTrampoline> methodTable_Parser = <String, MethodTrampoline>{ |
| 25 'parseCompilationUnit_1': new MethodTrampoline( | 24 'parseCompilationUnit_1': new MethodTrampoline( |
| 26 1, | 25 1, |
| (...skipping 2648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2675 } else if (!_matchesIdentifier()) { | 2674 } else if (!_matchesIdentifier()) { |
| 2676 // | 2675 // |
| 2677 // Recover from an error. | 2676 // Recover from an error. |
| 2678 // | 2677 // |
| 2679 if (_matchesKeyword(Keyword.CLASS)) { | 2678 if (_matchesKeyword(Keyword.CLASS)) { |
| 2680 _reportErrorForCurrentToken(ParserErrorCode.CLASS_IN_CLASS); | 2679 _reportErrorForCurrentToken(ParserErrorCode.CLASS_IN_CLASS); |
| 2681 // TODO(brianwilkerson) We don't currently have any way to capture the | 2680 // TODO(brianwilkerson) We don't currently have any way to capture the |
| 2682 // class that was parsed. | 2681 // class that was parsed. |
| 2683 _parseClassDeclaration(commentAndMetadata, null); | 2682 _parseClassDeclaration(commentAndMetadata, null); |
| 2684 return null; | 2683 return null; |
| 2685 } else if (_matchesKeyword(Keyword.ABSTRACT) && _tokenMatchesKeyword(_peek
(), Keyword.CLASS)) { | 2684 } else if (_matchesKeyword(Keyword.ABSTRACT) && |
| 2685 _tokenMatchesKeyword(_peek(), Keyword.CLASS)) { |
| 2686 _reportErrorForToken(ParserErrorCode.CLASS_IN_CLASS, _peek()); | 2686 _reportErrorForToken(ParserErrorCode.CLASS_IN_CLASS, _peek()); |
| 2687 // TODO(brianwilkerson) We don't currently have any way to capture the | 2687 // TODO(brianwilkerson) We don't currently have any way to capture the |
| 2688 // class that was parsed. | 2688 // class that was parsed. |
| 2689 _parseClassDeclaration(commentAndMetadata, getAndAdvance()); | 2689 _parseClassDeclaration(commentAndMetadata, getAndAdvance()); |
| 2690 return null; | 2690 return null; |
| 2691 } else if (_isOperator(_currentToken)) { | 2691 } else if (_isOperator(_currentToken)) { |
| 2692 // | 2692 // |
| 2693 // We appear to have found an operator declaration without the | 2693 // We appear to have found an operator declaration without the |
| 2694 // 'operator' keyword. | 2694 // 'operator' keyword. |
| 2695 // | 2695 // |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2933 return null; | 2933 return null; |
| 2934 } | 2934 } |
| 2935 | 2935 |
| 2936 /** | 2936 /** |
| 2937 * Parse a compilation unit, starting with the given token. | 2937 * Parse a compilation unit, starting with the given token. |
| 2938 * | 2938 * |
| 2939 * @param token the first token of the compilation unit | 2939 * @param token the first token of the compilation unit |
| 2940 * @return the compilation unit that was parsed | 2940 * @return the compilation unit that was parsed |
| 2941 */ | 2941 */ |
| 2942 CompilationUnit parseCompilationUnit(Token token) { | 2942 CompilationUnit parseCompilationUnit(Token token) { |
| 2943 InstrumentationBuilder instrumentation = | 2943 _currentToken = token; |
| 2944 Instrumentation.builder2("dart.engine.Parser.parseCompilationUnit"); | 2944 return parseCompilationUnit2(); |
| 2945 try { | |
| 2946 _currentToken = token; | |
| 2947 return parseCompilationUnit2(); | |
| 2948 } finally { | |
| 2949 instrumentation.log2(2); | |
| 2950 //Record if >= 2ms | |
| 2951 } | |
| 2952 } | 2945 } |
| 2953 | 2946 |
| 2954 /** | 2947 /** |
| 2955 * Parse a compilation unit. | 2948 * Parse a compilation unit. |
| 2956 * | 2949 * |
| 2957 * Specified: | 2950 * Specified: |
| 2958 * | 2951 * |
| 2959 * <pre> | 2952 * <pre> |
| 2960 * compilationUnit ::= | 2953 * compilationUnit ::= |
| 2961 * scriptTag? directive* topLevelDeclaration* | 2954 * scriptTag? directive* topLevelDeclaration* |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3137 | 3130 |
| 3138 /** | 3131 /** |
| 3139 * Parse the script tag and directives in a compilation unit, starting with th
e given token, until | 3132 * Parse the script tag and directives in a compilation unit, starting with th
e given token, until |
| 3140 * the first non-directive is encountered. The remainder of the compilation un
it will not be | 3133 * the first non-directive is encountered. The remainder of the compilation un
it will not be |
| 3141 * parsed. Specifically, if there are directives later in the file, they will
not be parsed. | 3134 * parsed. Specifically, if there are directives later in the file, they will
not be parsed. |
| 3142 * | 3135 * |
| 3143 * @param token the first token of the compilation unit | 3136 * @param token the first token of the compilation unit |
| 3144 * @return the compilation unit that was parsed | 3137 * @return the compilation unit that was parsed |
| 3145 */ | 3138 */ |
| 3146 CompilationUnit parseDirectives(Token token) { | 3139 CompilationUnit parseDirectives(Token token) { |
| 3147 InstrumentationBuilder instrumentation = | 3140 _currentToken = token; |
| 3148 Instrumentation.builder2("dart.engine.Parser.parseDirectives"); | 3141 return _parseDirectives(); |
| 3149 try { | |
| 3150 _currentToken = token; | |
| 3151 return _parseDirectives(); | |
| 3152 } finally { | |
| 3153 instrumentation.log2(2); | |
| 3154 //Record if >= 2ms | |
| 3155 } | |
| 3156 } | 3142 } |
| 3157 | 3143 |
| 3158 /** | 3144 /** |
| 3159 * Parse an expression, starting with the given token. | 3145 * Parse an expression, starting with the given token. |
| 3160 * | 3146 * |
| 3161 * @param token the first token of the expression | 3147 * @param token the first token of the expression |
| 3162 * @return the expression that was parsed, or `null` if the tokens do not repr
esent a | 3148 * @return the expression that was parsed, or `null` if the tokens do not repr
esent a |
| 3163 * recognizable expression | 3149 * recognizable expression |
| 3164 */ | 3150 */ |
| 3165 Expression parseExpression(Token token) { | 3151 Expression parseExpression(Token token) { |
| 3166 InstrumentationBuilder instrumentation = | 3152 _currentToken = token; |
| 3167 Instrumentation.builder2("dart.engine.Parser.parseExpression"); | 3153 return parseExpression2(); |
| 3168 try { | |
| 3169 _currentToken = token; | |
| 3170 return parseExpression2(); | |
| 3171 } finally { | |
| 3172 instrumentation.log2(2); | |
| 3173 //Record if >= 2ms | |
| 3174 } | |
| 3175 } | 3154 } |
| 3176 | 3155 |
| 3177 /** | 3156 /** |
| 3178 * Parse an expression that might contain a cascade. | 3157 * Parse an expression that might contain a cascade. |
| 3179 * | 3158 * |
| 3180 * <pre> | 3159 * <pre> |
| 3181 * expression ::= | 3160 * expression ::= |
| 3182 * assignableExpression assignmentOperator expression | 3161 * assignableExpression assignmentOperator expression |
| 3183 * | conditionalExpression cascadeSection* | 3162 * | conditionalExpression cascadeSection* |
| 3184 * | throwExpression | 3163 * | throwExpression |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3718 } | 3697 } |
| 3719 | 3698 |
| 3720 /** | 3699 /** |
| 3721 * Parse a statement, starting with the given token. | 3700 * Parse a statement, starting with the given token. |
| 3722 * | 3701 * |
| 3723 * @param token the first token of the statement | 3702 * @param token the first token of the statement |
| 3724 * @return the statement that was parsed, or `null` if the tokens do not repre
sent a | 3703 * @return the statement that was parsed, or `null` if the tokens do not repre
sent a |
| 3725 * recognizable statement | 3704 * recognizable statement |
| 3726 */ | 3705 */ |
| 3727 Statement parseStatement(Token token) { | 3706 Statement parseStatement(Token token) { |
| 3728 InstrumentationBuilder instrumentation = | 3707 _currentToken = token; |
| 3729 Instrumentation.builder2("dart.engine.Parser.parseStatement"); | 3708 return parseStatement2(); |
| 3730 try { | |
| 3731 _currentToken = token; | |
| 3732 return parseStatement2(); | |
| 3733 } finally { | |
| 3734 instrumentation.log2(2); | |
| 3735 //Record if >= 2ms | |
| 3736 } | |
| 3737 } | 3709 } |
| 3738 | 3710 |
| 3739 /** | 3711 /** |
| 3740 * Parse a statement. | 3712 * Parse a statement. |
| 3741 * | 3713 * |
| 3742 * <pre> | 3714 * <pre> |
| 3743 * statement ::= | 3715 * statement ::= |
| 3744 * label* nonLabeledStatement | 3716 * label* nonLabeledStatement |
| 3745 * </pre> | 3717 * </pre> |
| 3746 * | 3718 * |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3759 } | 3731 } |
| 3760 | 3732 |
| 3761 /** | 3733 /** |
| 3762 * Parse a sequence of statements, starting with the given token. | 3734 * Parse a sequence of statements, starting with the given token. |
| 3763 * | 3735 * |
| 3764 * @param token the first token of the sequence of statement | 3736 * @param token the first token of the sequence of statement |
| 3765 * @return the statements that were parsed, or `null` if the tokens do not rep
resent a | 3737 * @return the statements that were parsed, or `null` if the tokens do not rep
resent a |
| 3766 * recognizable sequence of statements | 3738 * recognizable sequence of statements |
| 3767 */ | 3739 */ |
| 3768 List<Statement> parseStatements(Token token) { | 3740 List<Statement> parseStatements(Token token) { |
| 3769 InstrumentationBuilder instrumentation = | 3741 _currentToken = token; |
| 3770 Instrumentation.builder2("dart.engine.Parser.parseStatements"); | 3742 return _parseStatementList(); |
| 3771 try { | |
| 3772 _currentToken = token; | |
| 3773 return _parseStatementList(); | |
| 3774 } finally { | |
| 3775 instrumentation.log2(2); | |
| 3776 //Record if >= 2ms | |
| 3777 } | |
| 3778 } | 3743 } |
| 3779 | 3744 |
| 3780 /** | 3745 /** |
| 3781 * Parse a string literal. | 3746 * Parse a string literal. |
| 3782 * | 3747 * |
| 3783 * <pre> | 3748 * <pre> |
| 3784 * stringLiteral ::= | 3749 * stringLiteral ::= |
| 3785 * MULTI_LINE_STRING+ | 3750 * MULTI_LINE_STRING+ |
| 3786 * | SINGLE_LINE_STRING+ | 3751 * | SINGLE_LINE_STRING+ |
| 3787 * </pre> | 3752 * </pre> |
| (...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4792 * | 'super' assignableSelector | 4757 * | 'super' assignableSelector |
| 4793 * | identifier | 4758 * | identifier |
| 4794 * </pre> | 4759 * </pre> |
| 4795 * | 4760 * |
| 4796 * @param primaryAllowed `true` if the expression is allowed to be a primary w
ithout any | 4761 * @param primaryAllowed `true` if the expression is allowed to be a primary w
ithout any |
| 4797 * assignable selector | 4762 * assignable selector |
| 4798 * @return the assignable expression that was parsed | 4763 * @return the assignable expression that was parsed |
| 4799 */ | 4764 */ |
| 4800 Expression _parseAssignableExpression(bool primaryAllowed) { | 4765 Expression _parseAssignableExpression(bool primaryAllowed) { |
| 4801 if (_matchesKeyword(Keyword.SUPER)) { | 4766 if (_matchesKeyword(Keyword.SUPER)) { |
| 4802 return _parseAssignableSelector(new SuperExpression(getAndAdvance()), fals
e); | 4767 return _parseAssignableSelector( |
| 4768 new SuperExpression(getAndAdvance()), |
| 4769 false); |
| 4803 } | 4770 } |
| 4804 // | 4771 // |
| 4805 // A primary expression can start with an identifier. We resolve the | 4772 // A primary expression can start with an identifier. We resolve the |
| 4806 // ambiguity by determining whether the primary consists of anything other | 4773 // ambiguity by determining whether the primary consists of anything other |
| 4807 // than an identifier and/or is followed by an assignableSelector. | 4774 // than an identifier and/or is followed by an assignableSelector. |
| 4808 // | 4775 // |
| 4809 Expression expression = _parsePrimaryExpression(); | 4776 Expression expression = _parsePrimaryExpression(); |
| 4810 bool isOptional = primaryAllowed || expression is SimpleIdentifier; | 4777 bool isOptional = primaryAllowed || expression is SimpleIdentifier; |
| 4811 while (true) { | 4778 while (true) { |
| 4812 while (_matches(TokenType.OPEN_PAREN)) { | 4779 while (_matches(TokenType.OPEN_PAREN)) { |
| (...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6385 Token awaitKeyword = null; | 6352 Token awaitKeyword = null; |
| 6386 if (_matchesString(_AWAIT)) { | 6353 if (_matchesString(_AWAIT)) { |
| 6387 awaitKeyword = getAndAdvance(); | 6354 awaitKeyword = getAndAdvance(); |
| 6388 } | 6355 } |
| 6389 Token forKeyword = _expectKeyword(Keyword.FOR); | 6356 Token forKeyword = _expectKeyword(Keyword.FOR); |
| 6390 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); | 6357 Token leftParenthesis = _expect(TokenType.OPEN_PAREN); |
| 6391 VariableDeclarationList variableList = null; | 6358 VariableDeclarationList variableList = null; |
| 6392 Expression initialization = null; | 6359 Expression initialization = null; |
| 6393 if (!_matches(TokenType.SEMICOLON)) { | 6360 if (!_matches(TokenType.SEMICOLON)) { |
| 6394 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); | 6361 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); |
| 6395 if (_matchesIdentifier() && (_tokenMatchesKeyword(_peek(), Keyword.IN) |
| _tokenMatches(_peek(), TokenType.COLON))) { | 6362 if (_matchesIdentifier() && |
| 6363 (_tokenMatchesKeyword(_peek(), Keyword.IN) || |
| 6364 _tokenMatches(_peek(), TokenType.COLON))) { |
| 6396 List<VariableDeclaration> variables = new List<VariableDeclaration>(); | 6365 List<VariableDeclaration> variables = new List<VariableDeclaration>(); |
| 6397 SimpleIdentifier variableName = parseSimpleIdentifier(); | 6366 SimpleIdentifier variableName = parseSimpleIdentifier(); |
| 6398 variables.add( | 6367 variables.add( |
| 6399 new VariableDeclaration(null, null, variableName, null, null)); | 6368 new VariableDeclaration(null, null, variableName, null, null)); |
| 6400 variableList = new VariableDeclarationList( | 6369 variableList = new VariableDeclarationList( |
| 6401 commentAndMetadata.comment, | 6370 commentAndMetadata.comment, |
| 6402 commentAndMetadata.metadata, | 6371 commentAndMetadata.metadata, |
| 6403 null, | 6372 null, |
| 6404 null, | 6373 null, |
| 6405 variables); | 6374 variables); |
| (...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7898 * | mapLiteral | 7867 * | mapLiteral |
| 7899 * | listLiteral | 7868 * | listLiteral |
| 7900 * </pre> | 7869 * </pre> |
| 7901 * | 7870 * |
| 7902 * @return the primary expression that was parsed | 7871 * @return the primary expression that was parsed |
| 7903 */ | 7872 */ |
| 7904 Expression _parsePrimaryExpression() { | 7873 Expression _parsePrimaryExpression() { |
| 7905 if (_matchesKeyword(Keyword.THIS)) { | 7874 if (_matchesKeyword(Keyword.THIS)) { |
| 7906 return new ThisExpression(getAndAdvance()); | 7875 return new ThisExpression(getAndAdvance()); |
| 7907 } else if (_matchesKeyword(Keyword.SUPER)) { | 7876 } else if (_matchesKeyword(Keyword.SUPER)) { |
| 7908 return _parseAssignableSelector(new SuperExpression(getAndAdvance()), fals
e); | 7877 return _parseAssignableSelector( |
| 7878 new SuperExpression(getAndAdvance()), |
| 7879 false); |
| 7909 } else if (_matchesKeyword(Keyword.NULL)) { | 7880 } else if (_matchesKeyword(Keyword.NULL)) { |
| 7910 return new NullLiteral(getAndAdvance()); | 7881 return new NullLiteral(getAndAdvance()); |
| 7911 } else if (_matchesKeyword(Keyword.FALSE)) { | 7882 } else if (_matchesKeyword(Keyword.FALSE)) { |
| 7912 return new BooleanLiteral(getAndAdvance(), false); | 7883 return new BooleanLiteral(getAndAdvance(), false); |
| 7913 } else if (_matchesKeyword(Keyword.TRUE)) { | 7884 } else if (_matchesKeyword(Keyword.TRUE)) { |
| 7914 return new BooleanLiteral(getAndAdvance(), true); | 7885 return new BooleanLiteral(getAndAdvance(), true); |
| 7915 } else if (_matches(TokenType.DOUBLE)) { | 7886 } else if (_matches(TokenType.DOUBLE)) { |
| 7916 Token token = getAndAdvance(); | 7887 Token token = getAndAdvance(); |
| 7917 double value = 0.0; | 7888 double value = 0.0; |
| 7918 try { | 7889 try { |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8617 Token operator = getAndAdvance(); | 8588 Token operator = getAndAdvance(); |
| 8618 if (_matchesKeyword(Keyword.SUPER)) { | 8589 if (_matchesKeyword(Keyword.SUPER)) { |
| 8619 if (_tokenMatches(_peek(), TokenType.OPEN_SQUARE_BRACKET) || | 8590 if (_tokenMatches(_peek(), TokenType.OPEN_SQUARE_BRACKET) || |
| 8620 _tokenMatches(_peek(), TokenType.PERIOD)) { | 8591 _tokenMatches(_peek(), TokenType.PERIOD)) { |
| 8621 // "prefixOperator unaryExpression" | 8592 // "prefixOperator unaryExpression" |
| 8622 // --> "prefixOperator postfixExpression" | 8593 // --> "prefixOperator postfixExpression" |
| 8623 // --> "prefixOperator primary selector*" | 8594 // --> "prefixOperator primary selector*" |
| 8624 // --> "prefixOperator 'super' assignableSelector selector*" | 8595 // --> "prefixOperator 'super' assignableSelector selector*" |
| 8625 return new PrefixExpression(operator, _parseUnaryExpression()); | 8596 return new PrefixExpression(operator, _parseUnaryExpression()); |
| 8626 } | 8597 } |
| 8627 return new PrefixExpression(operator, new SuperExpression(getAndAdvance(
))); | 8598 return new PrefixExpression( |
| 8599 operator, |
| 8600 new SuperExpression(getAndAdvance())); |
| 8628 } | 8601 } |
| 8629 return new PrefixExpression(operator, _parseUnaryExpression()); | 8602 return new PrefixExpression(operator, _parseUnaryExpression()); |
| 8630 } else if (_currentToken.type.isIncrementOperator) { | 8603 } else if (_currentToken.type.isIncrementOperator) { |
| 8631 Token operator = getAndAdvance(); | 8604 Token operator = getAndAdvance(); |
| 8632 if (_matchesKeyword(Keyword.SUPER)) { | 8605 if (_matchesKeyword(Keyword.SUPER)) { |
| 8633 if (_tokenMatches(_peek(), TokenType.OPEN_SQUARE_BRACKET) || | 8606 if (_tokenMatches(_peek(), TokenType.OPEN_SQUARE_BRACKET) || |
| 8634 _tokenMatches(_peek(), TokenType.PERIOD)) { | 8607 _tokenMatches(_peek(), TokenType.PERIOD)) { |
| 8635 // --> "prefixOperator 'super' assignableSelector selector*" | 8608 // --> "prefixOperator 'super' assignableSelector selector*" |
| 8636 return new PrefixExpression(operator, _parseUnaryExpression()); | 8609 return new PrefixExpression(operator, _parseUnaryExpression()); |
| 8637 } | 8610 } |
| (...skipping 3524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12162 * Copy resolution data from one node to another. | 12135 * Copy resolution data from one node to another. |
| 12163 * | 12136 * |
| 12164 * @param fromNode the node from which resolution information will be copied | 12137 * @param fromNode the node from which resolution information will be copied |
| 12165 * @param toNode the node to which resolution information will be copied | 12138 * @param toNode the node to which resolution information will be copied |
| 12166 */ | 12139 */ |
| 12167 static void copyResolutionData(AstNode fromNode, AstNode toNode) { | 12140 static void copyResolutionData(AstNode fromNode, AstNode toNode) { |
| 12168 ResolutionCopier copier = new ResolutionCopier(); | 12141 ResolutionCopier copier = new ResolutionCopier(); |
| 12169 copier._isEqualNodes(fromNode, toNode); | 12142 copier._isEqualNodes(fromNode, toNode); |
| 12170 } | 12143 } |
| 12171 } | 12144 } |
| OLD | NEW |