Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

sort.c File Reference

#include "lclintMacros.nf"
#include "llbasic.h"
#include "llgrammar.h"
#include "lclscan.h"

Go to the source code of this file.

Defines

#define MAXBUFFLEN   1024
#define DELTA   100
#define NOSORTHANDLE   0
#define HOFSORTHANDLE   1
#define MAX_SORT_DEPTH   10

Functions

void sort_destroyMod (void)
sort sort_makeNoSort (void)
sort sort_makeHOFSort (sort base)
sort sort_makeSort ( ltoken t, lsymbol n)
sort sort_makeSyn (ltoken t, sort s, lsymbol n)
sort sort_makeFormal (sort insort)
sort sort_makeGlobal (sort insort)
sort sort_makeObj (sort sor)
sort sort_makePtr (ltoken t, sort baseSort)
sort sort_makePtrN (sort s, int pointers)
sort sort_makeArr (ltoken t, sort baseSort)
sort sort_makeVec (ltoken t, sort arraySort)
sort sort_makeVal (sort sor)
sort sort_makeImmutable (ltoken t, lsymbol name)
sort sort_makeMutable (ltoken t, lsymbol name)
sort sort_makeStr (ltoken opttagid)
bool sort_updateStr (sort strSort, smemberInfo *info)
sort sort_makeTuple (ltoken t, sort strSort)
sort sort_makeUnion (ltoken opttagid)
bool sort_updateUnion (sort unionSort, smemberInfo *info)
sort sort_makeUnionVal (ltoken t, sort unionSort)
sort sort_makeEnum (ltoken opttagid)
bool sort_updateEnum (sort enumSort, smemberInfo *info)
void sort_init (void)
sort sort_lookupName (lsymbol name)
void sort_printStats (void)
sortNode sort_lookup (sort sor)
sortNode sort_quietLookup (sort sor)
cstring sort_unparse (sort s)
sort sort_getUnderlying (sort s)
bool sort_mutable (sort s)
bool sort_setExporting (bool flag)
bool sort_isValidSort (sort s)
void sort_dump (FILE *f, bool lco)
void sort_import (tsource *imported, ltoken tok, mapping * map)
bool sort_equal (sort *s1, sort *s2)
bool sort_compatible (sort s1, sort s2)
bool sort_compatible_modulo_cstring (sort s1, sort s2)
lsymbol sort_getLsymbol (sort sor)
char* sort_getName (sort s)
cstring sort_unparseName (sort s)
sort sort_fromLsymbol (lsymbol sortid)
bool sort_isHOFSortKind (sort s)

Variables

sort sort_bool
sort sort_capBool
sort sort_int
sort sort_char
sort sort_float
sort sort_double
sort sort_cstring


Define Documentation

#define DELTA   100
 

Definition at line 53 of file sort.c.

#define HOFSORTHANDLE   1
 

Definition at line 59 of file sort.c.

#define MAXBUFFLEN   1024
 

Definition at line 50 of file sort.c.

#define MAX_SORT_DEPTH   10
 

Definition at line 2243 of file sort.c.

#define NOSORTHANDLE   0
 

Definition at line 56 of file sort.c.


Function Documentation

bool sort_compatible ( sort s1,
sort s2 )
 

Definition at line 3017 of file sort.c.

Referenced by checkLclPredicate(), and sort_compatible_modulo_cstring().

03018 {
03019   sort syn1, syn2;
03020  /* later: might consider "char" and enum types the same as "int" */
03021   if (s1 == s2)
03022     return TRUE;
03023  /* handle synonym sorts */
03024   syn1 = sort_getUnderlying (s1);
03025   syn2 = sort_getUnderlying (s2);
03026   if (syn1 == syn2)
03027     return TRUE;
03028   /* makes bool and Bool equal */
03029   return FALSE;
03030 }

bool sort_compatible_modulo_cstring ( sort s1,
sort s2 )
 

Definition at line 3033 of file sort.c.

03034 {
03035  /* like sort_compatible but also handles special cstring inits,
03036     allows the following 2 cases:
03037      char c[] = "abc"; (LHS: char_Obj_Arr, RHS = char_Vec)
03038                        (c as implicitly coerced into c^)
03039      char *d = "abc";  (LHS: char_Obj_Ptr, RHS = char_Vec)
03040                        (d as implicitly coerced into d[]^)
03041                        */
03042   sort syn1, syn2;
03043   if (sort_compatible (s1, s2))
03044     return TRUE;
03045   syn1 = sort_getUnderlying (s1);
03046   syn2 = sort_getUnderlying (s2);
03047   if (sort_cstring == syn2 &&
03048       (syn1 == char_obj_ptrSort || syn1 == char_obj_ArrSort))
03049     return TRUE;
03050   return FALSE;
03051 }

void sort_destroyMod ( void )
 

Definition at line 195 of file sort.c.

00201 {
00202   if (sortTable != NULL)  
00203     {
00204       int i;
00205 
00206       for (i = 0; i < sortTableSize; i++)
00207         {
00208           sortNode_free (sortTable[i]);
00209         }
00210 
00211       nameNode_free (arrayRefNameNode);
00212       nameNode_free (ptr2arrayNameNode);
00213       nameNode_free (deRefNameNode);
00214       nameNode_free (nilNameNode);
00215       nameNode_free (plusNameNode);
00216       nameNode_free (minusNameNode);
00217       nameNode_free (condNameNode);
00218       nameNode_free (eqNameNode);
00219       nameNode_free (neqNameNode);
00220 
00221       sfree (sortTable);
00222       /*@-branchstate@*/
00223     }
00224 }

void sort_dump ( FILE * f,
bool lco )
 

Definition at line 2329 of file sort.c.

Referenced by outputLCSFile().

