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

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