filename and linenumber info in more places

This commit is contained in:
dick 1988-08-29 15:51:48 +00:00
parent 62d1432035
commit 32e5679d6c
16 changed files with 108 additions and 71 deletions

View file

@ -285,6 +285,8 @@ firstline:
PushBack(); PushBack();
*tg++ = '\0'; /* mark the end of the identifier */ *tg++ = '\0'; /* mark the end of the identifier */
idef = ptok->tk_idf = idf_hashed(buf, tg - buf, hash); idef = ptok->tk_idf = idf_hashed(buf, tg - buf, hash);
idef->id_file = ptok->tk_file;
idef->id_line = ptok->tk_line;
#ifndef NOPP #ifndef NOPP
if (idef->id_macro && ReplaceMacros && replace(idef)) if (idef->id_macro && ReplaceMacros && replace(idef))
/* macro replacement should be performed */ /* macro replacement should be performed */

View file

@ -37,11 +37,15 @@ label datlab_count = 1;
int fp_used; int fp_used;
#endif NOFLOAT #endif NOFLOAT
/* global function info */
char *func_name;
struct type *func_type;
int func_notypegiven;
#ifdef USE_TMP #ifdef USE_TMP
static int tmp_id; static int tmp_id;
static int pro_id; static int pro_id;
#endif USE_TMP #endif USE_TMP
static char *pro_name;
extern char options[]; extern char options[];
char *symbol2str(); char *symbol2str();
@ -160,15 +164,14 @@ code_scope(text, def)
static label return_label, return2_label; static label return_label, return2_label;
static char return_expr_occurred; static char return_expr_occurred;
static struct type *func_tp;
static arith func_size; static arith func_size;
static label func_res_label; static label func_res_label;
static char *last_fn_given = ""; static char *last_fn_given = "";
static label file_name_label; static label file_name_label;
begin_proc(name, def) /* to be called when entering a procedure */ begin_proc(ds, idf) /* to be called when entering a procedure */
char *name; struct decspecs *ds;
register struct def *def; struct idf *idf;
{ {
/* begin_proc() is called at the entrance of a new function /* begin_proc() is called at the entrance of a new function
and performs the necessary code generation: 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 does not fit in the return area
- a fil pseudo instruction - 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 #ifndef USE_TMP
code_scope(name, def); code_scope(name, def);
@ -188,21 +192,24 @@ begin_proc(name, def) /* to be called when entering a procedure */
DfaStartFunction(name); DfaStartFunction(name);
#endif DATAFLOW #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"); error("making function body for non-function");
tp = error_type; func_type = error_type;
} }
else else {
tp = tp->tp_up; func_type = def->df_type->tp_up;
func_tp = tp; }
func_size = ATW(tp->tp_size); func_notypegiven = ds->ds_notypegiven;
pro_name = name; func_size = ATW(func_type->tp_size);
#ifndef USE_TMP #ifndef USE_TMP
C_pro_narg(name); C_pro_narg(name);
#else #else
C_insertpart(pro_id = C_getid()); C_insertpart(pro_id = C_getid());
#endif #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_df_dlb(func_res_label = data_label());
C_bss_cst(func_size, (arith)0, 1); C_bss_cst(func_size, (arith)0, 1);
} }
@ -260,7 +267,7 @@ end_proc(fbytes)
if (return_expr_occurred) { if (return_expr_occurred) {
if (func_res_label != 0) { if (func_res_label != 0) {
C_lae_dlb(func_res_label, (arith)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_lae_dlb(func_res_label, (arith)0);
C_ret(pointer_size); C_ret(pointer_size);
} }
@ -268,7 +275,6 @@ end_proc(fbytes)
C_ret(func_size); C_ret(func_size);
} }
else C_ret((arith) 0); else C_ret((arith) 0);
/* getting the number of "local" bytes is posponed until here, /* getting the number of "local" bytes is posponed until here,
because copying the function result in "func_res_label" may because copying the function result in "func_res_label" may
need temporaries! However, local_level is now L_FORMAL2, because need temporaries! However, local_level is now L_FORMAL2, because
@ -278,11 +284,11 @@ end_proc(fbytes)
nbytes = ATW(- local_level->sl_max_block); nbytes = ATW(- local_level->sl_max_block);
#ifdef USE_TMP #ifdef USE_TMP
C_beginpart(pro_id); C_beginpart(pro_id);
C_pro(pro_name, nbytes); C_pro(func_name, nbytes);
#endif #endif
if (fbytes > max_int) { if (fbytes > max_int) {
error("%s has more than %ld parameter bytes", 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 */ C_ms_par(fbytes); /* # bytes for formals */
if (sp_occurred[SP_SETJMP]) { /* indicate use of "setjmp" */ if (sp_occurred[SP_SETJMP]) { /* indicate use of "setjmp" */
@ -297,7 +303,7 @@ end_proc(fbytes)
C_end(nbytes); C_end(nbytes);
if (nbytes > max_int) { if (nbytes > max_int) {
error("%s has more than %ld bytes of local variables", error("%s has more than %ld bytes of local variables",
pro_name, (long) max_int); func_name, (long) max_int);
} }
options['n'] = optionsn; options['n'] = optionsn;
} }
@ -318,7 +324,7 @@ do_return_expr(expr)
/* do_return_expr() generates the expression and the jump for /* do_return_expr() generates the expression and the jump for
a return statement with an expression. 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); code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL);
C_bra(return_label); C_bra(return_label);
return_expr_occurred = 1; return_expr_occurred = 1;

View file

@ -126,7 +126,7 @@ conversion(from_type, to_type)
signed, unsigned or floating signed, unsigned or floating
*/ */
static int static int
convtype(tp)/* bad name ???*/ convtype(tp)
register struct type *tp; register struct type *tp;
{ {
switch (tp->tp_fund) { switch (tp->tp_fund) {

View file

@ -51,8 +51,10 @@ do_decspecs(ds)
*/ */
/* some adjustments as described in RM 8.2 */ /* some adjustments as described in RM 8.2 */
if (tp == 0) if (tp == 0) {
ds->ds_notypegiven = 1;
tp = int_type; tp = int_type;
}
switch (ds->ds_size) { switch (ds->ds_size) {
case SHORT: case SHORT:
if (tp == int_type) if (tp == int_type)

View file

@ -8,6 +8,7 @@
struct decspecs { struct decspecs {
struct decspecs *next; struct decspecs *next;
struct type *ds_type; /* single type */ 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_given; /* 1 if the st. class is explicitly given */
int ds_sc; /* storage class, given or implied */ int ds_sc; /* storage class, given or implied */
int ds_size; /* LONG, SHORT or 0 */ int ds_size; /* LONG, SHORT or 0 */

View file

@ -19,6 +19,8 @@ struct def { /* for ordinary tags */
char df_initialized; /* an initialization has been generated */ char df_initialized; /* an initialization has been generated */
char df_alloc; /* 0, ALLOC_SEEN or ALLOC_DONE */ char df_alloc; /* 0, ALLOC_SEEN or ALLOC_DONE */
char df_used; /* set if idf is used */ 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 */ char df_formal_array; /* to warn if sizeof is taken */
arith df_address; arith df_address;
}; };

View file

@ -173,6 +173,8 @@ dumpdefs(def, opt)
def->df_sc == ENUM ? ", =" : " at", def->df_sc == ENUM ? ", =" : " at",
def->df_address def->df_address
); );
print("%s, line %u",
def->df_file ? def->df_file : "NO_FILE", def->df_line);
def = def->next; def = def->next;
} }
dumplevel--; dumplevel--;

View file

@ -37,7 +37,6 @@ int err_occurred = 0;
extern char *symbol2str(); extern char *symbol2str();
extern char options[]; extern char options[];
extern char loptions[];
/* There are three general error-message functions: /* There are three general error-message functions:
lexerror() lexical and pre-processor error messages lexerror() lexical and pre-processor error messages

View file

@ -278,6 +278,8 @@ declare_idf(ds, dc, lvl)
switch (lvl) { switch (lvl) {
case L_GLOBAL: case L_GLOBAL:
global_redecl(idf, sc, type); global_redecl(idf, sc, type);
def->df_file = idf->id_file;
def->df_line = idf->id_line;
break; break;
case L_FORMAL1: /* formal declaration */ case L_FORMAL1: /* formal declaration */
error("formal %s redeclared", idf->id_text); error("formal %s redeclared", idf->id_text);
@ -295,6 +297,8 @@ declare_idf(ds, dc, lvl)
def->df_formal_array = formal_array; def->df_formal_array = formal_array;
def->df_sc = sc; def->df_sc = sc;
def->df_level = L_FORMAL2; /* CJ */ def->df_level = L_FORMAL2; /* CJ */
def->df_file = idf->id_file;
def->df_line = idf->id_line;
} }
else else
if ( lvl >= L_LOCAL && if ( lvl >= L_LOCAL &&
@ -320,6 +324,8 @@ declare_idf(ds, dc, lvl)
newdef->df_level = lvl; newdef->df_level = lvl;
newdef->df_type = type; newdef->df_type = type;
newdef->df_sc = sc; 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 */ /* link it into the name list in the proper place */
idf->id_def = newdef; idf->id_def = newdef;
update_ahead(idf); update_ahead(idf);

View file

@ -34,6 +34,8 @@ struct idf {
int id_resmac; /* if nonzero: keyword of macroproc. */ int id_resmac; /* if nonzero: keyword of macroproc. */
#endif NOPP #endif NOPP
int id_reserved; /* non-zero for reserved words */ 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 def *id_def; /* variables, typedefs, enum-constants */
struct sdef *id_sdef; /* selector tags */ struct sdef *id_sdef; /* selector tags */
struct tag *id_struct; /* struct and union tags */ struct tag *id_struct; /* struct and union tags */

View file

@ -30,7 +30,7 @@
extern struct tokenname tkidf[], tkother[]; extern struct tokenname tkidf[], tkother[];
extern char *symbol2str(); extern char *symbol2str();
char options[128]; /* one for every char */ extern char options[128];
#ifndef NOPP #ifndef NOPP
int inc_pos = 1; /* place where next -I goes */ int inc_pos = 1; /* place where next -I goes */

View file

@ -1,4 +1,6 @@
cat <<'--EOT--' cat <<'--EOT--'
/* Generated by make.tokcase */
/* $Header: */
#include "Lpars.h" #include "Lpars.h"
char * char *
@ -14,11 +16,13 @@ symbol2str(tok)
} }
switch (tok) { switch (tok) {
--EOT-- --EOT--
sed ' sed '
/{[A-Z]/!d /{[A-Z]/!d
s/.*{\(.*\),.*\(".*"\).*$/ case \1 :\ s/.*{\(.*\),.*\(".*"\).*$/ case \1 :\
return \2;/ return \2;/
' '
cat <<'--EOT--' cat <<'--EOT--'
case '\n': case '\n':
case '\f': case '\f':

View file

@ -1,3 +1,8 @@
cat <<'--EOT--'
/* Generated by make.tokfile */
/* $Header: */
--EOT--
sed ' sed '
/{[A-Z]/!d /{[A-Z]/!d
s/.*{// s/.*{//

View file

@ -28,7 +28,7 @@ extern int inc_max;
extern int inc_total; extern int inc_total;
#endif NOPP #endif NOPP
extern char options[]; char options[128]; /* one for every char */
extern int idfsize; extern int idfsize;
int txt2int(); int txt2int();
@ -36,10 +36,12 @@ int txt2int();
do_option(text) do_option(text)
char *text; char *text;
{ {
switch(*text++) { register char opt;
switch (opt = *text++) {
default: default:
fatal("illegal option: %c", *--text); fatal("illegal option: %c", opt);
break; break;
case '-': case '-':
options[*text] = 1; /* flags, debug options etc. */ options[*text] = 1; /* flags, debug options etc. */
@ -55,8 +57,9 @@ do_option(text)
#ifndef NOROPTION #ifndef NOROPTION
case 'R': /* strict version */ case 'R': /* strict version */
#endif #endif
options[*(text-1)] = 1; options[opt] = 1;
break; break;
#ifdef NOROPTION #ifdef NOROPTION
case 'R': case 'R':
warning("-R option not implemented"); warning("-R option not implemented");
@ -208,62 +211,62 @@ deleted, is now a debug-flag
break; break;
#else NOCROSS #else NOCROSS
{ {
register arith size, align; register arith sz, algn;
char c; char c;
while (c = *text++) { while (c = *text++) {
size = txt2int(&text); sz = txt2int(&text);
align = 0; algn = 0;
if (*text == '.') { if (*text == '.') {
text++; text++;
align = txt2int(&text); algn = txt2int(&text);
} }
switch (c) { switch (c) {
case 's': /* short */ case 's': /* short */
if (size != (arith)0) if (sz != (arith)0)
short_size = size; short_size = sz;
if (align != 0) if (algn != 0)
short_align = align; short_align = algn;
break; break;
case 'w': /* word */ case 'w': /* word */
if (size != (arith)0) if (sz != (arith)0)
dword_size = (word_size = size) << 1; dword_size = (word_size = sz) << 1;
if (align != 0) if (algn != 0)
word_align = align; word_align = algn;
break; break;
case 'i': /* int */ case 'i': /* int */
if (size != (arith)0) if (sz != (arith)0)
int_size = size; int_size = sz;
if (align != 0) if (algn != 0)
int_align = align; int_align = algn;
break; break;
case 'l': /* long */ case 'l': /* long */
if (size != (arith)0) if (sz != (arith)0)
long_size = size; long_size = sz;
if (align != 0) if (algn != 0)
long_align = align; long_align = algn;
break; break;
case 'f': /* float */ case 'f': /* float */
#ifndef NOFLOAT #ifndef NOFLOAT
if (size != (arith)0) if (sz != (arith)0)
float_size = size; float_size = sz;
if (align != 0) if (algn != 0)
float_align = align; float_align = algn;
#endif NOFLOAT #endif NOFLOAT
break; break;
case 'd': /* double */ case 'd': /* double */
#ifndef NOFLOAT #ifndef NOFLOAT
if (size != (arith)0) if (sz != (arith)0)
double_size = size; double_size = sz;
if (align != 0) if (algn != 0)
double_align = align; double_align = algn;
#endif NOFLOAT #endif NOFLOAT
break; break;
case 'p': /* pointer */ case 'p': /* pointer */
if (size != (arith)0) if (sz != (arith)0)
pointer_size = size; pointer_size = sz;
if (align != 0) if (algn != 0)
pointer_align = align; pointer_align = algn;
break; break;
case 'r': /* adjust bitfields right */ case 'r': /* adjust bitfields right */
#ifndef NOBITFIELD #ifndef NOBITFIELD
@ -273,12 +276,12 @@ deleted, is now a debug-flag
#endif NOBITFIELD #endif NOBITFIELD
break; break;
case 'S': /* initial struct alignment */ case 'S': /* initial struct alignment */
if (size != (arith)0) if (sz != (arith)0)
struct_align = size; struct_align = sz;
break; break;
case 'U': /* initial union alignment */ case 'U': /* initial union alignment */
if (size != (arith)0) if (sz != (arith)0)
union_align = size; union_align = sz;
break; break;
default: default:
error("-V: bad type indicator %c\n", c); error("-V: bad type indicator %c\n", c);

View file

@ -128,7 +128,7 @@ external_definition
is a function, not an old-fashioned is a function, not an old-fashioned
initialization. initialization.
*/ */
function(&Dc) function(&Ds, &Dc)
| |
non_function(&Ds, &Dc) non_function(&Ds, &Dc)
] ]
@ -166,7 +166,7 @@ non_function(register struct decspecs *ds; register struct declarator *dc;)
; ;
/* 10.1 */ /* 10.1 */
function(struct declarator *dc;) function(struct decspecs *ds; struct declarator *dc;)
{ {
arith fbytes; arith fbytes;
} }
@ -175,7 +175,7 @@ function(struct declarator *dc;)
init_idf(idf); init_idf(idf);
stack_level(); /* L_FORMAL1 declarations */ stack_level(); /* L_FORMAL1 declarations */
declare_params(dc); declare_params(dc);
begin_proc(idf->id_text, idf->id_def); begin_proc(ds, idf); /* sets global function info */
stack_level(); /* L_FORMAL2 declarations */ stack_level(); /* L_FORMAL2 declarations */
} }
declaration* declaration*

View file

@ -97,6 +97,9 @@ construct_type(fund, tp, count)
count *= tp->tp_size; count *= tp->tp_size;
dtp = array_of(tp, count); dtp = array_of(tp, count);
break; break;
default:
crash("bad constructor in construct_type");
/*NOTREACHED*/
} }
return dtp; return dtp;
} }
@ -212,14 +215,14 @@ align(pos, al)
} }
struct type * struct type *
standard_type(fund, sign, algn, size) standard_type(fund, sgn, algn, sz)
int algn; arith size; int algn; arith sz;
{ {
register struct type *tp = create_type(fund); register struct type *tp = create_type(fund);
tp->tp_unsigned = sign; tp->tp_unsigned = sgn;
tp->tp_align = algn; tp->tp_align = algn;
tp->tp_size = size; tp->tp_size = sz;
return tp; return tp;
} }