diff options
author | Ryoga <ryoga_314@yahoo.co.jp> | 2019-03-19 06:02:49 +0900 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2019-03-18 14:02:49 -0700 |
commit | e65f66425a823401783a02ba6155bee2ca216cde (patch) | |
tree | b42ef6ac3acd21f37befc09ca076a4711c00bbe8 | |
parent | 907dfb0a2527fb849c068f80b683fa05f6b3e798 (diff) | |
download | binaryen-e65f66425a823401783a02ba6155bee2ca216cde.tar.gz binaryen-e65f66425a823401783a02ba6155bee2ca216cde.tar.bz2 binaryen-e65f66425a823401783a02ba6155bee2ca216cde.zip |
Add const specifiers (#1952)
With this we can write stuff like:
const wasm::Expression* p;
const wasm::Binary* q = p->cast<wasm::Binary>();
-rw-r--r-- | src/parsing.h | 4 | ||||
-rw-r--r-- | src/wasm.h | 15 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/parsing.h b/src/parsing.h index 6eecb38f2..97fc88432 100644 --- a/src/parsing.h +++ b/src/parsing.h @@ -40,7 +40,7 @@ struct ParseException { ParseException(std::string text) : text(text), line(-1), col(-1) {} ParseException(std::string text, size_t line, size_t col) : text(text), line(line), col(col) {} - void dump(std::ostream& o) { + void dump(std::ostream& o) const { Colors::magenta(o); o << "["; Colors::red(o); @@ -63,7 +63,7 @@ struct MapParseException { MapParseException() : text("unknown parse error") {} MapParseException(std::string text) : text(text) {} - void dump(std::ostream& o) { + void dump(std::ostream& o) const { Colors::magenta(o); o << "["; Colors::red(o); diff --git a/src/wasm.h b/src/wasm.h index a4fb7e357..258ed0f35 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -54,7 +54,7 @@ struct FeatureSet { FeatureSet(uint32_t features) : features(features) {} bool isMVP() const { return features == MVP; } - bool has(Feature f) { return (features & f) == f; } + bool has(Feature f) const { return (features & f) == f; } bool hasAtomics() const { return features & Atomics; } bool hasMutableGlobals() const { return features & MutableGlobals; } bool hasTruncSat() const { return features & TruncSat; } @@ -270,7 +270,7 @@ public: void finalize() {} template<class T> - bool is() { + bool is() const { return int(_id) == int(T::SpecificId); } @@ -279,11 +279,22 @@ public: return int(_id) == int(T::SpecificId) ? (T*)this : nullptr; } + template <class T> + const T* dynCast() const { + return int(_id) == int(T::SpecificId) ? (const T*)this : nullptr; + } + template<class T> T* cast() { assert(int(_id) == int(T::SpecificId)); return (T*)this; } + + template<class T> + const T* cast() const { + assert(int(_id) == int(T::SpecificId)); + return (const T*)this; + } }; const char* getExpressionName(Expression* curr); |