02330 {
02331   int i;
02332   sortNode s;
02333   smemberInfo *mem;
02334 
02335   fprintf (f, "%s\n", BEGINSORTTABLE);
02336   llassert (sortTable != NULL);
02337 
02338   for (i = 2; i < sortTableSize; i++)
02339     {
02340       /* skips 0 and 1, noSort and HOFSort */
02341       s = sortTable[i];
02342       
02343       /* if (lco && !s.export) continue; */
02344       /* Difficult to keep track of where each op and sort belong to
02345          which LCL type.  Easiest to export them all (even private sorts and
02346          op's) but for checking imported modules, we only use LCL types and
02347          variables to check, i.e., we don't rely on sorts and op's for such
02348          checking. */
02349       
02350       if (s.kind == SRT_NONE)
02351         continue;
02352       
02353       if (lco)
02354         {
02355           fprintf (f, "%%LCL");
02356         }
02357 
02358       if (lsymbol_isDefined (s.name))
02359         {
02360           fprintf (f, "sort %s ", lsymbol_toCharsSafe (s.name));
02361         }
02362       else
02363         {
02364           llcontbug (message ("Invalid sort in sort_dump: sort %d; sortname: %s.  This may result from using .lcs files produced by an old version of LCLint.  Remove the .lcs files, and rerun LCLint.",
02365                               i, lsymbol_toString (s.name)));
02366           fprintf (f, "sort _error_ ");
02367         }
02368       
02369       if (!lco && !s.export)
02370         fprintf (f, "private ");
02371 
02372       /*@-loopswitchbreak@*/
02373       switch (s.kind)
02374         {
02375         case SRT_HOF:
02376           fprintf (f, "hof nil nil\n");
02377           break;
02378         case SRT_PRIM:
02379           if (s.abstract)
02380             fprintf (f, "immutable nil nil\n");
02381           else
02382             fprintf (f, "primitive nil nil\n");
02383           break;
02384         case SRT_OBJ:
02385           if (s.abstract)
02386             fprintf (f, "mutable %s nil\n",
02387                      lsymbol_toCharsSafe (sortTable[s.baseSort].name));
02388           else
02389             fprintf (f, "obj %s nil\n",
02390                      lsymbol_toCharsSafe (sortTable[s.baseSort].name));
02391           break;
02392         case SRT_SYN:
02393           fprintf (f, "synonym %s nil\n",
02394                    lsymbol_toCharsSafe (sortTable[s.baseSort].name));
02395           break;
02396         case SRT_PTR:
02397           fprintf (f, "ptr %s nil\n", lsymbol_toCharsSafe (sortTable[s.baseSort].name));
02398           break;
02399         case SRT_ARRAY:
02400           fprintf (f, "arr %s nil\n",
02401                    lsymbol_toCharsSafe (sortTable[s.baseSort].name));
02402           break;
02403         case SRT_VECTOR:
02404           fprintf (f, "vec %s %s\n",
02405                    lsymbol_toCharsSafe (sortTable[s.baseSort].name),
02406                    lsymbol_toCharsSafe (sortTable[s.objSort].name));
02407           break;
02408         case SRT_STRUCT:
02409           if (s.tag == lsymbol_undefined)
02410             {
02411               /* we need to make up a tag to prevent excessive
02412                  growth of .lcs files when tags are overloaded
02413                  */
02414               llbuglit ("Struct has no tag");
02415             }
02416           else
02417             fprintf (f, "str %s nil\n", lsymbol_toCharsSafe (s.tag));
02418 
02419           for (mem = s.members;
02420                mem != smemberInfo_undefined; mem = mem->next)
02421             {
02422               if (lco)
02423                 fprintf (f, "%%LCL");
02424               fprintf (f, "sort %s strMem %s nil\n", lsymbol_toCharsSafe (mem->name),
02425                        lsymbol_toCharsSafe (sortTable[mem->sort].name));
02426             }
02427           if (lco)
02428             fprintf (f, "%%LCL");
02429           fprintf (f, "sort strEnd nil nil nil\n");
02430           break;
02431         case SRT_UNION:
02432           if (s.tag == lsymbol_undefined)
02433             llbuglit ("Union has no tag");
02434           else
02435             fprintf (f, "union %s nil\n", lsymbol_toCharsSafe (s.tag));
02436           for (mem = s.members;
02437                mem != smemberInfo_undefined; mem = mem->next)
02438             {
02439               if (lco)
02440                 fprintf (f, "%%LCL");
02441               fprintf (f, "sort %s unionMem %s nil\n", lsymbol_toCharsSafe (mem->name),
02442                        lsymbol_toCharsSafe (sortTable[mem->sort].name));
02443             }
02444           if (lco)
02445             fprintf (f, "%%LCL");
02446           fprintf (f, "sort unionEnd nil nil nil\n");
02447           break;
02448         case SRT_ENUM:
02449           if (s.tag == lsymbol_undefined)
02450             {
02451               llbuglit ("Enum has no tag");
02452             }
02453 
02454           fprintf (f, "enum %s nil\n", lsymbol_toCharsSafe (s.tag));
02455 
02456           for (mem = s.members;
02457                mem != smemberInfo_undefined; mem = mem->next)
02458             {
02459               if (lco)
02460                 fprintf (f, "%%LCL");
02461               fprintf (f, "sort %s enumMem nil nil\n", lsymbol_toCharsSafe (mem->name));
02462             }
02463           if (lco)
02464             fprintf (f, "%%LCL");
02465           fprintf (f, "sort enumEnd nil nil nil\n");
02466           break;
02467         case SRT_TUPLE:
02468           fprintf (f, "tup %s nil\n", lsymbol_toCharsSafe (sortTable[s.baseSort].name));
02469           break;
02470         case SRT_UNIONVAL:
02471           fprintf (f, "unionval %s nil\n",
02472                    lsymbol_toCharsSafe (sortTable[s.baseSort].name));
02473           break;
02474         default:
02475           fprintf (f, "sort_dump: unexpected sort: %d", (int)s.kind);
02476         }                       /* switch */
02477       /*@=loopswitchbreak@*/
02478     }
02479 
02480   fprintf (f, "%s\n", SORTTABLEEND);
02481 }

bool sort_equal ( sort * s1,
sort * s2 )
 

Definition at line 2999 of file sort.c.

Referenced by sortSet_member(), and symtable_opsWithLegalDomain().

03000 {
03001   sort syn1, syn2;
03002   if ((s1 != 0) && (s2 != 0))
03003     {
03004       if ((*s1) == (*s2))
03005         return TRUE;
03006      /* handle synonym sorts */
03007       syn1 = sort_getUnderlying (*s1);
03008       syn2 = sort_getUnderlying (*s2);
03009       if (syn1 == syn2)
03010         return TRUE;
03011      /* makes bool and Bool equal */
03012     }
03013   return FALSE;
03014 }

sort sort_fromLsymbol ( lsymbol sortid )
 

Definition at line 3120 of file sort.c.

Referenced by processTraitSortId(), and sigNode_rangeSort().

03121 {
03122  /* like sort_lookupName but creates sort if not already present */
03123   sort sort = sort_lookupName (sortid);
03124   if (sort == NOSORTHANDLE)
03125     sort = sort_makeSort (ltoken_undefined, sortid);
03126   return sort;
03127 }

lsymbol sort_getLsymbol ( sort sor )
 

Definition at line 3054 of file sort.c.

Referenced by checkAndEnterTag(), and symtable_enterType().

03055 {
03056  /*  sortNode sn = sort_lookup (sor); */
03057   sortNode sn = sort_quietLookup (sor);
03058   return sn.name;
03059 }

char * sort_getName ( sort s )
 

Definition at line 3063 of file sort.c.

03064 {
03065   return (lsymbol_toCharsSafe (sort_getLsymbol (s)));
03066 }

sort sort_getUnderlying ( sort s )
 

Definition at line 2265 of file sort.c.

Referenced by makeTypeSpecifier(), sort_compatible(), sort_compatible_modulo_cstring(), sort_equal(), sort_makeFormal(), sort_makeGlobal(), and sort_makeObj().

02266 {
02267   return sort_getUnderlyingAux (s, 0);
02268 }

void sort_import ( tsource * imported,
ltoken tok,
mapping * map )
 

Definition at line 2867 of file sort.c.

Referenced by processImport().

02868 {
02869   /* tok is only used for error message line number */
02870   char *buf, *importfile;
02871   tsource *lclsource;
02872   sort bsort;
02873   lsymbolList slist = lsymbolList_new ();
02874 
02875   buf = tsource_nextLine (imported);
02876 
02877   llassert (buf != NULL);
02878 
02879   importfile = tsource_fileName (imported);
02880 
02881   if (!firstWord (buf, "%LCLSortTable"))
02882     {
02883       lclsource = LCLScanSource ();
02884 
02885       lclfatalerror (tok, message ("Expecting \"%%LCLSortTable\" line "
02886                                    "in import file %s:\n%s",
02887                                    cstring_fromChars (importfile), 
02888                                    cstring_fromChars (buf)));
02889       
02890     }
02891 
02892   for (;;)
02893     {
02894       buf = tsource_nextLine (imported);
02895 
02896       llassert (buf != NULL);
02897 
02898       if (firstWord (buf, "%LCLSortTableEnd"))
02899         {
02900           break;
02901         }
02902       else
02903         { /* a good line, remove %LCL from line first */
02904           if (firstWord (buf, "%LCL"))
02905             {
02906               parseSortLine (buf + 4, tok, imported, map, slist);
02907             }
02908           else
02909             {
02910               lclsource = LCLScanSource ();
02911               lclfatalerror
02912                 (tok, 
02913                  message ("Expecting '%%LCL' prefix in import file %s:\n%s\n",
02914                           cstring_fromChars (importfile), 
02915                           cstring_fromChars (buf)));
02916             }
02917         }
02918     }
02919 
02920   /* now process the smemberInfo in the sort List */
02921   lsymbolList_elements (slist, s)
02922     {
02923       if (s != lsymbol_undefined)
02924         {
02925           sort sor;
02926           sortNode sn;
02927 
02928           sor = sort_lookupName (s);
02929           sn = sort_quietLookup (sor);
02930           
02931           switch (sn.kind)
02932             {
02933             case SRT_ENUM:
02934               {                 /* update the symbol table with members of enum */
02935                 varInfo vi;
02936                 smemberInfo *mlist = sn.members;
02937                 for (; mlist != NULL; mlist = mlist->next)
02938                   {
02939                     /* check that enumeration constants are unique */
02940                     vi = symtable_varInfo (g_symtab, mlist->name);
02941                     if (!varInfo_exists (vi))
02942                       { /* put info into symbol table */
02943                         vi = (varInfo) dmalloc (sizeof (*vi));
02944                         vi->id = ltoken_create (NOTTOKEN, mlist->name);
02945                         vi->kind = VRK_ENUM;
02946                         vi->sort = sor;
02947                         vi->export = TRUE;
02948 
02949                         (void) symtable_enterVar (g_symtab, vi);
02950                         varInfo_free (vi);
02951                       }
02952                     else
02953                       {
02954                         lclplainerror 
02955                           (message ("%s: enum member %s of %s has already been declared",
02956                                     cstring_fromChars (importfile), 
02957                                     lsymbol_toString (mlist->name),
02958                                     lsymbol_toString (sn.name)));
02959                       }
02960                   }
02961                 /*@switchbreak@*/ break;
02962               }
02963             case SRT_STRUCT:
02964             case SRT_UNION:
02965               {
02966                 smemberInfo *mlist = sn.members;
02967 
02968                 for (; mlist != NULL; mlist = mlist->next)
02969                   {
02970                     bsort = sort_lookupName (lsymbol_translateSort (map, mlist->sortname));
02971                     if (sort_isNoSort (bsort))
02972                       {
02973                         lclbug (message ("%s: member %s of %s has unknown sort\n",
02974                                          cstring_fromChars (importfile), 
02975                                          cstring_fromChars (lsymbol_toChars (mlist->name)),
02976                                          cstring_fromChars (lsymbol_toChars (sn.name))));
02977                       }
02978                     else
02979                       {
02980                         mlist->sort = bsort;
02981                       }
02982                   }
02983                 /*@switchbreak@*/ break;
02984               }
02985             default:
02986               lclbug (message ("%s: %s has unexpected sort kind %s",
02987                                cstring_fromChars (importfile), 
02988                                cstring_fromChars (lsymbol_toChars (sn.name)),
02989                                sort_unparseKind (sn.kind)));
02990             }
02991         }
02992     } end_lsymbolList_elements;
02993   
02994   /* list and sorts in it are not used anymore */
02995   lsymbolList_free (slist);
02996 }

