Another batch..
This commit is contained in:
parent
2bbd5a38de
commit
20d58dea19
@ -5,6 +5,8 @@
|
||||
/* $Id$ */
|
||||
/* L E X I C A L A N A L Y Z E R */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "idfsize.h"
|
||||
#include "numsize.h"
|
||||
#include "strsize.h"
|
||||
@ -23,6 +25,12 @@
|
||||
|
||||
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 AccDefined = 0; /* accept "defined(...)" */
|
||||
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 */
|
||||
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_DOTSEEN 0x02 /* certainly a floating point number */
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ struct token {
|
||||
};
|
||||
|
||||
#include "file_info.h"
|
||||
#include <symbol2str.h>
|
||||
|
||||
#define tk_symb tok_symb
|
||||
#define tk_str tok_data.tok_str
|
||||
@ -41,8 +42,41 @@ extern int NoUnstack; /* buffer.c */
|
||||
|
||||
extern int err_occurred; /* "error.c" */
|
||||
|
||||
struct idf;
|
||||
struct repl;
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
#include "Lpars.h"
|
||||
#include "arith.h"
|
||||
#include "LLlex.h"
|
||||
|
||||
#define arith_sign (1L << (sizeof(arith)*8-1))
|
||||
|
||||
|
||||
@ -587,7 +587,7 @@ int getparams(char *buf[], char parbuf[])
|
||||
|
||||
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
|
||||
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;
|
||||
} else {
|
||||
#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)
|
||||
setbit(bit0);
|
||||
setbit(bit1);
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
#include "print.h"
|
||||
#include "arith.h"
|
||||
#include "errout.h"
|
||||
#include "LLlex.h"
|
||||
|
||||
@ -5,6 +5,9 @@
|
||||
/* $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 */
|
||||
|
||||
#ifndef LANG_CEM_CPP_ANSI_FILE_INFO_H
|
||||
#define LANG_CEM_CPP_ANSI_FILE_INFO_H
|
||||
|
||||
struct file_info {
|
||||
unsigned int fil_lino;
|
||||
char *fil_name;
|
||||
@ -16,3 +19,5 @@ struct file_info {
|
||||
#define WorkingDir finfo.fil_wdir
|
||||
|
||||
extern struct file_info finfo; /* input.c */
|
||||
|
||||
#endif /* LANG_CEM_CPP_ANSI_FILE_INFO_H */
|
||||
@ -13,6 +13,9 @@
|
||||
#include "class.h"
|
||||
#include "macro.h"
|
||||
#include "idf.h"
|
||||
#include "print.h"
|
||||
#include "arith.h"
|
||||
#include "LLlex.h"
|
||||
|
||||
struct mkey {
|
||||
char *mk_reserved;
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
#include <string.h>
|
||||
#include "file_info.h"
|
||||
#include "input.h"
|
||||
#include "arith.h"
|
||||
#include "LLlex.h"
|
||||
|
||||
#define INP_PUSHBACK 3
|
||||
#define INP_TYPE struct file_info
|
||||
|
||||
@ -16,8 +16,9 @@
|
||||
#include "idfsize.h"
|
||||
#include "idf.h"
|
||||
#include "macro.h"
|
||||
#include "print.h"
|
||||
#include "LLlex.h"
|
||||
|
||||
extern char *symbol2str();
|
||||
extern char *getwdir();
|
||||
extern int err_occurred;
|
||||
extern int do_dependencies;
|
||||
|
||||
@ -12,6 +12,8 @@
|
||||
#include "class.h"
|
||||
#include "macro.h"
|
||||
#include "idf.h"
|
||||
#include "arith.h"
|
||||
#include "LLlex.h"
|
||||
|
||||
char options[128]; /* one for every char */
|
||||
int inc_pos = 1; /* place where next -I goes */
|
||||
@ -24,11 +26,13 @@ char *dep_file = 0;
|
||||
|
||||
extern int idfsize;
|
||||
|
||||
int txt2int(char **tp);
|
||||
|
||||
void do_option(char *text)
|
||||
{
|
||||
switch(*text++) {
|
||||
case '-':
|
||||
options[*text] = 1;
|
||||
options[*(unsigned char *)text] = 1;
|
||||
break;
|
||||
case 'u':
|
||||
if (! strcmp(text, "ndef")) {
|
||||
@ -53,19 +57,19 @@ void do_option(char *text)
|
||||
case 'm':
|
||||
case 'o': /* ignore garbage after #else or #endif */
|
||||
case 'C' : /* comment output */
|
||||
options[*(text-1)] = 1;
|
||||
options[*(unsigned char *)(text-1)] = 1;
|
||||
break;
|
||||
case 'D' : /* -Dname : predefine name */
|
||||
{
|
||||
register char *cp = text, *name, *mactext;
|
||||
char *cp = text, *name, *mactext;
|
||||
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);
|
||||
break;
|
||||
}
|
||||
name = cp;
|
||||
while (*cp && in_idf(*cp))
|
||||
while (*cp && in_idf(*(unsigned char *)cp))
|
||||
++cp;
|
||||
if (!*cp) { /* -Dname */
|
||||
maclen = 1;
|
||||
@ -85,8 +89,8 @@ void do_option(char *text)
|
||||
}
|
||||
case 'I' : /* -Ipath : insert "path" into include list */
|
||||
if (*text) {
|
||||
register int i;
|
||||
register char *new = text;
|
||||
int i;
|
||||
char *new = text;
|
||||
|
||||
if (++inc_total > inc_max) {
|
||||
inctable = (char **)
|
||||
@ -130,8 +134,8 @@ int txt2int(char **tp)
|
||||
/* the integer pointed to by *tp is read, while increasing
|
||||
*tp; the resulting value is yielded.
|
||||
*/
|
||||
register int val = 0;
|
||||
register int ch;
|
||||
int val = 0;
|
||||
int ch;
|
||||
|
||||
while (ch = **tp, ch >= '0' && ch <= '9') {
|
||||
val = val * 10 + ch - '0';
|
||||
|
||||
@ -51,11 +51,11 @@ void preprocess(char *fn);
|
||||
|
||||
void do_pragma()
|
||||
{
|
||||
register int size = ITEXTSIZE;
|
||||
int size = ITEXTSIZE;
|
||||
char *cur_line = Malloc((unsigned)size);
|
||||
register char *c_ptr = cur_line;
|
||||
register int c = GetChar();
|
||||
register int delim = 0;
|
||||
char *c_ptr = cur_line;
|
||||
int c = GetChar();
|
||||
int delim = 0;
|
||||
|
||||
while(c != '\n') {
|
||||
if (c_ptr + 1 - cur_line == size) {
|
||||
@ -109,9 +109,9 @@ char Xbuf[256];
|
||||
|
||||
void preprocess(char *fn)
|
||||
{
|
||||
register int c;
|
||||
register char *op = _obuf;
|
||||
register char *ob = &_obuf[OBUFSIZE];
|
||||
int c;
|
||||
char *op = _obuf;
|
||||
char *ob = &_obuf[OBUFSIZE];
|
||||
int lineno = 0;
|
||||
int startline;
|
||||
|
||||
@ -123,7 +123,7 @@ void preprocess(char *fn)
|
||||
/* Generate a line directive communicating the
|
||||
source filename
|
||||
*/
|
||||
register char *p = Xbuf;
|
||||
char *p = Xbuf;
|
||||
|
||||
sprint(p, "%s 1 \"%s\"\n",
|
||||
LINE_PREFIX,
|
||||
@ -138,14 +138,14 @@ void preprocess(char *fn)
|
||||
fn = FileName; \
|
||||
lineno = LineNumber; \
|
||||
if (! options['P']) { \
|
||||
register char *p = Xbuf; \
|
||||
char *p = Xbuf; \
|
||||
sprint(Xbuf, "%s %d \"%s\"\n", \
|
||||
LINE_PREFIX, \
|
||||
(int)LineNumber, \
|
||||
FileName); \
|
||||
op--; \
|
||||
while (op >= _obuf \
|
||||
&& (class(*op) == STSKIP \
|
||||
&& (class(*(unsigned char *)op) == STSKIP \
|
||||
|| *op == '\n')) op--; \
|
||||
op++; \
|
||||
newline(); \
|
||||
@ -163,12 +163,12 @@ void preprocess(char *fn)
|
||||
while (startline) {
|
||||
/* first flush the saved pragma's */
|
||||
if (pragma_nr) {
|
||||
register int i = 0;
|
||||
int i = 0;
|
||||
int LiNo = LineNumber;
|
||||
char *FiNam = FileName;
|
||||
|
||||
while (i < pragma_nr) {
|
||||
register char *c_ptr = "#pragma";
|
||||
char *c_ptr = "#pragma";
|
||||
|
||||
LineNumber = pragma_tab[i].pr_linnr;
|
||||
FileName = pragma_tab[i].pr_fil;
|
||||
@ -252,7 +252,7 @@ void preprocess(char *fn)
|
||||
case STSTR:
|
||||
case STCHAR:
|
||||
{
|
||||
register int stopc = c;
|
||||
int stopc = c;
|
||||
int escaped;
|
||||
|
||||
do {
|
||||
@ -326,9 +326,9 @@ void preprocess(char *fn)
|
||||
case STIDF: {
|
||||
extern int idfsize; /* ??? */
|
||||
char buf[IDFSIZE + 1];
|
||||
register char *tg = &buf[0];
|
||||
register char *maxpos = &buf[idfsize];
|
||||
register struct idf *idef;
|
||||
char *tg = &buf[0];
|
||||
char *maxpos = &buf[idfsize];
|
||||
struct idf *idef;
|
||||
int NoExpandNext = 0;
|
||||
|
||||
#define tstmac(bx) if (!(bits[c] & bx)) goto nomac
|
||||
@ -413,7 +413,7 @@ void preprocess(char *fn)
|
||||
static char *SkipComment(char *op, int *lineno)
|
||||
{
|
||||
char *ob = &_obuf[OBUFSIZE];
|
||||
register int c, oldc = '\0';
|
||||
int c, oldc = '\0';
|
||||
|
||||
NoUnstack++;
|
||||
if (options['C']) {
|
||||
|
||||
@ -35,8 +35,7 @@ void macro_func(struct idf *idef);
|
||||
void macro2buffer(struct repl *repl, struct idf *idf, struct args *args);
|
||||
void add2repl(struct repl *repl, int ch);
|
||||
void stash(struct repl *repl, int ch, int stashraw);
|
||||
|
||||
char *GetIdentifier(int skiponerr); /* domacro.c */
|
||||
int expand_macro(struct repl *repl, 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 */
|
||||
--repl->r_ptr;
|
||||
while (repl->r_ptr >= repl->r_text
|
||||
&& is_wsp(*repl->r_ptr))
|
||||
&& is_wsp(*(unsigned char *)repl->r_ptr))
|
||||
--repl->r_ptr;
|
||||
|
||||
/* ## 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 */
|
||||
|
||||
/* skip space in macro replacement list */
|
||||
while ((*ptr & FORMALP) == 0 && is_wsp(*ptr))
|
||||
while ((*ptr & FORMALP) == 0 && is_wsp(*(unsigned char *)ptr))
|
||||
ptr++;
|
||||
|
||||
/* ## 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);
|
||||
p = args->a_rawvec[n-1];
|
||||
if (p) { /* else macro argument missing */
|
||||
while (is_wsp(*p)) p++;
|
||||
while (is_wsp(*(unsigned char *)p)) p++;
|
||||
if (*p == NOEXPM) p++;
|
||||
while (*p)
|
||||
add2repl(repl, *p++);
|
||||
}
|
||||
while (tmpindex > 0
|
||||
&& in_idf(repl->r_text[tmpindex]))
|
||||
&& in_idf((unsigned char)repl->r_text[tmpindex]))
|
||||
tmpindex--;
|
||||
if (tmpindex >= 0
|
||||
&& repl->r_text[tmpindex] == NOEXPM)
|
||||
@ -625,10 +624,10 @@ void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
||||
err = 1;
|
||||
break;
|
||||
} else {
|
||||
if (in_idf(*ptr)) {
|
||||
if (in_idf(*(unsigned char *)ptr)) {
|
||||
tmpindex--;
|
||||
while (tmpindex > 0
|
||||
&& in_idf(repl->r_text[tmpindex]))
|
||||
&& in_idf((unsigned char)repl->r_text[tmpindex]))
|
||||
tmpindex--;
|
||||
if (tmpindex >= 0
|
||||
&& 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
|
||||
one.
|
||||
*/
|
||||
for (p = ptr; (*p & FORMALP) == 0 && is_wsp(*p); p++)
|
||||
for (p = ptr; (*p & FORMALP) == 0 && is_wsp(*(unsigned char *)p); p++)
|
||||
/* EMPTY */;
|
||||
if (*p == '#' && p[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 \ */
|
||||
|
||||
/* skip spaces macro replacement list */
|
||||
while ((*ptr & FORMALP) == 0 && is_wsp(*ptr))
|
||||
while ((*ptr & FORMALP) == 0 && is_wsp(*(unsigned char *)ptr))
|
||||
ptr++;
|
||||
|
||||
if (*ptr & FORMALP) {
|
||||
@ -701,7 +700,7 @@ char *stringify(struct repl *repl, char *ptr, struct args *args)
|
||||
p = args->a_rawvec[n-1];
|
||||
add2repl(repl, '"');
|
||||
while (*p) {
|
||||
if (is_wsp(*p)) {
|
||||
if (is_wsp(*(unsigned char *)p)) {
|
||||
if (!space) {
|
||||
space = 1;
|
||||
add2repl(repl, ' ');
|
||||
@ -723,7 +722,7 @@ char *stringify(struct repl *repl, char *ptr, struct args *args)
|
||||
}
|
||||
|
||||
/* 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 */;
|
||||
++repl->r_ptr; /* oops, one to far */
|
||||
add2repl(repl, '"');
|
||||
|
||||
@ -12,14 +12,12 @@
|
||||
|
||||
extern int InputLevel;
|
||||
|
||||
int
|
||||
skipspaces(ch, skipnl)
|
||||
register int ch;
|
||||
int skipspaces(int ch, int skipnl)
|
||||
{
|
||||
/* skipspaces() skips any white space and returns the first
|
||||
non-space character.
|
||||
*/
|
||||
register int nlseen = 0;
|
||||
int nlseen = 0;
|
||||
|
||||
for (;;) {
|
||||
while (class(ch) == STSKIP)
|
||||
@ -56,11 +54,11 @@ skipspaces(ch, skipnl)
|
||||
}
|
||||
}
|
||||
|
||||
SkipToNewLine()
|
||||
int SkipToNewLine()
|
||||
{
|
||||
register int ch;
|
||||
register int garbage = 0;
|
||||
register int delim = 0;
|
||||
int ch;
|
||||
int garbage = 0;
|
||||
int delim = 0;
|
||||
|
||||
while ((ch = GetChar()) != '\n') {
|
||||
if (delim) {
|
||||
|
||||
@ -72,6 +72,9 @@ void init_pp();
|
||||
void do_option(char *text);
|
||||
void preprocess(char *fn);
|
||||
void domacro();
|
||||
int rank_of(int oper);
|
||||
char *GetIdentifier();
|
||||
char **getactuals(struct idf *idef);
|
||||
|
||||
/* External */
|
||||
int InsertFile(char *, char **, char **);
|
||||
@ -7,9 +7,7 @@
|
||||
|
||||
#include "Lpars.h"
|
||||
|
||||
int
|
||||
rank_of(oper)
|
||||
int oper;
|
||||
int rank_of(int oper)
|
||||
{
|
||||
/* The rank of the operator oper is returned.
|
||||
*/
|
||||
|
||||
@ -26,9 +26,6 @@ static struct mlist *ReplList; /* list of currently active macros */
|
||||
static char *macro2buffer(struct idf *idef, char **actpars, int *siztext);
|
||||
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 */
|
||||
|
||||
int replace(struct idf *idef)
|
||||
@ -42,11 +39,11 @@ int replace(struct idf *idef)
|
||||
replace() returns 1 if the replacement succeeded and 0 if
|
||||
some error has occurred.
|
||||
*/
|
||||
register struct macro *mac = idef->id_macro;
|
||||
register char c;
|
||||
struct macro *mac = idef->id_macro;
|
||||
char c;
|
||||
char **actpars;
|
||||
char *reptext;
|
||||
register struct mlist *repl;
|
||||
struct mlist *repl;
|
||||
int size;
|
||||
|
||||
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
|
||||
used.
|
||||
*/
|
||||
register struct macro *mac = idef->id_macro;
|
||||
struct macro *mac = idef->id_macro;
|
||||
|
||||
switch (idef->id_text[2]) { /* This switch is very blunt... */
|
||||
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
|
||||
the same as strcpy().
|
||||
*/
|
||||
register unsigned int size = idef->id_macro->mc_length + ITEXTSIZE;
|
||||
register char *text = Malloc(size);
|
||||
register int pos = 0;
|
||||
register char *ptr = idef->id_macro->mc_text;
|
||||
unsigned int size = idef->id_macro->mc_length + ITEXTSIZE;
|
||||
char *text = Malloc(size);
|
||||
int pos = 0;
|
||||
char *ptr = idef->id_macro->mc_text;
|
||||
|
||||
while (*ptr) {
|
||||
if (*ptr & FORMALP) { /* non-asc formal param. mark */
|
||||
register int n = *ptr++ & 0177;
|
||||
register char *p;
|
||||
int n = *ptr++ & 0177;
|
||||
char *p;
|
||||
|
||||
assert(n != 0);
|
||||
/* copy the text of the actual parameter
|
||||
@ -217,7 +214,7 @@ void DoUnstack()
|
||||
|
||||
void EnableMacros()
|
||||
{
|
||||
register struct mlist *p = ReplList, *prev = 0;
|
||||
struct mlist *p = ReplList, *prev = 0;
|
||||
|
||||
assert(Unstacked > 0);
|
||||
while (p) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user