diff options
Diffstat (limited to 'src/support')
-rw-r--r-- | src/support/archive.cpp | 21 | ||||
-rw-r--r-- | src/support/colors.cpp | 3 | ||||
-rw-r--r-- | src/support/command-line.cpp | 18 | ||||
-rw-r--r-- | src/support/file.cpp | 18 | ||||
-rw-r--r-- | src/support/json.h | 15 | ||||
-rw-r--r-- | src/support/path.cpp | 3 | ||||
-rw-r--r-- | src/support/small_vector.h | 6 | ||||
-rw-r--r-- | src/support/sorted_vector.h | 7 | ||||
-rw-r--r-- | src/support/threads.cpp | 3 |
9 files changed, 62 insertions, 32 deletions
diff --git a/src/support/archive.cpp b/src/support/archive.cpp index 66f9c192a..1704fd88e 100644 --- a/src/support/archive.cpp +++ b/src/support/archive.cpp @@ -46,8 +46,9 @@ std::string ArchiveMemberHeader::getName() const { } auto* end = static_cast<const uint8_t*>(memchr(fileName, endChar, sizeof(fileName))); - if (!end) + if (!end) { end = fileName + sizeof(fileName); + } return std::string((char*)(fileName), end - fileName); } @@ -81,16 +82,18 @@ Archive::Archive(Buffer& b, bool& error) return; } child_iterator end = child_end(); - if (it == end) + if (it == end) { return; // Empty archive. + } const Child* c = &*it; auto increment = [&]() { ++it; error = it.hasError(); - if (error) + if (error) { return true; + } c = &*it; return false; }; @@ -98,15 +101,17 @@ Archive::Archive(Buffer& b, bool& error) std::string name = c->getRawName(); if (name == "/") { symbolTable = c->getBuffer(); - if (increment() || it == end) + if (increment() || it == end) { return; + } name = c->getRawName(); } if (name == "//") { stringTable = c->getBuffer(); - if (increment() || it == end) + if (increment() || it == end) { return; + } setFirstRegular(*c); return; } @@ -120,8 +125,9 @@ Archive::Archive(Buffer& b, bool& error) Archive::Child::Child(const Archive* parent, const uint8_t* data, bool* error) : parent(parent), data(data) { - if (!data) + if (!data) { return; + } len = sizeof(ArchiveMemberHeader) + getHeader()->getSize(); startOfFile = sizeof(ArchiveMemberHeader); } @@ -180,8 +186,9 @@ std::string Archive::Child::getName() const { } Archive::child_iterator Archive::child_begin(bool SkipInternal) const { - if (data.size() == 0) + if (data.size() == 0) { return child_end(); + } if (SkipInternal) { child_iterator it; diff --git a/src/support/colors.cpp b/src/support/colors.cpp index d0dc5ceb3..6d06b69fd 100644 --- a/src/support/colors.cpp +++ b/src/support/colors.cpp @@ -34,8 +34,9 @@ void Colors::outputColorCode(std::ostream& stream, const char* colorCode) { (isatty(STDOUT_FILENO) && (!getenv("COLORS") || getenv("COLORS")[0] != '0')); // implicit }(); - if (has_color && !colors_disabled) + if (has_color && !colors_disabled) { stream << colorCode; + } } #elif defined(_WIN32) #include <io.h> diff --git a/src/support/command-line.cpp b/src/support/command-line.cpp index f3b9ffe25..f1b4fca4d 100644 --- a/src/support/command-line.cpp +++ b/src/support/command-line.cpp @@ -37,8 +37,9 @@ void printWrap(std::ostream& os, int leftPad, const std::string& content) { } os << nextWord; space -= nextWord.size() + 1; - if (space > 0) + if (space > 0) { os << ' '; + } nextWord.clear(); if (content[i] == '\n') { os << '\n'; @@ -56,8 +57,9 @@ Options::Options(const std::string& command, const std::string& description) Arguments::Zero, [this, command, description](Options* o, const std::string&) { std::cout << command; - if (positional != Arguments::Zero) + if (positional != Arguments::Zero) { std::cout << ' ' << positionalName; + } std::cout << "\n\n"; printWrap(std::cout, 0, description); std::cout << "\n\nOptions:\n"; @@ -109,8 +111,9 @@ void Options::parse(int argc, const char* argv[]) { size_t positionalsSeen = 0; auto dashes = [](const std::string& s) { for (size_t i = 0;; ++i) { - if (s[i] != '-') + if (s[i] != '-') { return i; + } } }; for (size_t i = 1, e = argc; i != e; ++i) { @@ -147,9 +150,11 @@ void Options::parse(int argc, const char* argv[]) { currentOption = currentOption.substr(0, equal); } Option* option = nullptr; - for (auto& o : options) - if (o.longName == currentOption || o.shortName == currentOption) + for (auto& o : options) { + if (o.longName == currentOption || o.shortName == currentOption) { option = &o; + } + } if (!option) { std::cerr << "Unknown option '" << currentOption << "'\n"; exit(EXIT_FAILURE); @@ -181,8 +186,9 @@ void Options::parse(int argc, const char* argv[]) { break; case Arguments::Optional: if (!argument.size()) { - if (i + 1 != e) + if (i + 1 != e) { argument = argv[++i]; + } } break; } diff --git a/src/support/file.cpp b/src/support/file.cpp index 3af7af44b..b4c410b5e 100644 --- a/src/support/file.cpp +++ b/src/support/file.cpp @@ -22,8 +22,9 @@ #include <limits> std::vector<char> wasm::read_stdin(Flags::DebugOption debug) { - if (debug == Flags::Debug) + if (debug == Flags::Debug) { std::cerr << "Loading stdin..." << std::endl; + } std::vector<char> input; char c; while (std::cin.get(c) && !std::cin.eof()) { @@ -36,12 +37,14 @@ template<typename T> T wasm::read_file(const std::string& filename, Flags::BinaryOption binary, Flags::DebugOption debug) { - if (debug == Flags::Debug) + if (debug == Flags::Debug) { std::cerr << "Loading '" << filename << "'..." << std::endl; + } std::ifstream infile; std::ios_base::openmode flags = std::ifstream::in; - if (binary == Flags::Binary) + if (binary == Flags::Binary) { flags |= std::ifstream::binary; + } infile.open(filename, flags); if (!infile.is_open()) { std::cerr << "Failed opening '" << filename << "'" << std::endl; @@ -58,8 +61,9 @@ T wasm::read_file(const std::string& filename, exit(EXIT_FAILURE); } T input(size_t(insize) + (binary == Flags::Binary ? 0 : 1), '\0'); - if (size_t(insize) == 0) + if (size_t(insize) == 0) { return input; + } infile.seekg(0); infile.read(&input[0], insize); if (binary == Flags::Text) { @@ -88,11 +92,13 @@ wasm::Output::Output(const std::string& filename, } std::streambuf* buffer; if (filename.size()) { - if (debug == Flags::Debug) + if (debug == Flags::Debug) { std::cerr << "Opening '" << filename << "'" << std::endl; + } auto flags = std::ofstream::out | std::ofstream::trunc; - if (binary == Flags::Binary) + if (binary == Flags::Binary) { flags |= std::ofstream::binary; + } outfile.open(filename, flags); if (!outfile.is_open()) { std::cerr << "Failed opening '" << filename << "'" << std::endl; diff --git a/src/support/json.h b/src/support/json.h index 8f2edc04d..d31fcf59b 100644 --- a/src/support/json.h +++ b/src/support/json.h @@ -224,8 +224,9 @@ struct Value { } bool operator==(const Value& other) { - if (type != other.type) + if (type != other.type) { return false; + } switch (other.type) { case String: return str == other.str; @@ -273,8 +274,9 @@ struct Value { arr->push_back(temp); curr = temp->parse(curr); skip(); - if (*curr == ']') + if (*curr == ']') { break; + } assert(*curr == ','); curr++; skip(); @@ -316,8 +318,9 @@ struct Value { curr = value->parse(curr); (*obj)[key] = value; skip(); - if (*curr == '}') + if (*curr == '}') { break; + } assert(*curr == ','); curr++; skip(); @@ -348,8 +351,9 @@ struct Value { void setSize(size_t size) { assert(isArray()); auto old = arr->size(); - if (old != size) + if (old != size) { arr->resize(size); + } if (old < size) { for (auto i = old; i < size; i++) { (*arr)[i] = Ref(new Value()); @@ -376,8 +380,9 @@ struct Value { Ref back() { assert(isArray()); - if (arr->size() == 0) + if (arr->size() == 0) { return nullptr; + } return arr->back(); } diff --git a/src/support/path.cpp b/src/support/path.cpp index 7ae68d719..e9817aca9 100644 --- a/src/support/path.cpp +++ b/src/support/path.cpp @@ -36,8 +36,9 @@ std::string getPathSeparator() { std::string getBinaryenRoot() { auto* envVar = getenv("BINARYEN_ROOT"); - if (envVar) + if (envVar) { return envVar; + } return "."; } diff --git a/src/support/small_vector.h b/src/support/small_vector.h index dd6afb526..7f00bd4a6 100644 --- a/src/support/small_vector.h +++ b/src/support/small_vector.h @@ -109,11 +109,13 @@ public: } bool operator==(const SmallVector<T, N>& other) const { - if (usedFixed != other.usedFixed) + if (usedFixed != other.usedFixed) { return false; + } for (size_t i = 0; i < usedFixed; i++) { - if (fixed[i] != other.fixed[i]) + if (fixed[i] != other.fixed[i]) { return false; + } } return flexible == other.flexible; } diff --git a/src/support/sorted_vector.h b/src/support/sorted_vector.h index e26d5e3af..872c2f8fb 100644 --- a/src/support/sorted_vector.h +++ b/src/support/sorted_vector.h @@ -61,9 +61,9 @@ struct SortedVector : public std::vector<Index> { void insert(Index x) { auto it = std::lower_bound(begin(), end(), x); - if (it == end()) + if (it == end()) { push_back(x); - else if (*it > x) { + } else if (*it > x) { Index i = it - begin(); resize(size() + 1); std::move_backward(begin() + i, begin() + size() - 1, end()); @@ -107,8 +107,9 @@ struct SortedVector : public std::vector<Index> { void dump(const char* str = nullptr) const { std::cout << "SortedVector " << (str ? str : "") << ": "; - for (auto x : *this) + for (auto x : *this) { std::cout << x << " "; + } std::cout << '\n'; } }; diff --git a/src/support/threads.cpp b/src/support/threads.cpp index 785994b4e..ab9de4175 100644 --- a/src/support/threads.cpp +++ b/src/support/threads.cpp @@ -114,8 +114,9 @@ std::mutex ThreadPool::workMutex; std::mutex ThreadPool::threadMutex; void ThreadPool::initialize(size_t num) { - if (num == 1) + if (num == 1) { return; // no multiple cores, don't create threads + } DEBUG_POOL("initialize()\n"); std::unique_lock<std::mutex> lock(threadMutex); // initial state before first resetThreadsAreReady() |