Another batch..

This commit is contained in:
Manoel Trapier
2013-03-18 19:50:01 +01:00
committed by Manoël Trapier
parent 2bbd5a38de
commit 20d58dea19
16 changed files with 120 additions and 69 deletions

View File

@@ -5,6 +5,8 @@
/* $Id$ */ /* $Id$ */
/* L E X I C A L A N A L Y Z E R */ /* L E X I C A L A N A L Y Z E R */
#include <string.h>
#include "idfsize.h" #include "idfsize.h"
#include "numsize.h" #include "numsize.h"
#include "strsize.h" #include "strsize.h"
@@ -23,6 +25,12 @@
struct token dot; struct token dot;
char *string_token(char *nm, int stop_char);
arith char_constant(char *nm);
int val_in_base(int ch, int base);
int quoted(int ch);
int trigraph();
int ReplaceMacros = 1; /* replacing macros */ int ReplaceMacros = 1; /* replacing macros */
int AccDefined = 0; /* accept "defined(...)" */ int AccDefined = 0; /* accept "defined(...)" */
int UnknownIdIsZero = 0; /* interpret unknown id as integer 0 */ int UnknownIdIsZero = 0; /* interpret unknown id as integer 0 */
@@ -31,9 +39,6 @@ int AccFileSpecifier = 0; /* return filespecifier <...> */
int LexSave = 0; /* last character read by GetChar */ int LexSave = 0; /* last character read by GetChar */
extern int InputLevel; /* # of current macro expansions */ extern int InputLevel; /* # of current macro expansions */
extern char *string_token();
extern char *strcpy();
extern arith char_constant();
#define FLG_ESEEN 0x01 /* possibly a floating point number */ #define FLG_ESEEN 0x01 /* possibly a floating point number */
#define FLG_DOTSEEN 0x02 /* certainly a floating point number */ #define FLG_DOTSEEN 0x02 /* certainly a floating point number */

View File

@@ -23,6 +23,7 @@ struct token {
}; };
#include "file_info.h" #include "file_info.h"
#include <symbol2str.h>
#define tk_symb tok_symb #define tk_symb tok_symb
#define tk_str tok_data.tok_str #define tk_str tok_data.tok_str
@@ -41,8 +42,41 @@ extern int NoUnstack; /* buffer.c */
extern int err_occurred; /* "error.c" */ extern int err_occurred; /* "error.c" */
struct idf;
struct repl;
void skipcomment(); void skipcomment();
void fatal(char *fmt, ...);
void error(char *fmt, ...);
void warning(char *fmt, ...);
void strict(char *fmt, ...);
void crash(char *fmt, ...);
int GetToken(struct token *ptok);
void EnableMacros();
int replace(struct idf *idf);
int skipspaces(int ch, int skipnl);
int SkipToNewLine();
void do_pragma();
int ifexpr();
void If_expr(void);
void add_dependency(char *s);
int getparams(char *buf[], char parbuf[]);
int macroeq(char *s, char *t);
void add2repl(struct repl *repl, int ch);
char *GetIdentifier(int skiponerr);
void macro_def(struct idf *id, char *text, int nformals, int length, int flags);
void unstackrepl();
void init_pp();
void do_option(char *text);
void preprocess(char *fn);
void do_undef(char *argstr);
void domacro();
int actual(struct repl *repl);
void ch3mon(int oper, arith *pval, int *puns);
int rank_of(int oper);
void ch3bin(arith *pval, int *pis_uns, int oper, arith val, int is_uns);
/* External */
int InsertFile(char *, char **, char **);
#define DOT dot.tk_symb #define DOT dot.tk_symb

View File

@@ -7,6 +7,7 @@
#include "Lpars.h" #include "Lpars.h"
#include "arith.h" #include "arith.h"
#include "LLlex.h"
#define arith_sign (1L << (sizeof(arith)*8-1)) #define arith_sign (1L << (sizeof(arith)*8-1))

View File

