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

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