|
@@ -17,26 +17,28 @@
|
|
|
#include "nparams.h"
|
|
|
#include "idfsize.h"
|
|
|
#include "numsize.h"
|
|
|
+#include "arith.h"
|
|
|
#include <alloc.h>
|
|
|
#include "idf.h"
|
|
|
+#include "idf_loc.h"
|
|
|
#include "input.h"
|
|
|
#include "macro.h"
|
|
|
-#include "arith.h"
|
|
|
#include "LLlex.h"
|
|
|
#include "class.h"
|
|
|
#include "assert.h"
|
|
|
#include "static.h"
|
|
|
#include "macbuf.h"
|
|
|
#include "replace.h"
|
|
|
+#include "replace_loc.h"
|
|
|
+#include "error.h"
|
|
|
+#include "skip.h"
|
|
|
+#include "domacro.h"
|
|
|
+#include "replace_loc.h"
|
|
|
|
|
|
-extern struct idf *GetIdentifier();
|
|
|
extern int InputLevel;
|
|
|
struct repl *ReplaceList; /* list of currently active macros */
|
|
|
-//extern char *strcat(), *strcpy();
|
|
|
|
|
|
-int
|
|
|
-replace(idf)
|
|
|
- register struct idf *idf;
|
|
|
+int replace(struct idf *idf)
|
|
|
{
|
|
|
/* replace is called by the lexical analyzer to perform
|
|
|
macro replacement. The routine actualy functions as a
|
|
@@ -62,15 +64,14 @@ replace(idf)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-unstackrepl()
|
|
|
+void unstackrepl()
|
|
|
{
|
|
|
Unstacked++;
|
|
|
}
|
|
|
|
|
|
-freeargs(args)
|
|
|
- struct args *args;
|
|
|
+void freeargs(struct args *args)
|
|
|
{
|
|
|
- register int i;
|
|
|
+ int i;
|
|
|
|
|
|
/* We must don't know how many parameters were specified, so be
|
|
|
* prepared to free all NPARAMS parameters.
|
|
@@ -86,9 +87,9 @@ freeargs(args)
|
|
|
free_args(args);
|
|
|
}
|
|
|
|
|
|
-EnableMacros()
|
|
|
+void EnableMacros()
|
|
|
{
|
|
|
- register struct repl *r = ReplaceList, *prev = 0;
|
|
|
+ struct repl *r = ReplaceList, *prev = 0;
|
|
|
|
|
|
ASSERT(Unstacked > 0);
|
|
|
while(r) {
|
|
@@ -108,9 +109,7 @@ EnableMacros()
|
|
|
Unstacked = 0;
|
|
|
}
|
|
|
|
|
|
-expand_macro(repl, idf)
|
|
|
- register struct repl *repl;
|
|
|
- register struct idf *idf;
|
|
|
+int expand_macro(struct repl *repl, struct idf *idf)
|
|
|
{
|
|
|
/* expand_macro() does the actual macro replacement.
|
|
|
"idf" is a description of the identifier which
|
|
@@ -129,9 +128,9 @@ expand_macro(repl, idf)
|
|
|
on a single, unexpanded identifier, which may be surrounded
|
|
|
by parenthesis. The function expand_defined() handles this.
|
|
|
*/
|
|
|
- register struct macro *mac = idf->id_macro;
|
|
|
+ struct macro *mac = idf->id_macro;
|
|
|
struct args *args = repl->r_args;
|
|
|
- register int ch;
|
|
|
+ int ch;
|
|
|
|
|
|
if (mac->mc_nps != -1) { /* with parameter list */
|
|
|
if (mac->mc_flag & FUNC) {
|
|
@@ -180,10 +179,9 @@ expand_macro(repl, idf)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-expand_defined(repl)
|
|
|
- register struct repl *repl;
|
|
|
+void expand_defined(struct repl *repl)
|
|
|
{
|
|
|
- register int ch = GetChar();
|
|
|
+ int ch = GetChar();
|
|
|
struct idf *id;
|
|
|
int parens = 0;
|
|
|
|
|
@@ -212,25 +210,22 @@ expand_defined(repl)
|
|
|
add2repl(repl, ' ');
|
|
|
}
|
|
|
|
|
|
-newarg(args)
|
|
|
- struct args *args;
|
|
|
+void newarg(struct args *args)
|
|
|
{
|
|
|
args->a_expptr = args->a_expbuf = Malloc(args->a_expsize = ARGBUF);
|
|
|
args->a_rawptr = args->a_rawbuf = Malloc(args->a_rawsize = ARGBUF);
|
|
|
}
|
|
|
|
|
|
-getactuals(repl, idf)
|
|
|
- struct repl *repl;
|
|
|
- register struct idf *idf;
|
|
|
+void getactuals(struct repl *repl, struct idf *idf)
|
|
|
{
|
|
|
/* Get the actual parameters from the input stream.
|
|
|
The hard part is done by actual(), only comma's and
|
|
|
other syntactic trivialities are checked here.
|
|
|
*/
|
|
|
- register struct args *args = repl->r_args;
|
|
|
- register int nps = idf->id_macro->mc_nps;
|
|
|
- register int argcnt;
|
|
|
- register int ch;
|
|
|
+ struct args *args = repl->r_args;
|
|
|
+ int nps = idf->id_macro->mc_nps;
|
|
|
+ int argcnt;
|
|
|
+ int ch;
|
|
|
|
|
|
argcnt = 0;
|
|
|
newarg(args);
|
|
@@ -262,12 +257,11 @@ getactuals(repl, idf)
|
|
|
lexerror("too many macro arguments");
|
|
|
}
|
|
|
|
|
|
-saveraw(repl)
|
|
|
-struct repl *repl;
|
|
|
+void saveraw(struct repl *repl)
|
|
|
{
|
|
|
- register struct repl *nrepl = ReplaceList;
|
|
|
- register struct args *ap = nrepl->r_args;
|
|
|
- register char *p;
|
|
|
+ struct repl *nrepl = ReplaceList;
|
|
|
+ struct args *ap = nrepl->r_args;
|
|
|
+ char *p;
|
|
|
|
|
|
/* stash identifier name */
|
|
|
for (p = nrepl->r_idf->id_text; *p != '\0'; p++)
|
|
@@ -288,7 +282,7 @@ struct repl *repl;
|
|
|
*/
|
|
|
if (ap->a_rawvec[0]) {
|
|
|
/* stash arguments */
|
|
|
- register int i;
|
|
|
+ int i;
|
|
|
|
|
|
for (i = 0; ap->a_rawvec[i] != (char *)0; i++) {
|
|
|
if (i == 0) stash(repl, '(', -1);
|
|
@@ -300,16 +294,14 @@ struct repl *repl;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int
|
|
|
-actual(repl)
|
|
|
- struct repl *repl;
|
|
|
+int actual(struct repl *repl)
|
|
|
{
|
|
|
/* This routine deals with the scanning of an actual parameter.
|
|
|
It keeps in account the opening and closing brackets,
|
|
|
preprocessor numbers, strings and character constants.
|
|
|
*/
|
|
|
- register int ch = 0;
|
|
|
- register int level = 0, nostashraw = 0;
|
|
|
+ int ch = 0;
|
|
|
+ int level = 0, nostashraw = 0;
|
|
|
int lastch;
|
|
|
static int Unstacked_missed;
|
|
|
|
|
@@ -335,9 +327,9 @@ actual(repl)
|
|
|
token is a macro, it is expanded first.
|
|
|
*/
|
|
|
char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1];
|
|
|
- register char *p = buf;
|
|
|
- register struct idf *idef;
|
|
|
- register int pos = -1;
|
|
|
+ char *p = buf;
|
|
|
+ struct idf *idef;
|
|
|
+ int pos = -1;
|
|
|
extern int idfsize;
|
|
|
int NoExpandMacro;
|
|
|
|
|
@@ -478,7 +470,7 @@ a_new_line: ch = GetChar();
|
|
|
/* Strings are considered as ONE token, thus no
|
|
|
replacement within strings.
|
|
|
*/
|
|
|
- register int match = ch;
|
|
|
+ int match = ch;
|
|
|
|
|
|
stash(repl, ch, !nostashraw);
|
|
|
while ((ch = GetChar()) != EOI) {
|
|
@@ -507,15 +499,14 @@ a_new_line: ch = GetChar();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-macro_func(idef)
|
|
|
- register struct idf *idef;
|
|
|
+void macro_func(struct idf *idef)
|
|
|
{
|
|
|
/* macro_func() performs the special actions needed with some
|
|
|
macros. These macros are __FILE__ and __LINE__ which
|
|
|
replacement texts must be evaluated at the time they are
|
|
|
used.
|
|
|
*/
|
|
|
- register struct macro *mac = idef->id_macro;
|
|
|
+ struct macro *mac = idef->id_macro;
|
|
|
static char FilNamBuf[PATHLENGTH];
|
|
|
char *long2str();
|
|
|
|
|
@@ -537,10 +528,7 @@ macro_func(idef)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-macro2buffer(repl, idf, args)
|
|
|
- register struct repl *repl;
|
|
|
- register struct idf *idf;
|
|
|
- register struct args *args;
|
|
|
+void macro2buffer(struct repl *repl, struct idf *idf, struct args *args)
|
|
|
{
|
|
|
/* macro2buffer expands the replacement list and places the
|
|
|
result onto the replacement buffer. It deals with the #
|
|
@@ -568,15 +556,14 @@ macro2buffer(repl, idf, args)
|
|
|
linear fashion. This is VERY expensive, something
|
|
|
smarter should be done (but even a DFA is O(|s|)).
|
|
|
*/
|
|
|
- register char *ptr = idf->id_macro->mc_text;
|
|
|
+ char *ptr = idf->id_macro->mc_text;
|
|
|
int err = 0;
|
|
|
int func = idf->id_macro->mc_nps != -1;
|
|
|
- char *stringify();
|
|
|
|
|
|
ASSERT(ptr[idf->id_macro->mc_length] == '\0');
|
|
|
while (*ptr) {
|
|
|
if (*ptr == '\'' || *ptr == '"') {
|
|
|
- register int delim = *ptr;
|
|
|
+ int delim = *ptr;
|
|
|
|
|
|
do {
|
|
|
add2repl(repl, *ptr);
|
|
@@ -591,14 +578,14 @@ macro2buffer(repl, idf, args)
|
|
|
add2repl(repl, *ptr++);
|
|
|
} else if (*ptr == '#' && (func || *(ptr+1) == '#')) {
|
|
|
if (*++ptr == '#') {
|
|
|
- register int tmpindex;
|
|
|
+ int tmpindex;
|
|
|
/* ## - paste operator */
|
|
|
ptr++;
|
|
|
|
|
|
/* 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.
|
|
@@ -617,25 +604,25 @@ macro2buffer(repl, idf, 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.
|
|
|
*/
|
|
|
if (*ptr & FORMALP) {
|
|
|
- register int n = *ptr++ & 0177;
|
|
|
- register char *p;
|
|
|
+ int n = *ptr++ & 0177;
|
|
|
+ char *p;
|
|
|
|
|
|
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)
|
|
@@ -644,10 +631,10 @@ macro2buffer(repl, idf, 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)
|
|
@@ -659,8 +646,8 @@ macro2buffer(repl, idf, args)
|
|
|
}
|
|
|
} else if (*ptr & FORMALP) {
|
|
|
/* insert actual parameter */
|
|
|
- register int n = *ptr++ & 0177;
|
|
|
- register char *p, *q;
|
|
|
+ int n = *ptr++ & 0177;
|
|
|
+ char *p, *q;
|
|
|
|
|
|
ASSERT(n > 0);
|
|
|
|
|
@@ -669,7 +656,7 @@ macro2buffer(repl, idf, 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,11 +677,7 @@ macro2buffer(repl, idf, args)
|
|
|
lexerror("illegal use of the ## operator");
|
|
|
}
|
|
|
|
|
|
-char *
|
|
|
-stringify(repl, ptr, args)
|
|
|
- register struct repl *repl;
|
|
|
- register char *ptr;
|
|
|
- register struct args *args;
|
|
|
+char *stringify(struct repl *repl, char *ptr, struct args *args)
|
|
|
{
|
|
|
/* If a parameter is immediately preceded by a # token
|
|
|
both are replaced by a single string literal that
|
|
@@ -708,23 +691,23 @@ stringify(repl, ptr, args)
|
|
|
as appropriate. We only escape backslashes if they
|
|
|
occure within string tokens.
|
|
|
*/
|
|
|
- register int space = 1; /* skip leading spaces */
|
|
|
- register int delim = 0; /* string or character constant delim */
|
|
|
- register int backslash = 0; /* last character was a \ */
|
|
|
+ int space = 1; /* skip leading spaces */
|
|
|
+ int delim = 0; /* string or character constant delim */
|
|
|
+ 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) {
|
|
|
- register int n = *ptr++ & 0177;
|
|
|
- register char *p;
|
|
|
+ int n = *ptr++ & 0177;
|
|
|
+ char *p;
|
|
|
|
|
|
ASSERT(n != 0);
|
|
|
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, ' ');
|
|
@@ -746,7 +729,7 @@ stringify(repl, ptr, 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, '"');
|
|
@@ -757,11 +740,9 @@ stringify(repl, ptr, args)
|
|
|
|
|
|
/* The following routine is also called from domacro.c.
|
|
|
*/
|
|
|
-add2repl(repl, ch)
|
|
|
- register struct repl *repl;
|
|
|
- int ch;
|
|
|
+void add2repl(struct repl *repl, int ch)
|
|
|
{
|
|
|
- register int index = repl->r_ptr - repl->r_text;
|
|
|
+ int index = repl->r_ptr - repl->r_text;
|
|
|
|
|
|
ASSERT(index < repl->r_size);
|
|
|
if (index + 2 >= repl->r_size) {
|
|
@@ -776,15 +757,12 @@ add2repl(repl, ch)
|
|
|
* buffer. If the variable is zero, we must only stash into the expanded
|
|
|
* buffer. Otherwise, we must use both buffers.
|
|
|
*/
|
|
|
-stash(repl, ch, stashraw)
|
|
|
- struct repl *repl;
|
|
|
- register int ch;
|
|
|
- int stashraw;
|
|
|
+void stash(struct repl *repl ,int ch, int stashraw)
|
|
|
{
|
|
|
/* Stash characters into the macro expansion buffer.
|
|
|
*/
|
|
|
- register struct args *args = repl->r_args;
|
|
|
- register int index = args->a_expptr - args->a_expbuf;
|
|
|
+ struct args *args = repl->r_args;
|
|
|
+ int index = args->a_expptr - args->a_expbuf;
|
|
|
|
|
|
if (stashraw >= 0) {
|
|
|
ASSERT(index < args->a_expsize);
|