Skip to content

Commit e5d86c5

Browse files
committed
Add const qualifiers to fields of type Type
1 parent 40f6670 commit e5d86c5

23 files changed

+60
-59
lines changed

bindgen/TypeTranslator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ TypeTranslator::translateFunctionPointer(const clang::QualType &qtpe,
4343
const auto *fc = inner->getAs<clang::FunctionProtoType>();
4444
std::shared_ptr<Type> returnType =
4545
translate(fc->getReturnType(), avoid);
46-
std::vector<std::shared_ptr<Type>> parametersTypes;
46+
std::vector<std::shared_ptr<const Type>> parametersTypes;
4747

4848
for (const clang::QualType &param : fc->param_types()) {
4949
parametersTypes.push_back(translate(param, avoid));

bindgen/Utils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static inline bool startsWith(const std::string &str,
6464
}
6565

6666
template <typename T, typename PT> static inline bool isInstanceOf(PT *type) {
67-
auto *p = dynamic_cast<T *>(type);
67+
auto *p = dynamic_cast<const T *>(type);
6868
return p != nullptr;
6969
}
7070

@@ -82,13 +82,13 @@ static inline std::string replaceChar(const std::string &str,
8282
* Types may be wrapper in a chain of typedefs.
8383
* @return true if given type is of type T or is an alias for type T.
8484
*/
85-
template <typename T> static inline bool isAliasForType(Type *type) {
85+
template <typename T> static inline bool isAliasForType(const Type *type) {
8686
if (isInstanceOf<T>(type)) {
8787
return true;
8888
}
89-
auto *typeDef = dynamic_cast<TypeDef *>(type);
89+
auto *typeDef = dynamic_cast<const TypeDef *>(type);
9090
if (typeDef) {
91-
return isAliasForType<T>(typeDef->getType().get());
91+
return isAliasForType<const T>(typeDef->getType().get());
9292
}
9393
return false;
9494
}

bindgen/ir/Function.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#include "../Utils.h"
33
#include "Struct.h"
44

5-
Parameter::Parameter(std::string name, std::shared_ptr<Type> type)
5+
Parameter::Parameter(std::string name, std::shared_ptr<const Type> type)
66
: TypeAndName(std::move(name), type) {}
77

88
Function::Function(const std::string &name,
99
std::vector<std::shared_ptr<Parameter>> parameters,
10-
std::shared_ptr<Type> retType, bool isVariadic)
10+
std::shared_ptr<const Type> retType, bool isVariadic)
1111
: name(name), scalaName(name), parameters(std::move(parameters)),
1212
retType(std::move(retType)), isVariadic(isVariadic) {}
1313

bindgen/ir/Function.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
class Parameter : public TypeAndName {
1111
public:
12-
Parameter(std::string name, std::shared_ptr<Type> type);
12+
Parameter(std::string name, std::shared_ptr<const Type> type);
1313
};
1414

1515
class Function {
1616
public:
1717
Function(const std::string &name,
1818
std::vector<std::shared_ptr<Parameter>> parameters,
19-
std::shared_ptr<Type> retType, bool isVariadic);
19+
std::shared_ptr<const Type> retType, bool isVariadic);
2020

2121
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &s,
2222
const Function &func);
@@ -41,7 +41,7 @@ class Function {
4141
std::string name; // real name of the function
4242
std::string scalaName; // not empty
4343
std::vector<std::shared_ptr<Parameter>> parameters;
44-
std::shared_ptr<Type> retType;
44+
std::shared_ptr<const Type> retType;
4545
bool isVariadic;
4646
};
4747

bindgen/ir/IR.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ void IR::filterTypeDefs(const std::string &excludePrefix) {
260260
}
261261
}
262262

263-
void IR::replaceTypeInTypeDefs(std::shared_ptr<Type> oldType,
264-
std::shared_ptr<Type> newType) {
263+
void IR::replaceTypeInTypeDefs(std::shared_ptr<const Type> oldType,
264+
std::shared_ptr<const Type> newType) {
265265
for (auto &typeDef : typeDefs) {
266266
if (typeDef->getType() == oldType) {
267267
typeDef->setType(newType);
@@ -443,15 +443,15 @@ template <typename T> bool IR::inMainFile(const T &type) const {
443443
/* generated TypeDef */
444444
auto *typeDef = dynamic_cast<const TypeDef *>(&type);
445445
assert(typeDef);
446-
Type *innerType = typeDef->getType().get();
446+
const Type *innerType = typeDef->getType().get();
447447
if (isInstanceOf<Struct>(innerType)) {
448-
return inMainFile(*dynamic_cast<Struct *>(innerType));
448+
return inMainFile(*dynamic_cast<const Struct *>(innerType));
449449
}
450450
if (isInstanceOf<Union>(innerType)) {
451-
return inMainFile(*dynamic_cast<Union *>(innerType));
451+
return inMainFile(*dynamic_cast<const Union *>(innerType));
452452
}
453453
if (isInstanceOf<Enum>(innerType)) {
454-
return inMainFile(*dynamic_cast<Enum *>(innerType));
454+
return inMainFile(*dynamic_cast<const Enum *>(innerType));
455455
}
456456
}
457457
return location && locationManager.inMainFile(*location);

bindgen/ir/IR.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ class IR {
108108
/**
109109
* Find all typedefs that use oldType and replace it with newType.
110110
*/
111-
void replaceTypeInTypeDefs(std::shared_ptr<Type> oldType,
112-
std::shared_ptr<Type> newType);
111+
void replaceTypeInTypeDefs(std::shared_ptr<const Type> oldType,
112+
std::shared_ptr<const Type> newType);
113113

114114
/**
115115
* @return true if given type is used only in typedefs.

bindgen/ir/LiteralDefine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "LiteralDefine.h"
22

33
LiteralDefine::LiteralDefine(std::string name, std::string literal,
4-
std::shared_ptr<Type> type)
4+
std::shared_ptr<const Type> type)
55
: Define(std::move(name)), literal(std::move(literal)), type(type) {}
66

77
llvm::raw_ostream &operator<<(llvm::raw_ostream &s,

bindgen/ir/LiteralDefine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class LiteralDefine : public Define {
99
public:
1010
LiteralDefine(std::string name, std::string literal,
11-
std::shared_ptr<Type> type);
11+
std::shared_ptr<const Type> type);
1212

1313
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &s,
1414
const LiteralDefine &literalDefine);
@@ -17,7 +17,7 @@ class LiteralDefine : public Define {
1717

1818
private:
1919
std::string literal;
20-
std::shared_ptr<Type> type;
20+
std::shared_ptr<const Type> type;
2121
};
2222

2323
#endif // SCALA_NATIVE_BINDGEN_LITERALDEFINE_H

bindgen/ir/Struct.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include "types/PrimitiveType.h"
66
#include <sstream>
77

8-
Field::Field(std::string name, std::shared_ptr<Type> type)
8+
Field::Field(std::string name, std::shared_ptr<const Type> type)
99
: TypeAndName(std::move(name), std::move(type)) {}
1010

11-
Field::Field(std::string name, std::shared_ptr<Type> type,
11+
Field::Field(std::string name, std::shared_ptr<const Type> type,
1212
uint64_t offsetInBits)
1313
: TypeAndName(std::move(name), std::move(type)),
1414
offsetInBits(offsetInBits) {}
@@ -262,7 +262,7 @@ std::string Union::generateHelperClass() const {
262262
if (!field->getName().empty()) {
263263
std::string getter = handleReservedWords(field->getName());
264264
std::string setter = handleReservedWords(field->getName(), "_=");
265-
std::shared_ptr<Type> ftype = field->getType();
265+
std::shared_ptr<const Type> ftype = field->getType();
266266
s << " def " << getter << ": native.Ptr[" << ftype->str()
267267
<< "] = p.cast[native.Ptr[" << ftype->str() << "]]\n";
268268

bindgen/ir/Struct.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
class Field : public TypeAndName {
1313
public:
14-
Field(std::string name, std::shared_ptr<Type> type);
14+
Field(std::string name, std::shared_ptr<const Type> type);
1515

16-
Field(std::string name, std::shared_ptr<Type> type, uint64_t offsetInBits);
16+
Field(std::string name, std::shared_ptr<const Type> type,
17+
uint64_t offsetInBits);
1718

1819
uint64_t getOffsetInBits() const;
1920

0 commit comments

Comments
 (0)