Changeset 235249 in webkit
- Timestamp:
- Aug 23, 2018 2:43:03 PM (6 years ago)
- Location:
- trunk/Tools
- Files:
-
- 13 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r235243 r235249 1 2018-08-23 Myles C. Maxfield <mmaxfield@apple.com> 2 3 [WSL] Ternary expressions appear to be unimplemented 4 https://bugs.webkit.org/show_bug.cgi?id=178981 5 6 Reviewed by Saam Barati. 7 8 Implement ternary statements. These can be both lvalues and rvalues. (a ? b : c ? d : e) 9 is parsed as (a ? b : (c ? d : e)). 10 11 * WebGPUShadingLanguageRI/All.js: 12 * WebGPUShadingLanguageRI/Checker.js: 13 (Checker.prototype.visitTernaryExpression): 14 * WebGPUShadingLanguageRI/Evaluator.js: 15 (Evaluator.prototype.visitTernaryExpression): 16 * WebGPUShadingLanguageRI/NormalUsePropertyResolver.js: 17 (NormalUsePropertyResolver.prototype.visitTernaryExpression): 18 (NormalUsePropertyResolver): 19 * WebGPUShadingLanguageRI/Parse.js: 20 (parsePossibleTernaryConditional): 21 * WebGPUShadingLanguageRI/PropertyResolver.js: 22 (PropertyResolver.prototype._visitRValuesWithinLValue.RValueFinder.prototype.visitTernaryExpression): 23 (PropertyResolver.prototype._visitRValuesWithinLValue.RValueFinder): 24 (PropertyResolver.prototype._visitRValuesWithinLValue): 25 * WebGPUShadingLanguageRI/Rewriter.js: 26 (Rewriter.prototype.visitTernaryExpression): 27 * WebGPUShadingLanguageRI/SPIRV.html: 28 * WebGPUShadingLanguageRI/Test.html: 29 * WebGPUShadingLanguageRI/Test.js: 30 * WebGPUShadingLanguageRI/Visitor.js: 31 (Visitor.prototype.visitProtocolDecl): 32 * WebGPUShadingLanguageRI/index.html: 33 1 34 2018-08-22 Ryosuke Niwa <rniwa@webkit.org> 2 35 -
trunk/Tools/WebGPUShadingLanguageRI/All.js
r235237 r235249 154 154 load("SynthesizeCopyConstructorOperator.js"); 155 155 load("SynthesizeDefaultConstructorOperator.js"); 156 load("TernaryExpression.js"); 156 157 load("TrapStatement.js"); 157 158 load("TypeDef.js"); -
trunk/Tools/WebGPUShadingLanguageRI/Checker.js
r235237 r235249 649 649 return result; 650 650 } 651 652 visitTernaryExpression(node) 653 { 654 this._requireBool(node.predicate); 655 let bodyType = node.bodyExpression.visit(this); 656 let elseType = node.elseExpression.visit(this); 657 if (!bodyType) 658 throw new Error("Ternary expression body has no type: " + node.bodyExpression); 659 if (!elseType) 660 throw new Error("Ternary expression else has no type: " + node.elseExpression); 661 if (!bodyType.equalsWithCommit(elseType)) 662 throw new WTypeError("Body and else clause of ternary statement don't have the same type: " + node); 663 node.isLValue = node.bodyExpression.isLValue && node.elseExpression.isLValue; 664 return bodyType; 665 } 651 666 652 667 visitCallExpression(node) -
trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js
r235096 r235249 143 143 return result; 144 144 } 145 146 visitTernaryExpression(node) 147 { 148 if (node.predicate.visit(this).loadValue()) 149 return node.bodyExpression.visit(this); 150 return node.elseExpression.visit(this); 151 152 } 145 153 146 154 visitVariableRef(node) -
trunk/Tools/WebGPUShadingLanguageRI/NormalUsePropertyResolver.js
r222169 r235249 35 35 return super.visitIndexExpression(node).rewriteAfterCloning(); 36 36 } 37 38 visitTernaryExpression(node) 39 { 40 let result = super.visitTernaryExpression(node); 41 result.isLValue = node.isLValue; 42 return result; 43 } 37 44 } 38 45 -
trunk/Tools/WebGPUShadingLanguageRI/Parse.js
r235144 r235249 521 521 if (!operator) 522 522 return predicate; 523 return new TernaryExpression(operator, predicate, parsePossibleAssignment(), parsePossibleAssignment()); 523 let bodyExpression = parsePossibleAssignment(); 524 consume(":"); 525 let elseExpression = parsePossibleAssignment(); 526 return new TernaryExpression(operator, predicate, bodyExpression, elseExpression); 524 527 } 525 528 -
trunk/Tools/WebGPUShadingLanguageRI/PropertyResolver.js
r222750 r235249 59 59 { 60 60 visit(node.lValue); 61 } 62 63 visitTernaryExpression(node) 64 { 61 65 } 62 66 } -
trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js
r235237 r235249 165 165 return result; 166 166 } 167 168 visitTernaryExpression(node) 169 { 170 return new TernaryExpression(node.origin, node.predicate.visit(this), node.bodyExpression.visit(this), node.elseExpression.visit(this)); 171 } 167 172 168 173 _handlePropertyAccessExpression(result, node) -
trunk/Tools/WebGPUShadingLanguageRI/SPIRV.html
r235237 r235249 137 137 <script src="SynthesizeCopyConstructorOperator.js"></script> 138 138 <script src="SynthesizeDefaultConstructorOperator.js"></script> 139 <script src="TernaryExpression.js"></script> 139 140 <script src="TrapStatement.js"></script> 140 141 <script src="TypeDef.js"></script> -
trunk/Tools/WebGPUShadingLanguageRI/TernaryExpression.js
r235248 r235249 1 1 /* 2 * Copyright (C) 201 7Apple Inc. All rights reserved.2 * Copyright (C) 2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 25 25 "use strict"; 26 26 27 class NormalUsePropertyResolver extends Rewriter{28 visitDotExpression(node)27 class TernaryExpression extends Expression { 28 constructor(origin, predicate, bodyExpression, elseExpression) 29 29 { 30 return super.visitDotExpression(node).rewriteAfterCloning(); 30 super(origin); 31 this._predicate = predicate; 32 this._bodyExpression = bodyExpression; 33 this._elseExpression = elseExpression; 34 this._isLValue = null; // We use null to indicate that we don't know yet. 31 35 } 32 36 33 visitIndexExpression(node) 37 get predicate() { return this._predicate; } 38 get bodyExpression() { return this._bodyExpression; } 39 get elseExpression() { return this._elseExpression; } 40 get isLValue() { return this._isLValue; } 41 set isLValue(value) { this._isLValue = value; } 42 43 toString() 34 44 { 35 return super.visitIndexExpression(node).rewriteAfterCloning();45 return "(" + this.predicate + ") ? (" + this.bodyExpression + ") : (" + this.elseExpression + ")"; 36 46 } 37 47 } 38 -
trunk/Tools/WebGPUShadingLanguageRI/Test.html
r235237 r235249 131 131 <script src="SynthesizeCopyConstructorOperator.js"></script> 132 132 <script src="SynthesizeDefaultConstructorOperator.js"></script> 133 <script src="TernaryExpression.js"></script> 133 134 <script src="TrapStatement.js"></script> 134 135 <script src="TypeDef.js"></script> -
trunk/Tools/WebGPUShadingLanguageRI/Test.js
r235237 r235249 197 197 `), 198 198 (e) => e instanceof WSyntaxError); 199 } 200 201 tests.ternaryExpression = function() { 202 let program = doPrep(` 203 int foo(int x) 204 { 205 return x < 3 ? 4 : 5; 206 } 207 int bar(int x) 208 { 209 int y = 1; 210 int z = 2; 211 (x < 3 ? y : z) = 7; 212 return y; 213 } 214 int baz(int x) 215 { 216 return x < 10 ? 11 : x < 12 ? 14 : 15; 217 } 218 int quux(int x) 219 { 220 return 3 < 4 ? x : 5; 221 } 222 `); 223 checkInt(program, callFunction(program, "foo", [], [makeInt(program, 767)]), 5); 224 checkInt(program, callFunction(program, "foo", [], [makeInt(program, 2)]), 4); 225 checkInt(program, callFunction(program, "bar", [], [makeInt(program, 2)]), 7); 226 checkInt(program, callFunction(program, "bar", [], [makeInt(program, 8)]), 1); 227 checkInt(program, callFunction(program, "baz", [], [makeInt(program, 8)]), 11); 228 checkInt(program, callFunction(program, "baz", [], [makeInt(program, 9)]), 11); 229 checkInt(program, callFunction(program, "baz", [], [makeInt(program, 10)]), 14); 230 checkInt(program, callFunction(program, "baz", [], [makeInt(program, 11)]), 14); 231 checkInt(program, callFunction(program, "baz", [], [makeInt(program, 12)]), 15); 232 checkInt(program, callFunction(program, "baz", [], [makeInt(program, 13)]), 15); 233 checkInt(program, callFunction(program, "quux", [], [makeInt(program, 14)]), 14); 234 checkFail( 235 () => doPrep(` 236 int foo() 237 { 238 int x; 239 (4 < 5 ? x : 7) = 8; 240 } 241 `), 242 (e) => e instanceof WTypeError); 243 checkFail( 244 () => doPrep(` 245 int foo() 246 { 247 int x; 248 float y; 249 return 4 < 5 ? x : y; 250 } 251 `), 252 (e) => e instanceof WTypeError); 253 checkFail( 254 () => doPrep(` 255 int foo() 256 { 257 return 4 < 5 ? 6 : 7.0; 258 } 259 `), 260 (e) => e instanceof WTypeError); 199 261 } 200 262 -
trunk/Tools/WebGPUShadingLanguageRI/Visitor.js
r235237 r235249 163 163 node.ptr.visit(this); 164 164 } 165 166 visitTernaryExpression(node) 167 { 168 node.predicate.visit(this); 169 node.bodyExpression.visit(this); 170 node.elseExpression.visit(this); 171 } 165 172 166 173 _handlePropertyAccessExpression(node) -
trunk/Tools/WebGPUShadingLanguageRI/index.html
r235237 r235249 131 131 <script src="SynthesizeCopyConstructorOperator.js"></script> 132 132 <script src="SynthesizeDefaultConstructorOperator.js"></script> 133 <script src="TernaryExpression.js"></script> 133 134 <script src="TrapStatement.js"></script> 134 135 <script src="TypeDef.js"></script>
Note: See TracChangeset
for help on using the changeset viewer.