Skip to content

Print warnings only ones #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ add_executable(bindgen
ir/Define.cpp
ir/LiteralDefine.cpp
ir/LiteralDefine.h
utils/WarningManager.cpp
utils/WarningManager.h
)

set_target_properties(bindgen
Expand Down
11 changes: 5 additions & 6 deletions bindgen/TypeTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,15 @@ std::string TypeTranslator::Translate(const clang::QualType &qtpe,
// Warning / Sanity checks

if (qtpe.isConstQualified() || (ctx && qtpe.isConstant(*ctx))) {
llvm::errs() << "Warning: Const qualifier not supported\n";
llvm::errs().flush();
warningManager.printWarning("Warning: Const qualifier not supported");
}
if (qtpe.isVolatileQualified()) {
llvm::errs() << "Warning: Volatile qualifier not supported\n";
llvm::errs().flush();
warningManager.printWarning(
"Warning: Volatile qualifier not supported");
}
if (qtpe.isRestrictQualified()) {
llvm::errs() << "Warning: Restrict qualifier not supported\n";
llvm::errs().flush();
warningManager.printWarning(
"Warning: Restrict qualifier not supported");
}

const clang::Type *tpe = qtpe.getTypePtr();
Expand Down
2 changes: 2 additions & 0 deletions bindgen/TypeTranslator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "utils/WarningManager.h"
#include <clang/AST/AST.h>
#include <clang/AST/ASTContext.h>
#include <clang/Tooling/Tooling.h>
Expand All @@ -8,6 +9,7 @@ class TypeTranslator {
private:
clang::ASTContext *ctx;
std::map<std::string, std::string> typeMap;
WarningManager warningManager;

public:
explicit TypeTranslator(clang::ASTContext *ctx);
Expand Down
11 changes: 11 additions & 0 deletions bindgen/utils/WarningManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "WarningManager.h"

#include <llvm/Support/raw_ostream.h>

void WarningManager::printWarning(std::string warning) {
if (printedWarnings.find(warning) == printedWarnings.end()) {
llvm::errs() << warning << "\n";
llvm::errs().flush();
printedWarnings.insert(warning);
}
}
18 changes: 18 additions & 0 deletions bindgen/utils/WarningManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef SCALA_NATIVE_BINDGEN_WARNINGMANAGER_H
#define SCALA_NATIVE_BINDGEN_WARNINGMANAGER_H

#include <string>
#include <unordered_set>

/**
* Ignores duplicate warnings
*/
class WarningManager {
public:
void printWarning(std::string warning);

private:
std::unordered_set<std::string> printedWarnings;
};

#endif // SCALA_NATIVE_BINDGEN_WARNINGMANAGER_H