Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ast: add FunctionNoProtoType #832

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ func Parse(fullline string) Node {
return parseFunctionDecl(line)
case "FullComment":
return parseFullComment(line)
case "FunctionNoProtoType":
return parseFunctionNoProtoType(line)
case "FunctionProtoType":
return parseFunctionProtoType(line)
case "ForStmt":
Expand Down
49 changes: 49 additions & 0 deletions ast/function_no_proto_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ast

// FunctionNoProtoType is a function type without parameters.
//
// Example:
// int (*)()
type FunctionNoProtoType struct {
Addr Address
Type string
CallingConv string
ChildNodes []Node
}

func parseFunctionNoProtoType(line string) *FunctionNoProtoType {
groups := groupsFromRegex(
"'(?P<type>.*?)' (?P<calling_conv>.*)",
line,
)

return &FunctionNoProtoType{
Addr: ParseAddress(groups["address"]),
Type: groups["type"],
CallingConv: groups["calling_conv"],
ChildNodes: []Node{},
}
}

// AddChild adds a new child node. Child nodes can then be accessed with the
// Children attribute.
func (n *FunctionNoProtoType) 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 *FunctionNoProtoType) 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 *FunctionNoProtoType) Children() []Node {
return n.ChildNodes
}

// Position returns the position in the original source code.
func (n *FunctionNoProtoType) Position() Position {
return Position{}
}
18 changes: 18 additions & 0 deletions ast/function_no_proto_type_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ast

import (
"testing"
)

func TestFunctionNoProtoType(t *testing.T) {
nodes := map[string]Node{
`0x556e32bfde50 'int ()' cdecl`: &FunctionNoProtoType{
Addr: 0x556e32bfde50,
Type: "int ()",
CallingConv: "cdecl",
ChildNodes: []Node{},
},
}

runNodeTests(t, nodes)
}
7 changes: 4 additions & 3 deletions ast/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,10 @@ func setPosition(node Node, position Position) {
n.Pos = position
case *TypedefType, *Typedef, *TranslationUnitDecl, *RecordType, *Record,
*QualType, *PointerType, *DecayedType, *ParenType,
*IncompleteArrayType, *FunctionProtoType, *EnumType, *Enum,
*ElaboratedType, *ConstantArrayType, *BuiltinType, *ArrayFiller,
*Field, *AttributedType:
*IncompleteArrayType, *FunctionNoProtoType, *FunctionProtoType,
*EnumType, *Enum, *ElaboratedType, *ConstantArrayType, *BuiltinType,
*ArrayFiller, *Field, *AttributedType:

// These do not have positions so they can be ignored.
default:
panic(fmt.Sprintf("unknown node type: %+#v", node))
Expand Down