decompiler  1.0.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ghidra::EmitPrettyPrint Class Reference

A generic source code pretty printer. More...

#include <prettyprint.hh>

Inheritance diagram for ghidra::EmitPrettyPrint:
ghidra::Emit

Public Member Functions

 EmitPrettyPrint (void)
 Construct with an initial maximum line size.
 
virtual int4 beginDocument (void)
 Begin a whole document of output. More...
 
virtual void endDocument (int4 id)
 End a whole document of output. More...
 
virtual int4 beginFunction (const Funcdata *fd)
 Begin a whole declaration and body of a function. More...
 
virtual void endFunction (int4 id)
 End a whole declaration and body of a function. More...
 
virtual int4 beginBlock (const FlowBlock *bl)
 Begin a control-flow element. More...
 
virtual void endBlock (int4 id)
 End a control-flow element. More...
 
virtual void tagLine (void)
 Force a line break. More...
 
virtual void tagLine (int4 indent)
 Force a line break and indent level. More...
 
virtual int4 beginReturnType (const Varnode *vn)
 Begin a return type declaration. More...
 
virtual void endReturnType (int4 id)
 End a return type declaration. More...
 
virtual int4 beginVarDecl (const Symbol *sym)
 Begin a variable declaration. More...
 
virtual void endVarDecl (int4 id)
 End a variable declaration. More...
 
virtual int4 beginStatement (const PcodeOp *op)
 Begin a source code statement. More...
 
virtual void endStatement (int4 id)
 End a source code statement. More...
 
virtual int4 beginFuncProto (void)
 Begin a function prototype declaration. More...
 
virtual void endFuncProto (int4 id)
 End a function prototype declaration. More...
 
virtual void tagVariable (const string &name, syntax_highlight hl, const Varnode *vn, const PcodeOp *op)
 Emit a variable token. More...
 
virtual void tagOp (const string &name, syntax_highlight hl, const PcodeOp *op)
 Emit an operation token. More...
 
virtual void tagFuncName (const string &name, syntax_highlight hl, const Funcdata *fd, const PcodeOp *op)
 Emit a function identifier. More...
 
virtual void tagType (const string &name, syntax_highlight hl, const Datatype *ct)
 Emit a data-type identifier. More...
 
virtual void tagField (const string &name, syntax_highlight hl, const Datatype *ct, int4 off, const PcodeOp *op)
 Emit an identifier for a field within a structured data-type. More...
 
virtual void tagComment (const string &name, syntax_highlight hl, const AddrSpace *spc, uintb off)
 Emit a comment string as part of the generated source code. More...
 
virtual void tagLabel (const string &name, syntax_highlight hl, const AddrSpace *spc, uintb off)
 Emit a code label identifier. More...
 
virtual void print (const string &data, syntax_highlight hl=no_color)
 Emit other (more unusual) syntax as part of source code generation. More...
 
virtual int4 openParen (const string &paren, int4 id=0)
 Emit an open parenthesis. More...
 
virtual void closeParen (const string &paren, int4 id)
 Emit a close parenthesis. More...
 
virtual int4 openGroup (void)
 Start a group of things that are printed together. More...
 
virtual void closeGroup (int4 id)
 End a group of things that are printed together. More...
 
virtual void clear (void)
 Reset the emitter to its initial state.
 
virtual void setOutputStream (ostream *t)
 Set the output stream for the emitter.
 
virtual ostream * getOutputStream (void) const
 Get the current output stream.
 
virtual void spaces (int4 num, int4 bump=0)
 Emit a sequence of space characters as part of source code. More...
 
virtual int4 startIndent (void)
 Start a new indent level. More...
 
virtual void stopIndent (int4 id)
 End an indent level. More...
 
virtual int4 startComment (void)
 Start a comment block within the emitted source code. More...
 
virtual void stopComment (int4 id)
 End a comment block. More...
 
virtual void flush (void)
 Flush any remaining character data. More...
 
