[cfe] Implement clone methods for the new variable model
Part of https://github.com/dart-lang/sdk/issues/61572 Change-Id: Ic255fa48e8fe6611bf00cad8d798cca289b67fa6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/492120 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
This commit is contained in:
committed by
Commit Queue
parent
22581060b2
commit
86e99cefd5
+111
-4
@@ -705,21 +705,128 @@ class CloneVisitorNotMembers
|
||||
|
||||
@override
|
||||
TreeNode visitVariableDeclaration(VariableDeclaration node) {
|
||||
throw new UnimplementedError(
|
||||
"${this.runtimeType}.visitVariableDeclaration",
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TreeNode visitPositionalParameter(PositionalParameter node) {
|
||||
return setVariableClone(
|
||||
node,
|
||||
new VariableDeclaration(
|
||||
new PositionalParameter(
|
||||
cosmeticName: node.cosmeticName,
|
||||
type: visitType(node.type),
|
||||
defaultValue: cloneOptional(node.defaultValue),
|
||||
)
|
||||
..flags = node.flags
|
||||
..annotations = _cloneAnnotations(node)
|
||||
..fileEqualsOffset = _cloneFileOffset(node.fileEqualsOffset),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TreeNode visitNamedParameter(NamedParameter node) {
|
||||
return setVariableClone(
|
||||
node,
|
||||
new NamedParameter(
|
||||
parameterName: node.parameterName,
|
||||
type: visitType(node.type),
|
||||
defaultValue: cloneOptional(node.defaultValue),
|
||||
)
|
||||
..flags = node.flags
|
||||
..annotations = _cloneAnnotations(node)
|
||||
..fileEqualsOffset = _cloneFileOffset(node.fileEqualsOffset),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TreeNode visitCatchVariable(CatchVariable node) {
|
||||
return setVariableClone(
|
||||
node,
|
||||
new CatchVariable(
|
||||
name: node.catchVariableName,
|
||||
type: visitOptionalType(node.type),
|
||||
)
|
||||
..flags = node.flags
|
||||
..annotations = _cloneAnnotations(node)
|
||||
..fileEqualsOffset = _cloneFileOffset(node.fileEqualsOffset),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TreeNode visitLocalVariable(LocalVariable node) {
|
||||
return setVariableClone(
|
||||
node,
|
||||
new LocalVariable(
|
||||
cosmeticName: node.cosmeticName,
|
||||
type: visitOptionalType(node.type),
|
||||
)
|
||||
..flags = node.flags
|
||||
..annotations = _cloneAnnotations(node)
|
||||
..fileEqualsOffset = _cloneFileOffset(node.fileEqualsOffset),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TreeNode visitSyntheticVariable(SyntheticVariable node) {
|
||||
return setVariableClone(
|
||||
node,
|
||||
SyntheticVariable(
|
||||
cosmeticName: node.cosmeticName,
|
||||
type: visitType(node.type),
|
||||
)
|
||||
..flags = node.flags
|
||||
..annotations = _cloneAnnotations(node)
|
||||
..fileEqualsOffset = _cloneFileOffset(node.fileEqualsOffset),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TreeNode visitThisVariable(ThisVariable node) {
|
||||
return setVariableClone(
|
||||
node,
|
||||
new ThisVariable(type: visitType(node.type))
|
||||
..flags = node.flags
|
||||
..annotations = _cloneAnnotations(node)
|
||||
..fileEqualsOffset = _cloneFileOffset(node.fileEqualsOffset),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TreeNode visitVariableStatement(VariableStatement node) {
|
||||
return setVariableClone(
|
||||
node,
|
||||
new VariableStatement(
|
||||
node.name,
|
||||
initializer: cloneOptional(node.initializer),
|
||||
type: visitType(node.type),
|
||||
flags: node.flags,
|
||||
)
|
||||
..annotations = cloneAnnotations && !node.annotations.isEmpty
|
||||
? node.annotations.map(clone).toList()
|
||||
: const <Expression>[]
|
||||
..annotations = _cloneAnnotations(node)
|
||||
..fileEqualsOffset = _cloneFileOffset(node.fileEqualsOffset),
|
||||
);
|
||||
}
|
||||
|
||||
List<Expression> _cloneAnnotations(Annotatable node) {
|
||||
return cloneAnnotations && !node.annotations.isEmpty
|
||||
? node.annotations.map(clone).toList()
|
||||
: const <Expression>[];
|
||||
}
|
||||
|
||||
@override
|
||||
TreeNode visitVariableInitialization(VariableInitialization node) {
|
||||
return new VariableInitialization(
|
||||
variable: clone(node.variable),
|
||||
initializer: cloneOptional(node.initializer),
|
||||
)
|
||||
..flags = node.flags
|
||||
..annotations = cloneAnnotations && !node.annotations.isEmpty
|
||||
? node.annotations.map(clone).toList()
|
||||
: const <Expression>[]
|
||||
..fileEqualsOffset = _cloneFileOffset(node.fileEqualsOffset);
|
||||
}
|
||||
|
||||
@override
|
||||
TreeNode visitFunctionDeclaration(FunctionDeclaration node) {
|
||||
VariableDeclaration newVariable = clone(node.variable);
|
||||
|
||||
@@ -859,6 +859,7 @@ sealed class FunctionParameter extends VariableDeclaration {
|
||||
static const int FlagLowered = 1 << 7;
|
||||
static const int FlagHasDeclaredDefaultType = 1 << 8;
|
||||
static const int FlagSynthesized = 1 << 9;
|
||||
static const int FlagErroneouslyInitialized = 1 << 10;
|
||||
|
||||
@override
|
||||
bool get isFinal => flags & FlagFinal != 0;
|
||||
@@ -957,6 +958,16 @@ sealed class FunctionParameter extends VariableDeclaration {
|
||||
flags = value ? (flags | FlagSynthesized) : (flags & ~FlagSynthesized);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isErroneouslyInitialized => flags & FlagErroneouslyInitialized != 0;
|
||||
|
||||
@override
|
||||
void set isErroneouslyInitialized(bool value) {
|
||||
flags = value
|
||||
? (flags | FlagErroneouslyInitialized)
|
||||
: (flags & ~FlagErroneouslyInitialized);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isLate {
|
||||
// Function parameters can't be 'late'.
|
||||
@@ -979,16 +990,6 @@ sealed class FunctionParameter extends VariableDeclaration {
|
||||
throw new UnsupportedError("${this.runtimeType}");
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isErroneouslyInitialized {
|
||||
throw new UnsupportedError("${this.runtimeType}");
|
||||
}
|
||||
|
||||
@override
|
||||
void set isErroneouslyInitialized(bool value) {
|
||||
throw new UnsupportedError("${this.runtimeType}");
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isHoisted {
|
||||
throw new UnsupportedError("${this.runtimeType}");
|
||||
@@ -1121,7 +1122,7 @@ class PositionalParameter extends FunctionParameter {
|
||||
bool get hasIsSuperInitializingFormal => true;
|
||||
|
||||
@override
|
||||
bool get hasIsErroneouslyInitialized => false;
|
||||
bool get hasIsErroneouslyInitialized => true;
|
||||
|
||||
@override
|
||||
int binaryOffsetNoTag = -1;
|
||||
@@ -1257,7 +1258,7 @@ class NamedParameter extends FunctionParameter {
|
||||
bool get hasIsSuperInitializingFormal => true;
|
||||
|
||||
@override
|
||||
bool get hasIsErroneouslyInitialized => false;
|
||||
bool get hasIsErroneouslyInitialized => true;
|
||||
|
||||
@override
|
||||
int binaryOffsetNoTag = -1;
|
||||
|
||||
Reference in New Issue
Block a user