Skip to content

Commit 2e32eda

Browse files
committed
refactor: cleaned up Variable.create function
1 parent 646c42c commit 2e32eda

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

src/variables.ts

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -874,13 +874,7 @@ export abstract class Variable {
874874
static async create(debugVariable: dap.DebugVariable, frameId: number,
875875
context: ExecContext, logger: utils.ILogger,
876876
parent?: Variable) {
877-
878877
const effectiveType = Variable.getRealType(debugVariable.type, context);
879-
/*
880-
* We pass RealVariable (not generic Variable), because if we
881-
* want to use this function - it means we create variable
882-
* using debugger interface and this variable is present in code.
883-
*/
884878
const args: RealVariableArgs = {
885879
...debugVariable,
886880
frameId,
@@ -893,6 +887,11 @@ export abstract class Variable {
893887

894888
if ( context.debug.isValueStruct(debugVariable, effectiveType)
895889
|| !context.debug.isValidPointerType(debugVariable)) {
890+
/*
891+
* We are here if got scalar type or value struct (not pointer).
892+
* These types are not so interesting for us, so pass here to
893+
* quickly return usual variable.
894+
*/
896895

897896
if (context.debug.isNull(debugVariable) &&
898897
debugVariable.type.endsWith('List *')) {
@@ -915,30 +914,26 @@ export abstract class Variable {
915914
return new BitmapwordVariable(args);
916915
}
917916

918-
if (parent && context.canUseMacros) {
919-
let parentType = Variable.getRealType(parent.type, context);
920-
if (utils.isValueStructOrPointerType(parentType)) {
917+
if (parent) {
918+
if (utils.isValueStructOrPointerType(parent.type)) {
921919
const flagsMember = context.specialMemberRegistry.getFlagsMember(
922-
utils.getStructNameFromType(parentType),
923-
debugVariable.name);
920+
utils.getStructNameFromType(parent.type),
921+
debugVariable.name);
924922
if (flagsMember) {
925923
return new FlagsMemberVariable(flagsMember, args);
926924
}
927925
}
928-
}
929-
930-
/*
931-
* Flexible array members for now recognized as
932-
* non-valid pointers/scalars, but we actually
933-
* can handle them.
934-
*/
935-
if (debugVariable.type.endsWith('[]')) {
936-
if (parent?.type && parent instanceof RealVariable) {
926+
927+
/*
928+
* Flexible array members for now recognized as non-valid
929+
* pointers/scalars, but we actually can handle them.
930+
*/
931+
if (debugVariable.type.endsWith('[]')) {
937932
const parentType = Variable.getRealType(parent.type, context);
938933
const specialMember = context.specialMemberRegistry
939-
.getArraySpecialMember(parentType, debugVariable.name);
934+
.getArraySpecialMember(parentType, debugVariable.name);
940935
if (specialMember) {
941-
return new ArraySpecialMember(parent, specialMember, args);
936+
return new ArraySpecialMember(specialMember, args);
942937
}
943938
}
944939
}
@@ -953,11 +948,11 @@ export abstract class Variable {
953948
* It should never be one of others (Node, HTAB, etc...), but elements
954949
* of array can be.
955950
*/
956-
if (parent?.type && parent instanceof RealVariable) {
951+
if (parent) {
957952
const specialMember = context.specialMemberRegistry
958-
.getArraySpecialMember(parent.type, debugVariable.name);
953+
.getArraySpecialMember(parent.type, debugVariable.name);
959954
if (specialMember) {
960-
return new ArraySpecialMember(parent, specialMember, args);
955+
return new ArraySpecialMember(specialMember, args);
961956
}
962957
}
963958

@@ -972,9 +967,8 @@ export abstract class Variable {
972967
/* NodeTag variables: Node, List, Bitmapset etc.. */
973968
if (context.nodeVarRegistry.isNodeVar(effectiveType)) {
974969
const nodeVar = await NodeVariable.createNode(debugVariable, frameId,
975-
context, logger, args);
970+
context, logger, args);
976971
if (nodeVar) {
977-
await nodeVar.typeComputed
978972
return nodeVar;
979973
}
980974
}
@@ -4012,13 +4006,10 @@ export class ArraySpecialMember extends RealVariable {
40124006
* can be correction expressions i.e. '+ 1'.
40134007
*/
40144008
info: ArraySpecialMemberInfo;
4015-
parent: RealVariable;
40164009

4017-
constructor(parent: RealVariable, info: ArraySpecialMemberInfo,
4018-
args: RealVariableArgs) {
4010+
constructor(info: ArraySpecialMemberInfo, args: RealVariableArgs) {
40194011
super(args);
40204012
this.info = info;
4021-
this.parent = parent;
40224013
}
40234014

40244015
protected isExpandable(): boolean {
@@ -4043,7 +4034,7 @@ export class ArraySpecialMember extends RealVariable {
40434034
* so we can reference parent (members) multple times or use function
40444035
* invocation instead of simple member.
40454036
*/
4046-
const parentExpr = `((${this.parent.type})${this.parent.getPointer()})`;
4037+
const parentExpr = `((${this.parent!.type})${this.parent!.getPointer()})`;
40474038
const lengthExpr = this.info.lengthExpr.replace(/{}/g, parentExpr);
40484039
if (lengthExpr.startsWith('!')) {
40494040
return lengthExpr.substring(1);
@@ -4078,7 +4069,8 @@ export class ArraySpecialMember extends RealVariable {
40784069
length = ArraySpecialMember.plausibleMaxLength;
40794070
}
40804071

4081-
const memberExpr = `((${this.parent.type})${this.parent.getPointer()})->${this.info.memberName}`;
4072+
const parent = this.parent!;
4073+
const memberExpr = `((${parent.type})${parent.getPointer()})->${this.info.memberName}`;
40824074
const debugVariables = await this.debug.getArrayVariables(memberExpr,
40834075
length, this.frameId);
40844076
return await Variable.mapVariables(debugVariables, this.frameId, this.context,

0 commit comments

Comments
 (0)