github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/compound_stmt.go (about) 1 package ast 2 3 // CompoundStmt is node represents a compound of nodes 4 type CompoundStmt struct { 5 Addr Address 6 Pos Position 7 ChildNodes []Node 8 9 // TODO: remove this 10 BelongsToSwitch bool 11 } 12 13 func parseCompoundStmt(line string) *CompoundStmt { 14 groups := groupsFromRegex( 15 "<(?P<position>.*)>", 16 line, 17 ) 18 19 return &CompoundStmt{ 20 Addr: ParseAddress(groups["address"]), 21 Pos: NewPositionFromString(groups["position"]), 22 ChildNodes: []Node{}, 23 BelongsToSwitch: false, 24 } 25 } 26 27 // AddChild adds a new child node. Child nodes can then be accessed with the 28 // Children attribute. 29 func (n *CompoundStmt) AddChild(node Node) { 30 n.ChildNodes = append(n.ChildNodes, node) 31 } 32 33 // Address returns the numeric address of the node. See the documentation for 34 // the Address type for more information. 35 func (n *CompoundStmt) Address() Address { 36 return n.Addr 37 } 38 39 // Children returns the child nodes. If this node does not have any children or 40 // this node does not support children it will always return an empty slice. 41 func (n *CompoundStmt) Children() []Node { 42 return n.ChildNodes 43 } 44 45 // Position returns the position in the original source code. 46 func (n *CompoundStmt) Position() Position { 47 return n.Pos 48 }