Modified: trunk/Tools/WebGPUShadingLanguageRI/Checker.js (236448 => 236449)
--- trunk/Tools/WebGPUShadingLanguageRI/Checker.js 2018-09-25 01:13:26 UTC (rev 236448)
+++ trunk/Tools/WebGPUShadingLanguageRI/Checker.js 2018-09-25 01:16:15 UTC (rev 236449)
@@ -688,7 +688,6 @@
throw new Error("Ternary _expression_ else has no type: " + node.elseExpression);
if (!bodyType.equalsWithCommit(elseType))
throw new WTypeError("Body and else clause of ternary statement don't have the same type: " + node);
- node.isLValue = node.bodyExpression.isLValue && node.elseExpression.isLValue;
return bodyType;
}
Modified: trunk/Tools/WebGPUShadingLanguageRI/NormalUsePropertyResolver.js (236448 => 236449)
--- trunk/Tools/WebGPUShadingLanguageRI/NormalUsePropertyResolver.js 2018-09-25 01:13:26 UTC (rev 236448)
+++ trunk/Tools/WebGPUShadingLanguageRI/NormalUsePropertyResolver.js 2018-09-25 01:16:15 UTC (rev 236449)
@@ -34,12 +34,5 @@
{
return super.visitIndexExpression(node).rewriteAfterCloning();
}
-
- visitTernaryExpression(node)
- {
- let result = super.visitTernaryExpression(node);
- result.isLValue = node.isLValue;
- return result;
- }
}
Modified: trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js (236448 => 236449)
--- trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js 2018-09-25 01:13:26 UTC (rev 236448)
+++ trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js 2018-09-25 01:16:15 UTC (rev 236449)
@@ -167,9 +167,7 @@
visitTernaryExpression(node)
{
- let result = new TernaryExpression(node.origin, node.predicate.visit(this), node.bodyExpression.visit(this), node.elseExpression.visit(this));
- result.isLValue = node.isLValue;
- return result;
+ return new TernaryExpression(node.origin, node.predicate.visit(this), node.bodyExpression.visit(this), node.elseExpression.visit(this));
}
_handlePropertyAccessExpression(result, node)
Modified: trunk/Tools/WebGPUShadingLanguageRI/TernaryExpression.js (236448 => 236449)
--- trunk/Tools/WebGPUShadingLanguageRI/TernaryExpression.js 2018-09-25 01:13:26 UTC (rev 236448)
+++ trunk/Tools/WebGPUShadingLanguageRI/TernaryExpression.js 2018-09-25 01:16:15 UTC (rev 236449)
@@ -31,15 +31,14 @@
this._predicate = predicate;
this._bodyExpression = bodyExpression;
this._elseExpression = elseExpression;
- this._isLValue = null; // We use null to indicate that we don't know yet.
}
get predicate() { return this._predicate; }
get bodyExpression() { return this._bodyExpression; }
get elseExpression() { return this._elseExpression; }
- get isLValue() { return this._isLValue; }
- set isLValue(value) { this._isLValue = value; }
+ // Like in C, it is not never possible to use a ternary _expression_ as an lValue.
+
toString()
{
return "(" + this.predicate + ") ? (" + this.bodyExpression + ") : (" + this.elseExpression + ")";
Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (236448 => 236449)
--- trunk/Tools/WebGPUShadingLanguageRI/Test.js 2018-09-25 01:13:26 UTC (rev 236448)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js 2018-09-25 01:16:15 UTC (rev 236449)
@@ -333,13 +333,6 @@
{
return x < 3 ? 4 : 5;
}
- test int bar(int x)
- {
- int y = 1;
- int z = 2;
- (x < 3 ? y : z) = 7;
- return y;
- }
test int baz(int x)
{
return x < 10 ? 11 : x < 12 ? 14 : 15;
@@ -351,8 +344,6 @@
`);
checkInt(program, callFunction(program, "foo", [makeInt(program, 767)]), 5);
checkInt(program, callFunction(program, "foo", [makeInt(program, 2)]), 4);
- checkInt(program, callFunction(program, "bar", [makeInt(program, 2)]), 7);
- checkInt(program, callFunction(program, "bar", [makeInt(program, 8)]), 1);
checkInt(program, callFunction(program, "baz", [makeInt(program, 8)]), 11);
checkInt(program, callFunction(program, "baz", [makeInt(program, 9)]), 11);
checkInt(program, callFunction(program, "baz", [makeInt(program, 10)]), 14);
@@ -374,6 +365,39 @@
int foo()
{
int x;
+ int y;
+ (0 < 1 ? x : y) = 42;
+ return x;
+ }
+ `),
+ (e) => e instanceof WTypeError && e.message.indexOf("not an LValue") != -1);
+ checkFail(
+ () => doPrep(`
+ int foo()
+ {
+ int x;
+ int y;
+ thread int* z = &(0 < 1 ? x : y);
+ return *z;
+ }
+ `),
+ (e) => e instanceof WTypeError && e.message.indexOf("not an LValue") != -1);
+ checkFail(
+ () => doPrep(`
+ int foo()
+ {
+ int x;
+ int y;
+ thread int[] z = @(0 < 1 ? x : y);
+ return *z;
+ }
+ `),
+ (e) => e instanceof WTypeError && e.message.indexOf("not an LValue") != -1);
+ checkFail(
+ () => doPrep(`
+ int foo()
+ {
+ int x;
float y;
return 4 < 5 ? x : y;
}
@@ -389,29 +413,6 @@
(e) => e instanceof WTypeError);
}
-tests.ternaryExpressionIsLValue = function() {
- function ternaryExpressionIsLValue(node)
- {
- let isLValue;
- class TernaryExpressionVisitor extends Visitor {
- visitTernaryExpression(node)
- {
- isLValue = node.isLValue;
- }
- }
- node.visit(new TernaryExpressionVisitor());
- return isLValue;
- }
-
- let program = doPrep(`int foo() { return 0 < 1 ? 0 : 1; }`);
- if (ternaryExpressionIsLValue(program))
- throw new Error(`r-value ternary _expression_ incorrectly parsed as l-value`);
-
- program = doPrep(`void foo() { int x; int y; (0 < 1 ? x : y) = 1; }`);
- if (!ternaryExpressionIsLValue(program))
- throw new Error(`l-value ternary _expression_ incorrectly parsed as r-value`);
-}
-
tests.literalBool = function() {
let program = doPrep("test bool foo() { return true; }");
checkBool(program, callFunction(program, "foo", []), true);