void sort_init ( void )
 

Definition at line 1786 of file sort.c.

01798 {
01799   /* on alpha, declaration does not allocate storage */
01800   opFormNode opform;
01801   opFormUnion u;
01802   underscoreSymbol = lsymbol_fromChars ("_");
01803 
01804   /*
01805   ** commonly used data for generating operators 
01806   */
01807   
01808   lsymbol_setbool (lsymbol_fromChars ("bool"));
01809   intToken = ltoken_createType (simpleId, SID_SORT, lsymbol_fromChars ("int"));
01810   
01811   /*
01812   ** __ \eq __: sort, sort -> bool 
01813   */
01814 
01815   u.anyop = ltoken_copy (ltoken_eq);
01816   opform = makeOpFormNode (ltoken_undefined, OPF_MANYOPM, u, ltoken_undefined);
01817   eqNameNode = makeNameNodeForm (opform);
01818   
01819   /*
01820   ** __ \neq __: sort, sort -> bool 
01821   */
01822 
01823   u.anyop = ltoken_copy (ltoken_neq);
01824   opform = makeOpFormNode (ltoken_undefined, OPF_MANYOPM, u, ltoken_undefined);
01825   neqNameNode = makeNameNodeForm (opform);
01826   
01827   /*
01828   **if __ then __ else __: bool, sort, sort -> sort 
01829   */
01830 
01831   opform = makeOpFormNode (ltoken_undefined, OPF_IF, 
01832                            opFormUnion_createMiddle (0), ltoken_undefined);
01833   condNameNode = makeNameNodeForm (opform);
01834   
01835   /* operator: __[__]: arraySort, int -> elementSort_Obj */
01836   u.middle = 1;
01837   opform = makeOpFormNode (ltoken_copy (ltoken_lbracked), OPF_BMMIDDLE, u,
01838                            ltoken_copy (ltoken_rbracket));
01839   arrayRefNameNode = makeNameNodeForm (opform);
01840   
01841   /* operator: __[]: ptrSort -> arraySort */
01842   u.middle = 0;
01843   opform = makeOpFormNode (ltoken_copy (ltoken_lbracked), 
01844                            OPF_BMMIDDLE, u,
01845                            ltoken_copy (ltoken_rbracket));
01846   ptr2arrayNameNode = makeNameNodeForm (opform);
01847   
01848   /* operator: *__ */
01849   u.anyop = ltoken_create (LLT_MULOP, lsymbol_fromChars ("*"));
01850   opform = makeOpFormNode (ltoken_undefined, OPF_ANYOPM, u, ltoken_undefined);
01851   deRefNameNode = makeNameNodeForm (opform);
01852   
01853   /* operator: __ + __ */
01854   u.anyop = ltoken_create (simpleOp, lsymbol_fromChars ("+"));
01855   opform = makeOpFormNode (ltoken_undefined, OPF_MANYOPM, u, ltoken_undefined);
01856   plusNameNode = makeNameNodeForm (opform);
01857   
01858   /* operator: __ - __ */
01859   u.anyop = ltoken_create (simpleOp, lsymbol_fromChars ("-"));
01860   opform = makeOpFormNode (ltoken_undefined, OPF_MANYOPM, u, ltoken_undefined);
01861   minusNameNode = makeNameNodeForm (opform);
01862   
01863   /* operator: NIL */
01864   nilNameNode = (nameNode) dmalloc (sizeof (*nilNameNode));
01865   nilNameNode->isOpId = TRUE;
01866   nilNameNode->content.opid = ltoken_createType (simpleId, SID_OP, 
01867                                                  lsymbol_fromChars ("NIL"));
01868 
01869   noSort.kind = SRT_NONE;
01870   noSort.name = lsymbol_fromChars ("_unknown");;
01871   noSort.tag = lsymbol_undefined;
01872   noSort.baseSort = NOSORTHANDLE;
01873   noSort.objSort = NOSORTHANDLE;
01874   noSort.members = smemberInfo_undefined;
01875   noSort.export = FALSE;
01876   noSort.mutable = FALSE;
01877   noSort.abstract = FALSE;
01878   noSort.imported = FALSE;
01879   noSort.handle = NOSORTHANDLE;
01880   
01881   /*
01882   ** Store the null sort into table, and in the process initialize the sort table. 
01883   ** Must be the first sort_enter so NOSORTHANDLE is truly = 0. Similarly, 
01884   ** for HOFSORTHANDLE = 1.
01885   */
01886   
01887   noSort.handle = sort_enterGlobal (noSort);
01888   (void) sort_enterGlobal (HOFSort); 
01889   
01890   /* Other builtin sorts */
01891   
01892   sort_bool = sort_makeImmutable (ltoken_undefined, lsymbol_fromChars ("bool"));
01893   sort_capBool = sort_makeSortNoOps (ltoken_undefined, lsymbol_fromChars ("Bool"));
01894   
01895   llassert (sortTable != NULL);
01896 
01897   /* make sort_Bool a synonym for sort_bool */
01898   sortTable[sort_capBool].kind = SRT_SYN;
01899   sortTable[sort_capBool].baseSort = sort_bool;
01900   sortTable[sort_capBool].mutable = FALSE;
01901   sortTable[sort_capBool].abstract = TRUE;
01902   
01903   sort_int = sort_makeLiteralSort (ltoken_undefined, 
01904                                    lsymbol_fromChars ("int"));
01905   sort_char = sort_makeLiteralSort (ltoken_undefined,
01906                                     lsymbol_fromChars ("char"));
01907   sort_void = sort_makeLiteralSort (ltoken_undefined,
01908                                     lsymbol_fromChars ("void"));
01909   
01910   /* sort_cstring is char__Vec, for C strings eg: "xyz" */
01911   char_obj_ptrSort = sort_makePtr (ltoken_undefined, sort_char);
01912   char_obj_ArrSort = sort_makeArr (ltoken_undefined, sort_char);
01913   
01914   sort_cstring = sort_makeVal (char_obj_ArrSort);
01915   sort_float = sort_makeLiteralSort (ltoken_undefined, lsymbol_fromChars ("float"));
01916   sort_double = sort_makeLiteralSort (ltoken_undefined, lsymbol_fromChars ("double"));
01917 }

bool sort_isHOFSortKind ( sort s )
 

Definition at line 3130 of file sort.c.

03131 {
03132   sortNode sn = sort_quietLookup (s);
03133   if (sn.kind == SRT_HOF)
03134     return TRUE;
03135   return FALSE;
03136 }

bool sort_isValidSort ( sort s )
 

Definition at line 2318 of file sort.c.

Referenced by makeModifyNodeRef().

02319 {
02320   sortNode sn = sort_quietLookup (s);
02321   sortKind k = sn.kind;
02322   if (k != SRT_NONE && k > SRT_FIRST && k < SRT_LAST)
02323     return TRUE;
02324   else
02325     return FALSE;
02326 }

sortNode sort_lookup ( sort sor )
 

Definition at line 2034 of file sort.c.

Referenced by sort_makeArr(), sort_makeFormal(), sort_makeGlobal(), sort_makePtr(), sort_makeTuple(), sort_makeUnionVal(), sort_makeVec(), sort_updateEnum(), sort_updateStr(), and sort_updateUnion().

