filename and linenumber info in more places
authordick <none@none>
Mon, 29 Aug 1988 15:51:48 +0000 (15:51 +0000)
committerdick <none@none>
Mon, 29 Aug 1988 15:51:48 +0000 (15:51 +0000)
16 files changed:
lang/cem/cemcom/LLlex.c
lang/cem/cemcom/code.c
lang/cem/cemcom/conversion.c
lang/cem/cemcom/decspecs.c
lang/cem/cemcom/decspecs.str
lang/cem/cemcom/def.str
lang/cem/cemcom/dumpidf.c
lang/cem/cemcom/error.c
lang/cem/cemcom/idf.c
lang/cem/cemcom/idf.str
lang/cem/cemcom/main.c
lang/cem/cemcom/make.tokcase
lang/cem/cemcom/make.tokfile
lang/cem/cemcom/options.c
lang/cem/cemcom/program.g
lang/cem/cemcom/type.c

index cf1cf87..89ec339 100644 (file)
@@ -285,6 +285,8 @@ firstline:
                        PushBack();
                *tg++ = '\0';   /* mark the end of the identifier       */
                idef = ptok->tk_idf = idf_hashed(buf, tg - buf, hash);
+               idef->id_file = ptok->tk_file;
+               idef->id_line = ptok->tk_line;
 #ifndef NOPP
                if (idef->id_macro && ReplaceMacros && replace(idef))
                        /* macro replacement should be performed        */
index 1fa3647..e1564f7 100644 (file)
@@ -37,11 +37,15 @@ label datlab_count = 1;
 int fp_used;
 #endif NOFLOAT
 
+/* global function info */
+char *func_name;
+struct type *func_type;
+int func_notypegiven;
+
 #ifdef USE_TMP
 static int     tmp_id;
 static int     pro_id;
 #endif USE_TMP
-static char    *pro_name;
 
 extern char options[];
 char *symbol2str();
@@ -160,15 +164,14 @@ code_scope(text, def)
 
 static label return_label, return2_label;
 static char return_expr_occurred;
-static struct type *func_tp;
 static arith func_size;
 static label func_res_label;
 static char *last_fn_given = "";
 static label file_name_label;
 
