Skip to content

Commit f384d75

Browse files
committed
Add test for resserved words in array types
1 parent 4c8540f commit f384d75

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

TypeTranslator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ std::string TypeTranslator::TranslatePointer(const clang::QualType& pte, const s
8181

8282

8383

84-
return std::string("native.Ptr[") + handleReservedWords(Translate(pte, avoid)) + std::string("]");
84+
return std::string("native.Ptr[") + Translate(pte, avoid) + std::string("]");
8585
}
8686

8787
std::string TypeTranslator::TranslateStructOrUnion(const clang::QualType& qtpe){
@@ -153,7 +153,7 @@ std::string TypeTranslator::Translate(const clang::QualType& qtpe, const std::st
153153
return TranslatePointer(tpe->getAs<clang::PointerType>()->getPointeeType(), avoid);
154154

155155
} else if(qtpe->isStructureType() || qtpe->isUnionType()){
156-
return TranslateStructOrUnion(qtpe);
156+
return handleReservedWords(TranslateStructOrUnion(qtpe));
157157

158158
} else if(qtpe->isEnumeralType()){
159159
return TranslateEnum(qtpe);
@@ -166,10 +166,10 @@ std::string TypeTranslator::Translate(const clang::QualType& qtpe, const std::st
166166

167167
auto found = typeMap.find(qtpe.getUnqualifiedType().getAsString());
168168
if(found != typeMap.end()){
169-
return found->second;
169+
return handleReservedWords(found->second);
170170
} else {
171171
//TODO: Properly handle non-default types
172-
return qtpe.getUnqualifiedType().getAsString();
172+
return handleReservedWords(qtpe.getUnqualifiedType().getAsString());
173173
}
174174
}
175175

tests/samples/ReservedWords.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
typedef int match;
2+
typedef match var[5];
23

34
struct object {
45
match yield;
@@ -19,7 +20,7 @@ union lazy {
1920

2021
typedef union lazy lazy;
2122

22-
type with(match sealed, int implicit, lazy forSome);
23+
type with(match sealed, var implicit, lazy forSome);
2324

2425
typedef match def;
2526
typedef struct { def val; lazy finally; } finally;

tests/samples/ReservedWords.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import scala.scalanative.native.Nat._
66
@native.extern
77
object ReservedWords {
88
type `match` = native.CInt
9+
type `var` = native.CArray[`match`, _5]
910
type `object` = struct_object
1011
type `type` = struct_object
1112
type `lazy` = union_lazy
@@ -14,7 +15,7 @@ object ReservedWords {
1415
type struct_object = native.CStruct2[`match`, native.CInt]
1516
type struct_finally = native.CStruct2[`def`, `lazy`]
1617
type union_lazy = native.CArray[Byte, Digit[_1, Digit[_2, _8]]]
17-
def `with`(`sealed`: `match`, `implicit`: native.CInt, `forSome`: `lazy`): `type` = native.extern
18+
def `with`(`sealed`: `match`, `implicit`: native.Ptr[`match`], `forSome`: `lazy`): `type` = native.extern
1819
def `implicit`(`type`: native.Ptr[`finally`]): `match` = native.extern
1920
}
2021

0 commit comments

Comments
 (0)