Repository: Konstantin8105/c4go
Pull request #437 (2019-05-06 14:16:40)

AST: AllocAlignAttr

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/437?src=pr&el=h1) Report
> Merging [#437](https://codecov.io/gh/Konstantin8105/c4go/pull/437?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/f0be0b60adf381dd98818c4b0330325377f0fa57?src=pr&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/437/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/437?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #437      +/-   ##
==========================================
+ Coverage   85.14%   85.17%   +0.02%     
==========================================
  Files         193      194       +1     
  Lines       11756    11778      +22     
==========================================
+ Hits        10010    10032      +22     
  Misses       1261     1261              
  Partials      485      485
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/437?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [ast/position.go](https://codecov.io/gh/Konstantin8105/c4go/pull/437/diff?src=pr&el=tree#diff-YXN0L3Bvc2l0aW9uLmdv) | `93.94% <100%> (+0.03%)` | :arrow_up: |
| [ast/ast.go](https://codecov.io/gh/Konstantin8105/c4go/pull/437/diff?src=pr&el=tree#diff-YXN0L2FzdC5nbw==) | `98.98% <100%> (ø)` | :arrow_up: |
| [ast/alloc\_align\_attr.go](https://codecov.io/gh/Konstantin8105/c4go/pull/437/diff?src=pr&el=tree#diff-YXN0L2FsbG9jX2FsaWduX2F0dHIuZ28=) | `100% <100%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/437?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/437?src=pr&el=footer). Last update [f0be0b6...e29afb4](https://codecov.io/gh/Konstantin8105/c4go/pull/437?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Konstantin8105: Closes #439

Patch:
diff --git a/.gitignore b/.gitignore
index c4ca1fc..7da4e9c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,4 @@ tests/debug*.h
 examples/*.go
 debug.txt
 tests/bind/debug.bind.h
+version/git_version.go
diff --git a/README.md b/README.md
index 410ea78..f0dc212 100644
--- a/README.md
+++ b/README.md
@@ -15,14 +15,30 @@ Notes:
 * Transpiler works on linux machines
 * Need to have installed `clang`. See [llvm download page](http://releases.llvm.org/download.html)
 
+
+
 # Installation
 
-`c4go` requires Go 1.10 or newer.
+Installation with version generation.
 
 ```bash
+# get code
 go get -u github.com/Konstantin8105/c4go
+
+# move to project source
+cd $GOPATH/src/github.com/Konstantin8105/c4go
+
+# generate version
+go generate ./...
+
+# install
+go install
+
+# testing
+c4go version
 ```
 
+
 # Usage example
 
 ```bash
@@ -550,18 +566,3 @@ go tool pprof ./testdata/cpu.out
 
 For more information, see [Profiling Go Programs](https://blog.golang.org/profiling-go-programs).
 
-## Installation
-
-```bash
-# move to project source
-cd $GOPATH/src/github.com/Konstantin8105/c4go
-
-# generate version
-go generate ./...
-
-# install
-go install
-
-# testing
-c4go version
-```
diff --git a/ast/alloc_align_attr.go b/ast/alloc_align_attr.go
new file mode 100644
index 0000000..e51403e
--- /dev/null
+++ b/ast/alloc_align_attr.go
@@ -0,0 +1,47 @@
+package ast
+
+// AllocAlignAttr is a type of attribute that is optionally attached to a variable
+// or struct field definition.
+type AllocAlignAttr struct {
+	Addr       Address
+	Pos        Position
+	Tags       string
+	ChildNodes []Node
+}
+
+func parseAllocAlignAttr(line string) *AllocAlignAttr {
+	groups := groupsFromRegex(
+		"<(?P<position>.*)>(?P<tags>.*)",
+		line,
+	)
+
+	return &AllocAlignAttr{
+		Addr:       ParseAddress(groups["address"]),
+		Pos:        NewPositionFromString(groups["position"]),
+		Tags:       groups["tags"],
+		ChildNodes: []Node{},
+	}
+}
+
+// AddChild adds a new child node. Child nodes can then be accessed with the
+// Children attribute.
+func (n *AllocAlignAttr) 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 *AllocAlignAttr) 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 *AllocAlignAttr) Children() []Node {
+	return n.ChildNodes
+}
+
+// Position returns the position in the original source code.
+func (n *AllocAlignAttr) Position() Position {
+	return n.Pos
+}
diff --git a/ast/ast.go b/ast/ast.go
index 0500795..44c6c4b 100644
--- a/ast/ast.go
+++ b/ast/ast.go
@@ -204,6 +204,8 @@ func Parse(fullline string) (returnNode Node, err error) {
 		return parseLabelStmt(line), nil
 	case "LinkageSpecDecl":
 		return parseLinkageSpecDecl(line), nil
+	case "AllocAlignAttr":
+		return parseAllocAlignAttr(line), nil
 	case "MallocAttr":
 		return parseMallocAttr(line), nil
 	case "MaxFieldAlignmentAttr":
diff --git a/ast/position.go b/ast/position.go
index d9e623d..b429f79 100644
--- a/ast/position.go
+++ b/ast/position.go
@@ -352,6 +352,8 @@ func setPosition(node Node, position Position) {
 		n.Pos = position
 	case *LinkageSpecDecl:
 		n.Pos = position
+	case *AllocAlignAttr:
+		n.Pos = position
 	case *MallocAttr:
 		n.Pos = position
 	case *MaxFieldAlignmentAttr:
diff --git a/main.go b/main.go
index 92accd4..4e5e091 100644
--- a/main.go
+++ b/main.go
@@ -201,6 +201,7 @@ func buildTree(nodes []treeNode, depth int) []ast.Node {
 		// ignore all comments in ast tree
 		case *ast.FullComment, *ast.BlockCommandComment,
 			*ast.HTMLStartTagComment, *ast.HTMLEndTagComment,
+			*ast.AllocAlignAttr,
 			*ast.InlineCommandComment, *ast.ParagraphComment,
 			*ast.ParamCommandComment, *ast.TextComment,
 			*ast.VerbatimLineComment, *ast.VerbatimBlockComment,
diff --git a/transpiler/declarations.go b/transpiler/declarations.go
index 888069e..b08a39d 100644
--- a/transpiler/declarations.go
+++ b/transpiler/declarations.go
@@ -391,6 +391,9 @@ func transpileCXXRecordDecl(p *program.Program, n *ast.RecordDecl) (
 		case *ast.CXXRecordDecl:
 			// ignore
 
+		case *ast.AccessSpecDecl:
+			// ignore
+
 		case *ast.FieldDecl:
 			var f *goast.Field
 			f, err = transpileFieldDecl(p, v)
@@ -401,7 +404,7 @@ func transpileCXXRecordDecl(p *program.Program, n *ast.RecordDecl) (
 
 		default:
 			p.AddMessage(p.GenerateWarningMessage(
-				fmt.Errorf("Cannot transpilation field in CXXRecordDecl : %T", v), n))
+				fmt.Errorf("Cannot transpilation field: %T", v), n))
 		}
 	}
 


Test patch:
diff --git a/ast/alloc_align_attr_test.go b/ast/alloc_align_attr_test.go
new file mode 100644
index 0000000..566d679
--- /dev/null
+++ b/ast/alloc_align_attr_test.go
@@ -0,0 +1,18 @@
+package ast
+
+import (
+	"testing"
+)
+
+func TestAllocAlignAttr(t *testing.T) {
+	nodes := map[string]Node{
+		`0x7fc0a69091d1 <line:11:7, line:18:7> 1`: &AllocAlignAttr{
+			Addr:       0x7fc0a69091d1,
+			Pos:        NewPositionFromString("line:11:7, line:18:7"),
+			Tags:       " 1",
+			ChildNodes: []Node{},
+		},
+	}
+
+	runNodeTests(t, nodes)
+}