virtual void setMaxLineSize (int4 val)
 Provide a maximum line size to the pretty printer. More...
 
virtual int4 getMaxLineSize (void) const
 Get the current maximum line size. More...
 
virtual void setCommentFill (const string &fill)
 Set the comment fill characters for when line breaks are forced. More...
 
virtual bool emitsMarkup (void) const
 Determine if this is an XML markup emitter. More...
 
virtual void resetDefaults (void)
 (Re)set the default emitting options
 
void setMarkup (bool val)
 Toggle whether the low-level emitter emits markup or not. More...
 
- Public Member Functions inherited from ghidra::Emit
 Emit (void)
 
virtual ~Emit (void)
 Destructor.
 
int4 getParenLevel (void) const
 Get the current parentheses depth. More...
 
int4 getIndentIncrement (void) const
 Get the number of characters indented per level of nesting. More...
 
void setIndentIncrement (int4 val)
 Set the number of characters indented per level of nesting. More...
 
void setPendingPrint (PendPrint *pend)
 Set a pending print callback. More...
 
void cancelPendingPrint (void)
 Cancel any pending print callback. More...
 
bool hasPendingPrint (PendPrint *pend) const
 Check if the given print callback is still pending. More...
 

Private Member Functions

void expand (void)
 Expand the stream buffer. More...
 
void checkstart (void)
 Enforce whitespace for a start token. More...
 
void checkend (void)
 Enforce whitespace for an end token. More...
 
void checkstring (void)
 Enforce whitespace for a content token. More...
 
void checkbreak (void)
 Enforce whitespace for a line break. More...
 
void overflow (void)
 Reset indenting levels to accommodate a token that won't fit. More...
 
void print (const TokenSplit &tok)
 Output the given token to the low-level emitter. More...
 
void advanceleft (void)
 Emit tokens that have been fully committed. More...
 
void scan (void)
 Process a new token. More...
 
void resetDefaultsPrettyPrint (void)
 Reset the defaults.
 

Private Attributes

Emitlowlevel
 The low-level emitter.
 
vector< int4 > indentstack
 Space available for currently active nesting levels.
 
int4 spaceremain
 Space remaining in current line.
 
int4 maxlinesize
 Maximum number of characters allowed in a line.
 
int4 leftotal
 

of characters committed from the current line


 
int4 rightotal
 

of characters yet to be committed from the current line


 
bool needbreak
 true if break needed before next token
 
bool commentmode
 true if in the middle of a comment
 
string commentfill
 Used to fill comments if line breaks are forced.
 
circularqueue< int4 > scanqueue
 References to current open and whitespace tokens.
 
circularqueue< TokenSplittokqueue
 The full stream of tokens.
 

Additional Inherited Members

- Public Types inherited from ghidra::Emit
enum  syntax_highlight {
  keyword_color = 0, comment_color = 1, type_color = 2, funcname_color = 3,
  var_color = 4, const_color = 5, param_color = 6, global_color = 7,
  no_color = 8, error_color = 9, special_color = 10
}
 Possible types of syntax highlighting. More...
 
- Static Public Attributes inherited from ghidra::Emit
static const string EMPTY_STRING = ""
 An empty string.
 
- Protected Member Functions inherited from ghidra::Emit
void resetDefaultsInternal (void)
 Set options to default values for EmitMarkup.
 
void emitPending (void)
 Emit any pending print commands.
 
- Protected Attributes inherited from ghidra::Emit
int4 indentlevel
 Current indent level (in fixed width characters)
 
int4 parenlevel
 Current depth of parentheses.
 
int4 indentincrement
 Change in indentlevel per level of nesting.
 
PendPrintpendPrint
 Pending print callback.
 

Detailed Description

A generic source code pretty printer.

