Skip to content

Commit 31cf805

Browse files
committed
Fix #39: Enable compiler warnings
1 parent 7f7baa1 commit 31cf805

File tree

6 files changed

+13
-18
lines changed

6 files changed

+13
-18
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ find_package(Clang REQUIRED CONFIG)
66
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
77
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
88

9-
include_directories(${LLVM_INCLUDE_DIRS})
9+
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
1010
add_definitions(${LLVM_DEFINITIONS})
1111

12-
add_compile_options(-fexceptions -std=c++11)
12+
add_compile_options(-fexceptions -std=c++11 -Wall -Wconversion -Werror)
1313

1414
add_executable(bindgen
1515
Main.cpp

Utils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ inline std::string uint64ToScalaNat(uint64_t v, std::string accumulator = "") {
1919
if (v == 0)
2020
return accumulator;
2121

22-
int last_digit = v % 10;
23-
int rest = v / 10;
22+
auto last_digit = v % 10;
23+
auto rest = v / 10;
2424

2525
if (accumulator.empty()) {
2626
return uint64ToScalaNat(rest, "_" + std::to_string(last_digit));
@@ -44,11 +44,11 @@ inline bool typeEquals(const clang::Type* tpe1, const std::string* tpe2){
4444
return false;
4545
}
4646

47-
static std::array<std::string, 39> reserved_words = {"abstract", "case", "catch", "class", "def", "do", "else", "extends",
47+
static std::array<std::string, 39> reserved_words = {{"abstract", "case", "catch", "class", "def", "do", "else", "extends",
4848
"false", "final", "finally", "for", "forSome", "if", "implicit", "import",
4949
"lazy", "match", "new", "null", "object", "override", "package", "private",
5050
"protected", "return", "sealed", "super", "this", "throw", "trait", "try",
51-
"true", "type", "val", "var", "while", "with", "yield"};
51+
"true", "type", "val", "var", "while", "with", "yield"}};
5252

5353
inline std::string handleReservedWords(std::string name, std::string suffix = "") {
5454
auto found = std::find(reserved_words.begin(), reserved_words.end(), name);

ir/Function.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ Function::Function(std::string name, std::vector<Parameter> parameters,
1313
llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const Function &func) {
1414
s << " def " << handleReservedWords(func.name)
1515
<< "(";
16-
auto paramsCount = static_cast<int>(func.parameters.size());
17-
for (int i = 0; i < paramsCount; ++i) {
16+
for (std::vector<Parameter>::size_type i = 0; i < func.parameters.size(); i++) {
1817
const Parameter &param = func.parameters[i];
1918
s << handleReservedWords(param.getName())
2019
<< ": "
2120
<< param.getType();
22-
if (i < paramsCount - 1) {
21+
if (i + 1 != func.parameters.size()) {
2322
s << ", ";
2423
}
2524
}

ir/Struct.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ TypeDef Struct::generateTypeDef() const {
2424

2525
std::string Struct::getFieldsTypes() const {
2626
std::stringstream s;
27-
auto fieldsCount = static_cast<int>(fields.size());
28-
for (int i = 0; i < fieldsCount; i++) {
27+
for (std::vector<Field>::size_type i = 0; i < fields.size(); i++) {
2928
s << fields[i].getType();
30-
if (i < fieldsCount - 1) {
29+
if (i + 1 != fields.size()) {
3130
s << ", ";
3231
}
3332
}

scripts/test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ if [[ ! -e target/.llvm-version ]] || [[ "$(<target/.llvm-version)" != "${LLVM_V
1010
mkdir -p target
1111
echo "${LLVM_VERSION:-}" > target/.llvm-version
1212
(cd target && cmake ..)
13-
make -C target
1413
fi
1514

15+
make -C target
16+
1617
cd tests
1718
sbt "${@:-test}"

visitor/TreeConsumer.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ class TreeConsumer : public clang::ASTConsumer {
1717

1818
clang::SourceManager &smanager;
1919

20-
/* pointer to ir that is stored in ScalaFrontendActionFactory */
21-
IR *ir;
22-
2320
public:
2421

2522
explicit TreeConsumer(clang::CompilerInstance *CI, IR *ir)
2623
: visitor(CI, ir),
27-
smanager(CI->getASTContext().getSourceManager()),
28-
ir(ir) {}
24+
smanager(CI->getASTContext().getSourceManager()) {}
2925

3026
bool HandleTopLevelDecl(clang::DeclGroupRef DG) override {
3127
// a DeclGroupRef may have multiple Decls, so we iterate through each one

0 commit comments

Comments
 (0)