statement printing now infers the type of a def from the instruction where

possible, thus allowing anonymous defs to print their contents.
This commit is contained in:
Bill Currie 2001-08-13 23:49:04 +00:00
parent d55199bece
commit 07a09e0812
3 changed files with 30 additions and 23 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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");