Repository: Konstantin8105/c4go (c)

Issue:
Ast
/* AST Error :
Cannot parse line: `AllocSizeAttr 0xb8abfd90 <col:100, col:116> 2`. bad integer: strconv.Atoi: parsing "": invalid syntax
*/
/* AST Error :
unknown node type: `EnableIfAttr 0xb8add300 <col:91, col:106> "<no message provided>"`
*/
/* AST Error :                                                      unknown node type: `OverloadableAttr 0xb8add330 <col:61>`           */

Pull request:
ast: add node for termux clang
Close #359

Patch:
diff --git a/ast/alloc_size_attr.go b/ast/alloc_size_attr.go
index cd885bd..e98bbaf 100644
--- a/ast/alloc_size_attr.go
+++ b/ast/alloc_size_attr.go
@@ -23,12 +23,22 @@ func parseAllocSizeAttr(line string) *AllocSizeAttr {
 		line,
 	)
 
+	var av, bv int
+	a := strings.TrimSpace(groups["a"])
+	if a != "" {
+		av = util.Atoi(a)
+	}
+	b := strings.TrimSpace(groups["b"])
+	if b != "" {
+		bv = util.Atoi(b)
+	}
+
 	return &AllocSizeAttr{
 		Addr:        ParseAddress(groups["address"]),
 		Pos:         NewPositionFromString(groups["position"]),
 		IsInherited: len(groups["inherited"]) > 0,
-		A:           util.Atoi(strings.TrimSpace(groups["a"])),
-		B:           util.Atoi(strings.TrimSpace(groups["b"])),
+		A:           av,
+		B:           bv,
 		ChildNodes:  []Node{},
 	}
 }
