diff --git a/bindgen/TypeTranslator.cpp b/bindgen/TypeTranslator.cpp index 73f48fb..c7d334f 100644 --- a/bindgen/TypeTranslator.cpp +++ b/bindgen/TypeTranslator.cpp @@ -43,7 +43,7 @@ TypeTranslator::translateFunctionPointer(const clang::QualType &qtpe, const auto *fc = inner->getAs(); std::shared_ptr returnType = translate(fc->getReturnType(), avoid); - std::vector> parametersTypes; + std::vector> parametersTypes; for (const clang::QualType ¶m : fc->param_types()) { parametersTypes.push_back(translate(param, avoid)); diff --git a/bindgen/Utils.h b/bindgen/Utils.h index 6ebfcc0..5f39e32 100644 --- a/bindgen/Utils.h +++ b/bindgen/Utils.h @@ -64,7 +64,7 @@ static inline bool startsWith(const std::string &str, } template static inline bool isInstanceOf(PT *type) { - auto *p = dynamic_cast(type); + auto *p = dynamic_cast(type); return p != nullptr; } @@ -82,13 +82,13 @@ static inline std::string replaceChar(const std::string &str, * Types may be wrapper in a chain of typedefs. * @return true if given type is of type T or is an alias for type T. */ -template static inline bool isAliasForType(Type *type) { +template static inline bool isAliasForType(const Type *type) { if (isInstanceOf(type)) { return true; } - auto *typeDef = dynamic_cast(type); + auto *typeDef = dynamic_cast(type); if (typeDef) { - return isAliasForType(typeDef->getType().get()); + return isAliasForType(typeDef->getType().get()); } return false; } diff --git a/bindgen/ir/Function.cpp b/bindgen/ir/Function.cpp index e84ae7e..9641b04 100644 --- a/bindgen/ir/Function.cpp +++ b/bindgen/ir/Function.cpp @@ -2,12 +2,12 @@ #include "../Utils.h" #include "Struct.h" -Parameter::Parameter(std::string name, std::shared_ptr type) +Parameter::Parameter(std::string name, std::shared_ptr type) : TypeAndName(std::move(name), type) {} Function::Function(const std::string &name, std::vector> parameters, - std::shared_ptr retType, bool isVariadic) + std::shared_ptr retType, bool isVariadic) : name(name), scalaName(name), parameters(std::move(parameters)), retType(std::move(retType)), isVariadic(isVariadic) {} diff --git a/bindgen/ir/Function.h b/bindgen/ir/Function.h index f956d89..2e4ec6e 100644 --- a/bindgen/ir/Function.h +++ b/bindgen/ir/Function.h @@ -9,14 +9,14 @@ class Parameter : public TypeAndName { public: - Parameter(std::string name, std::shared_ptr type); + Parameter(std::string name, std::shared_ptr type); }; class Function { public: Function(const std::string &name, std::vector> parameters, - std::shared_ptr retType, bool isVariadic); + std::shared_ptr retType, bool isVariadic); friend llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const Function &func); @@ -41,7 +41,7 @@ class Function { std::string name; // real name of the function std::string scalaName; // not empty std::vector> parameters; - std::shared_ptr retType; + std::shared_ptr retType; bool isVariadic; }; diff --git a/bindgen/ir/IR.cpp b/bindgen/ir/IR.cpp index 3b34069..06db144 100644 --- a/bindgen/ir/IR.cpp +++ b/bindgen/ir/IR.cpp @@ -260,8 +260,8 @@ void IR::filterTypeDefs(const std::string &excludePrefix) { } } -void IR::replaceTypeInTypeDefs(std::shared_ptr oldType, - std::shared_ptr newType) { +void IR::replaceTypeInTypeDefs(std::shared_ptr oldType, + std::shared_ptr newType) { for (auto &typeDef : typeDefs) { if (typeDef->getType() == oldType) { typeDef->setType(newType); @@ -443,15 +443,15 @@ template bool IR::inMainFile(const T &type) const { /* generated TypeDef */ auto *typeDef = dynamic_cast(&type); assert(typeDef); - Type *innerType = typeDef->getType().get(); + const Type *innerType = typeDef->getType().get(); if (isInstanceOf(innerType)) { - return inMainFile(*dynamic_cast(innerType)); + return inMainFile(*dynamic_cast(innerType)); } if (isInstanceOf(innerType)) { - return inMainFile(*dynamic_cast(innerType)); + return inMainFile(*dynamic_cast(innerType)); } if (isInstanceOf(innerType)) { - return inMainFile(*dynamic_cast(innerType)); + return inMainFile(*dynamic_cast(innerType)); } } return location && locationManager.inMainFile(*location); diff --git a/bindgen/ir/IR.h b/bindgen/ir/IR.h index 38cf5c6..b6fbe1d 100644 --- a/bindgen/ir/IR.h +++ b/bindgen/ir/IR.h @@ -108,8 +108,8 @@ class IR { /** * Find all typedefs that use oldType and replace it with newType. */ - void replaceTypeInTypeDefs(std::shared_ptr oldType, - std::shared_ptr newType); + void replaceTypeInTypeDefs(std::shared_ptr oldType, + std::shared_ptr newType); /** * @return true if given type is used only in typedefs. diff --git a/bindgen/ir/LiteralDefine.cpp b/bindgen/ir/LiteralDefine.cpp index 001518c..e79e8bb 100644 --- a/bindgen/ir/LiteralDefine.cpp +++ b/bindgen/ir/LiteralDefine.cpp @@ -1,7 +1,7 @@ #include "LiteralDefine.h" LiteralDefine::LiteralDefine(std::string name, std::string literal, - std::shared_ptr type) + std::shared_ptr type) : Define(std::move(name)), literal(std::move(literal)), type(type) {} llvm::raw_ostream &operator<<(llvm::raw_ostream &s, diff --git a/bindgen/ir/LiteralDefine.h b/bindgen/ir/LiteralDefine.h index 01a08b1..5aa32cf 100644 --- a/bindgen/ir/LiteralDefine.h +++ b/bindgen/ir/LiteralDefine.h @@ -8,7 +8,7 @@ class LiteralDefine : public Define { public: LiteralDefine(std::string name, std::string literal, - std::shared_ptr type); + std::shared_ptr type); friend llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const LiteralDefine &literalDefine); @@ -17,7 +17,7 @@ class LiteralDefine : public Define { private: std::string literal; - std::shared_ptr type; + std::shared_ptr type; }; #endif // SCALA_NATIVE_BINDGEN_LITERALDEFINE_H diff --git a/bindgen/ir/Struct.cpp b/bindgen/ir/Struct.cpp index 45dbb66..e3bef58 100644 --- a/bindgen/ir/Struct.cpp +++ b/bindgen/ir/Struct.cpp @@ -5,10 +5,10 @@ #include "types/PrimitiveType.h" #include -Field::Field(std::string name, std::shared_ptr type) +Field::Field(std::string name, std::shared_ptr type) : TypeAndName(std::move(name), std::move(type)) {} -Field::Field(std::string name, std::shared_ptr type, +Field::Field(std::string name, std::shared_ptr type, uint64_t offsetInBits) : TypeAndName(std::move(name), std::move(type)), offsetInBits(offsetInBits) {} @@ -262,7 +262,7 @@ std::string Union::generateHelperClass() const { if (!field->getName().empty()) { std::string getter = handleReservedWords(field->getName()); std::string setter = handleReservedWords(field->getName(), "_="); - std::shared_ptr ftype = field->getType(); + std::shared_ptr ftype = field->getType(); s << " def " << getter << ": native.Ptr[" << ftype->str() << "] = p.cast[native.Ptr[" << ftype->str() << "]]\n"; diff --git a/bindgen/ir/Struct.h b/bindgen/ir/Struct.h index 182f8e4..2fb2468 100644 --- a/bindgen/ir/Struct.h +++ b/bindgen/ir/Struct.h @@ -11,9 +11,10 @@ class Field : public TypeAndName { public: - Field(std::string name, std::shared_ptr type); + Field(std::string name, std::shared_ptr type); - Field(std::string name, std::shared_ptr type, uint64_t offsetInBits); + Field(std::string name, std::shared_ptr type, + uint64_t offsetInBits); uint64_t getOffsetInBits() const; diff --git a/bindgen/ir/TypeAndName.cpp b/bindgen/ir/TypeAndName.cpp index b6a0fe7..1064a24 100644 --- a/bindgen/ir/TypeAndName.cpp +++ b/bindgen/ir/TypeAndName.cpp @@ -1,14 +1,16 @@ #include "TypeAndName.h" #include -TypeAndName::TypeAndName(std::string name, std::shared_ptr type) +TypeAndName::TypeAndName(std::string name, std::shared_ptr type) : name(std::move(name)), type(std::move(type)) {} -std::shared_ptr TypeAndName::getType() const { return type; } +std::shared_ptr TypeAndName::getType() const { return type; } std::string TypeAndName::getName() const { return name; } -void TypeAndName::setType(std::shared_ptr type) { this->type = type; } +void TypeAndName::setType(std::shared_ptr type) { + this->type = type; +} bool TypeAndName::operator==(const TypeAndName &other) const { if (this == &other) { diff --git a/bindgen/ir/TypeAndName.h b/bindgen/ir/TypeAndName.h index 1b2b588..0a45cd0 100644 --- a/bindgen/ir/TypeAndName.h +++ b/bindgen/ir/TypeAndName.h @@ -11,11 +11,11 @@ */ class TypeAndName { public: - TypeAndName(std::string name, std::shared_ptr type); + TypeAndName(std::string name, std::shared_ptr type); - std::shared_ptr getType() const; + std::shared_ptr getType() const; - void setType(std::shared_ptr name); + void setType(std::shared_ptr name); std::string getName() const; @@ -27,7 +27,7 @@ class TypeAndName { protected: std::string name; - std::shared_ptr type; + std::shared_ptr type; }; #endif // SCALA_NATIVE_BINDGEN_TYPEANDNAME_H diff --git a/bindgen/ir/TypeDef.cpp b/bindgen/ir/TypeDef.cpp index 91edaa7..c845221 100644 --- a/bindgen/ir/TypeDef.cpp +++ b/bindgen/ir/TypeDef.cpp @@ -3,7 +3,7 @@ #include "Enum.h" #include "Struct.h" -TypeDef::TypeDef(std::string name, std::shared_ptr type, +TypeDef::TypeDef(std::string name, std::shared_ptr type, std::shared_ptr location) : TypeAndName(std::move(name), std::move(type)), location(std::move(location)) {} @@ -36,7 +36,7 @@ bool TypeDef::operator==(const Type &other) const { if (this == &other) { return true; } - if (isInstanceOf(&other)) { + if (isInstanceOf(&other)) { auto *typDef = dynamic_cast(&other); if (name != typDef->name) { return false; diff --git a/bindgen/ir/TypeDef.h b/bindgen/ir/TypeDef.h index 2ecdf18..2557b02 100644 --- a/bindgen/ir/TypeDef.h +++ b/bindgen/ir/TypeDef.h @@ -8,7 +8,7 @@ class TypeDef : public TypeAndName, public Type { public: - TypeDef(std::string name, std::shared_ptr type, + TypeDef(std::string name, std::shared_ptr type, std::shared_ptr location); friend llvm::raw_ostream &operator<<(llvm::raw_ostream &s, diff --git a/bindgen/ir/Variable.cpp b/bindgen/ir/Variable.cpp index 16433d1..4827324 100644 --- a/bindgen/ir/Variable.cpp +++ b/bindgen/ir/Variable.cpp @@ -1,7 +1,7 @@ #include "Variable.h" #include "../Utils.h" -Variable::Variable(const std::string &name, std::shared_ptr type) +Variable::Variable(const std::string &name, std::shared_ptr type) : TypeAndName(name, type) {} llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const Variable &variable) { diff --git a/bindgen/ir/Variable.h b/bindgen/ir/Variable.h index 54ced06..08ddea7 100644 --- a/bindgen/ir/Variable.h +++ b/bindgen/ir/Variable.h @@ -6,7 +6,7 @@ class Variable : public TypeAndName { public: - Variable(const std::string &name, std::shared_ptr type); + Variable(const std::string &name, std::shared_ptr type); friend llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const Variable &variable); diff --git a/bindgen/ir/types/ArrayType.cpp b/bindgen/ir/types/ArrayType.cpp index 6109042..f506bd7 100644 --- a/bindgen/ir/types/ArrayType.cpp +++ b/bindgen/ir/types/ArrayType.cpp @@ -2,7 +2,7 @@ #include "../../Utils.h" #include "../Struct.h" -ArrayType::ArrayType(std::shared_ptr elementsType, uint64_t size) +ArrayType::ArrayType(std::shared_ptr elementsType, uint64_t size) : size(size), elementsType(std::move(elementsType)) {} std::string ArrayType::str() const { @@ -20,8 +20,7 @@ bool ArrayType::operator==(const Type &other) const { if (this == &other) { return true; } - if (isInstanceOf(&other) && - !isInstanceOf(&other)) { + if (isInstanceOf(&other) && !isInstanceOf(&other)) { auto *arrayType = dynamic_cast(&other); if (size != arrayType->size) { return false; diff --git a/bindgen/ir/types/ArrayType.h b/bindgen/ir/types/ArrayType.h index 4a1b556..4126ee4 100644 --- a/bindgen/ir/types/ArrayType.h +++ b/bindgen/ir/types/ArrayType.h @@ -5,7 +5,7 @@ class ArrayType : public virtual Type { public: - ArrayType(std::shared_ptr elementsType, uint64_t size); + ArrayType(std::shared_ptr elementsType, uint64_t size); bool usesType(const std::shared_ptr &type, bool stopOnTypeDefs) const override; @@ -16,7 +16,7 @@ class ArrayType : public virtual Type { private: const uint64_t size; - std::shared_ptr elementsType; + std::shared_ptr elementsType; }; #endif // SCALA_NATIVE_BINDGEN_ARRAYTYPE_H diff --git a/bindgen/ir/types/FunctionPointerType.cpp b/bindgen/ir/types/FunctionPointerType.cpp index 3a528d5..651f43a 100644 --- a/bindgen/ir/types/FunctionPointerType.cpp +++ b/bindgen/ir/types/FunctionPointerType.cpp @@ -3,8 +3,8 @@ #include FunctionPointerType::FunctionPointerType( - std::shared_ptr returnType, - const std::vector> ¶metersTypes, bool isVariadic) + std::shared_ptr returnType, + std::vector> ¶metersTypes, bool isVariadic) : returnType(std::move(returnType)), parametersTypes(parametersTypes), isVariadic(isVariadic) {} @@ -25,14 +25,13 @@ std::string FunctionPointerType::str() const { bool FunctionPointerType::usesType(const std::shared_ptr &type, bool stopOnTypeDefs) const { - if (*returnType == *type || - returnType.get()->usesType(type, stopOnTypeDefs)) { + if (*returnType == *type || returnType->usesType(type, stopOnTypeDefs)) { return true; } for (const auto ¶meterType : parametersTypes) { if (*parameterType == *type || - parameterType.get()->usesType(type, stopOnTypeDefs)) { + parameterType->usesType(type, stopOnTypeDefs)) { return true; } } @@ -43,7 +42,7 @@ bool FunctionPointerType::operator==(const Type &other) const { if (this == &other) { return true; } - if (isInstanceOf(&other)) { + if (isInstanceOf(&other)) { auto *functionPointerType = dynamic_cast(&other); if (isVariadic != functionPointerType->isVariadic) { diff --git a/bindgen/ir/types/FunctionPointerType.h b/bindgen/ir/types/FunctionPointerType.h index 8dec9a7..4170b36 100644 --- a/bindgen/ir/types/FunctionPointerType.h +++ b/bindgen/ir/types/FunctionPointerType.h @@ -7,8 +7,8 @@ class FunctionPointerType : public Type { public: FunctionPointerType( - std::shared_ptr returnType, - const std::vector> ¶metersTypes, + std::shared_ptr returnType, + std::vector> ¶metersTypes, bool isVariadic); bool usesType(const std::shared_ptr &type, @@ -19,8 +19,8 @@ class FunctionPointerType : public Type { bool operator==(const Type &other) const override; private: - std::shared_ptr returnType; - std::vector> parametersTypes; + std::shared_ptr returnType; + std::vector> parametersTypes; bool isVariadic; }; diff --git a/bindgen/ir/types/PointerType.cpp b/bindgen/ir/types/PointerType.cpp index ba03462..c753bc1 100644 --- a/bindgen/ir/types/PointerType.cpp +++ b/bindgen/ir/types/PointerType.cpp @@ -1,7 +1,8 @@ #include "PointerType.h" #include "../../Utils.h" -PointerType::PointerType(std::shared_ptr type) : type(std::move(type)) {} +PointerType::PointerType(std::shared_ptr type) + : type(std::move(type)) {} std::string PointerType::str() const { return "native.Ptr[" + type->str() + "]"; @@ -17,7 +18,7 @@ bool PointerType::operator==(const Type &other) const { if (this == &other) { return true; } - if (isInstanceOf(&other)) { + if (isInstanceOf(&other)) { auto *pointerType = dynamic_cast(&other); return *type == *pointerType->type; } diff --git a/bindgen/ir/types/PointerType.h b/bindgen/ir/types/PointerType.h index b0a3c35..3262884 100644 --- a/bindgen/ir/types/PointerType.h +++ b/bindgen/ir/types/PointerType.h @@ -5,7 +5,7 @@ class PointerType : public Type { public: - explicit PointerType(std::shared_ptr type); + explicit PointerType(std::shared_ptr type); bool usesType(const std::shared_ptr &type, bool stopOnTypeDefs) const override; @@ -15,7 +15,7 @@ class PointerType : public Type { bool operator==(const Type &other) const override; private: - std::shared_ptr type; + std::shared_ptr type; }; #endif // SCALA_NATIVE_BINDGEN_POINTERTYPE_H diff --git a/bindgen/ir/types/PrimitiveType.cpp b/bindgen/ir/types/PrimitiveType.cpp index 9cd300f..6925074 100644 --- a/bindgen/ir/types/PrimitiveType.cpp +++ b/bindgen/ir/types/PrimitiveType.cpp @@ -17,8 +17,7 @@ bool PrimitiveType::operator==(const Type &other) const { if (this == &other) { return true; } - if (isInstanceOf(&other) && - !isInstanceOf(&other)) { + if (isInstanceOf(&other) && !isInstanceOf(&other)) { auto *primitiveType = dynamic_cast(&other); return type == primitiveType->type; }