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

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

Issue 2902113005: Complain about duplicated names. (Closed)
Patch Set: Update status file. 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 | pkg/front_end/lib/src/fasta/kernel/fasta_accessors.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 '../fasta_codes.dart' 7 import '../fasta_codes.dart'
8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody;
9 9
10 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; 10 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 addCompileTimeError(-1, "Label not found: '$name'."); 299 addCompileTimeError(-1, "Label not found: '$name'.");
300 } else { 300 } else {
301 outerSwitchScope.forwardDeclareLabel(name, builder); 301 outerSwitchScope.forwardDeclareLabel(name, builder);
302 } 302 }
303 }); 303 });
304 } 304 }
305 switchScope = outerSwitchScope; 305 switchScope = outerSwitchScope;
306 } 306 }
307 307
308 void declareVariable(VariableDeclaration variable) { 308 void declareVariable(VariableDeclaration variable) {
309 // ignore: UNUSED_LOCAL_VARIABLE
310 Statement discardedStatement;
311 String name = variable.name;
312 int offset = variable.fileOffset;
313 if (scope.local[name] != null) {
314 discardedStatement = pop();
315 push(buildCompileTimeErrorStatement(
316 "'$name' already declared in this scope.", offset));
317 return;
Paul Berry 2017/05/24 20:46:15 This may cause problems with the integration into
ahe 2017/05/24 21:06:38 Good point. We should probably add a compile-time
ahe 2017/05/29 07:18:00 Done.
318 }
309 InputError error = scope.declare( 319 InputError error = scope.declare(
310 variable.name, 320 variable.name,
311 new KernelVariableBuilder( 321 new KernelVariableBuilder(
312 variable, member ?? classBuilder ?? library, uri), 322 variable, member ?? classBuilder ?? library, uri),
313 variable.fileOffset, 323 variable.fileOffset,
314 uri); 324 uri);
315 if (error != null) { 325 if (error != null) {
316 addCompileTimeError( 326 discardedStatement = pop();
Paul Berry 2017/05/24 20:46:15 Is this code reachable? It looks like scope.decla
ahe 2017/05/24 21:06:38 The code isn't reachable at the moment because sco
Paul Berry 2017/05/24 22:10:39 Ah, ok. Thanks for the clarification. I have con
Paul Berry 2017/05/24 22:12:59 If you want to defer this to a future CL, that's o
ahe 2017/05/25 10:38:31 This is one of the things that I have implemented
Paul Berry 2017/05/25 11:47:17 Ah, ok. That wasn't obvious to me. Thank you. I
ahe 2017/05/25 13:16:15 I will add comments.
ahe 2017/05/29 07:18:00 Done.
317 variable.fileOffset, 327 push(buildCompileTimeErrorStatement(
318 "Can't declare '${variable.name}' because it was already used in " 328 "Can't declare '$name' because it was already used in this scope.",
319 "this scope."); 329 offset));
320 library.addCompileTimeError(error.charOffset, error.error, 330 library.addCompileTimeError(error.charOffset, error.error,
321 fileUri: error.uri); 331 fileUri: error.uri);
322 } 332 }
323 } 333 }
324 334
325 @override 335 @override
326 JumpTarget createJumpTarget(JumpTargetKind kind, int charOffset) { 336 JumpTarget createJumpTarget(JumpTargetKind kind, int charOffset) {
327 return new JumpTarget(kind, functionNestingLevel, member, charOffset); 337 return new JumpTarget(kind, functionNestingLevel, member, charOffset);
328 } 338 }
329 339
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 count--; 1681 count--;
1672 } 1682 }
1673 FormalParameters formals = new FormalParameters( 1683 FormalParameters formals = new FormalParameters(
1674 popList(count) ?? <VariableDeclaration>[], 1684 popList(count) ?? <VariableDeclaration>[],
1675 optional, 1685 optional,
1676 beginToken.charOffset); 1686 beginToken.charOffset);
1677 push(formals); 1687 push(formals);
1678 if ((inCatchClause || functionNestingLevel != 0) && 1688 if ((inCatchClause || functionNestingLevel != 0) &&
1679 kind != MemberKind.GeneralizedFunctionType) { 1689 kind != MemberKind.GeneralizedFunctionType) {
1680 enterLocalScope(formals.computeFormalParameterScope( 1690 enterLocalScope(formals.computeFormalParameterScope(
1681 scope, member ?? classBuilder ?? library)); 1691 scope, member ?? classBuilder ?? library, this));
1682 } 1692 }
1683 } 1693 }
1684 1694
1685 @override 1695 @override
1686 void beginCatchClause(Token token) { 1696 void beginCatchClause(Token token) {
1687 debugEvent("beginCatchClause"); 1697 debugEvent("beginCatchClause");
1688 inCatchClause = true; 1698 inCatchClause = true;
1689 } 1699 }
1690 1700
1691 @override 1701 @override
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
2124 typeParameters: typeParameters, asyncMarker: asyncModifier) 2134 typeParameters: typeParameters, asyncMarker: asyncModifier)
2125 ..fileOffset = formals.charOffset 2135 ..fileOffset = formals.charOffset
2126 ..fileEndOffset = endToken.charOffset)); 2136 ..fileEndOffset = endToken.charOffset));
2127 } 2137 }
2128 2138
2129 @override 2139 @override
2130 void endFunctionDeclaration(Token token) { 2140 void endFunctionDeclaration(Token token) {
2131 debugEvent("FunctionDeclaration"); 2141 debugEvent("FunctionDeclaration");
2132 FunctionNode function = pop(); 2142 FunctionNode function = pop();
2133 exitLocalScope(); 2143 exitLocalScope();
2134 FunctionDeclaration declaration = pop(); 2144 var declaration = pop();
2135 function.returnType = pop() ?? const DynamicType(); 2145 var returnType = pop() ?? const DynamicType();
2136 declaration.variable.type = function.functionType;
2137 pop(); // Modifiers. 2146 pop(); // Modifiers.
2138 exitFunction(); 2147 exitFunction();
2139 declaration.function = function; 2148 if (declaration is FunctionDeclaration) {
2140 function.parent = declaration; 2149 function.returnType = returnType;
2150 declaration.variable.type = function.functionType;
2151 declaration.function = function;
2152 function.parent = declaration;
2153 } else {
2154 // If [declaration] isn't a [FunctionDeclaration], it must be because
2155 // there was a compile-time error.
Paul Berry 2017/05/24 20:46:15 Maybe add a similar todo here, e.g.: "TODO(paulber
ahe 2017/05/29 07:18:00 Done.
2156 assert(library.compileTimeErrors.isNotEmpty);
2157 }
2141 push(declaration); 2158 push(declaration);
2142 } 2159 }
2143 2160
2144 @override 2161 @override
2145 void endUnnamedFunction(Token beginToken, Token token) { 2162 void endUnnamedFunction(Token beginToken, Token token) {
2146 debugEvent("UnnamedFunction"); 2163 debugEvent("UnnamedFunction");
2147 Statement body = popStatement(); 2164 Statement body = popStatement();
2148 AsyncMarker asyncModifier = pop(); 2165 AsyncMarker asyncModifier = pop();
2149 exitLocalScope(); 2166 exitLocalScope();
2150 FormalParameters formals = pop(); 2167 FormalParameters formals = pop();
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 debugEvent("Operator"); 2652 debugEvent("Operator");
2636 push(new Operator(token.stringValue)..fileOffset = token.charOffset); 2653 push(new Operator(token.stringValue)..fileOffset = token.charOffset);
2637 } 2654 }
2638 2655
2639 @override 2656 @override
2640 void handleSymbolVoid(Token token) { 2657 void handleSymbolVoid(Token token) {
2641 debugEvent("SymbolVoid"); 2658 debugEvent("SymbolVoid");
2642 push(new Identifier(token)); 2659 push(new Identifier(token));
2643 } 2660 }
2644 2661
2662 @override
2645 dynamic addCompileTimeError(int charOffset, String message, 2663 dynamic addCompileTimeError(int charOffset, String message,
2646 {bool silent: false}) { 2664 {bool silent: false}) {
2647 // TODO(ahe): If constantExpressionRequired is set, set it to false to 2665 // TODO(ahe): If constantExpressionRequired is set, set it to false to
2648 // avoid a long list of errors. 2666 // avoid a long list of errors.
2649 return library.addCompileTimeError(charOffset, message, fileUri: uri); 2667 return library.addCompileTimeError(charOffset, message, fileUri: uri);
2650 } 2668 }
2651 2669
2652 @override 2670 @override
2653 void handleInvalidFunctionBody(Token token) { 2671 void handleInvalidFunctionBody(Token token) {
2654 if (member.isNative) { 2672 if (member.isNative) {
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
3118 namedParameters.add(new NamedType(parameter.name, parameter.type)); 3136 namedParameters.add(new NamedType(parameter.name, parameter.type));
3119 } 3137 }
3120 namedParameters.sort(); 3138 namedParameters.sort();
3121 } 3139 }
3122 } 3140 }
3123 return new FunctionType(positionalParameters, returnType, 3141 return new FunctionType(positionalParameters, returnType,
3124 namedParameters: namedParameters, 3142 namedParameters: namedParameters,
3125 requiredParameterCount: requiredParameterCount); 3143 requiredParameterCount: requiredParameterCount);
3126 } 3144 }
3127 3145
3128 Scope computeFormalParameterScope(Scope parent, Builder builder) { 3146 Scope computeFormalParameterScope(
3147 Scope parent, Builder builder, BuilderHelper helper) {
3129 if (required.length == 0 && optional == null) return parent; 3148 if (required.length == 0 && optional == null) return parent;
3130 Map<String, Builder> local = <String, Builder>{}; 3149 Map<String, Builder> local = <String, Builder>{};
3150
3131 for (VariableDeclaration parameter in required) { 3151 for (VariableDeclaration parameter in required) {
3152 if (local[parameter.name] != null) {
3153 helper.addCompileTimeError(parameter.fileOffset, "Duplicated name.");
3154 }
3132 local[parameter.name] = 3155 local[parameter.name] =
3133 new KernelVariableBuilder(parameter, builder, builder.fileUri); 3156 new KernelVariableBuilder(parameter, builder, builder.fileUri);
3134 } 3157 }
3135 if (optional != null) { 3158 if (optional != null) {
3136 for (VariableDeclaration parameter in optional.formals) { 3159 for (VariableDeclaration parameter in optional.formals) {
3160 if (local[parameter.name] != null) {
3161 helper.addCompileTimeError(parameter.fileOffset, "Duplicated name.");
3162 }
3137 local[parameter.name] = 3163 local[parameter.name] =
3138 new KernelVariableBuilder(parameter, builder, builder.fileUri); 3164 new KernelVariableBuilder(parameter, builder, builder.fileUri);
3139 } 3165 }
3140 } 3166 }
3141 return new Scope(local, null, parent, isModifiable: false); 3167 return new Scope(local, null, parent, isModifiable: false);
3142 } 3168 }
3143 } 3169 }
3144 3170
3145 /// Returns a block like this: 3171 /// Returns a block like this:
3146 /// 3172 ///
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3193 if (starToken == null) { 3219 if (starToken == null) {
3194 return AsyncMarker.Async; 3220 return AsyncMarker.Async;
3195 } else { 3221 } else {
3196 assert(identical(starToken.stringValue, "*")); 3222 assert(identical(starToken.stringValue, "*"));
3197 return AsyncMarker.AsyncStar; 3223 return AsyncMarker.AsyncStar;
3198 } 3224 }
3199 } else { 3225 } else {
3200 return internalError("Unknown async modifier: $asyncToken"); 3226 return internalError("Unknown async modifier: $asyncToken");
3201 } 3227 }
3202 } 3228 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698