This pretty printer is based on the standard Derek C. Oppen pretty printing algorithm. It allows configurable indenting, spacing, and line breaks that enhances the readability of the high-level language output. It makes use of the extra information inherent in the AST to make decisions about how to best print language statements. It attempts to abstract the main formatting elements of imperative languages: statements, code blocks, declarations, etc., and so should be largely language independent. In this way, the main language emitter doesn't have to worry about formatting issues.

This emitter encapsulates a lower-level emitter that does the final emitting to stream and may add markup.

Member Function Documentation

◆ advanceleft()

void ghidra::EmitPrettyPrint::advanceleft ( void  )
private

Emit tokens that have been fully committed.

Groups of tokens that have been fully committed are sent to the low-level emitter and purged from the queue. Delimiter tokens that open a new printing group initially have a negative size, indicating the group is uncommitted and may need additional line breaks inserted. As the ending delimiters are scanned and/or line breaks are forced. The negative sizes are converted to positive and the corresponding group becomes committed, and the constituent content is emitted by this method.

References leftotal, print(), ghidra::TokenSplit::tokenbreak, ghidra::TokenSplit::tokenstring, and tokqueue.

Referenced by scan().

◆ beginBlock()

int4 ghidra::EmitPrettyPrint::beginBlock ( const FlowBlock bl)
virtual

Begin a control-flow element.

Inform the emitter that a new control-flow section is starting. This is a source code unit usually surrounded with curly braces '{' and '}'.

Parameters
blis the block structure object associated with the section
Returns
an id associated with the section

Implements ghidra::Emit.

References ghidra::TokenSplit::beginBlock(), scan(), and tokqueue.

◆ beginDocument()

int4 ghidra::EmitPrettyPrint::beginDocument ( void  )
virtual

Begin a whole document of output.

Inform the emitter that generation of the source code document has begun

Returns
an id associated with the document

Implements ghidra::Emit.

References ghidra::TokenSplit::beginDocument(), checkstart(), scan(), and tokqueue.

◆ beginFuncProto()

int4 ghidra::EmitPrettyPrint::beginFuncProto ( void  )
virtual

Begin a function prototype declaration.

Inform the emitter that a function prototype is starting.

Returns
an id associated with the prototype

Implements ghidra::Emit.

References ghidra::TokenSplit::beginFuncProto(), checkstart(), scan(), and tokqueue.

◆ beginFunction()

int4 ghidra::EmitPrettyPrint::beginFunction ( const Funcdata fd)
virtual

Begin a whole declaration and body of a function.

Inform the emitter that generation of a function body has begun

Returns
an id associated with the function body

Implements ghidra::Emit.

References ghidra::TokenSplit::beginFunction(), checkstart(), scan(), and tokqueue.

◆ beginReturnType()

int4 ghidra::EmitPrettyPrint::beginReturnType ( const Varnode vn)
virtual

Begin a return type declaration.

Inform the emitter that generation of a function's return type is starting.

Parameters
vn(if non-null) is the storage location for the return value
Returns
an id associated with the return type

Implements ghidra::Emit.

References ghidra::TokenSplit::beginReturnType(), checkstart(), scan(), and tokqueue.

◆ beginStatement()

int4 ghidra::EmitPrettyPrint::beginStatement ( const PcodeOp op)
virtual

Begin a source code statement.

Inform the emitter that a source code statement is beginning.

Parameters
opis the root p-code operation of the statement
Returns
an id associated with the statement

Implements ghidra::Emit.

References ghidra::TokenSplit::beginStatement(), checkstart(), scan(), and tokqueue.

◆ beginVarDecl()

int4 ghidra::EmitPrettyPrint::beginVarDecl ( const Symbol sym)
virtual

Begin a variable declaration.

Inform the emitter that a variable declaration has started.

Parameters
symis the symbol being declared
Returns
an id associated with the declaration

Implements ghidra::Emit.

References ghidra::TokenSplit::beginVarDecl(), checkstart(), scan(), and tokqueue.

◆ checkbreak()

