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

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