github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/malloc_attr.go (about)

     1  package ast
     2  
     3  // MallocAttr is a type of attribute that is optionally attached to a variable
     4  // or struct field definition.
     5  type MallocAttr struct {
     6  	Addr       Address
     7  	Pos        Position
     8  	ChildNodes []Node
     9  }
    10  
    11  func parseMallocAttr(line string) *MallocAttr {
    12  	groups := groupsFromRegex(
    13  		"<(?P<position>.*)>",
    14  		line,
    15  	)
    16  
    17  	return &MallocAttr{
    18  		Addr:       ParseAddress(groups["address"]),
    19  		Pos:        NewPositionFromString(groups["position"]),
    20  		ChildNodes: []Node{},
    21  	}
    22  }
    23  
    24  // AddChild adds a new child node. Child nodes can then be accessed with the
    25  // Children attribute.
    26  func (n *MallocAttr) AddChild(node Node) {
    27  	n.ChildNodes = append(n.ChildNodes, node)
    28  }
    29  
    30  // Address returns the numeric address of the node. See the documentation for
    31  // the Address type for more information.
    32  func (n *MallocAttr) Address() Address {
    33  	return n.Addr
    34  }
    35  
    36  // Children returns the child nodes. If this node does not have any children or
    37  // this node does not support children it will always return an empty slice.
    38  func (n *MallocAttr) Children() []Node {
    39  	return n.ChildNodes
    40  }
    41  
    42  // Position returns the position in the original source code.
    43  func (n *MallocAttr) Position() Position {
    44  	return n.Pos
    45  }