void ghidra::EmitPrettyPrint::checkbreak ( void  )
private

Enforce whitespace for a line break.

Make sure there is some content either in the current print group or following the last line break, inserting an empty string token if necessary, before emitting a line break token.

References ghidra::Emit::EMPTY_STRING, needbreak, ghidra::Emit::no_color, ghidra::TokenSplit::print(), scan(), and tokqueue.

Referenced by spaces(), and tagLine().

◆ checkend()

void ghidra::EmitPrettyPrint::checkend ( void  )
private

Enforce whitespace for an end token.

Make sure there is some content either in the current print group or following the last line break, inserting an empty string token if necessary, before emitting an end token.

References ghidra::Emit::EMPTY_STRING, needbreak, ghidra::Emit::no_color, ghidra::TokenSplit::print(), scan(), and tokqueue.

Referenced by closeGroup(), endDocument(), endFuncProto(), endFunction(), endReturnType(), endStatement(), endVarDecl(), and stopComment().

◆ checkstart()

void ghidra::EmitPrettyPrint::checkstart ( void  )
private

Enforce whitespace for a start token.

Make sure there is whitespace after the last content token, inserting a zero-sized whitespace token if necessary, before emitting a start token.

References needbreak, scan(), ghidra::TokenSplit::spaces(), and tokqueue.

Referenced by beginDocument(), beginFuncProto(), beginFunction(), beginReturnType(), beginStatement(), beginVarDecl(), openGroup(), and startComment().

◆ checkstring()

void ghidra::EmitPrettyPrint::checkstring ( void  )
private

Enforce whitespace for a content token.

Make sure there is whitespace after the last content token, inserting a zero-sized whitespace token if necessary, before emitting a content token.

References needbreak, scan(), ghidra::TokenSplit::spaces(), and tokqueue.

Referenced by closeParen(), print(), tagComment(), tagField(), tagFuncName(), tagLabel(), tagOp(), tagType(), and tagVariable().

◆ closeGroup()

void ghidra::EmitPrettyPrint::closeGroup ( int4  id)
virtual

End a group of things that are printed together.

Inform the emitter that a printing group is ending.

Parameters
idis the id associated with the group (as returned by openGroup)

Reimplemented from ghidra::Emit.

References checkend(), ghidra::TokenSplit::closeGroup(), scan(), and tokqueue.

Referenced by closeParen().

◆ closeParen()

void ghidra::EmitPrettyPrint::closeParen ( const string &  paren,
int4  id 
)
virtual

Emit a close parenthesis.

This method emits the parenthesis character itself and ends the printing unit that was started by the matching open parenthesis.

Parameters
parenis the close parenthesis character to emit
idis the id associated with the matching open parenthesis (as returned by openParen)

Implements ghidra::Emit.

References checkstring(), closeGroup(), ghidra::TokenSplit::closeParen(), scan(), and tokqueue.

◆ emitsMarkup()

virtual bool ghidra::EmitPrettyPrint::emitsMarkup ( void  ) const
inlinevirtual

Determine if this is an XML markup emitter.

Returns
true if this produces an XML markup of its emitted source code

Implements ghidra::Emit.

References ghidra::Emit::emitsMarkup(), and ghidra::Emit::resetDefaults().

◆ endBlock()

void ghidra::EmitPrettyPrint::endBlock ( int4  id)
virtual

End a control-flow element.

Inform the emitter that a control-flow section is ending.

Parameters
idis the id associated with the section (as returned by beginBlock)

Implements ghidra::Emit.

References ghidra::TokenSplit::endBlock(), scan(), and tokqueue.

◆ endDocument()

void ghidra::EmitPrettyPrint::endDocument ( int4  id)
virtual

End a whole document of output.

Inform the emitter that generation of the source code document is finished

Parameters
idis the id associated with the document (as returned by beginDocument)

Implements ghidra::Emit.

References checkend(), ghidra::TokenSplit::endDocument(), scan(), and tokqueue.