@@ -587,7 +587,7 @@ int getparams(char *buf[], char parbuf[])
void macro_def(struct idf *id, char *text, int nformals, int length, int flags) void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
{ {
register struct macro *newdef = id->id_macro; struct macro *newdef = id->id_macro;
/* macro_def() puts the contents and information of a macro /* macro_def() puts the contents and information of a macro
definition into a structure and stores it into the symbol definition into a structure and stores it into the symbol
@@ -603,7 +603,7 @@ void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
return; return;
} else { } else {
#ifdef DOBITS #ifdef DOBITS
register char *p = id->id_text; unsigned char *p = (unsigned char *)id->id_text;
#define setbit(bx) if (!*p) goto go_on; bits[*p++] |= (bx) #define setbit(bx) if (!*p) goto go_on; bits[*p++] |= (bx)
setbit(bit0); setbit(bit0);
setbit(bit1); setbit(bit1);

View File

@@ -12,6 +12,7 @@
#include <varargs.h> #include <varargs.h>
#endif #endif
#include "print.h"
#include "arith.h" #include "arith.h"
#include "errout.h" #include "errout.h"
#include "LLlex.h" #include "LLlex.h"

View File

@@ -5,6 +5,9 @@
/* $Id$ */ /* $Id$ */
/* F I L E I N F O R M A T I O N S T R U C T U R E */ /* F I L E I N F O R M A T I O N S T R U C T U R E */
#ifndef LANG_CEM_CPP_ANSI_FILE_INFO_H
#define LANG_CEM_CPP_ANSI_FILE_INFO_H
struct file_info { struct file_info {
unsigned int fil_lino; unsigned int fil_lino;
char *fil_name; char *fil_name;
@@ -16,3 +19,5 @@ struct file_info {
#define WorkingDir finfo.fil_wdir #define WorkingDir finfo.fil_wdir
extern struct file_info finfo; /* input.c */ extern struct file_info finfo; /* input.c */
#endif /* LANG_CEM_CPP_ANSI_FILE_INFO_H */

View File

@@ -13,6 +13,9 @@
#include "class.h" #include "class.h"
#include "macro.h" #include "macro.h"
#include "idf.h" #include "idf.h"
#include "print.h"
#include "arith.h"
#include "LLlex.h"
struct mkey { struct mkey {
char *mk_reserved; char *mk_reserved;

View File

@@ -9,6 +9,8 @@
#include <string.h> #include <string.h>
#include "file_info.h" #include "file_info.h"
#include "input.h" #include "input.h"
#include "arith.h"
#include "LLlex.h"
#define INP_PUSHBACK 3 #define INP_PUSHBACK 3
#define INP_TYPE struct file_info #define INP_TYPE struct file_info

View File

@@ -16,8 +16,9 @@
#include "idfsize.h" #include "idfsize.h"
#include "idf.h" #include "idf.h"
#include "macro.h" #include "macro.h"
#include "print.h"
#include "LLlex.h"
extern char *symbol2str();
extern char *getwdir(); extern char *getwdir();
extern int err_occurred; extern int err_occurred;
extern int do_dependencies; extern int do_dependencies;

View File

@@ -12,6 +12,8 @@
#include "class.h" #include "class.h"
#include "macro.h" #include "macro.h"
#include "idf.h" #include "idf.h"
#include "arith.h"
#include "LLlex.h"
char options[128]; /* one for every char */ char options[128]; /* one for every char */
int inc_pos = 1; /* place where next -I goes */ int inc_pos = 1; /* place where next -I goes */
@@ -24,11 +26,13 @@ char *dep_file = 0;
extern int idfsize; extern int idfsize;
int txt2int(char **tp);
void do_option(char *text) void do_option(char *text)
{ {
switch(*text++) { switch(*text++) {
case '-': case '-':
options[*text] = 1; options[*(unsigned char *)text] = 1;
break; break;
case 'u': case 'u':
if (! strcmp(text, "ndef")) { if (! strcmp(text, "ndef")) {
@@ -53,19 +57,19 @@ void do_option(char *text)
case 'm': case 'm':
case 'o': /* ignore garbage after #else or #endif */ case 'o': /* ignore garbage after #else or #endif */
case 'C' : /* comment output */ case 'C' : /* comment output */
options[*(text-1)] = 1; options[*(unsigned char *)(text-1)] = 1;
break; break;
case 'D' : /* -Dname : predefine name */ case 'D' : /* -Dname : predefine name */
{ {
register char *cp = text, *name, *mactext; char *cp = text, *name, *mactext;
unsigned maclen; unsigned maclen;
if (class(*cp) != STIDF && class(*cp) != STELL) { if (class(*(unsigned char *)cp) != STIDF && class(*(unsigned char *)cp) != STELL) {
error("identifier missing in -D%s", text); error("identifier missing in -D%s", text);
break; break;
} }
name = cp; name = cp;
while (*cp && in_idf(*cp)) while (*cp && in_idf(*(unsigned char *)cp))
++cp; ++cp;
if (!*cp) { /* -Dname */ if (!*cp) { /* -Dname */
maclen = 1; maclen = 1;
@@ -85,8 +89,8 @@ void do_option(char *text)
} }
case 'I' : /* -Ipath : insert "path" into include list */ case 'I' : /* -Ipath : insert "path" into include list */
if (*text) { if (*text) {
register int i; int i;
register char *new = text; char *new = text;
if (++inc_total > inc_max) { if (++inc_total > inc_max) {
inctable = (char **) inctable = (char **)
@@ -130,8 +134,8 @@ int txt2int(char **tp)
/* the integer pointed to by *tp is read, while increasing /* the integer pointed to by *tp is read, while increasing
*tp; the resulting value is yielded. *tp; the resulting value is yielded.
*/ */
register int val = 0; int val = 0;
register int ch; int ch;
while (ch = **tp, ch >= '0' && ch <= '9') { while (ch = **tp, ch >= '0' && ch <= '9') {
val = val * 10 + ch - '0'; val = val * 10 + ch - '0';

View File

@@ -51,11 +51,11 @@ void preprocess(char *fn);
void do_pragma() void do_pragma()
{ {
register int size = ITEXTSIZE; int size = ITEXTSIZE;
char *cur_line = Malloc((unsigned)size); char *cur_line = Malloc((unsigned)size);
register char *c_ptr = cur_line; char *c_ptr = cur_line;
register int c = GetChar(); int c = GetChar();
register int delim = 0; int delim = 0;
while(c != '\n') { while(c != '\n') {
if (c_ptr + 1 - cur_line == size) { if (c_ptr + 1 - cur_line == size) {
@@ -109,9 +109,9 @@ char Xbuf[256];
void preprocess(char *fn) void preprocess(char *fn)
{ {
register int c; int c;
register char *op = _obuf; char *op = _obuf;
register char *ob = &_obuf[OBUFSIZE]; char *ob = &_obuf[OBUFSIZE];
int lineno = 0; int lineno = 0;
int startline; int startline;
@@ -123,7 +123,7 @@ void preprocess(char *fn)
/* Generate a line directive communicating the /* Generate a line directive communicating the
source filename source filename
*/ */
register char *p = Xbuf; char *p = Xbuf;
sprint(p, "%s 1 \"%s\"\n", sprint(p, "%s 1 \"%s\"\n",
LINE_PREFIX, LINE_PREFIX,
@@ -138,14 +138,14 @@ void preprocess(char *fn)
fn = FileName; \ fn = FileName; \
lineno = LineNumber; \ lineno = LineNumber; \
if (! options['P']) { \ if (! options['P']) { \
register char *p = Xbuf; \ char *p = Xbuf; \
sprint(Xbuf, "%s %d \"%s\"\n", \ sprint(Xbuf, "%s %d \"%s\"\n", \
LINE_PREFIX, \ LINE_PREFIX, \
(int)LineNumber, \ (int)LineNumber, \
FileName); \ FileName); \
op--; \ op--; \
while (op >= _obuf \ while (op >= _obuf \
&& (class(*op) == STSKIP \ && (class(*(unsigned char *)op) == STSKIP \
|| *op == '\n')) op--; \ || *op == '\n')) op--; \
op++; \ op++; \
newline(); \ newline(); \
@@ -163,12 +163,12 @@ void preprocess(char *fn)
while (startline) { while (startline) {
/* first flush the saved pragma's */ /* first flush the saved pragma's */
if (pragma_nr) { if (pragma_nr) {
register int i = 0; int i = 0;
int LiNo = LineNumber; int LiNo = LineNumber;
char *FiNam = FileName; char *FiNam = FileName;
while (i < pragma_nr) { while (i < pragma_nr) {
register char *c_ptr = "#pragma"; char *c_ptr = "#pragma";
LineNumber = pragma_tab[i].pr_linnr; LineNumber = pragma_tab[i].pr_linnr;
FileName = pragma_tab[i].pr_fil; FileName = pragma_tab[i].pr_fil;
@@ -252,7 +252,7 @@ void preprocess(char *fn)
case STSTR: case STSTR:
case STCHAR: case STCHAR:
{ {
register int stopc = c; int stopc = c;
int escaped; int escaped;
do { do {
@@ -326,9 +326,9 @@ void preprocess(char *fn)
case STIDF: { case STIDF: {
extern int idfsize; /* ??? */ extern int idfsize; /* ??? */
char buf[IDFSIZE + 1]; char buf[IDFSIZE + 1];
register char *tg = &buf[0]; char *tg = &buf[0];
register char *maxpos = &buf[idfsize]; char *maxpos = &buf[idfsize];
register struct idf *idef; struct idf *idef;
int NoExpandNext = 0; int NoExpandNext = 0;
#define tstmac(bx) if (!(bits[c] & bx)) goto nomac #define tstmac(bx) if (!(bits[c] & bx)) goto nomac
@@ -413,7 +413,7 @@ void preprocess(char *fn)
static char *SkipComment(char *op, int *lineno) static char *SkipComment(char *op, int *lineno)
{ {
char *ob = &_obuf[OBUFSIZE]; char *ob = &_obuf[OBUFSIZE];
register int c, oldc = '\0'; int c, oldc = '\0';
NoUnstack++; NoUnstack++;
if (options['C']) { if (options['C']) {

View File

@@ -35,8 +35,7 @@ void macro_func(struct idf *idef);
void macro2buffer(struct repl *repl, struct idf *idf, struct args *args); void macro2buffer(struct repl *repl, struct idf *idf, struct args *args);
void add2repl(struct repl *repl, int ch); void add2repl(struct repl *repl, int ch);
void stash(struct repl *repl, int ch, int stashraw); void stash(struct repl *repl, int ch, int stashraw);
int expand_macro(struct repl *repl, struct idf *idf);
char *GetIdentifier(int skiponerr); /* domacro.c */
int replace(struct idf *idf) int replace(struct idf *idf)
{ {
@@ -579,7 +578,7 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
/* trim the actual replacement list */ /* trim the actual replacement list */
--repl->r_ptr; --repl->r_ptr;
while (repl->r_ptr >= repl->r_text while (repl->r_ptr >= repl->r_text
&& is_wsp(*repl->r_ptr)) && is_wsp(*(unsigned char *)repl->r_ptr))
--repl->r_ptr; --repl->r_ptr;
/* ## occurred at the beginning of the replacement list. /* ## occurred at the beginning of the replacement list.
@@ -598,7 +597,7 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
/* tmpindex can be 0 */ /* tmpindex can be 0 */
/* skip space in macro replacement list */ /* skip space in macro replacement list */
while ((*ptr & FORMALP) == 0 && is_wsp(*ptr)) while ((*ptr & FORMALP) == 0 && is_wsp(*(unsigned char *)ptr))
ptr++; ptr++;
/* ## occurred at the end of the replacement list. /* ## occurred at the end of the replacement list.
@@ -610,13 +609,13 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
assert(n > 0); assert(n > 0);
p = args->a_rawvec[n-1]; p = args->a_rawvec[n-1];
if (p) { /* else macro argument missing */ if (p) { /* else macro argument missing */
while (is_wsp(*p)) p++; while (is_wsp(*(unsigned char *)p)) p++;
if (*p == NOEXPM) p++; if (*p == NOEXPM) p++;
while (*p) while (*p)
add2repl(repl, *p++); add2repl(repl, *p++);
} }
while (tmpindex > 0 while (tmpindex > 0
&& in_idf(repl->r_text[tmpindex])) && in_idf((unsigned char)repl->r_text[tmpindex]))
tmpindex--; tmpindex--;
if (tmpindex >= 0 if (tmpindex >= 0
&& repl->r_text[tmpindex] == NOEXPM) && repl->r_text[tmpindex] == NOEXPM)
@@ -625,10 +624,10 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
err = 1; err = 1;
break; break;
} else { } else {
if (in_idf(*ptr)) { if (in_idf(*(unsigned char *)ptr)) {
tmpindex--; tmpindex--;
while (tmpindex > 0 while (tmpindex > 0
&& in_idf(repl->r_text[tmpindex])) && in_idf((unsigned char)repl->r_text[tmpindex]))
tmpindex--; tmpindex--;
if (tmpindex >= 0 if (tmpindex >= 0
&& repl->r_text[tmpindex] == NOEXPM) && repl->r_text[tmpindex] == NOEXPM)
@@ -650,7 +649,7 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
argument buffer instead of the expanded argument buffer instead of the expanded
one. one.
*/ */
for (p = ptr; (*p & FORMALP) == 0 && is_wsp(*p); p++) for (p = ptr; (*p & FORMALP) == 0 && is_wsp(*(unsigned char *)p); p++)
/* EMPTY */; /* EMPTY */;
if (*p == '#' && p[1] == '#') if (*p == '#' && p[1] == '#')
q = args->a_rawvec[n-1]; q = args->a_rawvec[n-1];
@@ -690,7 +689,7 @@ char *stringify(struct repl *repl, char *ptr, struct args *args)
register int backslash = 0; /* last character was a \ */ register int backslash = 0; /* last character was a \ */
/* skip spaces macro replacement list */ /* skip spaces macro replacement list */
while ((*ptr & FORMALP) == 0 && is_wsp(*ptr)) while ((*ptr & FORMALP) == 0 && is_wsp(*(unsigned char *)ptr))
ptr++; ptr++;
if (*ptr & FORMALP) { if (*ptr & FORMALP) {
@@ -701,7 +700,7 @@ char *stringify(struct repl *repl, char *ptr, struct args *args)
p = args->a_rawvec[n-1]; p = args->a_rawvec[n-1];
add2repl(repl, '"'); add2repl(repl, '"');
while (*p) { while (*p) {
if (is_wsp(*p)) { if (is_wsp(*(unsigned char *)p)) {
if (!space) { if (!space) {
space = 1; space = 1;
add2repl(repl, ' '); add2repl(repl, ' ');
@@ -723,7 +722,7 @@ char *stringify(struct repl *repl, char *ptr, struct args *args)
} }
/* trim spaces in the replacement list */ /* trim spaces in the replacement list */
for (--repl->r_ptr; is_wsp(*repl->r_ptr); repl->r_ptr--) for (--repl->r_ptr; is_wsp(*(unsigned char *)repl->r_ptr); repl->r_ptr--)
/* EMPTY */; /* EMPTY */;
++repl->r_ptr; /* oops, one to far */ ++repl->r_ptr; /* oops, one to far */
add2repl(repl, '"'); add2repl(repl, '"');

View File

@@ -12,14 +12,12 @@
extern int InputLevel; extern int InputLevel;
int int skipspaces(int ch, int skipnl)
skipspaces(ch, skipnl)
register int ch;
{ {
/* skipspaces() skips any white space and returns the first /* skipspaces() skips any white space and returns the first
non-space character. non-space character.
*/ */
register int nlseen = 0; int nlseen = 0;
for (;;) { for (;;) {
while (class(ch) == STSKIP) while (class(ch) == STSKIP)
@@ -56,11 +54,11 @@ skipspaces(ch, skipnl)
} }
} }
SkipToNewLine() int SkipToNewLine()
{ {
register int ch; int ch;
register int garbage = 0; int garbage = 0;
register int delim = 0; int delim = 0;
while ((ch = GetChar()) != '\n') { while ((ch = GetChar()) != '\n') {
if (delim) { if (delim) {

View File

@@ -72,6 +72,9 @@ void init_pp();
void do_option(char *text); void do_option(char *text);
void preprocess(char *fn); void preprocess(char *fn);
void domacro(); void domacro();
int rank_of(int oper);
char *GetIdentifier();
char **getactuals(struct idf *idef);
/* External */ /* External */
int InsertFile(char *, char **, char **); int InsertFile(char *, char **, char **);

View File

@@ -7,9 +7,7 @@
#include "Lpars.h" #include "Lpars.h"
int int rank_of(int oper)
rank_of(oper)
int oper;
{ {
/* The rank of the operator oper is returned. /* The rank of the operator oper is returned.
*/ */

View File

@@ -26,9 +26,6 @@ static struct mlist *ReplList; /* list of currently active macros */
static char *macro2buffer(struct idf *idef, char **actpars, int *siztext); static char *macro2buffer(struct idf *idef, char **actpars, int *siztext);
static void macro_func(struct idf *idef); static void macro_func(struct idf *idef);
char *GetIdentifier(); /* domacro.c */
char **getactuals(struct idf *idef); /* scan.c */
char *long2str(long value, int base); /* External lib */ char *long2str(long value, int base); /* External lib */
int replace(struct idf *idef) int replace(struct idf *idef)
@@ -42,11 +39,11 @@ int replace(struct idf *idef)
replace() returns 1 if the replacement succeeded and 0 if replace() returns 1 if the replacement succeeded and 0 if
some error has occurred. some error has occurred.
*/ */
register struct macro *mac = idef->id_macro; struct macro *mac = idef->id_macro;
register char c; char c;
char **actpars; char **actpars;
char *reptext; char *reptext;
register struct mlist *repl; struct mlist *repl;
int size; int size;
if (mac->mc_flag & NOREPLACE) { if (mac->mc_flag & NOREPLACE) {
@@ -146,7 +143,7 @@ static void macro_func(struct idf *idef)
replacement texts must be evaluated at the time they are replacement texts must be evaluated at the time they are
used. used.
*/ */
register struct macro *mac = idef->id_macro; struct macro *mac = idef->id_macro;
switch (idef->id_text[2]) { /* This switch is very blunt... */ switch (idef->id_text[2]) { /* This switch is very blunt... */
case 'F' : /* __FILE__ */ case 'F' : /* __FILE__ */
@@ -179,15 +176,15 @@ static char *macro2buffer(struct idf *idef, char **actpars, int *siztext)
If there are no parameters, this function behaves If there are no parameters, this function behaves
the same as strcpy(). the same as strcpy().
*/ */
register unsigned int size = idef->id_macro->mc_length + ITEXTSIZE; unsigned int size = idef->id_macro->mc_length + ITEXTSIZE;
register char *text = Malloc(size); char *text = Malloc(size);
register int pos = 0; int pos = 0;
register char *ptr = idef->id_macro->mc_text; char *ptr = idef->id_macro->mc_text;
while (*ptr) { while (*ptr) {
if (*ptr & FORMALP) { /* non-asc formal param. mark */ if (*ptr & FORMALP) { /* non-asc formal param. mark */
register int n = *ptr++ & 0177; int n = *ptr++ & 0177;
register char *p; char *p;
assert(n != 0); assert(n != 0);
/* copy the text of the actual parameter /* copy the text of the actual parameter
@@ -217,7 +214,7 @@ void DoUnstack()
void EnableMacros() void EnableMacros()
{ {
register struct mlist *p = ReplList, *prev = 0; struct mlist *p = ReplList, *prev = 0;
assert(Unstacked > 0); assert(Unstacked > 0);
while (p) { while (p) {