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

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