github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/indirect_field_decl.go (about)

     1  package ast
     2  
     3  import "strings"
     4  
     5  // IndirectFieldDecl is node represents a indirect field declaration.
     6  type IndirectFieldDecl struct {
     7  	Addr       Address
     8  	Pos        Position
     9  	Position2  string
    10  	IsImplicit bool
    11  	Name       string
    12  	Type       string
    13  	ChildNodes []Node
    14  }
    15  
    16  func parseIndirectFieldDecl(line string) *IndirectFieldDecl {
    17  	groups := groupsFromRegex(
    18  		`<(?P<position>.*)>
    19  		(?P<position2> [^ ]+:[\d:]+)?
    20  		(?P<implicit> implicit)?
    21  		 (?P<name>\w+)
    22  		 '(?P<type>.+?)'`,
    23  		line,
    24  	)
    25  
    26  	return &IndirectFieldDecl{
    27  		Addr:       ParseAddress(groups["address"]),
    28  		Pos:        NewPositionFromString(groups["position"]),
    29  		Position2:  strings.TrimSpace(groups["position2"]),
    30  		IsImplicit: len(groups["implicit"]) > 0,
    31  		Name:       groups["name"],
    32  		Type:       groups["type"],
    33  		ChildNodes: []Node{},
    34  	}
    35  }
    36  
    37  // AddChild adds a new child node. Child nodes can then be accessed with the
    38  // Children attribute.
    39  func (n *IndirectFieldDecl) AddChild(node Node) {
    40  	n.ChildNodes = append(n.ChildNodes, node)
    41  }
    42  
    43  // Address returns the numeric address of the node. See the documentation for
    44  // the Address type for more information.
    45  func (n *IndirectFieldDecl) Address() Address {
    46  	return n.Addr
    47  }
    48  
    49  // Children returns the child nodes. If this node does not have any children or
    50  // this node does not support children it will always return an empty slice.
    51  func (n *IndirectFieldDecl) Children() []Node {
    52  	return n.ChildNodes
    53  }
    54  
    55  // Position returns the position in the original source code.
    56  func (n *IndirectFieldDecl) Position() Position {
    57  	return n.Pos
    58  }