WIP: parseSwitchCase draft
authorDavid Teller <dteller@mozilla.com>
Sun, 06 Aug 2017 10:29:52 +0200
changeset 641385 803178856345aa070c3e7632360fa3a77f655fa3
parent 641384 1cda64878981601d5ed4204f9f25567a68831ce4
child 641386 f98c5a2d9182f0980d5e2767386b7342eef0b436
push id72504
push userdteller@mozilla.com
push dateSun, 06 Aug 2017 22:28:40 +0000
milestone57.0a1
WIP: parseSwitchCase MozReview-Commit-ID: Cj2D0ZzQnwE
js/src/frontend/BinSource.cpp
--- a/js/src/frontend/BinSource.cpp
+++ b/js/src/frontend/BinSource.cpp
@@ -231,24 +231,25 @@ public:
     BinParseContext(ASTReader*, GlobalSharedContext*, Directives*);
 };
 
 bool
 ASTReader::parse(char* start, char* stop, GlobalSharedContext* sc, UniquePtr<ParseNode>& out) {
     SimpleTokenReader reader(this->cx);
     reader.init(start, stop, nullptr);
 
+#if 0
     Directives directives(options().strictOption);
     GlobalSharedContext globalsc(this->cx, ScopeKind::Global,
                                  directives, options().extraWarningsOption);
     BinParseContext globalpc(this, &globalsc, /* newDirectives = */ nullptr);
     if (!globalpc.init()) {
         return false;
     }
-
+#endif // 0
 
     if (!this->parseProgram(&reader, out) || !reader.uninit()) {
         return false;
     }
 
     return true;
 }
 
@@ -2226,16 +2227,71 @@ ASTReader::parseDirectiveList(SimpleToke
             return false;
         }
     }
 
     return true;
 }
 
 bool
+ASTReader::parseSwitchCase(SimpleTokenReader* reader, UniquePtr<ParseNode>& out) {
+    if (out) {
+        return this->raiseError();
+    }
+
+    BinKind kind;
+    SimpleTokenReader::BinFields fields(this->cx);
+    SimpleTokenReader sub(this->cx);
+
+    if (!reader->taggedTuple(kind, fields, &sub)) {
+        return false;
+    }
+
+    if (kind != BinKind::switch_case) {
+        return this->raiseError();
+    }
+
+    UniquePtr<ParseNode> test; // Optional.
+    UniquePtr<ParseNode> statements; // Required.
+
+    for (auto field: fields) {
+        switch (field) {
+            case BinField::test:
+                if (!this->parseExpression(&sub, test)) {
+                    return false;
+                }
+                break;
+            case BinField::consequent:
+                if (!this->parseStatementList(&sub, statements)) {
+                    return false;
+                }
+                break;
+            default:
+                return this->raiseError();
+        }
+    }
+
+    if (!statements) {
+        return this->raiseError();
+    }
+    MOZ_ASSERT(statements->isKind(PNK_STATEMENTLIST));
+
+    UniquePtr<ParseNode> result;
+
+    result = UniquePtr<ParseNode>(new_<CaseClause>(test.get(), statements.get(), 0));
+    if (!result) {
+        return false;
+    }
+
+    Unused << test.release();
+    Unused << statements.release();
+}
+
+
+bool
 ASTReader::readNumber(SimpleTokenReader* reader, Maybe<double>& out) {
     if (out) {
         return this->raiseError();
     }
 
     return reader->readMaybeF64(&out);
 }