diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-06-14 18:46:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-14 18:46:42 -0700 |
commit | 96923f19eb0e7233fd1c7f438d3ebcf97690fd53 (patch) | |
tree | ab20ee27bdebccf367342119e86fc6aab7efab40 /src | |
parent | ee5e48d5c1408dfb291c4b9bfa4804dbe5ba1520 (diff) | |
download | binaryen-96923f19eb0e7233fd1c7f438d3ebcf97690fd53.tar.gz binaryen-96923f19eb0e7233fd1c7f438d3ebcf97690fd53.tar.bz2 binaryen-96923f19eb0e7233fd1c7f438d3ebcf97690fd53.zip |
[Parser][NFC] Small code cleanups (#4729)
Apply cleanups suggested by aheejin in post-merge code review of previous
parser PRs.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-io.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wat-lexer.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wat-parser.cpp | 12 | ||||
-rw-r--r-- | src/wat-lexer.h | 16 | ||||
-rw-r--r-- | src/wat-parser.h | 3 |
5 files changed, 19 insertions, 16 deletions
diff --git a/src/wasm/wasm-io.cpp b/src/wasm/wasm-io.cpp index 55892975b..90f267e9b 100644 --- a/src/wasm/wasm-io.cpp +++ b/src/wasm/wasm-io.cpp @@ -24,12 +24,12 @@ // binary. // +#include "wasm-io.h" #include "support/debug.h" #include "wasm-binary.h" #include "wasm-s-parser.h" #include "wat-parser.h" -#include "wasm-io.h" namespace wasm { diff --git a/src/wasm/wat-lexer.cpp b/src/wasm/wat-lexer.cpp index 0d1dc2794..c7959295c 100644 --- a/src/wasm/wat-lexer.cpp +++ b/src/wasm/wat-lexer.cpp @@ -942,7 +942,7 @@ void Lexer::lexToken() { curr = {tok}; } -TextPos Lexer::position(const char* c) { +TextPos Lexer::position(const char* c) const { assert(size_t(c - buffer.data()) < buffer.size()); TextPos pos{1, 0}; for (const char* p = buffer.data(); p != c; ++p) { diff --git a/src/wasm/wat-parser.cpp b/src/wasm/wat-parser.cpp index aafb66019..caeccfd76 100644 --- a/src/wasm/wat-parser.cpp +++ b/src/wasm/wat-parser.cpp @@ -32,11 +32,11 @@ // definitions. This phase establishes the indices and names of each module // element so that subsequent phases can look them up. // -// The second phase, not yet implemented, parses type definitions to construct -// the types used in the module. This has to be its own phase because we have no -// way to refer to a type before it has been built along with all the other -// types, unlike for other module elements that can be referred to by name -// before their definitions have been parsed. +// The second phase parses type definitions to construct the types used in the +// module. This has to be its own phase because we have no way to refer to a +// type before it has been built along with all the other types, unlike for +// other module elements that can be referred to by name before their +// definitions have been parsed. // // The third phase, not yet implemented, further parses and constructs types // implicitly defined by type uses in functions, blocks, and call_indirect @@ -89,7 +89,7 @@ struct ParseInput { lexer.setIndex(index); } - bool empty() { return lexer == lexer.end(); } + bool empty() { return lexer.empty(); } std::optional<Token> peek() { if (!empty()) { diff --git a/src/wat-lexer.h b/src/wat-lexer.h index 30aa1e036..b41cbd8c1 100644 --- a/src/wat-lexer.h +++ b/src/wat-lexer.h @@ -166,7 +166,7 @@ public: Lexer(std::string_view buffer) : buffer(buffer) { setIndex(0); } - size_t getIndex() { return index; } + size_t getIndex() const { return index; } void setIndex(size_t i) { index = i; @@ -206,12 +206,16 @@ public: Lexer begin() { return *this; } - Lexer end() { return Lexer(); } + Lexer end() const { return Lexer(); } - TextPos position(const char* c); - TextPos position(size_t i) { return position(buffer.data() + i); } - TextPos position(std::string_view span) { return position(span.data()); } - TextPos position(Token tok) { return position(tok.span); } + bool empty() const { return *this == end(); } + + TextPos position(const char* c) const; + TextPos position(size_t i) const { return position(buffer.data() + i); } + TextPos position(std::string_view span) const { + return position(span.data()); + } + TextPos position(Token tok) const { return position(tok.span); } private: void skipSpace(); diff --git a/src/wat-parser.h b/src/wat-parser.h index 4bb9b62c8..7f92de9e4 100644 --- a/src/wat-parser.h +++ b/src/wat-parser.h @@ -17,7 +17,6 @@ #ifndef wasm_wat_parser_h #define wasm_wat_parser_h -#include <optional> #include <string_view> #include "wasm.h" @@ -37,7 +36,7 @@ template<typename T = Ok> struct Result { Result(Result<T>& other) = default; Result(const Err& e) : val(std::in_place_type<Err>, e) {} - Result(Err&& e) : val(std::in_place_type<Err>, e) {} + Result(Err&& e) : val(std::in_place_type<Err>, std::move(e)) {} template<typename U = T> Result(U&& u) : val(std::in_place_type<T>, std::forward<U>(u)) {} |