summaryrefslogtreecommitdiff
path: root/src/parser/input.h
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-02-05 10:24:16 -0800
committerGitHub <noreply@github.com>2024-02-05 10:24:16 -0800
commited15efeedd33bbdbadfafabc812d70a792a9a06c (patch)
tree187d8cdd828369022d406e517d92be1f85ab2443 /src/parser/input.h
parent845e0700c99d603c920d82c2312ec9b39a555c68 (diff)
downloadbinaryen-ed15efeedd33bbdbadfafabc812d70a792a9a06c.tar.gz
binaryen-ed15efeedd33bbdbadfafabc812d70a792a9a06c.tar.bz2
binaryen-ed15efeedd33bbdbadfafabc812d70a792a9a06c.zip
[Parser] Templatize lexing of integers (#6272)
Have a single implementation for lexing each of unsigned, signed, and uninterpreted integers, each generic over the bit width of the integer. This reduces duplication in the existing code and it will make it much easier to support lexing more 8- and 16-bit integers.
Diffstat (limited to 'src/parser/input.h')
-rw-r--r--src/parser/input.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/parser/input.h b/src/parser/input.h
index dbf3e4868..d4fdde1bd 100644
--- a/src/parser/input.h
+++ b/src/parser/input.h
@@ -51,11 +51,9 @@ struct ParseInput {
std::optional<uint64_t> takeOffset();
std::optional<uint32_t> takeAlign();
std::optional<uint64_t> takeU64();
- std::optional<int64_t> takeS64();
- std::optional<int64_t> takeI64();
+ std::optional<uint64_t> takeI64();
std::optional<uint32_t> takeU32();
- std::optional<int32_t> takeS32();
- std::optional<int32_t> takeI32();
+ std::optional<uint32_t> takeI32();
std::optional<uint8_t> takeU8();
std::optional<double> takeF64();
std::optional<float> takeF32();
@@ -67,6 +65,11 @@ struct ParseInput {
Index getPos();
[[nodiscard]] Err err(Index pos, std::string reason);
[[nodiscard]] Err err(std::string reason) { return err(getPos(), reason); }
+
+private:
+ template<typename T> std::optional<T> takeU();
+ template<typename T> std::optional<T> takeS();
+ template<typename T> std::optional<T> takeI();
};
#include "input-impl.h"