diff --git a/ast/ast.go b/ast/ast.go
index 36fc50d..a8a6588 100644
--- a/ast/ast.go
+++ b/ast/ast.go
@@ -142,6 +142,8 @@ func Parse(fullline string) (returnNode Node, err error) {
 		return parseElaboratedType(line), nil
 	case "EmptyDecl":
 		return parseEmptyDecl(line), nil
+	case "EnableIfAttr":
+		return parseEnableIfAttr(line), nil
 	case "Enum":
 		return parseEnum(line), nil
 	case "EnumConstantDecl":
@@ -216,6 +218,8 @@ func Parse(fullline string) (returnNode Node, err error) {
 		return parseNotTailCalledAttr(line), nil
 	case "OffsetOfExpr":
 		return parseOffsetOfExpr(line), nil
+	case "OverloadableAttr":
+		return parseOverloadableAttr(line), nil
 	case "PackedAttr":
 		return parsePackedAttr(line), nil
 	case "ParagraphComment":
diff --git a/ast/enable_if_attr.go b/ast/enable_if_attr.go
new file mode 100644
index 0000000..8761ba0
--- /dev/null
+++ b/ast/enable_if_attr.go
@@ -0,0 +1,49 @@
+package ast
+
+// EnableIfAttr is a type of attribute that is optionally attached to a variable
+// or struct field definition.
+type EnableIfAttr struct {
+	Addr        Address
+	Pos         Position
+	Message1    string
+	IsInherited bool
+	ChildNodes  []Node
+}
+
+func parseEnableIfAttr(line string) *EnableIfAttr {
+	groups := groupsFromRegex(
+		`<(?P<position>.*)>(?P<inherited> Inherited)? "(?P<message1>.*?)"`,
+		line,
+	)
+
+	return &EnableIfAttr{
+		Addr:        ParseAddress(groups["address"]),
+		Pos:         NewPositionFromString(groups["position"]),
+		Message1:    removeQuotes(groups["message1"]),
+		IsInherited: len(groups["inherited"]) > 0,
+		ChildNodes:  []Node{},
+	}
+}
+
+// AddChild adds a new child node. Child nodes can then be accessed with the
+// Children attribute.
+func (n *EnableIfAttr) 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 *EnableIfAttr) 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 *EnableIfAttr) Children() []Node {
+	return n.ChildNodes
+}
+
+// Position returns the position in the original source code.
+func (n *EnableIfAttr) Position() Position {
+	return n.Pos
+}
diff --git a/ast/overloadable_attr.go b/ast/overloadable_attr.go
new file mode 100644
index 0000000..6f0e5e6
--- /dev/null
+++ b/ast/overloadable_attr.go
@@ -0,0 +1,45 @@
+package ast
+
+// OverloadableAttr is a type of attribute that is optionally attached to a variable
+// or struct field definition.
+type OverloadableAttr struct {
+	Addr       Address
+	Pos        Position
+	ChildNodes []Node
+}
+
+func parseOverloadableAttr(line string) *OverloadableAttr {
+	groups := groupsFromRegex(
+		"<(?P<position>.*)>",
+		line,
+	)
+
+	return &OverloadableAttr{
+		Addr:       ParseAddress(groups["address"]),
+		Pos:        NewPositionFromString(groups["position"]),
+		ChildNodes: []Node{},
+	}
+}
+
+// AddChild adds a new child node. Child nodes can then be accessed with the
+// Children attribute.
+func (n *OverloadableAttr) 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 *OverloadableAttr) 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 *OverloadableAttr) Children() []Node {
+	return n.ChildNodes
+}
+
+// Position returns the position in the original source code.
+func (n *OverloadableAttr) Position() Position {
+	return n.Pos
+}
diff --git a/ast/position.go b/ast/position.go
index 8027fa6..8f49e19 100644
--- a/ast/position.go
+++ b/ast/position.go
@@ -302,6 +302,8 @@ func setPosition(node Node, position Position) {
 		n.Pos = position
 	case *EmptyDecl:
 		n.Pos = position
+	case *EnableIfAttr:
+		n.Pos = position
 	case *EnumConstantDecl:
 		n.Pos = position
 	case *EnumDecl:
@@ -366,6 +368,8 @@ func setPosition(node Node, position Position) {
 		n.Pos = position
 	case *OffsetOfExpr:
 		n.Pos = position
+	case *OverloadableAttr:
+		n.Pos = position
 	case *PackedAttr:
 		n.Pos = position
 	case *ParagraphComment:


Test patch:
diff --git a/ast/alloc_size_attr_test.go b/ast/alloc_size_attr_test.go
index 291aa88..89e2769 100644
--- a/ast/alloc_size_attr_test.go
+++ b/ast/alloc_size_attr_test.go
@@ -21,6 +21,14 @@ func TestAllocSizeAttr(t *testing.T) {
 			B:           0,
 			ChildNodes:  []Node{},
 		},
+		`0xb8abfd90 <col:100, col:116> 2`: &AllocSizeAttr{
+			Addr:        0xb8abfd90,
+			Pos:         NewPositionFromString("col:100, col:116"),
+			IsInherited: false,
+			A:           2,
+			B:           0,
+			ChildNodes:  []Node{},
+		},
 	}
 
 	runNodeTests(t, nodes)
diff --git a/ast/enable_if_attr_test.go b/ast/enable_if_attr_test.go
new file mode 100644
index 0000000..0a9aad8
--- /dev/null
+++ b/ast/enable_if_attr_test.go
@@ -0,0 +1,19 @@
+package ast
+
+import (
+	"testing"
+)
+
+func TestEnableIfAttr(t *testing.T) {
+	nodes := map[string]Node{
+		`0xb8add300 <col:91, col:106> "<no message provided>"`: &EnableIfAttr{
+			Addr:        0xb8add300,
+			Pos:         NewPositionFromString("col:91, col:106"),
+			Message1:    "<no message provided>",
+			IsInherited: false,
+			ChildNodes:  []Node{},
+		},
+	}
+
+	runNodeTests(t, nodes)
+}
diff --git a/ast/overloadable_attr_test.go b/ast/overloadable_attr_test.go
new file mode 100644
index 0000000..90d6fcd
--- /dev/null
+++ b/ast/overloadable_attr_test.go
@@ -0,0 +1,17 @@
+package ast
+
+import (
+	"testing"
+)
+
+func TestOverloadableAttr(t *testing.T) {
+	nodes := map[string]Node{
+		`0x7fa3b88bbb38 <line:4:1, line:13:1>`: &OverloadableAttr{
+			Addr:       0x7fa3b88bbb38,
+			Pos:        NewPositionFromString("line:4:1, line:13:1"),
+			ChildNodes: []Node{},
+		},
+	}
+
+	runNodeTests(t, nodes)
+}