]> Shamusworld >> Repos - rmac/blobdiff - symbol.c
Misc. whitespace cleanups, removal of unneeded code.
[rmac] / symbol.c
index b13ef3c52fb1de59ea871a2f1531029cc83f6b79..2edf9fd2f564066ee0324a4fca2a6909aaae4475 100644 (file)
--- a/symbol.c
+++ b/symbol.c
@@ -11,6 +11,7 @@
 #include "procln.h"
 #include "error.h"
 
+
 // Macros
 #define NBUCKETS 256                                   // Number of hash buckets (power of 2)
 
@@ -34,7 +35,7 @@ static char tdb_text[8] = {
 
 
 //
-// Initialize Symbol Table
+// Initialize symbol table
 //
 void InitSymbolTable(void)
 {
@@ -53,7 +54,7 @@ void InitSymbolTable(void)
 
 
 //
-// Hash the Print Name and Enviroment Number
+// Hash the print name and enviroment number
 //
 int HashSymbol(char * name, int envno)
 {
@@ -90,7 +91,12 @@ SYM * NewSymbol(char * name, int type, int envno)
        symbol->stype  = (BYTE)type;
        symbol->senv   = (WORD)envno;
        symbol->sattr  = 0;
-       symbol->sattre = (rgpu || rdsp ? RISCSYM : 0);
+       // Don't do this, it could be a forward reference!
+//     symbol->sattr  = DEFINED;               // We just defined it...
+       // This is a bad assumption. Not every symbol 1st seen in a RISC section is
+       // a RISC symbol!
+//     symbol->sattre = (rgpu || rdsp ? RISCSYM : 0);
+       symbol->sattre = 0;
        symbol->svalue = 0;
        symbol->sorder = NULL;
        symbol->uid    = currentUID++;
@@ -150,20 +156,22 @@ SYM * lookup(char * name, int type, int envno)
                if (symbol->stype == type                       // Type, envno and name must match
                        && symbol->senv  == envno
                        && *name == *symbol->sname              // Fast check for first character
-                       && !strcmp(name, symbol->sname))
+                       && !strcmp(name, symbol->sname))        // More expensive check
                        break;
 
                symbol = symbol->snext;
        }
 
-       return symbol;                                                  // Return NULL or matching symbol
+       // Return NULL or matching symbol
+       return symbol;
 }
 
 
 //
 // Put symbol on "order-of-declaration" list of symbols
 //
-void sym_decl(SYM * symbol)
+//void sym_decl(SYM * symbol)
+void AddToSymbolOrderList(SYM * symbol)
 {
        if (symbol->sattr & SDECLLIST)
                return;                                                         // Already on list
@@ -183,11 +191,11 @@ void sym_decl(SYM * symbol)
 //
 // Make all referenced, undefined symbols global
 //
-int syg_fix(void)
+void ForceUndefinedSymbolsGlobal(void)
 {
        SYM * sy;
 
-       DEBUG printf("~syg_fix()\n");
+       DEBUG printf("~ForceUndefinedSymbolsGlobal()\n");
 
        // Scan through all symbols;
        // If a symbol is REFERENCED but not DEFINED, then make it global.
@@ -197,8 +205,6 @@ int syg_fix(void)
                        && ((sy->sattr & (REFERENCED | DEFINED)) == REFERENCED))
                        sy->sattr |= GLOBAL;
        }
-
-       return 0;
 }
 
 
@@ -225,10 +231,7 @@ int uc_string(char * s)
 int sy_assign(char * buf, char *(* constr)())
 {
        SYM * sy;
-       int scount;
-       //int i;
-
-       scount = 0;
+       int scount = 0;
 
        if (buf == NULL)
        {
@@ -238,16 +241,16 @@ int sy_assign(char * buf, char *(* constr)())
                {
                        // Essentially the same as 'sym_decl()' above:
                        if (sy->sattr & SDECLLIST)
-                               continue;                // Already on list 
+                               continue;                               // Already on list 
 
-                       sy->sattr |= SDECLLIST;                            // Mark "on the list"
+                       sy->sattr |= SDECLLIST;         // Mark "on the list"
 
                        if (sdecl == NULL)
-                               sdecl = sy;                      // First on decl-list 
+                               sdecl = sy;                             // First on decl-list 
                        else
-                               sdecltail->sdecl = sy;                        // Add to end of list
+                               sdecltail->sdecl = sy;  // Add to end of list
 
-                       sy->sdecl = NULL;                                  // Fix up list's tail
+                       sy->sdecl = NULL;                       // Fix up list's tail
                        sdecltail = sy;
                }
        }
@@ -314,7 +317,6 @@ int symtable(void)
 
        // Allocate storage for list headers and partition all labels.  
        // Throw away macros and macro arguments.
-//     sy = (SYM **)amem((LONG)(128 * sizeof(LONG)));
        sy = (SYM **)malloc(128 * sizeof(LONG));
 
        for(i=0; i<128; ++i)
@@ -328,27 +330,27 @@ int symtable(void)
                        j = *p->sname;
                        r = NULL;
 
-                       if (p->stype != LABEL)
-                               continue;                   // Ignore non-labels
-
-                       if (p->sattre & UNDEF_EQUR)
+                       // Ignore non-labels
+                       if ((p->stype != LABEL) || (p->sattre & UNDEF_EQUR))
                                continue;
 
                        for(q=sy[j]; q!=NULL; q=q->snext)
                        {
                                if (strcmp(p->sname, q->sname) < 0)
                                        break;
-                               else
-                                       r = q;
+
+                               r = q;
                        }
 
                        if (r == NULL)
-                       {                               // Insert at front of list
+                       {
+                               // Insert at front of list
                                p->snext = sy[j];
                                sy[j] = p;
                        }
                        else
-                       {                               // Insert in middle or append to list
+                       {
+                               // Insert in middle or append to list
                                p->snext = r->snext;
                                r->snext = p;
                        }
@@ -445,3 +447,4 @@ int symtable(void)
 
        return 0;
 }
+