◆ endFuncProto()

void ghidra::EmitPrettyPrint::endFuncProto ( int4  id)
virtual

End a function prototype declaration.

Inform the emitter that a function prototype is ending.

Parameters
idis the id associated with the prototype (as returned by beginFuncProto)

Implements ghidra::Emit.

References checkend(), ghidra::TokenSplit::endFuncProto(), scan(), and tokqueue.

◆ endFunction()

void ghidra::EmitPrettyPrint::endFunction ( int4  id)
virtual

End a whole declaration and body of a function.

Inform the emitter that generation of a function body has ended

Parameters
idis the id associated with the function body (as returned by beginFunction)

Implements ghidra::Emit.

References checkend(), ghidra::TokenSplit::endFunction(), scan(), and tokqueue.

◆ endReturnType()

void ghidra::EmitPrettyPrint::endReturnType ( int4  id)
virtual

End a return type declaration.

Inform the emitter that generation of a function's return type is ending.

Parameters
idis the id associated with the return type (as returned by beginReturnType)

Implements ghidra::Emit.

References checkend(), ghidra::TokenSplit::endReturnType(), scan(), and tokqueue.

◆ endStatement()

void ghidra::EmitPrettyPrint::endStatement ( int4  id)
virtual

End a source code statement.

Inform the emitter that a source code statement is ending.

Parameters
idis the id associated with the statement (as returned by beginStatement)

Implements ghidra::Emit.

References checkend(), ghidra::TokenSplit::endStatement(), scan(), and tokqueue.

◆ endVarDecl()

void ghidra::EmitPrettyPrint::endVarDecl ( int4  id)
virtual

End a variable declaration.

Inform the emitter that a variable declaration has ended.

Parameters
idis the id associated with the declaration (as returned by beginVarDecl)

Implements ghidra::Emit.

References checkend(), ghidra::TokenSplit::endVarDecl(), scan(), and tokqueue.

◆ expand()

void ghidra::EmitPrettyPrint::expand ( void  )
private

Expand the stream buffer.

Increase the number of tokens that can be in the queue simultaneously. This is automatically called when the buffers are full. Given a fixed maximum line size for the pretty printer, the buffer should quickly reach a size that supports the biggest possible number of cached tokens. The current token queue is preserved and references into the queue are recalculated.

References ghidra::circularqueue< _type >::expand(), ghidra::circularqueue< _type >::ref(), scanqueue, and tokqueue.

Referenced by scan().

◆ flush()

void ghidra::EmitPrettyPrint::flush ( void  )
virtual

Flush any remaining character data.

Depending on the particular emitter, tokens and syntax that have been submitted to the emitter may be held internally for a time before getting output to the final stream. This routine makes sure submitted syntax is fully output.

Reimplemented from ghidra::Emit.

References ghidra::circularqueue< _type >::empty(), ghidra::Emit::flush(), indentstack, lowlevel, needbreak, print(), scanqueue, and tokqueue.

◆ getMaxLineSize()

virtual int4 ghidra::EmitPrettyPrint::getMaxLineSize ( void  ) const
inlinevirtual

Get the current maximum line size.

If the emitter respects a maximum line size, return that size.

Returns
the maximum line size or -1 if the emitter does not have a maximum

Reimplemented from ghidra::Emit.

◆ openGroup()

int4 ghidra::EmitPrettyPrint::openGroup ( void  )
virtual

Start a group of things that are printed together.

Inform the emitter that a new printing group is starting.

Returns
an id associated with the group

Reimplemented from ghidra::Emit.

References checkstart(), ghidra::TokenSplit::openGroup(), scan(), and tokqueue.

Referenced by openParen().

◆ openParen()

int4 ghidra::EmitPrettyPrint::openParen ( const string &  paren,
int4  id = 0 
)
virtual

Emit an open parenthesis.

