Package ghidra.app.decompiler
Class ClangToken
java.lang.Object
ghidra.app.decompiler.ClangToken
- All Implemented Interfaces:
ClangNode
- Direct Known Subclasses:
ClangBreak
,ClangCaseToken
,ClangCommentToken
,ClangFieldToken
,ClangFuncNameToken
,ClangLabelToken
,ClangOpToken
,ClangSyntaxToken
,ClangTypeToken
,ClangVariableToken
Class representing a source code language token.
A token has numerous display attributes and may link to the data-flow analysis
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
ConstructorDescriptionClangToken
(ClangNode par) ClangToken
(ClangNode par, String txt) ClangToken
(ClangNode par, String txt, int color) -
Method Summary
Modifier and TypeMethodDescriptionstatic ClangToken
buildSpacer
(ClangNode par, int indent, String indentStr) Add a spacer token to the given text groupingstatic ClangToken
buildToken
(int node, ClangNode par, Decoder decoder, PcodeFactory pfactory) Decode one specialized token from the current position in an encoded stream.Child
(int i) Get the i-th child groupingvoid
decode
(Decoder decoder, PcodeFactory pfactory) Decode this token from the current position in an encoded streamvoid
Flatten this text into a list of tokens (see ClangToken)Get the text representing an entire function of which this is part.Get the background highlight color used to render this token, or null if not highlightedgetHighSymbol
(HighFunction highFunction) Get the symbol associated with this token or null otherwise.Get the high-level variable associate with this token or null otherwiseGet the element representing an entire line of text that contains this elementGet the biggest Program address associated with the code that this text representsGet the smallest Program address associated with the code that this text representsMany tokens directly represent a pcode operator in the data-flowIf the token represents an underlying integer constant, return the constant as a Scalar.int
Get the "syntax" type (color) associated with this token (keyword, type, etc)getText()
Many tokens directly represent a variable in the data-flowboolean
boolean
iterator
(boolean forward) Get an iterator over tokens starting with this ClangToken.int
Return the number of immediate groupings this text breaks up intoParent()
Get the immediate grouping (parent) containing this text element.void
setHighlight
(Color val) Set a highlighting background color for all text elementsvoid
setLineParent
(ClangLine line) Set (change) the line which this text element part of.void
setMatchingToken
(boolean matchingToken) Set whether or not additional "matching" highlighting is applied to this token.toString()
-
Field Details
-
KEYWORD_COLOR
public static final int KEYWORD_COLOR- See Also:
-
COMMENT_COLOR
public static final int COMMENT_COLOR- See Also:
-
TYPE_COLOR
public static final int TYPE_COLOR- See Also:
-
FUNCTION_COLOR
public static final int FUNCTION_COLOR- See Also:
-
VARIABLE_COLOR
public static final int VARIABLE_COLOR- See Also:
-
CONST_COLOR
public static final int CONST_COLOR- See Also:
-
PARAMETER_COLOR
public static final int PARAMETER_COLOR- See Also:
-
GLOBAL_COLOR
public static final int GLOBAL_COLOR- See Also:
-
DEFAULT_COLOR
public static final int DEFAULT_COLOR- See Also:
-
ERROR_COLOR
public static final int ERROR_COLOR- See Also:
-
SPECIAL_COLOR
public static final int SPECIAL_COLOR- See Also:
-
MAX_COLOR
public static final int MAX_COLOR- See Also:
-
-
Constructor Details
-
ClangToken
-
ClangToken
-
ClangToken
-
-
Method Details
-
Parent
Description copied from interface:ClangNode
Get the immediate grouping (parent) containing this text element. If this is a complete document, null is returned. -
getLineParent
Get the element representing an entire line of text that contains this element- Returns:
- the containing ClangLine
-
setLineParent
Set (change) the line which this text element part of.- Parameters:
line
- is the new ClangLine
-
getMinAddress
Description copied from interface:ClangNode
Get the smallest Program address associated with the code that this text represents- Specified by:
getMinAddress
in interfaceClangNode
- Returns:
- the smallest Address
-
getMaxAddress
Description copied from interface:ClangNode
Get the biggest Program address associated with the code that this text represents- Specified by:
getMaxAddress
in interfaceClangNode
- Returns:
- the biggest Address
-
numChildren
public int numChildren()Description copied from interface:ClangNode
Return the number of immediate groupings this text breaks up into- Specified by:
numChildren
in interfaceClangNode
- Returns:
- the number of child groupings
-
Child
Description copied from interface:ClangNode
Get the i-th child grouping -
getClangFunction
Description copied from interface:ClangNode
Get the text representing an entire function of which this is part.- Specified by:
getClangFunction
in interfaceClangNode
- Returns:
- text for the whole function
-
setHighlight
Description copied from interface:ClangNode
Set a highlighting background color for all text elements- Specified by:
setHighlight
in interfaceClangNode
- Parameters:
val
- is the color to set
-
getHighlight
Get the background highlight color used to render this token, or null if not highlighted- Returns:
- the Color or null
-
setMatchingToken
public void setMatchingToken(boolean matchingToken) Set whether or not additional "matching" highlighting is applied to this token. Currently this means a bounding box is drawn around the token.- Parameters:
matchingToken
- is true to enable highlighting, false to disable
-
isMatchingToken
public boolean isMatchingToken()- Returns:
- true if this token should be displayed with "matching" highlighting
-
isVariableRef
public boolean isVariableRef()- Returns:
- true if this token represents a variable (in source code)
-
getSyntaxType
public int getSyntaxType()Get the "syntax" type (color) associated with this token (keyword, type, etc)- Returns:
- the color code
-
getText
- Returns:
- this token's display text as a string
-
decode
Decode this token from the current position in an encoded stream- Parameters:
decoder
- is the decoder for the streampfactory
- is used to look up p-code objects associated with the token- Throws:
DecoderException
- for problems decoding the stream
-
flatten
Description copied from interface:ClangNode
Flatten this text into a list of tokens (see ClangToken) -
buildToken
public static ClangToken buildToken(int node, ClangNode par, Decoder decoder, PcodeFactory pfactory) throws DecoderException Decode one specialized token from the current position in an encoded stream. This serves as a factory for allocating the various objects derived from ClangToken- Parameters:
node
- is the particular token type (already) decoded from the streampar
- is the text grouping which will contain the tokendecoder
- is the decoder for the streampfactory
- is used to look up p-code objects associated with tokens- Returns:
- the new ClangToken
- Throws:
DecoderException
- for problems decoding the stream
-
buildSpacer
Add a spacer token to the given text grouping- Parameters:
par
- is the text groupingindent
- is the number of levels to indentindentStr
- is a string representing containg the number of spaces in one indent level- Returns:
- the new spacer token
-
toString
-
getHighVariable
Get the high-level variable associate with this token or null otherwise- Returns:
- HighVariable
-
getHighSymbol
Get the symbol associated with this token or null otherwise. This token may be directly associated with the symbol or a reference, in which case the symbol is looked up in the containing HighFunction- Parameters:
highFunction
- is the function- Returns:
- HighSymbol
-
getVarnode
Many tokens directly represent a variable in the data-flow- Returns:
- the variable (Varnode) associated with this token or null
-
getPcodeOp
Many tokens directly represent a pcode operator in the data-flow- Returns:
- the operation (PcodeOp) associated with this token or null
-
getScalar
If the token represents an underlying integer constant, return the constant as a Scalar. Otherwise return null.- Returns:
- the Scalar that the token represents or null
-
iterator
Get an iterator over tokens starting with this ClangToken. Tokens are returned in normal display order (forward=true) or in the reverse of normal display order (forward=false)- Parameters:
forward
- is true for forward iterator, false for a backward iterator- Returns:
- the Iterator object
-