decompiler  1.0.0
Public Types | Public Member Functions | Private Attributes | Static Private Attributes | List of all members
TokenSplit Class Reference

A token/command object in the pretty printing stream. More...

#include <prettyprint.hh>

Public Types

enum  printclass {
  begin, end, tokenstring, tokenbreak,
  begin_indent, end_indent, begin_comment, end_comment,
  ignore
}
 An enumeration denoting the general class of a token. More...
 
enum  tag_type {
  docu_b, docu_e, func_b, func_e,
  bloc_b, bloc_e, rtyp_b, rtyp_e,
  vard_b, vard_e, stat_b, stat_e,
  prot_b, prot_e, vari_t, op_t,
  fnam_t, type_t, field_t, comm_t,
  label_t, synt_t, opar_t, cpar_t,
  oinv_t, cinv_t, spac_t, bump_t,
  line_t
}
 The exhaustive list of possible token types. More...
 

Public Member Functions

 TokenSplit (void)
 Constructor.
 
int4 beginDocument (void)
 Create a "begin document" command. More...
 
void endDocument (int4 id)
 Create an "end document" command. More...
 
int4 beginFunction (const Funcdata *f)
 Create a "begin function body" command. More...
 
void endFunction (int4 id)
 Create an "end function body" command. More...
 
int4 beginBlock (const FlowBlock *b)
 Create a "begin control-flow element" command. More...
 
void endBlock (int4 id)
 Create an "end control-flow element" command. More...
 
int4 beginReturnType (const Varnode *v)
 Create a "begin return type declaration" command. More...
 
void endReturnType (int4 id)
 Create an "end return type declaration" command. More...
 
int4 beginVarDecl (const Symbol *sym)
 Create a "begin variable declaration" command. More...
 
void endVarDecl (int4 id)
 Create an "end variable declaration" command. More...
 
int4 beginStatement (const PcodeOp *o)
 Create a "begin source code statement" command. More...
 
void endStatement (int4 id)
 Create an "end source code statement" command. More...
 
int4 beginFuncProto (void)
 Create a "begin function prototype declaration" command. More...
 
void endFuncProto (int4 id)
 Create an "end function prototype declaration" command. More...
 
void tagVariable (const char *ptr, EmitXml::syntax_highlight h, const Varnode *v, const PcodeOp *o)
 Create a variable identifier token. More...
 
void tagOp (const char *ptr, EmitXml::syntax_highlight h, const PcodeOp *o)
 Create an operator token. More...
 
void tagFuncName (const char *ptr, EmitXml::syntax_highlight h, const Funcdata *f, const PcodeOp *o)
 Create a function identifier token. More...
 
void tagType (const char *ptr, EmitXml::syntax_highlight h, const Datatype *ct)
 Create a data-type identifier token. More...
 
void tagField (const char *ptr, EmitXml::syntax_highlight h, const Datatype *ct, int4 o)
 Create an identifier for a field within a structured data-type. More...
 
void tagComment (const char *ptr, EmitXml::syntax_highlight h, const AddrSpace *s, uintb o)
 Create a comment string in the generated source code. More...
 
void tagLabel (const char *ptr, EmitXml::syntax_highlight h, const AddrSpace *s, uintb o)
 Create a code label identifier token. More...
 
void print (const char *str, EmitXml::syntax_highlight h)
 Create a token for other (more unusual) syntax in source code. More...
 
void openParen (char o, int4 id)
 Create an open parenthesis. More...
 
void closeParen (char c, int4 id)
 Create a close parenthesis. More...
 
int4 openGroup (void)
 Create a "start a printing group" command. More...
 
void closeGroup (int4 id)
 Create an "end a printing group" command. More...
 
int4 startIndent (int4 bump)
 Create a "start a new indent level" command. More...
 
void stopIndent (int4 id)
 Create an "end an indent level" command. More...
 
int4 startComment (void)
 Create a "start a comment block" command. More...
 
void stopComment (int4 id)
 Create an "end a comment block" command. More...
 
void spaces (int4 num, int4 bump)
 Create a whitespace token. More...
 
void tagLine (void)
 Create a line break token.
 
void tagLine (int4 indent)
 Create a line break token with special indentation.
 
void print (EmitXml *emit) const
 Send this token to emitter. More...
 
int4 getIndentBump (void) const
 Get the extra indent after a line break.
 
int4 getNumSpaces (void) const
 Get the number of characters of whitespace.
 
int4 getSize (void) const
 Get the number of content characters.
 
void setSize (int4 sz)
 Set the number of content characters.
 
printclass getClass (void) const
 Get the print class of this.
 
tag_type getTag (void) const
 Get this tag type.
 

Private Attributes

