Changeset 247493 in webkit
- Timestamp:
- Jul 16, 2019 1:26:01 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 deleted
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r247484 r247493 1 2019-07-16 Robin Morisset <rmorisset@apple.com> 2 3 [WHLSL] Desugar for loops and while loops 4 https://bugs.webkit.org/show_bug.cgi?id=199726 5 6 Reviewed by Myles C. Maxfield. 7 8 I added the for-loop tests from Test.mjs (with help from Saam). 9 I did not add the foo9 and foo10 tests, as they are forbidden by the behavior checker in the C++ implementation (and by the spec). 10 11 I also changed one test from whlsl-return-spec-tests.html to assert_fail, because it relied on a lone variable declaration in an if, which is forbidden by the spec. 12 13 * webgpu/whlsl-for-loop-expected.txt: Added. 14 * webgpu/whlsl-for-loop.html: Added. 15 * webgpu/whlsl-return-spec-tests.html: 16 1 17 2019-07-16 Wenson Hsieh <wenson_hsieh@apple.com> 2 18 -
trunk/LayoutTests/webgpu/whlsl-return-spec-tests.html
r247289 r247493 112 112 } 113 113 `); 114 115 program = ` 116 int foo(int x) 117 { 118 int y = 6; 119 if (x == 7) 120 int y = 8; 121 return y; 122 } 123 `; 124 assert_equals(await callIntFunction(program, "foo", [makeInt(7)]), 6); 114 await checkFail( 115 ` 116 int foo(int x) 117 { 118 int y = 6; 119 if (x == 7) 120 int y = 8; 121 return y; 122 } 123 `); 125 124 }; 126 125 -
trunk/Source/WebCore/ChangeLog
r247490 r247493 1 2019-07-16 Robin Morisset <rmorisset@apple.com> 2 3 [WHLSL] Desugar for loops and while loops 4 https://bugs.webkit.org/show_bug.cgi?id=199726 5 6 Reviewed by Myles C. Maxfield. 7 8 This patch makes loops behave a lot more similarly to the spec. 9 In particular, while loops are just degenerate for loops, so they can be desugared in the parser. 10 And for loops can themselves be heavily desugared, into having no initializer, one condition and one increment 11 by putting any initializer in a block around the loop, putting true in the condition if there is none, and putting any litteral in the increment if there is none. 12 13 Debugging this patch revealed an unrelated bug where the parser would generate an empty comma expression on ";", which the checker would then choke on. 14 The parser now generates an empty block in that case (as specified in the spec), which fixes the problem. 15 16 Finally, while updating the NameResolver for the new structure of loops I realized that it was needlessly generating extra NameContext. 17 They are not expected by the spec, that forbids naked variable declarations outside of blocks anyway. 18 So I removed this unnecessary work, and fixed the parser to correctly forbid such naked variable declarations. 19 20 * Modules/webgpu/WHLSL/AST/WHLSLAST.h: 21 * Modules/webgpu/WHLSL/AST/WHLSLForLoop.h: 22 (WebCore::WHLSL::AST::ForLoop::ForLoop): 23 (WebCore::WHLSL::AST::ForLoop::condition): 24 (WebCore::WHLSL::AST::ForLoop::increment): 25 * Modules/webgpu/WHLSL/AST/WHLSLStatement.h: 26 (WebCore::WHLSL::AST::Statement::isVariableDeclarationsStatement const): 27 * Modules/webgpu/WHLSL/AST/WHLSLWhileLoop.h: Removed. 28 * Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp: 29 (WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit): 30 * Modules/webgpu/WHLSL/WHLSLASTDumper.cpp: 31 (WebCore::WHLSL::ASTDumper::visit): 32 * Modules/webgpu/WHLSL/WHLSLASTDumper.h: 33 * Modules/webgpu/WHLSL/WHLSLChecker.cpp: 34 (WebCore::WHLSL::Checker::visit): 35 * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp: 36 (WebCore::WHLSL::NameResolver::visit): 37 * Modules/webgpu/WHLSL/WHLSLNameResolver.h: 38 * Modules/webgpu/WHLSL/WHLSLParser.cpp: 39 (WebCore::WHLSL::Parser::parseBlockBody): 40 (WebCore::WHLSL::Parser::parseForLoop): 41 (WebCore::WHLSL::Parser::parseWhileLoop): 42 (WebCore::WHLSL::Parser::parseStatement): 43 (WebCore::WHLSL::Parser::parseEffectfulExpression): 44 * Modules/webgpu/WHLSL/WHLSLParser.h: 45 * Modules/webgpu/WHLSL/WHLSLStatementBehaviorChecker.cpp: 46 * Modules/webgpu/WHLSL/WHLSLVisitor.cpp: 47 (WebCore::WHLSL::Visitor::visit): 48 * Modules/webgpu/WHLSL/WHLSLVisitor.h: 49 * WebCore.xcodeproj/project.pbxproj: 50 1 51 2019-07-16 Tim Horton <timothy_horton@apple.com> 2 52 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLAST.h
r247124 r247493 102 102 #include "WHLSLVariableDeclarationsStatement.h" 103 103 #include "WHLSLVariableReference.h" 104 #include "WHLSLWhileLoop.h"105 104 106 105 #endif -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLForLoop.h
r247341 r247493 45 45 class ForLoop : public Statement { 46 46 public: 47 ForLoop(CodeLocation location, Variant<UniqueRef<Statement>, UniqueRef<Expression>>&& initialization, std::unique_ptr<Expression>&& condition, std::unique_ptr<Expression>&& increment, UniqueRef<Statement>&& body)47 ForLoop(CodeLocation location, UniqueRef<Expression>&& condition, UniqueRef<Expression>&& increment, UniqueRef<Statement>&& body) 48 48 : Statement(location) 49 , m_initialization(WTFMove(initialization))50 49 , m_condition(WTFMove(condition)) 51 50 , m_increment(WTFMove(increment)) … … 54 53 } 55 54 56 virtual ~ForLoop() 57 { 58 } 55 virtual ~ForLoop() = default; 59 56 60 57 ForLoop(const ForLoop&) = delete; … … 63 60 bool isForLoop() const override { return true; } 64 61 65 Variant<UniqueRef<Statement>, UniqueRef<Expression>>& initialization() { return m_initialization; } 66 Expression* condition() { return m_condition.get(); } 67 Expression* increment() { return m_increment.get(); } 62 Expression& condition() { return m_condition; } 63 Expression& increment() { return m_increment; } 68 64 Statement& body() { return m_body; } 69 65 70 66 private: 71 Variant<UniqueRef<Statement>, UniqueRef<Expression>> m_initialization; 72 std::unique_ptr<Expression> m_condition; 73 std::unique_ptr<Expression> m_increment; 67 UniqueRef<Expression> m_condition; 68 UniqueRef<Expression> m_increment; 74 69 UniqueRef<Statement> m_body; 75 70 }; -
trunk/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatement.h
r247329 r247493 63 63 virtual bool isTrap() const { return false; } 64 64 virtual bool isVariableDeclarationsStatement() const { return false; } 65 virtual bool isWhileLoop() const { return false; }66 65 67 66 CodeLocation codeLocation() const { return m_codeLocation; } -
trunk/Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp
r247450 r247493 129 129 void visit(AST::Trap&) override; 130 130 void visit(AST::VariableDeclarationsStatement&) override; 131 void visit(AST::WhileLoop&) override;132 131 void visit(AST::IntegerLiteral&) override; 133 132 void visit(AST::UnsignedIntegerLiteral&) override; … … 351 350 } 352 351 353 void FunctionDefinitionWriter::visit(AST::WhileLoop& whileLoop)354 {355 emitLoop(LoopConditionLocation::BeforeBody, &whileLoop.conditional(), nullptr, whileLoop.body());356 }357 358 352 void FunctionDefinitionWriter::visit(AST::ForLoop& forLoop) 359 353 { 360 m_stringBuilder.append("{\n"); 361 362 WTF::visit(WTF::makeVisitor([&](AST::Statement& statement) { 363 checkErrorAndVisit(statement); 364 }, [&](UniqueRef<AST::Expression>& expression) { 365 checkErrorAndVisit(expression); 366 takeLastValue(); // We don't need to do anything with the result. 367 }), forLoop.initialization()); 368 369 emitLoop(LoopConditionLocation::BeforeBody, forLoop.condition(), forLoop.increment(), forLoop.body()); 370 m_stringBuilder.append("}\n"); 354 emitLoop(LoopConditionLocation::BeforeBody, &forLoop.condition(), &forLoop.increment(), forLoop.body()); 371 355 } 372 356 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.cpp
r246625 r247493 394 394 } 395 395 396 void ASTDumper::visit(AST::WhileLoop& whileLoop)397 {398 m_out.print("while (");399 visit(whileLoop.conditional());400 m_out.print(")");401 visit(whileLoop.body());402 }403 404 396 void ASTDumper::visit(AST::DoWhileLoop& doWhileLoop) 405 397 { … … 413 405 void ASTDumper::visit(AST::ForLoop& forLoop) 414 406 { 415 m_out.print("for ("); 416 WTF::visit(WTF::makeVisitor([&](UniqueRef<AST::Statement>& statement) { 417 visit(statement); 418 }, [&](UniqueRef<AST::Expression>& expression) { 419 visit(expression); 420 }), forLoop.initialization()); 407 m_out.print("for (; "); 408 visit(forLoop.condition()); 421 409 m_out.print("; "); 422 if (forLoop.condition()) 423 visit(*forLoop.condition()); 424 m_out.print("; "); 425 if (forLoop.increment()) 426 visit(*forLoop.increment()); 410 visit(forLoop.increment()); 427 411 m_out.print(") "); 428 412 visit(forLoop.body()); -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLASTDumper.h
r246550 r247493 101 101 void visit(AST::Trap&) override; 102 102 void visit(AST::VariableDeclarationsStatement&) override; 103 void visit(AST::WhileLoop&) override;104 103 void visit(AST::VariableDeclaration&) override; 105 104 void visit(AST::AssignmentExpression&) override; -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
r247419 r247493 58 58 #include "WHLSLTernaryExpression.h" 59 59 #include "WHLSLVisitor.h" 60 #include "WHLSLWhileLoop.h"61 60 #include <wtf/HashMap.h> 62 61 #include <wtf/HashSet.h> … … 502 501 void visit(AST::LogicalExpression&) override; 503 502 void visit(AST::IfStatement&) override; 504 void visit(AST::WhileLoop&) override;505 503 void visit(AST::DoWhileLoop&) override; 506 504 void visit(AST::ForLoop&) override; … … 1248 1246 } 1249 1247 1250 void Checker::visit(AST::WhileLoop& whileLoop)1251 {1252 if (!recurseAndRequireBoolType(whileLoop.conditional()))1253 return;1254 checkErrorAndVisit(whileLoop.body());1255 }1256 1257 1248 void Checker::visit(AST::DoWhileLoop& doWhileLoop) 1258 1249 { … … 1263 1254 void Checker::visit(AST::ForLoop& forLoop) 1264 1255 { 1265 WTF::visit(WTF::makeVisitor([&](UniqueRef<AST::Statement>& statement) { 1266 checkErrorAndVisit(statement); 1267 }, [&](UniqueRef<AST::Expression>& expression) { 1268 checkErrorAndVisit(expression); 1269 }), forLoop.initialization()); 1270 if (error()) 1271 return; 1272 if (forLoop.condition()) { 1273 if (!recurseAndRequireBoolType(*forLoop.condition())) 1274 return; 1275 } 1276 if (forLoop.increment()) 1277 checkErrorAndVisit(*forLoop.increment()); 1256 if (!recurseAndRequireBoolType(forLoop.condition())) 1257 return; 1258 checkErrorAndVisit(forLoop.increment()); 1278 1259 checkErrorAndVisit(forLoop.body()); 1279 1260 } … … 1435 1416 void Checker::visit(AST::CommaExpression& commaExpression) 1436 1417 { 1437 ASSERT( commaExpression.list().size() > 0);1418 ASSERT(!commaExpression.list().isEmpty()); 1438 1419 Visitor::visit(commaExpression); 1439 1420 if (error()) -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
r247419 r247493 44 44 #include "WHLSLVariableDeclaration.h" 45 45 #include "WHLSLVariableReference.h" 46 #include "WHLSLWhileLoop.h"47 46 48 47 namespace WebCore { … … 121 120 return; 122 121 123 { 124 NameContext nameContext(&m_nameContext); 125 NameResolver newNameResolver(*this, nameContext); 126 newNameResolver.checkErrorAndVisit(ifStatement.body()); 127 } 128 if (error()) 129 return; 130 131 if (ifStatement.elseBody()) { 132 NameContext nameContext(&m_nameContext); 133 NameResolver newNameResolver(*this, nameContext); 134 newNameResolver.checkErrorAndVisit(*ifStatement.elseBody()); 135 } 136 } 137 138 void NameResolver::visit(AST::WhileLoop& whileLoop) 139 { 122 checkErrorAndVisit(ifStatement.body()); 123 if (error()) 124 return; 125 126 if (ifStatement.elseBody()) 127 checkErrorAndVisit(*ifStatement.elseBody()); 128 } 129 130 void NameResolver::visit(AST::DoWhileLoop& whileLoop) 131 { 132 checkErrorAndVisit(whileLoop.body()); 133 if (error()) 134 return; 135 140 136 checkErrorAndVisit(whileLoop.conditional()); 141 if (error())142 return;143 144 NameContext nameContext(&m_nameContext);145 NameResolver newNameResolver(*this, nameContext);146 newNameResolver.checkErrorAndVisit(whileLoop.body());147 }148 149 void NameResolver::visit(AST::DoWhileLoop& whileLoop)150 {151 {152 NameContext nameContext(&m_nameContext);153 NameResolver newNameResolver(*this, nameContext);154 newNameResolver.checkErrorAndVisit(whileLoop.body());155 }156 157 checkErrorAndVisit(whileLoop.conditional());158 137 } 159 138 160 139 void NameResolver::visit(AST::ForLoop& forLoop) 161 140 { 162 NameContext nameContext(&m_nameContext); 163 NameResolver newNameResolver(*this, nameContext); 164 newNameResolver.Visitor::visit(forLoop); 141 checkErrorAndVisit(forLoop.condition()); 142 if (error()) 143 return; 144 checkErrorAndVisit(forLoop.increment()); 145 if (error()) 146 return; 147 148 checkErrorAndVisit(forLoop.body()); 165 149 } 166 150 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h
r247419 r247493 51 51 void visit(AST::Block&) override; 52 52 void visit(AST::IfStatement&) override; 53 void visit(AST::WhileLoop&) override;54 53 void visit(AST::DoWhileLoop&) override; 55 54 void visit(AST::ForLoop&) override; -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp
r247341 r247493 1064 1064 AST::Statements statements; 1065 1065 while (!peekTypes<Token::Type::RightCurlyBracket, Token::Type::Case, Token::Type::Default>()) { 1066 PARSE(statement, Statement); 1066 bool allowVariableDeclarations = true; 1067 PARSE(statement, Statement, allowVariableDeclarations); 1067 1068 statements.append(WTFMove(*statement)); 1068 1069 } … … 1143 1144 } 1144 1145 1145 auto Parser::parseForLoop() -> Expected<AST:: ForLoop, Error>1146 auto Parser::parseForLoop() -> Expected<AST::Block, Error> 1146 1147 { 1147 1148 CONSUME_TYPE(origin, For); 1148 1149 CONSUME_TYPE(leftParenthesis, LeftParenthesis); 1149 1150 1150 auto parseRemainder = [&](Variant<UniqueRef<AST::Statement>, UniqueRef<AST::Expression>>&& initialization) -> Expected<AST::ForLoop, Error> {1151 CONSUME_TYPE(semicolon, Semicolon);1152 1153 std::unique_ptr<AST::Expression> condition(nullptr);1154 if (!tryType(Token::Type::Semicolon)) {1155 if (auto expression = parseExpression())1156 condition = (*expression).moveToUniquePtr();1157 else1158 return Unexpected<Error>(expression.error());1159 CONSUME_TYPE(secondSemicolon, Semicolon);1160 }1161 1162 std::unique_ptr<AST::Expression> increment(nullptr);1163 if (!tryType(Token::Type::RightParenthesis)) {1164 if (auto expression = parseExpression())1165 increment = (*expression).moveToUniquePtr();1166 else1167 return Unexpected<Error>(expression.error());1168 CONSUME_TYPE(rightParenthesis, RightParenthesis);1169 }1170 1171 PARSE(body, Statement);1172 AST::CodeLocation location(origin->codeLocation, (*body)->codeLocation());1173 return AST::ForLoop(location, WTFMove(initialization), WTFMove(condition), WTFMove(increment), WTFMove(*body));1174 };1175 1151 1176 1152 auto variableDeclarations = backtrackingScope<Expected<AST::VariableDeclarationsStatement, Error>>([&]() { 1177 1153 return parseVariableDeclarations(); 1178 1154 }); 1179 if (variableDeclarations) { 1180 UniqueRef<AST::Statement> declarationStatement = makeUniqueRef<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations)); 1181 return parseRemainder(WTFMove(declarationStatement)); 1182 } 1183 1184 PARSE(effectfulExpression, EffectfulExpression); 1185 1186 return parseRemainder(WTFMove(*effectfulExpression)); 1187 } 1188 1189 auto Parser::parseWhileLoop() -> Expected<AST::WhileLoop, Error> 1155 Optional<UniqueRef<AST::Statement>> initialization; 1156 if (variableDeclarations) 1157 initialization = static_cast<UniqueRef<AST::Statement>>(makeUniqueRef<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations))); 1158 else { 1159 PARSE(effectfulExpression, EffectfulExpression); 1160 initialization = WTFMove(*effectfulExpression); 1161 } 1162 1163 CONSUME_TYPE(semicolon, Semicolon); 1164 1165 Optional<UniqueRef<AST::Expression>> condition; 1166 auto secondSemicolon = tryType(Token::Type::Semicolon); 1167 if (!secondSemicolon) { 1168 PARSE(expression, Expression); 1169 condition = WTFMove(*expression); 1170 CONSUME_TYPE(secondSemicolon, Semicolon); 1171 } else 1172 condition = static_cast<UniqueRef<AST::Expression>>(makeUniqueRef<AST::BooleanLiteral>(*secondSemicolon, true)); 1173 1174 Optional<UniqueRef<AST::Expression>> increment; 1175 auto rightParenthesis = tryType(Token::Type::RightParenthesis); 1176 if (!rightParenthesis) { 1177 PARSE(expression, Expression); 1178 increment = WTFMove(*expression); 1179 CONSUME_TYPE(rightParenthesis, RightParenthesis); 1180 } else 1181 increment = static_cast<UniqueRef<AST::Expression>>(makeUniqueRef<AST::BooleanLiteral>(*origin, true)); // FIXME: NullLiteral would make more sense, but is buggy right now. Anything side-effect free is fine. 1182 1183 PARSE(body, Statement); 1184 AST::CodeLocation location(origin->codeLocation, (*body)->codeLocation()); 1185 1186 auto forLoop = makeUniqueRef<AST::ForLoop>(location, WTFMove(*condition), WTFMove(*increment), WTFMove(*body)); 1187 AST::Statements statements = Vector<UniqueRef<AST::Statement>>::from(WTFMove(*initialization), WTFMove(forLoop)); 1188 return AST::Block(location, WTFMove(statements)); 1189 } 1190 1191 auto Parser::parseWhileLoop() -> Expected<AST::ForLoop, Error> 1190 1192 { 1191 1193 CONSUME_TYPE(origin, While); … … 1196 1198 1197 1199 AST::CodeLocation location(origin->codeLocation, (*body)->codeLocation()); 1198 return AST::WhileLoop(location, WTFMove(*conditional), WTFMove(*body)); 1200 auto increment = makeUniqueRef<AST::BooleanLiteral>(*origin, true); // FIXME: NullLiteral would make more sense, but is buggy right now. Anything side-effect free is fine. 1201 return AST::ForLoop(location, WTFMove(*conditional), WTFMove(increment), WTFMove(*body)); 1199 1202 } 1200 1203 … … 1255 1258 } 1256 1259 1257 auto Parser::parseStatement( ) -> Expected<UniqueRef<AST::Statement>, Error>1260 auto Parser::parseStatement(bool allowVariableDeclarations) -> Expected<UniqueRef<AST::Statement>, Error> 1258 1261 { 1259 1262 PEEK(token); … … 1273 1276 case Token::Type::For: { 1274 1277 PARSE(forLoop, ForLoop); 1275 return { makeUniqueRef<AST:: ForLoop>(WTFMove(*forLoop)) };1278 return { makeUniqueRef<AST::Block>(WTFMove(*forLoop)) }; 1276 1279 } 1277 1280 case Token::Type::While: { 1278 1281 PARSE(whileLoop, WhileLoop); 1279 return { makeUniqueRef<AST:: WhileLoop>(WTFMove(*whileLoop)) };1282 return { makeUniqueRef<AST::ForLoop>(WTFMove(*whileLoop)) }; 1280 1283 } 1281 1284 case Token::Type::Do: { … … 1347 1350 1348 1351 { 1349 auto effectfulExpression = backtrackingScope<Expected<UniqueRef<AST::Expression>, Error>>([&]() -> Expected<UniqueRef<AST::Expression>, Error> {1352 auto effectfulExpressionStatement = backtrackingScope<Expected<UniqueRef<AST::Statement>, Error>>([&]() -> Expected<UniqueRef<AST::Statement>, Error> { 1350 1353 PARSE(result, EffectfulExpression); 1351 1354 CONSUME_TYPE(semicolon, Semicolon); 1352 1355 return result; 1353 1356 }); 1354 if (effectfulExpression) 1355 return { makeUniqueRef<AST::EffectfulExpressionStatement>(WTFMove(*effectfulExpression)) }; 1356 } 1357 1358 PARSE(variableDeclarations, VariableDeclarations); 1359 CONSUME_TYPE(semicolon, Semicolon); 1360 return { makeUniqueRef<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations)) }; 1361 } 1362 1363 auto Parser::parseEffectfulExpression() -> Expected<UniqueRef<AST::Expression>, Error> 1357 if (effectfulExpressionStatement) 1358 return effectfulExpressionStatement; 1359 } 1360 1361 if (allowVariableDeclarations) { 1362 PARSE(variableDeclarations, VariableDeclarations); 1363 CONSUME_TYPE(semicolon, Semicolon); 1364 return { makeUniqueRef<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations)) }; 1365 } 1366 1367 return Unexpected<Error>("A variable declaration is only valid inside a block"); 1368 } 1369 1370 auto Parser::parseEffectfulExpression() -> Expected<UniqueRef<AST::Statement>, Error> 1364 1371 { 1365 1372 PEEK(origin); 1373 if (origin->type == Token::Type::Semicolon) { 1374 AST::Statements statements; 1375 return { makeUniqueRef<AST::Block>(*origin, WTFMove(statements)) }; 1376 } 1377 1366 1378 Vector<UniqueRef<AST::Expression>> expressions; 1367 if (origin->type == Token::Type::Semicolon)1368 return { makeUniqueRef<AST::CommaExpression>(*origin, WTFMove(expressions)) };1369 1370 1379 PARSE(effectfulExpression, EffectfulAssignment); 1371 1380 expressions.append(WTFMove(*effectfulExpression)); … … 1377 1386 1378 1387 if (expressions.size() == 1) 1379 return WTFMove(expressions[0]);1388 return { makeUniqueRef<AST::EffectfulExpressionStatement>(WTFMove(expressions[0])) }; 1380 1389 unsigned endOffset = m_lexer.peek().startOffset(); 1381 1390 AST::CodeLocation location(origin->startOffset(), endOffset); 1382 return { makeUniqueRef<AST::CommaExpression>(location, WTFMove(expressions)) }; 1391 auto expression = makeUniqueRef<AST::CommaExpression>(location, WTFMove(expressions)); 1392 return { makeUniqueRef<AST::EffectfulExpressionStatement>(WTFMove(expression)) }; 1383 1393 } 1384 1394 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.h
r247329 r247493 92 92 #include "WHLSLVariableDeclarationsStatement.h" 93 93 #include "WHLSLVariableReference.h" 94 #include "WHLSLWhileLoop.h"95 94 #include <wtf/Expected.h> 96 95 #include <wtf/Optional.h> … … 204 203 Expected<AST::SwitchStatement, Error> parseSwitchStatement(); 205 204 Expected<AST::SwitchCase, Error> parseSwitchCase(); 206 Expected<AST:: ForLoop, Error> parseForLoop();207 Expected<AST:: WhileLoop, Error> parseWhileLoop();205 Expected<AST::Block, Error> parseForLoop(); 206 Expected<AST::ForLoop, Error> parseWhileLoop(); 208 207 Expected<AST::DoWhileLoop, Error> parseDoWhileLoop(); 209 208 Expected<AST::VariableDeclaration, Error> parseVariableDeclaration(UniqueRef<AST::UnnamedType>&&); 210 209 Expected<AST::VariableDeclarationsStatement, Error> parseVariableDeclarations(); 211 Expected<UniqueRef<AST::Statement>, Error> parseStatement( );212 213 Expected<UniqueRef<AST:: Expression>, Error> parseEffectfulExpression();210 Expected<UniqueRef<AST::Statement>, Error> parseStatement(bool allowVariableDeclaration = false); 211 212 Expected<UniqueRef<AST::Statement>, Error> parseEffectfulExpression(); 214 213 Expected<UniqueRef<AST::Expression>, Error> parseEffectfulAssignment(); 215 214 struct SuffixExpression { -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStatementBehaviorChecker.cpp
r240230 r247493 45 45 #include "WHLSLVariableDeclarationsStatement.h" 46 46 #include "WHLSLVisitor.h" 47 #include "WHLSLWhileLoop.h"48 47 #include <cstdint> 49 48 #include <wtf/OptionSet.h> … … 110 109 void visit(AST::ForLoop& forLoop) override 111 110 { 112 // The initialization always has a behavior of Nothing, which we already add unconditionally below,113 // so we can just ignore the initialization.114 115 111 checkErrorAndVisit(forLoop.body()); 116 if (error())117 return;118 auto b = m_stack.takeLast();119 b.remove(Behavior::Break);120 b.remove(Behavior::Continue);121 b.add(Behavior::Nothing);122 m_stack.append(b);123 }124 125 void visit(AST::WhileLoop& whileLoop) override126 {127 checkErrorAndVisit(whileLoop.body());128 112 if (error()) 129 113 return; -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp
r246640 r247493 332 332 else if (is<AST::Trap>(statement)) 333 333 checkErrorAndVisit(downcast<AST::Trap>(statement)); 334 else if (is<AST::VariableDeclarationsStatement>(statement)) 334 else { 335 ASSERT(is<AST::VariableDeclarationsStatement>(statement)); 335 336 checkErrorAndVisit(downcast<AST::VariableDeclarationsStatement>(statement)); 336 else 337 checkErrorAndVisit(downcast<AST::WhileLoop>(statement)); 337 } 338 338 } 339 339 … … 428 428 void Visitor::visit(AST::ForLoop& forLoop) 429 429 { 430 WTF::visit(WTF::makeVisitor([&](UniqueRef<AST::Statement>& statement) { 431 checkErrorAndVisit(statement); 432 }, [&](UniqueRef<AST::Expression>& expression) { 433 checkErrorAndVisit(expression); 434 }), forLoop.initialization()); 435 if (forLoop.condition()) 436 checkErrorAndVisit(*forLoop.condition()); 437 if (forLoop.increment()) 438 checkErrorAndVisit(*forLoop.increment()); 430 checkErrorAndVisit(forLoop.condition()); 431 checkErrorAndVisit(forLoop.increment()); 439 432 checkErrorAndVisit(forLoop.body()); 440 433 } … … 476 469 for (auto& variableDeclaration : variableDeclarationsStatement.variableDeclarations()) 477 470 checkErrorAndVisit(variableDeclaration.get()); 478 }479 480 void Visitor::visit(AST::WhileLoop& whileLoop)481 {482 checkErrorAndVisit(whileLoop.conditional());483 checkErrorAndVisit(whileLoop.body());484 471 } 485 472 -
trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.h
r245945 r247493 86 86 class Trap; 87 87 class VariableDeclarationsStatement; 88 class WhileLoop;89 88 class VariableDeclaration; 90 89 class AssignmentExpression; … … 167 166 virtual void visit(AST::Trap&); 168 167 virtual void visit(AST::VariableDeclarationsStatement&); 169 virtual void visit(AST::WhileLoop&);170 168 virtual void visit(AST::VariableDeclaration&); 171 169 virtual void visit(AST::AssignmentExpression&); -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r247472 r247493 13257 13257 C21BF70221CD89C400227979 /* WHLSLEnumerationMemberLiteral.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLEnumerationMemberLiteral.h; sourceTree = "<group>"; }; 13258 13258 C21BF70321CD89C500227979 /* WHLSLReturn.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLReturn.h; sourceTree = "<group>"; }; 13259 C21BF70421CD89C600227979 /* WHLSLWhileLoop.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLWhileLoop.h; sourceTree = "<group>"; };13260 13259 C21BF70521CD89C700227979 /* WHLSLFunctionAttribute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLFunctionAttribute.h; sourceTree = "<group>"; }; 13261 13260 C21BF70621CD89C700227979 /* WHLSLCommaExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLCommaExpression.h; sourceTree = "<group>"; }; … … 17133 17132 C21BF71421CD89D300227979 /* WHLSLVariableDeclarationsStatement.h */, 17134 17133 C21BF71321CD89D200227979 /* WHLSLVariableReference.h */, 17135 C21BF70421CD89C600227979 /* WHLSLWhileLoop.h */,17136 17134 ); 17137 17135 path = AST;
Note: See TracChangeset
for help on using the changeset viewer.