Skip to content

Commit 38f356a

Browse files
committed
Remove duplicate TypeDef::isAliasFor method
1 parent 9e7bb2d commit 38f356a

File tree

3 files changed

+11
-33
lines changed

3 files changed

+11
-33
lines changed

bindgen/Utils.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,14 @@ static inline std::string replaceChar(const std::string &str,
116116
* @return true if given type is of type T or is an alias for type T.
117117
*/
118118
template <typename T> static inline bool isAliasForType(Type *type) {
119-
if (isInstanceOf<TypeDef>(type)) {
120-
auto *typeDef = dynamic_cast<TypeDef *>(type);
119+
if (isInstanceOf<T>(type)) {
120+
return true;
121+
}
122+
auto *typeDef = dynamic_cast<TypeDef *>(type);
123+
if (typeDef) {
121124
return isAliasForType<T>(typeDef->getType().get());
122125
}
123-
return isInstanceOf<T>(type);
126+
return false;
124127
}
125128

126129
#endif // UTILS_H

bindgen/ir/Function.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,15 @@ Function::~Function() {
7474
}
7575

7676
bool Function::isLegalScalaNativeFunction() const {
77-
/* structs and unions are used only through corresponding TypeDefs so it's
78-
* okay to cast only to TypeDef.
79-
* Return type and parameters types cannot be array types because array type
77+
/* Return type and parameters types cannot be array types because array type
8078
* in this case is always represented as a pointer to element type */
81-
auto *typeDef = dynamic_cast<TypeDef *>(retType.get());
82-
if (typeDef &&
83-
(typeDef->isAliasFor<Struct>() || typeDef->isAliasFor<ArrayType>())) {
79+
if (isAliasForType<Struct>(retType.get()) ||
80+
isAliasForType<Union>(retType.get())) {
8481
return false;
8582
}
8683
for (const auto &parameter : parameters) {
87-
typeDef = dynamic_cast<TypeDef *>(parameter->getType().get());
88-
if (typeDef && (typeDef->isAliasFor<Struct>() ||
89-
typeDef->isAliasFor<ArrayType>())) {
84+
if (isAliasForType<Struct>(parameter->getType().get()) ||
85+
isAliasForType<Union>(parameter->getType().get())) {
9086
return false;
9187
}
9288
}

bindgen/ir/TypeDef.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,6 @@ class TypeDef : public TypeAndName, public Type {
2323

2424
std::shared_ptr<Location> getLocation() const;
2525

26-
/**
27-
* @tparam T Type
28-
* @return true if the typedef is an alias for give type directly or through
29-
* a chain of typedefs
30-
*/
31-
template <typename T> bool isAliasFor() const {
32-
/* if body is moved to cpp file then linker gives undefined symbols
33-
* error */
34-
if (!type) {
35-
return false;
36-
}
37-
if (dynamic_cast<T *>(type.get())) {
38-
return true;
39-
}
40-
auto *typeDef = dynamic_cast<TypeDef *>(type.get());
41-
if (typeDef) {
42-
return typeDef->isAliasFor<T>();
43-
}
44-
return false;
45-
}
46-
4726
private:
4827
/**
4928
* nullptr if type is generated.

0 commit comments

Comments
 (0)