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

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

Issue 2769113004: Setup type and modifiers of local variables on creation. (Closed)
Patch Set: Created 3 years, 9 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 | pkg/front_end/lib/src/fasta/kernel/kernel_variable_builder.dart » ('j') | 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.body_builder; 5 library fasta.body_builder;
6 6
7 import '../parser/parser.dart' show FormalParameterType, optional; 7 import '../parser/parser.dart' show FormalParameterType, optional;
8 8
9 import '../parser/error_kind.dart' show ErrorKind; 9 import '../parser/error_kind.dart' show ErrorKind;
10 10
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 Statement compileTimeErrorInTry; 119 Statement compileTimeErrorInTry;
120 120
121 Statement compileTimeErrorInLoopOrSwitch; 121 Statement compileTimeErrorInLoopOrSwitch;
122 122
123 Scope switchScope; 123 Scope switchScope;
124 124
125 CloneVisitor cloner; 125 CloneVisitor cloner;
126 126
127 bool constantExpressionRequired = false; 127 bool constantExpressionRequired = false;
128 128
129 DartType currentLocalVariableType = const DynamicType();
130
131 int currentLocalVariableModifiers = -1;
132
129 BodyBuilder( 133 BodyBuilder(
130 KernelLibraryBuilder library, 134 KernelLibraryBuilder library,
131 this.member, 135 this.member,
132 Scope scope, 136 Scope scope,
133 this.formalParameterScope, 137 this.formalParameterScope,
134 this.hierarchy, 138 this.hierarchy,
135 this.coreTypes, 139 this.coreTypes,
136 this.classBuilder, 140 this.classBuilder,
137 this.isInstanceMember, 141 this.isInstanceMember,
138 this.uri) 142 this.uri)
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 Statement elsePart = popStatementIfNotNull(elseToken); 896 Statement elsePart = popStatementIfNotNull(elseToken);
893 Statement thenPart = popStatement(); 897 Statement thenPart = popStatement();
894 Expression condition = popForValue(); 898 Expression condition = popForValue();
895 push(new IfStatement(condition, thenPart, elsePart)); 899 push(new IfStatement(condition, thenPart, elsePart));
896 } 900 }
897 901
898 @override 902 @override
899 void endVariableInitializer(Token assignmentOperator) { 903 void endVariableInitializer(Token assignmentOperator) {
900 debugEvent("VariableInitializer"); 904 debugEvent("VariableInitializer");
901 assert(assignmentOperator.stringValue == "="); 905 assert(assignmentOperator.stringValue == "=");
902 Expression initializer = popForValue(); 906 pushNewLocalVariable(popForValue(),
903 Identifier identifier = pop(); 907 equalsCharOffset: assignmentOperator.charOffset);
904 push(new VariableDeclaration(identifier.name, initializer: initializer)
905 ..fileEqualsOffset = assignmentOperator.charOffset);
906 } 908 }
907 909
908 @override 910 @override
909 void handleNoVariableInitializer(Token token) { 911 void handleNoVariableInitializer(Token token) {
910 debugEvent("NoVariableInitializer"); 912 debugEvent("NoVariableInitializer");
913 pushNewLocalVariable(null);
914 }
915
916 void pushNewLocalVariable(Expression initializer,
917 {int equalsCharOffset: TreeNode.noOffset}) {
918 Identifier identifier = pop();
919 bool isConst = (currentLocalVariableModifiers & constMask) != 0;
karlklose 2017/03/23 09:52:15 assert(currentLocalVariableModifiers != -1) here?
ahe 2017/03/23 11:17:54 Done.
920 bool isFinal = (currentLocalVariableModifiers & finalMask) != 0;
921 assert(isConst == constantExpressionRequired);
922 push(new VariableDeclaration(identifier.name,
923 initializer: initializer,
924 type: currentLocalVariableType,
925 isFinal: isFinal,
926 isConst: isConst)..fileEqualsOffset = equalsCharOffset);
911 } 927 }
912 928
913 @override 929 @override
914 void endFieldInitializer(Token assignmentOperator) { 930 void endFieldInitializer(Token assignmentOperator) {
915 debugEvent("FieldInitializer"); 931 debugEvent("FieldInitializer");
916 assert(assignmentOperator.stringValue == "="); 932 assert(assignmentOperator.stringValue == "=");
917 push(popForValue()); 933 push(popForValue());
918 } 934 }
919 935
920 @override 936 @override
921 void handleNoFieldInitializer(Token token) { 937 void handleNoFieldInitializer(Token token) {
922 debugEvent("NoFieldInitializer"); 938 debugEvent("NoFieldInitializer");
923 push(NullValue.FieldInitializer); 939 push(NullValue.FieldInitializer);
924 } 940 }
925 941
926 @override 942 @override
927 void endInitializedIdentifier(Token nameToken) { 943 void endInitializedIdentifier(Token nameToken) {
928 // TODO(ahe): Use [InitializedIdentifier] here? 944 // TODO(ahe): Use [InitializedIdentifier] here?
929 debugEvent("InitializedIdentifier"); 945 debugEvent("InitializedIdentifier");
930 TreeNode node = pop(); 946 VariableDeclaration variable = pop();
931 VariableDeclaration variable;
932 if (node is VariableDeclaration) {
933 variable = node;
934 } else if (node is Identifier) {
935 variable = new VariableDeclaration(node.name);
936 } else {
937 internalError("unhandled identifier: ${node.runtimeType}");
938 }
939 variable.fileOffset = nameToken.charOffset; 947 variable.fileOffset = nameToken.charOffset;
940 push(variable); 948 push(variable);
941 scope[variable.name] = new KernelVariableBuilder( 949 scope[variable.name] = new KernelVariableBuilder(
942 variable, member ?? classBuilder ?? library, uri); 950 variable, member ?? classBuilder ?? library, uri);
943 } 951 }
944 952
945 @override 953 @override
954 void beginVariablesDeclaration(Token token) {
955 debugEvent("beginVariablesDeclaration");
956 DartType type = pop();
957 int modifiers = Modifier.validate(pop());
958 super.push(currentLocalVariableModifiers);
Paul Berry 2017/03/23 10:50:52 Why not: push(currentLocalVariableModifiers ?? Nu
ahe 2017/03/23 11:17:55 I need to use super.push to avoid changing inIniti
959 super.push(currentLocalVariableType);
Paul Berry 2017/03/23 10:50:52 Similar question here.
ahe 2017/03/23 11:17:55 I'll change it to ?? NullValue.Type.
960 currentLocalVariableType = type ?? const DynamicType();
Paul Berry 2017/03/23 10:50:52 FYI, for type inference we will need to keep track
ahe 2017/03/23 11:17:54 Done.
961 currentLocalVariableModifiers = modifiers;
962 super.push(constantExpressionRequired);
Paul Berry 2017/03/23 10:50:52 AFAICT, `constantExpressionRequired` is never null
ahe 2017/03/23 11:17:54 As mentioned above, super.push is used to avoid in
963 constantExpressionRequired = (modifiers & constMask) != 0;
964 }
965
966 @override
946 void endVariablesDeclaration(int count, Token endToken) { 967 void endVariablesDeclaration(int count, Token endToken) {
947 debugEvent("VariablesDeclaration"); 968 debugEvent("VariablesDeclaration");
948 List<VariableDeclaration> variables = popList(count); 969 List<VariableDeclaration> variables = popList(count);
949 DartType type = pop(); 970 constantExpressionRequired = pop();
950 int modifiers = Modifier.validate(pop()); 971 currentLocalVariableType = pop();
951 bool isConst = (modifiers & constMask) != 0; 972 currentLocalVariableModifiers = pop();
952 bool isFinal = (modifiers & finalMask) != 0;
953 if (type != null || isConst || isFinal) {
954 type ??= const DynamicType();
955 for (VariableDeclaration variable in variables) {
956 variable
957 ..type = type
958 ..isConst = isConst
959 ..isFinal = isFinal;
960 }
961 }
962 if (variables.length != 1) { 973 if (variables.length != 1) {
963 push(variables); 974 push(variables);
964 } else { 975 } else {
965 push(variables.single); 976 push(variables.single);
966 } 977 }
967 } 978 }
968 979
969 @override 980 @override
970 void endBlock(int count, Token beginToken, Token endToken) { 981 void endBlock(int count, Token beginToken, Token endToken) {
971 debugEvent("Block"); 982 debugEvent("Block");
(...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after
2782 } else if (node is PrefixBuilder) { 2793 } else if (node is PrefixBuilder) {
2783 return node.name; 2794 return node.name;
2784 } else if (node is ThisAccessor) { 2795 } else if (node is ThisAccessor) {
2785 return node.isSuper ? "super" : "this"; 2796 return node.isSuper ? "super" : "this";
2786 } else if (node is BuilderAccessor) { 2797 } else if (node is BuilderAccessor) {
2787 return node.plainNameForRead; 2798 return node.plainNameForRead;
2788 } else { 2799 } else {
2789 return internalError("Unhandled: ${node.runtimeType}"); 2800 return internalError("Unhandled: ${node.runtimeType}");
2790 } 2801 }
2791 } 2802 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/kernel_variable_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698