Skip to content

Commit 4dcb58a

Browse files
committed
More tests for native types
1 parent 6fb13d0 commit 4dcb58a

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

ScalaBindgen.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class TreeConsumer : public clang::ASTConsumer {
8383
for (clang::DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; i++) {
8484
clang::Decl *D = *i;
8585
std::string fpath = smanager.getFilename(D->getLocation()).str();
86-
if(std::find(stdheaders.begin(), stdheaders.end(), basename(fpath)) == stdheaders.end()){
86+
//llvm::errs() << "DEBUG: " << fpath << "\n";
87+
if(std::find(stdheaders.begin(), stdheaders.end(), basename(fpath)) == stdheaders.end() && fpath != ""){
8788
visitor->TraverseDecl(D); // recursively visit each AST node in Decl "D"
8889
}
8990
}

SimpleTypeTests.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ std::string Translate(std::string code){
1010
declarations = "";
1111
enums = "";
1212
auto* action = new ExampleFrontendAction;
13-
clang::tooling::runToolOnCode(action, code);
13+
clang::tooling::runToolOnCode(action, code, "input.h");
1414
return declarations;
1515
}
1616

1717
TEST_CASE("native types", "[Type]" ) {
1818

1919
std::map<std::string, std::string> types = {
2020
{"void", "Unit"},
21-
//{"bool", "native.CBool"},
2221
{"char", "native.CChar"},
2322
{"signed char", "native.CSignedChar"},
2423
{"unsigned char", "native.CUnsignedChar"},
@@ -32,8 +31,8 @@ TEST_CASE("native types", "[Type]" ) {
3231
{"unsigned long", "native.CUnsignedLong"},
3332
{"long long", "native.CLongLong"},
3433
{"unsigned long long", "native.CUnsignedLongLong"},
35-
//{"size_t", "native.CSize"},
36-
//{"ptrdiff_t", "native.CPtrDiff"},
34+
{"size_t", "native.CSize"},
35+
{"ptrdiff_t", "native.CPtrDiff"},
3736
{"wchar_t", "native.CWideChar"},
3837
{"char16_t", "native.CChar16"},
3938
{"char32_t", "native.CChar32"},
@@ -47,10 +46,9 @@ TEST_CASE("native types", "[Type]" ) {
4746
};
4847

4948
for(const auto& kv: types){
50-
std::string code = "typedef " + kv.first + " a;\n";
49+
std::string code = "#include<uchar.h>\n#include<stddef.h>\ntypedef " + kv.first + " a;\n";
5150
std::string answer = "\ttype a = " + kv.second + "\n";
5251

5352
REQUIRE(answer == Translate(code));
5453
}
55-
56-
}
54+
}

TypeTranslator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ TypeTranslator::TypeTranslator(clang::ASTContext* ctx_) : ctx(ctx_), typeMap() {
88
//Native Types
99
typeMap["void"] = "Unit";
1010
typeMap["bool"] = "native.CBool";
11-
typeMap["char"] = "native.CChar";
11+
typeMap["_Bool"] = "native.CBool";
12+
typeMap["char"] = "native.CChar";
1213
typeMap["signed char"] = "native.CSignedChar";
1314
typeMap["unsigned char"] = "native.CUnsignedChar";
1415
typeMap["short"] = "native.CShort";

0 commit comments

Comments
 (0)