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

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