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