This method emits the parenthesis character itself and also starts a printing unit of the source code being surrounded by the parentheses.

Parameters
parenis the open parenthesis character to emit
idis an id to associate with the parenthesis
Returns
an id associated with the parenthesis

Implements ghidra::Emit.

References needbreak, openGroup(), ghidra::TokenSplit::openParen(), scan(), and tokqueue.

◆ overflow()

void ghidra::EmitPrettyPrint::overflow ( void  )
private

Reset indenting levels to accommodate a token that won't fit.

(Permanently) adjust the current set of indent levels to guarantee a minimum amount of space and issue a line break. This disrupts currently established indenting but makes sure that at least half the line is available for the next token.

References ghidra::Emit::comment_color, commentfill, commentmode, indentstack, lowlevel, maxlinesize, ghidra::Emit::print(), spaceremain, and ghidra::Emit::tagLine().

Referenced by print().

◆ print() [1/2]

void ghidra::EmitPrettyPrint::print ( const TokenSplit tok)
private

◆ print() [2/2]

void ghidra::EmitPrettyPrint::print ( const string &  data,
syntax_highlight  hl = no_color 
)
virtual

Emit other (more unusual) syntax as part of source code generation.

This method is used to emit syntax not covered by the other methods, such as spaces, semi-colons, braces, and other punctuation.

Parameters
datais the character data of the syntax being emitted
hlindicates how the syntax should be highlighted

Implements ghidra::Emit.

References checkstring(), ghidra::TokenSplit::print(), scan(), and tokqueue.

◆ scan()

void ghidra::EmitPrettyPrint::scan ( void  )
private

Process a new token.

The token is assumed to be just added and at the top of the queue. This is the heart of the pretty printing algorithm. The new token is assigned a size, the queue of open references and line breaks is updated. The amount of space currently available and the size of printing groups are updated. If the current line is going to overflow, a decision is made where in the uncommented tokens a line break needs to be inserted and what its indent level will be. If the leftmost print group closes without needing a line break, all the content it contains is committed and is sent to the low-level emitter.

References advanceleft(), ghidra::TokenSplit::begin, ghidra::TokenSplit::begin_comment, ghidra::TokenSplit::begin_indent, ghidra::circularqueue< _type >::empty(), ghidra::TokenSplit::end, ghidra::TokenSplit::end_comment, ghidra::TokenSplit::end_indent, expand(), ghidra::TokenSplit::getClass(), ghidra::TokenSplit::getSize(), ghidra::TokenSplit::ignore, leftotal, ghidra::circularqueue< _type >::pop(), ghidra::circularqueue< _type >::popbottom(), ghidra::circularqueue< _type >::push(), rightotal, scanqueue, ghidra::TokenSplit::setSize(), spaceremain, ghidra::TokenSplit::tokenbreak, ghidra::TokenSplit::tokenstring, tokqueue, and ghidra::circularqueue< _type >::top().

Referenced by beginBlock(), beginDocument(), beginFuncProto(), beginFunction(), beginReturnType(), beginStatement(), beginVarDecl(), checkbreak(), checkend(), checkstart(), checkstring(), closeGroup(), closeParen(), endBlock(), endDocument(), endFuncProto(), endFunction(), endReturnType(), endStatement(), endVarDecl(), openGroup(), openParen(), print(), spaces(), startComment(), startIndent(), stopComment(), stopIndent(), tagComment(), tagField(), tagFuncName(), tagLabel(), tagLine(), tagOp(), tagType(), and tagVariable().

◆ setCommentFill()

virtual void ghidra::EmitPrettyPrint::setCommentFill ( const string &  fill)
inlinevirtual

Set the comment fill characters for when line breaks are forced.

If the pretty printer forces a line break in the middle of a comment, this string is emitted to provide proper syntax and indenting to continue the comment.

Parameters
fillis the set of fill characters

Reimplemented from ghidra::Emit.

◆ setMarkup()