02035 {
02036   /* ymtan: can sor be 0 ? */
02037   /* evs --- yup...0 should return noSort ? */
02038   
02039   if (sor > 0U && sor < (unsigned) sortTableSize)
02040     {
02041       llassert (sortTable != NULL);
02042       return sortTable[sor];
02043     }
02044 
02045   llassert (sor == 0);
02046   return noSort;
02047 }

sort sort_lookupName ( lsymbol name )
 

Definition at line 1920 of file sort.c.

Referenced by o_fctInfo(), sort_fromLsymbol(), sort_import(), sort_makeArr(), sort_makeEnum(), sort_makeImmutable(), sort_makeMutable(), sort_makeObj(), sort_makePtr(), sort_makeSort(), sort_makeStr(), sort_makeSyn(), sort_makeTuple(), sort_makeUnion(), sort_makeUnionVal(), and sort_makeVec().

01921 {
01922   long int i;
01923 
01924   if (name == lsymbol_undefined)
01925     {
01926       return NOSORTHANDLE;
01927     }
01928 
01929   llassert (sortTable != NULL);
01930 
01931   for (i = 0; i < sortTableSize; i++)
01932     {
01933       if (sortTable[i].name == name)
01934         {
01935           return i;
01936         }
01937     }
01938 
01939   return NOSORTHANDLE;
01940 }

sort sort_makeArr ( ltoken t,
sort baseSort )
 

Definition at line 707 of file sort.c.

Referenced by sort_init(), and sort_makePtr().

00708 {
00709   sortNode s, outSort, old;
00710   sort handle, vecHandle;
00711   int dim;
00712   lsymbol name;
00713 
00714   s = sort_lookup (baseSort);
00715 
00716   if (s.kind == SRT_HOF)
00717     return baseSort;
00718   if (s.kind == SRT_NONE)
00719     return baseSort;
00720 
00721   if (s.kind != SRT_ARRAY && s.kind != SRT_STRUCT &&
00722       s.kind != SRT_UNION && s.kind != SRT_OBJ)
00723    /* base is not an array, struct or obj.  Need to insert a Obj. */
00724     baseSort = sort_makeObj (baseSort);
00725 
00726   name = sp (sp (underscoreSymbol, sort_getLsymbol (baseSort)),
00727              lsymbol_fromChars ("_Arr"));
00728   handle = sort_lookupName (name);
00729 
00730  /* must not clash with any LSL sorts */
00731   outSort.name = name;
00732   outSort.kind = SRT_ARRAY;
00733   outSort.baseSort = baseSort;
00734   outSort.objSort = NOSORTHANDLE;
00735   outSort.members = smemberInfo_undefined;
00736   outSort.mutable = TRUE;
00737   outSort.export = exporting;
00738   outSort.imported = context_inImport ();
00739   outSort.abstract = FALSE;
00740   outSort.handle = handle;
00741   
00742   if (handle == NOSORTHANDLE)
00743     {
00744       if (sort_isNewEntry (outSort))
00745         {
00746           outSort.handle = handle = sort_enterNew (outSort);
00747 
00748           for (old = outSort, dim = 0;
00749                old.kind == SRT_ARRAY;
00750                dim++, old = sort_lookup (old.baseSort))
00751             {
00752               ;
00753             }
00754 
00755           vecHandle = sort_makeVec (t, handle);
00756           genArrOps (baseSort, handle, dim, vecHandle);
00757         }
00758       else
00759         {
00760           outSort.handle = handle = sort_enterNew (outSort);
00761         }
00762     }
00763   else
00764     {
00765       llassert (sortTable != NULL);
00766 
00767       if (sortTable[handle].kind != SRT_ARRAY)
00768         {
00769           sortError (t, handle, outSort);
00770         }
00771 
00772       smemberInfo_free (outSort.members);
00773     }
00774 
00775   return handle;
00776 }

sort sort_makeEnum ( ltoken opttagid )
 

Definition at line 1467 of file sort.c.

Referenced by checkAndEnterTag(), and makeEnumSpecNode().

01468 {
01469   sortNode outSort;
01470   sort handle;
01471   bool isNew;
01472   lsymbol name;
01473 
01474   llassert (sortTable != NULL);
01475 
01476   if (ltoken_isUndefined (opttagid))
01477     {
01478       opttagid = ltoken_create (simpleId, newEnumTag ());
01479       outSort.realtag = FALSE;
01480     }
01481   else
01482     outSort.realtag = TRUE;
01483   
01484   /* must not clash with any LSL sorts, tag2sortname adds "_" prefix */
01485 
01486   name = sortTag_toSymbol ("Enum", opttagid, &isNew);
01487   handle = sort_lookupName (name);
01488   outSort.name = name;
01489   outSort.kind = SRT_ENUM;
01490   outSort.tag = ltoken_getText (opttagid);
01491   outSort.baseSort = NOSORTHANDLE;
01492   outSort.objSort = NOSORTHANDLE;
01493   outSort.members = smemberInfo_undefined;
01494   outSort.export = exporting;
01495   outSort.mutable = FALSE;
01496   outSort.imported = context_inImport ();
01497   outSort.abstract = FALSE;
01498   outSort.handle = handle;
01499 
01500   if (handle == NOSORTHANDLE)
01501     {
01502       if (sort_isNewEntry (outSort))
01503         {
01504           outSort.handle = handle = sort_enterNew (outSort);
01505         }
01506       else
01507         {
01508           outSort.handle = handle = sort_enterNewForce (outSort);
01509         }
01510     }
01511   else 
01512     {
01513       if (sortTable[handle].kind != SRT_ENUM)
01514         {
01515           sortError (opttagid, handle, outSort);
01516         }
01517 
01518       smemberInfo_free (outSort.members);
01519     }
01520 
01521   return handle;
01522 }

sort sort_makeFormal ( sort insort )
 

Definition at line 489 of file sort.c.

Referenced by enteringClaimScope(), and enteringFcnScope().

00490 {
00491   sortNode s;
00492   sort sor, handle;
00493 
00494   sor = sort_getUnderlying (insort);
00495   handle = sor;
00496   s = sort_lookup (sor);
00497 
00498   switch (s.kind)
00499     {
00500     case SRT_STRUCT:
00501       handle = sort_makeTuple (ltoken_undefined, sor);
00502       break;
00503     case SRT_UNION:
00504       handle = sort_makeUnionVal (ltoken_undefined, sor);
00505       break;
00506     default:
00507       break;
00508     }
00509 
00510   return handle;
00511 }

sort sort_makeGlobal ( sort insort )
 

Definition at line 514 of file sort.c.

Referenced by makeVarDeclarationNode(), and makestrOrUnionNode().

00515 {
00516   /* Make a Obj if not an array or a struct */
00517   sortNode s;
00518   sort sor, handle;
00519   sor = sort_getUnderlying (insort);
00520   handle = sor;
00521   s = sort_lookup (sor);
00522 
00523   switch (s.kind)
00524     {
00525     case SRT_ARRAY:
00526     case SRT_STRUCT:
00527     case SRT_UNION:
00528     case SRT_HOF:
00529     case SRT_NONE:
00530       break;
00531     case SRT_VECTOR:
00532     case SRT_TUPLE:
00533     case SRT_UNIONVAL:
00534       llcontbuglit ("sort_makeGlobal: can't make vectors, tuples, or unionvals global");
00535       break;
00536     default:
00537       handle = sort_makeObj (sor);
00538       break;
00539     }
00540   return handle;
00541 }

sort sort_makeHOFSort ( sort base )
 

Definition at line 233 of file sort.c.

Referenced by typeExpr2ptrSort().

00234 {
00235   sortNode outSort;
00236   sort handle;
00237 
00238   outSort.kind = SRT_HOF;
00239   outSort.name = cstring_toSymbol (message ("_HOF_sort_%d", sortTableSize));
00240   outSort.tag = lsymbol_undefined;
00241   outSort.baseSort = base;
00242   outSort.objSort = NOSORTHANDLE;
00243   outSort.members = smemberInfo_undefined;
00244   outSort.export = exporting;
00245   outSort.imported = context_inImport ();
00246   outSort.mutable = FALSE;
00247   outSort.abstract = FALSE;
00248 
00249   llassert (sortTable != NULL);
00250 
00251   outSort.handle = handle = sortTableSize;
00252   sortTable[handle] = outSort;
00253 
00254   sortTableSize++;
00255   return handle;
00256 }

sort sort_makeImmutable ( ltoken t,
lsymbol name )
 