-begin_proc(name, def)  /* to be called when entering a procedure       */
-       char *name;
-       register struct def *def;
+begin_proc(ds, idf)            /* to be called when entering a procedure */
+       struct decspecs *ds;
+       struct idf *idf;
 {
        /*      begin_proc() is called at the entrance of a new function
                and performs the necessary code generation:
@@ -178,7 +181,8 @@ begin_proc(name, def)       /* to be called when entering a procedure       */
                        does not fit in the return area
                -       a fil pseudo instruction
        */
-       register struct type *tp = def->df_type;
+       register char *name = idf->id_text;
+       register struct def *def = idf->id_def;
 
 #ifndef USE_TMP
        code_scope(name, def);
@@ -188,21 +192,24 @@ begin_proc(name, def)     /* to be called when entering a procedure       */
                DfaStartFunction(name);
 #endif DATAFLOW
 
-       if (tp->tp_fund != FUNCTION) {
+       /* set global function info */
+       func_name = name;
+       if (def->df_type->tp_fund != FUNCTION) {
                error("making function body for non-function");
-               tp = error_type;
+               func_type = error_type;
        }
-       else
-               tp = tp->tp_up;
-       func_tp = tp;
-       func_size = ATW(tp->tp_size);
-       pro_name = name;
+       else {
+               func_type = def->df_type->tp_up;
+       }
+       func_notypegiven = ds->ds_notypegiven;
+       func_size = ATW(func_type->tp_size);
+
 #ifndef USE_TMP
        C_pro_narg(name);
 #else
        C_insertpart(pro_id = C_getid());
 #endif
-       if (is_struct_or_union(tp->tp_fund))    {
+       if (is_struct_or_union(func_type->tp_fund))     {
                C_df_dlb(func_res_label = data_label());
                C_bss_cst(func_size, (arith)0, 1);
        }
@@ -260,7 +267,7 @@ end_proc(fbytes)
        if (return_expr_occurred) {
                if (func_res_label != 0)        {
                        C_lae_dlb(func_res_label, (arith)0);
-                       store_block(func_size, func_tp->tp_align);
+                       store_block(func_size, func_type->tp_align);
                        C_lae_dlb(func_res_label, (arith)0);
                        C_ret(pointer_size);
                }
@@ -268,7 +275,6 @@ end_proc(fbytes)
                        C_ret(func_size);
        }
        else    C_ret((arith) 0);
-
        /* getting the number of "local" bytes is posponed until here,
           because copying the function result in "func_res_label" may
           need temporaries! However, local_level is now L_FORMAL2, because
@@ -278,11 +284,11 @@ end_proc(fbytes)
        nbytes = ATW(- local_level->sl_max_block);
 #ifdef USE_TMP
        C_beginpart(pro_id);
-       C_pro(pro_name, nbytes);
+       C_pro(func_name, nbytes);
 #endif
        if (fbytes > max_int) {
                error("%s has more than %ld parameter bytes",
-                       pro_name, (long) max_int);
+                       func_name, (long) max_int);
        }
        C_ms_par(fbytes);               /* # bytes for formals          */
        if (sp_occurred[SP_SETJMP]) {   /* indicate use of "setjmp"     */
@@ -297,7 +303,7 @@ end_proc(fbytes)
        C_end(nbytes);
        if (nbytes > max_int) {
                error("%s has more than %ld bytes of local variables",
-                       pro_name, (long) max_int);
+                       func_name, (long) max_int);
        }
        options['n'] = optionsn;
 }
@@ -318,7 +324,7 @@ do_return_expr(expr)
        /*      do_return_expr() generates the expression and the jump for
                a return statement with an expression.
        */
-       ch7cast(&expr, RETURN, func_tp);
+       ch7cast(&expr, RETURN, func_type);
        code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL);
        C_bra(return_label);
        return_expr_occurred = 1;
index 3f8938a..afc7ec5 100644 (file)
@@ -126,7 +126,7 @@ conversion(from_type, to_type)
        signed, unsigned or floating
 */
 static int
-convtype(tp)/* bad name ???*/
+convtype(tp)
        register struct type *tp;
 {
        switch (tp->tp_fund)    {
index 530494b..7fc45a2 100644 (file)
@@ -51,8 +51,10 @@ do_decspecs(ds)
        */
 
        /* some adjustments as described in RM 8.2 */
-       if (tp == 0)
+       if (tp == 0) {
+               ds->ds_notypegiven = 1;
                tp = int_type;
+       }
        switch (ds->ds_size)    {
        case SHORT:
                if (tp == int_type)
index 03464f4..b7e3b51 100644 (file)
@@ -8,6 +8,7 @@
 struct decspecs        {
        struct decspecs *next;
        struct type *ds_type;   /* single type */
+       int ds_notypegiven;     /* set if type not given explicitly */
        int ds_sc_given;        /* 1 if the st. class is explicitly given */
        int ds_sc;              /* storage class, given or implied */
        int ds_size;            /* LONG, SHORT or 0 */
index 2270752..5de425e 100644 (file)
@@ -19,6 +19,8 @@ struct def    {               /* for ordinary tags */
        char df_initialized;    /* an initialization has been generated */
        char df_alloc;          /* 0, ALLOC_SEEN or ALLOC_DONE */
        char df_used;           /* set if idf is used */
+       char *df_file;          /* file containing the definition */
+       long df_line;           /* line number of the definition */
        char df_formal_array;   /* to warn if sizeof is taken */
        arith df_address;
 };
index 6390468..b07ebc9 100644 (file)
@@ -173,6 +173,8 @@ dumpdefs(def, opt)
                        def->df_sc == ENUM ? ", =" : " at",
                        def->df_address
                );
+               print("%s, line %u",
+                       def->df_file ? def->df_file : "NO_FILE", def->df_line);
                def = def->next;
        }
        dumplevel--;
index abd6028..bf3236a 100644 (file)
@@ -37,7 +37,6 @@ int err_occurred = 0;
 
 extern char *symbol2str();
 extern char options[];
-extern char loptions[];
 
 /*     There are three general error-message functions:
                lexerror()      lexical and pre-processor error messages
index 24e4a0b..b990c91 100644 (file)
@@ -278,6 +278,8 @@ declare_idf(ds, dc, lvl)
                switch (lvl)    {
                case L_GLOBAL:
                        global_redecl(idf, sc, type);
+                       def->df_file = idf->id_file;
+                       def->df_line = idf->id_line;
                        break;
                case L_FORMAL1: /* formal declaration */
                        error("formal %s redeclared", idf->id_text);
@@ -295,6 +297,8 @@ declare_idf(ds, dc, lvl)
                def->df_formal_array = formal_array;
                def->df_sc = sc;
                def->df_level = L_FORMAL2;      /* CJ */
+               def->df_file = idf->id_file;
+               def->df_line = idf->id_line;
        }
        else
        if (    lvl >= L_LOCAL &&
@@ -320,6 +324,8 @@ declare_idf(ds, dc, lvl)
                newdef->df_level = lvl;
                newdef->df_type = type;
                newdef->df_sc = sc;
+               newdef->df_file = idf->id_file;
+               newdef->df_line = idf->id_line;
                /* link it into the name list in the proper place */
                idf->id_def = newdef;
                update_ahead(idf);
index a9f8b9b..adf1e2f 100644 (file)
@@ -34,6 +34,8 @@ struct idf    {
        int id_resmac;          /* if nonzero: keyword of macroproc.    */
 #endif NOPP
        int id_reserved;        /* non-zero for reserved words          */
+       char *id_file;          /* used for warnings */
+       long id_line;
        struct def *id_def;     /* variables, typedefs, enum-constants  */
        struct sdef *id_sdef;   /* selector tags                        */
        struct tag *id_struct;  /* struct and union tags                */
index 2336572..ffc6efe 100644 (file)
@@ -30,7 +30,7 @@
 
 extern struct tokenname tkidf[], tkother[];
 extern char *symbol2str();
-char options[128];                     /* one for every char   */
+extern char options[128];
 
 #ifndef NOPP
 int inc_pos = 1;                       /* place where next -I goes */
index ef32292..90205c6 100755 (executable)
@@ -1,4 +1,6 @@
 cat <<'--EOT--'
+/* Generated by make.tokcase */
+/* $Header: */
 #include "Lpars.h"
 
 char *
@@ -14,11 +16,13 @@ symbol2str(tok)
        }
        switch (tok) {
 --EOT--
+
 sed '
 /{[A-Z]/!d
 s/.*{\(.*\),.*\(".*"\).*$/     case \1 :\
                return \2;/
 '
+
 cat <<'--EOT--'
        case '\n':
        case '\f':
index 494b7e3..74a7c44 100755 (executable)
@@ -1,3 +1,8 @@
+cat <<'--EOT--'
+/* Generated by make.tokfile */
+/* $Header: */
+--EOT--
+
 sed '
 /{[A-Z]/!d
 s/.*{//
index 10b0e55..3d664fe 100644 (file)
@@ -28,7 +28,7 @@ extern int inc_max;
 extern int inc_total;
 #endif NOPP
 
-extern char options[];
+char options[128];                     /* one for every char   */
 extern int idfsize;
 
 int txt2int();
@@ -36,10 +36,12 @@ int txt2int();
 do_option(text)
        char *text;
 {
-       switch(*text++) {
+       register char opt;
+
+       switch (opt = *text++)  {
 
        default:
-               fatal("illegal option: %c", *--text);
+               fatal("illegal option: %c", opt);
                break;
        case '-':
                options[*text] = 1;     /* flags, debug options etc.    */
@@ -55,8 +57,9 @@ do_option(text)
 #ifndef        NOROPTION
        case 'R':                       /* strict version */
 #endif
-               options[*(text-1)] = 1;
+               options[opt] = 1;
                break;
+
 #ifdef NOROPTION
        case 'R':
                warning("-R option not implemented");
@@ -208,62 +211,62 @@ deleted, is now a debug-flag
                break;
 #else NOCROSS
        {
-               register arith size, align;
+               register arith sz, algn;
                char c;
 
                while (c = *text++)     {
-                       size = txt2int(&text);
-                       align = 0;
+                       sz = txt2int(&text);
+                       algn = 0;
                        if (*text == '.')       {
                                text++;
-                               align = txt2int(&text);
+                               algn = txt2int(&text);
                        }
                        switch (c)      {
                        case 's':       /* short        */
-                               if (size != (arith)0)
-                                       short_size = size;
-                               if (align != 0)
-                                       short_align = align;
+                               if (sz != (arith)0)
+                                       short_size = sz;
+                               if (algn != 0)
+                                       short_align = algn;
                                break;
                        case 'w':       /* word         */
-                               if (size != (arith)0)
-                                       dword_size = (word_size = size) << 1;
-                               if (align != 0)
-                                       word_align = align;
+                               if (sz != (arith)0)
+                                       dword_size = (word_size = sz) << 1;
+                               if (algn != 0)
+                                       word_align = algn;
                                break;
                        case 'i':       /* int          */
-                               if (size != (arith)0)
-                                       int_size = size;
-                               if (align != 0)
-                                       int_align = align;
+                               if (sz != (arith)0)
+                                       int_size = sz;
+                               if (algn != 0)
+                                       int_align = algn;
                                break;
                        case 'l':       /* long         */
-                               if (size != (arith)0)
-                                       long_size = size;
-                               if (align != 0)
-                                       long_align = align;
+                               if (sz != (arith)0)
+                                       long_size = sz;
+                               if (algn != 0)
+                                       long_align = algn;
                                break;
                        case 'f':       /* float        */
 #ifndef NOFLOAT
-                               if (size != (arith)0)
-                                       float_size = size;
-                               if (align != 0)
-                                       float_align = align;
+                               if (sz != (arith)0)
+                                       float_size = sz;
+                               if (algn != 0)
+                                       float_align = algn;
 #endif NOFLOAT
                                break;
                        case 'd':       /* double       */
 #ifndef NOFLOAT
-                               if (size != (arith)0)
-                                       double_size = size;
-                               if (align != 0)
-                                       double_align = align;
+                               if (sz != (arith)0)
+                                       double_size = sz;
+                               if (algn != 0)
+                                       double_align = algn;
 #endif NOFLOAT
                                break;
                        case 'p':       /* pointer      */
-                               if (size != (arith)0)
-                                       pointer_size = size;
-                               if (align != 0)
-                                       pointer_align = align;
+                               if (sz != (arith)0)
+                                       pointer_size = sz;
+                               if (algn != 0)
+                                       pointer_align = algn;
                                break;
                        case 'r':       /* adjust bitfields right       */
 #ifndef NOBITFIELD
@@ -273,12 +276,12 @@ deleted, is now a debug-flag
 #endif NOBITFIELD
                                break;
                        case 'S':       /* initial struct alignment     */
-                               if (size != (arith)0)
-                                       struct_align = size;
+                               if (sz != (arith)0)
+                                       struct_align = sz;
                                break;
                        case 'U':       /* initial union alignment      */
-                               if (size != (arith)0)
-                                       union_align = size;
+                               if (sz != (arith)0)
+                                       union_align = sz;
                                break;
                        default:
                                error("-V: bad type indicator %c\n", c);
index afd33d9..aebe839 100644 (file)
@@ -128,7 +128,7 @@ external_definition
                                is a function, not an old-fashioned
                                initialization.
                        */
-                       function(&Dc)
+                       function(&Ds, &Dc)
                |
                        non_function(&Ds, &Dc)
                ]
@@ -166,7 +166,7 @@ non_function(register struct decspecs *ds; register struct declarator *dc;)
 ;
 
 /* 10.1 */
-function(struct declarator *dc;)
+function(struct decspecs *ds; struct declarator *dc;)
        {
                arith fbytes;
        }
@@ -175,7 +175,7 @@ function(struct declarator *dc;)
                init_idf(idf);
                stack_level();          /* L_FORMAL1 declarations */
                declare_params(dc);
-               begin_proc(idf->id_text, idf->id_def);
+               begin_proc(ds, idf);    /* sets global function info */
                stack_level();          /* L_FORMAL2 declarations */
        }
        declaration*
index 8482a82..dc8e813 100644 (file)
@@ -97,6 +97,9 @@ construct_type(fund, tp, count)
                        count *= tp->tp_size;
                dtp = array_of(tp, count);
                break;
+       default:
+               crash("bad constructor in construct_type");
+               /*NOTREACHED*/
        }
        return dtp;
 }
@@ -212,14 +215,14 @@ align(pos, al)
 }
 
 struct type *
-standard_type(fund, sign, algn, size)
-       int algn; arith size;
+standard_type(fund, sgn, algn, sz)
+       int algn; arith sz;
 {
        register struct type *tp = create_type(fund);
 
-       tp->tp_unsigned = sign;
+       tp->tp_unsigned = sgn;
        tp->tp_align = algn;
-       tp->tp_size = size;
+       tp->tp_size = sz;
 
        return tp;
 }