void ghidra::EmitPrettyPrint::setMarkup ( bool  val)

Toggle whether the low-level emitter emits markup or not.

This method toggles the low-level emitter between EmitMarkup and EmitNoMarkup depending on whether markup is desired.

Parameters
valis true if markup is desired

References ghidra::Emit::getOutputStream(), lowlevel, and ghidra::Emit::setOutputStream().

◆ setMaxLineSize()

void ghidra::EmitPrettyPrint::setMaxLineSize ( int4  mls)
virtual

Provide a maximum line size to the pretty printer.

The emitter may insert line breaks to enforce this maximum.

Parameters
mlsis the number of characters to set for the maximum line size

Reimplemented from ghidra::Emit.

References clear(), maxlinesize, scanqueue, ghidra::circularqueue< _type >::setMax(), spaceremain, and tokqueue.

◆ spaces()

void ghidra::EmitPrettyPrint::spaces ( int4  num,
int4  bump = 0 
)
virtual

Emit a sequence of space characters as part of source code.

Parameters
numis the number of space characters to emit
bumpis the number of characters to indent if the spaces force a line break

Reimplemented from ghidra::Emit.

References checkbreak(), scan(), ghidra::TokenSplit::spaces(), and tokqueue.

◆ startComment()

int4 ghidra::EmitPrettyPrint::startComment ( void  )
virtual

Start a comment block within the emitted source code.

Inform the emitter that a set of comment tokens/lines is starting.

Returns
an id associated with the comment block

Reimplemented from ghidra::Emit.

References checkstart(), scan(), ghidra::TokenSplit::startComment(), and tokqueue.

◆ startIndent()

int4 ghidra::EmitPrettyPrint::startIndent ( void  )
virtual

Start a new indent level.

Inform the emitter that one level of nesting is being added.

Returns
an id associated with the nesting

Reimplemented from ghidra::Emit.

References ghidra::Emit::indentincrement, scan(), ghidra::TokenSplit::startIndent(), and tokqueue.

◆ stopComment()

void ghidra::EmitPrettyPrint::stopComment ( int4  id)
virtual

End a comment block.

Inform the emitter that a set of comment tokens/lines is ending.

Parameters
idis the id associated with the block (as returned by startComment)

Reimplemented from ghidra::Emit.

References checkend(), scan(), ghidra::TokenSplit::stopComment(), and tokqueue.

◆ stopIndent()

void ghidra::EmitPrettyPrint::stopIndent ( int4  id)
virtual

End an indent level.

Inform the emitter that the current nesting has ended, and we are returning to the previous level.

Parameters
idis the id associated with the nesting (as returned by startIndent)

Reimplemented from ghidra::Emit.

References scan(), ghidra::TokenSplit::stopIndent(), and tokqueue.

◆ tagComment()

void ghidra::EmitPrettyPrint::tagComment ( const string &  name,
syntax_highlight  hl,
const AddrSpace spc,
uintb  off 
)
virtual

Emit a comment string as part of the generated source code.

Individual comments can be broken up and emitted using multiple calls to this method, but ultimately the comment delimiters and the body of the comment are both emitted with this method, which may provide addition markup.

Parameters
nameis the character data for the comment
hlindicates how the comment should be highlighted
spcis the address space of the address where the comment is attached
offis the offset of the address where the comment is attached

Implements ghidra::Emit.

References checkstring(), scan(), ghidra::TokenSplit::tagComment(), and tokqueue.

◆ tagField()

void ghidra::EmitPrettyPrint::tagField ( const string &  name,
syntax_highlight  hl,
const Datatype ct,
int4  off,
const PcodeOp op 
)
virtual

Emit an identifier for a field within a structured data-type.

A string representing an individual component of a structured data-type is emitted, possibly with additional markup.

Parameters
nameis the character data for the identifier
hlindicates how the identifier should be highlighted
ctis the data-type associated with the field
offis the (byte) offset of the field within its structured data-type
opis the PcodeOp associated with the field (usually PTRSUB or SUBPIECE)

