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