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

Side by Side Diff: pkg/front_end/lib/src/fasta/source/source_loader.dart

Issue 2970273004: Deprecate all diagnostics methods that use strings. (Closed)
Patch Set: Created 3 years, 5 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.source_loader; 5 library fasta.source_loader;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:typed_data' show Uint8List; 9 import 'dart:typed_data' show Uint8List;
10 10
(...skipping 22 matching lines...) Expand all
33 show 33 show
34 Builder, 34 Builder,
35 ClassBuilder, 35 ClassBuilder,
36 EnumBuilder, 36 EnumBuilder,
37 LibraryBuilder, 37 LibraryBuilder,
38 NamedTypeBuilder, 38 NamedTypeBuilder,
39 TypeBuilder; 39 TypeBuilder;
40 40
41 import '../compiler_context.dart' show CompilerContext; 41 import '../compiler_context.dart' show CompilerContext;
42 42
43 import '../errors.dart' show inputError; 43 import '../deprecated_problems.dart' show deprecated_inputError;
44 44
45 import '../export.dart' show Export; 45 import '../export.dart' show Export;
46 46
47 import '../loader.dart' show Loader; 47 import '../loader.dart' show Loader;
48 48
49 import '../parser/class_member_parser.dart' show ClassMemberParser; 49 import '../parser/class_member_parser.dart' show ClassMemberParser;
50 50
51 import '../scanner.dart' show ErrorToken, ScannerResult, Token, scan; 51 import '../scanner.dart' show ErrorToken, ScannerResult, Token, scan;
52 52
53 import 'diet_listener.dart' show DietListener; 53 import 'diet_listener.dart' show DietListener;
(...skipping 20 matching lines...) Expand all
74 TypeInferenceEngine typeInferenceEngine; 74 TypeInferenceEngine typeInferenceEngine;
75 75
76 Instrumentation instrumentation; 76 Instrumentation instrumentation;
77 77
78 SourceLoader(this.fileSystem, KernelTarget target) : super(target); 78 SourceLoader(this.fileSystem, KernelTarget target) : super(target);
79 79
80 Future<Token> tokenize(SourceLibraryBuilder library, 80 Future<Token> tokenize(SourceLibraryBuilder library,
81 {bool suppressLexicalErrors: false}) async { 81 {bool suppressLexicalErrors: false}) async {
82 Uri uri = library.fileUri; 82 Uri uri = library.fileUri;
83 if (uri == null || uri.scheme != "file") { 83 if (uri == null || uri.scheme != "file") {
84 return inputError(library.uri, -1, "Not found: ${library.uri}."); 84 return deprecated_inputError(
85 library.uri, -1, "Not found: ${library.uri}.");
85 } 86 }
86 87
87 // Get the library text from the cache, or read from the file system. 88 // Get the library text from the cache, or read from the file system.
88 List<int> bytes = sourceBytes[uri]; 89 List<int> bytes = sourceBytes[uri];
89 if (bytes == null) { 90 if (bytes == null) {
90 try { 91 try {
91 List<int> rawBytes = await fileSystem.entityForUri(uri).readAsBytes(); 92 List<int> rawBytes = await fileSystem.entityForUri(uri).readAsBytes();
92 Uint8List zeroTerminatedBytes = new Uint8List(rawBytes.length + 1); 93 Uint8List zeroTerminatedBytes = new Uint8List(rawBytes.length + 1);
93 zeroTerminatedBytes.setRange(0, rawBytes.length, rawBytes); 94 zeroTerminatedBytes.setRange(0, rawBytes.length, rawBytes);
94 bytes = zeroTerminatedBytes; 95 bytes = zeroTerminatedBytes;
95 sourceBytes[uri] = bytes; 96 sourceBytes[uri] = bytes;
96 } on FileSystemException catch (e) { 97 } on FileSystemException catch (e) {
97 return inputError(uri, -1, e.message); 98 return deprecated_inputError(uri, -1, e.message);
98 } 99 }
99 } 100 }
100 101
101 byteCount += bytes.length - 1; 102 byteCount += bytes.length - 1;
102 ScannerResult result = scan(bytes); 103 ScannerResult result = scan(bytes);
103 Token token = result.tokens; 104 Token token = result.tokens;
104 if (!suppressLexicalErrors) { 105 if (!suppressLexicalErrors) {
105 List<int> source = getSource(bytes); 106 List<int> source = getSource(bytes);
106 target.addSourceInformation(library.fileUri, result.lineStarts, source); 107 target.addSourceInformation(library.fileUri, result.lineStarts, source);
107 } 108 }
108 while (token is ErrorToken) { 109 while (token is ErrorToken) {
109 if (!suppressLexicalErrors) { 110 if (!suppressLexicalErrors) {
110 ErrorToken error = token; 111 ErrorToken error = token;
111 library.addCompileTimeError(token.charOffset, error.assertionMessage, 112 library.deprecated_addCompileTimeError(
113 token.charOffset, error.assertionMessage,
112 fileUri: uri); 114 fileUri: uri);
113 } 115 }
114 token = token.next; 116 token = token.next;
115 } 117 }
116 return token; 118 return token;
117 } 119 }
118 120
119 List<int> getSource(List<int> bytes) { 121 List<int> getSource(List<int> bytes) {
120 if (excludeSource) return const <int>[]; 122 if (excludeSource) return const <int>[];
121 123
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 if (reported.add(cls)) { 366 if (reported.add(cls)) {
365 List<ClassBuilder> involved = <ClassBuilder>[]; 367 List<ClassBuilder> involved = <ClassBuilder>[];
366 for (ClassBuilder cls in cycles) { 368 for (ClassBuilder cls in cycles) {
367 if (realCycles.containsKey(cls)) { 369 if (realCycles.containsKey(cls)) {
368 involved.add(cls); 370 involved.add(cls);
369 reported.add(cls); 371 reported.add(cls);
370 } 372 }
371 } 373 }
372 String involvedString = 374 String involvedString =
373 involved.map((c) => c.fullNameForErrors).join("', '"); 375 involved.map((c) => c.fullNameForErrors).join("', '");
374 cls.addCompileTimeError( 376 cls.deprecated_addCompileTimeError(
375 cls.charOffset, 377 cls.charOffset,
376 "'${cls.fullNameForErrors}' is a supertype of itself via " 378 "'${cls.fullNameForErrors}' is a supertype of itself via "
377 "'$involvedString'."); 379 "'$involvedString'.");
378 } 380 }
379 }); 381 });
380 ticker.logMs("Found cycles"); 382 ticker.logMs("Found cycles");
381 Set<ClassBuilder> blackListedClasses = new Set<ClassBuilder>.from([ 383 Set<ClassBuilder> blackListedClasses = new Set<ClassBuilder>.from([
382 coreLibrary["bool"], 384 coreLibrary["bool"],
383 coreLibrary["int"], 385 coreLibrary["int"],
384 coreLibrary["num"], 386 coreLibrary["num"],
385 coreLibrary["double"], 387 coreLibrary["double"],
386 coreLibrary["String"], 388 coreLibrary["String"],
387 ]); 389 ]);
388 for (ClassBuilder cls in allClasses) { 390 for (ClassBuilder cls in allClasses) {
389 if (cls.library.loader != this) continue; 391 if (cls.library.loader != this) continue;
390 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>(); 392 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>();
391 target.addDirectSupertype(cls, directSupertypes); 393 target.addDirectSupertype(cls, directSupertypes);
392 for (ClassBuilder supertype in directSupertypes) { 394 for (ClassBuilder supertype in directSupertypes) {
393 if (supertype is EnumBuilder) { 395 if (supertype is EnumBuilder) {
394 cls.addCompileTimeError( 396 cls.deprecated_addCompileTimeError(
395 cls.charOffset, 397 cls.charOffset,
396 "'${supertype.name}' is an enum and can't be extended or " 398 "'${supertype.name}' is an enum and can't be extended or "
397 "implemented."); 399 "implemented.");
398 } else if (!canImplementRestrictedTypes(cls.library) && 400 } else if (!canImplementRestrictedTypes(cls.library) &&
399 blackListedClasses.contains(supertype)) { 401 blackListedClasses.contains(supertype)) {
400 cls.addCompileTimeError( 402 cls.deprecated_addCompileTimeError(
401 cls.charOffset, 403 cls.charOffset,
402 "'${supertype.name}' is restricted and can't be extended or " 404 "'${supertype.name}' is restricted and can't be extended or "
403 "implemented."); 405 "implemented.");
404 } 406 }
405 } 407 }
406 TypeBuilder mixedInType = cls.mixedInType; 408 TypeBuilder mixedInType = cls.mixedInType;
407 if (mixedInType != null) { 409 if (mixedInType != null) {
408 bool isClassBuilder = false; 410 bool isClassBuilder = false;
409 if (mixedInType is NamedTypeBuilder) { 411 if (mixedInType is NamedTypeBuilder) {
410 var builder = mixedInType.builder; 412 var builder = mixedInType.builder;
411 if (builder is ClassBuilder) { 413 if (builder is ClassBuilder) {
412 isClassBuilder = true; 414 isClassBuilder = true;
413 for (Builder constructory in builder.constructors.local.values) { 415 for (Builder constructory in builder.constructors.local.values) {
414 if (constructory.isConstructor && !constructory.isSynthetic) { 416 if (constructory.isConstructor && !constructory.isSynthetic) {
415 cls.addCompileTimeError( 417 cls.deprecated_addCompileTimeError(
416 cls.charOffset, 418 cls.charOffset,
417 "Can't use '${builder.fullNameForErrors}' as a mixin " 419 "Can't use '${builder.fullNameForErrors}' as a mixin "
418 "because it has constructors."); 420 "because it has constructors.");
419 builder.addCompileTimeError( 421 builder.deprecated_addCompileTimeError(
420 constructory.charOffset, 422 constructory.charOffset,
421 "This constructor prevents using " 423 "This constructor prevents using "
422 "'${builder.fullNameForErrors}' as a mixin."); 424 "'${builder.fullNameForErrors}' as a mixin.");
423 } 425 }
424 } 426 }
425 } 427 }
426 } 428 }
427 if (!isClassBuilder) { 429 if (!isClassBuilder) {
428 cls.addCompileTimeError(cls.charOffset, 430 cls.deprecated_addCompileTimeError(cls.charOffset,
429 "The type '${mixedInType.fullNameForErrors}' can't be mixed in."); 431 "The type '${mixedInType.fullNameForErrors}' can't be mixed in.");
430 } 432 }
431 } 433 }
432 } 434 }
433 ticker.logMs("Checked restricted supertypes"); 435 ticker.logMs("Checked restricted supertypes");
434 } 436 }
435 437
436 void buildProgram() { 438 void buildProgram() {
437 builders.forEach((Uri uri, LibraryBuilder library) { 439 builders.forEach((Uri uri, LibraryBuilder library) {
438 if (library is SourceLibraryBuilder) { 440 if (library is SourceLibraryBuilder) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 isSuper: isSuper, 517 isSuper: isSuper,
516 isStatic: isStatic, 518 isStatic: isStatic,
517 isConstructor: isConstructor, 519 isConstructor: isConstructor,
518 isTopLevel: isTopLevel); 520 isTopLevel: isTopLevel);
519 } 521 }
520 522
521 Expression throwCompileConstantError(Expression error) { 523 Expression throwCompileConstantError(Expression error) {
522 return target.backendTarget.throwCompileConstantError(coreTypes, error); 524 return target.backendTarget.throwCompileConstantError(coreTypes, error);
523 } 525 }
524 526
525 Expression buildCompileTimeError(String message, int offset) { 527 Expression deprecated_buildCompileTimeError(String message, int offset) {
526 return target.backendTarget 528 return target.backendTarget
527 .buildCompileTimeError(coreTypes, message, offset); 529 .buildCompileTimeError(coreTypes, message, offset);
528 } 530 }
529 } 531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698