github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/cxx_method_decl.go (about) 1 package ast 2 3 import ( 4 "strings" 5 ) 6 7 // CXXMethodDecl method of class 8 type CXXMethodDecl struct { 9 Addr Address 10 Parent string 11 Prev string 12 Pos Position 13 Position2 string 14 IsImplicit bool 15 IsUsed bool 16 MethodName string 17 Type string 18 IsInline bool 19 Other string 20 ChildNodes []Node 21 } 22 23 func parseCXXMethodDecl(line string) *CXXMethodDecl { 24 groups := groupsFromRegex( 25 `(?:parent (?P<parent>0x[0-9a-f]+) )? 26 (?:prev (?P<prev>0x[0-9a-f]+) )? 27 <(?P<position>.*)> 28 (?P<position2> col:\d+| line:\d+:\d+)? 29 (?P<implicit> implicit)? 30 (?P<used> used)? 31 ( (?P<name>\w+)?)? 32 ( '(?P<type>.*?)')? 33 (?P<inline> inline)? 34 (?P<other>.*)`, 35 line, 36 ) 37 38 return &CXXMethodDecl{ 39 Addr: ParseAddress(groups["address"]), 40 Prev: groups["prev"], 41 Parent: groups["parent"], 42 Pos: NewPositionFromString(groups["position"]), 43 Position2: strings.TrimSpace(groups["position2"]), 44 IsImplicit: len(groups["implicit"]) > 0, 45 IsUsed: len(groups["used"]) > 0, 46 Type: groups["type"], 47 MethodName: groups["name"], 48 IsInline: len(groups["inline"]) > 0, 49 Other: groups["other"], 50 ChildNodes: []Node{}, 51 } 52 } 53 54 // AddChild adds a new child node. Child nodes can then be accessed with the 55 // Children attribute. 56 func (n *CXXMethodDecl) AddChild(node Node) { 57 n.ChildNodes = append(n.ChildNodes, node) 58 } 59 60 // Address returns the numeric address of the node. See the documentation for 61 // the Address type for more information. 62 func (n *CXXMethodDecl) Address() Address { 63 return n.Addr 64 } 65 66 // Children returns the child nodes. If this node does not have any children or 67 // this node does not support children it will always return an empty slice. 68 func (n *CXXMethodDecl) Children() []Node { 69 return n.ChildNodes 70 } 71 72 // Position returns the position in the original source code. 73 func (n *CXXMethodDecl) Position() Position { 74 return n.Pos 75 }