Tools/ChangeLog

 12018-08-20 Myles C. Maxfield <mmaxfield@apple.com>
 2
 3 [WHLSL] Call expressions shouldn't have type arguments
 4 https://bugs.webkit.org/show_bug.cgi?id=188770
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Call expressions only had type arguments for casts, becuase native types can have type arguments.
 9 However, instead of putting those type arguments on the CallExpression, we should parse the casted
 10 type as a real type and not as an identifier, which puts the type arguments in the TypeRef.
 11
 12 * WebGPUShadingLanguageRI/CallExpression.js:
 13 (CallExpression):
 14 (CallExpression.prototype.get name):
 15 (CallExpression.resolve):
 16 (CallExpression.prototype.get typeArguments): Deleted.
 17 (CallExpression.prototype.becomeCast): Deleted.
 18 * WebGPUShadingLanguageRI/NameResolver.js:
 19 (NameResolver.prototype.visitCallExpression):
 20 * WebGPUShadingLanguageRI/Parse.js:
 21 (parseConstexpr):
 22 (parseTypeDef):
 23 (parseLeftOperatorCall):
 24 (parseCallExpression.let.parseArguments):
 25 (parsePossiblePrefix):
 26 (parsePossibleRelationalEquality):
 27 (parseLeftLogicalExpression):
 28 (parseIfStatement):
 29 (parseWhile):
 30 (parseFor):
 31 (parseDo):
 32 * WebGPUShadingLanguageRI/RemoveTypeArguments.js:
 33 * WebGPUShadingLanguageRI/Rewriter.js:
 34 (Rewriter.prototype.visitCallExpression):
 35
1362018-08-20 Jonathan Bedard <jbedard@apple.com>
237
338 WebKitTestRunner: Add watchOS entitlements

Tools/WebGPUShadingLanguageRI/CallExpression.js

