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

     1  package ast
     2  
     3  // AsmLabelAttr is a type of attribute for assembler label
     4  type AsmLabelAttr struct {
     5  	Addr           Address
     6  	Pos            Position
     7  	IsInherited    bool
     8  	IsLiteralLabel bool
     9  	FunctionName   string
    10  	ChildNodes     []Node
    11  }
    12  
    13  func parseAsmLabelAttr(line string) *AsmLabelAttr {
    14  	groups := groupsFromRegex(
    15  		`<(?P<position>.*)>
    16  		(?P<inherited> Inherited)?
    17  		 "(?P<function>.+)"
    18  		(?P<isliterallabel> IsLiteralLabel)?`,
    19  		line,
    20  	)
    21  
    22  	return &AsmLabelAttr{
    23  		Addr:           ParseAddress(groups["address"]),
    24  		Pos:            NewPositionFromString(groups["position"]),
    25  		IsInherited:    len(groups["inherited"]) > 0,
    26  		FunctionName:   groups["function"],
    27  		IsLiteralLabel: len(groups["isliterallabel"]) > 0,
    28  		ChildNodes:     []Node{},
    29  	}
    30  }
    31  
    32  // AddChild adds a new child node. Child nodes can then be accessed with the
    33  // Children attribute.
    34  func (n *AsmLabelAttr) AddChild(node Node) {
    35  	n.ChildNodes = append(n.ChildNodes, node)
    36  }
    37  
    38  // Address returns the numeric address of the node. See the documentation for
    39  // the Address type for more information.
    40  func (n *AsmLabelAttr) Address() Address {
    41  	return n.Addr
    42  }
    43  
    44  // Children returns the child nodes. If this node does not have any children or
    45  // this node does not support children it will always return an empty slice.
    46  func (n *AsmLabelAttr) Children() []Node {
    47  	return n.ChildNodes
    48  }
    49  
    50  // Position returns the position in the original source code.
    51  func (n *AsmLabelAttr) Position() Position {
    52  	return n.Pos
    53  }