Skip to content

Commit 1410b98

Browse files
committed
Merge branch 'master' of github.com:mrRosset/scalaBindgen
2 parents e8b25d3 + a436cc7 commit 1410b98

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Building this tool require building LLVM and Clang. This can take hours. Please
1818

1919
* Follow the [building instructions](http://clang.llvm.org/docs/LibASTMatchersTutorial.html#step-0-obtaining-clang) for Clang (Only step 0)
2020
* Go to `llvm/tools/clang/tools/extra`
21-
* Clone this repository `git clone https://github.com/mrRosset/scalaBindgen.git`
21+
* Clone this repository `git clone https://github.com/mrRosset/scala-native-bindgen scala-bindgen`
2222
* Add `add_subdirectory(scala-bindgen)` to the CMakeLists.txt in the extra folder
2323
* Re-run the llvm/clang compilation
2424

SimpleTypeTests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ TEST_CASE("struct pointer", "[Type]"){
6666
REQUIRE(answ == Translate(code));
6767
}
6868

69+
TEST_CASE("struct helper methods") {
70+
std::string code = "struct listing { int a; int b; };";
71+
Translate(code);
72+
std::string answ = "\timplicit class struct_listing_ops(val p: native.Ptr[struct_listing]) extends AnyVal {\n"
73+
"\t\tdef a: native.CInt = !p._1\n"
74+
"\t\tdef a_=(value: native.CInt):Unit = !p._1 = value\n"
75+
"\t\tdef b: native.CInt = !p._2\n"
76+
"\t\tdef b_=(value: native.CInt):Unit = !p._2 = value\n"
77+
"\t}\n\n"
78+
"\tdef struct_listing()(implicit z: native.Zone): native.Ptr[struct_listing] = native.alloc[struct_listing]\n\n";
79+
REQUIRE(answ == helpers);
80+
}
81+
6982
TEST_CASE("func no args", "[Func]"){
7083
std::string code = "int foo();";
7184
std::string answ = "\tdef foo(): native.CInt = native.extern\n";

TreeVisitor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ bool TreeVisitor::VisitRecordDecl(clang::RecordDecl *record){
123123
helpers += helpersFunc;
124124
helpers += "\t}\n\n";
125125

126-
return true;
126+
return true;
127127

128128
} else if (record->isStruct() && record->isThisDeclarationADefinition() && !record->isAnonymousStructOrUnion() && name != ""){
129129

@@ -181,6 +181,8 @@ bool TreeVisitor::VisitRecordDecl(clang::RecordDecl *record){
181181
helpers += "\timplicit class " + newName + "_ops(val p: native.Ptr[struct_" + name + "]) extends AnyVal {\n";
182182
helpers += helpersFunc;
183183
helpers += "\t}\n\n";
184+
185+
helpers += "\tdef " + newName + "()(implicit z: native.Zone): native.Ptr[" + newName + "] = native.alloc[" + newName + "]\n\n";
184186
}
185187

186188
return true;

TypeTranslator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "TypeTranslator.h"
22
#include "Utils.h"
33

4-
#include <error.h>
5-
64
TypeTranslator::TypeTranslator(clang::ASTContext* ctx_) : ctx(ctx_), typeMap() {
75

86
//Native Types

0 commit comments

Comments
 (0)