fix printing for template within a template

This commit is contained in:
Kelvin Sherlock 2014-12-29 17:18:43 -05:00
parent 8e434d39f8
commit f7bee265cc
4 changed files with 14 additions and 62 deletions

View File

@ -135,6 +135,7 @@ namespace Debug {
return; return;
case kBoolean: case kBoolean:
fputc(' ', stdout);
fputs(value ? "true" : "false", stdout); fputs(value ? "true" : "false", stdout);
return; return;
@ -153,21 +154,19 @@ namespace Debug {
{ {
unsigned offset = 0; unsigned offset = 0;
if (!e) return;
for( ; e ; e = e->next) for( ; e ; e = e->next)
{ {
bool nonl = false;
unsigned count = e->count; unsigned count = e->count;
unsigned type = e->type; unsigned type = e->type;
unsigned s = (type & 0x0f00) >> 8; unsigned s = (type & 0x0f00) >> 8;
if (!s) { for (unsigned i = 0; i < indent; ++i) fputc('>',stdout);
// struct or pointer... fputs(e->name->c_str(),stdout);
if (e->type & 0x8000) s = 4; for(unsigned i = indent + e->name->length(); i < 40; ++i) fputc(' ',stdout);
else if (e->tmpl) s = e->tmpl->struct_size;
}
printf("%-20s", e->name->c_str());
// todo -- support arrays // todo -- support arrays
// todo -- pretty print values (boolean, oserr, ostype, etc.) // todo -- pretty print values (boolean, oserr, ostype, etc.)
@ -208,12 +207,14 @@ namespace Debug {
} }
if (type == 0) { if (type == 0) {
// struct ... recurse. // struct ... recurse.
fputc('\n', stdout);
nonl = true;
ApplyTemplate(address + offset, e->tmpl, indent + 1);
break; break;
} }
} }
printf("\n"); if (!nonl) fputc('\n', stdout);
offset += CalcOneSize(e); offset += CalcOneSize(e);
} }

View File

@ -52,57 +52,8 @@ namespace Debug {
return rv; return rv;
} }
enum {
kDisplayNative = 0,
kDisplayStringPtr, // p-string
kDisplayCStringPtr, // c-string
kDisplayOSType, // four-cc
kDisplayBoolean, // unsigned char, display true/false
kDisplayOSErr,
};
#if 0
struct Type {
enum {
kSimpleType,
kStructType,
kPointerType,
};
uint16_t tag;
uint16_t size;
};
// handles [signed/unsigned] type, type[], *type, and *type[]
struct SimpleType : public Type {
unsigned rank:16; // int == int[1]
unsigned display:14; //
unsigned sign:1;
unsigned pointer:1;
SimpleType() {
tag = kSimpleType;
size = 0;
rank = 0;
display = 0;
sign = 0;
pointer = 0;
}
};
struct PointerType: public Type {
Type *type;
};
struct StructType : public Type {
unsigned total_size;
FieldEntry *firstField;
};
#endif
struct FieldEntry; struct FieldEntry;
typedef FieldEntry *Template; typedef FieldEntry *Template;

View File

@ -139,7 +139,7 @@ void TemplateParse(void *yyp, int yymajor, const std::string *yyminor, Debug::Te
}; };
# identifier ... but also need to check if it's a type. # identifier ... but also need to check if it's a type.
[A-Za-z_][A-Za-z0-9_]+ { [A-Za-z_][A-Za-z0-9_]* {
// intern the string. // intern the string.
@ -236,7 +236,7 @@ bool LoadTemplateFile(const std::string &filename, std::unordered_map<std::strin
if (cs == lexer_error) if (cs == lexer_error)
{ {
fprintf(stderr, "illegal character: `%c'\n", *p); fprintf(stderr, "Template error: line %d - illegal character: `%c'\n", info.LineNumber, *p);
TemplateParseFree(parser, free); TemplateParseFree(parser, free);
munmap(buffer, st.st_size); munmap(buffer, st.st_size);
return false; return false;

View File

@ -57,7 +57,7 @@ struct_field(rhs) ::= opt_volatile TEMPLATE(a) opt_star(star) IDENTIFIER(b) arra
FieldEntry *e = (FieldEntry *)calloc(sizeof(FieldEntry), 1); FieldEntry *e = (FieldEntry *)calloc(sizeof(FieldEntry), 1);
e->name = (std::string *)b; e->name = (std::string *)b;
e->type = star ? kStruct : kStructPtr; e->type = star ? kStructPtr : kStruct;
e->tmpl = (Template)a; e->tmpl = (Template)a;
e->count = c; e->count = c;