diff --git a/ast/ast.go b/ast/ast.go index d28ea7e2c..bb44d1bf5 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -62,6 +62,8 @@ func Parse(fullline string) Node { return parseArraySubscriptExpr(line) case "AsmLabelAttr": return parseAsmLabelAttr(line) + case "AttributedType": + return parseAttributedType(line) case "AvailabilityAttr": return parseAvailabilityAttr(line) case "BinaryOperator": diff --git a/ast/attributed_type.go b/ast/attributed_type.go new file mode 100644 index 000000000..6fd068203 --- /dev/null +++ b/ast/attributed_type.go @@ -0,0 +1,43 @@ +package ast + +// AttributedType is an attribute type +type AttributedType struct { + Addr Address + Type string + Sugar bool + ChildNodes []Node +} + +func parseAttributedType(line string) *AttributedType { + groups := groupsFromRegex(`'(?P.*?)' sugar`, line) + + return &AttributedType{ + Addr: ParseAddress(groups["address"]), + Type: groups["type"], + Sugar: true, + ChildNodes: []Node{}, + } +} + +// AddChild adds a new child node. Child nodes can then be accessed with the +// Children attribute. +func (n *AttributedType) AddChild(node Node) { + n.ChildNodes = append(n.ChildNodes, node) +} + +// Address returns the numeric address of the node. See the documentation for +// the Address type for more information. +func (n *AttributedType) Address() Address { + return n.Addr +} + +// Children returns the child nodes. If this node does not have any children or +// this node does not support children it will always return an empty slice. +func (n *AttributedType) Children() []Node { + return n.ChildNodes +} + +// Position returns the position in the original source code. +func (n *AttributedType) Position() Position { + return Position{} +} diff --git a/ast/attributed_type_test.go b/ast/attributed_type_test.go new file mode 100644 index 000000000..e7fceae83 --- /dev/null +++ b/ast/attributed_type_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestAttributedType(t *testing.T) { + nodes := map[string]Node{ + `0x2b6c359e30 'int (void) __attribute__((cdecl))' sugar`: &AttributedType{ + Addr: 0x2b6c359e30, + Type: "int (void) __attribute__((cdecl))", + Sugar: true, + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/position.go b/ast/position.go index 931f58bc2..aa39c39b1 100644 --- a/ast/position.go +++ b/ast/position.go @@ -411,7 +411,7 @@ func setPosition(node Node, position Position) { *QualType, *PointerType, *DecayedType, *ParenType, *IncompleteArrayType, *FunctionProtoType, *EnumType, *Enum, *ElaboratedType, *ConstantArrayType, *BuiltinType, *ArrayFiller, - *Field: + *Field, *AttributedType: // These do not have positions so they can be ignored. default: panic(fmt.Sprintf("unknown node type: %+#v", node))