Konstantin8105 / c4go

Transpiling C code to Go code
MIT License
363 stars 37 forks source link

CPP: experimantal #123

Closed Konstantin8105 closed 6 years ago

Konstantin8105 commented 6 years ago

Create ast for cpp code:

clang++ -E -C cpp2.cpp  > y.cpp
clang++ -Xclang -ast-dump -fsyntax-only y.cpp
Konstantin8105 commented 6 years ago

C++:

class person {
public:
    float name;
    int number;
};

GO code:

type person struct{
    name   float32
    number int
}

AST:

|-CXXRecordDecl 0x1d3f1b8 </home/konstantin/go/src/github.com/Konstantin8105/c4go/tests/class.cpp:3:1, line:7:1> line:3:7 referenced class person definition
| |-CXXRecordDecl 0x1d3f2d0 <col:1, col:7> col:7 implicit class person
| |-AccessSpecDecl 0x1d3f360 <line:4:1, col:7> col:1 public
| |-FieldDecl 0x1d3f398 <line:5:5, col:11> col:11 referenced name 'float'
| |-FieldDecl 0x1d3f3f0 <line:6:5, col:9> col:9 referenced number 'int'
| |-CXXConstructorDecl 0x1d3f910 <line:3:7> col:7 implicit used person 'void (void) throw()' inline
| | `-CompoundStmt 0x1d3fc50 <col:7>
| `-CXXConstructorDecl 0x1d3fa68 <col:7> col:7 implicit person 'void (const class person &)' inline noexcept-unevaluated 0x1d3fa68
|   `-ParmVarDecl 0x1d3fbb0 <col:7> col:7 'const class person &'
Konstantin8105 commented 6 years ago
    |-DeclStmt 0x305ac98 <line:46:2, col:12>
    | `-VarDecl 0x305a890 <col:2, col:9> col:9 used obj 'class person' callinit
    |   `-CXXConstructExpr 0x305ac68 <col:9> 'class person' 'void (void) throw()'
    |-BinaryOperator 0x305ad48 <line:47:2, col:13> 'float' lvalue '='
    | |-MemberExpr 0x305acd8 <col:2, col:6> 'float' lvalue .name 0x305a398
    | | `-DeclRefExpr 0x305acb0 <col:2> 'class person' lvalue Var 0x305a890 'obj' 'class person'
    | `-ImplicitCastExpr 0x305ad30 <col:13> 'float' <FloatingCast>
    |   `-FloatingLiteral 0x305ad10 <col:13> 'double' 2.300000e+00
    |-BinaryOperator 0x305aea0 <line:48:2, col:15> 'int' lvalue '='
    | |-MemberExpr 0x305ae48 <col:2, col:6> 'int' lvalue .number 0x305a3f0
    | | `-DeclRefExpr 0x305ae20 <col:2> 'class person' lvalue Var 0x305a890 'obj' 'class person'
    | `-IntegerLiteral 0x305ae80 <col:15> 'int' 4