From 1bdc8aa9e9247ec07c7ec3f7f722557d908bd61d Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 17 Oct 2021 11:19:12 +0100 Subject: [PATCH] Fix context's tidy issues --- include/serene/context.h | 4 ++-- src/libserene/context.cpp | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/serene/context.h b/include/serene/context.h index 3b778e8..2e3a7e1 100644 --- a/include/serene/context.h +++ b/include/serene/context.h @@ -95,7 +95,7 @@ public: /// Insert the given `ns` into the context. The Context object is /// the owner of all the namespaces. The `ns` will overwrite any /// namespace with the same name. - void insertNS(std::shared_ptr ns); + void insertNS(const std::shared_ptr &ns); /// Sets the n ame of the current namespace in the context and return /// a boolean indicating the status of this operation. The operation @@ -133,7 +133,7 @@ public: CompilationPhase getTargetPhase() { return targetPhase; }; int getOptimizatioLevel(); - NSPtr readNamespace(std::string name); + NSPtr readNamespace(const std::string &name); NSPtr readNamespace(std::string name, reader::LocationRange loc); private: diff --git a/src/libserene/context.cpp b/src/libserene/context.cpp index 4e89f1a..620fa2e 100644 --- a/src/libserene/context.cpp +++ b/src/libserene/context.cpp @@ -24,15 +24,16 @@ #include "serene/slir/generatable.h" #include +#include namespace serene { -void SereneContext::insertNS(std::shared_ptr ns) { +void SereneContext::insertNS(const std::shared_ptr &ns) { namespaces[ns->name] = ns; }; std::shared_ptr SereneContext::getNS(llvm::StringRef ns_name) { - if (namespaces.count(ns_name.str())) { + if (namespaces.count(ns_name.str()) != 0) { return namespaces[ns_name.str()]; } @@ -40,7 +41,7 @@ std::shared_ptr SereneContext::getNS(llvm::StringRef ns_name) { }; bool SereneContext::setCurrentNS(llvm::StringRef ns_name) { - if (namespaces.count(ns_name.str())) { + if (namespaces.count(ns_name.str()) != 0) { this->current_ns = ns_name; return true; } @@ -49,7 +50,7 @@ bool SereneContext::setCurrentNS(llvm::StringRef ns_name) { }; Namespace &SereneContext::getCurrentNS() { - if (this->current_ns.empty() || !namespaces.count(this->current_ns)) { + if (this->current_ns.empty() || (namespaces.count(this->current_ns) == 0)) { panic(*this, llvm::formatv("getCurrentNS: Namespace '{0}' does not exist", this->current_ns) .str()); @@ -88,7 +89,7 @@ int SereneContext::getOptimizatioLevel() { return 3; } -NSPtr SereneContext::readNamespace(std::string name) { +NSPtr SereneContext::readNamespace(const std::string &name) { auto loc = reader::LocationRange::UnknownLocation(name); return readNamespace(name, loc); @@ -96,7 +97,7 @@ NSPtr SereneContext::readNamespace(std::string name) { NSPtr SereneContext::readNamespace(std::string name, reader::LocationRange loc) { - return sourceManager.readNamespace(*this, name, loc); + return sourceManager.readNamespace(*this, std::move(name), loc); } std::unique_ptr makeSereneContext() {