GP-4394 Add formatting to constant array indices

This commit is contained in:
caheckman 2024-03-05 22:41:52 +00:00
parent 63e64d5b28
commit ac0ed8d90b
4 changed files with 18 additions and 12 deletions

View file

@ -1955,7 +1955,6 @@ void PrintC::pushPartialSymbol(const Symbol *sym,int4 off,int4 sz,
entry.token = &object_member;
entry.field = field;
entry.parent = ct;
entry.fieldname = field->name;
entry.hilite = EmitMarkup::no_color;
ct = field->type;
succeeded = true;
@ -1968,9 +1967,8 @@ void PrintC::pushPartialSymbol(const Symbol *sym,int4 off,int4 sz,
stack.emplace_back();
PartialSymbolEntry &entry( stack.back() );
entry.token = &subscript;
ostringstream s;
s << dec << el;
entry.fieldname = s.str();
entry.offset = el;
entry.size = 0;
entry.field = (const TypeField *)0;
entry.hilite = EmitMarkup::const_color;
ct = arrayof;
@ -1987,7 +1985,6 @@ void PrintC::pushPartialSymbol(const Symbol *sym,int4 off,int4 sz,
entry.token = &object_member;
entry.field = field;
entry.parent = ct;
entry.fieldname = entry.field->name;
entry.hilite = EmitMarkup::no_color;
ct = field->type;
succeeded = true;
@ -2013,7 +2010,8 @@ void PrintC::pushPartialSymbol(const Symbol *sym,int4 off,int4 sz,
entry.token = &object_member;
if (sz == 0)
sz = ct->getSize() - off;
entry.fieldname = unnamedField(off, sz); // If nothing else works, generate artificial field name
entry.offset = off; // Generate artificial name, based on offset and size of entry
entry.size = sz;
entry.field = (const TypeField *)0;
entry.hilite = EmitMarkup::no_color;
ct = (Datatype *)0;
@ -2029,11 +2027,17 @@ void PrintC::pushPartialSymbol(const Symbol *sym,int4 off,int4 sz,
pushOp(stack[i].token,op);
pushSymbol(sym,vn,op); // Push base symbol name
for(int4 i=0;i<stack.size();++i) {
const TypeField *field = stack[i].field;
if (field == (const TypeField *)0)
pushAtom(Atom(stack[i].fieldname,syntax,stack[i].hilite,op));
PartialSymbolEntry &entry (stack[i]);
if (entry.field == (const TypeField *)0) {
if (entry.size <= 0)
push_integer(entry.offset, entry.size, (entry.offset < 0), syntax, (Varnode *)0, op);
else {
string field = unnamedField(entry.offset,entry.size);
pushAtom(Atom(field,syntax,entry.hilite,op));
}
}
else
pushAtom(Atom(stack[i].fieldname,fieldtoken,stack[i].hilite,stack[i].parent,field->ident,op));
pushAtom(Atom(entry.field->name,fieldtoken,stack[i].hilite,stack[i].parent,entry.field->ident,op));
}
}

View file

@ -48,7 +48,8 @@ struct PartialSymbolEntry {
const OpToken *token; ///< Operator used to drill-down to the field
const TypeField *field; ///< The component object describing the field
const Datatype *parent; ///< The parent data-type owning the field
string fieldname; ///< The name of the field
int8 offset; ///< Array index or unlabeled offset (if field is null)
int4 size; ///< (if > 0) Size of the unlabeled entry
EmitMarkup::syntax_highlight hilite; ///< Highlight information for the field token
};