improve symtab.h signature

This commit is contained in:
2025-12-01 15:22:05 +09:00
parent 1204abb4f9
commit 1840ea6b74

View File

@@ -28,7 +28,6 @@ typedef struct LineListRec {
*/ */
typedef struct BucketListRec { typedef struct BucketListRec {
char *name; char *name;
TreeNode *treeNode;
LineList lines; LineList lines;
ExpType type; ExpType type;
int memloc; /* memory location for variable */ int memloc; /* memory location for variable */
@@ -74,46 +73,35 @@ void insert_scope_to_list(Scope scope);
* @return the current scope or NULL if the stack is empty * @return the current scope or NULL if the stack is empty
*/ */
Scope curr_scope(void); Scope curr_scope(void);
/** /**
* insert a variable into the symbol table * insert a variable into the symbol table
* or update a variable if it already exists * or update a variable if it already exists
* @param scope_name name of the scope * @param scope_name name of the scope
* @param name name of the variable * @param name name of the variable
* @param type type of the variable * @param type type of the variable
* @param treeNode syntax tree node
* @param lineno line number of the variable * @param lineno line number of the variable
* @param loc memory location of the variable * @param loc memory location of the variable
* @return 0 if success, -1 if failure * @return 0 if success, -1 if failure
*/ */
int st_try_insert( int st_try_insert(char *name, ExpType type, int loc);
char *scope_name,
char *name,
ExpType type,
TreeNode *treeNode,
int loc);
/** /**
* lookup a variable in the current scope * lookup a variable in the current scope
* @param name name of the variable to lookup * @param name name of the variable to lookup
* @return the bucket list entry of the variable or NULL if not found * @return the bucket list entry of the variable or NULL if not found
*/ */
BucketList st_lookup_current(char *name); BucketList st_lookup_current(char *name);
/** /**
* lookup a variable from the given scope * lookup a variable from the given scope to root
* @param name name of the variable to lookup * @param name name of the variable to lookup
* @return the bucket list entry of the variable or NULL if not found * @return the bucket list entry of the variable or NULL if not found
*/ */
BucketList st_lookup(char *name); BucketList st_lookup(char *name);
/** /**
* find a scope from the scope list * find a scope from the scope list
* @param scope_name name of the scope to find * @param scope_name name of the scope to find
* @return the scope or NULL if not found * @return the scope or NULL if not found
*/ */
Scope find_scope(char *scope_name); Scope find_scope(char *scope_name);
/** /**
* Procedure printSymTab prints a formatted * Procedure printSymTab prints a formatted
* listing of the symbol table contents * listing of the symbol table contents