@@ -34,19 +34,17 @@ TypeTranslator::TypeTranslator(clang::ASTContext *ctx_, IR &ir)
34
34
}
35
35
36
36
std::shared_ptr<Type>
37
- TypeTranslator::translateFunctionPointer (const clang::QualType &qtpe,
38
- const std::string *avoid) {
37
+ TypeTranslator::translateFunctionPointer (const clang::QualType &qtpe) {
39
38
const auto *ptr = qtpe.getTypePtr ()->getAs <clang::PointerType>();
40
39
const clang::QualType &inner = ptr->getPointeeType ();
41
40
42
41
if (inner->isFunctionProtoType ()) {
43
42
const auto *fc = inner->getAs <clang::FunctionProtoType>();
44
- std::shared_ptr<Type> returnType =
45
- translate (fc->getReturnType (), avoid);
43
+ std::shared_ptr<Type> returnType = translate (fc->getReturnType ());
46
44
std::vector<std::shared_ptr<const Type>> parametersTypes;
47
45
48
46
for (const clang::QualType ¶m : fc->param_types ()) {
49
- parametersTypes.push_back (translate (param, avoid ));
47
+ parametersTypes.push_back (translate (param));
50
48
}
51
49
52
50
return std::make_shared<FunctionPointerType>(
@@ -61,8 +59,7 @@ TypeTranslator::translateFunctionPointer(const clang::QualType &qtpe,
61
59
}
62
60
63
61
std::shared_ptr<Type>
64
- TypeTranslator::translatePointer (const clang::QualType &pte,
65
- const std::string *avoid) {
62
+ TypeTranslator::translatePointer (const clang::QualType &pte) {
66
63
67
64
if (pte->isBuiltinType ()) {
68
65
const clang::BuiltinType *as = pte->getAs <clang::BuiltinType>();
@@ -81,7 +78,7 @@ TypeTranslator::translatePointer(const clang::QualType &pte,
81
78
}
82
79
}
83
80
84
- return std::make_shared<PointerType>(translate (pte, avoid ));
81
+ return std::make_shared<PointerType>(translate (pte));
85
82
}
86
83
87
84
std::shared_ptr<Type>
@@ -120,10 +117,9 @@ TypeTranslator::translateStructOrUnion(const clang::QualType &qtpe) {
120
117
}
121
118
122
119
std::shared_ptr<Type>
123
- TypeTranslator::translateConstantArray (const clang::ConstantArrayType *ar,
124
- const std::string *avoid) {
120
+ TypeTranslator::translateConstantArray (const clang::ConstantArrayType *ar) {
125
121
const uint64_t size = ar->getSize ().getZExtValue ();
126
- std::shared_ptr<Type> elementType = translate (ar->getElementType (), avoid );
122
+ std::shared_ptr<Type> elementType = translate (ar->getElementType ());
127
123
if (elementType == nullptr ) {
128
124
llvm::errs () << " Failed to translate array type "
129
125
<< ar->getElementType ().getAsString () << " \n " ;
@@ -133,30 +129,20 @@ TypeTranslator::translateConstantArray(const clang::ConstantArrayType *ar,
133
129
return std::make_shared<ArrayType>(elementType, size);
134
130
}
135
131
136
- std::shared_ptr<Type> TypeTranslator::translate (const clang::QualType &qtpe,
137
- const std::string *avoid) {
132
+ std::shared_ptr<Type> TypeTranslator::translate (const clang::QualType &qtpe) {
138
133
139
134
const clang::Type *tpe = qtpe.getTypePtr ();
140
135
141
- if (typeEquals (tpe, avoid)) {
142
- // This is a type that we want to avoid the usage.
143
- // Êxample: A struct that has a pointer to itself
144
- uint64_t sizeInBits = ctx->getTypeSize (tpe);
145
- assert (sizeInBits % 8 == 0 );
146
- return std::make_shared<ArrayType>(
147
- std::make_shared<PrimitiveType>(" Byte" ), sizeInBits / 8 );
148
- }
149
-
150
136
if (tpe->isFunctionType ()) {
151
137
return nullptr ;
152
138
}
153
139
154
140
if (tpe->isFunctionPointerType ()) {
155
- return translateFunctionPointer (qtpe, avoid );
141
+ return translateFunctionPointer (qtpe);
156
142
157
143
} else if (tpe->isPointerType ()) {
158
144
return translatePointer (
159
- tpe->getAs <clang::PointerType>()->getPointeeType (), avoid );
145
+ tpe->getAs <clang::PointerType>()->getPointeeType ());
160
146
161
147
} else if (qtpe->isStructureType ()) {
162
148
return translateStructOrUnion (qtpe);
@@ -168,10 +154,9 @@ std::shared_ptr<Type> TypeTranslator::translate(const clang::QualType &qtpe,
168
154
return translateStructOrUnionOrEnum (qtpe);
169
155
170
156
} else if (qtpe->isConstantArrayType ()) {
171
- return translateConstantArray (ctx->getAsConstantArrayType (qtpe), avoid );
157
+ return translateConstantArray (ctx->getAsConstantArrayType (qtpe));
172
158
} else if (qtpe->isArrayType ()) {
173
- return translatePointer (ctx->getAsArrayType (qtpe)->getElementType (),
174
- avoid);
159
+ return translatePointer (ctx->getAsArrayType (qtpe)->getElementType ());
175
160
} else {
176
161
177
162
auto found = typeMap.find (qtpe.getUnqualifiedType ().getAsString ());
0 commit comments