Definition at line 910 of file sort.c.

Referenced by makeAbstractNode(), sort_init(), and sort_makeMutable().

00911 {
00912   sortNode outSort;
00913   sort handle;
00914 
00915   handle = sort_lookupName (name);
00916 
00917   outSort.kind = SRT_PRIM;
00918   outSort.name = name;
00919   outSort.baseSort = NOSORTHANDLE;
00920   outSort.objSort = NOSORTHANDLE;
00921   outSort.members = smemberInfo_undefined;
00922   outSort.export = exporting;
00923   outSort.mutable = FALSE;
00924   outSort.imported = context_inImport ();
00925   outSort.abstract = TRUE;
00926   outSort.handle = handle;
00927 
00928   if (handle == NOSORTHANDLE)
00929     {
00930       outSort.handle = handle = sort_enterNew (outSort);
00931       overloadSizeof (handle);
00932     }
00933   else
00934     {                           /* complain */
00935       llassert (sortTable != NULL);
00936 
00937       if ((sortTable[handle].kind != SRT_PRIM) &&
00938           (sortTable[handle].abstract) &&
00939           (!sortTable[handle].mutable))
00940         {
00941           sortError (t, handle, outSort);
00942         }
00943 
00944       smemberInfo_free (outSort.members);
00945     }
00946 
00947   return handle;
00948 }

sort sort_makeMutable ( ltoken t,
lsymbol name )
 

Definition at line 951 of file sort.c.

Referenced by makeAbstractNode().

00952 {
00953   sort immutable_old, handle, baseSort;
00954   lsymbol objName;
00955 
00956   immutable_old = sort_lookupName (name);
00957 
00958  /* First generate the value sort */
00959   baseSort = sort_makeImmutable (t, name);
00960 
00961   llassert (sortTable != NULL);
00962 
00963   /* to prevent duplicate error messages */
00964   if (immutable_old != NOSORTHANDLE &&
00965       (sortTable[baseSort].kind != SRT_PRIM) &&
00966       (sortTable[baseSort].abstract) &&
00967       (!sortTable[baseSort].mutable))
00968     {
00969      /* already complained */
00970       handle = NOSORTHANDLE;
00971     }
00972   else
00973     {                           /* sort_makeImmutable must have succeeded */
00974       sortNode outSort;
00975 
00976      /* must not clash with any LSL sorts */
00977       objName = sp (sp (underscoreSymbol, name),
00978                     lsymbol_fromChars ("_Obj"));
00979       handle = sort_lookupName (objName);
00980 
00981       outSort.kind = SRT_OBJ;
00982       outSort.name = objName;
00983       outSort.tag = lsymbol_undefined;
00984       outSort.baseSort = baseSort;
00985       outSort.objSort = NOSORTHANDLE;
00986       outSort.members = smemberInfo_undefined;
00987       outSort.mutable = TRUE;
00988       outSort.export = exporting;
00989       outSort.imported = context_inImport ();
00990       outSort.abstract = TRUE;
00991       outSort.handle = handle;
00992 
00993       if (handle == NOSORTHANDLE)
00994         {
00995           if (sort_isNewEntry (outSort))
00996             {
00997               outSort.handle = handle = sort_enterNew (outSort);
00998             }
00999           else
01000             {
01001               handle = sort_enterNew (outSort);
01002             }
01003         }
01004       else 
01005         {
01006           llassert (sortTable != NULL);
01007 
01008           if ((sortTable[handle].kind != SRT_OBJ) 
01009               && sortTable[handle].abstract
01010               && sortTable[handle].mutable)
01011             {
01012               sortError (t, handle, outSort);
01013             }
01014 
01015           smemberInfo_free (outSort.members);
01016         }
01017     }
01018   return handle;
01019 }

sort sort_makeNoSort ( void )
 

Definition at line 227 of file sort.c.

Referenced by checkAndEnterTag(), lclTypeSpecNode2sort(), makeArrayNode(), makeCTypesNode(), makeEnumSpecNode2(), makeForwardstrOrUnionNode(), makeFunctionNode(), makeIfTermNode(), makeInfixTermNode(), makeLetDeclNode(), makeLiteralTermNode(), makeMapTermNode(), makeMatchedNode(), makeOpCallTermNode(), makePointerNode(), makePostfixTermNode2(), makePrefixTermNode(), makeSelectTermNode(), makeSimpleTermNode(), makeSizeofTermNode(), makeSqBracketedNode(), makeTypeExpr(), makeTypeSpecifier(), makeUnchangedTermNode1(), makeUnchangedTermNode2(), makeVarNode(), o_fctInfo(), pushInfixOpPartNode(), and sigNode_rangeSort().

00228 {
00229   return NOSORTHANDLE;
00230 }

sort sort_makeObj ( sort sor )
 

Definition at line 544 of file sort.c.

Referenced by makeModifyNodeRef(), makeVarNode(), sort_makeArr(), sort_makeGlobal(), and sort_makePtr().

00545 {
00546   sortNode baseSortNode, outSort;
00547   sort baseSort, handle;
00548   lsymbol name;
00549 
00550  /* skip the synonym sort */
00551   baseSort = sort_getUnderlying (sor);
00552   baseSortNode = sort_quietLookup (baseSort);
00553   switch (baseSortNode.kind)
00554     {
00555     case SRT_HOF:
00556     case SRT_NONE:
00557       return baseSort;
00558     case SRT_VECTOR:
00559       if (baseSortNode.objSort != 0)
00560         return baseSortNode.objSort;
00561       else                      /* must have well-defined objSort field */
00562         {
00563           llcontbuglit ("sort_makeObj: Inconsistent vector reps:invalid objSort field");
00564           return baseSort;
00565         }
00566     case SRT_TUPLE:
00567     case SRT_UNIONVAL:
00568      /* need to map *_Struct_Tuple to *_Struct and *_Union_UnionVal to
00569       *_Union, according to sort naming conventions */
00570       if (baseSortNode.baseSort != NOSORTHANDLE)
00571        /* for tuples and unionvals, baseSort field keeps the map from
00572           value sort to obj sort. */
00573         return baseSortNode.baseSort;
00574       else                      /* valid tuples and unionvals must have baseSort fields */
00575         {
00576           llcontbuglit ("sort_makeObj: Inconsistent tuples or unionvals reps: invalid baseSort field");
00577           return baseSort;
00578         }
00579     default:
00580       name = sp (sp (underscoreSymbol, sort_getLsymbol (baseSort)),
00581                  lsymbol_fromChars ("_Obj"));
00582       handle = sort_lookupName (name);
00583 
00584       outSort.kind = SRT_OBJ;
00585       /* must not clash with any LSL sorts */
00586       outSort.name = name;
00587       outSort.tag = lsymbol_undefined;
00588       outSort.baseSort = baseSort;
00589       outSort.objSort = NOSORTHANDLE;
00590       outSort.members = smemberInfo_undefined;
00591       outSort.mutable = TRUE;
00592       outSort.export = exporting;
00593       outSort.abstract = FALSE;
00594       outSort.handle = handle;
00595       outSort.imported = TRUE;
00596 
00597       if (handle == NOSORTHANDLE)
00598         {
00599           if (sort_isNewEntry (outSort))
00600             {
00601               outSort.handle = handle = sort_enterNew (outSort);
00602             }
00603           else
00604             {
00605               outSort.handle = handle = sort_enterNew (outSort);
00606             }
00607         }
00608       else
00609         {
00610           llassert (sortTable != NULL);
00611 
00612           if (sortTable[handle].kind != SRT_OBJ)
00613             {
00614               sortError (ltoken_undefined, handle, outSort);
00615             }
00616 
00617           smemberInfo_free (outSort.members);
00618         }
00619 
00620       return handle;
00621     }
00622 }

sort sort_makePtr ( ltoken t,
sort baseSort )
 

Definition at line 625 of file sort.c.

Referenced by sort_init().

