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

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

Issue 2996163002: support class native clause (Closed)
Patch Set: add new fasta native clause error code 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 13 matching lines...) Expand all
24 import 'package:front_end/src/fasta/messages.dart' 24 import 'package:front_end/src/fasta/messages.dart'
25 show Code, Message, codeExpectedExpression, codeExpectedFunctionBody; 25 show Code, Message, codeExpectedExpression, codeExpectedFunctionBody;
26 import 'package:front_end/src/fasta/kernel/kernel_builder.dart' 26 import 'package:front_end/src/fasta/kernel/kernel_builder.dart'
27 show Builder, KernelLibraryBuilder, Scope; 27 show Builder, KernelLibraryBuilder, Scope;
28 import 'package:front_end/src/fasta/quote.dart'; 28 import 'package:front_end/src/fasta/quote.dart';
29 import 'package:front_end/src/fasta/source/scope_listener.dart' 29 import 'package:front_end/src/fasta/source/scope_listener.dart'
30 show JumpTargetKind, NullValue, ScopeListener; 30 show JumpTargetKind, NullValue, ScopeListener;
31 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; 31 import 'package:analyzer/src/dart/error/syntactic_errors.dart';
32 32
33 class AstBuilder extends ScopeListener { 33 class AstBuilder extends ScopeListener {
34 /// The native clause in class, method, and function declarations
35 /// is being replaced by the @native(...) annotation.
36 static bool isNativeClauseAllowed = true;
ahe 2017/08/21 12:04:10 I think this should only be true if: * The curren
danrubel 2017/08/22 01:35:27 Good point. Cleaned up and added TODO per discussi
37
34 final AstFactory ast = standard.astFactory; 38 final AstFactory ast = standard.astFactory;
35 39
36 final ErrorReporter errorReporter; 40 final ErrorReporter errorReporter;
37 final KernelLibraryBuilder library; 41 final KernelLibraryBuilder library;
38 final Builder member; 42 final Builder member;
39 43
40 ScriptTag scriptTag; 44 ScriptTag scriptTag;
41 final List<Directive> directives = <Directive>[]; 45 final List<Directive> directives = <Directive>[];
42 final List<CompilationUnitMember> declarations = <CompilationUnitMember>[]; 46 final List<CompilationUnitMember> declarations = <CompilationUnitMember>[];
43 47
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 className = name.lexeme; 1281 className = name.lexeme;
1278 } 1282 }
1279 1283
1280 @override 1284 @override
1281 void endClassDeclaration( 1285 void endClassDeclaration(
1282 int interfacesCount, 1286 int interfacesCount,
1283 Token beginToken, 1287 Token beginToken,
1284 Token classKeyword, 1288 Token classKeyword,
1285 Token extendsKeyword, 1289 Token extendsKeyword,
1286 Token implementsKeyword, 1290 Token implementsKeyword,
1291 Token nativeToken,
1287 Token endToken) { 1292 Token endToken) {
1288 debugEvent("ClassDeclaration"); 1293 debugEvent("ClassDeclaration");
1289 _ClassBody body = pop(); 1294 _ClassBody body = pop();
1295 NativeClause nativeClause;
1296 if (nativeToken?.next?.type == TokenType.STRING) {
ahe 2017/08/21 12:04:10 This feels like implementing parser logic in the l
danrubel 2017/08/22 01:35:27 I was trying for the simplest thing given that thi
1297 nativeClause = ast.nativeClause(nativeToken, pop());
1298 }
1290 ImplementsClause implementsClause; 1299 ImplementsClause implementsClause;
1291 if (implementsKeyword != null) { 1300 if (implementsKeyword != null) {
1292 List<TypeName> interfaces = popList(interfacesCount); 1301 List<TypeName> interfaces = popList(interfacesCount);
1293 implementsClause = ast.implementsClause(implementsKeyword, interfaces); 1302 implementsClause = ast.implementsClause(implementsKeyword, interfaces);
1294 } 1303 }
1295 ExtendsClause extendsClause; 1304 ExtendsClause extendsClause;
1296 WithClause withClause; 1305 WithClause withClause;
1297 var supertype = pop(); 1306 var supertype = pop();
1298 if (supertype == null) { 1307 if (supertype == null) {
1299 // No extends clause 1308 // No extends clause
1300 } else if (supertype is TypeName) { 1309 } else if (supertype is TypeName) {
1301 extendsClause = ast.extendsClause(extendsKeyword, supertype); 1310 extendsClause = ast.extendsClause(extendsKeyword, supertype);
1302 } else if (supertype is _MixinApplication) { 1311 } else if (supertype is _MixinApplication) {
1303 extendsClause = ast.extendsClause(extendsKeyword, supertype.supertype); 1312 extendsClause = ast.extendsClause(extendsKeyword, supertype.supertype);
1304 withClause = ast.withClause(supertype.withKeyword, supertype.mixinTypes); 1313 withClause = ast.withClause(supertype.withKeyword, supertype.mixinTypes);
1305 } else { 1314 } else {
1306 unhandled("${supertype.runtimeType}", "supertype", 1315 unhandled("${supertype.runtimeType}", "supertype",
1307 extendsKeyword.charOffset, uri); 1316 extendsKeyword.charOffset, uri);
1308 } 1317 }
1309 TypeParameterList typeParameters = pop(); 1318 TypeParameterList typeParameters = pop();
1310 SimpleIdentifier name = pop(); 1319 SimpleIdentifier name = pop();
1311 assert(className == name.name); 1320 assert(className == name.name);
1312 className = null; 1321 className = null;
1313 _Modifiers modifiers = pop(); 1322 _Modifiers modifiers = pop();
1314 Token abstractKeyword = modifiers?.abstractKeyword; 1323 Token abstractKeyword = modifiers?.abstractKeyword;
1315 List<Annotation> metadata = pop(); 1324 List<Annotation> metadata = pop();
1316 Comment comment = pop(); 1325 Comment comment = pop();
1317 declarations.add(ast.classDeclaration( 1326 ClassDeclaration classDeclaration = ast.classDeclaration(
1318 comment, 1327 comment,
1319 metadata, 1328 metadata,
1320 abstractKeyword, 1329 abstractKeyword,
1321 classKeyword, 1330 classKeyword,
1322 name, 1331 name,
1323 typeParameters, 1332 typeParameters,
1324 extendsClause, 1333 extendsClause,
1325 withClause, 1334 withClause,
1326 implementsClause, 1335 implementsClause,
1327 body.beginToken, 1336 body.beginToken,
1328 body.members, 1337 body.members,
1329 body.endToken)); 1338 body.endToken);
1339 classDeclaration.nativeClause = nativeClause;
1340 declarations.add(classDeclaration);
1330 } 1341 }
1331 1342
1332 @override 1343 @override
1333 void endMixinApplication(Token withKeyword) { 1344 void endMixinApplication(Token withKeyword) {
1334 debugEvent("MixinApplication"); 1345 debugEvent("MixinApplication");
1335 List<TypeName> mixinTypes = pop(); 1346 List<TypeName> mixinTypes = pop();
1336 TypeName supertype = pop(); 1347 TypeName supertype = pop();
1337 push(new _MixinApplication(supertype, withKeyword, mixinTypes)); 1348 push(new _MixinApplication(supertype, withKeyword, mixinTypes));
1338 } 1349 }
1339 1350
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 1895
1885 @override 1896 @override
1886 void addCompileTimeError(Message message, int charOffset) { 1897 void addCompileTimeError(Message message, int charOffset) {
1887 Code code = message.code; 1898 Code code = message.code;
1888 Map<String, dynamic> arguments = message.arguments; 1899 Map<String, dynamic> arguments = message.arguments;
1889 switch (code.analyzerCode) { 1900 switch (code.analyzerCode) {
1890 case "EXPECTED_TYPE_NAME": 1901 case "EXPECTED_TYPE_NAME":
1891 errorReporter?.reportErrorForOffset( 1902 errorReporter?.reportErrorForOffset(
1892 ParserErrorCode.EXPECTED_TYPE_NAME, charOffset, 1); 1903 ParserErrorCode.EXPECTED_TYPE_NAME, charOffset, 1);
1893 return; 1904 return;
1905 case "NATIVE_CLAUSE_SHOULD_BE_ANNOTATION":
1906 if (!isNativeClauseAllowed) {
1907 errorReporter?.reportErrorForOffset(
1908 ParserErrorCode.NATIVE_CLAUSE_SHOULD_BE_ANNOTATION,
1909 charOffset,
1910 1);
1911 }
1912 return;
1894 case "EXPECTED_STRING_LITERAL": 1913 case "EXPECTED_STRING_LITERAL":
1895 errorReporter?.reportErrorForOffset( 1914 errorReporter?.reportErrorForOffset(
1896 ParserErrorCode.EXPECTED_STRING_LITERAL, charOffset, 1); 1915 ParserErrorCode.EXPECTED_STRING_LITERAL, charOffset, 1);
1897 return; 1916 return;
1898 case "UNEXPECTED_TOKEN": 1917 case "UNEXPECTED_TOKEN":
1899 var text = arguments['string']; 1918 var text = arguments['string'];
1900 if (text == null) { 1919 if (text == null) {
1901 Token token = arguments['token']; 1920 Token token = arguments['token'];
1902 if (token != null) { 1921 if (token != null) {
1903 text = token.lexeme; 1922 text = token.lexeme;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 } else if (identical('var', s)) { 2030 } else if (identical('var', s)) {
2012 finalConstOrVarKeyword = token; 2031 finalConstOrVarKeyword = token;
2013 } else if (identical('covariant', s)) { 2032 } else if (identical('covariant', s)) {
2014 covariantKeyword = token; 2033 covariantKeyword = token;
2015 } else { 2034 } else {
2016 unhandled("$s", "modifier", token.charOffset, null); 2035 unhandled("$s", "modifier", token.charOffset, null);
2017 } 2036 }
2018 } 2037 }
2019 } 2038 }
2020 } 2039 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698