decompiler  1.0.0
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ghidra::PrintC Class Reference

The c-language token emitter. More...

#include <printc.hh>

Inheritance diagram for ghidra::PrintC:
ghidra::PrintLanguage ghidra::PrintJava

Public Member Functions

 PrintC (Architecture *g, const string &nm="c-language")
 Constructor. More...
 
void setNULLPrinting (bool val)
 Toggle the printing of a 'NULL' token.
 
void setInplaceOps (bool val)
 Toggle the printing of in-place operators.
 
void setConvention (bool val)
 Toggle whether calling conventions are printed.
 
void setNoCastPrinting (bool val)
 Toggle whether casts should not be printed.
 
void setCStyleComments (void)
 Set c-style "/* */" comment delimiters.
 
void setCPlusPlusStyleComments (void)
 Set c++-style "//" comment delimiters.
 
void setDisplayUnplaced (bool val)
 Toggle whether unplaced comments are displayed in the header.
 
void setHideImpliedExts (bool val)
 Toggle whether implied extensions are hidden.
 
virtual void resetDefaults (void)
 Set printing options to their default value.
 
virtual void initializeFromArchitecture (void)
 Initialize architecture specific aspects of printer.
 
virtual void adjustTypeOperators (void)
 Set basic data-type information for p-code operators.
 
virtual void setCommentStyle (const string &nm)
 Set the way comments are displayed in decompiler output. More...
 
virtual void docTypeDefinitions (const TypeFactory *typegrp)
 Emit definitions of data-types. More...
 
virtual void docAllGlobals (void)
 Emit declarations of global variables.
 
virtual void docSingleGlobal (const Symbol *sym)
 Emit the declaration for a single (global) Symbol. More...
 
virtual void docFunction (const Funcdata *fd)
 Emit the declaration (and body) of a function. More...
 
virtual void emitBlockBasic (const BlockBasic *bb)
 Emit statements in a basic block.
 
virtual void emitBlockGraph (const BlockGraph *bl)
 Emit (an unspecified) list of blocks.
 
virtual void emitBlockCopy (const BlockCopy *bl)
 Emit a basic block (with any labels)
 
virtual void emitBlockGoto (const BlockGoto *bl)
 Emit a block ending with a goto statement.
 
virtual void emitBlockLs (const BlockList *bl)
 Emit a sequence of blocks.
 
virtual void emitBlockCondition (const BlockCondition *bl)
 Emit a conditional statement.
 
virtual void emitBlockIf (const BlockIf *bl)
 Emit an if/else style construct.
 
virtual void emitBlockWhileDo (const BlockWhileDo *bl)
 Emit a loop structure, check at top.
 
virtual void emitBlockDoWhile (const BlockDoWhile *bl)
 Emit a loop structure, check at bottom.
 
virtual void emitBlockInfLoop (const BlockInfLoop *bl)
 Emit an infinite loop structure.
 
virtual void emitBlockSwitch (const BlockSwitch *bl)
 Emit a switch structure.
 
virtual void opCopy (const PcodeOp *op)
 Emit a COPY operator.
 
virtual void opLoad (const PcodeOp *op)
 Emit a LOAD operator.
 
virtual void opStore (const PcodeOp *op)
 Emit a STORE operator.
 
virtual void opBranch (const PcodeOp *op)
 Emit a BRANCH operator.
 
virtual void opCbranch (const PcodeOp *op)
 
virtual void opBranchind (const PcodeOp *op)
 Emit a BRANCHIND operator.
 
virtual void opCall (const PcodeOp *op)
 Emit a CALL operator.
 
virtual void opCallind (const PcodeOp *op)
 Emit a CALLIND operator.
 
virtual void opCallother (const PcodeOp *op)
 Emit a CALLOTHER operator.
 
virtual void opConstructor (const PcodeOp *op, bool withNew)
 Emit an operator constructing an object.
 
virtual void opReturn (const PcodeOp *op)
 Emit a RETURN operator.
 
virtual void opIntEqual (const PcodeOp *op)
 Emit a INT_EQUAL operator.
 
virtual void opIntNotEqual (const PcodeOp *op)
 Emit a INT_NOTEQUAL operator.
 
virtual void opIntSless (const PcodeOp *op)
 Emit a INT_SLESS operator.
 
virtual void opIntSlessEqual (const PcodeOp *op)
 Emit a INT_SLESSEQUAL operator.
 
virtual void opIntLess (const PcodeOp *op)
 Emit a INT_LESS operator.
 
virtual void opIntLessEqual (const PcodeOp *op)
 Emit a INT_LESSEQUAL operator.
 
virtual void opIntZext (const PcodeOp *op, const PcodeOp *readOp)
 Emit a INT_ZEXT operator.
 
virtual void opIntSext (const PcodeOp *op, const PcodeOp *readOp)
 Emit a INT_SEXT operator.
 
virtual void opIntAdd (const PcodeOp *op)
 Emit a INT_ADD operator.
 
virtual void opIntSub (const PcodeOp *op)
 Emit a INT_SUB operator.
 
virtual void opIntCarry (const PcodeOp *op)
 Emit a INT_CARRY operator.
 
virtual void opIntScarry (const PcodeOp *op)
 Emit a INT_SCARRY operator.
 
virtual void opIntSborrow (const PcodeOp *op)
 Emit a INT_SBORROW operator.
 
virtual void opInt2Comp (const PcodeOp *op)
 Emit a INT_2COMP operator.
 
virtual void opIntNegate (const PcodeOp *op)
 Emit a INT_NEGATE operator.
 
virtual void opIntXor (const PcodeOp *op)
 Emit a INT_XOR operator.
 
virtual void opIntAnd (const PcodeOp *op)
 Emit a INT_AND operator.
 
virtual void opIntOr (const PcodeOp *op)
 Emit a INT_OR operator.
 
virtual void opIntLeft (const PcodeOp *op)
 Emit a INT_LEFT operator.
 
virtual void opIntRight (const PcodeOp *op)
 Emit a INT_RIGHT operator.
 
virtual void opIntSright (const PcodeOp *op)
 Emit a INT_SRIGHT operator.
 
virtual void opIntMult (const PcodeOp *op)
 Emit a INT_MULT operator.
 
virtual void opIntDiv (const PcodeOp *op)
 Emit a INT_DIV operator.
 
virtual void opIntSdiv (const PcodeOp *op)
 Emit a INT_SDIV operator.
 
virtual void opIntRem (const PcodeOp *op)
 Emit a INT_REM operator.
 
virtual void opIntSrem (const PcodeOp *op)
 Emit a INT_SREM operator.
 
virtual void opBoolNegate (const PcodeOp *op)
 
virtual void opBoolXor (const PcodeOp *op)
 Emit a BOOL_XOR operator.
 
virtual void opBoolAnd (const PcodeOp *op)
 Emit a BOOL_AND operator.
 
virtual void opBoolOr (const PcodeOp *op)
 Emit a BOOL_OR operator.
 
virtual void opFloatEqual (const PcodeOp *op)
 Emit a FLOAT_EQUAL operator.
 
virtual void opFloatNotEqual (const PcodeOp *op)
 Emit a FLOAT_NOTEQUAL operator.
 
virtual void opFloatLess (const PcodeOp *op)
 Emit a FLOAT_LESS operator.
 
virtual void opFloatLessEqual (const PcodeOp *op)
 Emit a FLOAT_LESSEQUAL operator.
 
virtual void opFloatNan (const PcodeOp *op)
 Emit a FLOAT_NAN operator.
 
virtual void opFloatAdd (const PcodeOp *op)
 Emit a FLOAT_ADD operator.
 
virtual void opFloatDiv (const PcodeOp *op)
 Emit a FLOAT_DIV operator.
 
virtual void opFloatMult (const PcodeOp *op)
 Emit a FLOAT_MULT operator.
 
virtual void opFloatSub (const PcodeOp *op)
 Emit a FLOAT_SUB operator.
 
virtual void opFloatNeg (const PcodeOp *op)
 Emit a FLOAT_NEG operator.
 
virtual void opFloatAbs (const PcodeOp *op)
 Emit a FLOAT_ABS operator.
 
virtual void opFloatSqrt (const PcodeOp *op)
 Emit a FLOAT_SQRT operator.
 
virtual void opFloatInt2Float (const PcodeOp *op)
 Emit a FLOAT_INT2FLOAT operator.
 
virtual void opFloatFloat2Float (const PcodeOp *op)
 Emit a FLOAT_FLOAT2FLOAT operator.
 
virtual void opFloatTrunc (const PcodeOp *op)
 Emit a FLOAT_TRUNC operator.
 
virtual void opFloatCeil (const PcodeOp *op)
 Emit a FLOAT_CEIL operator.
 
virtual void opFloatFloor (const PcodeOp *op)
 Emit a FLOAT_FLOOR operator.
 
virtual void opFloatRound (const PcodeOp *op)
 Emit a FLOAT_ROUND operator.
 
virtual void opMultiequal (const PcodeOp *op)
 Emit a MULTIEQUAL operator.
 
virtual void opIndirect (const PcodeOp *op)
 Emit a INDIRECT operator.
 
virtual void opPiece (const PcodeOp *op)
 Emit a PIECE operator.
 
virtual void opSubpiece (const PcodeOp *op)
 Emit a SUBPIECE operator.
 
virtual void opCast (const PcodeOp *op)
 Emit a CAST operator.
 
virtual void opPtradd (const PcodeOp *op)
 Emit a PTRADD operator.
 
