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' show Token, TokenType; | 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; |
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 } | 1283 } |
1284 | 1284 |
1285 @override | 1285 @override |
1286 void beginClassDeclaration(Token beginToken, Token name) { | 1286 void beginClassDeclaration(Token beginToken, Token name) { |
1287 assert(className == null); | 1287 assert(className == null); |
1288 className = name.lexeme; | 1288 className = name.lexeme; |
1289 } | 1289 } |
1290 | 1290 |
1291 @override | 1291 @override |
1292 void handleNativeClause(Token nativeToken, bool hasName) { | 1292 void handleNativeClause(Token nativeToken, bool hasName) { |
1293 push(ast.nativeClause(nativeToken, hasName ? pop() : null)); | 1293 if (!hasName) push(NullValue.StringLiteral); |
1294 } | 1294 } |
1295 | 1295 |
1296 @override | 1296 @override |
1297 void endClassDeclaration( | 1297 void endClassDeclaration( |
1298 int interfacesCount, | 1298 int interfacesCount, |
1299 Token beginToken, | 1299 Token beginToken, |
1300 Token classKeyword, | 1300 Token classKeyword, |
1301 Token extendsKeyword, | 1301 Token extendsKeyword, |
1302 Token implementsKeyword, | 1302 Token implementsKeyword, |
1303 Token nativeToken, | 1303 Token nativeToken, |
1304 Token endToken) { | 1304 Token endToken) { |
1305 debugEvent("ClassDeclaration"); | 1305 debugEvent("ClassDeclaration"); |
1306 _ClassBody body = pop(); | 1306 _ClassBody body = pop(); |
1307 NativeClause nativeClause = nativeToken != null ? pop() : null; | 1307 NativeClause nativeClause; |
| 1308 if (nativeToken != null) { |
| 1309 var nativeName = pop(); |
| 1310 nativeClause = ast.nativeClause(nativeToken, |
| 1311 nativeName == NullValue.StringLiteral ? null : nativeName); |
| 1312 } |
1308 ImplementsClause implementsClause; | 1313 ImplementsClause implementsClause; |
1309 if (implementsKeyword != null) { | 1314 if (implementsKeyword != null) { |
1310 List<TypeName> interfaces = popList(interfacesCount); | 1315 List<TypeName> interfaces = popList(interfacesCount); |
1311 implementsClause = ast.implementsClause(implementsKeyword, interfaces); | 1316 implementsClause = ast.implementsClause(implementsKeyword, interfaces); |
1312 } | 1317 } |
1313 ExtendsClause extendsClause; | 1318 ExtendsClause extendsClause; |
1314 WithClause withClause; | 1319 WithClause withClause; |
1315 var supertype = pop(); | 1320 var supertype = pop(); |
1316 if (supertype == null) { | 1321 if (supertype == null) { |
1317 // No extends clause | 1322 // No extends clause |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 } | 1605 } |
1601 | 1606 |
1602 @override | 1607 @override |
1603 void endTypeVariables(int count, Token beginToken, Token endToken) { | 1608 void endTypeVariables(int count, Token beginToken, Token endToken) { |
1604 debugEvent("TypeVariables"); | 1609 debugEvent("TypeVariables"); |
1605 List<TypeParameter> typeParameters = popList(count); | 1610 List<TypeParameter> typeParameters = popList(count); |
1606 push(ast.typeParameterList(beginToken, typeParameters, endToken)); | 1611 push(ast.typeParameterList(beginToken, typeParameters, endToken)); |
1607 } | 1612 } |
1608 | 1613 |
1609 @override | 1614 @override |
1610 void endMethod(Token getOrSet, Token beginToken, Token endToken) { | 1615 void endMethod( |
| 1616 Token getOrSet, Token beginToken, Token nativeToken, Token endToken) { |
1611 debugEvent("Method"); | 1617 debugEvent("Method"); |
1612 FunctionBody body = pop(); | 1618 FunctionBody body = pop(); |
| 1619 if (nativeToken != null) { |
| 1620 var nativeName = pop(); |
| 1621 if (nativeName == NullValue.StringLiteral) { |
| 1622 nativeName = null; |
| 1623 } |
| 1624 if (body is EmptyFunctionBody) { |
| 1625 body = ast.nativeFunctionBody(nativeToken, nativeName, body.endToken); |
| 1626 } else { |
| 1627 // TODO(danrubel): Report error if native clause is used with |
| 1628 // non-empty function body. |
| 1629 } |
| 1630 } |
1613 ConstructorName redirectedConstructor = null; // TODO(paulberry) | 1631 ConstructorName redirectedConstructor = null; // TODO(paulberry) |
1614 List<ConstructorInitializer> initializers = pop() ?? const []; | 1632 List<ConstructorInitializer> initializers = pop() ?? const []; |
1615 Token separator = pop(); | 1633 Token separator = pop(); |
1616 FormalParameterList parameters = pop(); | 1634 FormalParameterList parameters = pop(); |
1617 TypeParameterList typeParameters = pop(); | 1635 TypeParameterList typeParameters = pop(); |
1618 var name = pop(); | 1636 var name = pop(); |
1619 TypeAnnotation returnType = pop(); | 1637 TypeAnnotation returnType = pop(); |
1620 _Modifiers modifiers = pop(); | 1638 _Modifiers modifiers = pop(); |
1621 List<Annotation> metadata = pop(); | 1639 List<Annotation> metadata = pop(); |
1622 Comment comment = pop(); | 1640 Comment comment = pop(); |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2044 } else if (identical('var', s)) { | 2062 } else if (identical('var', s)) { |
2045 finalConstOrVarKeyword = token; | 2063 finalConstOrVarKeyword = token; |
2046 } else if (identical('covariant', s)) { | 2064 } else if (identical('covariant', s)) { |
2047 covariantKeyword = token; | 2065 covariantKeyword = token; |
2048 } else { | 2066 } else { |
2049 unhandled("$s", "modifier", token.charOffset, null); | 2067 unhandled("$s", "modifier", token.charOffset, null); |
2050 } | 2068 } |
2051 } | 2069 } |
2052 } | 2070 } |
2053 } | 2071 } |
OLD | NEW |