tag_type tagtype
 Type of token.
 
printclass delimtype
 The general class of the token.
 
string tok
 Characters of token (if any)
 
EmitXml::syntax_highlight hl
 Highlighting for token.
 
const PcodeOpop
 Pcode-op associated with this token.
 
union {
   const Varnode *   vn
 Associated Varnode.
 
   const FlowBlock *   bl
 Associated Control-flow.
 
   const Funcdata *   fd
 Associated Function.
 
   const Datatype *   ct
 Associated Data-type.
 
   const AddrSpace *   spc
 Associated Address.
 
   const Symbol *   symbol
 Associated Symbol being displayed.
 
ptr_second
 Additional markup associated with the token.
 
uintb off
 Offset associated either with address or field markup.
 
int4 indentbump
 Amount to indent if a line breaks.
 
int4 numspaces
 Number of spaces in a whitespace token (tokenbreak)
 
int4 size
 Number of content characters or other size information.
 
int4 count
 Associated id (for matching begin/end pairs)
 

Static Private Attributes

static int4 countbase = 0
 Static counter for uniquely assigning begin/end pair ids.
 

Detailed Description

A token/command object in the pretty printing stream.

The pretty printing algorithm (see EmitPrettyPrint) works on the stream of tokens, constituting the content actually being output, plus additional embedded commands made up begin/end or open/close pairs that delimit the (hierarchy of) groups of tokens that should be printed as a unit. Instances of this class represent all the possible elements of this stream.

All instances exhibit a broad printclass that generally reflects whether the token is one of the begin/end delimiters or is actual content. Instances also have a tag_type that indicate the specific function of the token within the stream, which mirror the begin/end/open/close/tag methods on the emitter classes (EmitXml).

Member Enumeration Documentation

◆ printclass

An enumeration denoting the general class of a token.

Enumerator
begin 

A token that starts a printing group.

end 

A token that ends a printing group.

tokenstring 

A token representing actual content.

tokenbreak 

White space (where line breaks can be inserted)

begin_indent 

Start of a new nesting level.

end_indent 

End of a nesting level.

begin_comment 

Start of a comment block.

end_comment 

End of a comment block.

ignore 

Mark-up that doesn't affect pretty printing.

◆ tag_type

The exhaustive list of possible token types.

Enumerator
docu_b 

Start of a document.

docu_e 

End of a document.

func_b 

Start of a function body.

func_e 

End of a function body.

bloc_b 

Start of a control-flow section.

bloc_e 

End of a control-flow section.

rtyp_b 

Start of a return type declaration.

rtyp_e 

End of a return type declaration.

vard_b 

Start of a variable declaration.

vard_e 

End of a variable declaration.

stat_b 

Start of a statement.

stat_e 

End of a statement.

prot_b 

Start of a function prototype.

prot_e 

End of a function prototype.

vari_t 

A variable identifier.

op_t 

An operator.

fnam_t 

A function identifier.

type_t 

A data-type identifier.

field_t 

A field name for a structured data-type.

comm_t 

Part of a comment block.

label_t 

A code label.

synt_t 

Other unspecified syntax.

opar_t 

Open parenthesis.

cpar_t 

Close parenthesis.

oinv_t 

Start of an arbitrary (invisible) grouping.

cinv_t 

End of an arbitrary (invisible) grouping.

spac_t 

White space.

bump_t 

Required line break.

line_t 

Required line break with one-time indent level.

Member Function Documentation

◆ beginBlock()

int4 TokenSplit::beginBlock ( const FlowBlock b)
inline

Create a "begin control-flow element" command.

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

References bloc_b, count, countbase, delimtype, ignore, ptr_second, and tagtype.

Referenced by EmitPrettyPrint::beginBlock().

◆ beginDocument()

int4 TokenSplit::beginDocument ( void  )
inline

Create a "begin document" command.

Returns
an id associated with the document

References begin, count, countbase, delimtype, docu_b, size, and tagtype.

Referenced by EmitPrettyPrint::beginDocument().

◆ beginFuncProto()

int4 TokenSplit::beginFuncProto ( void  )
inline

Create a "begin function prototype declaration" command.

Returns
an id associated with the prototype

References begin, count, countbase, delimtype, prot_b, and tagtype.

Referenced by EmitPrettyPrint::beginFuncProto().

◆ beginFunction()

int4 TokenSplit::beginFunction ( const Funcdata f)
inline

Create a "begin function body" command.

Returns
an id associated with the function body

References begin, count, countbase, delimtype, func_b, ptr_second, size, and tagtype.

Referenced by EmitPrettyPrint::beginFunction().

◆ beginReturnType()

int4 TokenSplit::beginReturnType ( const Varnode v)
inline

Create a "begin return type declaration" command.

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

References begin, count, countbase, delimtype, ptr_second, rtyp_b, and tagtype.

Referenced by EmitPrettyPrint::beginReturnType().

◆ beginStatement()

int4 TokenSplit::beginStatement ( const PcodeOp o)
inline

Create a "begin source code statement" command.

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

References begin, count, countbase, delimtype, op, stat_b, and tagtype.

Referenced by EmitPrettyPrint::beginStatement().

◆ beginVarDecl()

int4 TokenSplit::beginVarDecl ( const Symbol sym)
inline

Create a "begin variable declaration" command.

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

References begin, count, countbase, delimtype, ptr_second, tagtype, and vard_b.

Referenced by EmitPrettyPrint::beginVarDecl().

◆ closeGroup()

void TokenSplit::closeGroup ( int4  id)
inline

Create an "end a printing group" command.

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

References cinv_t, count, delimtype, end, and tagtype.

Referenced by EmitPrettyPrint::closeGroup().

◆ closeParen()

void TokenSplit::closeParen ( char  c,
int4  id 
)
inline

Create a close parenthesis.

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

References count, cpar_t, delimtype, size, tagtype, tok, and tokenstring.

Referenced by EmitPrettyPrint::closeParen().

◆ endBlock()

void TokenSplit::endBlock ( int4  id)
inline

Create an "end control-flow element" command.

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

References bloc_e, count, delimtype, ignore, and tagtype.

Referenced by EmitPrettyPrint::endBlock().

◆ endDocument()

void TokenSplit::endDocument ( int4  id)
inline

Create an "end document" command.

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

References count, delimtype, docu_e, end, size, and tagtype.

Referenced by EmitPrettyPrint::endDocument().

◆ endFuncProto()

void TokenSplit::endFuncProto ( int4  id)
inline

Create an "end function prototype declaration" command.

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

References count, delimtype, end, prot_e, and tagtype.

Referenced by EmitPrettyPrint::endFuncProto().

◆ endFunction()

void TokenSplit::endFunction ( int4  id)
inline

Create an "end function body" command.

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

References count, delimtype, end, func_e, size, and tagtype.

Referenced by EmitPrettyPrint::endFunction().

◆ endReturnType()

void TokenSplit::endReturnType ( int4  id)
inline

Create an "end return type declaration" command.

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

References count, delimtype, end, rtyp_e, and tagtype.

Referenced by EmitPrettyPrint::endReturnType().

◆ endStatement()

void TokenSplit::endStatement ( int4  id)
inline

Create an "end source code statement" command.

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

References count, delimtype, end, stat_e, and tagtype.

Referenced by EmitPrettyPrint::endStatement().

◆ endVarDecl()

void TokenSplit::endVarDecl ( int4  id)
inline

Create an "end variable declaration" command.

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

References count, delimtype, end, tagtype, and vard_e.

Referenced by EmitPrettyPrint::endVarDecl().

◆ openGroup()

int4 TokenSplit::openGroup ( void  )
inline

Create a "start a printing group" command.

Returns
an id associated with the group

References begin, count, countbase, delimtype, oinv_t, and tagtype.

Referenced by EmitPrettyPrint::openGroup().

◆ openParen()

void TokenSplit::openParen ( char  o,
int4  id 
)
inline

Create an open parenthesis.

Parameters
ois the open parenthesis character to emit
idis an id to associate with the parenthesis

References count, delimtype, opar_t, size, tagtype, tok, and tokenstring.

Referenced by EmitPrettyPrint::openParen().

◆ print() [1/2]

void TokenSplit::print ( const char *  str,
EmitXml::syntax_highlight  h 
)
inline

Create a token for other (more unusual) syntax in source code.

Parameters
stris the character data of the syntax being emitted
hindicates how the syntax should be highlighted

References delimtype, hl, size, synt_t, tagtype, tok, and tokenstring.

Referenced by EmitPrettyPrint::checkbreak(), EmitPrettyPrint::checkend(), and EmitPrettyPrint::print().

◆ print() [2/2]

void TokenSplit::print ( EmitXml emit) const

Send this token to emitter.

Emit markup or content corresponding to this token on a low-level emitter. The API method matching the token type is called, feeding it content contained in the object.

Parameters
emitis the low-level emitter to output to

◆ spaces()

void TokenSplit::spaces ( int4  num,
int4  bump 
)
inline

Create a whitespace token.

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

References delimtype, indentbump, numspaces, spac_t, tagtype, and tokenbreak.

Referenced by EmitPrettyPrint::checkstart(), EmitPrettyPrint::checkstring(), and EmitPrettyPrint::spaces().

◆ startComment()

int4 TokenSplit::startComment ( void  )
inline

Create a "start a comment block" command.

Returns
an id associated with the comment block

References begin_comment, count, countbase, delimtype, oinv_t, and tagtype.

Referenced by EmitPrettyPrint::startComment().

◆ startIndent()

int4 TokenSplit::startIndent ( int4  bump)
inline

Create a "start a new indent level" command.

Parameters
bumpthe number of additional characters to indent
Returns
an id associated with the nesting

References begin_indent, bump_t, count, countbase, delimtype, indentbump, size, and tagtype.

Referenced by EmitPrettyPrint::startIndent().

◆ stopComment()

void TokenSplit::stopComment ( int4  id)
inline

Create an "end a comment block" command.

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

References cinv_t, count, delimtype, end_comment, and tagtype.

Referenced by EmitPrettyPrint::stopComment().

◆ stopIndent()

void TokenSplit::stopIndent ( int4  id)
inline

Create an "end an indent level" command.

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

References bump_t, count, delimtype, end_indent, size, and tagtype.

Referenced by EmitPrettyPrint::stopIndent().

◆ tagComment()

void TokenSplit::tagComment ( const char *  ptr,
EmitXml::syntax_highlight  h,
const AddrSpace s,
uintb  o 
)
inline

Create a comment string in the generated source code.

Parameters
ptris the character data for the comment
hindicates how the comment should be highlighted
sis the address space of the address where the comment is attached
ois the offset of the address where the comment is attached

References comm_t, delimtype, hl, off, ptr_second, size, tagtype, tok, and tokenstring.

Referenced by EmitPrettyPrint::tagComment().

◆ tagField()

void TokenSplit::tagField ( const char *  ptr,
EmitXml::syntax_highlight  h,
const Datatype ct,
int4  o 
)
inline

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

Parameters
ptris the character data for the identifier
hindicates how the identifier should be highlighted
ctis the data-type associated with the field
ois the (byte) offset of the field within its structured data-type

References ct, delimtype, field_t, hl, off, ptr_second, size, tagtype, tok, and tokenstring.

Referenced by EmitPrettyPrint::tagField().

◆ tagFuncName()

void TokenSplit::tagFuncName ( const char *  ptr,
EmitXml::syntax_highlight  h,
const Funcdata f,
const PcodeOp o 
)
inline

Create a function identifier token.

Parameters
ptris the character data for the identifier
hindicates how the identifier should be highlighted
fis the function
ois the CALL operation associated within the syntax tree or null for a declaration

References delimtype, fnam_t, hl, op, ptr_second, size, tagtype, tok, and tokenstring.

Referenced by EmitPrettyPrint::tagFuncName().

◆ tagLabel()

void TokenSplit::tagLabel ( const char *  ptr,
EmitXml::syntax_highlight  h,
const AddrSpace s,
uintb  o 
)
inline

Create a code label identifier token.

Parameters
ptris the character data of the label
hindicates how the label should be highlighted
sis the address space of the code address being labeled
ois the offset of the code address being labeled

References delimtype, hl, label_t, off, ptr_second, size, tagtype, tok, and tokenstring.

Referenced by EmitPrettyPrint::tagLabel().

◆ tagOp()

void TokenSplit::tagOp ( const char *  ptr,
EmitXml::syntax_highlight  h,
const PcodeOp o 
)
inline

Create an operator token.

Parameters
ptris the character data for the emitted representation
hindicates how the token should be highlighted
ois the PcodeOp object associated with the operation with the syntax tree

References delimtype, hl, op, op_t, size, tagtype, tok, and tokenstring.

Referenced by EmitPrettyPrint::tagOp().

◆ tagType()

void TokenSplit::tagType ( const char *  ptr,
EmitXml::syntax_highlight  h,
const Datatype ct 
)
inline

Create a data-type identifier token.

Parameters
ptris the character data for the identifier
hindicates how the identifier should be highlighted
ctis the data-type description object

References ct, delimtype, hl, ptr_second, size, tagtype, tok, tokenstring, and type_t.

Referenced by EmitPrettyPrint::tagType().

◆ tagVariable()

void TokenSplit::tagVariable ( const char *  ptr,
EmitXml::syntax_highlight  h,
const Varnode v,
const PcodeOp o 
)
inline

Create a variable identifier token.

Parameters
ptris the character data for the identifier
hindicates how the identifier should be highlighted
vis the Varnode representing the variable within the syntax tree
ois a p-code operation related to the use of the variable (may be null)

References delimtype, hl, op, ptr_second, size, tagtype, tok, tokenstring, and vari_t.

Referenced by EmitPrettyPrint::tagVariable().


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