virtual void opPtrsub (const PcodeOp *op)
 
virtual void opSegmentOp (const PcodeOp *op)
 
virtual void opCpoolRefOp (const PcodeOp *op)
 Emit a CPOOLREF operator.
 
virtual void opNewOp (const PcodeOp *op)
 Emit a NEW operator.
 
virtual void opInsertOp (const PcodeOp *op)
 Emit an INSERT operator.
 
virtual void opExtractOp (const PcodeOp *op)
 Emit an EXTRACT operator.
 
virtual void opPopcountOp (const PcodeOp *op)
 Emit a POPCOUNT operator.
 
virtual void opLzcountOp (const PcodeOp *op)
 Emit a LZCOUNT operator.
 
- Public Member Functions inherited from ghidra::PrintLanguage
 PrintLanguage (Architecture *g, const string &nm)
 Constructor. More...
 
virtual ~PrintLanguage (void)
 Destructor.
 
const string & getName (void) const
 Get the language name.
 
CastStrategygetCastStrategy (void) const
 Get the casting strategy for the language.
 
ostream * getOutputStream (void) const
 Get the output stream being emitted to.
 
void setOutputStream (ostream *t)
 Set the output stream to emit to.
 
void setMaxLineSize (int4 mls)
 Set the maximum number of characters per line.
 
void setIndentIncrement (int4 inc)
 Set the number of characters to indent per level of code nesting.
 
void setLineCommentIndent (int4 val)
 Set the number of characters to indent comment lines. More...
 
void setCommentDelimeter (const string &start, const string &stop, bool usecommentfill)
 Establish comment delimiters for the language. More...
 
uint4 getInstructionComment (void) const
 Get the type of comments suitable within the body of a function.
 
void setInstructionComment (uint4 val)
 Set the type of comments suitable within the body of a function.
 
void setNamespaceStrategy (namespace_strategy strat)
 Set how namespace tokens are displayed.
 
uint4 getHeaderComment (void) const
 Get the type of comments suitable for a function header.
 
void setHeaderComment (uint4 val)
 Set the type of comments suitable for a function header.
 
bool emitsMarkup (void) const
 Does the low-level emitter, emit markup.
 
void setMarkup (bool val)
 Set whether the low-level emitter, emits markup. More...
 
void setFlat (bool val)
 Set whether nesting code structure should be emitted. More...
 
virtual void clear (void)
 Clear the RPN stack and the low-level emitter.
 
virtual void setIntegerFormat (const string &nm)
 Set the default integer format. More...
 
virtual string unnamedField (int4 off, int4 size)
 Generate an artificial field name. More...
 

Static Public Attributes

static const string EMPTY_STRING = ""
 An empty token.
 
static const string OPEN_CURLY = "{"
 "{" token
 
static const string CLOSE_CURLY = "}"
 "}" token
 
static const string SEMICOLON = ";"
 ";" token
 
static const string COLON = ":"
 ":" token
 
static const string EQUALSIGN = "="
 "=" token
 
static const string COMMA = ","
 "," token
 
static const string DOTDOTDOT = "..."
 "..." token
 
static const string KEYWORD_VOID = "void"
 "void" keyword
 
static const string KEYWORD_TRUE = "true"
 "true" keyword
 
static const string KEYWORD_FALSE = "false"
 "false" keyword
 
static const string KEYWORD_IF = "if"
 "if" keyword
 
static const string KEYWORD_ELSE = "else"
 "else" keyword
 
static const string KEYWORD_DO = "do"
 "do" keyword
 
static const string KEYWORD_WHILE = "while"
 "while" keyword
 
static const string KEYWORD_FOR = "for"
 "for" keyword
 
static const string KEYWORD_GOTO = "goto"
 "goto" keyword
 
static const string KEYWORD_BREAK = "break"
 "break" keyword
 
static const string KEYWORD_CONTINUE = "continue"
 "continue" keyword
 
static const string KEYWORD_CASE = "case"
 "case" keyword
 
static const string KEYWORD_SWITCH = "switch"
 "switch" keyword
 
static const string KEYWORD_DEFAULT = "default"
 "default" keyword
 
static const string KEYWORD_RETURN = "return"
 "return" keyword
 
static const string KEYWORD_NEW = "new"
 "new" keyword
 
static const string typePointerRelToken = "ADJ"
 The token to print indicating PTRSUB relative to a TypePointerRel.
 
- Static Public Attributes inherited from ghidra::PrintLanguage
static const string OPEN_PAREN = "("
 "(" token
 
static const string CLOSE_PAREN = ")"
 ")" token
 

Protected Member Functions

void buildTypeStack (const Datatype *ct, vector< const Datatype *> &typestack)
 Prepare to push components of a data-type declaration. More...
 
void pushPrototypeInputs (const FuncProto *proto)
 Push input parameters. More...
 
void pushSymbolScope (const Symbol *symbol)
 Push tokens resolving a symbol's scope. More...
 
void emitSymbolScope (const Symbol *symbol)
 Emit tokens resolving a symbol's scope. More...
 
virtual void pushTypeStart (const Datatype *ct, bool noident)
 Push part of a data-type declaration onto the RPN stack, up to the identifier. More...
 
virtual void pushTypeEnd (const Datatype *ct)
 Push the tail ends of a data-type declaration onto the RPN stack. More...
 
void pushBoolConstant (uintb val, const TypeBase *ct, const Varnode *vn, const PcodeOp *op)
 Push a true or false token to the RPN stack. More...
 
void pushCharConstant (uintb val, const Datatype *ct, const Varnode *vn, const PcodeOp *op)
 Push a single character constant to the RPN stack. More...
 
void pushEnumConstant (uintb val, const TypeEnum *ct, const Varnode *vn, const PcodeOp *op)
 Push an enumerated value to the RPN stack. More...
 
virtual bool pushPtrCharConstant (uintb val, const TypePointer *ct, const Varnode *vn, const PcodeOp *op)
 Attempt to push a quoted string representing a given constant pointer onto the RPN stack. More...
 
bool pushPtrCodeConstant (uintb val, const TypePointer *ct, const Varnode *vn, const PcodeOp *op)
 Attempt to push a function name representing a constant pointer onto the RPN stack. More...
 
virtual bool doEmitWideCharPrefix (void) const
 Return true if this language requires a prefix when expressing wide characters. More...
 
bool checkArrayDeref (const Varnode *vn) const
 Determine whether a LOAD/STORE expression requires pointer '*' syntax. More...
 
void emitStructDefinition (const TypeStruct *ct)
 Emit the definition of a structure data-type. More...
 
void emitEnumDefinition (const TypeEnum *ct)
 Emit the definition of an enumeration data-type. More...
 
void emitPrototypeOutput (const FuncProto *proto, const Funcdata *fd)
 Emit the output data-type of a function prototype. More...
 
void emitPrototypeInputs (const FuncProto *proto)
 Emit the input data-types of a function prototype. More...
 
void emitGlobalVarDeclsRecursive (Scope *symScope)
 Emit variable declarations for all global symbols under given scope. More...
 
void emitLocalVarDecls (const Funcdata *fd)
 Emit variable declarations for a function. More...
 
void emitStatement (const PcodeOp *inst)
 Emit a statement in the body of a function. More...
 
bool emitInplaceOp (const PcodeOp *op)
 Attempt to emit an expression rooted at an in-place operator. More...
 
void emitGotoStatement (const FlowBlock *bl, const FlowBlock *exp_bl, uint4 type)
 Emit a statement representing an unstructured branch. More...
 
void emitSwitchCase (int4 casenum, const BlockSwitch *switchbl)
 Emit labels for a case block. More...
 
void emitLabel (const FlowBlock *bl)
 Emit a formal label for a given control-flow block. More...
 
void emitLabelStatement (const FlowBlock *bl)
 Emit any required label statement for a given basic block. More...
 
void emitAnyLabelStatement (const FlowBlock *bl)
 Emit any required label statement for a given control-flow block. More...
 
void emitCommentGroup (const PcodeOp *inst)
 Emit comments associated with a given statement. More...
 
void emitCommentBlockTree (const FlowBlock *bl)
 Emit any comments under the given control-flow subtree. More...
 
void emitCommentFuncHeader (const Funcdata *fd)
 Emit comments in the given function's header. More...
 
void emitForLoop (const BlockWhileDo *bl)
 Emit block as a for loop. More...
 
void opFunc (const PcodeOp *op)
 Push a functional expression based on the given p-code op to the RPN stack. More...
 
void opTypeCast (const PcodeOp *op)
 Push the given p-code op using type-cast syntax to the RPN stack. More...
 
void opHiddenFunc (const PcodeOp *op)
 Push the given p-code op as a hidden token. More...
 
bool printCharacterConstant (ostream &s, const Address &addr, Datatype *charType) const
 Print a quoted (unicode) string at the given address. More...
 
int4 getHiddenThisSlot (const PcodeOp *op, FuncProto *fc)
 Get position of "this" pointer needing to be hidden. More...
 
void resetDefaultsPrintC (void)
 Set default values for options specific to PrintC.
 
virtual void pushConstant (uintb val, const Datatype *ct, const Varnode *vn, const PcodeOp *op)
 Push a constant onto the RPN stack. More...
 
virtual bool pushEquate (uintb val, int4 sz, const EquateSymbol *sym, const Varnode *vn, const PcodeOp *op)
 Push a constant marked up by and EquateSymbol onto the RPN stack. More...
 
