| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library fasta.analyzer.ast_builder; | 5 library fasta.analyzer.ast_builder; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; | 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; |
| 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; | 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; |
| 10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; | 10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 push(ast.ifStatement( | 409 push(ast.ifStatement( |
| 410 toAnalyzerToken(ifToken), | 410 toAnalyzerToken(ifToken), |
| 411 toAnalyzerToken(ifToken.next), | 411 toAnalyzerToken(ifToken.next), |
| 412 condition, | 412 condition, |
| 413 toAnalyzerToken(leftParenthesis.endGroup), | 413 toAnalyzerToken(leftParenthesis.endGroup), |
| 414 thenPart, | 414 thenPart, |
| 415 toAnalyzerToken(elseToken), | 415 toAnalyzerToken(elseToken), |
| 416 elsePart)); | 416 elsePart)); |
| 417 } | 417 } |
| 418 | 418 |
| 419 void prepareInitializers() { | |
| 420 debugEvent("prepareInitializers"); | |
| 421 } | |
| 422 | |
| 423 void handleNoInitializers() { | 419 void handleNoInitializers() { |
| 424 debugEvent("NoInitializers"); | 420 debugEvent("NoInitializers"); |
| 425 push(NullValue.ConstructorInitializerSeparator); | 421 push(NullValue.ConstructorInitializerSeparator); |
| 426 push(NullValue.ConstructorInitializers); | 422 push(NullValue.ConstructorInitializers); |
| 427 } | 423 } |
| 428 | 424 |
| 429 void endInitializers(int count, Token beginToken, Token endToken) { | 425 void endInitializers(int count, Token beginToken, Token endToken) { |
| 430 debugEvent("Initializers"); | 426 debugEvent("Initializers"); |
| 431 List<Object> initializerObjects = popList(count) ?? const []; | 427 List<Object> initializerObjects = popList(count) ?? const []; |
| 432 | 428 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 // SimpleIdentifier into a VariableDeclaration, and then when this code was | 530 // SimpleIdentifier into a VariableDeclaration, and then when this code was |
| 535 // reached, node would always be a VariableDeclaration. | 531 // reached, node would always be a VariableDeclaration. |
| 536 if (node is VariableDeclaration) { | 532 if (node is VariableDeclaration) { |
| 537 variable = node; | 533 variable = node; |
| 538 } else if (node is SimpleIdentifier) { | 534 } else if (node is SimpleIdentifier) { |
| 539 variable = ast.variableDeclaration(node, null, null); | 535 variable = ast.variableDeclaration(node, null, null); |
| 540 } else { | 536 } else { |
| 541 internalError("unhandled identifier: ${node.runtimeType}"); | 537 internalError("unhandled identifier: ${node.runtimeType}"); |
| 542 } | 538 } |
| 543 push(variable); | 539 push(variable); |
| 544 scope[variable.name.name] = variable.name.staticElement = | 540 scope.declare( |
| 545 new AnalyzerLocalVariableElemment(variable); | 541 variable.name.name, |
| 542 variable.name.staticElement = |
| 543 new AnalyzerLocalVariableElemment(variable), |
| 544 nameToken.charOffset, |
| 545 uri); |
| 546 } | 546 } |
| 547 | 547 |
| 548 void endVariablesDeclaration(int count, Token endToken) { | 548 void endVariablesDeclaration(int count, Token endToken) { |
| 549 debugEvent("VariablesDeclaration"); | 549 debugEvent("VariablesDeclaration"); |
| 550 List<VariableDeclaration> variables = popList(count); | 550 List<VariableDeclaration> variables = popList(count); |
| 551 TypeAnnotation type = pop(); | 551 TypeAnnotation type = pop(); |
| 552 _Modifiers modifiers = pop(); | 552 _Modifiers modifiers = pop(); |
| 553 Token keyword = modifiers?.finalConstOrVarKeyword; | 553 Token keyword = modifiers?.finalConstOrVarKeyword; |
| 554 List<Annotation> metadata = pop(); | 554 List<Annotation> metadata = pop(); |
| 555 Comment comment = pop(); | 555 Comment comment = pop(); |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 } | 894 } |
| 895 } | 895 } |
| 896 | 896 |
| 897 ParameterKind analyzerKind = _toAnalyzerParameterKind(kind); | 897 ParameterKind analyzerKind = _toAnalyzerParameterKind(kind); |
| 898 if (analyzerKind != ParameterKind.REQUIRED) { | 898 if (analyzerKind != ParameterKind.REQUIRED) { |
| 899 node = ast.defaultFormalParameter(node, analyzerKind, | 899 node = ast.defaultFormalParameter(node, analyzerKind, |
| 900 toAnalyzerToken(defaultValue?.separator), defaultValue?.value); | 900 toAnalyzerToken(defaultValue?.separator), defaultValue?.value); |
| 901 } | 901 } |
| 902 | 902 |
| 903 if (name != null) { | 903 if (name != null) { |
| 904 scope[name.name] = | 904 scope.declare( |
| 905 name.staticElement = new AnalyzerParameterElement(node); | 905 name.name, |
| 906 name.staticElement = new AnalyzerParameterElement(node), |
| 907 name.offset, |
| 908 uri); |
| 906 } | 909 } |
| 907 push(node); | 910 push(node); |
| 908 } | 911 } |
| 909 | 912 |
| 910 @override | 913 @override |
| 911 void endFunctionTypedFormalParameter( | 914 void endFunctionTypedFormalParameter( |
| 912 Token thisKeyword, FormalParameterType kind) { | 915 Token thisKeyword, FormalParameterType kind) { |
| 913 debugEvent("FunctionTypedFormalParameter"); | 916 debugEvent("FunctionTypedFormalParameter"); |
| 914 | 917 |
| 915 FormalParameterList formalParameters = pop(); | 918 FormalParameterList formalParameters = pop(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 941 comment: comment, | 944 comment: comment, |
| 942 covariantKeyword: toAnalyzerToken(covariantKeyword), | 945 covariantKeyword: toAnalyzerToken(covariantKeyword), |
| 943 type: returnType, | 946 type: returnType, |
| 944 thisKeyword: toAnalyzerToken(thisKeyword), | 947 thisKeyword: toAnalyzerToken(thisKeyword), |
| 945 period: toAnalyzerToken(period), | 948 period: toAnalyzerToken(period), |
| 946 identifier: name, | 949 identifier: name, |
| 947 typeParameters: typeParameters, | 950 typeParameters: typeParameters, |
| 948 parameters: formalParameters); | 951 parameters: formalParameters); |
| 949 } | 952 } |
| 950 | 953 |
| 951 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); | 954 scope.declare( |
| 955 name.name, |
| 956 name.staticElement = new AnalyzerParameterElement(node), |
| 957 name.offset, |
| 958 uri); |
| 952 push(node); | 959 push(node); |
| 953 } | 960 } |
| 954 | 961 |
| 955 void endFormalParameters( | 962 void endFormalParameters( |
| 956 int count, Token beginToken, Token endToken, MemberKind kind) { | 963 int count, Token beginToken, Token endToken, MemberKind kind) { |
| 957 debugEvent("FormalParameters"); | 964 debugEvent("FormalParameters"); |
| 958 List rawParameters = popList(count) ?? const <Object>[]; | 965 List rawParameters = popList(count) ?? const <Object>[]; |
| 959 List<FormalParameter> parameters = <FormalParameter>[]; | 966 List<FormalParameter> parameters = <FormalParameter>[]; |
| 960 Token leftDelimiter; | 967 Token leftDelimiter; |
| 961 Token rightDelimiter; | 968 Token rightDelimiter; |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1980 | 1987 |
| 1981 /// Scans the given [code], and returns the tokens, otherwise returns `null`. | 1988 /// Scans the given [code], and returns the tokens, otherwise returns `null`. |
| 1982 Token _scanGenericMethodComment(String code, int offset) { | 1989 Token _scanGenericMethodComment(String code, int offset) { |
| 1983 var scanner = new SubStringScanner(offset, code); | 1990 var scanner = new SubStringScanner(offset, code); |
| 1984 Token firstToken = scanner.tokenize(); | 1991 Token firstToken = scanner.tokenize(); |
| 1985 if (scanner.hasErrors) { | 1992 if (scanner.hasErrors) { |
| 1986 return null; | 1993 return null; |
| 1987 } | 1994 } |
| 1988 return firstToken; | 1995 return firstToken; |
| 1989 } | 1996 } |
| 1997 |
| 1998 @override |
| 1999 void addCompileTimeErrorFromMessage(FastaMessage message) { |
| 2000 library.addCompileTimeError(message.charOffset, message.message, |
| 2001 fileUri: message.uri); |
| 2002 } |
| 1990 } | 2003 } |
| 1991 | 2004 |
| 1992 /// Data structure placed on the stack to represent a class body. | 2005 /// Data structure placed on the stack to represent a class body. |
| 1993 /// | 2006 /// |
| 1994 /// This is needed because analyzer has no separate AST representation of a | 2007 /// This is needed because analyzer has no separate AST representation of a |
| 1995 /// class body; it simply stores all of the relevant data in the | 2008 /// class body; it simply stores all of the relevant data in the |
| 1996 /// [ClassDeclaration] object. | 2009 /// [ClassDeclaration] object. |
| 1997 class _ClassBody { | 2010 class _ClassBody { |
| 1998 final Token beginToken; | 2011 final Token beginToken; |
| 1999 | 2012 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2087 } else if (identical('var', s)) { | 2100 } else if (identical('var', s)) { |
| 2088 finalConstOrVarKeyword = token; | 2101 finalConstOrVarKeyword = token; |
| 2089 } else if (identical('covariant', s)) { | 2102 } else if (identical('covariant', s)) { |
| 2090 covariantKeyword = token; | 2103 covariantKeyword = token; |
| 2091 } else { | 2104 } else { |
| 2092 internalError('Unhandled modifier: $s'); | 2105 internalError('Unhandled modifier: $s'); |
| 2093 } | 2106 } |
| 2094 } | 2107 } |
| 2095 } | 2108 } |
| 2096 } | 2109 } |
| OLD | NEW |