Skip to content

Commit

Permalink
pass debug param through some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pointbazaar committed Sep 4, 2020
1 parent 1245203 commit 4ac6c58
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
6 changes: 5 additions & 1 deletion transpiler/main/c_code_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ void transpileAssignStmt(struct AssignStmt* as, struct Ctx* ctx){
//find type via local variable symbol table
assert(ctx->tables->lvst != NULL);

struct LVSTLine* line = lvst_get(ctx->tables->lvst, as->var->simpleVar->name);
struct LVSTLine* line = lvst_get(
ctx->tables->lvst,
as->var->simpleVar->name,
ctx->flags->debug
);

assert(line != NULL);

Expand Down
29 changes: 19 additions & 10 deletions transpiler/main/tables/localvarsymtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void discoverLVAssignStmt(
// --------------------------------------------------------
//to add a row to the local variable symbol table
//the lvst works as a set regarding the 'name' of the local variable
void lvst_add(struct LVST* lvst, struct LVSTLine* line);
void lvst_add(struct LVST* lvst, struct LVSTLine* line, bool debug);
// --------------------------------------------------------

struct LVST* makeLocalVarSymTable(bool debug){
Expand Down Expand Up @@ -90,7 +90,7 @@ void fillLocalVarSymTable(
line->isArg = true;
line->firstOccur = NULL;

lvst_add(st->lvst, line);
lvst_add(st->lvst, line, debug);
}

if(debug){
Expand Down Expand Up @@ -130,10 +130,14 @@ void freeLVSTLine(struct LVSTLine* l){
free(l);
}

void lvst_add(struct LVST* lvst, struct LVSTLine* line){

//no debug param, so we print
printf("lvst_add(%p, %p)\n", lvst, line);
void lvst_add(
struct LVST* lvst,
struct LVSTLine* line,
bool debug
){
if(debug){
printf("lvst_add(%p, %p)\n", lvst, line);
}

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

struct LVSTLine* lvst_get(struct LVST* lvst, char* name){
struct LVSTLine* lvst_get(
struct LVST* lvst,
char* name,
bool debug
){

//no debug param, so we print
printf("lvst_get(%p, %s)\n", lvst, name);
if(debug){
printf("lvst_get(%p, %s)\n", lvst, name);
}

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

Expand Down Expand Up @@ -273,7 +282,7 @@ void discoverLVAssignStmt(
line->firstOccur = a;
line->isArg = false;;

lvst_add(st->lvst, line);
lvst_add(st->lvst, line, debug);
}

void lvst_print(struct LVST* lvst){
Expand Down
4 changes: 3 additions & 1 deletion transpiler/main/tables/localvarsymtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ void fillLocalVarSymTable(
void freeLocalVarSymTable(struct LVST* lvst);

//obtain a reference to the line for that identifier
struct LVSTLine* lvst_get(struct LVST* lvst, char* name);
struct LVSTLine* lvst_get(
struct LVST* lvst, char* name, bool debug
);

void lvst_print(struct LVST* lvst);
#endif
4 changes: 3 additions & 1 deletion transpiler/main/tables/subrsymtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ struct SST* makeSubrSymTable(struct Namespace* ns, bool debug){
line->isLibC = false;
line->returnType = m->returnType;

printf("\tadding '%s' to subroutine symbol table\n", line->name);
if(debug){
printf("\tadding '%s' to subroutine symbol table\n", line->name);
}
sst_add(sst, line);
}

Expand Down
4 changes: 3 additions & 1 deletion transpiler/main/typeinference.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ struct Type* inferTypeSimpleVar(struct ST* st, struct SimpleVar* v){
//of another variable, it should have been initialized
//before. so we can pull it's type from the LSVT

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

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

0 comments on commit 4ac6c58

Please sign in to comment.