00626 {
00627   sortNode s, outSort;
00628   sort handle, arrayHandle;
00629   lsymbol name;
00630 
00631   s = sort_lookup (baseSort);
00632 
00633   if (s.kind == SRT_HOF)
00634     {
00635       return baseSort;
00636     }
00637   if (s.kind == SRT_NONE)
00638     {
00639       return baseSort;
00640     }
00641 
00642   if (s.kind != SRT_ARRAY && s.kind != SRT_STRUCT &&
00643       s.kind != SRT_UNION)
00644     /* && s.kind != SRT_OBJ) */
00645     /* base is not an SRT_ARRAY, struct or union.  Need to insert a obj. */
00646     baseSort = sort_makeObj (baseSort);
00647   
00648   name = sp (sp (underscoreSymbol, sort_getLsymbol (baseSort)),
00649              lsymbol_fromChars ("_Ptr"));
00650   handle = sort_lookupName (name);
00651   
00652   outSort.kind = SRT_PTR;
00653   outSort.name = name;
00654   outSort.tag = lsymbol_undefined;
00655   outSort.baseSort = baseSort;
00656   outSort.objSort = NOSORTHANDLE;
00657   outSort.members = smemberInfo_undefined;
00658   outSort.mutable = FALSE;
00659   outSort.export = exporting;
00660   outSort.imported = context_inImport ();
00661   outSort.abstract = FALSE;
00662   outSort.handle = handle;
00663   
00664   if (handle == NOSORTHANDLE)
00665     {
00666       if (sort_isNewEntry (outSort))
00667         {
00668           outSort.handle = handle = sort_enterNew (outSort);
00669           arrayHandle = sort_makeArr (t, baseSort);
00670           genPtrOps (baseSort, handle, arrayHandle);
00671         }
00672       else
00673         {
00674           outSort.handle = handle = sort_enterNew (outSort);
00675         }
00676     }
00677   else
00678     {
00679       llassert (sortTable != NULL);
00680 
00681       if (sortTable[handle].kind != SRT_PTR)
00682         {
00683           sortError (t, handle, outSort);
00684         }
00685       smemberInfo_free (outSort.members);
00686     }
00687   return handle;
00688 }

sort sort_makePtrN ( sort s,
int pointers )
 

Definition at line 691 of file sort.c.

Referenced by lclTypeSpecNode2sort().

00692 {
00693   llassert (pointers >= 0);
00694 
00695   if (pointers == 0)
00696     {
00697       return s;
00698     }
00699   else
00700     {
00701       return sort_makePtrN (sort_makePtr (ltoken_undefined, s), 
00702                             pointers - 1);
00703     }
00704 }

sort sort_makeSort ( ltoken t,
lsymbol n )
 

Definition at line 356 of file sort.c.

Referenced by sort_fromLsymbol().

00357 {
00358   /*
00359   ** Expects n to be a new sort.
00360   ** Generate a sort with the given name.  Useful for LSL sorts. 
00361   */
00362 
00363   sort handle = sort_lookupName (n);
00364 
00365   if (handle == NOSORTHANDLE)
00366     {
00367       sortNode outSort;
00368 
00369       outSort.handle = handle;      
00370       outSort.kind = SRT_PRIM;
00371       outSort.name = n;
00372       outSort.tag = lsymbol_undefined;
00373       outSort.baseSort = NOSORTHANDLE;
00374       outSort.objSort = NOSORTHANDLE;
00375       outSort.members = smemberInfo_undefined;
00376       outSort.export = exporting;
00377       outSort.mutable = FALSE;
00378       outSort.imported = context_inImport ();
00379       outSort.abstract = FALSE;
00380 
00381       /* Put into sort table, sort_enter checks for duplicates. */
00382       outSort.handle = handle = sort_enterNew (outSort);
00383     }
00384   else
00385     {
00386       /* don't override old info */
00387      ;
00388     }
00389 
00390   return handle;
00391 }

sort sort_makeStr ( ltoken opttagid )
 

Definition at line 1022 of file sort.c.

Referenced by checkAndEnterTag(), makeForwardstrOrUnionNode(), and makestrOrUnionNode().

01023 {
01024   sortNode outSort;
01025   sort handle;
01026   bool isNewTag;
01027   lsymbol name;
01028 
01029   /* must not clash with any LSL sorts, tag2sortname adds "_" prefix */
01030   /* isNewTag true means that the name generated is new */
01031 
01032   if (ltoken_isUndefined (opttagid))
01033     {
01034       opttagid = ltoken_create (simpleId, newStructTag ());
01035 
01036       outSort.realtag = FALSE;
01037     }
01038   else
01039     {
01040       outSort.realtag = TRUE;
01041     }
01042   
01043   name = sortTag_toSymbol ("Struct", opttagid, &isNewTag);
01044   
01045   llassert (sortTable != NULL);
01046   handle = sort_lookupName (name);
01047   outSort.name = name;
01048   outSort.kind = SRT_STRUCT;
01049   outSort.tag = ltoken_getText (opttagid);
01050   outSort.baseSort = NOSORTHANDLE;
01051   outSort.objSort = NOSORTHANDLE;
01052   outSort.members = smemberInfo_undefined;
01053   outSort.export = exporting;
01054   outSort.mutable = TRUE;
01055   outSort.imported = context_inImport ();
01056   outSort.abstract = FALSE;
01057   outSort.handle = handle;
01058 
01059   if (handle == NOSORTHANDLE)
01060     {
01061       if (sort_isNewEntry (outSort))
01062         {
01063           outSort.handle = handle = sort_enterNew (outSort);
01064         }
01065       else
01066         {
01067           outSort.handle = handle = sort_enterNewForce (outSort);
01068         }
01069     }
01070   else 
01071     {
01072       if (sortTable[handle].kind != SRT_STRUCT)
01073         {
01074           sortError (opttagid, handle, outSort);
01075         }
01076 
01077       smemberInfo_free (outSort.members);
01078     }
01079 
01080   return handle;
01081 }

sort sort_makeSyn ( ltoken t,
sort s,
lsymbol n )
 

Definition at line 439 of file sort.c.

Referenced by declareForwardType().

00440 {
00441   /* make a synonym sort with name n that is == to sort s */
00442   /* expect n to be a new sort name */
00443   sortNode outSort;
00444   sort handle;
00445   /* must not clash with any LSL sorts */
00446   lsymbol newname = sp (underscoreSymbol, n);
00447   
00448   if (n == lsymbol_undefined)
00449     {
00450       llbuglit ("sort_makeSyn: synonym must have name");
00451     }
00452 
00453   handle = sort_lookupName (newname);
00454 
00455   outSort.kind = SRT_SYN;
00456   outSort.name = newname;
00457   outSort.baseSort = s;
00458   outSort.objSort = NOSORTHANDLE;
00459   /* info is not duplicated */
00460   outSort.tag = lsymbol_undefined;
00461   outSort.members = smemberInfo_undefined;
00462   outSort.export = exporting;
00463   outSort.mutable = FALSE;
00464   outSort.imported = context_inImport ();
00465   outSort.abstract = FALSE;
00466   outSort.handle = handle;
00467 
00468   if (handle == NOSORTHANDLE)
00469     {
00470       outSort.handle = handle = sort_enterNew (outSort);
00471       /* No operators to generate for synonyms */
00472     }
00473   else
00474     {
00475       llassert (sortTable != NULL);
00476       
00477       if (sortTable[handle].kind != SRT_SYN)
00478         {
00479           sortError (t, handle, outSort);
00480         }
00481 
00482       smemberInfo_free (outSort.members);
00483     }
00484 
00485   return handle;
00486 }

sort sort_makeTuple ( ltoken t,
sort strSort )
 

Definition at line 1109 of file sort.c.

Referenced by sort_makeFormal(), sort_makeVal(), and sort_updateStr().

01110 {
01111   sort handle;
01112   sortNode outSort, s = sort_lookup (strSort);
01113   lsymbol name;
01114 
01115   if (s.kind != SRT_STRUCT)
01116     {
01117       llfatalbug (message ("sort_makeTuple: Only structs can become tuples: given sort is %s",
01118                            sort_unparseKind (s.kind)));
01119     }
01120 
01121   name = sp (s.name, lsymbol_fromChars ("_Tuple"));
01122   llassert (sortTable != NULL);
01123   handle = sort_lookupName (name);
01124 
01125   outSort.kind = SRT_TUPLE;
01126   outSort.name = name;
01127   outSort.tag = s.tag;
01128   outSort.realtag = s.realtag;
01129   outSort.baseSort = strSort;
01130   outSort.objSort = NOSORTHANDLE;
01131   outSort.members = smemberInfo_undefined;
01132   outSort.export = exporting;
01133   outSort.abstract = FALSE;
01134   outSort.imported = context_inImport ();
01135   outSort.mutable = FALSE;
01136   outSort.handle = handle;
01137 
01138   if (handle == NOSORTHANDLE)
01139     {
01140       if (sort_isNewEntry (outSort))
01141         {
01142           outSort.handle = handle = sort_enterNew (outSort);
01143 
01144           sort_addTupleMembers (handle, strSort);
01145           genTupleOps (handle);
01146         }
01147       else
01148         {
01149           outSort.handle = handle = sort_enterNew (outSort);
01150         }
01151     }
01152   else 
01153     {
01154       if (sortTable[handle].kind != SRT_TUPLE)
01155         {
01156           sortError (t, handle, outSort);
01157         }
01158 
01159       smemberInfo_free (outSort.members);
01160     }
01161 
01162   return handle;
01163 }

