github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/unary_operator.go (about) 1 package ast 2 3 // UnaryOperator is type of unary operator 4 type UnaryOperator struct { 5 Addr Address 6 Pos Position 7 Type string 8 Type2 string 9 IsLvalue bool 10 IsPrefix bool 11 IsCannotOverflow bool 12 Operator string 13 ChildNodes []Node 14 } 15 16 func parseUnaryOperator(line string) *UnaryOperator { 17 groups := groupsFromRegex( 18 `<(?P<position>.*)> 19 '(?P<type>.*?)'(:'(?P<type2>.*)')? 20 (?P<lvalue> lvalue)? 21 (?P<prefix> prefix)? 22 (?P<postfix> postfix)? 23 '(?P<operator>.*?)' 24 (?P<overflow> cannot overflow)?`, 25 line, 26 ) 27 28 return &UnaryOperator{ 29 Addr: ParseAddress(groups["address"]), 30 Pos: NewPositionFromString(groups["position"]), 31 Type: groups["type"], 32 Type2: groups["type2"], 33 IsLvalue: len(groups["lvalue"]) > 0, 34 IsPrefix: len(groups["prefix"]) > 0, 35 IsCannotOverflow: len(groups["overflow"]) > 0, 36 Operator: groups["operator"], 37 ChildNodes: []Node{}, 38 } 39 } 40 41 // AddChild adds a new child node. Child nodes can then be accessed with the 42 // Children attribute. 43 func (n *UnaryOperator) AddChild(node Node) { 44 n.ChildNodes = append(n.ChildNodes, node) 45 } 46 47 // Address returns the numeric address of the node. See the documentation for 48 // the Address type for more information. 49 func (n *UnaryOperator) Address() Address { 50 return n.Addr 51 } 52 53 // Children returns the child nodes. If this node does not have any children or 54 // this node does not support children it will always return an empty slice. 55 func (n *UnaryOperator) Children() []Node { 56 return n.ChildNodes 57 } 58 59 // Position returns the position in the original source code. 60 func (n *UnaryOperator) Position() Position { 61 return n.Pos 62 }