From f7bee265ccb32aba447d379f22b2a89ce496a058 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 29 Dec 2014 17:18:43 -0500 Subject: [PATCH] fix printing for template within a template --- bin/template.cpp | 21 +++++++++-------- bin/template.h | 49 --------------------------------------- bin/template_loader.rl | 4 ++-- bin/template_parser.lemon | 2 +- 4 files changed, 14 insertions(+), 62 deletions(-) diff --git a/bin/template.cpp b/bin/template.cpp index a17fab5..b5a1bc5 100644 --- a/bin/template.cpp +++ b/bin/template.cpp @@ -135,6 +135,7 @@ namespace Debug { return; case kBoolean: + fputc(' ', stdout); fputs(value ? "true" : "false", stdout); return; @@ -153,21 +154,19 @@ namespace Debug { { unsigned offset = 0; + if (!e) return; + for( ; e ; e = e->next) { + bool nonl = false; unsigned count = e->count; unsigned type = e->type; unsigned s = (type & 0x0f00) >> 8; - if (!s) { - // struct or pointer... - if (e->type & 0x8000) s = 4; - else if (e->tmpl) s = e->tmpl->struct_size; - } - - - printf("%-20s", e->name->c_str()); + for (unsigned i = 0; i < indent; ++i) fputc('>',stdout); + fputs(e->name->c_str(),stdout); + for(unsigned i = indent + e->name->length(); i < 40; ++i) fputc(' ',stdout); // todo -- support arrays // todo -- pretty print values (boolean, oserr, ostype, etc.) @@ -208,12 +207,14 @@ namespace Debug { } if (type == 0) { // struct ... recurse. - + fputc('\n', stdout); + nonl = true; + ApplyTemplate(address + offset, e->tmpl, indent + 1); break; } } - printf("\n"); + if (!nonl) fputc('\n', stdout); offset += CalcOneSize(e); } diff --git a/bin/template.h b/bin/template.h index d1e65b1..a1dc023 100644 --- a/bin/template.h +++ b/bin/template.h @@ -52,57 +52,8 @@ namespace Debug { 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; typedef FieldEntry *Template; diff --git a/bin/template_loader.rl b/bin/template_loader.rl index 931e252..2a65746 100644 --- a/bin/template_loader.rl +++ b/bin/template_loader.rl @@ -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. - [A-Za-z_][A-Za-z0-9_]+ { + [A-Za-z_][A-Za-z0-9_]* { // intern the string. @@ -236,7 +236,7 @@ bool LoadTemplateFile(const std::string &filename, std::unordered_mapname = (std::string *)b; - e->type = star ? kStruct : kStructPtr; + e->type = star ? kStructPtr : kStruct; e->tmpl = (Template)a; e->count = c;