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

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

Issue 2940843003: Ignore recoverable parser errors in outline_builder to avoid double reporting. (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.outline_builder; 5 library fasta.outline_builder;
6 6
7 import 'package:kernel/ast.dart' show ProcedureKind; 7 import 'package:kernel/ast.dart' show ProcedureKind;
8 8
9 import '../fasta_codes.dart' show FastaMessage, codeExpectedBlockToSkip; 9 import '../fasta_codes.dart' show FastaMessage, codeExpectedBlockToSkip;
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 Abstract, 43 Abstract,
44 Regular, 44 Regular,
45 RedirectingFactoryBody, 45 RedirectingFactoryBody,
46 } 46 }
47 47
48 class OutlineBuilder extends UnhandledListener { 48 class OutlineBuilder extends UnhandledListener {
49 final SourceLibraryBuilder library; 49 final SourceLibraryBuilder library;
50 50
51 final bool enableNative; 51 final bool enableNative;
52 52
53 /// When true, recoverable parser errors are silently ignored. This is
54 /// because they will be reported by the BodyBuilder later. However, typedefs
55 /// are fully compiled by the outline builder, so parser errors are turned on
56 /// when parsing typedefs.
57 bool silenceParserErrors = true;
58
53 String nativeMethodName; 59 String nativeMethodName;
54 60
55 OutlineBuilder(SourceLibraryBuilder library) 61 OutlineBuilder(SourceLibraryBuilder library)
56 : library = library, 62 : library = library,
57 enableNative = library.loader.target.enableNative(library); 63 enableNative = library.loader.target.enableNative(library);
58 64
59 @override 65 @override
60 Uri get uri => library.fileUri; 66 Uri get uri => library.fileUri;
61 67
62 @override 68 @override
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 String name = pop(); 596 String name = pop();
591 List<MetadataBuilder> metadata = pop(); 597 List<MetadataBuilder> metadata = pop();
592 library.addEnum(metadata, name, constantNamesAndOffsets, charOffset, 598 library.addEnum(metadata, name, constantNamesAndOffsets, charOffset,
593 endBrace.charOffset); 599 endBrace.charOffset);
594 checkEmpty(enumKeyword.charOffset); 600 checkEmpty(enumKeyword.charOffset);
595 } 601 }
596 602
597 @override 603 @override
598 void beginFunctionTypeAlias(Token token) { 604 void beginFunctionTypeAlias(Token token) {
599 library.beginNestedDeclaration(null, hasMembers: false); 605 library.beginNestedDeclaration(null, hasMembers: false);
606 silenceParserErrors = false;
600 } 607 }
601 608
602 @override 609 @override
603 void handleFunctionType(Token functionToken, Token endToken) { 610 void handleFunctionType(Token functionToken, Token endToken) {
604 debugEvent("FunctionType"); 611 debugEvent("FunctionType");
605 List<FormalParameterBuilder> formals = pop(); 612 List<FormalParameterBuilder> formals = pop();
606 pop(); // formals offset 613 pop(); // formals offset
607 List<TypeVariableBuilder> typeVariables = pop(); 614 List<TypeVariableBuilder> typeVariables = pop();
608 TypeBuilder returnType = pop(); 615 TypeBuilder returnType = pop();
609 push(library.addFunctionType( 616 push(library.addFunctionType(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 } else { 649 } else {
643 // TODO(ahe): Improve this error message. 650 // TODO(ahe): Improve this error message.
644 library.addCompileTimeError( 651 library.addCompileTimeError(
645 equals.charOffset, "Can't create typedef from non-function type."); 652 equals.charOffset, "Can't create typedef from non-function type.");
646 } 653 }
647 } 654 }
648 List<MetadataBuilder> metadata = pop(); 655 List<MetadataBuilder> metadata = pop();
649 library.addFunctionTypeAlias( 656 library.addFunctionTypeAlias(
650 metadata, returnType, name, typeVariables, formals, charOffset); 657 metadata, returnType, name, typeVariables, formals, charOffset);
651 checkEmpty(typedefKeyword.charOffset); 658 checkEmpty(typedefKeyword.charOffset);
659 silenceParserErrors = true;
652 } 660 }
653 661
654 @override 662 @override
655 void endTopLevelFields(int count, Token beginToken, Token endToken) { 663 void endTopLevelFields(int count, Token beginToken, Token endToken) {
656 debugEvent("endTopLevelFields"); 664 debugEvent("endTopLevelFields");
657 List fieldsInfo = popList(count * 4); 665 List fieldsInfo = popList(count * 4);
658 TypeBuilder type = pop(); 666 TypeBuilder type = pop();
659 int modifiers = Modifier.validate(pop()); 667 int modifiers = Modifier.validate(pop());
660 List<MetadataBuilder> metadata = pop(); 668 List<MetadataBuilder> metadata = pop();
661 library.addFields(metadata, modifiers, type, fieldsInfo); 669 library.addFields(metadata, modifiers, type, fieldsInfo);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 push(new Modifier.fromString(token.stringValue)); 816 push(new Modifier.fromString(token.stringValue));
809 } 817 }
810 818
811 @override 819 @override
812 void handleModifiers(int count) { 820 void handleModifiers(int count) {
813 debugEvent("Modifiers"); 821 debugEvent("Modifiers");
814 push(popList(count) ?? NullValue.Modifiers); 822 push(popList(count) ?? NullValue.Modifiers);
815 } 823 }
816 824
817 @override 825 @override
826 void handleRecoverableError(Token token, FastaMessage message) {
827 if (silenceParserErrors) {
828 debugEvent("RecoverableError");
829 } else {
830 super.handleRecoverableError(token, message);
831 }
832 }
833
834 @override
818 Token handleUnrecoverableError(Token token, FastaMessage message) { 835 Token handleUnrecoverableError(Token token, FastaMessage message) {
819 if (enableNative && message.code == codeExpectedBlockToSkip) { 836 if (enableNative && message.code == codeExpectedBlockToSkip) {
820 var target = library.loader.target; 837 var target = library.loader.target;
821 Token recover = target.skipNativeClause(token); 838 Token recover = target.skipNativeClause(token);
822 if (recover != null) { 839 if (recover != null) {
823 nativeMethodName = target.extractNativeMethodName(token); 840 nativeMethodName = target.extractNativeMethodName(token);
824 return recover; 841 return recover;
825 } 842 }
826 } 843 }
827 return super.handleUnrecoverableError(token, message); 844 return super.handleUnrecoverableError(token, message);
828 } 845 }
829 846
830 @override 847 @override
831 void addCompileTimeErrorFromMessage(FastaMessage message) { 848 void addCompileTimeErrorFromMessage(FastaMessage message) {
832 library.addCompileTimeError(message.charOffset, message.message, 849 library.addCompileTimeError(message.charOffset, message.message,
833 fileUri: message.uri); 850 fileUri: message.uri);
834 } 851 }
835 852
836 @override 853 @override
837 Link<Token> handleMemberName(Link<Token> identifiers) { 854 Link<Token> handleMemberName(Link<Token> identifiers) {
838 if (!enableNative || identifiers.isEmpty) return identifiers; 855 if (!enableNative || identifiers.isEmpty) return identifiers;
839 return removeNativeClause(identifiers); 856 return removeNativeClause(identifiers);
840 } 857 }
841 858
842 @override 859 @override
843 void debugEvent(String name) { 860 void debugEvent(String name) {
844 // printEvent(name); 861 // printEvent(name);
845 } 862 }
846 } 863 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698