Skip to content

Commit 57f7941

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe] Remove 'functionNestingLevel' for VariableDeclaration.forValue
The 'functionNestingLevel' property is only needed for mutation and for-value variables are final. Change-Id: I970b8b0d9f185ca6fdf9b0599c792672f853105d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114503 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Aske Simon Christensen <[email protected]>
1 parent 35382f9 commit 57f7941

File tree

4 files changed

+41
-31
lines changed

4 files changed

+41
-31
lines changed

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,9 +1436,8 @@ class BodyBuilder extends ScopeListener<JumpTarget>
14361436
push(new VariableUseGenerator(this, token, expression.variable));
14371437
expression.extend();
14381438
} else {
1439-
VariableDeclaration variable = new VariableDeclarationJudgment.forValue(
1440-
expression, functionNestingLevel)
1441-
..fileOffset = expression.fileOffset;
1439+
VariableDeclaration variable = forest.createVariableDeclarationForValue(
1440+
expression.fileOffset, expression);
14421441
push(new CascadeJudgment(variable)..fileOffset = expression.fileOffset);
14431442
push(new VariableUseGenerator(this, token, variable));
14441443
}
@@ -1792,7 +1791,7 @@ class BodyBuilder extends ScopeListener<JumpTarget>
17921791
VariableDeclaration extensionThis,
17931792
List<TypeParameter> extensionTypeParameters,
17941793
Token token) {
1795-
int charOffset = offsetForToken(token);
1794+
int fileOffset = offsetForToken(token);
17961795

17971796
FunctionNode function = procedure.function;
17981797
List<TypeParameter> typeParameters = [];
@@ -1836,7 +1835,8 @@ class BodyBuilder extends ScopeListener<JumpTarget>
18361835
return forest.createVariableDeclaration(
18371836
parameter.name, functionNestingLevel,
18381837
type: substitution.substituteType(parameter.type),
1839-
initializer: isOptional ? forest.createNullLiteral(token) : null);
1838+
initializer:
1839+
isOptional ? forest.createNullLiteral(fileOffset) : null);
18401840
}
18411841

18421842
for (int position = 0;
@@ -1845,12 +1845,12 @@ class BodyBuilder extends ScopeListener<JumpTarget>
18451845
VariableDeclaration parameter = function.positionalParameters[position];
18461846
if (position == 0) {
18471847
/// Pass `this` as a captured variable.
1848-
positionalArguments.add(createVariableGet(extensionThis, charOffset));
1848+
positionalArguments.add(createVariableGet(extensionThis, fileOffset));
18491849
} else {
18501850
VariableDeclaration newParameter = copyParameter(parameter,
18511851
isOptional: position >= function.requiredParameterCount);
18521852
positionalParameters.add(newParameter);
1853-
positionalArguments.add(createVariableGet(newParameter, charOffset));
1853+
positionalArguments.add(createVariableGet(newParameter, fileOffset));
18541854
}
18551855
}
18561856
List<VariableDeclaration> namedParameters = [];
@@ -1860,17 +1860,17 @@ class BodyBuilder extends ScopeListener<JumpTarget>
18601860
copyParameter(parameter, isOptional: true);
18611861
namedParameters.add(newParameter);
18621862
namedArguments.add(forest.createNamedExpression(
1863-
parameter.name, createVariableGet(newParameter, charOffset)));
1863+
parameter.name, createVariableGet(newParameter, fileOffset)));
18641864
}
18651865

18661866
Statement body = forest.createReturnStatement(
18671867
null,
18681868
buildStaticInvocation(
18691869
procedure,
1870-
forest.createArguments(charOffset, positionalArguments,
1870+
forest.createArguments(fileOffset, positionalArguments,
18711871
types: typeArguments, named: namedArguments),
1872-
charOffset: charOffset),
1873-
charOffset);
1872+
charOffset: fileOffset),
1873+
fileOffset);
18741874

