Class AsnNode

java.lang.Object
net.aifusion.asn.AsnNode
Direct Known Subclasses:
AsnModule

public class AsnNode extends Object
AST Node for ASN.1 parsing. Contains a name and/or a value
Author:
Sharad Singhal
  • Constructor Details

    • AsnNode

      public AsnNode(AsnProduction production)
      Create a node for a production
      Parameters:
      production - production associated with this node
    • AsnNode

      public AsnNode(AsnProduction production, Token token)
      Create a new parser node with a given token (name)
      Parameters:
      production - production associated with this node
      token - - Token at this node
    • AsnNode

      public AsnNode(AsnProduction production, Token token, boolean isClassField)
      Create a parser node with a given name
      Parameters:
      production - - production at this node
      token - - name token at this node
      isClassField - - true if this node is an ObjectClass field, false otherwise
    • AsnNode

      public AsnNode(AsnProduction production, Token nameToken, Token valueToken)
      Create a new parser node with a given token pair
      Parameters:
      production - - AstProduction
      nameToken - - name token
      valueToken - - value token
    • AsnNode

      public AsnNode(AsnProduction production, List<Token> tokens)
      Create a parser node with a list of tokens
      Parameters:
      production - - production
      tokens - - associated tokens
  • Method Details

    • addChild

      public AsnNode addChild(AsnNode child)
      Add a child node to this node
      Parameters:
      child - - child node
      Returns:
      the child node
    • getChildren

      public List<AsnNode> getChildren()
      Get the children of this node
      Returns:
      - children for this node
    • getChild

      public AsnNode getChild(int index)
      Get a given child
      Parameters:
      index - - index of the child
      Returns:
      - child at given index
    • hasChildren

      public boolean hasChildren()
      Check if this node has any children
      Returns:
      - true if this node has children, false otherwise
    • getProduction

      public AsnProduction getProduction()
      Get the production at this node
      Returns:
      - production at this node
    • getName

      public String getName()
      Get the name (value of token[0]) at this node
      Returns:
      name of the node
    • getNameToken

      public Token getNameToken()
      Get the name token from this node
      Returns:
      - token at element 0, if any. Null if none present
    • getValue

      public String getValue()
      Get the value (value of token[1]) at this node
      Returns:
      value of the node
    • getAsnValue

      public AsnValue getAsnValue()
      Get the ASN.1 value, if any
      Returns:
      asn value, if the node reduces to a constant value. Null otherwise
    • getValueToken

      public Token getValueToken()
      Get the value token from this node.
      Returns:
      - token at element 1, if any. Null if none present
    • getFullName

      public String getFullName()
      Get the full name of the node
      Returns:
      full name of the node
    • locateType

      public AsnNode locateType(String name)
      Locate the node corresponding to the type for a given name
      Parameters:
      name - - string containing the name of the node
      Returns:
      - node defining the corresponding type, null if none found
    • isBuiltInType

      public boolean isBuiltInType()
      Check if this node represents a built-in type
      Returns:
      - true if the name of the node is a built-in type, false otherwise
    • locate

      public AsnNode locate(AsnProduction production, String name)
      Locate a node corresponding to a given name and production starting at this node
      Parameters:
      production - - production to match
      name - - name to match
      Returns:
      - Corresponding node. Null if none found
    • toString

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

      public String toString(String indent)
      Return a string value for this node. Subclasses should override this rather than toString()
      Parameters:
      indent - - indent used before the value of this node
      Returns:
      - string containing the ASN.1 definition at this node
    • search

      public AsnNode search(String name)
    • reduce

      public void reduce(AsnNode searchRoot, PrintStream f)
      Add values to this subtree for defined constants
      Parameters:
      searchRoot - - root of the tree (for locating referenced constants)
      f - - print stream to dump the tree