sort sort_makeUnion ( ltoken opttagid )
 

Definition at line 1297 of file sort.c.

Referenced by checkAndEnterTag(), makeForwardstrOrUnionNode(), and makestrOrUnionNode().

01298 {
01299   sortNode outSort;
01300   sort handle;
01301   bool isNewTag; 
01302   lsymbol name;
01303 
01304   /* must not clash with any LSL sorts, tag2sortname adds "_" prefix */
01305   /* isNewTag true means that the name generated is new */
01306 
01307   if (ltoken_isUndefined (opttagid))
01308     {
01309       opttagid = ltoken_create (simpleId, newUnionTag ());
01310       outSort.realtag = FALSE;
01311     }
01312   else
01313     outSort.realtag = TRUE;
01314 
01315   llassert (sortTable != NULL);
01316   name = sortTag_toSymbol ("Union", opttagid, &isNewTag);
01317   handle = sort_lookupName (name);
01318   outSort.name = name;
01319   outSort.kind = SRT_UNION;
01320   outSort.tag = ltoken_getText (opttagid);
01321   outSort.baseSort = NOSORTHANDLE;
01322   outSort.objSort = NOSORTHANDLE;
01323   outSort.members = smemberInfo_undefined;
01324   outSort.export = exporting;
01325   outSort.mutable = TRUE;
01326   outSort.imported = context_inImport ();
01327   outSort.abstract = FALSE;
01328   outSort.handle = handle;
01329   
01330   if (handle == NOSORTHANDLE)
01331     {
01332       if (sort_isNewEntry (outSort))
01333         {
01334           outSort.handle = handle = sort_enterNew (outSort);
01335         }
01336       else
01337         {
01338           outSort.handle = handle = sort_enterNewForce (outSort);
01339         }
01340     }
01341   else 
01342     {
01343       if (sortTable[handle].kind != SRT_UNION)
01344         {
01345           sortError (opttagid, handle, outSort);
01346         }
01347 
01348       smemberInfo_free (outSort.members);
01349     }
01350 
01351   return handle;
01352 }

sort sort_makeUnionVal ( ltoken t,
sort unionSort )
 

Definition at line 1382 of file sort.c.

Referenced by sort_makeFormal(), sort_makeVal(), and sort_updateUnion().

01383 {
01384   sort handle;
01385   sortNode outSort, s = sort_lookup (unionSort);
01386   lsymbol name;
01387 
01388   if (s.kind != SRT_UNION)
01389     {
01390       llfatalbug (message ("sort_makeUnion: only unions can become unionVals: given sort is: %s",
01391                            sort_unparseKind (s.kind)));
01392     }
01393 
01394   llassert (sortTable != NULL);
01395 
01396   name = sp (s.name, lsymbol_fromChars ("_UnionVal"));
01397   handle = sort_lookupName (name);
01398 
01399   outSort.kind = SRT_UNIONVAL;
01400   outSort.name = name;
01401   outSort.tag = s.tag;
01402   outSort.realtag = s.realtag;
01403   outSort.baseSort = unionSort;
01404   outSort.objSort = NOSORTHANDLE;
01405   outSort.members = smemberInfo_undefined;
01406   outSort.export = exporting;
01407   outSort.abstract = FALSE;
01408   outSort.imported = context_inImport ();
01409   outSort.mutable = FALSE;
01410   outSort.handle = handle;
01411 
01412   if (handle == NOSORTHANDLE)
01413     {
01414       if (sort_isNewEntry (outSort))
01415         {
01416           outSort.handle = handle = sort_enterNew (outSort);
01417 
01418           /* Add members to the unionVal's. */
01419           /* same as structs and tuples */
01420 
01421           sort_addTupleMembers (handle, unionSort);
01422           genUnionOps (handle);
01423         }
01424       else
01425         {
01426           outSort.handle = handle = sort_enterNew (outSort);
01427         }
01428     }
01429   else 
01430     {
01431       if (sortTable[handle].kind != SRT_UNIONVAL)
01432         {
01433           sortError (t, handle, outSort);
01434         }
01435 
01436       smemberInfo_free (outSort.members);
01437     }
01438 
01439   return handle;
01440 }

sort sort_makeVal ( sort sor )
 

Definition at line 858 of file sort.c.

Referenced by makeVarNode(), sort_init(), and sort_makeVec().

00859 {
00860   sort retSort = sor;
00861   sortNode rsn, s;
00862 
00863   llassert (sortTable != NULL);
00864   s = sort_quietLookup (sor);
00865 
00866   switch (s.kind)
00867     {
00868     case SRT_PRIM:
00869     case SRT_ENUM:
00870     case SRT_PTR:
00871     case SRT_TUPLE:
00872     case SRT_UNIONVAL:
00873     case SRT_VECTOR:
00874     case SRT_HOF:
00875     case SRT_NONE:
00876      /* Do nothing for basic types and pointers. */
00877       retSort = sor;
00878       break;
00879     case SRT_SYN:
00880       return sort_makeVal (sortTable[sor].baseSort);
00881     case SRT_OBJ:
00882      /* Strip out the last Obj's */
00883       if (s.baseSort == NOSORTHANDLE)
00884         {
00885           llbuglit ("sort_makeVal: expecting a base sort for Obj");
00886         }
00887       retSort = s.baseSort;
00888       break;
00889     case SRT_ARRAY:
00890       retSort = sort_makeVec (ltoken_undefined, sor);
00891       break;
00892     case SRT_STRUCT:
00893       retSort = sort_makeTuple (ltoken_undefined, sor);
00894       break;
00895     case SRT_UNION:
00896       retSort = sort_makeUnionVal (ltoken_undefined, sor);
00897       break;
00898     default:
00899       llbuglit ("sort_makeVal: invalid sort kind");
00900     }
00901   rsn = sort_quietLookup (retSort);
00902   if (rsn.kind == SRT_NONE)
00903     {
00904       llfatalbug (message ("sort_makeVal: invalid return sort kind: %d", (int)rsn.kind));
00905     }
00906   return retSort;
00907 }

sort sort_makeVec ( ltoken t,
sort arraySort )
 

Definition at line 779 of file sort.c.

Referenced by sort_makeArr(), and sort_makeVal().

00780 {
00781   sortNode s, outSort, old;
00782   sort baseSort, handle, elementSort;
00783   int dim;                      /* array dimension count. */
00784   lsymbol name;
00785 
00786   s = sort_lookup (arraySort);
00787 
00788   if (s.kind == SRT_HOF)
00789     return arraySort;
00790   if (s.kind == SRT_NONE)
00791     return arraySort;
00792 
00793   if (s.kind != SRT_ARRAY)
00794     {
00795       llbug (message ("sort_makeVec: only arrays can become vectors: given sort is %s",
00796                       sort_unparseKind (s.kind)));
00797     }
00798 
00799   if (s.baseSort == NOSORTHANDLE)
00800     llbuglit ("sort_makeVec: arrays must have base (element) sort");
00801 
00802  /* Vectors return "values", so make array elements values. */
00803 
00804   baseSort = s.baseSort;
00805   elementSort = sort_makeVal (baseSort);
00806 
00807   name = sp (sp (underscoreSymbol, sort_getLsymbol (elementSort)),
00808              lsymbol_fromChars ("_Vec"));
00809   handle = sort_lookupName (name);
00810 
00811   outSort.baseSort = elementSort;
00812   outSort.name = name;
00813   outSort.objSort = arraySort;
00814   outSort.kind = SRT_VECTOR;
00815   outSort.members = smemberInfo_undefined;
00816   outSort.mutable = FALSE;
00817   outSort.export = exporting;
00818   outSort.imported = context_inImport ();
00819   outSort.abstract = FALSE;
00820   outSort.handle = handle;
00821 
00822   if (handle == NOSORTHANDLE)
00823     {
00824       if (sort_isNewEntry (outSort))
00825         {
00826           outSort.handle = handle = sort_enterNew (outSort);
00827 
00828           for (old = outSort, dim = 0;
00829                old.kind == SRT_VECTOR;
00830                dim++, old = sort_lookup (old.baseSort))
00831             {
00832               ;
00833             }
00834 
00835           genVecOps (elementSort, handle, dim);
00836         }
00837       else
00838         {
00839           outSort.handle = handle = sort_enterNew (outSort);
00840         }
00841     }
00842   else
00843     {
00844       llassert (sortTable != NULL);
00845 
00846       if (sortTable[handle].kind != SRT_VECTOR)
00847         {
00848           sortError (t, handle, outSort);
00849         }
00850 
00851       smemberInfo_free (outSort.members);
00852     }
00853 
00854   return handle;
00855 }

