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