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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2978063002: Move parser helper classes to own files and clean them up. (Closed)
Patch Set: Don't use problems.dart in parser. 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.body_builder; 5 library fasta.body_builder;
6 6
7 import 'package:kernel/ast.dart' 7 import 'package:kernel/ast.dart'
8 hide InvalidExpression, InvalidInitializer, InvalidStatement; 8 hide InvalidExpression, InvalidInitializer, InvalidStatement;
9 9
10 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; 10 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
11 11
12 import 'package:kernel/clone.dart' show CloneVisitor; 12 import 'package:kernel/clone.dart' show CloneVisitor;
13 13
14 import 'package:kernel/core_types.dart' show CoreTypes; 14 import 'package:kernel/core_types.dart' show CoreTypes;
15 15
16 import 'package:kernel/transformations/flags.dart' show TransformerFlag; 16 import 'package:kernel/transformations/flags.dart' show TransformerFlag;
17 17
18 import '../../scanner/token.dart' show BeginToken, Token; 18 import '../../scanner/token.dart' show BeginToken, Token;
19 19
20 import '../fasta_codes.dart' as fasta; 20 import '../fasta_codes.dart' as fasta;
21 21
22 import '../fasta_codes.dart' show LocatedMessage, Message; 22 import '../fasta_codes.dart' show LocatedMessage, Message;
23 23
24 import '../messages.dart' as messages show getLocationFromUri; 24 import '../messages.dart' as messages show getLocationFromUri;
25 25
26 import '../modifier.dart' show Modifier, constMask, finalMask; 26 import '../modifier.dart' show Modifier, constMask, finalMask;
27 27
28 import '../parser/identifier_context.dart' show IdentifierContext;
29
30 import '../parser/native_support.dart' show skipNativeClause; 28 import '../parser/native_support.dart' show skipNativeClause;
31 29
32 import '../parser/parser.dart' 30 import '../parser.dart'
33 show Assert, FormalParameterType, MemberKind, optional; 31 show Assert, FormalParameterKind, IdentifierContext, MemberKind, optional;
32
33 import '../parser/formal_parameter_kind.dart'
34 show isOptionalPositionalFormalParameterKind;
34 35
35 import '../problems.dart' 36 import '../problems.dart'
36 show internalProblem, unexpected, unhandled, unsupported; 37 show internalProblem, unexpected, unhandled, unsupported;
37 38
38 import '../quote.dart' 39 import '../quote.dart'
39 show 40 show
40 Quote, 41 Quote,
41 analyzeQuote, 42 analyzeQuote,
42 unescape, 43 unescape,
43 unescapeFirstStringPart, 44 unescapeFirstStringPart,
(...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 push(deprecated_buildCompileTimeError( 1806 push(deprecated_buildCompileTimeError(
1806 "Not a constant expression.", throwToken.charOffset)); 1807 "Not a constant expression.", throwToken.charOffset));
1807 } else { 1808 } else {
1808 push( 1809 push(
1809 new KernelThrow(expression)..fileOffset = offsetForToken(throwToken)); 1810 new KernelThrow(expression)..fileOffset = offsetForToken(throwToken));
1810 } 1811 }
1811 } 1812 }
1812 1813
1813 @override 1814 @override
1814 void endFormalParameter(Token thisKeyword, Token nameToken, 1815 void endFormalParameter(Token thisKeyword, Token nameToken,
1815 FormalParameterType kind, MemberKind memberKind) { 1816 FormalParameterKind kind, MemberKind memberKind) {
1816 debugEvent("FormalParameter"); 1817 debugEvent("FormalParameter");
1817 if (thisKeyword != null) { 1818 if (thisKeyword != null) {
1818 if (!inConstructor) { 1819 if (!inConstructor) {
1819 deprecated_addCompileTimeError(thisKeyword.charOffset, 1820 deprecated_addCompileTimeError(thisKeyword.charOffset,
1820 "'this' parameters can only be used on constructors."); 1821 "'this' parameters can only be used on constructors.");
1821 thisKeyword = null; 1822 thisKeyword = null;
1822 } 1823 }
1823 } 1824 }
1824 Identifier name = pop(); 1825 Identifier name = pop();
1825 DartType type = pop(); 1826 DartType type = pop();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 variable.fileOffset = offsetForToken(name.token); 1858 variable.fileOffset = offsetForToken(name.token);
1858 } 1859 }
1859 } 1860 }
1860 push(variable); 1861 push(variable);
1861 } 1862 }
1862 1863
1863 @override 1864 @override
1864 void endOptionalFormalParameters( 1865 void endOptionalFormalParameters(
1865 int count, Token beginToken, Token endToken) { 1866 int count, Token beginToken, Token endToken) {
1866 debugEvent("OptionalFormalParameters"); 1867 debugEvent("OptionalFormalParameters");
1867 FormalParameterType kind = optional("{", beginToken) 1868 FormalParameterKind kind = optional("{", beginToken)
1868 ? FormalParameterType.NAMED 1869 ? FormalParameterKind.optionalNamed
1869 : FormalParameterType.POSITIONAL; 1870 : FormalParameterKind.optionalPositional;
1870 push(new OptionalFormals(kind, popList(count) ?? [])); 1871 push(new OptionalFormals(kind, popList(count) ?? []));
1871 } 1872 }
1872 1873
1873 @override 1874 @override
1874 void beginFunctionTypedFormalParameter(Token token) { 1875 void beginFunctionTypedFormalParameter(Token token) {
1875 debugEvent("beginFunctionTypedFormalParameter"); 1876 debugEvent("beginFunctionTypedFormalParameter");
1876 functionNestingLevel++; 1877 functionNestingLevel++;
1877 enterFunctionTypeScope(); 1878 enterFunctionTypeScope();
1878 } 1879 }
1879 1880
(...skipping 1766 matching lines...) Expand 10 before | Expand all | Expand 10 after
3646 3647
3647 void resolveGotos(SwitchCase target) { 3648 void resolveGotos(SwitchCase target) {
3648 unsupported("resolveGotos", charOffset, fileUri); 3649 unsupported("resolveGotos", charOffset, fileUri);
3649 } 3650 }
3650 3651
3651 @override 3652 @override
3652 String get fullNameForErrors => "<label-target>"; 3653 String get fullNameForErrors => "<label-target>";
3653 } 3654 }
3654 3655
3655 class OptionalFormals { 3656 class OptionalFormals {
3656 final FormalParameterType kind; 3657 final FormalParameterKind kind;
3657 3658
3658 final List<VariableDeclaration> formals; 3659 final List<VariableDeclaration> formals;
3659 3660
3660 OptionalFormals(this.kind, this.formals); 3661 OptionalFormals(this.kind, this.formals);
3661 } 3662 }
3662 3663
3663 class FormalParameters { 3664 class FormalParameters {
3664 final List<VariableDeclaration> required; 3665 final List<VariableDeclaration> required;
3665 final OptionalFormals optional; 3666 final OptionalFormals optional;
3666 final int charOffset; 3667 final int charOffset;
3667 3668
3668 FormalParameters(this.required, this.optional, this.charOffset); 3669 FormalParameters(this.required, this.optional, this.charOffset);
3669 3670
3670 FunctionNode addToFunction(FunctionNode function) { 3671 FunctionNode addToFunction(FunctionNode function) {
3671 function.requiredParameterCount = required.length; 3672 function.requiredParameterCount = required.length;
3672 function.positionalParameters.addAll(required); 3673 function.positionalParameters.addAll(required);
3673 if (optional != null) { 3674 if (optional != null) {
3674 if (optional.kind.isPositional) { 3675 if (isOptionalPositionalFormalParameterKind(optional.kind)) {
3675 function.positionalParameters.addAll(optional.formals); 3676 function.positionalParameters.addAll(optional.formals);
3676 } else { 3677 } else {
3677 function.namedParameters.addAll(optional.formals); 3678 function.namedParameters.addAll(optional.formals);
3678 setParents(function.namedParameters, function); 3679 setParents(function.namedParameters, function);
3679 } 3680 }
3680 } 3681 }
3681 setParents(function.positionalParameters, function); 3682 setParents(function.positionalParameters, function);
3682 return function; 3683 return function;
3683 } 3684 }
3684 3685
3685 FunctionType toFunctionType(DartType returnType, 3686 FunctionType toFunctionType(DartType returnType,
3686 [List<TypeParameter> typeParameters]) { 3687 [List<TypeParameter> typeParameters]) {
3687 returnType ??= const DynamicType(); 3688 returnType ??= const DynamicType();
3688 typeParameters ??= const <TypeParameter>[]; 3689 typeParameters ??= const <TypeParameter>[];
3689 int requiredParameterCount = required.length; 3690 int requiredParameterCount = required.length;
3690 List<DartType> positionalParameters = <DartType>[]; 3691 List<DartType> positionalParameters = <DartType>[];
3691 List<NamedType> namedParameters = const <NamedType>[]; 3692 List<NamedType> namedParameters = const <NamedType>[];
3692 for (VariableDeclaration parameter in required) { 3693 for (VariableDeclaration parameter in required) {
3693 positionalParameters.add(parameter.type); 3694 positionalParameters.add(parameter.type);
3694 } 3695 }
3695 if (optional != null) { 3696 if (optional != null) {
3696 if (optional.kind.isPositional) { 3697 if (isOptionalPositionalFormalParameterKind(optional.kind)) {
3697 for (VariableDeclaration parameter in optional.formals) { 3698 for (VariableDeclaration parameter in optional.formals) {
3698 positionalParameters.add(parameter.type); 3699 positionalParameters.add(parameter.type);
3699 } 3700 }
3700 } else { 3701 } else {
3701 namedParameters = <NamedType>[]; 3702 namedParameters = <NamedType>[];
3702 for (VariableDeclaration parameter in optional.formals) { 3703 for (VariableDeclaration parameter in optional.formals) {
3703 namedParameters.add(new NamedType(parameter.name, parameter.type)); 3704 namedParameters.add(new NamedType(parameter.name, parameter.type));
3704 } 3705 }
3705 namedParameters.sort(); 3706 namedParameters.sort();
3706 } 3707 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
3788 return AsyncMarker.Async; 3789 return AsyncMarker.Async;
3789 } else { 3790 } else {
3790 assert(identical(starToken.stringValue, "*")); 3791 assert(identical(starToken.stringValue, "*"));
3791 return AsyncMarker.AsyncStar; 3792 return AsyncMarker.AsyncStar;
3792 } 3793 }
3793 } else { 3794 } else {
3794 return unhandled(asyncToken.lexeme, "asyncMarkerFromTokens", 3795 return unhandled(asyncToken.lexeme, "asyncMarkerFromTokens",
3795 asyncToken.charOffset, null); 3796 asyncToken.charOffset, null);
3796 } 3797 }
3797 } 3798 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/builder/formal_parameter_builder.dart ('k') | pkg/front_end/lib/src/fasta/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698