Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: pkg/analyzer/lib/src/fasta/ast_builder.dart

Issue 2996163002: support class native clause (Closed)
Patch Set: update DietListener and test Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 bool parseGenericMethodComments = false; 53 bool parseGenericMethodComments = false;
54 54
55 /// The name of the class currently being parsed, or `null` if no class is 55 /// The name of the class currently being parsed, or `null` if no class is
56 /// being parsed. 56 /// being parsed.
57 String className; 57 String className;
58 58
59 /// If true, this is building a full AST. Otherwise, only create method 59 /// If true, this is building a full AST. Otherwise, only create method
60 /// bodies. 60 /// bodies.
61 final bool isFullAst; 61 final bool isFullAst;
62 62
63 /// `true` if the `native` clause is allowed
64 /// in class, method, and function declarations.
65 ///
66 /// This is being replaced by the @native(...) annotation.
67 //
68 // TODO(danrubel) Move this flag to a better location
69 // and should only be true if either:
70 // * The current library is a platform library
71 // * The current library has an import that uses the scheme "dart-ext".
72 bool allowNativeClause = false;
73
63 AstBuilder(this.errorReporter, this.library, this.member, Scope scope, 74 AstBuilder(this.errorReporter, this.library, this.member, Scope scope,
64 this.isFullAst, 75 this.isFullAst,
65 [Uri uri]) 76 [Uri uri])
66 : uri = uri ?? library.fileUri, 77 : uri = uri ?? library.fileUri,
67 super(scope); 78 super(scope);
68 79
69 createJumpTarget(JumpTargetKind kind, int charOffset) { 80 createJumpTarget(JumpTargetKind kind, int charOffset) {
70 // TODO(ahe): Implement jump targets. 81 // TODO(ahe): Implement jump targets.
71 return null; 82 return null;
72 } 83 }
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 beginToken, popList(memberCount) ?? <ClassMember>[], endToken)); 1282 beginToken, popList(memberCount) ?? <ClassMember>[], endToken));
1272 } 1283 }
1273 1284
1274 @override 1285 @override
1275 void beginClassDeclaration(Token beginToken, Token name) { 1286 void beginClassDeclaration(Token beginToken, Token name) {
1276 assert(className == null); 1287 assert(className == null);
1277 className = name.lexeme; 1288 className = name.lexeme;
1278 } 1289 }
1279 1290
1280 @override 1291 @override
1292 void handleNativeClause(Token nativeToken, bool hasName) {
1293 push(ast.nativeClause(nativeToken, hasName ? pop() : null));
1294 }
1295
1296 @override
1281 void endClassDeclaration( 1297 void endClassDeclaration(
1282 int interfacesCount, 1298 int interfacesCount,
1283 Token beginToken, 1299 Token beginToken,
1284 Token classKeyword, 1300 Token classKeyword,
1285 Token extendsKeyword, 1301 Token extendsKeyword,
1286 Token implementsKeyword, 1302 Token implementsKeyword,
1303 Token nativeToken,
1287 Token endToken) { 1304 Token endToken) {
1288 debugEvent("ClassDeclaration"); 1305 debugEvent("ClassDeclaration");
1289 _ClassBody body = pop(); 1306 _ClassBody body = pop();
1307 NativeClause nativeClause = nativeToken != null ? pop() : null;
1290 ImplementsClause implementsClause; 1308 ImplementsClause implementsClause;
1291 if (implementsKeyword != null) { 1309 if (implementsKeyword != null) {
1292 List<TypeName> interfaces = popList(interfacesCount); 1310 List<TypeName> interfaces = popList(interfacesCount);
1293 implementsClause = ast.implementsClause(implementsKeyword, interfaces); 1311 implementsClause = ast.implementsClause(implementsKeyword, interfaces);
1294 } 1312 }
1295 ExtendsClause extendsClause; 1313 ExtendsClause extendsClause;
1296 WithClause withClause; 1314 WithClause withClause;
1297 var supertype = pop(); 1315 var supertype = pop();
1298 if (supertype == null) { 1316 if (supertype == null) {
1299 // No extends clause 1317 // No extends clause
1300 } else if (supertype is TypeName) { 1318 } else if (supertype is TypeName) {
1301 extendsClause = ast.extendsClause(extendsKeyword, supertype); 1319 extendsClause = ast.extendsClause(extendsKeyword, supertype);
1302 } else if (supertype is _MixinApplication) { 1320 } else if (supertype is _MixinApplication) {
1303 extendsClause = ast.extendsClause(extendsKeyword, supertype.supertype); 1321 extendsClause = ast.extendsClause(extendsKeyword, supertype.supertype);
1304 withClause = ast.withClause(supertype.withKeyword, supertype.mixinTypes); 1322 withClause = ast.withClause(supertype.withKeyword, supertype.mixinTypes);
1305 } else { 1323 } else {
1306 unhandled("${supertype.runtimeType}", "supertype", 1324 unhandled("${supertype.runtimeType}", "supertype",
1307 extendsKeyword.charOffset, uri); 1325 extendsKeyword.charOffset, uri);
1308 } 1326 }
1309 TypeParameterList typeParameters = pop(); 1327 TypeParameterList typeParameters = pop();
1310 SimpleIdentifier name = pop(); 1328 SimpleIdentifier name = pop();
1311 assert(className == name.name); 1329 assert(className == name.name);
1312 className = null; 1330 className = null;
1313 _Modifiers modifiers = pop(); 1331 _Modifiers modifiers = pop();
1314 Token abstractKeyword = modifiers?.abstractKeyword; 1332 Token abstractKeyword = modifiers?.abstractKeyword;
1315 List<Annotation> metadata = pop(); 1333 List<Annotation> metadata = pop();
1316 Comment comment = pop(); 1334 Comment comment = pop();
1317 declarations.add(ast.classDeclaration( 1335 ClassDeclaration classDeclaration = ast.classDeclaration(
1318 comment, 1336 comment,
1319 metadata, 1337 metadata,
1320 abstractKeyword, 1338 abstractKeyword,
1321 classKeyword, 1339 classKeyword,
1322 name, 1340 name,
1323 typeParameters, 1341 typeParameters,
1324 extendsClause, 1342 extendsClause,
1325 withClause, 1343 withClause,
1326 implementsClause, 1344 implementsClause,
1327 body.beginToken, 1345 body.beginToken,
1328 body.members, 1346 body.members,
1329 body.endToken)); 1347 body.endToken);
1348 classDeclaration.nativeClause = nativeClause;
1349 declarations.add(classDeclaration);
1330 } 1350 }
1331 1351
1332 @override 1352 @override
1333 void endMixinApplication(Token withKeyword) { 1353 void endMixinApplication(Token withKeyword) {
1334 debugEvent("MixinApplication"); 1354 debugEvent("MixinApplication");
1335 List<TypeName> mixinTypes = pop(); 1355 List<TypeName> mixinTypes = pop();
1336 TypeName supertype = pop(); 1356 TypeName supertype = pop();
1337 push(new _MixinApplication(supertype, withKeyword, mixinTypes)); 1357 push(new _MixinApplication(supertype, withKeyword, mixinTypes));
1338 } 1358 }
1339 1359
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 1904
1885 @override 1905 @override
1886 void addCompileTimeError(Message message, int charOffset) { 1906 void addCompileTimeError(Message message, int charOffset) {
1887 Code code = message.code; 1907 Code code = message.code;
1888 Map<String, dynamic> arguments = message.arguments; 1908 Map<String, dynamic> arguments = message.arguments;
1889 switch (code.analyzerCode) { 1909 switch (code.analyzerCode) {
1890 case "EXPECTED_TYPE_NAME": 1910 case "EXPECTED_TYPE_NAME":
1891 errorReporter?.reportErrorForOffset( 1911 errorReporter?.reportErrorForOffset(
1892 ParserErrorCode.EXPECTED_TYPE_NAME, charOffset, 1); 1912 ParserErrorCode.EXPECTED_TYPE_NAME, charOffset, 1);
1893 return; 1913 return;
1914 case "NATIVE_CLAUSE_SHOULD_BE_ANNOTATION":
1915 if (!allowNativeClause) {
1916 errorReporter?.reportErrorForOffset(
1917 ParserErrorCode.NATIVE_CLAUSE_SHOULD_BE_ANNOTATION,
1918 charOffset,
1919 1);
1920 }
1921 return;
1894 case "EXPECTED_STRING_LITERAL": 1922 case "EXPECTED_STRING_LITERAL":
1895 errorReporter?.reportErrorForOffset( 1923 errorReporter?.reportErrorForOffset(
1896 ParserErrorCode.EXPECTED_STRING_LITERAL, charOffset, 1); 1924 ParserErrorCode.EXPECTED_STRING_LITERAL, charOffset, 1);
1897 return; 1925 return;
1898 case "UNEXPECTED_TOKEN": 1926 case "UNEXPECTED_TOKEN":
1899 var text = arguments['string']; 1927 var text = arguments['string'];
1900 if (text == null) { 1928 if (text == null) {
1901 Token token = arguments['token']; 1929 Token token = arguments['token'];
1902 if (token != null) { 1930 if (token != null) {
1903 text = token.lexeme; 1931 text = token.lexeme;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 } else if (identical('var', s)) { 2039 } else if (identical('var', s)) {
2012 finalConstOrVarKeyword = token; 2040 finalConstOrVarKeyword = token;
2013 } else if (identical('covariant', s)) { 2041 } else if (identical('covariant', s)) {
2014 covariantKeyword = token; 2042 covariantKeyword = token;
2015 } else { 2043 } else {
2016 unhandled("$s", "modifier", token.charOffset, null); 2044 unhandled("$s", "modifier", token.charOffset, null);
2017 } 2045 }
2018 } 2046 }
2019 } 2047 }
2020 } 2048 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/error/syntactic_errors.dart ('k') | pkg/analyzer/test/generated/parser_fasta_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698