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

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: Merged with 4df146dd9a465d63344330bf3e45524b927c92ec 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 if (reported.add(cls)) { 358 if (reported.add(cls)) {
357 List<ClassBuilder> involved = <ClassBuilder>[]; 359 List<ClassBuilder> involved = <ClassBuilder>[];
358 for (ClassBuilder cls in cycles) { 360 for (ClassBuilder cls in cycles) {
359 if (realCycles.containsKey(cls)) { 361 if (realCycles.containsKey(cls)) {
360 involved.add(cls); 362 involved.add(cls);
361 reported.add(cls); 363 reported.add(cls);
362 } 364 }
363 } 365 }
364 String involvedString = 366 String involvedString =
365 involved.map((c) => c.fullNameForErrors).join("', '"); 367 involved.map((c) => c.fullNameForErrors).join("', '");
366 cls.addCompileTimeError( 368 cls.deprecated_addCompileTimeError(
367 cls.charOffset, 369 cls.charOffset,
368 "'${cls.fullNameForErrors}' is a supertype of itself via " 370 "'${cls.fullNameForErrors}' is a supertype of itself via "
369 "'$involvedString'."); 371 "'$involvedString'.");
370 } 372 }
371 }); 373 });
372 ticker.logMs("Found cycles"); 374 ticker.logMs("Found cycles");
373 Set<ClassBuilder> blackListedClasses = new Set<ClassBuilder>.from([ 375 Set<ClassBuilder> blackListedClasses = new Set<ClassBuilder>.from([
374 coreLibrary["bool"], 376 coreLibrary["bool"],
375 coreLibrary["int"], 377 coreLibrary["int"],
376 coreLibrary["num"], 378 coreLibrary["num"],
377 coreLibrary["double"], 379 coreLibrary["double"],
378 coreLibrary["String"], 380 coreLibrary["String"],
379 ]); 381 ]);
380 for (ClassBuilder cls in allClasses) { 382 for (ClassBuilder cls in allClasses) {
381 if (cls.library.loader != this) continue; 383 if (cls.library.loader != this) continue;
382 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>(); 384 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>();
383 target.addDirectSupertype(cls, directSupertypes); 385 target.addDirectSupertype(cls, directSupertypes);
384 for (ClassBuilder supertype in directSupertypes) { 386 for (ClassBuilder supertype in directSupertypes) {
385 if (supertype is EnumBuilder) { 387 if (supertype is EnumBuilder) {
386 cls.addCompileTimeError( 388 cls.deprecated_addCompileTimeError(
387 cls.charOffset, 389 cls.charOffset,
388 "'${supertype.name}' is an enum and can't be extended or " 390 "'${supertype.name}' is an enum and can't be extended or "
389 "implemented."); 391 "implemented.");
390 } else if (!cls.library.mayImplementRestrictedTypes && 392 } else if (!cls.library.mayImplementRestrictedTypes &&
391 blackListedClasses.contains(supertype)) { 393 blackListedClasses.contains(supertype)) {
392 cls.addCompileTimeError( 394 cls.deprecated_addCompileTimeError(
393 cls.charOffset, 395 cls.charOffset,
394 "'${supertype.name}' is restricted and can't be extended or " 396 "'${supertype.name}' is restricted and can't be extended or "
395 "implemented."); 397 "implemented.");
396 } 398 }
397 } 399 }
398 TypeBuilder mixedInType = cls.mixedInType; 400 TypeBuilder mixedInType = cls.mixedInType;
399 if (mixedInType != null) { 401 if (mixedInType != null) {
400 bool isClassBuilder = false; 402 bool isClassBuilder = false;
401 if (mixedInType is NamedTypeBuilder) { 403 if (mixedInType is NamedTypeBuilder) {
402 var builder = mixedInType.builder; 404 var builder = mixedInType.builder;
403 if (builder is ClassBuilder) { 405 if (builder is ClassBuilder) {
404 isClassBuilder = true; 406 isClassBuilder = true;
405 for (Builder constructory in builder.constructors.local.values) { 407 for (Builder constructory in builder.constructors.local.values) {
406 if (constructory.isConstructor && !constructory.isSynthetic) { 408 if (constructory.isConstructor && !constructory.isSynthetic) {
407 cls.addCompileTimeError( 409 cls.deprecated_addCompileTimeError(
408 cls.charOffset, 410 cls.charOffset,
409 "Can't use '${builder.fullNameForErrors}' as a mixin " 411 "Can't use '${builder.fullNameForErrors}' as a mixin "
410 "because it has constructors."); 412 "because it has constructors.");
411 builder.addCompileTimeError( 413 builder.deprecated_addCompileTimeError(
412 constructory.charOffset, 414 constructory.charOffset,
413 "This constructor prevents using " 415 "This constructor prevents using "
414 "'${builder.fullNameForErrors}' as a mixin."); 416 "'${builder.fullNameForErrors}' as a mixin.");
415 } 417 }
416 } 418 }
417 } 419 }
418 } 420 }
419 if (!isClassBuilder) { 421 if (!isClassBuilder) {
420 cls.addCompileTimeError(cls.charOffset, 422 cls.deprecated_addCompileTimeError(cls.charOffset,
421 "The type '${mixedInType.fullNameForErrors}' can't be mixed in."); 423 "The type '${mixedInType.fullNameForErrors}' can't be mixed in.");
422 } 424 }
423 } 425 }
424 } 426 }
425 ticker.logMs("Checked restricted supertypes"); 427 ticker.logMs("Checked restricted supertypes");
426 } 428 }
427 429
428 void buildProgram() { 430 void buildProgram() {
429 builders.forEach((Uri uri, LibraryBuilder library) { 431 builders.forEach((Uri uri, LibraryBuilder library) {
430 if (library is SourceLibraryBuilder) { 432 if (library is SourceLibraryBuilder) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 isSuper: isSuper, 509 isSuper: isSuper,
508 isStatic: isStatic, 510 isStatic: isStatic,
509 isConstructor: isConstructor, 511 isConstructor: isConstructor,
510 isTopLevel: isTopLevel); 512 isTopLevel: isTopLevel);
511 } 513 }
512 514
513 Expression throwCompileConstantError(Expression error) { 515 Expression throwCompileConstantError(Expression error) {
514 return target.backendTarget.throwCompileConstantError(coreTypes, error); 516 return target.backendTarget.throwCompileConstantError(coreTypes, error);
515 } 517 }
516 518
517 Expression buildCompileTimeError(String message, int offset) { 519 Expression deprecated_buildCompileTimeError(String message, int offset) {
518 return target.backendTarget 520 return target.backendTarget
519 .buildCompileTimeError(coreTypes, message, offset); 521 .buildCompileTimeError(coreTypes, message, offset);
520 } 522 }
521 } 523 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/source/source_library_builder.dart ('k') | pkg/front_end/lib/src/fasta/source/stack_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698