2525"use strict";
2626
2727class CallExpression extends Expression {
28  constructor(origin, name, typeArguments, argumentList)
 28 constructor(origin, name, argumentList)
2929 {
3030 super(origin);
3131 this._name = name;
32  this._typeArguments = typeArguments;
3332 this._argumentList = argumentList;
3433 this.func = null;
3534 this._isCast = false;

@@class CallExpression extends Expression {
3736 }
3837
3938 get name() { return this._name; }
40  get typeArguments() { return this._typeArguments; }
4139 get argumentList() { return this._argumentList; }
4240 get isCast() { return this._isCast; }
4341 get returnType() { return this._returnType; }
4442
4543 static resolve(origin, possibleOverloads, name, argumentList, argumentTypes, returnType, program)
4644 {
47  let call = new CallExpression(origin, name, [], argumentList);
 45 let call = new CallExpression(origin, name, argumentList);
4846 call.argumentTypes = argumentTypes.map(argument => argument.visit(new AutoWrapper()));
4947 call.possibleOverloads = possibleOverloads;
5048 if (returnType)

@@class CallExpression extends Expression {
164162 return result;
165163 }
166164
167  becomeCast(returnType)
168  {
169  this._returnType = new TypeRef(this.origin, this.name);
170  this._returnType.type = returnType;
171  this._name = "operator cast";
172  this._isCast = true;
173  }
174 
175165 setCastData(returnType)
176166 {
177167 this._returnType = returnType;

Tools/WebGPUShadingLanguageRI/NameResolver.js

@@class NameResolver extends Visitor {
198198 let funcs = this._nameContext.get(Func, node.name);
199199 if (funcs)
200200 node.possibleOverloads = funcs;
201  else {
202  let type = this._nameContext.get(Type, node.name);
203  if (!type)
204  throw new WTypeError(node.origin.originString, "Cannot find any function or type named \"" + node.name + "\"");
205  node.becomeCast(type);
 201 else if (node.name != "operator cast"){
 202 node.setCastData(new TypeRef(node.origin, node.name));
206203 node.possibleOverloads = this._nameContext.get(Func, "operator cast");
207  if (!node.possibleOverloads)
208  throw new WTypeError(node.origin.originString, "Cannot find any operator cast implementations in cast to " + type);
209204 }
 205
 206 if (!node.possibleOverloads)
 207 throw new WTypeError(node.origin.originString, "Cannot find any possible overloads for " + node);
210208
211209 super.visitCallExpression(node);
212210 }

Tools/WebGPUShadingLanguageRI/Parse.js

@@function parse(program, origin, originKind, lineNumberOffset, text)
188188 {
189189 let token;
190190 if (token = tryConsume("-"))
191  return new CallExpression(token, "operator" + token.text, [], [parseTerm()]);
 191 return new CallExpression(token, "operator" + token.text, [parseTerm()]);
192192 let left = parseTerm();
193193 if (token = tryConsume("."))
194194 left = new DotExpression(token, left, consumeKind("identifier").text);

@@function parse(program, origin, originKind, lineNumberOffset, text)
285285 let origin = consume("typedef");
286286 let name = consumeKind("identifier").text;
287287 consume("=");
288  let type = parseType(true);
 288 let type = parseType();
289289 consume(";");
290290 return new TypeDef(origin, name, type);
291291 }

@@function parse(program, origin, originKind, lineNumberOffset, text)
304304 return genericParseLeft(
305305 texts, nextParser,
306306 (token, left, right) =>
307  new CallExpression(token, "operator" + token.text, [], [left, right]));
 307 new CallExpression(token, "operator" + token.text, [left, right]));
308308 }
309309
310310 function parseCallExpression()
311311 {
312  let name = consumeKind("identifier");
313  let typeArguments = parseTypeArguments();
314  consume("(");
315  let argumentList = [];
316  while (!test(")")) {
317  let argument = parsePossibleAssignment();
318  argumentList.push(argument);
319  if (!tryConsume(","))
320  break;
 312 let parseArguments = function(origin, callName) {
 313 let argumentList = [];
 314 while (!test(")")) {
 315 let argument = parsePossibleAssignment();
 316 argumentList.push(argument);
 317 if (!tryConsume(","))
 318 break;
 319 }
 320 consume(")");
 321 return new CallExpression(origin, callName, argumentList);
 322 }
 323
 324 let name = lexer.backtrackingScope(() => {
 325 let name = consumeKind("identifier");
 326 consume("(");
 327 return name;
 328 });
 329
 330 if (name) {
 331 let result = parseArguments(name, name.text);
 332 return result;
 333 } else {
 334 let returnType = parseType();
 335 consume("(");
 336 let result = parseArguments(returnType.origin, "operator cast");
 337 result.setCastData(returnType);
 338 return result;
321339 }
322  consume(")");
323  let result = new CallExpression(name, name.text, typeArguments, argumentList);
324  return result;
325340 }
326341
327342 function isCallExpression()

@@function parse(program, origin, originKind, lineNumberOffset, text)
346361 if (name == "operator")
347362 throw new Error("Invalid name: " + name);
348363
349  return new CallExpression(token, name, [], args);
 364 return new CallExpression(token, name, args);
350365 }
351366
352367 function finishParsingPostIncrement(token, left)

@@function parse(program, origin, originKind, lineNumberOffset, text)
419434 if (test("++", "--"))
420435 return parsePreIncrement();
421436 if (token = tryConsume("+", "-", "~"))
422  return new CallExpression(token, "operator" + token.text, [], [parsePossiblePrefix()]);
 437 return new CallExpression(token, "operator" + token.text, [parsePossiblePrefix()]);
423438 if (token = tryConsume("*"))
424439 return new DereferenceExpression(token, parsePossiblePrefix());
425440 if (token = tryConsume("&"))

@@function parse(program, origin, originKind, lineNumberOffset, text)
428443 return new MakeArrayRefExpression(token, parsePossiblePrefix());
429444 if (token = tryConsume("!")) {
430445 let remainder = parsePossiblePrefix();
431  return new LogicalNot(token, new CallExpression(remainder.origin, "bool", [], [remainder]));
 446 return new LogicalNot(token, new CallExpression(remainder.origin, "bool", [remainder]));
432447 }
433448 return parsePossibleSuffix();
434449 }

@@function parse(program, origin, originKind, lineNumberOffset, text)
458473 return genericParseLeft(
459474 ["==", "!="], parsePossibleRelationalInequality,
460475 (token, left, right) => {
461  let result = new CallExpression(token, "operator==", [], [left, right]);
 476 let result = new CallExpression(token, "operator==", [left, right]);
462477 if (token.text == "!=")
463478 result = new LogicalNot(token, result);
464479 return result;

@@function parse(program, origin, originKind, lineNumberOffset, text)
484499 {
485500 return genericParseLeft(
486501 texts, nextParser,
487  (token, left, right) => new LogicalExpression(token, token.text, new CallExpression(left.origin, "bool", [], [left]), new CallExpression(right.origin, "bool", [], [right])));
 502 (token, left, right) => new LogicalExpression(token, token.text, new CallExpression(left.origin, "bool", [left]), new CallExpression(right.origin, "bool", [right])));
488503 }
489504
490505 function parsePossibleLogicalAnd()

@@function parse(program, origin, originKind, lineNumberOffset, text)
621636 let elseBody;
622637 if (tryConsume("else"))
623638 elseBody = parseStatement();
624  return new IfStatement(origin, new CallExpression(conditional.origin, "bool", [], [conditional]), body, elseBody);
 639 return new IfStatement(origin, new CallExpression(conditional.origin, "bool", [conditional]), body, elseBody);
625640 }
626641
627642 function parseWhile()

@@function parse(program, origin, originKind, lineNumberOffset, text)
631646 let conditional = parseExpression();
632647 consume(")");
633648 let body = parseStatement();
634  return new WhileLoop(origin, new CallExpression(conditional.origin, "bool", [], [conditional]), body);
 649 return new WhileLoop(origin, new CallExpression(conditional.origin, "bool", [conditional]), body);
635650 }
636651
637652 function parseFor()

@@function parse(program, origin, originKind, lineNumberOffset, text)
652667 else {
653668 condition = parseExpression();
654669 consume(";");
655  condition = new CallExpression(condition.origin, "bool", [], [condition]);
 670 condition = new CallExpression(condition.origin, "bool", [condition]);
656671 }
657672 let increment;
658673 if (tryConsume(")"))

@@function parse(program, origin, originKind, lineNumberOffset, text)
673688 consume("(");
674689 let conditional = parseExpression();
675690 consume(")");
676  return new DoWhileLoop(origin, body, new CallExpression(conditional.origin, "bool", [], [conditional]));
 691 return new DoWhileLoop(origin, body, new CallExpression(conditional.origin, "bool", [conditional]));
677692 }
678693
679694 function parseVariableDecls()

Tools/WebGPUShadingLanguageRI/RemoveTypeArguments.js

@@function removeTypeArguments(program)
5959 node._name = RemoveTypeArguments.resolveNameAndArguments(node);
6060 node._typeArguments = null;
6161 }
62 
63  visitCallExpression(node)
64  {
65  node._name = RemoveTypeArguments.resolveNameAndArguments(node);
66  if (!node._name || !node._name.length)
67  throw new Error("lazy");
68  node._typeArguments = null;
69  }
7062 }
7163
7264 program.visit(new RemoveTypeArguments());
73 }
7465\ No newline at end of file
 66}

Tools/WebGPUShadingLanguageRI/Rewriter.js

@@class Rewriter {
298298 visitCallExpression(node)
299299 {
300300 let result = new CallExpression(
301  node.origin, node.name, null,
 301 node.origin, node.name,
302302 node.argumentList.map(argument => Node.visit(argument, this)));
303303 return this.processDerivedCallData(node, result);
304304 }