[Synopsis-cvs] CVS: Synopsis/Synopsis/Parser/C++/ucpp assert.c,1.6 hashtable.c,1.5 hashtable.h,1.4 macro.c,1.11
Stephen Davies chalky at users.sourceforge.netThu Sep 19 02:19:02 UTC 2002
- Previous message: [Synopsis-cvs] CVS: Synopsis/Synopsis/Parser/C++/syn decoder.cc,1.15
- Next message: [Synopsis-cvs] CVS: Synopsis/Synopsis/Parser/C++/syn synopsis.cc,1.36
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Update of /cvsroot/synopsis/Synopsis/Synopsis/Parser/C++/ucpp
In directory usw-pr-cvs1:/tmp/cvs-serv15183
Modified Files:
assert.c hashtable.c hashtable.h macro.c
Log Message:
Oops, missed hashtable rename..
Index: macro.c
===================================================================
RCS file: /cvsroot/synopsis/Synopsis/Synopsis/Parser/C++/ucpp/macro.c,v
retrieving revision 1.4
retrieving revision 1.11
diff -C2 -d -r1.4 -r1.11
*** macro.c 22 Feb 2001 03:27:56 -0000 1.4
--- macro.c 19 Sep 2002 09:18:04 -0000 1.11
***************
*** 34,40 ****
#include "ucppi.h"
#include "mem.h"
! #include "hash.h"
#include "tune.h"
/*
* we store macros in a hash table, and retrieve them using their name
--- 34,42 ----
#include "ucppi.h"
#include "mem.h"
! #include "hashtable.h"
#include "tune.h"
+ #define DEBUG_MACROS 0
+
/*
* we store macros in a hash table, and retrieve them using their name
***************
*** 245,248 ****
--- 247,262 ----
char *x = t->name;
+ #if DEBUG_MACROS
+ if (!ttWHI(t->type)) {
+ char* y = x;
+ if (!S_TOKEN(t->type)) y = operators_name[t->type];
+ for (; *y; y++) fprintf(stderr, "%c", *y);
+ fprintf(stderr, "\n");
+ }
+ #endif
+ if (t->type == MACROEND)
+ /* Don't print or keep macro endings */
+ return;
+
if (uz_line && t->line < 0) t->line = uz_line;
if (ls->flags & LEXER) {
***************
*** 266,269 ****
--- 280,303 ----
/*
+ * Send a token to the output at a given line (this is for text output
+ * and unreplaced macros due to lack of arguments).
+ */
+ static void print_token_nailed(struct lexer_state *ls, struct token *t,
+ long nail_line)
+ {
+ char *x = t->name;
+
+ if (ls->flags & LEXER) {
+ print_token(ls, t, 0);
+ return;
+ }
+ if (ls->flags & KEEP_OUTPUT) {
+ for (; ls->oline < nail_line;) put_char(ls, '\n');
+ }
+ if (!S_TOKEN(t->type)) x = operators_name[t->type];
+ for (; *x; x ++) put_char(ls, *x);
+ }
+
+ /*
* send a reduced whitespace token to the output
*/
***************
*** 286,290 ****
int handle_define(struct lexer_state *ls)
{
! struct macro *m, *n;
#ifdef LOW_MEM
struct token_fifo mv;
--- 320,324 ----
int handle_define(struct lexer_state *ls)
{
! struct macro *m = 0, *n;
#ifdef LOW_MEM
struct token_fifo mv;
***************
*** 296,299 ****
--- 330,336 ----
long l = ls->line;
+ #ifdef LOW_MEM
+ mv.art = mv.nt = 0;
+ #endif
/* find the next non-white token on the line, this should be
the macro name */
***************
*** 330,340 ****
#endif
freemem(mname);
}
if (!redef) {
m = new_macro();
m->name = mname;
m->narg = -1;
#ifdef LOW_MEM
- mv.art = mv.nt = 0;
#define mval mv
#else
--- 367,378 ----
#endif
freemem(mname);
+ mname = 0;
}
if (!redef) {
m = new_macro();
m->name = mname;
+ mname = 0;
m->narg = -1;
#ifdef LOW_MEM
#define mval mv
#else
***************
*** 356,360 ****
if (ls->ctok->type == NEWLINE) {
error(l, "truncated macro definition");
! return 1;
}
if (ls->ctok->type == COMMA) {
--- 394,398 ----
if (ls->ctok->type == NEWLINE) {
error(l, "truncated macro definition");
! goto define_error;
}
if (ls->ctok->type == COMMA) {
***************
*** 384,387 ****
--- 422,429 ----
aol(m->arg, narg,
sdup(ls->ctok->name), 8);
+ /* we must keep track of m->narg
+ so that cleanup in case of
+ error works. */
+ m->narg = narg;
if (narg == 128
&& (ls->flags & WARN_STANDARD))
***************
*** 571,575 ****
error(l, "operator '##' may neither begin "
"nor end a macro");
! return 1;
}
if (m->narg >= 0) for (i = 0; i < mval.nt; i ++)
--- 613,617 ----
error(l, "operator '##' may neither begin "
"nor end a macro");
! goto define_error;
}
if (m->narg >= 0) for (i = 0; i < mval.nt; i ++)
***************
*** 584,588 ****
error(l, "operator '#' not followed "
"by a macro argument");
! return 1;
}
}
--- 626,630 ----
error(l, "operator '#' not followed "
"by a macro argument");
! goto define_error;
}
}
***************
*** 621,631 ****
while (ls->ctok->type != NEWLINE && !next_token(ls));
redef_error_2:
! /* Ignore.
error(l, "macro '%s' redefined unidentically", n->name);
return 1;
! */
return 0;
warp_error:
while (ls->ctok->type != NEWLINE && !next_token(ls));
return 1;
#undef mval
--- 663,686 ----
while (ls->ctok->type != NEWLINE && !next_token(ls));
redef_error_2:
! #ifndef SYNOPSIS
error(l, "macro '%s' redefined unidentically", n->name);
return 1;
! #else
return 0;
+ #endif
warp_error:
while (ls->ctok->type != NEWLINE && !next_token(ls));
+ define_error:
+ if (m) del_macro(m);
+ if (mname) freemem(mname);
+ #ifdef LOW_MEM
+ if (mv.nt) {
+ size_t i;
+
+ for (i = 0; i < mv.nt; i ++)
+ if (S_TOKEN(mv.t[i].type)) freemem(mv.t[i].name);
+ freemem(mv.t);
+ }
+ #endif
return 1;
#undef mval
***************
*** 667,670 ****
--- 722,736 ----
while (!unravel(ls)) {
if (!read_from_fifo && ct->type == NEWLINE) ls->ltwnl = 1;
+ #if DEBUG_MACROS
+ fprintf(stderr, "Type: %d (%d)\n", ct->type, MACROEND);
+ #endif
+ if (ct->type == MACROEND) {
+ /* End of macro -- restore it's saved nest level */
+ struct macro *nm;
+ if ((nm = getHT(macros, &ct->name)) != NULL) {
+ nm->nest = ct->line;
+ continue;
+ }
+ }
if (ttWHI(ct->type)) {
*wr = 1;
***************
*** 971,974 ****
--- 1037,1045 ----
int ltwds, ntwds, ltwws;
int pragma_op = 0;
+ #if DEBUG_MACROS
+ static int debug_depth = 0;
+ int debug_save = debug_depth;
+ int debug_count;
+ #endif
/*
***************
*** 1071,1074 ****
--- 1142,1152 ----
}
+ #if DEBUG_MACROS
+ // Dumps the macro with arguments
+ debug_depth++;
+ for (debug_count = 1; debug_count < debug_depth; debug_count++) fputs(" ", stderr);
+ fprintf(stderr, "%d /^^%s: Starting '%s%s'\n", ls->line, m->name, m->name, m->narg >= 0 ? "(...)" : "");
+ #endif
+
/*
* If the macro has arguments, collect them.
***************
*** 1100,1104 ****
t.line = l;
t.name = m->name;
! print_token(ls, &t, 0);
if (wr) {
t.type = NONE;
--- 1178,1182 ----
t.line = l;
t.name = m->name;
! print_token_nailed(ls, &t, l);
if (wr) {
t.type = NONE;
***************
*** 1113,1121 ****
case 4:
ls->flags = save_flags;
! return 1;
}
ls->flags = save_flags;
}
/*
* If the macro is _Pragma, and we got here, then we have
--- 1191,1215 ----
case 4:
ls->flags = save_flags;
! goto exit_error_1;
}
ls->flags = save_flags;
}
+ #if DEBUG_MACROS
+ // Dumps the macro with arguments
+ for (debug_count = 1; debug_count < debug_depth; debug_count++) fputs(" ", stderr);
+ fprintf(stderr, "%d | %s: Expanding '%s", ls->line, m->name, m->name);
+ if (m->narg > 0) {
+ int i, j;
+ for (i = 0; i < m->narg; i++) {
+ fprintf(stderr, i == 0 ? "(" : ", ");
+ for (j = 0; j < atl[i].nt; j++)
+ fputs(token_name(atl[i].t + j), stderr);
+ }
+ fprintf(stderr, ")");
+ }
+ fputs("'\n", stderr);
+ #endif
+
/*
* If the macro is _Pragma, and we got here, then we have
***************
*** 1130,1134 ****
if (atl[0].nt) freemem(atl[0].t);
freemem(atl);
! return 1;
}
pn = atl[0].t[0].name;
--- 1224,1228 ----
if (atl[0].nt) freemem(atl[0].t);
freemem(atl);
! goto exit_error;
}
pn = atl[0].t[0].name;
***************
*** 1190,1194 ****
freemem(atl[0].t);
freemem(atl);
! return 1;
}
#else
--- 1284,1288 ----
freemem(atl[0].t);
freemem(atl);
! goto exit_error;
}
#else
***************
*** 1305,1309 ****
token_name(etl.t + etl.nt),
token_name(atl[z].t));
- m->nest = save_nest;
#ifdef LOW_MEM
m->cval.rp = save_art;
--- 1399,1402 ----
***************
*** 1311,1315 ****
m->val.art = save_art;
#endif
! return 1;
}
if (etl.nt == 0) freemem(etl.t);
--- 1404,1409 ----
m->val.art = save_art;
#endif
! etl.nt ++;
! goto exit_error_2;
}
if (etl.nt == 0) freemem(etl.t);
***************
*** 1375,1379 ****
ls->flags = save_flags;
if (ret) {
- m->nest = save_nest;
#ifdef LOW_MEM
m->cval.rp = save_art;
--- 1469,1472 ----
***************
*** 1381,1385 ****
m->val.art = save_art;
#endif
! return ret;
}
}
--- 1474,1478 ----
m->val.art = save_art;
#endif
! goto exit_error_2;
}
}
***************
*** 1407,1411 ****
if (ltwds) {
error(ls->line, "quad sharp");
- m->nest = save_nest;
#ifdef LOW_MEM
m->cval.rp = save_art;
--- 1500,1503 ----
***************
*** 1413,1417 ****
m->val.art = save_art;
#endif
! return 1;
}
#ifdef LOW_MEM
--- 1505,1509 ----
m->val.art = save_art;
#endif
! goto exit_error_2;
}
#ifdef LOW_MEM
***************
*** 1432,1436 ****
token_name(etl.t + etl.nt),
token_name(ct));
- m->nest = save_nest;
#ifdef LOW_MEM
m->cval.rp = save_art;
--- 1524,1527 ----
***************
*** 1438,1442 ****
m->val.art = save_art;
#endif
! return 1;
}
if (etl.nt == 0) freemem(etl.t);
--- 1529,1534 ----
m->val.art = save_art;
#endif
! etl.nt ++;
! goto exit_error_2;
}
if (etl.nt == 0) freemem(etl.t);
***************
*** 1500,1503 ****
--- 1592,1607 ----
#endif
+ #if DEBUG_MACROS
+ // Dumps the expanded macro
+ for (debug_count = 1; debug_count < debug_depth; debug_count++) fputs(" ", stderr);
+ fprintf(stderr, "%d | %s: to '", ls->line, m->name);
+ {
+ int art = etl.art, nt = etl.nt;
+ while (art < nt)
+ fputs(token_name(etl.t + (art++)), stderr);
+ }
+ fputs("'\n", stderr);
+ #endif
+
/*
***************
*** 1512,1518 ****
--- 1616,1635 ----
* OPT_NONE NONE are emitted.
*/
+ #if DEBUG_MACROS
+ for (debug_count = 1; debug_count < debug_depth; debug_count++) fputs(" ", stderr);
+ fprintf(stderr, "%d | %s: Appending macro end token\n", ls->line, m->name);
+ #endif
+
+ /* Add end of macro token */
+ t.type = MACROEND;
+ t.name = m->name;
+ t.line = save_nest;
+ aol(etl.t, etl.nt, t, TOKEN_LIST_MEMG);
+
etl_limit = etl.nt;
+
if (tfi) {
save_tfi = tfi->art;
+
while (tfi->art < tfi->nt) aol(etl.t, etl.nt,
tfi->t[tfi->art ++], TOKEN_LIST_MEMG);
***************
*** 1528,1532 ****
penury, reject_nested, l)) {
m->nest = save_nest;
! return 1;
}
ltwws = 0;
--- 1645,1649 ----
penury, reject_nested, l)) {
m->nest = save_nest;
! goto exit_error_2;
}
ltwws = 0;
***************
*** 1544,1549 ****
--- 1661,1676 ----
print_token(ls, ct, reject_nested ? 0 : l);
}
+ #if DEBUG_MACROS
+ // Dumps the expanded macro
+ for (debug_count = 1; debug_count < debug_depth; debug_count++) fputs(" ", stderr);
+ fprintf(stderr, "%d \\__%s: Done\n", ls->line, m->name);
+ debug_depth = debug_save;
+ #endif
if (etl.nt) freemem(etl.t);
if (tfi) {
+ #if DEBUG_MACROS
+ for (debug_count = 1; debug_count < debug_depth; debug_count++) fputs(" ", stderr);
+ fprintf(stderr, "Adjusting tfi by %d\n", (etl.art - etl_limit));
+ #endif
tfi->art = save_tfi + (etl.art - etl_limit);
}
***************
*** 1552,1559 ****
print_space(ls);
exit_macro_2:
- for (i = 0; i < m->narg; i ++) if (atl[i].nt) freemem(atl[i].t);
- if (m->narg > 0) freemem(atl);
m->nest = save_nest;
return 0;
}
--- 1679,1705 ----
print_space(ls);
exit_macro_2:
m->nest = save_nest;
+
+ for (i = 0; i < (m->narg + m->vaarg); i ++)
+ if (atl[i].nt) freemem(atl[i].t);
+ if (m->narg > 0 || m->vaarg) freemem(atl);
+
+ #if DEBUG_MACROS
+ debug_depth = debug_save;
+ #endif
return 0;
+
+ exit_error_2:
+ if (etl.nt) freemem(etl.t);
+ exit_error_1:
+ for (i = 0; i < (m->narg + m->vaarg); i ++)
+ if (atl[i].nt) freemem(atl[i].t);
+ if (m->narg > 0 || m->vaarg) freemem(atl);
+ m->nest = save_nest;
+ exit_error:
+ #if DEBUG_MACROS
+ debug_depth = debug_save;
+ #endif
+ return 1;
}
***************
*** 1792,1800 ****
/*
* initialize the macro table
*/
void init_macros(void)
{
! if (macros) killHT(macros);
macros = newHT(128, cmp_struct, hash_struct, del_macro);
if (!no_special_macros) add_special_macros();
--- 1938,1955 ----
/*
+ * erase the macro table.
+ */
+ void wipe_macros(void)
+ {
+ if (macros) killHT(macros);
+ macros = 0;
+ }
+
+ /*
* initialize the macro table
*/
void init_macros(void)
{
! wipe_macros();
macros = newHT(128, cmp_struct, hash_struct, del_macro);
if (!no_special_macros) add_special_macros();
- Previous message: [Synopsis-cvs] CVS: Synopsis/Synopsis/Parser/C++/syn decoder.cc,1.15
- Next message: [Synopsis-cvs] CVS: Synopsis/Synopsis/Parser/C++/syn synopsis.cc,1.36
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Synopsis-changes mailing list