diff --git a/include/serene/context.h b/include/serene/context.h index e42302b..f3f238c 100644 --- a/include/serene/context.h +++ b/include/serene/context.h @@ -42,7 +42,7 @@ namespace serene { namespace reader { class LocationRange; -} +} // namespace reader namespace exprs { class Expression; diff --git a/include/serene/errors/constants.h b/include/serene/errors/constants.h index d38cbcb..495a170 100644 --- a/include/serene/errors/constants.h +++ b/include/serene/errors/constants.h @@ -20,8 +20,10 @@ #define SERENE_ERRORS_CONSTANTS_H #include + #include #include +#include namespace serene { namespace errors { @@ -50,7 +52,8 @@ struct ErrorVariant { std::string longDescription; ErrorVariant(ErrID id, std::string desc, std::string longDesc) - : id(id), description(desc), longDescription(longDesc){}; + : id(id), description(std::move(desc)), + longDescription(std::move(longDesc)){}; std::string getErrId() { return llvm::formatv("E{0:d}", id); }; }; diff --git a/include/serene/errors/traits.h b/include/serene/errors/traits.h index 359ad57..ae5b979 100644 --- a/include/serene/errors/traits.h +++ b/include/serene/errors/traits.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef ERRORS_TRAITS_H -#define ERRORS_TRAITS_H +#ifndef SERENE_ERRORS_TRAITS_H +#define SERENE_ERRORS_TRAITS_H #include "serene/context.h" #include "serene/errors/constants.h" diff --git a/include/serene/exprs/call.h b/include/serene/exprs/call.h index 06da372..d933c2c 100644 --- a/include/serene/exprs/call.h +++ b/include/serene/exprs/call.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EXPRS_CALL_H -#define EXPRS_CALL_H +#ifndef SERENE_EXPRS_CALL_H +#define SERENE_EXPRS_CALL_H #include "serene/context.h" #include "serene/errors/error.h" @@ -26,6 +26,7 @@ #include #include + #include #include @@ -49,8 +50,9 @@ public: ExprType getType() const override; std::string toString() const override; - MaybeNode analyze(SereneContext &) override; - void generateIR(serene::Namespace &, mlir::ModuleOp &) override{}; + MaybeNode analyze(SereneContext & /*ctx*/) override; + void generateIR(serene::Namespace & /*ns*/, + mlir::ModuleOp & /*m*/) override{}; static bool classof(const Expression *e); diff --git a/include/serene/exprs/def.h b/include/serene/exprs/def.h index 01f8752..b3c7f98 100644 --- a/include/serene/exprs/def.h +++ b/include/serene/exprs/def.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EXPRS_DEF_H -#define EXPRS_DEF_H +#ifndef SERENE_EXPRS_DEF_H +#define SERENE_EXPRS_DEF_H #include "serene/context.h" #include "serene/errors/error.h" @@ -25,6 +25,7 @@ #include #include + #include #include @@ -48,8 +49,8 @@ public: ExprType getType() const override; std::string toString() const override; - MaybeNode analyze(SereneContext &) override; - void generateIR(serene::Namespace &, mlir::ModuleOp &) override; + MaybeNode analyze(SereneContext & /*ctx*/) override; + void generateIR(serene::Namespace & /*ns*/, mlir::ModuleOp & /*m*/) override; static bool classof(const Expression *e); diff --git a/include/serene/exprs/expression.h b/include/serene/exprs/expression.h index 52fea56..b50627b 100644 --- a/include/serene/exprs/expression.h +++ b/include/serene/exprs/expression.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EXPRS_EXPRESSION_H -#define EXPRS_EXPRESSION_H +#ifndef SERENE_EXPRS_EXPRESSION_H +#define SERENE_EXPRS_EXPRESSION_H #include "serene/context.h" #include "serene/errors/error.h" @@ -25,9 +25,10 @@ #include "serene/reader/location.h" #include "serene/utils.h" -#include #include +#include + namespace serene { /// Contains all the builtin AST expressions including those which do not appear diff --git a/include/serene/exprs/fn.h b/include/serene/exprs/fn.h index d8147bc..b12b272 100644 --- a/include/serene/exprs/fn.h +++ b/include/serene/exprs/fn.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EXPRS_FN_H -#define EXPRS_FN_H +#ifndef SERENE_EXPRS_FN_H +#define SERENE_EXPRS_FN_H #include "serene/context.h" #include "serene/errors/error.h" @@ -27,6 +27,7 @@ #include #include + #include #include @@ -52,8 +53,8 @@ public: ExprType getType() const override; std::string toString() const override; - MaybeNode analyze(SereneContext &) override; - void generateIR(serene::Namespace &, mlir::ModuleOp &) override; + MaybeNode analyze(SereneContext & /*ctx*/) override; + void generateIR(serene::Namespace & /*ns*/, mlir::ModuleOp & /*m*/) override; static bool classof(const Expression *e); diff --git a/include/serene/exprs/list.h b/include/serene/exprs/list.h index 2df9812..a3182b2 100644 --- a/include/serene/exprs/list.h +++ b/include/serene/exprs/list.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EXPRS_LIST_H -#define EXPRS_LIST_H +#ifndef SERENE_EXPRS_LIST_H +#define SERENE_EXPRS_LIST_H #include "serene/context.h" #include "serene/exprs/expression.h" diff --git a/include/serene/exprs/number.h b/include/serene/exprs/number.h index 07e2e9a..cae8d77 100644 --- a/include/serene/exprs/number.h +++ b/include/serene/exprs/number.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EXPRS_NUMBER_H -#define EXPRS_NUMBER_H +#ifndef SERENE_EXPRS_NUMBER_H +#define SERENE_EXPRS_NUMBER_H #include "serene/context.h" #include "serene/exprs/expression.h" @@ -48,7 +48,7 @@ struct Number : public Expression { std::string toString() const override; MaybeNode analyze(SereneContext &ctx) override; - void generateIR(serene::Namespace &, mlir::ModuleOp &) override; + void generateIR(serene::Namespace & /*ns*/, mlir::ModuleOp & /*m*/) override; // TODO: This is horrible, we need to fix it after the mvp int toI64() const; diff --git a/include/serene/exprs/symbol.h b/include/serene/exprs/symbol.h index 485e156..c937a6d 100644 --- a/include/serene/exprs/symbol.h +++ b/include/serene/exprs/symbol.h @@ -16,13 +16,14 @@ * along with this program. If not, see . */ -#ifndef EXPRS_SYMBOL_H -#define EXPRS_SYMBOL_H +#ifndef SERENE_EXPRS_SYMBOL_H +#define SERENE_EXPRS_SYMBOL_H #include "serene/context.h" #include "serene/exprs/expression.h" #include + #include namespace serene { @@ -44,8 +45,9 @@ public: ExprType getType() const override; std::string toString() const override; - MaybeNode analyze(SereneContext &) override; - void generateIR(serene::Namespace &, mlir::ModuleOp &) override{}; + MaybeNode analyze(SereneContext & /*ctx*/) override; + void generateIR(serene::Namespace & /*ns*/, + mlir::ModuleOp & /*m*/) override{}; ~Symbol() = default; diff --git a/include/serene/exprs/traits.h b/include/serene/exprs/traits.h index 81f99dc..6c933d8 100644 --- a/include/serene/exprs/traits.h +++ b/include/serene/exprs/traits.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EXPRS_TRAITS_H -#define EXPRS_TRAITS_H +#ifndef SERENE_EXPRS_TRAITS_H +#define SERENE_EXPRS_TRAITS_H #include "serene/context.h" #include "serene/reader/location.h" diff --git a/include/serene/llvm/IR/Value.h b/include/serene/llvm/IR/Value.h index 75d2a72..fac0004 100644 --- a/include/serene/llvm/IR/Value.h +++ b/include/serene/llvm/IR/Value.h @@ -1,5 +1,5 @@ -#ifndef SERENE_LLVM_VALUE_H -#define SERENE_LLVM_VALUE_H +#ifndef LLVM_IR_VALUE_H +#define LLVM_IR_VALUE_H #pragma clang diagnostic ignored "-Wunused-parameter" #include diff --git a/include/serene/llvm/patches.h b/include/serene/llvm/patches.h index c116705..7f2226e 100644 --- a/include/serene/llvm/patches.h +++ b/include/serene/llvm/patches.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef SERENE_LLVM_PATCHES_H -#define SERENE_LLVM_PATCHES_H +#ifndef LLVM_PATCHES_H +#define LLVM_PATCHES_H #include @@ -34,17 +34,19 @@ struct DenseMapInfo { return "0TOMBED"; } - static unsigned getHashValue(std::string Val) { + static unsigned getHashValue(const std::string &Val) { assert(Val != getEmptyKey() && "Cannot hash the empty key!"); assert(Val != getTombstoneKey() && "Cannot hash the tombstone key!"); return (unsigned)(llvm::hash_value(Val)); } - static bool isEqual(std::string LHS, std::string RHS) { - if (RHS == getEmptyKey()) + static bool isEqual(const std::string &LHS, const std::string &RHS) { + if (RHS == getEmptyKey()) { return LHS == getEmptyKey(); - if (RHS == getTombstoneKey()) + } + if (RHS == getTombstoneKey()) { return LHS == getTombstoneKey(); + } return LHS == RHS; } }; diff --git a/include/serene/namespace.h b/include/serene/namespace.h index f0dcd76..153aa53 100644 --- a/include/serene/namespace.h +++ b/include/serene/namespace.h @@ -34,17 +34,18 @@ #include "serene/traits.h" #include "serene/utils.h" -#include #include #include #include #include -#include #include #include #include #include #include + +#include +#include #include #define NAMESPACE_LOG(...) \ diff --git a/include/serene/reader/location.h b/include/serene/reader/location.h index 227d5c5..636d464 100644 --- a/include/serene/reader/location.h +++ b/include/serene/reader/location.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef SERENE_LOCATION_H -#define SERENE_LOCATION_H +#ifndef SERENE_READER_LOCATION_H +#define SERENE_READER_LOCATION_H #include #include @@ -77,7 +77,7 @@ public: LocationRange(Location _start, Location _end) : start(_start), end(_end){}; // LocationRange(const LocationRange &); - bool isKnownLocation() { return start.knownLocation; }; + bool isKnownLocation() const { return start.knownLocation; }; static LocationRange UnknownLocation(llvm::StringRef ns) { return LocationRange(Location::UnknownLocation(ns)); diff --git a/include/serene/reader/reader.h b/include/serene/reader/reader.h index b62b63f..c0b2053 100644 --- a/include/serene/reader/reader.h +++ b/include/serene/reader/reader.h @@ -31,8 +31,8 @@ */ -#ifndef READER_H -#define READER_H +#ifndef SERENE_READER_READER_H +#define SERENE_READER_READER_H #include "serene/errors.h" #include "serene/exprs/expression.h" @@ -121,10 +121,10 @@ public: /// Parses the given `input` string and returns a `Result` /// which may contains an AST or an `llvm::Error` -Result read(SereneContext &ctx, const llvm::StringRef input, +Result read(SereneContext &ctx, llvm::StringRef input, llvm::StringRef ns, llvm::Optional filename); -Result read(SereneContext &ctx, const llvm::MemoryBufferRef input, +Result read(SereneContext &ctx, llvm::MemoryBufferRef input, llvm::StringRef ns, llvm::Optional filename); } // namespace serene::reader diff --git a/include/serene/reader/semantics.h b/include/serene/reader/semantics.h index 72fc253..843788e 100644 --- a/include/serene/reader/semantics.h +++ b/include/serene/reader/semantics.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef READER_SEMANTICS_H -#define READER_SEMANTICS_H +#ifndef SERENE_READER_SEMANTICS_H +#define SERENE_READER_SEMANTICS_H #include "serene/context.h" #include "serene/errors/error.h" diff --git a/include/serene/reader/traits.h b/include/serene/reader/traits.h index febbfd6..8fdfea9 100644 --- a/include/serene/reader/traits.h +++ b/include/serene/reader/traits.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef READER_TRAITS_H -#define READER_TRAITS_H +#ifndef SERENE_READER_TRAITS_H +#define SERENE_READER_TRAITS_H #include "serene/reader/location.h" #include "serene/traits.h" diff --git a/include/serene/slir/dialect.h b/include/serene/slir/dialect.h index 265ce04..3f8cea7 100644 --- a/include/serene/slir/dialect.h +++ b/include/serene/slir/dialect.h @@ -15,8 +15,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SERENE_SLIR_DIALECT_H_ -#define SERENE_SLIR_DIALECT_H_ +#ifndef SERENE_SLIR_DIALECT_H +#define SERENE_SLIR_DIALECT_H #include #include @@ -34,4 +34,4 @@ #include "serene/slir/ops.h.inc" -#endif // DIALECT_H_ +#endif // SERENE_SLIR_DIALECT_H diff --git a/include/serene/slir/slir.h b/include/serene/slir/slir.h index 2c95004..644e1c5 100644 --- a/include/serene/slir/slir.h +++ b/include/serene/slir/slir.h @@ -15,15 +15,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SERENE_SLIR_H -#define SERENE_SLIR_H +#ifndef SERENE_SLIR_SLIR_H +#define SERENE_SLIR_SLIR_H #include "serene/exprs/expression.h" -#include #include #include +#include + namespace serene { namespace slir { std::unique_ptr compileToLLVMIR(serene::SereneContext &ctx, diff --git a/include/serene/slir/utils.h b/include/serene/slir/utils.h index 03928b3..618dbc5 100644 --- a/include/serene/slir/utils.h +++ b/include/serene/slir/utils.h @@ -25,7 +25,7 @@ namespace serene { class Namespace; -} +} // namespace serene namespace serene::slir { diff --git a/include/serene/traits/locatable.h b/include/serene/traits/locatable.h index 2a0b9c9..7d7519a 100644 --- a/include/serene/traits/locatable.h +++ b/include/serene/traits/locatable.h @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#ifndef TRAITS_LOCATABLE_H -#define TRAITS_LOCATABLE_H +#ifndef SERENE_TRAITS_LOCATABLE_H +#define SERENE_TRAITS_LOCATABLE_H #endif diff --git a/include/serene/utils.h b/include/serene/utils.h index 76a9fb9..cd625ab 100644 --- a/include/serene/utils.h +++ b/include/serene/utils.h @@ -22,6 +22,7 @@ #include "serene/export.h" #include + #include // Sometimes we need this to make both analyzer happy @@ -92,33 +93,6 @@ public: bool ok() const { return std::holds_alternative(contents); }; operator bool() const { return ok(); } - - const T &getValueOrFail(llvm::StringRef msg, int exitCode = 1) const & { - if (ok()) { - return getValue(); - } - - llvm::errs() << msg << "\n"; - exit(exitCode); - } - - T &getValueOrFail(llvm::StringRef msg, int exitCode = 1) & { - if (ok()) { - return getValue(); - } - - llvm::errs() << msg << "\n"; - exit(exitCode); - } - - T &&getValueOrFail(llvm::StringRef msg, int exitCode = 1) && { - if (ok()) { - return std::move(getValue()); - } - - llvm::errs() << msg << "\n"; - exit(exitCode); - } }; } // namespace serene diff --git a/src/serenec/serenec.cpp b/src/serenec/serenec.cpp index 59ce935..a931b43 100644 --- a/src/serenec/serenec.cpp +++ b/src/serenec/serenec.cpp @@ -42,6 +42,7 @@ #include #include #include + #include using namespace std;