home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / msm-1 / icont.sit / lglob.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-19  |  3.7 KB  |  127 lines  |  [TEXT/MPS ]

  1. /*
  2.  * lgloc.c -- routines for processing .u2 files.
  3.  */
  4.  
  5. #include "link.h"
  6. #include "tproto.h"
  7. #include "opcode.h"
  8. #include "::h:version.h"
  9.  
  10. int nrecords = 0;        /* number of records in program */
  11.  
  12. /*
  13.  * readglob reads the global information from infile (.u2) and merges it with
  14.  *  the global table and record table.
  15.  */
  16. novalue readglob()
  17.    {
  18.    register word id;
  19.    register int n, op;
  20.    int k;
  21.    int implicit;
  22.    char *name;
  23.    struct gentry *gp;
  24.    extern char *progname;
  25.  
  26.    if (getopc(&name) != Op_Version)
  27.       quitf("ucode file %s has no version identification",inname);
  28.    id = getid();        /* get version number of ucode */
  29.    newline();
  30.    if (strcmp(&lsspace[id],UVersion)) {
  31.       fprintf(stderr,"version mismatch in ucode file %s\n",inname);
  32.       fprintf(stderr,"\tucode version: %s\n",&lsspace[id]);
  33.       fprintf(stderr,"\texpected version: %s\n",UVersion);
  34.  
  35. #ifdef Xver
  36. xver(lglob.1)
  37. #endif                            /* Xver */
  38.  
  39. #ifndef Xver
  40.       exit(ErrorExit);
  41. #endif                            /* Xver */
  42.  
  43.       }
  44.    while ((op = getopc(&name)) != EOF) {
  45.       switch (op) {
  46.          case Op_Record:    /* a record declaration */
  47.             id = getid();    /* record name */
  48.             n = getdec();    /* number of fields */
  49.             newline();
  50.             gp = glocate(id);
  51.             /*
  52.              * It's ok if the name isn't already in use or if the
  53.              *  name is just used in a "global" declaration.  Otherwise,
  54.              *  it is an inconsistent redeclaration.
  55.              */
  56.             if (gp == NULL || (gp->g_flag & ~F_Global) == 0) {
  57.                putglobal(id, F_Record, n, ++nrecords);
  58.                while (n--) {    /* loop reading field numbers and names */
  59.                   k = getdec();
  60.                   putfield(getid(), nrecords, k);
  61.                   newline();
  62.                   }
  63.                }
  64.             else {
  65.                lfatal(&lsspace[id], "inconsistent redeclaration");
  66.                while (n--)
  67.                   newline();
  68.                }
  69.             break;
  70.  
  71.          case Op_Impl:        /* undeclared identifiers should be noted */
  72.             if (getopc(&name) == Op_Local)
  73.                implicit = 0;
  74.             else
  75.                implicit = F_ImpError;
  76.             break;
  77.  
  78.          case Op_Trace:        /* turn on tracing */
  79.             trace = -1;
  80.             break;
  81.  
  82.          case Op_Global:    /* global variable declarations */
  83.             n = getdec();    /* number of global declarations */
  84.             newline();
  85.             while (n--) {    /* process each declaration */
  86.                getdec();    /* throw away sequence number */
  87.                k = getoct();    /* get flags */
  88.                if (k & (F_Proc & ~F_Global))
  89.                   k |= implicit;
  90.                id = getid();    /* get variable name */
  91.                gp = glocate(id);
  92.                /*
  93.                 * Check for conflicting declarations and install the
  94.                 *  variable.
  95.                 */
  96.                if (gp != NULL &&
  97.                    (k & (F_Proc & ~F_Global)) && gp->g_flag != F_Global)
  98.                   lfatal(&lsspace[id], "inconsistent redeclaration");
  99.                else if (gp == NULL || (k & (F_Proc & ~F_Global)))
  100.                   putglobal(id, k, getdec(), 0);
  101.                newline();
  102.                }
  103.             break;
  104.  
  105.          case Op_Link:        /* link the named file */
  106.             name = &lsspace[getrest()];    /* get the name and */
  107.  
  108. #if ARM
  109.         {
  110.             char *flipname (char *);
  111.  
  112.         /* put it on the list of files to link */
  113.             alsolink(flipname(name));
  114.             }
  115. #else                    /* ARM */
  116.             alsolink(name);    /*  put it on the list of files to link */
  117. #endif                    /* ARM */
  118.  
  119.             newline();
  120.             break;
  121.  
  122.          default:
  123.         quitf("ill-formed global file %s",inname);
  124.          }
  125.       }
  126.    }
  127.