18751875
FunctionExpression expression = forest.createFunctionExpression(
18761876
forest.createFunctionNode(body,
@@ -1882,7 +1882,7 @@ class BodyBuilder extends ScopeListener<JumpTarget>
18821882
returnType: returnType,
18831883
asyncMarker: procedure.function.asyncMarker,
18841884
dartAsyncMarker: procedure.function.dartAsyncMarker),
1885-
charOffset);
1885+
fileOffset);
18861886
functionNestingLevel--;
18871887
return expression;
18881888
}
@@ -2319,7 +2319,7 @@ class BodyBuilder extends ScopeListener<JumpTarget>
23192319
debugEvent("NoFieldInitializer");
23202320
if (constantContext == ConstantContext.inferred) {
23212321
// Creating a null value to prevent the Dart VM from crashing.
2322-
push(forest.createNullLiteral(token));
2322+
push(forest.createNullLiteral(offsetForToken(token)));
23232323
} else {
23242324
push(NullValue.FieldInitializer);
23252325
}
@@ -2794,7 +2794,7 @@ class BodyBuilder extends ScopeListener<JumpTarget>
27942794
@override
27952795
void handleLiteralNull(Token token) {
27962796
debugEvent("LiteralNull");
2797-
push(forest.createNullLiteral(token));
2797+
push(forest.createNullLiteral(offsetForToken(token)));
27982798
}
27992799

