github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/parm_var_decl.go (about) 1 package ast 2 3 import ( 4 "strings" 5 ) 6 7 // ParmVarDecl is node represents a parameter of variable declaration. 8 type ParmVarDecl struct { 9 Addr Address 10 Pos Position 11 Position2 string 12 Name string 13 Type string 14 Type2 string 15 IsUsed bool 16 IsReferenced bool 17 IsRegister bool 18 ChildNodes []Node 19 } 20 21 func parseParmVarDecl(line string) *ParmVarDecl { 22 groups := groupsFromRegex( 23 `<(?P<position>.*)> 24 (?P<position2> [^ ]+:[\d:]+)? 25 (?P<used> used)? 26 (?P<referenced> referenced)? 27 (?P<name> \w+)? 28 '(?P<type>.*?)' 29 (?P<type2>:'.*?')? 30 (?P<register> register)? 31 `, 32 line, 33 ) 34 35 type2 := groups["type2"] 36 if type2 != "" { 37 type2 = type2[2 : len(type2)-1] 38 } 39 40 if strings.Index(groups["position"], "<invalid sloc>") > -1 { 41 groups["position"] = "<invalid sloc>" 42 groups["position2"] = "<invalid sloc>" 43 } 44 45 return &ParmVarDecl{ 46 Addr: ParseAddress(groups["address"]), 47 Pos: NewPositionFromString(groups["position"]), 48 Position2: strings.TrimSpace(groups["position2"]), 49 Name: strings.TrimSpace(groups["name"]), 50 Type: groups["type"], 51 Type2: type2, 52 IsUsed: len(groups["used"]) > 0, 53 IsReferenced: len(groups["referenced"]) > 0, 54 IsRegister: len(groups["register"]) > 0, 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 *ParmVarDecl) 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 *ParmVarDecl) 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 *ParmVarDecl) Children() []Node { 74 return n.ChildNodes 75 } 76 77 // Position returns the position in the original source code. 78 func (n *ParmVarDecl) Position() Position { 79 return n.Pos 80 }