Implements ghidra::Emit.

References checkstring(), scan(), ghidra::TokenSplit::tagField(), and tokqueue.

◆ tagFuncName()

void ghidra::EmitPrettyPrint::tagFuncName ( const string &  name,
syntax_highlight  hl,
const Funcdata fd,
const PcodeOp op 
)
virtual

Emit a function identifier.

An identifier string representing the symbol name of the function is emitted, possible with additional markup.

Parameters
nameis the character data for the identifier
hlindicates how the identifier should be highlighted
fdis the function
opis the CALL operation associated within the syntax tree or null for a declaration

Implements ghidra::Emit.

References checkstring(), scan(), ghidra::TokenSplit::tagFuncName(), and tokqueue.

◆ tagLabel()

void ghidra::EmitPrettyPrint::tagLabel ( const string &  name,
syntax_highlight  hl,
const AddrSpace spc,
uintb  off 
)
virtual

Emit a code label identifier.

A string describing a control-flow destination, as appropriate for the source language is output, possibly with additional markup.

Parameters
nameis the character data of the label
hlindicates how the label should be highlighted
spcis the address space of the code address being labeled
offis the offset of the code address being labeled

Implements ghidra::Emit.

References checkstring(), scan(), ghidra::TokenSplit::tagLabel(), and tokqueue.

◆ tagLine() [1/2]

void ghidra::EmitPrettyPrint::tagLine ( void  )
virtual

Force a line break.

Tell the emitter that a new line is desired at the current indent level

Implements ghidra::Emit.

References checkbreak(), ghidra::Emit::emitPending(), scan(), ghidra::TokenSplit::tagLine(), and tokqueue.

◆ tagLine() [2/2]

void ghidra::EmitPrettyPrint::tagLine ( int4  indent)
virtual

Force a line break and indent level.

Tell the emitter that a new line is desired at a specific indent level. The indent level is overridden only for the line, then it returns to its previous value.

Parameters
indentis the desired indent level for the new line

Implements ghidra::Emit.

References checkbreak(), ghidra::Emit::emitPending(), scan(), ghidra::TokenSplit::tagLine(), and tokqueue.

◆ tagOp()

void ghidra::EmitPrettyPrint::tagOp ( const string &  name,
syntax_highlight  hl,
const PcodeOp op 
)
virtual

Emit an operation token.

The string representing the operation as appropriate for the source language is emitted, possibly with additional markup.

Parameters
nameis the character data for the emitted representation
hlindicates how the token should be highlighted
opis the PcodeOp object associated with the operation with the syntax tree

Implements ghidra::Emit.

References checkstring(), scan(), ghidra::TokenSplit::tagOp(), and tokqueue.

◆ tagType()

void ghidra::EmitPrettyPrint::tagType ( const string &  name,
syntax_highlight  hl,
const Datatype ct 
)
virtual

Emit a data-type identifier.

A string representing the name of a data-type, as appropriate for the source language is emitted, possibly with additional markup.

Parameters
nameis the character data for the identifier
hlindicates how the identifier should be highlighted
ctis the data-type description object

Implements ghidra::Emit.

References checkstring(), scan(), ghidra::TokenSplit::tagType(), and tokqueue.

◆ tagVariable()

void ghidra::EmitPrettyPrint::tagVariable ( const string &  name,
syntax_highlight  hl,
const Varnode vn,
const PcodeOp op 
)
virtual

Emit a variable token.

An identifier string representing the variable is output, possibly with additional markup.

Parameters
nameis the character data for the identifier
hlindicates how the identifier should be highlighted
vnis the Varnode representing the variable within the syntax tree
opis a p-code operation related to the use of the variable (may be null)

Implements ghidra::Emit.

References checkstring(), scan(), ghidra::TokenSplit::tagVariable(), and tokqueue.


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