github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/format_attr.go (about) 1 package ast 2 3 import ( 4 "github.com/Konstantin8105/c4go/util" 5 ) 6 7 // FormatAttr is a type of attribute that is optionally attached to a variable 8 // or struct field definition. 9 type FormatAttr struct { 10 Addr Address 11 Pos Position 12 IsImplicit bool 13 IsInherited bool 14 FunctionName string 15 Unknown1 int 16 Unknown2 int 17 ChildNodes []Node 18 } 19 20 func parseFormatAttr(line string) *FormatAttr { 21 groups := groupsFromRegex( 22 `<(?P<position>.*)> 23 (?P<implicit> Implicit)? 24 (?P<inherited> Inherited)? 25 (?P<function>\w+) 26 (?P<unknown1>\d+) 27 (?P<unknown2>\d+)`, 28 line, 29 ) 30 31 return &FormatAttr{ 32 Addr: ParseAddress(groups["address"]), 33 Pos: NewPositionFromString(groups["position"]), 34 IsImplicit: len(groups["implicit"]) > 0, 35 IsInherited: len(groups["inherited"]) > 0, 36 FunctionName: groups["function"], 37 Unknown1: util.Atoi(groups["unknown1"]), 38 Unknown2: util.Atoi(groups["unknown2"]), 39 ChildNodes: []Node{}, 40 } 41 } 42 43 // AddChild adds a new child node. Child nodes can then be accessed with the 44 // Children attribute. 45 func (n *FormatAttr) AddChild(node Node) { 46 n.ChildNodes = append(n.ChildNodes, node) 47 } 48 49 // Address returns the numeric address of the node. See the documentation for 50 // the Address type for more information. 51 func (n *FormatAttr) Address() Address { 52 return n.Addr 53 } 54 55 // Children returns the child nodes. If this node does not have any children or 56 // this node does not support children it will always return an empty slice. 57 func (n *FormatAttr) Children() []Node { 58 return n.ChildNodes 59 } 60 61 // Position returns the position in the original source code. 62 func (n *FormatAttr) Position() Position { 63 return n.Pos 64 }