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

     1  package ast
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/Konstantin8105/c4go/util"
     7  )
     8  
     9  // AllocSizeAttr is a type of attribute that is optionally attached to a variable
    10  // or struct field definition.
    11  type AllocSizeAttr struct {
    12  	Addr        Address
    13  	Pos         Position
    14  	IsInherited bool
    15  	A           int
    16  	B           int
    17  	ChildNodes  []Node
    18  }
    19  
    20  func parseAllocSizeAttr(line string) *AllocSizeAttr {
    21  	groups := groupsFromRegex(
    22  		`<(?P<position>.*)>(?P<inherited> Inherited)?(?P<a> \d+)(?P<b> \d+)?`,
    23  		line,
    24  	)
    25  
    26  	var av, bv int
    27  	a := strings.TrimSpace(groups["a"])
    28  	if a != "" {
    29  		av = util.Atoi(a)
    30  	}
    31  	b := strings.TrimSpace(groups["b"])
    32  	if b != "" {
    33  		bv = util.Atoi(b)
    34  	}
    35  
    36  	return &AllocSizeAttr{
    37  		Addr:        ParseAddress(groups["address"]),
    38  		Pos:         NewPositionFromString(groups["position"]),
    39  		IsInherited: len(groups["inherited"]) > 0,
    40  		A:           av,
    41  		B:           bv,
    42  		ChildNodes:  []Node{},
    43  	}
    44  }
    45  
    46  // AddChild adds a new child node. Child nodes can then be accessed with the
    47  // Children attribute.
    48  func (n *AllocSizeAttr) AddChild(node Node) {
    49  	n.ChildNodes = append(n.ChildNodes, node)
    50  }
    51  
    52  // Address returns the numeric address of the node. See the documentation for
    53  // the Address type for more information.
    54  func (n *AllocSizeAttr) Address() Address {
    55  	return n.Addr
    56  }
    57  
    58  // Children returns the child nodes. If this node does not have any children or
    59  // this node does not support children it will always return an empty slice.
    60  func (n *AllocSizeAttr) Children() []Node {
    61  	return n.ChildNodes
    62  }
    63  
    64  // Position returns the position in the original source code.
    65  func (n *AllocSizeAttr) Position() Position {
    66  	return n.Pos
    67  }