Fix all the tidy issues on src

This commit is contained in:
Sameer Rahmani 2021-10-17 16:06:52 +01:00
parent 737226dbae
commit 55e0788bae
5 changed files with 34 additions and 18 deletions

View File

@ -32,11 +32,12 @@
#include <llvm/ADT/StringRef.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/Support/Host.h>
#include <memory>
#include <mlir/Dialect/StandardOps/IR/Ops.h>
#include <mlir/IR/MLIRContext.h>
#include <mlir/Pass/PassManager.h>
#include <memory>
namespace serene {
namespace reader {
@ -153,6 +154,9 @@ private:
/// process to store the state
SERENE_EXPORT std::unique_ptr<SereneContext> makeSereneContext();
}; // namespace serene
/// Terminates the serene compiler process in a thread safe manner
SERENE_EXPORT void terminate(SereneContext &ctx, int exitCode);
} // namespace serene
#endif

View File

@ -24,6 +24,7 @@
#include "serene/slir/generatable.h"
#include <llvm/Support/FormatVariadic.h>
#include <utility>
namespace serene {
@ -100,6 +101,15 @@ NSPtr SereneContext::readNamespace(std::string name,
return sourceManager.readNamespace(*this, std::move(name), loc);
}
void terminate(SereneContext &ctx, int exitCode) {
UNUSED(ctx);
// TODO: Since we are running in a single thread for now using exit is fine
// but we need to adjust and change it to a thread safe termination
// process later on.
// NOLINTNEXTLINE(concurrency-mt-unsafe)
std::exit(exitCode);
}
std::unique_ptr<SereneContext> makeSereneContext() {
return std::make_unique<SereneContext>();
};

View File

@ -28,6 +28,7 @@
#include <llvm/Support/FormatVariadic.h>
#include <llvm/Support/WithColor.h>
#include <llvm/Support/raw_ostream.h>
#include <memory>
namespace serene {
@ -57,7 +58,7 @@ void Diagnostic::writeColorByType(llvm::raw_ostream &os, llvm::StringRef str) {
};
std::string Diagnostic::getPrefix(llvm::StringRef prefix) {
if (prefix != "") {
if (!prefix.empty()) {
return prefix.str();
}
@ -104,8 +105,8 @@ void Diagnostic::print(llvm::raw_ostream &os, llvm::StringRef prefix) {
s << "\n\n";
auto &srcBuf = ctx.sourceManager.getBufferInfo(loc.start.ns);
const char *line = srcBuf.getPointerForLineNumber(loc.start.line);
const auto &srcBuf = ctx.sourceManager.getBufferInfo(loc.start.ns);
const char *line = srcBuf.getPointerForLineNumber(loc.start.line);
while (*line != '\n' && line != srcBuf.buffer->getBufferEnd()) {
s << *line;
@ -121,25 +122,25 @@ void Diagnostic::print(llvm::raw_ostream &os, llvm::StringRef prefix) {
s << '\n';
s << "[";
if (err) {
if (err != nullptr) {
writeColorByType(os, err->getErrId());
}
s << "] ";
writeColorByType(os, getPrefix(prefix));
s << ": ";
if (err) {
if (err != nullptr) {
s << err->description << '\n';
}
if (message != "") {
if (!message.empty()) {
s.changeColor(llvm::raw_ostream::Colors::YELLOW);
s << "With message";
s.resetColor();
s << ": " << message << "\n";
}
if (err) {
if (err != nullptr) {
s << "For more information checkout";
s.changeColor(llvm::raw_ostream::Colors::CYAN);
s << " `serenec --explain ";
@ -151,6 +152,7 @@ DiagnosticEngine::DiagnosticEngine(SereneContext &ctx)
: ctx(ctx), diagEngine(ctx.mlirContext.getDiagEngine()){};
void DiagnosticEngine::print(llvm::raw_ostream &os, Diagnostic &d) {
UNUSED(ctx);
UNUSED(os);
UNUSED(d);
};
@ -165,7 +167,7 @@ Diagnostic DiagnosticEngine::toDiagnostic(reader::LocationRange loc,
void DiagnosticEngine::enqueueError(llvm::StringRef msg) {
llvm::errs() << llvm::formatv("FIX ME (better emit error): {0}\n", msg);
exit(1);
terminate(ctx, 1);
};
void DiagnosticEngine::emitSyntaxError(reader::LocationRange loc,
@ -174,7 +176,7 @@ void DiagnosticEngine::emitSyntaxError(reader::LocationRange loc,
Diagnostic diag(ctx, loc, &e, msg);
diag.print(llvm::errs(), "SyntaxError");
exit(1);
terminate(ctx, 1);
};
void DiagnosticEngine::panic(llvm::StringRef msg) {
@ -194,7 +196,7 @@ void DiagnosticEngine::panic(llvm::StringRef msg) {
s << msg << "\n";
// TODO: Use a proper error code
std::exit(1);
terminate(ctx, 1);
};
std::unique_ptr<DiagnosticEngine> makeDiagnosticEngine(SereneContext &ctx) {

View File

@ -91,7 +91,7 @@ FnOpLowering::matchAndRewrite(serene::slir::FnOp op,
llvm::SmallVector<mlir::Type, 4> arg_types;
for (auto &arg : args) {
for (const auto &arg : args) {
auto attr = std::get<1>(arg).dyn_cast<mlir::TypeAttr>();
if (!attr) {

View File

@ -167,7 +167,7 @@ exprs::Node Reader::readNumber(bool neg) {
if (isdigit(*c) == 0) {
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidDigitForNumber);
exit(1);
terminate(ctx, 1);
}
for (;;) {
@ -179,7 +179,7 @@ exprs::Node Reader::readNumber(bool neg) {
if (*c == '.' && floatNum) {
loc = LocationRange(getCurrentLocation());
ctx.diagEngine->emitSyntaxError(loc, errors::TwoFloatPoints);
exit(1);
terminate(ctx, 1);
}
if (*c == '.') {
@ -196,7 +196,7 @@ exprs::Node Reader::readNumber(bool neg) {
advance();
loc.start = getCurrentLocation();
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidDigitForNumber);
exit(1);
terminate(ctx, 1);
}
loc.end = getCurrentLocation();
@ -222,7 +222,7 @@ exprs::Node Reader::readSymbol() {
ctx.diagEngine->emitSyntaxError(loc, errors::InvalidCharacterForSymbol,
msg);
exit(1);
terminate(ctx, 1);
}
if (*c == '-') {
@ -280,7 +280,7 @@ exprs::Node Reader::readList() {
list->location.end = getCurrentLocation();
ctx.diagEngine->emitSyntaxError(list->location,
errors::EOFWhileScaningAList);
exit(1);
terminate(ctx, 1);
}
switch (*c) {