Add "if" statements to WSL
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Sep 2017 02:57:23 +0000 (02:57 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Sep 2017 02:57:23 +0000 (02:57 +0000)
commitc78ae9b6f2b53039170acae77dcfd0f9b5e5cdad
tree74dac5997931a767da0ecfd07854671ecca2814e
parent84b09d6b813987e38ff6b3cc1ddd13364eb043cc
Add "if" statements to WSL
https://bugs.webkit.org/show_bug.cgi?id=176294

Reviewed by Filip Pizlo.

Fairly straightforward implementation. ReturnChecker only returns true iff there is an else block,
and both the if body and the else body recursively return true.

In order to accept both syntaxes:
if (foo)
    bar;
... and ...
if (foo) {
    bar;
}
This patch lets parseStatement() call parseBlock(). This means that the following is valid:
int x = 7;
if (foo) {
    int x = 8;
    // x is 8 here!
}
// x is 7 here!

This production means that these blocks don't require "if" statements, so you can just have:
int foo() {
   int x = 7;
   {
       int x = 8;
       // x is 8 here!
   }
   // x is 7 here!
}

However, this patch doesn't touch the following use-case:
if (int x = bar()) {
    // use x here
}

* WebGPUShadingLanguageRI/All.js:
* WebGPUShadingLanguageRI/Checker.js:
* WebGPUShadingLanguageRI/Evaluator.js:
(Evaluator.prototype.visitIfStatement):
* WebGPUShadingLanguageRI/IfStatement.js: Copied from Tools/WebGPUShadingLanguageRI/TypeDef.js.
(IfStatement):
(IfStatement.prototype.get origin):
(IfStatement.prototype.get conditional):
(IfStatement.prototype.get body):
(IfStatement.prototype.get elseBody):
(IfStatement.prototype.toString):
* WebGPUShadingLanguageRI/NameResolver.js:
(NameResolver.prototype.visitIfStatement):
* WebGPUShadingLanguageRI/Parse.js:
(parseTypeParameters):
(parseIfStatement):
(parseStatement):
* WebGPUShadingLanguageRI/ReturnChecker.js:
(ReturnChecker.prototype.visitIfStatement):
* WebGPUShadingLanguageRI/Rewriter.js:
(Rewriter.prototype.visitIfStatement):
(Rewriter):
* WebGPUShadingLanguageRI/Test.html:
* WebGPUShadingLanguageRI/Test.js:
(TEST_variableShadowing):
(TEST_ifStatement):
(TEST_ifElseStatement):
(TEST_ifElseIfStatement):
(TEST_ifElseIfElseStatement):
(TEST_returnIf):
(TEST_protocolMonoPolySigDoublePolyDefExplicit): Deleted.
* WebGPUShadingLanguageRI/TypeDef.js:
(TypeDef.prototype.toString):
(TypeDef):
* WebGPUShadingLanguageRI/Visitor.js:
(Visitor.prototype.visitIfStatement):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221776 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
Tools/ChangeLog
Tools/WebGPUShadingLanguageRI/All.js
Tools/WebGPUShadingLanguageRI/Checker.js
Tools/WebGPUShadingLanguageRI/Evaluator.js
Tools/WebGPUShadingLanguageRI/IfStatement.js [new file with mode: 0644]
Tools/WebGPUShadingLanguageRI/NameResolver.js
Tools/WebGPUShadingLanguageRI/Parse.js
Tools/WebGPUShadingLanguageRI/ReturnChecker.js
Tools/WebGPUShadingLanguageRI/Rewriter.js
Tools/WebGPUShadingLanguageRI/Test.html
Tools/WebGPUShadingLanguageRI/Test.js
Tools/WebGPUShadingLanguageRI/TypeDef.js
Tools/WebGPUShadingLanguageRI/Visitor.js