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

     1  package ast
     2  
     3  // DeclRefExpr is expression.
     4  type DeclRefExpr struct {
     5  	Addr       Address
     6  	Pos        Position
     7  	Type       string
     8  	Type1      string
     9  	IsLvalue   bool
    10  	For        string
    11  	Address2   string
    12  	Name       string
    13  	Type2      string
    14  	Type3      string
    15  	Other      string
    16  	ChildNodes []Node
    17  }
    18  
    19  func parseDeclRefExpr(line string) *DeclRefExpr {
    20  	groups := groupsFromRegex(
    21  		`<(?P<position>.*)>
    22  		 '(?P<type>.*?)'(:'(?P<type1>.*?)')?
    23  		.*?
    24  		(?P<lvalue> lvalue)?
    25  		 (?P<for>\w+)
    26  		 (?P<address2>[0-9a-fx]+)
    27  		 '(?P<name>.*?)'
    28  		 '(?P<type2>.*?)'(:'(?P<type3>.*?)')?
    29  		(?P<other> .*?)?
    30  		`,
    31  		line,
    32  	)
    33  
    34  	return &DeclRefExpr{
    35  		Addr:       ParseAddress(groups["address"]),
    36  		Pos:        NewPositionFromString(groups["position"]),
    37  		Type:       groups["type"],
    38  		Type1:      groups["type1"],
    39  		IsLvalue:   len(groups["lvalue"]) > 0,
    40  		For:        groups["for"],
    41  		Address2:   groups["address2"],
    42  		Name:       groups["name"],
    43  		Type2:      groups["type2"],
    44  		Type3:      groups["type3"],
    45  		Other:      groups["other"],
    46  		ChildNodes: []Node{},
    47  	}
    48  }
    49  
    50  // FunctionDeclRefExpr - value of DeclRefExpr.For for function
    51  var FunctionDeclRefExpr = "Function"
    52  
    53  // AddChild adds a new child node. Child nodes can then be accessed with the
    54  // Children attribute.
    55  func (n *DeclRefExpr) AddChild(node Node) {
    56  	n.ChildNodes = append(n.ChildNodes, node)
    57  }
    58  
    59  // Address returns the numeric address of the node. See the documentation for
    60  // the Address type for more information.
    61  func (n *DeclRefExpr) Address() Address {
    62  	return n.Addr
    63  }
    64  
    65  // Children returns the child nodes. If this node does not have any children or
    66  // this node does not support children it will always return an empty slice.
    67  func (n *DeclRefExpr) Children() []Node {
    68  	return n.ChildNodes
    69  }
    70  
    71  // Position returns the position in the original source code.
    72  func (n *DeclRefExpr) Position() Position {
    73  	return n.Pos
    74  }