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