summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-s-parser.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-05-08 14:05:22 -0700
committerGitHub <noreply@github.com>2017-05-08 14:05:22 -0700
commitb856925f6c25df22a0901d8f9e24e4247b4acc18 (patch)
treeebd204680c69f4309f2ef613ccb2cd627664ccf5 /src/wasm/wasm-s-parser.cpp
parentc72d10b7ffbc3083cf52de001407f89935422112 (diff)
downloadbinaryen-b856925f6c25df22a0901d8f9e24e4247b4acc18.tar.gz
binaryen-b856925f6c25df22a0901d8f9e24e4247b4acc18.tar.bz2
binaryen-b856925f6c25df22a0901d8f9e24e4247b4acc18.zip
text format parsing fixes (#1002)
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r--src/wasm/wasm-s-parser.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 2290a4972..69509afec 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -48,17 +48,18 @@ Element::List& Element::list() {
}
Element* Element::operator[](unsigned i) {
+ if (!isList()) throw ParseException("expected list", line, col);
if (i >= list().size()) throw ParseException("expected more elements in list", line, col);
return list()[i];
}
IString Element::str() {
- element_assert(!isList_);
+ if (!isStr()) throw ParseException("expected string", line, col);
return str_;
}
const char* Element::c_str() {
- element_assert(!isList_);
+ if (!isStr()) throw ParseException("expected string", line, col);
return str_.str;
}
@@ -207,7 +208,8 @@ Element* SExpressionParser::parseString() {
}
SExpressionWasmBuilder::SExpressionWasmBuilder(Module& wasm, Element& module, Name* moduleName) : wasm(wasm), allocator(wasm.allocator), globalCounter(0) {
- assert(module[0]->str() == MODULE);
+ if (module.size() == 0) throw ParseException("empty toplevel, expected module");
+ if (module[0]->str() != MODULE) throw ParseException("toplevel does not start with module");
if (module.size() == 1) return;
Index i = 1;
if (module[i]->dollared()) {
@@ -579,7 +581,6 @@ WasmType SExpressionWasmBuilder::stringToWasmType(const char* str, bool allowErr
}
Expression* SExpressionWasmBuilder::parseExpression(Element& s) {
- assert(s.isList());
IString id = s[0]->str();
const char *str = id.str;
const char *dot = strchr(str, '.');