Skip to content

Commit 76a9600

Browse files
committed
Add support for native Cstring
1 parent 4dcb58a commit 76a9600

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

SimpleTypeTests.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ TEST_CASE("native types", "[Type]" ) {
2424
{"short", "native.CShort"},
2525
{"unsigned short", "native.CUnsignedShort"},
2626
{"int", "native.CInt"},
27-
//{"long int", "native.CLongInt"},
28-
{"unsigned int", "native.CUnsignedInt"},
29-
//{"unsigned long int", "native.CUnsignedLongInt"},
3027
{"long", "native.CLong"},
28+
//{"long int", "native.CLongInt"}, <- similar to a long, why is it different ?
29+
{"unsigned int", "native.CUnsignedInt"},
3130
{"unsigned long", "native.CUnsignedLong"},
31+
//{"unsigned long int", "native.CUnsignedLongInt"}, <- similar to an unsigned long why is it different ?
3232
{"long long", "native.CLongLong"},
3333
{"unsigned long long", "native.CUnsignedLongLong"},
3434
{"size_t", "native.CSize"},
@@ -40,9 +40,7 @@ TEST_CASE("native types", "[Type]" ) {
4040
{"double", "native.CDouble"},
4141
{"void*", "native.Ptr[Byte]"},
4242
{"int*", "native.Ptr[native.CInt]"},
43-
//{"char*", "native.CString"},
44-
//{"int (*a)(int)", "native.CFunctionPtr1[native.CInt, native.CInt]"},
45-
//{"struct { int x, y; }*", "native.Ptr[native.CStruct2[native.CInt, native.CInt]]"}
43+
{"char*", "native.CString"},
4644
};
4745

4846
for(const auto& kv: types){
@@ -52,3 +50,10 @@ TEST_CASE("native types", "[Type]" ) {
5250
REQUIRE(answer == Translate(code));
5351
}
5452
}
53+
54+
TEST_CASE("native types function pointer", "[Type]"){
55+
std::string code = "typedef int (*a)(int);";
56+
std::string answ = "\ttype a = native.CFunctionPtr1[native.CInt, native.CInt]\n";
57+
REQUIRE(answ == Translate(code));
58+
}
59+

TypeTranslator.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,22 @@ std::string TypeTranslator::TranslateFunctionPointer(const clang::QualType& qtpe
6666
std::string TypeTranslator::TranslatePointer(const clang::PointerType* ptr, const std::string* avoid){
6767
const clang::QualType& pte = ptr->getPointeeType();
6868

69-
//Take care of void*
7069
if(pte->isBuiltinType()){
7170
const clang::BuiltinType* as = pte->getAs<clang::BuiltinType>();
71+
72+
//Take care of void*
7273
if(as->getKind() == clang::BuiltinType::Void){
7374
return "native.Ptr[Byte]";
7475
}
76+
77+
//Take care of char*
78+
if(as->getKind() == clang::BuiltinType::Char_S || as->getKind() == clang::BuiltinType::SChar){
79+
return "native.CString";
80+
}
7581
}
7682

83+
84+
7785
return std::string("native.Ptr[") + Translate(pte, avoid) + std::string("]");
7886
}
7987

0 commit comments

Comments
 (0)