bool sort_mutable ( sort s )
 

Definition at line 2290 of file sort.c.

Referenced by makeModifyNodeRef(), and makeUnchangedTermNode2().

02291 {
02292  /* if s is not a valid sort, then returns false */
02293   sortNode sn = sort_quietLookup (s);
02294   if (sn.mutable)
02295     return TRUE;
02296   return FALSE;
02297 }

void sort_printStats ( void )
 

Definition at line 2026 of file sort.c.

02027 {
02028   /* only for debugging */
02029   printf ("sortTableSize = %d; sortTableAlloc = %d\n", sortTableSize,
02030           sortTableAlloc);
02031 }

sortNode sort_quietLookup ( sort sor )
 

Definition at line 2050 of file sort.c.

Referenced by MAX_SORT_DEPTH(), sort_getLsymbol(), sort_import(), sort_isHOFSortKind(), sort_isValidSort(), sort_makeObj(), sort_makeVal(), sort_mutable(), and sort_unparse().

02051 {
02052   /* ymtan: can sor be 0 ? */
02053   if (sor > 0U && sor < (unsigned) sortTableSize)
02054     {
02055       llassert (sortTable != NULL);
02056       return (sortTable[sor]);
02057     }
02058   else
02059     {
02060       return noSort;
02061     }
02062 }

bool sort_setExporting ( bool flag )
 

Definition at line 2300 of file sort.c.

Referenced by processImport(), and symtable_export().

02301 {
02302   bool old;
02303   old = exporting;
02304   exporting = flag;
02305   return old;
02306 }

cstring sort_unparse ( sort s )
 

Definition at line 2099 of file sort.c.

Referenced by makeConstDeclarationNode(), and makeVarDeclarationNode().

02100 {
02101  /* printing routine for sorts */
02102   sortNode sn;
02103   lsymbol name;
02104 
02105   sn = sort_quietLookup (s);
02106   name = sn.name;
02107 
02108   switch (sn.kind)
02109     {
02110     case SRT_NONE:
02111       if (name == lsymbol_undefined)
02112         {
02113           return cstring_makeLiteral ("_unknown");
02114         }
02115 
02116       return (cstring_fromCharsNew (lsymbol_toChars (name)));
02117     case SRT_HOF:
02118       return cstring_makeLiteral ("procedural");
02119     case SRT_PRIM:
02120       return (cstring_fromCharsNew (lsymbol_toChars (name)));
02121     case SRT_SYN:
02122       return (cstring_fromCharsNew (lsymbol_toChars (name)));
02123 
02124     case SRT_PTR:
02125       return (message ("%q *", sort_unparse (sort_makeVal (sn.baseSort))));
02126     case SRT_OBJ:
02127       return (message ("obj %q", sort_unparse (sn.baseSort)));
02128     case SRT_ARRAY:
02129       return (message ("array of %q", sort_unparse (sort_makeVal (sn.baseSort))));
02130     case SRT_VECTOR:
02131       return (message ("vector of %q", sort_unparse (sn.baseSort)));
02132     case SRT_TUPLE:
02133       if (sn.tag != lsymbol_undefined && sn.realtag)
02134         {
02135           return (message ("struct %s", cstring_fromChars (lsymbol_toChars (sn.tag))));
02136         }
02137       else
02138         {
02139           return (message ("struct {%q}", printStructMembers (sn.members)));
02140         }
02141     case SRT_UNIONVAL:
02142       if (sn.tag != lsymbol_undefined && sn.realtag)
02143         {
02144           return (message ("union %s", cstring_fromChars (lsymbol_toChars (sn.tag))));
02145         }
02146       else
02147         {
02148           return (message ("union {%q}", printStructMembers (sn.members)));
02149         }
02150     case SRT_ENUM:
02151       if (sn.tag != lsymbol_undefined && sn.realtag)
02152         {
02153           return (message ("enum %s", cstring_fromChars (lsymbol_toChars (sn.tag))));
02154         }
02155       else
02156         {
02157           return (message ("enum {%q}", printEnumMembers (sn.members)));
02158         }
02159     case SRT_STRUCT:
02160       if (sn.tag != lsymbol_undefined && sn.realtag)
02161         {
02162           return (message ("obj struct %s", cstring_fromChars (lsymbol_toChars (sn.tag))));
02163         }
02164       else
02165         {
02166           return (message ("obj struct {%q}", printStructMembers (sn.members)));
02167         }
02168     case SRT_UNION:
02169       if (sn.tag != lsymbol_undefined && sn.realtag)
02170         {
02171           return (message ("obj union %s", cstring_fromChars (lsymbol_toChars (sn.tag))));
02172         }
02173       else
02174         {
02175           return (message ("obj union {%q}", printStructMembers (sn.members)));
02176         }
02177     default:
02178       return (cstring_makeLiteral ("illegal"));
02179     }
02180 }

cstring sort_unparseName ( sort s )
 

Definition at line 3069 of file sort.c.

Referenced by signNode_unparse().

03070 {
03071     return (cstring_fromChars (sort_getName (s)));
03072 }

bool sort_updateEnum ( sort enumSort,
smemberInfo * info )
 

Definition at line 1525 of file sort.c.

Referenced by makeEnumSpecNode().

01526 {
01527   /*
01528   ** Expect enumSort to be in sort table but not yet filled in.
01529   ** Return TRUE if it is "new" 
01530   */
01531 
01532   sortNode sn;
01533 
01534   llassert (sortTable != NULL);
01535 
01536   sn = sort_lookup (enumSort);
01537   if (sn.members == (smemberInfo *) 0)
01538     {
01539       sortTable[enumSort].members = info;
01540       genEnumOps (enumSort);
01541       return TRUE;
01542     }
01543   else
01544     {
01545       smemberInfo_free (info);
01546       return FALSE;
01547     }
01548 }

bool sort_updateStr ( sort strSort,
smemberInfo * info )
 

Definition at line 1084 of file sort.c.

Referenced by makestrOrUnionNode().

01085 {
01086   /* expect strSort to be in sort table but not yet filled in */
01087   /* return TRUE if it is "new" */
01088   sort tupleSort;
01089   sortNode sn;
01090   
01091   llassert (sortTable != NULL);
01092   sn = sort_lookup (strSort);
01093 
01094   if (sn.members == (smemberInfo *) 0)
01095     {
01096       sortTable[strSort].members = info;
01097       tupleSort = sort_makeTuple (ltoken_undefined, strSort);
01098       genStrOps (strSort, tupleSort);
01099       return TRUE;
01100     }
01101   else
01102     {
01103       smemberInfo_free (info);
01104       return FALSE;
01105     }
01106 }

bool sort_updateUnion ( sort unionSort,
smemberInfo * info )
 

Definition at line 1355 of file sort.c.

Referenced by makestrOrUnionNode().

01356 {
01357  /* expect unionSort to be in sort table but not yet filled in */
01358  /* return TRUE if it is "new" */
01359   sort uValSort;
01360   sortNode sn;
01361 
01362   llassert (sortTable != NULL);
01363 
01364   sn = sort_lookup (unionSort);
01365 
01366   if (sn.members == (smemberInfo *) 0)
01367     {
01368       sortTable[unionSort].members = info;
01369       uValSort = sort_makeUnionVal (ltoken_undefined, unionSort);
01370       /* same as struct operations */
01371       genStrOps (unionSort, uValSort);
01372       return TRUE;
01373     }
01374   else
01375     {
01376       smemberInfo_free (info);
01377       return FALSE;
01378     }
01379 }


Variable Documentation

sort sort_bool
 

Definition at line 118 of file sort.c.

sort sort_capBool
 

Definition at line 119 of file sort.c.

sort sort_char
 

Definition at line 121 of file sort.c.

sort sort_cstring
 

Definition at line 124 of file sort.c.

sort sort_double
 

Definition at line 123 of file sort.c.

sort sort_float
 

Definition at line 122 of file sort.c.

sort sort_int
 

Definition at line 120 of file sort.c.


Generated at Fri Nov 3 18:58:06 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000