Skip to content

Commit 4ac6c58

Browse files
committed
pass debug param through some methods
1 parent 1245203 commit 4ac6c58

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

transpiler/main/c_code_gen.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,11 @@ void transpileAssignStmt(struct AssignStmt* as, struct Ctx* ctx){
401401
//find type via local variable symbol table
402402
assert(ctx->tables->lvst != NULL);
403403

404-
struct LVSTLine* line = lvst_get(ctx->tables->lvst, as->var->simpleVar->name);
404+
struct LVSTLine* line = lvst_get(
405+
ctx->tables->lvst,
406+
as->var->simpleVar->name,
407+
ctx->flags->debug
408+
);
405409

406410
assert(line != NULL);
407411

transpiler/main/tables/localvarsymtable.c

+19-10
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void discoverLVAssignStmt(
5050
// --------------------------------------------------------
5151
//to add a row to the local variable symbol table
5252
//the lvst works as a set regarding the 'name' of the local variable
53-
void lvst_add(struct LVST* lvst, struct LVSTLine* line);
53+
void lvst_add(struct LVST* lvst, struct LVSTLine* line, bool debug);
5454
// --------------------------------------------------------
5555

5656
struct LVST* makeLocalVarSymTable(bool debug){
@@ -90,7 +90,7 @@ void fillLocalVarSymTable(
9090
line->isArg = true;
9191
line->firstOccur = NULL;
9292

93-
lvst_add(st->lvst, line);
93+
lvst_add(st->lvst, line, debug);
9494
}
9595

9696
if(debug){
@@ -130,10 +130,14 @@ void freeLVSTLine(struct LVSTLine* l){
130130
free(l);
131131
}
132132

133-
void lvst_add(struct LVST* lvst, struct LVSTLine* line){
134-
135-
//no debug param, so we print
136-
printf("lvst_add(%p, %p)\n", lvst, line);
133+
void lvst_add(
134+
struct LVST* lvst,
135+
struct LVSTLine* line,
136+
bool debug
137+
){
138+
if(debug){
139+
printf("lvst_add(%p, %p)\n", lvst, line);
140+
}
137141

138142
//the local var symbol table works as a set
139143
//with 'name' as the key
@@ -168,10 +172,15 @@ void lvst_add(struct LVST* lvst, struct LVSTLine* line){
168172
lvst->count += 1;
169173
}
170174

171-
struct LVSTLine* lvst_get(struct LVST* lvst, char* name){
175+
struct LVSTLine* lvst_get(
176+
struct LVST* lvst,
177+
char* name,
178+
bool debug
179+
){
172180

173-
//no debug param, so we print
174-
printf("lvst_get(%p, %s)\n", lvst, name);
181+
if(debug){
182+
printf("lvst_get(%p, %s)\n", lvst, name);
183+
}
175184

176185
for(int i = 0; i < lvst->count; i++){
177186

@@ -273,7 +282,7 @@ void discoverLVAssignStmt(
273282
line->firstOccur = a;
274283
line->isArg = false;;
275284

276-
lvst_add(st->lvst, line);
285+
lvst_add(st->lvst, line, debug);
277286
}
278287

279288
void lvst_print(struct LVST* lvst){

transpiler/main/tables/localvarsymtable.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ void fillLocalVarSymTable(
5656
void freeLocalVarSymTable(struct LVST* lvst);
5757

5858
//obtain a reference to the line for that identifier
59-
struct LVSTLine* lvst_get(struct LVST* lvst, char* name);
59+
struct LVSTLine* lvst_get(
60+
struct LVST* lvst, char* name, bool debug
61+
);
6062

6163
void lvst_print(struct LVST* lvst);
6264
#endif

transpiler/main/tables/subrsymtable.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ struct SST* makeSubrSymTable(struct Namespace* ns, bool debug){
2727
line->isLibC = false;
2828
line->returnType = m->returnType;
2929

30-
printf("\tadding '%s' to subroutine symbol table\n", line->name);
30+
if(debug){
31+
printf("\tadding '%s' to subroutine symbol table\n", line->name);
32+
}
3133
sst_add(sst, line);
3234
}
3335

transpiler/main/typeinference.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ struct Type* inferTypeSimpleVar(struct ST* st, struct SimpleVar* v){
149149
//of another variable, it should have been initialized
150150
//before. so we can pull it's type from the LSVT
151151

152-
struct LVSTLine* line = lvst_get(st->lvst, v->name);
152+
//debug=true as param because
153+
//we do not get debug param here
154+
struct LVSTLine* line = lvst_get(st->lvst, v->name, true);
153155

154156
//if it has an index, we unwrap the type
155157
if(v->optIndex != NULL){

0 commit comments

Comments
 (0)