1 /* $Id: scan.c,v 1.9 1994/06/24 10:19:00 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
6 /* PREPROCESSOR: SCANNER FOR THE ACTUAL PARAMETERS OF MACROS */
8 /* This file contains the function getactuals() which scans an actual
9 parameter list and splits it up into a list of strings, each one
10 representing an actual parameter.
13 #include "lapbuf.h" /* UF */
14 #include "nparams.h" /* UF */
20 #include "interface.h"
21 #include "file_info.h"
24 #define overflow() (fatal("actual parameter buffer overflow"))
26 PRIVATE char apbuf[LAPBUF]; /* temporary storage for actual parameters */
27 PRIVATE char *actparams[NPARAMS]; /* pointers to the text of the actuals */
28 PRIVATE char *aptr; /* pointer to last inserted character in apbuf */
30 #define copy(ch) ((aptr < &apbuf[LAPBUF]) ? (*aptr++ = ch) : overflow())
32 PRIVATE int nr_of_params; /* number of actuals read until now */
38 /* getactuals() collects the actual parameters and turns them
39 into a list of strings, a pointer to which is returned.
41 register acnt = idef->id_macro->mc_nps;
44 actparams[0] = aptr = &apbuf[0];
45 copyact('(', ')', 0); /* read the actual parameters */
46 copy(EOS); /* mark the end of it all */
48 if (!nr_of_params++) { /* 0 or 1 parameter */
49 /* there could be a ( <spaces, comment, ...> )
51 register char *p = actparams[0];
53 while ((class(*p) == STSKIP) || (*p == '\n')) {
57 if (!*p) { /* the case () : 0 parameters */
62 if (nr_of_params != acnt) {
63 /* argument mismatch: too many or too few
66 warning("argument mismatch, %s", idef->id_text);
68 while (nr_of_params < acnt) {
69 /* too few paraeters: remaining actuals are ""
71 actparams[nr_of_params] = "";
80 copyact(ch1, ch2, level)
84 /* copyact() is taken from Ceriel Jacobs' LLgen, with
85 permission. Its task is to build a list of actuals
86 parameters, which list is surrounded by '(' and ')' and in
87 which the parameters are separated by ',' if there are
88 more than 1. The balancing of '(',')' and '[',']' and
89 '{','}' is taken care of by calling this function
90 recursively. At each level, copyact() reads the input,
91 upto the corresponding closing bracket.
93 Opening bracket is ch1, closing bracket is ch2. If
94 level != 0, copy opening and closing parameters too.
96 register int ch; /* Current char */
97 register int match; /* used to read strings */
115 #ifdef __MATCHING_PAR__
119 error("unbalanced parenthesis");
121 #endif /* __MATCHING_PAR__ */
124 copyact('(', ')', level+1);
127 #ifdef __MATCHING_PAR__
130 #define declare(v, t) t v
131 declare(v, union{int i, j; float r;});
133 copyact('{', '}', level+1);
137 copyact('[', ']', level+1);
139 #endif /* __MATCHING_PAR__ */
145 /* This piece of code needs some
146 explanation: consider the call of
147 the macro defined as:
148 #define sum(b,c) (b + c)
149 in the following form:
151 #include my_phone_number
153 in which case the include must be
156 domacro(); /* has read nl, vt or ff */
158 /* Loop, for another control line */
168 if (ch == '*') { /* skip comment */
179 /* next parameter encountered */
182 if (++nr_of_params >= NPARAMS) {
183 fatal("(getact) too many actuals");
186 actparams[nr_of_params] = aptr;
195 /* watch out for brackets in strings, they do
213 error("newline in string");
229 error("unterminated macro call");