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