28002800
void buildLiteralMap(List<UnresolvedType> typeArguments, Token constKeyword,
@@ -4377,7 +4377,7 @@ class BodyBuilder extends ScopeListener<JumpTarget>
43774377

43784378
VariableDeclaration buildForInVariable(Object lvalue) {
43794379
if (lvalue is VariableDeclaration) return lvalue;
4380-
return new VariableDeclarationJudgment.forValue(null, functionNestingLevel);
4380+
return forest.createVariableDeclarationForValue(noLocation, null);
43814381
}
43824382

43834383
Expression checkForInVariable(

pkg/front_end/lib/src/fasta/kernel/expression_generator.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ abstract class Generator {
305305
complexAssignment?.isPostIncDec = true;
306306
VariableDeclarationJudgment dummy =
307307
new VariableDeclarationJudgment.forValue(
308-
_makeWrite(combiner, true, complexAssignment),
309-
_helper.functionNestingLevel);
308+
_makeWrite(combiner, true, complexAssignment));
310309
return _finish(
311310
makeLet(value, makeLet(dummy, valueAccess())), complexAssignment);
312311
}
@@ -317,7 +316,7 @@ abstract class Generator {
317316
Expression _makeInvalidRead() {
318317
return _helper.wrapSyntheticExpression(
319318
_helper.throwNoSuchMethodError(
320-
_forest.createNullLiteral(token),
319+
_forest.createNullLiteral(fileOffset),
321320
_plainNameForRead,
322321
_forest.createArgumentsEmpty(noLocation),
323322
fileOffset,
@@ -332,7 +331,7 @@ abstract class Generator {
332331
Expression _makeInvalidWrite(Expression value) {
333332
return _helper.wrapSyntheticExpression(
334333
_helper.throwNoSuchMethodError(
335-
_forest.createNullLiteral(token),
334+
_forest.createNullLiteral(fileOffset),
336335
_plainNameForRead,
337336
_forest.createArguments(noLocation, <Expression>[value]),
338337
fileOffset,
@@ -483,7 +482,7 @@ abstract class Generator {
483482
}
484483
return _helper.wrapInvalidConstructorInvocation(
485484
_helper.throwNoSuchMethodError(
486-
_forest.createNullLiteral(token),
485+
_forest.createNullLiteral(fileOffset),
487486
_helper.constructorNameForDiagnostics(name,
488487
className: _plainNameForRead),
489488
arguments,
@@ -1115,8 +1114,7 @@ class IndexedAccessGenerator extends Generator {
11151114
..fileOffset = fileOffset;
11161115
complexAssignment?.write = write;
11171116
VariableDeclarationJudgment dummy =
1118-
new VariableDeclarationJudgment.forValue(
1119-
write, _helper.functionNestingLevel);
1117+
new VariableDeclarationJudgment.forValue(write);
11201118
return makeLet(
11211119
valueVariable, makeLet(dummy, new VariableGet(valueVariable)));
11221120
}
@@ -1713,7 +1711,7 @@ class ExtensionInstanceAccessGenerator extends Generator {
17131711
_helper.forest.createArguments(fileOffset,
17141712
[_helper.createVariableGet(extensionThis, fileOffset)],
17151713
types: typeArguments),
1716-
charOffset: token.charOffset);
1714+
charOffset: fileOffset);
17171715
}
17181716
complexAssignment?.read = read;
17191717
return read;
@@ -2071,7 +2069,7 @@ class TypeUseGenerator extends ReadOnlyAccessGenerator {
20712069
Expression _makeInvalidWrite(Expression value) {
20722070
return _helper.wrapSyntheticExpression(
20732071
_helper.throwNoSuchMethodError(
2074-
_forest.createNullLiteral(token),
2072+
_forest.createNullLiteral(fileOffset),
20752073
_plainNameForRead,
20762074
_forest.createArguments(fileOffset, <Expression>[value]),
20772075
fileOffset,
@@ -2708,7 +2706,7 @@ class PrefixUseGenerator extends Generator {
27082706
int offset, Arguments arguments) {
27092707
return _helper.wrapInLocatedProblem(
27102708
_helper.evaluateArgumentsBefore(
2711-
arguments, _forest.createNullLiteral(token)),
2709+
arguments, _forest.createNullLiteral(fileOffset)),
27122710
messageCantUsePrefixAsExpression.withLocation(
27132711
_helper.uri, fileOffset, lengthForToken(token)));
27142712
}

pkg/front_end/lib/src/fasta/kernel/forest.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ class Forest {
190190
..fileOffset = offsetForToken(constKeyword ?? leftBrace);
191191
}
192192

193-
/// Return a representation of a null literal at the given [location].
194-
NullLiteral createNullLiteral(Token token) {
195-
return new NullLiteral()..fileOffset = offsetForToken(token);
193+
/// Return a representation of a null literal at the given [fileOffset].
194+
NullLiteral createNullLiteral(int fileOffset) {
195+
return new NullLiteral()..fileOffset = fileOffset ?? TreeNode.noOffset;
196196
}
197197

198198
/// Return a representation of a simple string literal at the given
@@ -637,7 +637,7 @@ class Forest {
637637
bool isFieldFormal: false,
638638
bool isCovariant: false,
639639
bool isLocalFunction: false}) {
640-
return VariableDeclarationJudgment(name, functionNestingLevel,
640+
return new VariableDeclarationJudgment(name, functionNestingLevel,
641641
type: type,
642642
initializer: initializer,
643643
isFinal: isFinal,
@@ -647,6 +647,18 @@ class Forest {
647647
isLocalFunction: isLocalFunction);
648648
}
649649

650+
VariableDeclaration createVariableDeclarationForValue(
651+
int fileOffset, Expression initializer,
652+
{DartType type = const DynamicType()}) {
653+
return new VariableDeclarationJudgment.forValue(initializer)
654+
..type = type
655+
..fileOffset = fileOffset ?? TreeNode.noOffset;
656+
}
657+
658+
Let createLet(VariableDeclaration variable, Expression body) {
659+
return new Let(variable, body);
660+
}
661+
650662
FunctionNode createFunctionNode(Statement body,
651663
{List<TypeParameter> typeParameters,
652664
List<VariableDeclaration> positionalParameters,

pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,9 +1626,9 @@ class VariableDeclarationJudgment extends VariableDeclaration
16261626
_isLocalFunction = false,
16271627
super.forValue(initializer);
16281628

1629-
VariableDeclarationJudgment.forValue(
1630-
Expression initializer, this._functionNestingLevel)
1629+
VariableDeclarationJudgment.forValue(Expression initializer)
16311630
: forSyntheticToken = false,
1631+
_functionNestingLevel = 0,
16321632
_implicitlyTyped = true,
16331633
_isLocalFunction = false,
16341634
super.forValue(initializer);

0 commit comments

Comments
 (0)