From 07a09e0812c071841cd3f24523246f74bc4fa6bc Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 13 Aug 2001 23:49:04 +0000 Subject: [PATCH] statement printing now infers the type of a def from the instruction where possible, thus allowing anonymous defs to print their contents. --- include/QF/progs.h | 2 +- libs/gamecode/pr_edict.c | 18 +++++++++++++----- libs/gamecode/pr_exec.c | 33 ++++++++++++++++----------------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/include/QF/progs.h b/include/QF/progs.h index 941d3d2ee..4bad0d658 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -156,7 +156,7 @@ void ED_PrintNum (progs_t *pr, int ent); void ED_Count (progs_t *pr); void PR_Profile (progs_t *pr); -char *PR_GlobalString (progs_t *pr, int ofs); +char *PR_GlobalString (progs_t *pr, int ofs, etype_t type); char *PR_GlobalStringNoContents (progs_t *pr, int ofs); pr_type_t *GetEdictFieldValue(progs_t *pr, edict_t *ed, const char *field); diff --git a/libs/gamecode/pr_edict.c b/libs/gamecode/pr_edict.c index b8c101255..45e51eda2 100644 --- a/libs/gamecode/pr_edict.c +++ b/libs/gamecode/pr_edict.c @@ -461,7 +461,7 @@ PR_UglyValueString (progs_t * pr, etype_t type, pr_type_t *val) padded to 20 field width */ char * -PR_GlobalString (progs_t * pr, int ofs) +PR_GlobalString (progs_t * pr, int ofs, etype_t type) { char *s; int i; @@ -474,12 +474,20 @@ PR_GlobalString (progs_t * pr, int ofs) val = (void *) &pr->pr_globals[ofs]; if (!def) def = ED_GlobalAtOfs (pr, ofs); - if (!def) + if (!def && type == ev_void) snprintf (line, sizeof (line), "%i(?)", ofs); else { - s = PR_ValueString (pr, def->type, val); - snprintf (line, sizeof (line), "%i(%s)%s", ofs, - PR_GetString (pr, def->s_name), s); + char *name = "?"; + char *oi = ""; + if (def) { + if (type == ev_void) + type = def->type; + name = PR_GetString (pr, def->s_name); + if (type != def->type) + oi = "!"; + } + s = PR_ValueString (pr, type, val); + snprintf (line, sizeof (line), "%i(%s%s)%s", ofs, oi, name, s); } i = strlen (line); diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index b88d114bf..c5321656d 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -56,7 +56,6 @@ extern cvar_t *pr_deadbeef; void PR_PrintStatement (progs_t * pr, dstatement_t *s) { - int i; int addr = s - pr->pr_statements; opcode_t *op; @@ -68,29 +67,29 @@ PR_PrintStatement (progs_t * pr, dstatement_t *s) } Con_Printf ("%-7d ", addr); op = PR_Opcode (s->op); - if (op) { - Con_Printf ("%s ", op->opname); - i = strlen (op->opname); - for (; i < 10; i++) - Con_Printf (" "); + if (!op) { + Con_Printf ("unknown opcode %d\n", s->op); + return; } + Con_Printf ("%-9s ", op->opname); if (s->op == OP_IF || s->op == OP_IFNOT) Con_Printf ("%sbranch %i (%i)", - PR_GlobalString (pr, s->a), s->b, - addr + s->b); + PR_GlobalString (pr, s->a, ev_integer), s->b, addr + s->b); else if (s->op == OP_GOTO) { Con_Printf ("branch %i (%i)", s->a, addr + s->a); - } else if ((unsigned int) (s->op - OP_STORE_F) < 6) { - Con_Printf ("%s", PR_GlobalString (pr, s->a)); - Con_Printf ("%s", - PR_GlobalStringNoContents (pr, s->b)); + } else if (s->op == OP_RETURN || s->op == OP_DONE) { + Con_Printf ("%s", PR_GlobalString (pr, s->a, ev_void)); } else { - if (s->a) - Con_Printf ("%s", PR_GlobalString (pr, s->a)); - if (s->b) - Con_Printf ("%s", PR_GlobalString (pr, s->b)); - if (s->c) + if (op->type_a != ev_void) + Con_Printf ("%s", PR_GlobalString (pr, s->a, op->type_a)); + if (op->type_b != ev_void) { + if (op->type_c != ev_void) + Con_Printf ("%s", PR_GlobalString (pr, s->b, op->type_b)); + else + Con_Printf ("%s", PR_GlobalStringNoContents (pr, s->b)); + } + if (op->type_c != ev_void) Con_Printf ("%s", PR_GlobalStringNoContents (pr, s->c)); } Con_Printf ("\n");