Code cleanup, style fixes
This commit is contained in:
parent
cbf7e661d2
commit
8665f8b03c
@ -588,7 +588,7 @@ SC_FUNC void delete_symbol(symbol *root,symbol *sym);
|
|||||||
SC_FUNC void delete_symbols(symbol *root,int level,int del_labels,int delete_functions);
|
SC_FUNC void delete_symbols(symbol *root,int level,int del_labels,int delete_functions);
|
||||||
SC_FUNC int refer_symbol(symbol *entry,symbol *bywhom);
|
SC_FUNC int refer_symbol(symbol *entry,symbol *bywhom);
|
||||||
SC_FUNC void markusage(symbol *sym,int usage);
|
SC_FUNC void markusage(symbol *sym,int usage);
|
||||||
SC_FUNC void rename_symbol(symbol *sym, const char *newname);
|
SC_FUNC void rename_symbol(symbol *sym,const char *newname);
|
||||||
SC_FUNC symbol *findglb(const char *name,int filter);
|
SC_FUNC symbol *findglb(const char *name,int filter);
|
||||||
SC_FUNC symbol *findloc(const char *name);
|
SC_FUNC symbol *findloc(const char *name);
|
||||||
SC_FUNC symbol *findconst(const char *name,int *matchtag);
|
SC_FUNC symbol *findconst(const char *name,int *matchtag);
|
||||||
|
@ -928,7 +928,7 @@ static void initglobals(void)
|
|||||||
litq=NULL; /* the literal queue */
|
litq=NULL; /* the literal queue */
|
||||||
glbtab.next=NULL; /* clear global variables/constants table */
|
glbtab.next=NULL; /* clear global variables/constants table */
|
||||||
loctab.next=NULL; /* " local " / " " */
|
loctab.next=NULL; /* " local " / " " */
|
||||||
hashmap_init(&symbol_cache_map, hashmap_hash_string, hashmap_compare_string, 10000000); // TODO: make sure this is big enough
|
hashmap_init(&symbol_cache_map,hashmap_hash_string,hashmap_compare_string,10000000); // TODO: make sure this is big enough
|
||||||
tagname_tab.next=NULL;/* tagname table */
|
tagname_tab.next=NULL;/* tagname table */
|
||||||
libname_tab.next=NULL;/* library table (#pragma library "..." syntax) */
|
libname_tab.next=NULL;/* library table (#pragma library "..." syntax) */
|
||||||
|
|
||||||
@ -3265,7 +3265,7 @@ static int operatoradjust(int opertok,symbol *sym,char *opername,int resulttag)
|
|||||||
refer_symbol(sym,oldsym->refer[i]);
|
refer_symbol(sym,oldsym->refer[i]);
|
||||||
delete_symbol(&glbtab,oldsym);
|
delete_symbol(&glbtab,oldsym);
|
||||||
} /* if */
|
} /* if */
|
||||||
rename_symbol(sym, tmpname);
|
rename_symbol(sym,tmpname);
|
||||||
|
|
||||||
/* operators should return a value, except the '~' operator */
|
/* operators should return a value, except the '~' operator */
|
||||||
if (opertok!='~')
|
if (opertok!='~')
|
||||||
|
@ -2623,6 +2623,57 @@ SC_FUNC int ishex(char c)
|
|||||||
return (c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F');
|
return (c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void symbol_cache_add(symbol *sym,symbol2 *new_cache_sym)
|
||||||
|
{
|
||||||
|
symbol2 *cache_sym;
|
||||||
|
|
||||||
|
if (new_cache_sym==NULL) {
|
||||||
|
new_cache_sym=(symbol2 *)malloc(sizeof(symbol2));
|
||||||
|
if (new_cache_sym==NULL)
|
||||||
|
error(103); /* insufficient memory */
|
||||||
|
new_cache_sym->symbol=sym;
|
||||||
|
}
|
||||||
|
new_cache_sym->next=NULL;
|
||||||
|
|
||||||
|
cache_sym=hashmap_get(&symbol_cache_map,sym->name);
|
||||||
|
if (cache_sym==NULL) {
|
||||||
|
if (hashmap_put(&symbol_cache_map,sym->name,new_cache_sym)==NULL)
|
||||||
|
error(103); /* insufficient memory */
|
||||||
|
} else {
|
||||||
|
while(cache_sym->next!=NULL)
|
||||||
|
cache_sym=cache_sym->next;
|
||||||
|
cache_sym->next=new_cache_sym;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static symbol2 *symbol_cache_remove(symbol *sym,int free_cache_sym)
|
||||||
|
{
|
||||||
|
symbol2 *cache_sym;
|
||||||
|
symbol2 *parent_cache_sym=NULL;
|
||||||
|
|
||||||
|
cache_sym=hashmap_get(&symbol_cache_map,sym->name);
|
||||||
|
if (cache_sym==NULL)
|
||||||
|
return NULL;
|
||||||
|
while (cache_sym->symbol!=sym) {
|
||||||
|
parent_cache_sym=cache_sym;
|
||||||
|
cache_sym=cache_sym->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parent_cache_sym!=NULL) {
|
||||||
|
parent_cache_sym->next=cache_sym->next;
|
||||||
|
} else {
|
||||||
|
hashmap_remove(&symbol_cache_map,sym->name);
|
||||||
|
if (cache_sym->next!=NULL)
|
||||||
|
if (hashmap_put(&symbol_cache_map,sym->name,cache_sym->next))
|
||||||
|
error(103); /* insufficient memory */
|
||||||
|
}
|
||||||
|
if (free_cache_sym) {
|
||||||
|
free(cache_sym);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return cache_sym;
|
||||||
|
}
|
||||||
|
|
||||||
/* The local variable table must be searched backwards, so that the deepest
|
/* The local variable table must be searched backwards, so that the deepest
|
||||||
* nesting of local variables is searched first. The simplest way to do
|
* nesting of local variables is searched first. The simplest way to do
|
||||||
* this is to insert all new items at the head of the list.
|
* this is to insert all new items at the head of the list.
|
||||||
@ -2632,8 +2683,6 @@ SC_FUNC int ishex(char c)
|
|||||||
static symbol *add_symbol(symbol *root,symbol *entry,int sort)
|
static symbol *add_symbol(symbol *root,symbol *entry,int sort)
|
||||||
{
|
{
|
||||||
symbol *newsym;
|
symbol *newsym;
|
||||||
symbol2 *cache_sym;
|
|
||||||
symbol2 *new_cache_sym;
|
|
||||||
|
|
||||||
if (sort)
|
if (sort)
|
||||||
while (root->next!=NULL && strcmp(entry->name,root->next->name)>0)
|
while (root->next!=NULL && strcmp(entry->name,root->next->name)>0)
|
||||||
@ -2646,35 +2695,14 @@ static symbol *add_symbol(symbol *root,symbol *entry,int sort)
|
|||||||
memcpy(newsym,entry,sizeof(symbol));
|
memcpy(newsym,entry,sizeof(symbol));
|
||||||
newsym->next=root->next;
|
newsym->next=root->next;
|
||||||
root->next=newsym;
|
root->next=newsym;
|
||||||
if (newsym->vclass == sGLOBAL) {
|
if (newsym->vclass==sGLOBAL)
|
||||||
if ((cache_sym=hashmap_get(&symbol_cache_map, newsym->name))==NULL) {
|
symbol_cache_add(newsym,NULL);
|
||||||
if ((cache_sym=(symbol2 *)malloc(sizeof(symbol2)))==NULL) {
|
|
||||||
error(103);
|
|
||||||
return NULL;
|
|
||||||
} /* if */
|
|
||||||
cache_sym->symbol=newsym;
|
|
||||||
cache_sym->next=NULL;
|
|
||||||
hashmap_put(&symbol_cache_map, newsym->name, cache_sym);
|
|
||||||
} else {
|
|
||||||
if ((new_cache_sym=(symbol2 *)malloc(sizeof(symbol2)))==NULL) {
|
|
||||||
error(103);
|
|
||||||
return NULL;
|
|
||||||
} /* if */
|
|
||||||
new_cache_sym->symbol=newsym;
|
|
||||||
new_cache_sym->next=NULL;
|
|
||||||
while(cache_sym->next!=NULL)
|
|
||||||
cache_sym=cache_sym->next;
|
|
||||||
cache_sym->next=new_cache_sym;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newsym;
|
return newsym;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_symbol(symbol *sym)
|
static void free_symbol(symbol *sym)
|
||||||
{
|
{
|
||||||
arginfo *arg;
|
arginfo *arg;
|
||||||
symbol2 *cache_sym;
|
|
||||||
symbol2 *parent_cache_sym=NULL;
|
|
||||||
|
|
||||||
/* free all sub-symbol allocated memory blocks, depending on the
|
/* free all sub-symbol allocated memory blocks, depending on the
|
||||||
* kind of the symbol
|
* kind of the symbol
|
||||||
@ -2713,24 +2741,8 @@ static void free_symbol(symbol *sym)
|
|||||||
free(sym->refer);
|
free(sym->refer);
|
||||||
if (sym->documentation!=NULL)
|
if (sym->documentation!=NULL)
|
||||||
free(sym->documentation);
|
free(sym->documentation);
|
||||||
if (sym->vclass == sGLOBAL) {
|
if (sym->vclass==sGLOBAL)
|
||||||
cache_sym=hashmap_get(&symbol_cache_map, sym->name);
|
symbol_cache_remove(sym,1);
|
||||||
while (cache_sym!=NULL) {
|
|
||||||
if (cache_sym->symbol!=sym) {
|
|
||||||
parent_cache_sym=cache_sym;
|
|
||||||
cache_sym=cache_sym->next;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parent_cache_sym!=NULL) {
|
|
||||||
parent_cache_sym->next=cache_sym->next;
|
|
||||||
free(cache_sym);
|
|
||||||
} else {
|
|
||||||
hashmap_remove(&symbol_cache_map, sym->name);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(sym);
|
free(sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2833,19 +2845,16 @@ SC_FUNC void delete_symbols(symbol *root,int level,int delete_labels,int delete_
|
|||||||
} /* while */
|
} /* while */
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_FUNC void rename_symbol(symbol *sym, const char *newname)
|
SC_FUNC void rename_symbol(symbol *sym,const char *newname)
|
||||||
{
|
{
|
||||||
char is_global = (sym->vclass == sGLOBAL);
|
int is_global=(sym->vclass==sGLOBAL);
|
||||||
symbol2 *cache_sym;
|
symbol2 *cache_sym;
|
||||||
|
|
||||||
if (is_global) {
|
if (is_global)
|
||||||
cache_sym=hashmap_get(&symbol_cache_map, sym->name);
|
cache_sym=symbol_cache_remove(sym,0);
|
||||||
if (cache_sym!=NULL)
|
strcpy(sym->name,newname);
|
||||||
hashmap_remove(&symbol_cache_map, sym->name); // TODO what if there are multiple symbols with same name and rename happens?
|
if (is_global && cache_sym!=NULL)
|
||||||
}
|
symbol_cache_add(sym,cache_sym);
|
||||||
strcpy(sym->name, newname);
|
|
||||||
if (is_global && cache_sym != NULL)
|
|
||||||
hashmap_put(&symbol_cache_map, sym->name, cache_sym);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int automaton,int *cmptag)
|
static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int automaton,int *cmptag)
|
||||||
@ -2854,14 +2863,14 @@ static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int a
|
|||||||
symbol *sym=root->next;
|
symbol *sym=root->next;
|
||||||
symbol2 *cache_sym=NULL;
|
symbol2 *cache_sym=NULL;
|
||||||
int count=0;
|
int count=0;
|
||||||
char is_global = (root == &glbtab);
|
int is_global=(root==&glbtab);
|
||||||
|
|
||||||
if (is_global) {
|
if (is_global) {
|
||||||
cache_sym=hashmap_get(&symbol_cache_map, name);
|
cache_sym=hashmap_get(&symbol_cache_map,name);
|
||||||
if (cache_sym)
|
if (cache_sym)
|
||||||
sym = cache_sym->symbol;
|
sym=cache_sym->symbol;
|
||||||
else
|
else
|
||||||
sym = NULL;
|
sym=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (sym!=NULL) {
|
while (sym!=NULL) {
|
||||||
@ -2891,9 +2900,9 @@ static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int a
|
|||||||
if (is_global) {
|
if (is_global) {
|
||||||
cache_sym=cache_sym->next;
|
cache_sym=cache_sym->next;
|
||||||
if (cache_sym)
|
if (cache_sym)
|
||||||
sym = cache_sym->symbol;
|
sym=cache_sym->symbol;
|
||||||
else
|
else
|
||||||
sym = NULL;
|
sym=NULL;
|
||||||
} else {
|
} else {
|
||||||
sym=sym->next;
|
sym=sym->next;
|
||||||
}
|
}
|
||||||
@ -2909,7 +2918,7 @@ static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int a
|
|||||||
|
|
||||||
static symbol *find_symbol_child(const symbol *root,const symbol *sym)
|
static symbol *find_symbol_child(const symbol *root,const symbol *sym)
|
||||||
{
|
{
|
||||||
if (sym->child && sym->child->parent == sym)
|
if (sym->child && sym->child->parent==sym)
|
||||||
return sym->child;
|
return sym->child;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1387,9 +1387,9 @@ SC_FUNC void stgwrite(const char *st)
|
|||||||
stgbuf[stgidx++]='\0';
|
stgbuf[stgidx++]='\0';
|
||||||
} else {
|
} else {
|
||||||
len=(stgbuf!=NULL) ? stglen : 0;
|
len=(stgbuf!=NULL) ? stglen : 0;
|
||||||
st_len = strlen(st);
|
st_len=strlen(st);
|
||||||
CHECK_STGBUFFER(len+st_len+1);
|
CHECK_STGBUFFER(len+st_len+1);
|
||||||
memcpy(stgbuf + len, st, st_len + 1); //strcat(stgbuf,st);
|
memcpy(stgbuf+len,st,st_len+1); //strcat(stgbuf,st);
|
||||||
len=len+st_len;
|
len=len+st_len;
|
||||||
stglen=len;
|
stglen=len;
|
||||||
if (len>0 && stgbuf[len-1]=='\n') {
|
if (len>0 && stgbuf[len-1]=='\n') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user