Skip to content

Commit

Permalink
fix parameter names for other constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Nov 18, 2023
1 parent d208020 commit 2db5afa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ export type Const_b = {
X: number;
y: number;
};
export function loadConst(slice: Slice, n: number): Const {
export function loadConst(slice: Slice, X: number): Const {
if (slice.preloadUint(1) == 0b0) {
let x: number;
x = slice.loadUint(32);
Expand Down
33 changes: 32 additions & 1 deletion tests/my.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,35 @@ function getCondition(conditions: Array<BinaryExpression>): Expression {
}
}

function checkConstructors(tlbType: TLBType) {
// TODO
}

function fillParameterNames(tlbType: TLBType) {
let parameterNames: string[] = []
tlbType.constructors[0]?.parameters.forEach(element => {
parameterNames.push(element.variable.name);
});
tlbType.constructors.forEach(constructor => {
for (let i = 0; i < constructor.parameters.length; i++) {
if (parameterNames[i] == '') {
let parameterName = constructor.parameters[i]?.variable.name;
if (parameterName != undefined) {
parameterNames[i] = parameterName;
}
}
}
});
tlbType.constructors.forEach(constructor => {
for (let i = 0; i < constructor.parameters.length; i++) {
let parameterName = parameterNames[i]
if (parameterName != undefined) {
constructor.parameters[i]!.variable.name = parameterName;
}
}
})
}

function fillConstructors(declarations: Declaration[], tlbCode: TLBCode) {
declarations.forEach(declaration => {
let tlbType: TLBType | undefined = tlbCode.types.get(declaration.combinator.name);
Expand Down Expand Up @@ -641,7 +670,7 @@ function fillConstructors(declarations: Declaration[], tlbCode: TLBCode) {
let derivedExpr = deriveMathExpression(element.expr);
parameter = {variable: {negated: true, const: false, type: '#', name: derivedExpr.name}, expression: derivedExpr.derived};
} else if (element instanceof NumberExpr) {
parameter = {variable: {negated: false, const: true, type: '#', name: 'n'}, expression: tNumericLiteral(element.num)}
parameter = {variable: {negated: false, const: true, type: '#', name: ''}, expression: tNumericLiteral(element.num)}
} else {
// throw new Error('Cannot identify combinator arg: ' + element)
}
Expand All @@ -651,6 +680,8 @@ function fillConstructors(declarations: Declaration[], tlbCode: TLBCode) {
}
});
});
checkConstructors(tlbType);
fillParameterNames(tlbType);
});
}

Expand Down

0 comments on commit 2db5afa

Please sign in to comment.