virtual void pushAnnotation (const Varnode *vn, const PcodeOp *op)
 Push an address which is not in the normal data-flow. More...
 
virtual void pushSymbol (const Symbol *sym, const Varnode *vn, const PcodeOp *op)
 Push a specific Symbol onto the RPN stack. More...
 
virtual void pushUnnamedLocation (const Address &addr, const Varnode *vn, const PcodeOp *op)
 Push an address as a substitute for a Symbol onto the RPN stack. More...
 
virtual void pushPartialSymbol (const Symbol *sym, int4 off, int4 sz, const Varnode *vn, const PcodeOp *op, int4 inslot)
 Push a variable that represents only part of a symbol onto the RPN stack. More...
 
virtual void pushMismatchSymbol (const Symbol *sym, int4 off, int4 sz, const Varnode *vn, const PcodeOp *op)
 Push an identifier for a variable that mismatches with its Symbol. More...
 
virtual void pushImpliedField (const Varnode *vn, const PcodeOp *op)
 Push the implied field of a given Varnode as an object member extraction operation. More...
 
virtual void push_integer (uintb val, int4 sz, bool sign, const Varnode *vn, const PcodeOp *op)
 Push a constant with an integer data-type to the RPN stack. More...
 
virtual void push_float (uintb val, int4 sz, const Varnode *vn, const PcodeOp *op)
 Push a constant with a floating-point data-type to the RPN stack. More...
 
virtual void printUnicode (ostream &s, int4 onechar) const
 Print a single unicode character as a character constant for the high-level language. More...
 
virtual void pushType (const Datatype *ct)
 Push a data-type name onto the RPN expression stack. More...
 
virtual string genericFunctionName (const Address &addr)
 Create a generic function name base on the entry point address. More...
 
virtual string genericTypeName (const Datatype *ct)
 Generate a generic name for an unnamed data-type. More...
 
virtual void emitExpression (const PcodeOp *op)
 Emit a full expression. More...
 
virtual void emitVarDecl (const Symbol *sym)
 Emit a variable declaration. More...
 
virtual void emitVarDeclStatement (const Symbol *sym)
 Emit a variable declaration statement. More...
 
virtual bool emitScopeVarDecls (const Scope *symScope, int4 cat)
 Emit all the variable declarations for a given scope. More...
 
virtual void emitFunctionDeclaration (const Funcdata *fd)
 Emit a function declaration. More...
 
virtual void emitTypeDefinition (const Datatype *ct)
 Emit the definition of the given data-type. More...
 
virtual bool checkPrintNegation (const Varnode *vn)
 Check whether a given boolean Varnode can be printed in negated form. More...
 
void pushTypePointerRel (const PcodeOp *op)
 Push a token indicating a PTRSUB (a -> operator) is acting at an offset from the original pointer. More...
 
- Protected Member Functions inherited from ghidra::PrintLanguage
bool isSet (uint4 m) const
 Is the given printing modification active.
 
void pushScope (const Scope *sc)
 Push a new symbol scope.
 
void popScope (void)
 Pop to the previous symbol scope.
 
void pushMod (void)
 Push current printing modifications to the stack.
 
void popMod (void)
 Pop to the previous printing modifications.
 
void setMod (uint4 m)
 Activate the given printing modification.
 
void unsetMod (uint4 m)
 Deactivate the given printing modification.
 
void pushOp (const OpToken *tok, const PcodeOp *op)
 Push an operator token onto the RPN stack. More...
 
void pushAtom (const Atom &atom)
 Push a variable token onto the RPN stack. More...
 
void pushVn (const Varnode *vn, const PcodeOp *op, uint4 m)
 Push an expression rooted at a Varnode onto the RPN stack. More...
 
void pushVnExplicit (const Varnode *vn, const PcodeOp *op)
 Push an explicit variable onto the RPN stack. More...
 
void pushSymbolDetail (const Varnode *vn, const PcodeOp *op, bool isRead)
 Push symbol name with adornments matching given Varnode. More...
 
bool parentheses (const OpToken *op2)
 Determine if the given token should be emitted in its own parenthetic expression. More...
 
void emitOp (const ReversePolish &entry)
 Send an operator token from the RPN to the emitter. More...
 
void emitAtom (const Atom &atom)
 Send an variable token from the RPN to the emitter. More...
 
bool escapeCharacterData (ostream &s, const uint1 *buf, int4 count, int4 charsize, bool bigend) const
 Emit a byte buffer to the stream as unicode characters. More...
 
void recurse (void)
 Emit from the RPN stack as much as possible. More...
 
void opBinary (const OpToken *tok, const PcodeOp *op)
 Push a binary operator onto the RPN stack. More...
 
void opUnary (const OpToken *tok, const PcodeOp *op)
 Push a unary operator onto the RPN stack. More...
 
int4 getPending (void) const
 Get the number of pending nodes yet to be put on the RPN stack.
 
void resetDefaultsInternal (void)
 Reset options to default for PrintLanguage.
 
virtual void emitLineComment (int4 indent, const Comment *comm)
 Emit a comment line. More...
 

Static Protected Member Functions

static void printCharHexEscape (ostream &s, int4 val)
 Print value as an escaped hex sequence. More...
 
- Static Protected Member Functions inherited from ghidra::PrintLanguage
static bool unicodeNeedsEscape (int4 codepoint)
 Determine if the given codepoint needs to be escaped. More...
 

Protected Attributes

bool option_NULL
 Set to true if we should emit NULL keyword.
 
bool option_inplace_ops
 Set to true if we should use '+=' '&=' etc.
 
bool option_convention
 Set to true if we should print calling convention.
 
bool option_nocasts
 Don't print a cast if true.
 
bool option_unplaced
 Set to true if we should display unplaced comments.
 
bool option_hide_exts
 Set to true if we should hide implied extension operations.
 
string nullToken
 Token to use for 'null'.
 
string sizeSuffix
 Characters to print to indicate a long integer token.
 
CommentSorter commsorter
 Container/organizer for comments in the current function.
 
- Protected Attributes inherited from ghidra::PrintLanguage
Architectureglb
 The Architecture owning the language emitter.
 
const Scopecurscope
 The current symbol scope.
 
CastStrategycastStrategy
 The strategy for emitting explicit case operations.
 
Emitemit
 The low-level token emitter.
 
uint4 mods
 Currently active printing modifications.
 
uint4 instr_comment_type
 Type of instruction comments to display.
 
uint4 head_comment_type
 Type of header comments to display.
 
namespace_strategy namespc_strategy
 How should namespace tokens be displayed.
 

Static Protected Attributes

static OpToken hidden = { "", "", 1, 70, false, OpToken::hiddenfunction, 0, 0, (OpToken *)0 }
 Hidden functional (that may force parentheses)
 
static OpToken scope = { "::", "", 2, 70, true, OpToken::binary, 0, 0, (OpToken *)0 }
 The sub-scope/namespace operator.
 
static OpToken object_member = { ".", "", 2, 66, true, OpToken::binary, 0, 0, (OpToken *)0 }
 The member operator.
 
static OpToken pointer_member = { "->", "", 2, 66, true, OpToken::binary, 0, 0, (OpToken *)0 }
 The points to member operator.
 
static OpToken subscript = { "[", "]", 2, 66, false, OpToken::postsurround, 0, 0, (OpToken *)0 }
 The array subscript operator.
 
static OpToken function_call = { "(", ")", 2, 66, false, OpToken::postsurround, 0, 10, (OpToken *)0 }
 The function call operator.
 
static OpToken bitwise_not = { "~", "", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 }
 The bitwise negate operator.
 
static OpToken boolean_not = { "!", "", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 }
 The boolean not operator.
 
static OpToken unary_minus = { "-", "", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 }
 The unary minus operator.
 
static OpToken unary_plus = { "+", "", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 }
 The unary plus operator.
 
static OpToken addressof = { "&", "", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 }
 The address of operator.
 
static OpToken dereference = { "*", "", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 }
 The pointer dereference operator.
 
static OpToken typecast = { "(", ")", 2, 62, false, OpToken::presurround, 0, 0, (OpToken *)0 }
 The type cast operator.
 
static OpToken multiply = { "*", "", 2, 54, true, OpToken::binary, 1, 0, (OpToken *)0 }
 The multiplication operator.
 
