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

public class ClangToken extends Object implements ClangNode
Class representing a source code language token. A token has numerous display attributes and may link to the data-flow analysis
  • Field Details

  • Constructor Details

  • Method Details

    • Parent

      public ClangNode Parent()
      Description copied from interface: ClangNode
      Get the immediate grouping (parent) containing this text element. If this is a complete document, null is returned.
      Specified by:
      Parent in interface ClangNode
      Returns:
      the parent grouping or null
    • getLineParent

      public ClangLine getLineParent()
      Get the element representing an entire line of text that contains this element
      Returns:
      the containing ClangLine
    • setLineParent

      public void setLineParent(ClangLine line)
      Set (change) the line which this text element part of.
      Parameters:
      line - is the new ClangLine
    • getMinAddress

      public Address getMinAddress()
      Description copied from interface: ClangNode
      Get the smallest Program address associated with the code that this text represents
      Specified by:
      getMinAddress in interface ClangNode
      Returns:
      the smallest Address
    • getMaxAddress

      public Address getMaxAddress()
      Description copied from interface: ClangNode
      Get the biggest Program address associated with the code that this text represents
      Specified by:
      getMaxAddress in interface ClangNode
      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 interface ClangNode
      Returns:
      the number of child groupings
    • Child

      public ClangNode Child(int i)
      Description copied from interface: ClangNode
      Get the i-th child grouping
      Specified by:
      Child in interface ClangNode
      Parameters:
      i - is the index selecting the grouping
      Returns:
      the selected grouping
    • getClangFunction

      public ClangFunction getClangFunction()
      Description copied from interface: ClangNode
      Get the text representing an entire function of which this is part.
      Specified by:
      getClangFunction in interface ClangNode
      Returns:
      text for the whole function
    • setHighlight

      public void setHighlight(Color val)
      Description copied from interface: ClangNode
      Set a highlighting background color for all text elements
      Specified by:
      setHighlight in interface ClangNode
      Parameters:
      val - is the color to set
    • getHighlight

      public Color 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

      public String getText()
      Returns:
      this token's display text as a string
    • decode

      public void decode(Decoder decoder, PcodeFactory pfactory) throws DecoderException
      Decode this token from the current position in an encoded stream
      Parameters:
      decoder - is the decoder for the stream
      pfactory - is used to look up p-code objects associated with the token
      Throws:
      DecoderException - for problems decoding the stream
    • flatten

      public void flatten(List<ClangNode> list)
      Description copied from interface: ClangNode
      Flatten this text into a list of tokens (see ClangToken)
      Specified by:
      flatten in interface ClangNode
      Parameters:
      list - is the container that will contain the tokens
    • 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 stream
      par - is the text grouping which will contain the token
      decoder - is the decoder for the stream
      pfactory - is used to look up p-code objects associated with tokens
      Returns:
      the new ClangToken
      Throws:
      DecoderException - for problems decoding the stream
    • buildSpacer

      public static ClangToken buildSpacer(ClangNode par, int indent, String indentStr)
      Add a spacer token to the given text grouping
      Parameters:
      par - is the text grouping
      indent - is the number of levels to indent
      indentStr - is a string representing containg the number of spaces in one indent level
      Returns:
      the new spacer token
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getHighVariable

      public HighVariable getHighVariable()
      Get the high-level variable associate with this token or null otherwise
      Returns:
      HighVariable
    • getHighSymbol

      public HighSymbol getHighSymbol(HighFunction highFunction)
      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

      public Varnode getVarnode()
      Many tokens directly represent a variable in the data-flow
      Returns:
      the variable (Varnode) associated with this token or null
    • getPcodeOp

      public PcodeOp getPcodeOp()
      Many tokens directly represent a pcode operator in the data-flow
      Returns:
      the operation (PcodeOp) associated with this token or null
    • getScalar

      public Scalar 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

      public Iterator<ClangToken> iterator(boolean forward)
      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