printdebug function with line and file names
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
|
||||
#include "symbol_table.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -19,8 +20,43 @@ TableNode *boo;
|
||||
TableNode *recprime;
|
||||
TableNode *funtypeprime;
|
||||
TableNode *undefined;
|
||||
// AdInfo *Undefined_function_type_info;
|
||||
|
||||
char *COLOR_RED = "\033[0;31m";
|
||||
char *COLOR_GREEN = "\033[0;32m";
|
||||
char *COLOR_ORANGE = "\033[0;33m";
|
||||
char *COLOR_BLUE = "\033[0;34m";
|
||||
char *COLOR_PURPLE = "\033[0;35m";
|
||||
char *COLOR_CYAN = "\033[0;36m";
|
||||
char *COLOR_LIGHTGRAY = "\033[0;37m";
|
||||
char *COLOR_DARKGRAY = "\033[1;30m";
|
||||
char *COLOR_LIGHTRED = "\033[1;31m";
|
||||
char *COLOR_LIGHTGREEN = "\033[1;32m";
|
||||
char *COLOR_YELLOW = "\033[1;33m";
|
||||
char *COLOR_LIGHTBLUE = "\033[1;34m";
|
||||
char *COLOR_LIGHTPURPLE = "\033[1;35m";
|
||||
char *COLOR_LIGHTCYAN = "\033[1;36m";
|
||||
char *COLOR_WHITE = "\033[1;37m";
|
||||
|
||||
bool DEBUG = true;
|
||||
|
||||
void printdebug_impl(char *file, int line, const char *format, ...);
|
||||
|
||||
void printdebug_impl(char *file, int line, const char *format, ...) {
|
||||
if (DEBUG) {
|
||||
printf("%s<%s> [%d]%s ", COLOR_DARKGRAY, file, line,
|
||||
COLOR_WHITE);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
va_end(args);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
#define printdebug(format, ...) \
|
||||
printdebug_impl(__FILE__, __LINE__, format, ##__VA_ARGS__)
|
||||
|
||||
// AdInfo *Undefined_function_type_info;
|
||||
typedef enum {
|
||||
// First 4 below are primitive types that are all encapsulated in
|
||||
// primitive type
|
||||
@ -107,16 +143,17 @@ AdInfo *CreatePrimitiveInfo(int size) {
|
||||
// only gets the size of a primitive type
|
||||
int getPrimSize(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printf(
|
||||
"passed an NULL entry to getPrimSize function. Invalid.\n");
|
||||
printdebug(
|
||||
"passed an NULL entry to getPrimSize function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (definition->additionalinfo == NULL) {
|
||||
printf("node has NULL additionalinfo. Invalid.\n");
|
||||
printdebug("node has NULL additionalinfo. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(getType(definition), "primitive") != 0) {
|
||||
printf("not checking the size of a primitive -- invalid op\n");
|
||||
printdebug(
|
||||
"not checking the size of a primitive -- invalid op");
|
||||
return 0;
|
||||
}
|
||||
return definition->additionalinfo->PrimAdInfo->size;
|
||||
@ -136,8 +173,8 @@ int getPrimSize(TableNode *definition) {
|
||||
// calculated at runtime so bounds checking only needs to be done then
|
||||
AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) {
|
||||
if (type == NULL || type == undefined) {
|
||||
printf("passed a NULL or undefined type reference to "
|
||||
"CreateArrayInfo. Invalid.\n");
|
||||
printdebug("passed a NULL or undefined type reference to "
|
||||
"CreateArrayInfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
|
||||
@ -151,12 +188,12 @@ AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) {
|
||||
// This gets the number of dimensions from array info
|
||||
int getNumArrDim(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printf("passed an NULL or undefined entry to getNumArrDim "
|
||||
"function. Invalid.\n");
|
||||
printdebug("passed an NULL or undefined entry to getNumArrDim "
|
||||
"function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(getType(definition), "array") != 0) {
|
||||
printf("not checking the dim of an array -- invalid op\n");
|
||||
printdebug("not checking the dim of an array -- invalid op");
|
||||
return 0;
|
||||
}
|
||||
return definition->additionalinfo->ArrayAdInfo->numofdimensions;
|
||||
@ -165,12 +202,12 @@ int getNumArrDim(TableNode *definition) {
|
||||
// the entry of that type
|
||||
TableNode *getArrType(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printf("passed an NULL or undefined entry to getArrType "
|
||||
"function. Invalid.\n");
|
||||
printdebug("passed an NULL or undefined entry to getArrType "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (strcmp(getType(definition), "array") != 0) {
|
||||
printf("not checking the type of an array -- invalid op\n");
|
||||
printdebug("not checking the type of an array -- invalid op");
|
||||
return undefined;
|
||||
}
|
||||
return definition->additionalinfo->ArrayAdInfo->typeofarray;
|
||||
@ -193,12 +230,13 @@ AdInfo *CreateRecordInfo(int length, SymbolTable *recordScope) {
|
||||
// anyways.
|
||||
int getRecLength(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printf("passed an NULL or undefined entry to getRecLength "
|
||||
"function. Invalid.\n");
|
||||
printdebug("passed an NULL or undefined entry to getRecLength "
|
||||
"function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(getType(definition), "record") != 0) {
|
||||
printf("not checking the length of an record -- invalid op\n");
|
||||
printdebug(
|
||||
"not checking the length of an record -- invalid op");
|
||||
return 0;
|
||||
}
|
||||
return definition->additionalinfo->RecAdInfo->numofelements;
|
||||
@ -206,13 +244,14 @@ int getRecLength(TableNode *definition) {
|
||||
// This gets the array. Needs to up be updated to get the scope instead
|
||||
SymbolTable *getRecList(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printf("passed an NULL or undefined entry to getRecList "
|
||||
"function. Invalid.\n");
|
||||
printdebug("passed an NULL or undefined entry to getRecList "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (strcmp(getType(definition), "record") != 0) {
|
||||
printf("not checking the list of types of a record -- invalid "
|
||||
"op\n");
|
||||
printdebug(
|
||||
"not checking the list of types of a record -- invalid "
|
||||
"op");
|
||||
return NULL;
|
||||
}
|
||||
return definition->additionalinfo->RecAdInfo->recordScope;
|
||||
@ -220,7 +259,7 @@ SymbolTable *getRecList(TableNode *definition) {
|
||||
|
||||
TableNode *setRecSize(TableNode *tn, int n) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
printf("passed in NULL entry for setRecSize. Invalid\n");
|
||||
printdebug("passed in NULL entry for setRecSize. Invalid");
|
||||
return undefined;
|
||||
}
|
||||
tn->additionalinfo->RecAdInfo->numofelements = n;
|
||||
@ -229,7 +268,8 @@ TableNode *setRecSize(TableNode *tn, int n) {
|
||||
|
||||
int getRecSize(SymbolTable *tn) {
|
||||
if (tn == NULL) {
|
||||
printf("passed in NULL SymbolTable for getRecSize. Invalid\n");
|
||||
printdebug(
|
||||
"passed in NULL SymbolTable for getRecSize. Invalid");
|
||||
return -1;
|
||||
}
|
||||
int s = 0;
|
||||
@ -261,13 +301,14 @@ AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular) {
|
||||
// out in table if needed)
|
||||
int getStartLine(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printf("passed an NULL or undefined entry to getStartLine "
|
||||
"function. Invalid.\n");
|
||||
printdebug("passed an NULL or undefined entry to getStartLine "
|
||||
"function. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(getType(definition), "primitive function") != 0) {
|
||||
printf("not checking the start line of a function -- invalid "
|
||||
"op\n");
|
||||
printdebug(
|
||||
"not checking the start line of a function -- invalid "
|
||||
"op");
|
||||
return 0;
|
||||
}
|
||||
return definition->additionalinfo->FunDecAdInfo->startlinenumber;
|
||||
@ -275,8 +316,9 @@ int getStartLine(TableNode *definition) {
|
||||
|
||||
TableNode *setStartLine(TableNode *tn, int start) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
printf("passing in a NULL or undefined entry to setStartLine. "
|
||||
"invalid\n");
|
||||
printdebug(
|
||||
"passing in a NULL or undefined entry to setStartLine. "
|
||||
"invalid");
|
||||
return undefined;
|
||||
}
|
||||
tn->additionalinfo->FunDecAdInfo->startlinenumber = start;
|
||||
@ -286,13 +328,14 @@ TableNode *setStartLine(TableNode *tn, int start) {
|
||||
// not used or used.
|
||||
bool getAsKeyword(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printf("passed an NULL or undefined entry to getAsKeyword "
|
||||
"function. Invalid.\n");
|
||||
printdebug("passed an NULL or undefined entry to getAsKeyword "
|
||||
"function. Invalid.");
|
||||
return false;
|
||||
}
|
||||
if (strcmp(getType(definition), "primitive function") != 0) {
|
||||
printf("not checking if a function is called with as or not -- "
|
||||
"invalid op\n");
|
||||
printdebug(
|
||||
"not checking if a function is called with as or not -- "
|
||||
"invalid op");
|
||||
return 0;
|
||||
}
|
||||
return definition->additionalinfo->FunDecAdInfo->regularoras;
|
||||
@ -300,8 +343,9 @@ bool getAsKeyword(TableNode *definition) {
|
||||
|
||||
TableNode *setAsKeyword(TableNode *tn, bool as) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
printf("passing in a NULL or undefined entry to setAsKeyword. "
|
||||
"invalid\n");
|
||||
printdebug(
|
||||
"passing in a NULL or undefined entry to setAsKeyword. "
|
||||
"invalid");
|
||||
return undefined;
|
||||
}
|
||||
tn->additionalinfo->FunDecAdInfo->regularoras = as;
|
||||
@ -311,13 +355,13 @@ TableNode *setAsKeyword(TableNode *tn, bool as) {
|
||||
// stores the type of a function (parameter type and return type)
|
||||
AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) {
|
||||
if (parameter == NULL || parameter == undefined) {
|
||||
printf("passed a NULL or undefined parameter to "
|
||||
"CreateFunctionTypeInfo. Invalid.\n");
|
||||
printdebug("passed a NULL or undefined parameter to "
|
||||
"CreateFunctionTypeInfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (returntype == NULL || returntype == undefined) {
|
||||
printf("passed a NULL or undefined return type to "
|
||||
"CreateFunctionTypeInfo. Invalid.\n");
|
||||
printdebug("passed a NULL or undefined return type to "
|
||||
"CreateFunctionTypeInfo. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
|
||||
@ -330,13 +374,13 @@ AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) {
|
||||
// returns parameter type of a function
|
||||
TableNode *getParameter(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printf("passed an NULL or undefined entry to getParameter "
|
||||
"function. Invalid.\n");
|
||||
printdebug("passed an NULL or undefined entry to getParameter "
|
||||
"function. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if (strcmp(getType(definition), "primitive function type") != 0) {
|
||||
printf(
|
||||
"not checking the parameter of a function -- invalid op\n");
|
||||
printdebug(
|
||||
"not checking the parameter of a function -- invalid op");
|
||||
return undefined;
|
||||
}
|
||||
return definition->additionalinfo->FunTypeAdInfo->parameter;
|
||||
@ -344,12 +388,13 @@ TableNode *getParameter(TableNode *definition) {
|
||||
// returns return type of a function
|
||||
TableNode *getReturn(TableNode *definition) {
|
||||
if (definition == NULL || definition == undefined) {
|
||||
printf("passed an NULL or undefined entry to getReturn "
|
||||
"function. Invalid.\n");
|
||||
printdebug("passed an NULL or undefined entry to getReturn "
|
||||
"function. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (strcmp(getType(definition), "primitive function type") != 0) {
|
||||
printf("not checking the return of a function -- invalid op\n");
|
||||
printdebug(
|
||||
"not checking the return of a function -- invalid op");
|
||||
return undefined;
|
||||
}
|
||||
return definition->additionalinfo->FunTypeAdInfo->returntype;
|
||||
@ -389,8 +434,8 @@ SymbolTable *CreateScope(SymbolTable *ParentScope, int Line, int Column) {
|
||||
// types
|
||||
SymbolTable *init(SymbolTable *start) {
|
||||
if (start->Parent_Scope != NULL) {
|
||||
printf(
|
||||
"Cannot initialize a scope that is not the parent scope\n");
|
||||
printdebug(
|
||||
"Cannot initialize a scope that is not the parent scope");
|
||||
return NULL;
|
||||
}
|
||||
integ = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
@ -504,18 +549,19 @@ TableNode* funtypeprime;
|
||||
*/
|
||||
TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
printf("passed in an invalid table node to modify (NULL or "
|
||||
"undefined).\n");
|
||||
printdebug("passed in an invalid table node to modify (NULL or "
|
||||
"undefined).");
|
||||
return undefined;
|
||||
}
|
||||
if (type == NULL || type == undefined) {
|
||||
printf("passed in a NULL or undefined type reference to "
|
||||
"populate a table node. Invalid.\n");
|
||||
printdebug("passed in a NULL or undefined type reference to "
|
||||
"populate a table node. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if (info == NULL) {
|
||||
printf("passed in a NULL info reference to populate a table "
|
||||
"node. Invalid.\n");
|
||||
printdebug(
|
||||
"passed in a NULL info reference to populate a table "
|
||||
"node. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
tn->theType = type;
|
||||
@ -526,12 +572,12 @@ TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) {
|
||||
|
||||
int getAdInfoType(TableNode *tn) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
printf("passing in NULL or undefined table entry. Invalid\n");
|
||||
printdebug("passing in NULL or undefined table entry. Invalid");
|
||||
return -1;
|
||||
}
|
||||
if (tn->theType == NULL || tn->theType == undefined) {
|
||||
printf("Entry being passed in has a null or undefined "
|
||||
"reference for theType. Invalid.\n");
|
||||
printdebug("Entry being passed in has a null or undefined "
|
||||
"reference for theType. Invalid.");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(getName(tn), getName(integ)) == 0) {
|
||||
@ -569,20 +615,21 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
|
||||
AdInfo *ad) {
|
||||
|
||||
if (table == NULL) {
|
||||
printf("Null reference to table");
|
||||
printdebug("Null reference to table");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/*
|
||||
TableNode* topDef = (table_lookup(getAncestor(table),typeOf));
|
||||
if(topDef == NULL){
|
||||
printf("This type is not defined at the top level\n");
|
||||
printdebug("This type is not defined at the top level");
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
if (typeOf == NULL || typeOf == undefined) {
|
||||
printf("This is not pointing to a proper definition (either "
|
||||
"NULL or undefined)\n");
|
||||
printdebug(
|
||||
"This is not pointing to a proper definition (either "
|
||||
"NULL or undefined)");
|
||||
return undefined;
|
||||
}
|
||||
TableNode *newEntry = (TableNode *)calloc(1, sizeof(TableNode));
|
||||
@ -602,11 +649,11 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
|
||||
|
||||
char *getType(TableNode *tn) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
printf("passed a NULL or undefined table entry to getType\n");
|
||||
printdebug("passed a NULL or undefined table entry to getType");
|
||||
return getName(undefined);
|
||||
}
|
||||
if (tn->theType == NULL || tn->theType == undefined) {
|
||||
printf("type of entry is currently NULL or undefined type \n");
|
||||
printdebug("type of entry is currently NULL or undefined type");
|
||||
return getName(undefined);
|
||||
}
|
||||
return tn->theType->theName;
|
||||
@ -614,12 +661,12 @@ char *getType(TableNode *tn) {
|
||||
|
||||
char *getName(TableNode *tn) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
// printf("passed a NULL or undefined table entry to
|
||||
// getName\n");
|
||||
// printdebug("passed a NULL or undefined table entry to
|
||||
// getName");
|
||||
return undefined->theName;
|
||||
}
|
||||
if (tn->theName == NULL) {
|
||||
// printf("name of entry is currently NULL, undefined \n");
|
||||
// printdebug("name of entry is currently NULL, undefined");
|
||||
return undefined->theName;
|
||||
}
|
||||
return tn->theName;
|
||||
@ -627,34 +674,36 @@ char *getName(TableNode *tn) {
|
||||
|
||||
int getLine(SymbolTable *st) {
|
||||
if (st == NULL) {
|
||||
printf("passed a NULL symbol table to getLine function. "
|
||||
"Invalid.\n");
|
||||
printdebug("passed a NULL symbol table to getLine function. "
|
||||
"Invalid.");
|
||||
return -1;
|
||||
}
|
||||
return st->Line_Number;
|
||||
}
|
||||
int getColumn(SymbolTable *st) {
|
||||
if (st == NULL) {
|
||||
printf("passed a NULL symbol table to getColumn function. "
|
||||
"Invalid.\n");
|
||||
printdebug("passed a NULL symbol table to getColumn function. "
|
||||
"Invalid.");
|
||||
return -1;
|
||||
}
|
||||
return st->Column_Number;
|
||||
}
|
||||
TableNode *addName(TableNode *tn, char *str) {
|
||||
if (tn == NULL || tn == undefined) {
|
||||
printf("passed a Null or undefined table node to the addName "
|
||||
"function. Invalid./n");
|
||||
printdebug(
|
||||
"passed a Null or undefined table node to the addName "
|
||||
"function. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
if (tn->theName != NULL) {
|
||||
printf("Name doesn't look like it is empty before you change. "
|
||||
"Are you sure you need to update name?/n");
|
||||
printdebug(
|
||||
"Name doesn't look like it is empty before you change. "
|
||||
"Are you sure you need to update name?");
|
||||
return undefined;
|
||||
}
|
||||
if (str == NULL) {
|
||||
printf(
|
||||
"passed a NULL string to the addName function. Invalid./n");
|
||||
printdebug(
|
||||
"passed a NULL string to the addName function. Invalid.");
|
||||
return undefined;
|
||||
}
|
||||
tn->theName = str;
|
||||
@ -663,8 +712,8 @@ TableNode *addName(TableNode *tn, char *str) {
|
||||
|
||||
SymbolTable *setLineNumber(SymbolTable *st, int line) {
|
||||
if (st == NULL) {
|
||||
printf("passed a Null Symbol Table to the setLineNumber "
|
||||
"function. Invalid./n");
|
||||
printdebug("passed a Null Symbol Table to the setLineNumber "
|
||||
"function. Invalid.");
|
||||
return st;
|
||||
}
|
||||
st->Line_Number = line;
|
||||
@ -673,8 +722,8 @@ SymbolTable *setLineNumber(SymbolTable *st, int line) {
|
||||
|
||||
SymbolTable *setColumnNumber(SymbolTable *st, int column) {
|
||||
if (st == NULL) {
|
||||
printf("passed a Null Symbol Table to the setColumnNumber "
|
||||
"function. Invalid./n");
|
||||
printdebug("passed a Null Symbol Table to the setColumnNumber "
|
||||
"function. Invalid.");
|
||||
return st;
|
||||
}
|
||||
st->Line_Number = column;
|
||||
@ -684,7 +733,7 @@ SymbolTable *setColumnNumber(SymbolTable *st, int column) {
|
||||
//we use false for type defs and true for functions for parameter of typeOf
|
||||
TableNode* Define(SymbolTable* table, bool typeOf, char* id) {
|
||||
if(table ==NULL || table->Parent_Scope != NULL){
|
||||
printf("No valid table given for header defs\n");
|
||||
printdebug("No valid table given for header defs");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -699,8 +748,8 @@ if (typeOf == 1){
|
||||
newEntry->theType = funy;
|
||||
}
|
||||
if(table_lookup(table,id) != NULL){
|
||||
printf("already defined at the top level, can't define duplicate
|
||||
names\n"); return NULL;
|
||||
printdebug("already defined at the top level, can't define duplicate
|
||||
names"); return NULL;
|
||||
}
|
||||
newEntry->theName = id;
|
||||
if (table->entries == NULL) {
|
||||
@ -718,7 +767,7 @@ names\n"); return NULL;
|
||||
// only check table that is given
|
||||
TableNode *table_lookup(SymbolTable *table, char *x) {
|
||||
if (table == NULL) {
|
||||
printf("passed in empty scope. error.\n");
|
||||
printdebug("passed in empty scope. error.");
|
||||
return undefined;
|
||||
}
|
||||
TableNode *entrie = table->entries;
|
||||
@ -732,16 +781,17 @@ TableNode *table_lookup(SymbolTable *table, char *x) {
|
||||
// check current table and all parents
|
||||
TableNode *look_up(SymbolTable *table, char *x) {
|
||||
if (table == NULL) {
|
||||
printf("passed in empty scope. error.\n");
|
||||
printdebug("passed in empty scope. error.");
|
||||
return undefined;
|
||||
}
|
||||
TableNode *ret = table_lookup(table, x);
|
||||
if (ret != NULL && ret != undefined) {
|
||||
return ret;
|
||||
}
|
||||
printf("could not find %s in scope that started at line %d and column "
|
||||
"%d so moving up a scope\n",
|
||||
x, getLine(table), getColumn(table));
|
||||
printdebug(
|
||||
"could not find %s in scope that started at line %d and column "
|
||||
"%d so moving up a scope",
|
||||
x, getLine(table), getColumn(table));
|
||||
return look_up(table->Parent_Scope, x);
|
||||
}
|
||||
/*
|
||||
@ -958,7 +1008,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
// get top most symbol table
|
||||
SymbolTable *getAncestor(SymbolTable *table) {
|
||||
if (table == NULL) {
|
||||
printf("passing a NULL reference to getAncestor. Invalid.\n");
|
||||
printdebug("passing a NULL reference to getAncestor. Invalid.");
|
||||
return NULL;
|
||||
}
|
||||
if (table->Parent_Scope == NULL) {
|
||||
@ -1005,11 +1055,11 @@ bool typeCheck(char *firstID, char *secondID) {
|
||||
TableNode *entry1 = look_up(cur, firstID);
|
||||
TableNode *entry2 = look_up(cur, secondID);
|
||||
if (entry1 == NULL || entry1 == undefined) {
|
||||
printf("first type not defined\n");
|
||||
printdebug("first type not defined");
|
||||
return false;
|
||||
}
|
||||
if (entry2 == NULL || entry2 == undefined) {
|
||||
printf("second type not defined\n");
|
||||
printdebug("second type not defined");
|
||||
return false;
|
||||
}
|
||||
if (table_lookup(getAncestor(cur), getType(look_up(cur, firstID))) ==
|
||||
@ -1052,36 +1102,11 @@ TableNode *getNextEntry(TableNode *tn) { return tn->next; }
|
||||
char* String = "STRING";
|
||||
char* X = "X";
|
||||
SymbolTable* Second = CreateScope(NULL, 2,2);
|
||||
printf("Line number is %d, Column number of scope is
|
||||
%d\n",Second->Line_Number,Second->Column_Number); TableNode* First_Entry =
|
||||
printdebug("Line number is %d, Column number of scope is
|
||||
%d",Second->Line_Number,Second->Column_Number); TableNode* First_Entry =
|
||||
CreateEntry(Second,String,X);
|
||||
|
||||
printf("The type of the first entry is %s\n",First_Entry->theType);
|
||||
printdebug("The type of the first entry is %s",First_Entry->theType);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
char *getLineStr();
|
||||
char *COLOR_RED = "\033[0;31m";
|
||||
char *COLOR_GREEN = "\033[0;32m";
|
||||
char *COLOR_ORANGE = "\033[0;33m";
|
||||
char *COLOR_BLUE = "\033[0;34m";
|
||||
char *COLOR_PURPLE = "\033[0;35m";
|
||||
char *COLOR_CYAN = "\033[0;36m";
|
||||
char *COLOR_LIGHTGRAY = "\033[0;37m";
|
||||
char *COLOR_DARKGRAY = "\033[1;30m";
|
||||
char *COLOR_LIGHTRED = "\033[1;31m";
|
||||
char *COLOR_LIGHTGREEN = "\033[1;32m";
|
||||
char *COLOR_YELLOW = "\033[1;33m";
|
||||
char *COLOR_LIGHTBLUE = "\033[1;34m";
|
||||
char *COLOR_LIGHTPURPLE = "\033[1;35m";
|
||||
char *COLOR_LIGHTCYAN = "\033[1;36m";
|
||||
char *COLOR_WHITE = "\033[1;37m";
|
||||
|
||||
bool DEBUG = false;
|
||||
|
||||
char *getLineStr(int d) {
|
||||
char *new_text = malloc(100);
|
||||
sprintf(new_text, "%s[%d]%s ", COLOR_DARKGRAY, d, COLOR_WHITE);
|
||||
return new_text;
|
||||
}
|
||||
*/
|
Reference in New Issue
Block a user