static OpToken divide = { "/", "", 2, 54, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The division operator.
 
static OpToken modulo = { "%", "", 2, 54, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The modulo operator.
 
static OpToken binary_plus = { "+", "", 2, 50, true, OpToken::binary, 1, 0, (OpToken *)0 }
 The binary addition operator.
 
static OpToken binary_minus = { "-", "", 2, 50, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The binary subtraction operator.
 
static OpToken shift_left = { "<<", "", 2, 46, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The left shift operator.
 
static OpToken shift_right = { ">>", "", 2, 46, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The right shift operator.
 
static OpToken shift_sright = { ">>", "", 2, 46, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The signed right shift operator.
 
static OpToken less_than = { "<", "", 2, 42, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The less than operator.
 
static OpToken less_equal = { "<=", "", 2, 42, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The less than or equal operator.
 
static OpToken greater_than = { ">", "", 2, 42, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The greater than operator.
 
static OpToken greater_equal = { ">=", "", 2, 42, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The greater than or equal operator.
 
static OpToken equal = { "==", "", 2, 38, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The equal operator.
 
static OpToken not_equal = { "!=", "", 2, 38, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The not equal operator.
 
static OpToken bitwise_and = { "&", "", 2, 34, true, OpToken::binary, 1, 0, (OpToken *)0 }
 The logical and operator.
 
static OpToken bitwise_xor = { "^", "", 2, 30, true, OpToken::binary, 1, 0, (OpToken *)0 }
 The logical xor operator.
 
static OpToken bitwise_or = { "|", "", 2, 26, true, OpToken::binary, 1, 0, (OpToken *)0 }
 The logical or operator.
 
static OpToken boolean_and = { "&&", "", 2, 22, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The boolean and operator.
 
static OpToken boolean_or = { "||", "", 2, 18, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The boolean or operator.
 
static OpToken boolean_xor = { "^^", "", 2, 20, false, OpToken::binary, 1, 0, (OpToken *)0 }
 The boolean xor operator.
 
static OpToken assignment = { "=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The assignment operator.
 
static OpToken comma = { ",", "", 2, 2, true, OpToken::binary, 0, 0, (OpToken *)0 }
 The comma operator (for parameter lists)
 
static OpToken new_op = { "", "", 2, 62, false, OpToken::space, 1, 0, (OpToken *)0 }
 The new operator.
 
static OpToken multequal = { "*=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The in-place multiplication operator.
 
static OpToken divequal = { "/=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The in-place division operator.
 
static OpToken remequal = { "%=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The in-place modulo operator.
 
static OpToken plusequal = { "+=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The in-place addition operator.
 
static OpToken minusequal = { "-=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The in-place subtraction operator.
 
static OpToken leftequal = { "<<=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The in-place left shift operator.
 
static OpToken rightequal = { ">>=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The in-place right shift operator.
 
static OpToken andequal = { "&=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The in-place logical and operator.
 
static OpToken orequal = { "|=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The in-place logical or operator.
 
static OpToken xorequal = { "^=", "", 2, 14, false, OpToken::binary, 1, 5, (OpToken *)0 }
 The in-place logical xor operator.
 
static OpToken type_expr_space = { "", "", 2, 10, false, OpToken::space, 1, 0, (OpToken *)0 }
 Type declaration involving a space (identifier or adornment)
 
static OpToken type_expr_nospace = { "", "", 2, 10, false, OpToken::space, 0, 0, (OpToken *)0 }
 Type declaration with no space.
 
static OpToken ptr_expr = { "*", "", 1, 62, false, OpToken::unary_prefix, 0, 0, (OpToken *)0 }
 Pointer adornment for a type declaration.
 
static OpToken array_expr = { "[", "]", 2, 66, false, OpToken::postsurround, 1, 0, (OpToken *)0 }
 Array adornment for a type declaration.
 
static OpToken enum_cat = { "|", "", 2, 26, true, OpToken::binary, 0, 0, (OpToken *)0 }
 The concatenation operator for enumerated values.
 

Additional Inherited Members

- Public Types inherited from ghidra::PrintLanguage
enum  modifiers {
  force_hex = 1, force_dec = 2, bestfit = 4, force_scinote = 8,
  force_pointer = 0x10, print_load_value = 0x20, print_store_value = 0x40, no_branch = 0x80,
  only_branch = 0x100, comma_separate = 0x200, flat = 0x400, falsebranch = 0x800,
  nofallthru = 0x1000, negatetoken = 0x2000, hide_thisparam = 0x4000, pending_brace = 0x8000
}
 Possible context sensitive modifiers to how tokens get emitted. More...
 
enum  tagtype {
  syntax, vartoken, functoken, optoken,
  typetoken, fieldtoken, blanktoken
}
 Possible types of Atom. More...
 
enum  namespace_strategy { MINIMAL_NAMESPACES = 0, NO_NAMESPACES = 1, ALL_NAMESPACES = 2 }
 Strategies for displaying namespace tokens. More...
 
- Static Public Member Functions inherited from ghidra::PrintLanguage
static int4 mostNaturalBase (uintb val)
 Determine the most natural base for an integer. More...
 
static void formatBinary (ostream &s, uintb val)
 Print a number in binary form. More...
 

Detailed Description

The c-language token emitter.

The c-language specific rules for emitting:

Constructor & Destructor Documentation

◆ PrintC()

ghidra::PrintC::PrintC ( Architecture g,
const string &  nm = "c-language" 
)

Constructor.

Parameters
gis the Architecture owning this c-language emitter
nmis the name assigned to this emitter

References ghidra::PrintLanguage::castStrategy, equal, greater_equal, greater_than, less_equal, less_than, ghidra::OpToken::negate, not_equal, nullToken, and resetDefaultsPrintC().

Member Function Documentation

◆ buildTypeStack()

void ghidra::PrintC::buildTypeStack ( const Datatype ct,
vector< const Datatype *> &  typestack 
)
protected

Prepare to push components of a data-type declaration.

Push nested components of a data-type declaration onto a stack, so we can access it bottom up

Parameters
ctis the data-type being emitted
typestackwill hold the sub-types involved in the displaying the declaration

References ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ghidra::FuncProto::getOutputType(), ghidra::TypeFactory::getTypeVoid(), ghidra::PrintLanguage::glb, ghidra::TYPE_ARRAY, ghidra::TYPE_CODE, ghidra::TYPE_PTR, and ghidra::Architecture::types.

Referenced by pushTypeStart().

◆ checkArrayDeref()

bool ghidra::PrintC::checkArrayDeref ( const Varnode vn) const
protected

Determine whether a LOAD/STORE expression requires pointer '*' syntax.

An expression involving a LOAD or STORE can sometimes be emitted using array syntax (or field member syntax). This method determines if this kind of syntax is appropriate or if a '*' operator is required.

Parameters
vnis the root of the pointer expression (feeding into LOAD or STORE)
Returns
false if '*' syntax is required, true if some other syntax is used

References ghidra::PcodeOp::code(), ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::CPUI_SEGMENTOP, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::isImplied(), and ghidra::Varnode::isWritten().

Referenced by opLoad(), and opStore().

◆ checkPrintNegation()

bool ghidra::PrintC::checkPrintNegation ( const Varnode vn)
protectedvirtual

Check whether a given boolean Varnode can be printed in negated form.

In many situations a boolean value can be inverted by flipping the operator token producing it to a complementary token.

Parameters
vnis the given boolean Varnode
Returns
true if the value can be easily inverted

Implements ghidra::PrintLanguage.

References ghidra::PcodeOp::code(), ghidra::CPUI_MAX, ghidra::Varnode::getDef(), ghidra::Varnode::isImplied(), and ghidra::Varnode::isWritten().

Referenced by opBoolNegate(), and opCbranch().

◆ docFunction()

void ghidra::PrintC::docFunction ( const Funcdata fd)
virtual

◆ docSingleGlobal()

void ghidra::PrintC::docSingleGlobal ( const Symbol sym)
virtual

◆ docTypeDefinitions()

void ghidra::PrintC::docTypeDefinitions ( const TypeFactory typegrp)
virtual

Emit definitions of data-types.

Parameters
typegrpis the container for the data-types that should be defined

Implements ghidra::PrintLanguage.

References ghidra::TypeFactory::dependentOrder(), and emitTypeDefinition().

◆ doEmitWideCharPrefix()

bool ghidra::PrintC::doEmitWideCharPrefix ( void  ) const
protectedvirtual

Return true if this language requires a prefix when expressing wide characters.

The c-language standard requires that strings (and character constants) made up of wide character elements have an 'L' prefix added before the quote characters. Other related languages may not do this. Having this as a virtual method lets derived languages to tailor their strings while still using the basic PrintC functionality

Returns
true if a prefix should be printed

Reimplemented in ghidra::PrintJava.

Referenced by printCharacterConstant(), push_integer(), and pushCharConstant().

◆ emitAnyLabelStatement()

void ghidra::PrintC::emitAnyLabelStatement ( const FlowBlock bl)
protected

Emit any required label statement for a given control-flow block.

The block does not have to be a basic block. This routine finds the entry basic block and prints any necessary labels for that.

Parameters
blis the given control-flow block

References emitLabelStatement(), ghidra::FlowBlock::getFrontLeaf(), and ghidra::FlowBlock::isLabelBumpUp().

Referenced by emitBlockCopy(), emitBlockDoWhile(), emitBlockInfLoop(), emitBlockWhileDo(), and emitForLoop().

◆ emitCommentBlockTree()

void ghidra::PrintC::emitCommentBlockTree ( const FlowBlock bl)
protected

Emit any comments under the given control-flow subtree.

With the control-flow hierarchy, print any comments associated with basic blocks in the specified subtree. Used where statements from multiple basic blocks are printed on one line and a normal comment would get printed in the middle of this line.

Parameters
blis the root of the control-flow subtree

References commsorter, emitCommentGroup(), ghidra::BlockGraph::getSize(), ghidra::FlowBlock::getType(), ghidra::CommentSorter::setupBlockList(), ghidra::FlowBlock::subBlock(), and ghidra::BlockGraph::subBlock().

Referenced by emitBlockIf(), emitBlockWhileDo(), and emitForLoop().

◆ emitCommentFuncHeader()

void ghidra::PrintC::emitCommentFuncHeader ( const Funcdata fd)
protected

◆ emitCommentGroup()

void ghidra::PrintC::emitCommentGroup ( const PcodeOp inst)
protected

Emit comments associated with a given statement.

Collect any comment lines the sorter has associated with a statement rooted at a given PcodeOp and emit them using appropriate delimiters

Parameters
instis the given PcodeOp

References commsorter, ghidra::PrintLanguage::emitLineComment(), ghidra::CommentSorter::getNext(), ghidra::Comment::getType(), ghidra::CommentSorter::hasNext(), ghidra::PrintLanguage::instr_comment_type, ghidra::Comment::isEmitted(), and ghidra::CommentSorter::setupOpList().

Referenced by emitBlockBasic(), and emitCommentBlockTree().

◆ emitEnumDefinition()

void ghidra::PrintC::emitEnumDefinition ( const TypeEnum ct)
protected

◆ emitExpression()

void ghidra::PrintC::emitExpression ( const PcodeOp op)
protectedvirtual

Emit a full expression.

This can be an assignment statement, if the given PcodeOp has an output Varnode, or it can be a statement with no left-hand side.

Parameters
opis the given PcodeOp performing the final operation of the expression

Implements ghidra::PrintLanguage.

References assignment, ghidra::PcodeOp::doesSpecialPrinting(), emitInplaceOp(), ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOpcode(), ghidra::PcodeOp::getOut(), opConstructor(), option_inplace_ops, ghidra::TypeOp::push(), ghidra::PrintLanguage::pushOp(), ghidra::PrintLanguage::pushSymbolDetail(), and ghidra::PrintLanguage::recurse().

Referenced by emitBlockBasic(), emitForLoop(), and emitStatement().

◆ emitForLoop()

void ghidra::PrintC::emitForLoop ( const BlockWhileDo bl)
protected

◆ emitFunctionDeclaration()

void ghidra::PrintC::emitFunctionDeclaration ( const Funcdata fd)
protectedvirtual

◆ emitGlobalVarDeclsRecursive()

void ghidra::PrintC::emitGlobalVarDeclsRecursive ( Scope symScope)
protected

Emit variable declarations for all global symbols under given scope.

For the given scope and all of its children that are not function scopes, emit a variable declaration for each symbol.

Parameters
symScopeis the given scope

References ghidra::Scope::childrenBegin(), ghidra::Scope::childrenEnd(), emitScopeVarDecls(), ghidra::Scope::isGlobal(), and ghidra::Symbol::no_category.

Referenced by docAllGlobals().

◆ emitGotoStatement()

void ghidra::PrintC::emitGotoStatement ( const FlowBlock bl,
const FlowBlock exp_bl,
uint4  type 
)
protected

Emit a statement representing an unstructured branch.

Given the type of unstructured branch, with source and destination blocks, construct a statement with the appropriate c-language keyword (goto, break, continue) representing a control-flow branch between the blocks.

Parameters
blis the source block
exp_blis the destination block (which may provide a label)
typeis the given type of the branch

References ghidra::Emit::beginStatement(), ghidra::PrintLanguage::emit, emitLabel(), ghidra::Emit::endStatement(), ghidra::FlowBlock::f_break_goto, ghidra::FlowBlock::f_continue_goto, ghidra::FlowBlock::f_goto_goto, KEYWORD_BREAK, ghidra::Emit::keyword_color, KEYWORD_CONTINUE, KEYWORD_GOTO, ghidra::FlowBlock::lastOp(), ghidra::Emit::print(), SEMICOLON, and ghidra::Emit::spaces().

Referenced by emitBlockGoto(), emitBlockIf(), emitBlockSwitch(), and emitBlockWhileDo().

◆ emitInplaceOp()

bool ghidra::PrintC::emitInplaceOp ( const PcodeOp op)
protected

Attempt to emit an expression rooted at an in-place operator.

Check that the given p-code op has an in-place token form and if the first input and the output are references to the same variable. If so, emit the expression using the in-place token.

Parameters
opis the given PcodeOp
Returns
true if the expression was emitted (as in-place), or false if not emitted at all

References andequal, ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_AND, ghidra::CPUI_INT_DIV, ghidra::CPUI_INT_LEFT, ghidra::CPUI_INT_MULT, ghidra::CPUI_INT_OR, ghidra::CPUI_INT_REM, ghidra::CPUI_INT_RIGHT, ghidra::CPUI_INT_SDIV, ghidra::CPUI_INT_SREM, ghidra::CPUI_INT_SRIGHT, ghidra::CPUI_INT_SUB, ghidra::CPUI_INT_XOR, divequal, ghidra::Varnode::getHigh(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOut(), leftequal, minusequal, ghidra::PrintLanguage::mods, multequal, orequal, plusequal, ghidra::PrintLanguage::pushOp(), ghidra::PrintLanguage::pushVn(), ghidra::PrintLanguage::pushVnExplicit(), ghidra::PrintLanguage::recurse(), remequal, rightequal, and xorequal.

Referenced by emitExpression().

◆ emitLabel()

void ghidra::PrintC::emitLabel ( const FlowBlock bl)
protected

◆ emitLabelStatement()

void ghidra::PrintC::emitLabelStatement ( const FlowBlock bl)
protected

Emit any required label statement for a given basic block.

If the basic block is the destination of a goto statement, emit a label for the block followed by the ':' terminator.

Parameters
blis the given control-flow block

References COLON, ghidra::PrintLanguage::emit, emitLabel(), ghidra::PrintLanguage::flat, ghidra::FlowBlock::getType(), ghidra::FlowBlock::isJumpTarget(), ghidra::PrintLanguage::isSet(), ghidra::FlowBlock::isUnstructuredTarget(), ghidra::PrintLanguage::only_branch, ghidra::Emit::print(), and ghidra::Emit::tagLine().

Referenced by emitAnyLabelStatement(), and emitBlockBasic().

◆ emitLocalVarDecls()

void ghidra::PrintC::emitLocalVarDecls ( const Funcdata fd)
protected

Emit variable declarations for a function.

A formal variable declaration is emitted for every symbol in the given function scope. I.e. all local variables are declared.

Parameters
fdis the function being emitted

References ghidra::Scope::childrenBegin(), ghidra::Scope::childrenEnd(), ghidra::PrintLanguage::emit, emitScopeVarDecls(), ghidra::Funcdata::getScopeLocal(), ghidra::Symbol::no_category, and ghidra::Emit::tagLine().

Referenced by docFunction().

◆ emitPrototypeInputs()

void ghidra::PrintC::emitPrototypeInputs ( const FuncProto proto)
protected

◆ emitPrototypeOutput()

void ghidra::PrintC::emitPrototypeOutput ( const FuncProto proto,
const Funcdata fd 
)
protected

Emit the output data-type of a function prototype.

In C, when printing a function prototype, the function's output data-type is displayed first as a type declaration, where the function name acts as the declaration's identifier. This method emits the declaration in preparation for this.

Parameters
protois the function prototype object
fdis the (optional) Funcdata object providing additional meta-data about the function

References ghidra::Emit::beginReturnType(), ghidra::PrintLanguage::emit, ghidra::Emit::endReturnType(), ghidra::Funcdata::getFirstReturnOp(), ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::FuncProto::getOutputType(), ghidra::PcodeOp::numInput(), pushType(), ghidra::PrintLanguage::recurse(), and ghidra::TYPE_VOID.

Referenced by emitFunctionDeclaration().

◆ emitScopeVarDecls()

bool ghidra::PrintC::emitScopeVarDecls ( const Scope symScope,
int4  cat 
)
protectedvirtual

◆ emitStatement()

void ghidra::PrintC::emitStatement ( const PcodeOp inst)
protected

Emit a statement in the body of a function.

This emits an entire statement rooted at a given operation. All associated expressions on the right-hand and left-hand sides are recursively emitted. Depending on the current printing properties, the statement is usually terminated with ';' character.

Parameters
instis the given root PcodeOp of the statement

References ghidra::Emit::beginStatement(), ghidra::PrintLanguage::comma_separate, ghidra::PrintLanguage::emit, emitExpression(), ghidra::Emit::endStatement(), ghidra::PrintLanguage::isSet(), ghidra::Emit::print(), and SEMICOLON.

Referenced by emitBlockBasic().

◆ emitStructDefinition()

void ghidra::PrintC::emitStructDefinition ( const TypeStruct ct)
protected

◆ emitSwitchCase()

void ghidra::PrintC::emitSwitchCase ( int4  casenum,
const BlockSwitch switchbl 
)
protected

Emit labels for a case block.

Given a switch block and an index indicating a particular case block, look up all the labels associated with that case and emit them using formal labels with the case keyword and a ':' terminator.

Parameters
casenumis the given index of the case block
switchblis the root block of the switch

References COLON, ghidra::PrintLanguage::emit, ghidra::BlockSwitch::getLabel(), ghidra::BlockSwitch::getNumLabels(), ghidra::BlockSwitch::getSwitchType(), ghidra::BlockSwitch::isDefaultCase(), KEYWORD_CASE, ghidra::Emit::keyword_color, KEYWORD_DEFAULT, ghidra::Emit::print(), pushConstant(), ghidra::PrintLanguage::recurse(), ghidra::Emit::spaces(), and ghidra::Emit::tagLine().

Referenced by emitBlockSwitch().

◆ emitSymbolScope()

void ghidra::PrintC::emitSymbolScope ( const Symbol symbol)
protected

◆ emitTypeDefinition()

void ghidra::PrintC::emitTypeDefinition ( const Datatype ct)
protectedvirtual

Emit the definition of the given data-type.

This is currently limited to a 'struct' or 'enum' definitions. The definition is emitted so that name associated with data-type object will be associated with the definition (in anything that parses it)

Parameters
ctis the given data-type

References ghidra::PrintLanguage::clear(), emitEnumDefinition(), emitStructDefinition(), ghidra::Datatype::getMetatype(), ghidra::Datatype::isEnumType(), and ghidra::TYPE_STRUCT.

Referenced by docTypeDefinitions().

◆ emitVarDecl()

void ghidra::PrintC::emitVarDecl ( const Symbol sym)
protectedvirtual

Emit a variable declaration.

This can be part of a full a statement, or just the declaration of a function parameter

Parameters
symis the Symbol to be declared

Implements ghidra::PrintLanguage.

References ghidra::Emit::beginVarDecl(), ghidra::PrintLanguage::emit, ghidra::Emit::endVarDecl(), ghidra::Symbol::getType(), pushSymbol(), pushTypeEnd(), pushTypeStart(), and ghidra::PrintLanguage::recurse().

Referenced by emitPrototypeInputs(), and emitVarDeclStatement().

◆ emitVarDeclStatement()

void ghidra::PrintC::emitVarDeclStatement ( const Symbol sym)
protectedvirtual

Emit a variable declaration statement.

Parameters
symis the Symbol to be declared

Implements ghidra::PrintLanguage.

References ghidra::PrintLanguage::emit, emitVarDecl(), ghidra::Emit::print(), SEMICOLON, and ghidra::Emit::tagLine().

Referenced by docSingleGlobal(), and emitScopeVarDecls().

◆ genericFunctionName()

string ghidra::PrintC::genericFunctionName ( const Address addr)
protectedvirtual

Create a generic function name base on the entry point address.

Parameters
addris the entry point address of the function
Returns
the generated name

References ghidra::Address::printRaw().

Referenced by opCall().

◆ genericTypeName()

string ghidra::PrintC::genericTypeName ( const Datatype ct)
protectedvirtual

Generate a generic name for an unnamed data-type.

Parameters
ctis the given data-type
Returns
the generated name

References ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::TYPE_FLOAT, ghidra::TYPE_INT, ghidra::TYPE_SPACEBASE, ghidra::TYPE_UINT, and ghidra::TYPE_UNKNOWN.

Referenced by ghidra::PrintJava::pushTypeStart(), and pushTypeStart().

◆ getHiddenThisSlot()

int4 ghidra::PrintC::getHiddenThisSlot ( const PcodeOp op,
FuncProto fc 
)
protected

Get position of "this" pointer needing to be hidden.

For the given CALL op, if a "this" pointer exists and needs to be hidden because of the print configuration, return the Varnode slot corresponding to the "this". Otherwise return -1.

Parameters
opis the given CALL PcodeOp
fcis the function prototype corresponding to the CALL
Returns
the "this" Varnode slot or -1

References ghidra::FuncProto::getParam(), ghidra::FuncProto::hasThisPointer(), ghidra::PrintLanguage::hide_thisparam, ghidra::PrintLanguage::isSet(), ghidra::ProtoParameter::isThisPointer(), and ghidra::PcodeOp::numInput().

Referenced by ghidra::PrintJava::opCallind(), and opCallind().

◆ opBoolNegate()

void ghidra::PrintC::opBoolNegate ( const PcodeOp op)
virtual

◆ opCbranch()

void ghidra::PrintC::opCbranch ( const PcodeOp op)
virtual

◆ opFunc()

void ghidra::PrintC::opFunc ( const PcodeOp op)
protected

Push a functional expression based on the given p-code op to the RPN stack.

This is used for expression that require functional syntax, where the name of the function is the name of the operator. The inputs to the p-code op form the roots of the comma separated list of parameters within the syntax.

Parameters
opis the given PcodeOp

References ghidra::PrintLanguage::blanktoken, comma, EMPTY_STRING, function_call, ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOpcode(), ghidra::TypeOp::getOperatorName(), ghidra::PrintLanguage::mods, ghidra::Emit::no_color, ghidra::PcodeOp::numInput(), ghidra::PrintLanguage::optoken, ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), and ghidra::PrintLanguage::pushVn().

Referenced by opExtractOp(), opInsertOp(), opIntSext(), opIntZext(), and opSubpiece().

◆ opHiddenFunc()

void ghidra::PrintC::opHiddenFunc ( const PcodeOp op)
protected

Push the given p-code op as a hidden token.

The syntax represents the given op using a function with one input, where the function name is not printed. The input expression is simply printed without adornment inside the larger expression, with one minor difference. The hidden operator protects against confusing evaluation order between the operators inside and outside the hidden function. If both the inside and outside operators are the same associative token, the hidden token makes sure the inner expression is surrounded with parentheses.

Parameters
opis the given PcodeOp

References ghidra::PcodeOp::getIn(), hidden, ghidra::PrintLanguage::mods, ghidra::PrintLanguage::pushOp(), and ghidra::PrintLanguage::pushVn().

Referenced by opIntSext(), and opIntZext().

◆ opPtrsub()

void ghidra::PrintC::opPtrsub ( const PcodeOp op)
virtual

We need to distinguish between the following cases:

  • ptr-> struct spacebase or array
  • valueoption on/off (from below)
  • valueflex yes/no (can we turn valueoption above?)

Then the printing breaks up into the following table:

val flex | val flex | val flex | val flex
off yes off no on yes on no
struct &( ).name &( )->name ( ).name ( )->name
spcbase n/a &name n/a name
array ( ) *( ) ( )[0] *( )[0]

The '&' is dropped if the output type is an array

Parameters
opis the PTRSUB PcodeOp

Implements ghidra::PrintLanguage.

References addressof, ghidra::AddrSpace::addressToByteInt(), ghidra::calc_mask(), ghidra::PrintLanguage::clear(), dereference, ghidra::PrintLanguage::fieldtoken, ghidra::Datatype::findTruncation(), ghidra::PcodeOp::getAddr(), ghidra::TypeSpacebase::getAddress(), ghidra::ResolvedUnion::getFieldNum(), ghidra::BlockBasic::getFuncdata(), ghidra::Varnode::getHigh(), ghidra::Varnode::getHighTypeReadFacing(), ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getParent(), ghidra::TypePointerRel::getParent(), ghidra::TypePointerRel::getPointerOffset(), ghidra::TypePointer::getPtrTo(), ghidra::Varnode::getSize(), ghidra::Datatype::getSize(), ghidra::HighVariable::getSymbol(), ghidra::HighVariable::getSymbolOffset(), ghidra::Symbol::getType(), ghidra::Funcdata::getUnionField(), ghidra::TypePointer::getWordSize(), ghidra::TypeField::ident, ghidra::Datatype::isFormalPointerRel(), ghidra::PrintLanguage::mods, ghidra::TypeField::name, ghidra::Emit::no_color, object_member, pointer_member, ghidra::PrintLanguage::print_load_value, ghidra::PrintLanguage::print_store_value, push_integer(), ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), pushPartialSymbol(), pushSymbol(), pushTypePointerRel(), pushUnnamedLocation(), ghidra::PrintLanguage::pushVn(), subscript, ghidra::TypeField::type, ghidra::TYPE_ARRAY, ghidra::TYPE_CODE, ghidra::TYPE_PTR, ghidra::TYPE_SPACEBASE, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.

◆ opSegmentOp()

void ghidra::PrintC::opSegmentOp ( const PcodeOp op)
virtual
  • slot 0 is the spaceid constant
  • slot 1 is the segment, we could conceivably try to annotate the segment here
  • slot 2 is the pointer we are really interested in printing
Parameters
opis the SEGMENTOP PcodeOp

Implements ghidra::PrintLanguage.

References ghidra::PcodeOp::getIn(), ghidra::PrintLanguage::mods, and ghidra::PrintLanguage::pushVn().

◆ opTypeCast()

void ghidra::PrintC::opTypeCast ( const PcodeOp op)
protected

Push the given p-code op using type-cast syntax to the RPN stack.

The syntax represents the given op using a standard c-language cast. The data-type being cast to is obtained from the output variable of the op. The input expression is also recursively pushed.

Parameters
opis the given PcodeOp

References ghidra::Varnode::getHighTypeDefFacing(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOut(), ghidra::PrintLanguage::mods, option_nocasts, ghidra::PrintLanguage::pushOp(), pushType(), ghidra::PrintLanguage::pushVn(), and typecast.

Referenced by opIntSext(), opIntZext(), and opSubpiece().

◆ printCharacterConstant()

bool ghidra::PrintC::printCharacterConstant ( ostream &  s,
const Address addr,
Datatype charType 
) const
protected

Print a quoted (unicode) string at the given address.

Data for the string is obtained directly from the LoadImage. The bytes are checked for appropriate unicode encoding and the presence of a terminator. If all these checks pass, the string is emitted.

Parameters
sis the output stream to print to
addris the address of the string data within the LoadImage
charTypeis the underlying character data-type
Returns
true if a proper string was found and printed to the stream

References doEmitWideCharPrefix(), ghidra::PrintLanguage::escapeCharacterData(), ghidra::Datatype::getSize(), ghidra::StringManager::getStringData(), ghidra::PrintLanguage::glb, ghidra::Translate::isBigEndian(), ghidra::Datatype::isOpaqueString(), ghidra::Architecture::stringManager, and ghidra::Architecture::translate.

Referenced by pushPtrCharConstant().

◆ printCharHexEscape()

void ghidra::PrintC::printCharHexEscape ( ostream &  s,
int4  val 
)
staticprotected

Print value as an escaped hex sequence.

Print the given value using the standard character hexadecimal escape sequence.

Parameters
sis the stream to write to
valis the given value

Referenced by printUnicode(), push_integer(), and pushCharConstant().

◆ printUnicode()

void ghidra::PrintC::printUnicode ( ostream &  s,
int4  onechar 
) const
protectedvirtual

Print a single unicode character as a character constant for the high-level language.

For most languages, this prints the character surrounded by single quotes.

Parameters
sis the output stream
onecharis the unicode code point of the character to print

Implements ghidra::PrintLanguage.

Reimplemented in ghidra::PrintJava.

References printCharHexEscape(), ghidra::PrintLanguage::unicodeNeedsEscape(), and ghidra::StringManager::writeUtf8().

Referenced by push_integer(), and pushCharConstant().

◆ push_float()

void ghidra::PrintC::push_float ( uintb  val,
int4  sz,
const Varnode vn,
const PcodeOp op 
)
protectedvirtual

Push a constant with a floating-point data-type to the RPN stack.

The encoding is drawn from the underlying Translate object, and the print properties are checked for formatting overrides. In any case, a format is decided upon, and the constant is pushed as a single token.

Parameters
valis the given encoded floating-point value
szis the size (in bytes) of the encoded value
vnis the Varnode holding the value
opis the PcodeOp using the value

References ghidra::Emit::const_color, ghidra::FloatFormat::extractSign(), ghidra::PrintLanguage::force_scinote, ghidra::FloatFormat::getDecimalPrecision(), ghidra::Translate::getFloatFormat(), ghidra::FloatFormat::getHostFloat(), ghidra::PrintLanguage::glb, ghidra::FloatFormat::infinity, ghidra::PrintLanguage::mods, ghidra::FloatFormat::nan, ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::syntax, ghidra::Architecture::translate, and ghidra::PrintLanguage::vartoken.

Referenced by pushConstant().

◆ push_integer()

void ghidra::PrintC::push_integer ( uintb  val,
int4  sz,
bool  sign,
const Varnode vn,
const PcodeOp op 
)
protectedvirtual

Push a constant with an integer data-type to the RPN stack.

Various checks are made to see if the integer should be printed as an equate symbol or if there is other overriding information about what format it should be printed in. In any case, a final determination of the format is made and the integer is pushed as a single token.

Parameters
valis the given integer value
szis the size (in bytes) to associate with the integer
signis set to true if the integer should be treated as a signed value
vnis the Varnode holding the value
opis the PcodeOp using the value

References ghidra::calc_mask(), ghidra::Emit::const_color, doEmitWideCharPrefix(), ghidra::Symbol::equate, ghidra::Symbol::force_char, ghidra::PrintLanguage::force_dec, ghidra::Symbol::force_dec, ghidra::PrintLanguage::force_hex, ghidra::Symbol::force_hex, ghidra::Symbol::force_oct, ghidra::PrintLanguage::formatBinary(), ghidra::Symbol::getCategory(), ghidra::Datatype::getDisplayFormat(), ghidra::Symbol::getDisplayFormat(), ghidra::Varnode::getHigh(), ghidra::HighVariable::getSymbol(), ghidra::HighVariable::getType(), ghidra::Varnode::isAnnotation(), ghidra::Varnode::isLongPrint(), ghidra::Symbol::isNameLocked(), ghidra::Varnode::isUnsignedPrint(), ghidra::PrintLanguage::mods, ghidra::PrintLanguage::mostNaturalBase(), printCharHexEscape(), printUnicode(), ghidra::PrintLanguage::pushAtom(), pushEquate(), sizeSuffix, ghidra::PrintLanguage::syntax, and ghidra::PrintLanguage::vartoken.

Referenced by emitEnumDefinition(), ghidra::PrintJava::opLoad(), opPtrsub(), ghidra::PrintJava::opStore(), pushCharConstant(), pushConstant(), pushEnumConstant(), pushEquate(), and pushTypeEnd().

◆ pushAnnotation()

void ghidra::PrintC::pushAnnotation ( const Varnode vn,
const PcodeOp op 
)
protectedvirtual

◆ pushBoolConstant()

void ghidra::PrintC::pushBoolConstant ( uintb  val,
const TypeBase ct,
const Varnode vn,
const PcodeOp op 
)
protected

Push a true or false token to the RPN stack.

A single Atom representing the boolean value is emitted

Parameters
valis the boolean value (non-zero for true)
ctis the data-type associated with the value
vnis the Varnode holding the value
opis the PcodeOp using the value

References ghidra::Emit::const_color, KEYWORD_FALSE, KEYWORD_TRUE, ghidra::PrintLanguage::pushAtom(), and ghidra::PrintLanguage::vartoken.

Referenced by pushConstant().

◆ pushCharConstant()

void ghidra::PrintC::pushCharConstant ( uintb  val,
const Datatype ct,
const Varnode vn,
const PcodeOp op 
)
protected

◆ pushConstant()

void ghidra::PrintC::pushConstant ( uintb  val,
const Datatype ct,
const Varnode vn,
const PcodeOp op 
)
protectedvirtual

◆ pushEnumConstant()

void ghidra::PrintC::pushEnumConstant ( uintb  val,
const TypeEnum ct,
const Varnode vn,
const PcodeOp op 
)
protected

Push an enumerated value to the RPN stack.

Handle cases where the value is built out of multiple named elements of the enumeration or where the value cannot be expressed using named elements

Parameters
valis the enumerated value being pushed
ctis the enumerated data-type attached to the value
vnis the Varnode holding the value
opis the PcodeOp using the value

References bitwise_not, ghidra::Emit::const_color, enum_cat, ghidra::TypeEnum::getMatches(), ghidra::Datatype::getSize(), push_integer(), ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), and ghidra::PrintLanguage::vartoken.

Referenced by pushConstant().

◆ pushEquate()

bool ghidra::PrintC::pushEquate ( uintb  val,
int4  sz,
const EquateSymbol sym,
const Varnode vn,
const PcodeOp op 
)
protectedvirtual

Push a constant marked up by and EquateSymbol onto the RPN stack.

The equate may substitute a name or force a conversion for the constant

Parameters
valis the value of the constant
szis the number of bytes to use for the encoding
symis the EquateSymbol that marks up the constant
vnis the Varnode holding the constant (optional)
opis the PcodeOp using the constant (optional)

Implements ghidra::PrintLanguage.

References binary_minus, binary_plus, bitwise_not, ghidra::calc_mask(), ghidra::EquateSymbol::getValue(), push_integer(), ghidra::PrintLanguage::pushOp(), pushSymbol(), and unary_minus.

Referenced by push_integer(), and pushCharConstant().

◆ pushImpliedField()

void ghidra::PrintC::pushImpliedField ( const Varnode vn,
const PcodeOp op 
)
protectedvirtual

Push the implied field of a given Varnode as an object member extraction operation.

If a Varnode is implied and has a union data-type, the particular read of the varnode may correspond to a particular field that needs to get printed as a token, even though the Varnode itself is printed directly. This method pushes the field name token.

Parameters
vnis the given Varnode
opis the particular PcodeOp reading the Varnode

Implements ghidra::PrintLanguage.

References ghidra::PrintLanguage::fieldtoken, ghidra::Varnode::getDef(), ghidra::ResolvedUnion::getFieldNum(), ghidra::BlockBasic::getFuncdata(), ghidra::Varnode::getHigh(), ghidra::Datatype::getMetatype(), ghidra::PcodeOp::getOpcode(), ghidra::PcodeOp::getParent(), ghidra::PcodeOp::getSlot(), ghidra::HighVariable::getType(), ghidra::Funcdata::getUnionField(), ghidra::TypeField::ident, ghidra::TypeField::name, ghidra::Datatype::needsResolution(), ghidra::Emit::no_color, object_member, ghidra::TypeOp::push(), ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.

◆ pushMismatchSymbol()

void ghidra::PrintC::pushMismatchSymbol ( const Symbol sym,
int4  off,
int4  sz,
const Varnode vn,
const PcodeOp op 
)
protectedvirtual

Push an identifier for a variable that mismatches with its Symbol.

This happens when a Varnode overlaps, but is not contained by a Symbol. This most commonly happens when the size of a Symbol is unknown

Parameters
symis the overlapped symbol
offis the byte offset of the variable relative to the symbol
szis the size of the variable in bytes
vnis the Varnode representing the variable
opis a PcodeOp associated with the Varnode

Implements ghidra::PrintLanguage.

References ghidra::Varnode::getAddr(), ghidra::Symbol::getDisplayName(), ghidra::PrintLanguage::pushAtom(), pushUnnamedLocation(), ghidra::Emit::var_color, and ghidra::PrintLanguage::vartoken.

◆ pushPartialSymbol()

void ghidra::PrintC::pushPartialSymbol ( const Symbol sym,
int4  off,
int4  sz,
const Varnode vn,
const PcodeOp op,
int4  inslot 
)
protectedvirtual

Push a variable that represents only part of a symbol onto the RPN stack.

Generally member syntax specifying a field within a structure gets emitted.

Parameters
symis the root Symbol
offis the byte offset, within the Symbol, of the partial variable
szis the number of bytes in the partial variable
vnis the Varnode holding the partial value
opis a PcodeOp associate with the Varnode
inslotis the input slot of vn with op, or -1 if op writes vn

Implements ghidra::PrintLanguage.

References ghidra::PrintLanguage::castStrategy, ghidra::Emit::const_color, ghidra::PrintLanguage::fieldtoken, ghidra::Datatype::findResolve(), ghidra::Datatype::findTruncation(), ghidra::SymbolEntry::getAddr(), ghidra::Symbol::getFirstWholeMap(), ghidra::Varnode::getHigh(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::Address::getSpace(), ghidra::HighVariable::getType(), ghidra::Symbol::getType(), ghidra::TypeField::ident, ghidra::AddrSpace::isBigEndian(), ghidra::CastStrategy::isSubpieceCastEndian(), ghidra::Datatype::name, ghidra::TypeField::name, ghidra::Datatype::needsResolution(), ghidra::Emit::no_color, object_member, option_nocasts, ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), pushSymbol(), pushType(), subscript, ghidra::PrintLanguage::syntax, ghidra::PartialSymbolEntry::token, ghidra::TypeField::type, ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, ghidra::TYPE_UNION, typecast, and ghidra::PrintLanguage::unnamedField().

Referenced by opPtrsub(), opSubpiece(), and pushAnnotation().

◆ pushPrototypeInputs()

void ghidra::PrintC::pushPrototypeInputs ( const FuncProto proto)
protected

Push input parameters.

Push the comma separated list of data-type declarations onto the RPN stack as part of emitting a given function prototype

Parameters
protois the given function prototype

References ghidra::PrintLanguage::blanktoken, comma, DOTDOTDOT, EMPTY_STRING, ghidra::FuncProto::getParam(), ghidra::ProtoParameter::getType(), ghidra::FuncProto::isDotdotdot(), ghidra::Emit::keyword_color, KEYWORD_VOID, ghidra::Emit::no_color, ghidra::FuncProto::numParams(), ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), pushTypeEnd(), pushTypeStart(), and ghidra::PrintLanguage::syntax.

Referenced by pushTypeEnd().

◆ pushPtrCharConstant()

bool ghidra::PrintC::pushPtrCharConstant ( uintb  val,
const TypePointer ct,
const Varnode vn,
const PcodeOp op 
)
protectedvirtual

Attempt to push a quoted string representing a given constant pointer onto the RPN stack.

Check if the constant pointer refers to character data that can be emitted as a quoted string. If so push the string, if not return false to indicate a token was not pushed

Parameters
valis the value of the given constant pointer
ctis the pointer data-type attached to the value
vnis the Varnode holding the value (may be null)
opis the PcodeOp using the value (may be null)
Returns
true if a quoted string was pushed to the RPN stack

References ghidra::Emit::const_color, ghidra::PcodeOp::getAddr(), ghidra::AddrSpaceManager::getDefaultDataSpace(), ghidra::Database::getGlobalScope(), ghidra::TypePointer::getPtrTo(), ghidra::Datatype::getSize(), ghidra::PrintLanguage::glb, ghidra::Address::isInvalid(), ghidra::Scope::isReadOnly(), printCharacterConstant(), ghidra::PrintLanguage::pushAtom(), ghidra::AddrSpaceManager::resolveConstant(), ghidra::Architecture::symboltab, and ghidra::PrintLanguage::vartoken.

Referenced by pushConstant().

◆ pushPtrCodeConstant()

bool ghidra::PrintC::pushPtrCodeConstant ( uintb  val,
const TypePointer ct,
const Varnode vn,
const PcodeOp op 
)
protected

Attempt to push a function name representing a constant pointer onto the RPN stack.

Given the pointer value, try to look up the function at that address and push the function's name as a single Atom.

Parameters
valis the given constant pointer value
ctis the pointer data-type attached to the value
vnis the Varnode holding the value
opis the PcodeOp using the value
Returns
true if a name was pushed to the RPN stack, return false otherwise

References ghidra::AddrSpace::addressToByte(), ghidra::Emit::funcname_color, ghidra::PrintLanguage::functoken, ghidra::AddrSpaceManager::getDefaultCodeSpace(), ghidra::Database::getGlobalScope(), ghidra::AddrSpace::getWordSize(), ghidra::PrintLanguage::glb, ghidra::PrintLanguage::pushAtom(), ghidra::Scope::queryFunction(), and ghidra::Architecture::symboltab.

Referenced by pushConstant().

◆ pushSymbol()

void ghidra::PrintC::pushSymbol ( const Symbol sym,
const Varnode vn,
const PcodeOp op 
)
protectedvirtual

◆ pushSymbolScope()

void ghidra::PrintC::pushSymbolScope ( const Symbol symbol)
protected

Push tokens resolving a symbol's scope.

Calculate what elements of a given symbol's namespace path are necessary to distinguish it within the current scope. Then print these elements.

Parameters
symbolis the given symbol

References ghidra::PrintLanguage::ALL_NAMESPACES, ghidra::PrintLanguage::curscope, ghidra::Scope::getParent(), ghidra::Symbol::getResolutionDepth(), ghidra::Symbol::getScope(), ghidra::Emit::global_color, ghidra::PrintLanguage::MINIMAL_NAMESPACES, ghidra::PrintLanguage::namespc_strategy, ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), scope, and ghidra::PrintLanguage::syntax.

Referenced by opCall(), and pushSymbol().

◆ pushType()

void ghidra::PrintC::pushType ( const Datatype ct)
protectedvirtual

Push a data-type name onto the RPN expression stack.

The data-type is generally emitted as if for a cast.

Parameters
ctis the data-type to push

Implements ghidra::PrintLanguage.

References ghidra::PrintLanguage::blanktoken, EMPTY_STRING, ghidra::Emit::no_color, ghidra::PrintLanguage::pushAtom(), pushTypeEnd(), and pushTypeStart().

Referenced by emitPrototypeOutput(), opTypeCast(), pushConstant(), and pushPartialSymbol().

◆ pushTypeEnd()

void ghidra::PrintC::pushTypeEnd ( const Datatype ct)
protectedvirtual

Push the tail ends of a data-type declaration onto the RPN stack.

Because the front-ends were pushed on base-type -> final-modifier, the tail-ends are pushed on final-modifier -> base-type. The tail-ends amount to

  • array subscripts . [ # ] and
  • function parameters . ( paramlist )
Parameters
ctis the data-type being pushed

Reimplemented in ghidra::PrintJava.

References ghidra::PrintLanguage::blanktoken, EMPTY_STRING, ghidra::PrintLanguage::force_dec, ghidra::TypeArray::getBase(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ghidra::FuncProto::getOutputType(), ghidra::TypeCode::getPrototype(), ghidra::Emit::no_color, ghidra::TypeArray::numElements(), ghidra::PrintLanguage::popMod(), push_integer(), ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushMod(), pushPrototypeInputs(), ghidra::PrintLanguage::setMod(), ghidra::TYPE_ARRAY, ghidra::TYPE_CODE, and ghidra::TYPE_PTR.

Referenced by emitPrototypeInputs(), emitStructDefinition(), emitVarDecl(), pushPrototypeInputs(), and pushType().

◆ pushTypePointerRel()

void ghidra::PrintC::pushTypePointerRel ( const PcodeOp op)
inlineprotected

Push a token indicating a PTRSUB (a -> operator) is acting at an offset from the original pointer.

When a variable has TypePointerRel as its data-type, PTRSUB acts relative to the parent data-type. We print a specific token to indicate this relative shift is happening.

Parameters
opis is the PTRSUB op

References ghidra::Emit::funcname_color.

Referenced by opPtrsub().

◆ pushTypeStart()

void ghidra::PrintC::pushTypeStart ( const Datatype ct,
bool  noident 
)
protectedvirtual

Push part of a data-type declaration onto the RPN stack, up to the identifier.

Store off array sizes for printing after the identifier

Parameters
ctis the data-type to push
noidentis true if an identifier will not be pushed as part of the declaration

Reimplemented in ghidra::PrintJava.

References array_expr, buildTypeStack(), ghidra::PrintLanguage::clear(), function_call, genericTypeName(), ghidra::Datatype::getDisplayName(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ptr_expr, ghidra::PrintLanguage::pushAtom(), ghidra::PrintLanguage::pushOp(), ghidra::TYPE_ARRAY, ghidra::TYPE_CODE, ghidra::Emit::type_color, type_expr_nospace, type_expr_space, ghidra::TYPE_PTR, and ghidra::PrintLanguage::typetoken.

Referenced by emitPrototypeInputs(), emitStructDefinition(), emitVarDecl(), pushPrototypeInputs(), and pushType().

◆ pushUnnamedLocation()

void ghidra::PrintC::pushUnnamedLocation ( const Address addr,
const Varnode vn,
const PcodeOp op 
)
protectedvirtual

Push an address as a substitute for a Symbol onto the RPN stack.

If there is no Symbol or other name source for an explicit variable, this method is used to print something to represent the variable based on its storage address.

Parameters
addris the storage address
vnis the Varnode representing the variable (if present)
opis a PcodeOp associated with the variable

Implements ghidra::PrintLanguage.

References ghidra::AddrSpace::getName(), ghidra::Address::getSpace(), ghidra::Address::printRaw(), ghidra::PrintLanguage::pushAtom(), ghidra::Emit::var_color, and ghidra::PrintLanguage::vartoken.

Referenced by opPtrsub(), and pushMismatchSymbol().

◆ setCommentStyle()

void ghidra::PrintC::setCommentStyle ( const string &  nm)
virtual

Set the way comments are displayed in decompiler output.

This method can either be provided a formal name or a sample of the initial delimiter, then it will choose from among the schemes it knows

Parameters
nmis the configuration description

Implements ghidra::PrintLanguage.

References setCPlusPlusStyleComments(), and setCStyleComments().


The documentation for this class was generated from the following files: