From 737226dbaed907d53483ecaa68f8347eae1bf75d Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 17 Oct 2021 14:57:17 +0100 Subject: [PATCH] Fix the reader tidy issues --- include/serene/reader/location.h | 2 +- include/serene/reader/reader.h | 9 +++-- include/serene/reader/semantics.h | 2 +- src/libserene/reader/location.cpp | 4 --- src/libserene/reader/reader.cpp | 55 +++++++++++++++---------------- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/include/serene/reader/location.h b/include/serene/reader/location.h index a48d783..227d5c5 100644 --- a/include/serene/reader/location.h +++ b/include/serene/reader/location.h @@ -21,6 +21,7 @@ #include #include + #include namespace serene { @@ -56,7 +57,6 @@ struct Location { : ns(ns), filename(fname), c(c), line(line), col(col), knownLocation(knownLocation){}; - Location clone(); Location clone() const; mlir::Location toMLIRLocation(SereneContext &ctx); diff --git a/include/serene/reader/reader.h b/include/serene/reader/reader.h index 2fc5061..b62b63f 100644 --- a/include/serene/reader/reader.h +++ b/include/serene/reader/reader.h @@ -41,15 +41,17 @@ #include "serene/reader/location.h" #include "serene/serene.h" +#include + #include #include #include #include + #include #include #include #include -#include #include #define READER_LOG(...) \ @@ -90,7 +92,7 @@ private: /// Returns a boolean indicating whether the given input character is valid /// for an identifier or not. - bool isValidForIdentifier(char c); + static bool isValidForIdentifier(char c); // The property to store the ast tree exprs::Ast ast; @@ -122,8 +124,9 @@ public: Result read(SereneContext &ctx, const llvm::StringRef input, llvm::StringRef ns, llvm::Optional filename); -Result read(SereneContext &ctx, const llvm::MemoryBufferRef but, +Result read(SereneContext &ctx, const llvm::MemoryBufferRef input, llvm::StringRef ns, llvm::Optional filename); } // namespace serene::reader + #endif diff --git a/include/serene/reader/semantics.h b/include/serene/reader/semantics.h index 8e1f10c..72fc253 100644 --- a/include/serene/reader/semantics.h +++ b/include/serene/reader/semantics.h @@ -37,7 +37,7 @@ using AnalyzeResult = Result>; /// /// \param ctx The semantic analysis context /// \param inputAst The raw AST to analyze and possibly rewrite. -AnalyzeResult analyze(serene::SereneContext &ctx, exprs::Ast &tree); +AnalyzeResult analyze(serene::SereneContext &ctx, exprs::Ast &inputAst); }; // namespace serene::reader #endif diff --git a/src/libserene/reader/location.cpp b/src/libserene/reader/location.cpp index ac9321c..159d658 100644 --- a/src/libserene/reader/location.cpp +++ b/src/libserene/reader/location.cpp @@ -36,10 +36,6 @@ std::string Location::toString() const { return llvm::formatv("{0}:{1}", line, col); }; -Location Location::clone() { - return Location{ns, filename, c, line, col, knownLocation}; -} - Location Location::clone() const { return Location{ns, filename, c, line, col, knownLocation}; } diff --git a/src/libserene/reader/reader.cpp b/src/libserene/reader/reader.cpp index 0e9ef84..d5c2a56 100644 --- a/src/libserene/reader/reader.cpp +++ b/src/libserene/reader/reader.cpp @@ -24,9 +24,6 @@ #include "serene/exprs/symbol.h" #include "serene/namespace.h" -#include -#include -#include #include #include #include @@ -34,10 +31,14 @@ #include #include #include -#include #include #include #include + +#include +#include +#include +#include #include namespace serene { @@ -89,9 +90,9 @@ void Reader::advanceByOne() { void Reader::advance(bool skipWhitespace) { if (skipWhitespace) { for (;;) { - auto next = currentChar + 1; + const auto *next = currentChar + 1; - if (!isspace(*next)) { + if (isspace(*next) == 0) { return; } @@ -108,8 +109,8 @@ const char *Reader::nextChar(bool skipWhitespace, unsigned count) { return currentChar + count; } - auto c = currentChar + 1; - while (isspace(*c)) { + const auto *c = currentChar + 1; + while (isspace(*c) != 0) { c++; }; @@ -148,10 +149,7 @@ bool Reader::isValidForIdentifier(char c) { return true; } - if (std::isalnum(c)) { - return true; - } - return false; + return std::isalnum(c) != 0; } /// Reads a number, @@ -162,12 +160,12 @@ exprs::Node Reader::readNumber(bool neg) { bool floatNum = false; bool empty = false; - auto c = nextChar(); + const auto *c = nextChar(); advance(); LocationRange loc(getCurrentLocation()); - if (!isdigit(*c)) { + if (isdigit(*c) == 0) { ctx.diagEngine->emitSyntaxError(loc, errors::InvalidDigitForNumber); exit(1); } @@ -177,8 +175,8 @@ exprs::Node Reader::readNumber(bool neg) { c = nextChar(false); empty = false; - if (isdigit(*c) || *c == '.') { - if (*c == '.' && floatNum == true) { + if ((isdigit(*c) != 0) || *c == '.') { + if (*c == '.' && floatNum) { loc = LocationRange(getCurrentLocation()); ctx.diagEngine->emitSyntaxError(loc, errors::TwoFloatPoints); exit(1); @@ -194,7 +192,7 @@ exprs::Node Reader::readNumber(bool neg) { break; } - if ((std::isalpha(*c) && !empty) || empty) { + if (((std::isalpha(*c) != 0) && !empty) || empty) { advance(); loc.start = getCurrentLocation(); ctx.diagEngine->emitSyntaxError(loc, errors::InvalidDigitForNumber); @@ -210,9 +208,10 @@ exprs::Node Reader::readNumber(bool neg) { exprs::Node Reader::readSymbol() { READER_LOG("Reading a symbol..."); LocationRange loc; - auto c = nextChar(); + const auto *c = nextChar(); - if (!this->isValidForIdentifier(*c) || isEndOfBuffer(c) || isspace(*c)) { + if (!this->isValidForIdentifier(*c) || isEndOfBuffer(c) || + (isspace(*c) != 0)) { advance(); loc = LocationRange(getCurrentLocation()); std::string msg; @@ -227,19 +226,19 @@ exprs::Node Reader::readSymbol() { } if (*c == '-') { - auto next = nextChar(false, 2); - if (isdigit(*next)) { + const auto *next = nextChar(false, 2); + if (isdigit(*next) != 0) { // Swallow the - advance(); return readNumber(true); } } - if (isdigit(*c)) { + if (isdigit(*c) != 0) { return readNumber(false); } - std::string sym(""); + std::string sym; advance(); for (;;) { @@ -247,7 +246,7 @@ exprs::Node Reader::readSymbol() { c = nextChar(); if (!isEndOfBuffer(c) && - ((!(isspace(*c)) && this->isValidForIdentifier(*c)))) { + ((((isspace(*c)) == 0) && this->isValidForIdentifier(*c)))) { advance(); continue; } @@ -262,7 +261,7 @@ exprs::Node Reader::readSymbol() { exprs::Node Reader::readList() { READER_LOG("Reading a list..."); - auto c = nextChar(); + const auto *c = nextChar(); advance(); auto list = exprs::makeAndCast(getCurrentLocation()); @@ -273,7 +272,7 @@ exprs::Node Reader::readList() { bool list_terminated = false; do { - auto c = nextChar(true); + const auto *c = nextChar(true); if (isEndOfBuffer(c)) { advance(true); @@ -304,7 +303,7 @@ exprs::Node Reader::readList() { /// Reads an expression by dispatching to the proper reader function. exprs::Node Reader::readExpr() { - auto c = nextChar(true); + const auto *c = nextChar(true); READER_LOG("Read char at `readExpr`: " << *c); @@ -330,7 +329,7 @@ exprs::Node Reader::readExpr() { Result Reader::read() { for (size_t current_pos = 0; current_pos < buf.size();) { - auto c = nextChar(true); + const auto *c = nextChar(true); if (isEndOfBuffer(c)) { break;