Improved switches, and fixed wrong place indication in error messages

This commit is contained in:
ceriel 1991-03-01 13:51:37 +00:00
parent 9d3696befe
commit bd1da2f86c
6 changed files with 34 additions and 18 deletions

View file

@ -31,7 +31,7 @@
!File: density.h !File: density.h
#define DENSITY 2 /* see switch.[ch] for an explanation */ #define DENSITY 3 /* see switch.[ch] for an explanation */
!File: macbuf.h !File: macbuf.h

View file

@ -31,7 +31,7 @@
!File: density.h !File: density.h
#define DENSITY 2 /* see switch.[ch] for an explanation */ #define DENSITY 3 /* see switch.[ch] for an explanation */
!File: macbuf.h !File: macbuf.h

View file

@ -115,7 +115,7 @@ domacro()
the arguments. the arguments.
*/ */
if (GetToken(&tk) != INTEGER) { if (GetToken(&tk) != INTEGER) {
error("bad #line syntax"); lexerror("bad #line syntax");
SkipToNewLine(); SkipToNewLine();
} }
else else
@ -303,17 +303,17 @@ do_include()
if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING) if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING)
filenm = tk.tk_bts; filenm = tk.tk_bts;
else { else {
error("bad include syntax"); lexerror("bad include syntax");
filenm = (char *)0; filenm = (char *)0;
} }
AccFileSpecifier = 0; AccFileSpecifier = 0;
if (SkipToNewLine()) { if (SkipToNewLine()) {
error("bad include syntax"); lexerror("bad include syntax");
} }
inctable[0] = WorkingDir; inctable[0] = WorkingDir;
if (filenm) { if (filenm) {
if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){ if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){
error("cannot open include file \"%s\"", filenm); lexerror("cannot open include file \"%s\"", filenm);
add_dependency(filenm); add_dependency(filenm);
} }
else { else {
@ -535,7 +535,7 @@ getparams(buf, parbuf)
*/ */
for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--) { for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--) {
if (!strcmp(*pbuf2, *pbuf)) { if (!strcmp(*pbuf2, *pbuf)) {
error("formal parameter \"%s\" already used", lexerror("formal parameter \"%s\" already used",
*pbuf); *pbuf);
} }
} }
@ -781,7 +781,7 @@ domacro()
EoiForNewline = 0; EoiForNewline = 0;
return; return;
} }
error("illegal # line"); lexerror("illegal # line");
EoiForNewline = 0; EoiForNewline = 0;
SkipToNewLine(); SkipToNewLine();
} }

View file

@ -15,8 +15,8 @@ L don't generate linenumbers and filename indications
o no warnings or stricts about normal old-style constuctions o no warnings or stricts about normal old-style constuctions
p trace p trace
P in running the preprocessor do not output '# line' lines P in running the preprocessor do not output '# line' lines
R restricted C
s no stricts s no stricts
S switch density
T take path following as directory for storing temporary file(s) T take path following as directory for storing temporary file(s)
U undefine predefined name U undefine predefined name
V set objectsize and alignment requirements V set objectsize and alignment requirements

View file

@ -37,6 +37,7 @@ char loptions[128]; /* one for every char */
#endif LINT #endif LINT
extern int idfsize; extern int idfsize;
extern int density;
static int txt2int(); static int txt2int();
@ -291,6 +292,9 @@ next_option: /* to allow combined one-char options */
break; break;
} }
#endif NOCROSS #endif NOCROSS
case 'S':
density = txt2int(&text);
break;
#endif LINT #endif LINT
} }
} }

View file

@ -29,6 +29,8 @@
extern char options[]; extern char options[];
int density = DENSITY;
compact(nr, low, up) compact(nr, low, up)
arith low, up; arith low, up;
{ {
@ -38,7 +40,7 @@ compact(nr, low, up)
*/ */
arith diff = up - low; arith diff = up - low;
return (nr == 0 || (diff >= 0 && diff / nr <= (DENSITY - 1))); return (nr == 0 || (diff >= 0 && diff / nr <= (density - 1)));
} }
static struct switch_hdr *switch_stack = 0; static struct switch_hdr *switch_stack = 0;
@ -103,6 +105,16 @@ code_endswitch()
#ifndef LINT #ifndef LINT
code_expr(sh->sh_expr, RVAL, TRUE, NO_LABEL, NO_LABEL); code_expr(sh->sh_expr, RVAL, TRUE, NO_LABEL, NO_LABEL);
#endif #endif
if (sh->sh_nrofentries <= 1) {
if (sh->sh_nrofentries) {
load_cst(sh->sh_lowerbd, size);
C_cms(size);
C_zeq(sh->sh_entries->ce_label);
}
else C_asp(size);
C_bra(sh->sh_default);
}
else {
tablabel = data_label(); /* the rom must have a label */ tablabel = data_label(); /* the rom must have a label */
C_df_dlb(tablabel); C_df_dlb(tablabel);
C_rom_ilb(sh->sh_default); C_rom_ilb(sh->sh_default);
@ -114,7 +126,6 @@ code_endswitch()
C_rom_icon(long2str((long)(sh->sh_upperbd - sh->sh_lowerbd),10), C_rom_icon(long2str((long)(sh->sh_upperbd - sh->sh_lowerbd),10),
size); size);
ce = sh->sh_entries; ce = sh->sh_entries;
if (sh->sh_nrofentries)
for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) { for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) {
ASSERT(ce); ASSERT(ce);
if (val == ce->ce_value) { if (val == ce->ce_value) {
@ -137,6 +148,7 @@ code_endswitch()
C_lae_dlb(tablabel, (arith)0); /* perform the switch */ C_lae_dlb(tablabel, (arith)0); /* perform the switch */
C_csb(size); C_csb(size);
} }
}
C_df_ilb(sh->sh_break); C_df_ilb(sh->sh_break);
switch_stack = sh->next; /* unstack the switch descriptor */ switch_stack = sh->next; /* unstack the switch descriptor */
for (ce = sh->sh_entries; ce;) { /* free allocated switch structure */ for (ce = sh->sh_entries; ce;) { /* free allocated switch structure */