[WHLSL] Standard library is too big to directly include in WebCore
[WebKit-https.git] / Source / WebCore / Modules / webgpu / WHLSL / WHLSLNameResolver.cpp
index d875da8..2c3a2d7 100644 (file)
@@ -39,6 +39,7 @@
 #include "WHLSLNameContext.h"
 #include "WHLSLProgram.h"
 #include "WHLSLPropertyAccessExpression.h"
+#include "WHLSLReplaceWith.h"
 #include "WHLSLResolveOverloadImpl.h"
 #include "WHLSLReturn.h"
 #include "WHLSLScopedSetAdder.h"
@@ -60,7 +61,6 @@ NameResolver::NameResolver(NameResolver& parentResolver, NameContext& nameContex
     : m_nameContext(nameContext)
     , m_parentNameResolver(&parentResolver)
 {
-    m_isResolvingCalls = parentResolver.m_isResolvingCalls;
     setCurrentFunctionDefinition(parentResolver.m_currentFunction);
 }
 
@@ -72,9 +72,6 @@ NameResolver::~NameResolver()
 
 void NameResolver::visit(AST::TypeReference& typeReference)
 {
-    if (m_isResolvingCalls)
-        return;
-
     ScopedSetAdder<AST::TypeReference*> adder(m_typeReferences, &typeReference);
     if (!adder.isNewEntry()) {
         setError();
@@ -82,6 +79,8 @@ void NameResolver::visit(AST::TypeReference& typeReference)
     }
 
     Visitor::visit(typeReference);
+    if (error())
+        return;
     if (typeReference.maybeResolvedType()) // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198161 Shouldn't we know by now whether the type has been resolved or not?
         return;
 
@@ -105,6 +104,8 @@ void NameResolver::visit(AST::FunctionDefinition& functionDefinition)
     NameContext newNameContext(&m_nameContext);
     NameResolver newNameResolver(*this, newNameContext);
     checkErrorAndVisit(functionDefinition.type());
+    if (error())
+        return;
     for (auto& parameter : functionDefinition.parameters())
         newNameResolver.checkErrorAndVisit(parameter);
     newNameResolver.checkErrorAndVisit(functionDefinition.block());
@@ -120,12 +121,18 @@ void NameResolver::visit(AST::Block& block)
 void NameResolver::visit(AST::IfStatement& ifStatement)
 {
     checkErrorAndVisit(ifStatement.conditional());
-    NameContext nameContext(&m_nameContext);
-    NameResolver newNameResolver(*this, nameContext);
-    newNameResolver.checkErrorAndVisit(ifStatement.body());
-    if (newNameResolver.error())
-        setError();
-    else if (ifStatement.elseBody()) {
+    if (error())
+        return;
+
+    {
+        NameContext nameContext(&m_nameContext);
+        NameResolver newNameResolver(*this, nameContext);
+        newNameResolver.checkErrorAndVisit(ifStatement.body());
+    }
+    if (error())
+        return;
+
+    if (ifStatement.elseBody()) {
         NameContext nameContext(&m_nameContext);
         NameResolver newNameResolver(*this, nameContext);
         newNameResolver.checkErrorAndVisit(*ifStatement.elseBody());
@@ -135,6 +142,9 @@ void NameResolver::visit(AST::IfStatement& ifStatement)
 void NameResolver::visit(AST::WhileLoop& whileLoop)
 {
     checkErrorAndVisit(whileLoop.conditional());
+    if (error())
+        return;
+
     NameContext nameContext(&m_nameContext);
     NameResolver newNameResolver(*this, nameContext);
     newNameResolver.checkErrorAndVisit(whileLoop.body());
@@ -142,9 +152,12 @@ void NameResolver::visit(AST::WhileLoop& whileLoop)
 
 void NameResolver::visit(AST::DoWhileLoop& whileLoop)
 {
-    NameContext nameContext(&m_nameContext);
-    NameResolver newNameResolver(*this, nameContext);
-    newNameResolver.checkErrorAndVisit(whileLoop.body());
+    {
+        NameContext nameContext(&m_nameContext);
+        NameResolver newNameResolver(*this, nameContext);
+        newNameResolver.checkErrorAndVisit(whileLoop.body());
+    }
+
     checkErrorAndVisit(whileLoop.conditional());
 }
 
@@ -186,14 +199,6 @@ void NameResolver::visit(AST::Return& returnStatement)
 
 void NameResolver::visit(AST::PropertyAccessExpression& propertyAccessExpression)
 {
-    if (m_isResolvingCalls) {
-        if (auto* getterFunctions = m_nameContext.getFunctions(propertyAccessExpression.getterFunctionName()))
-            propertyAccessExpression.setPossibleGetterOverloads(*getterFunctions);
-        if (auto* setterFunctions = m_nameContext.getFunctions(propertyAccessExpression.setterFunctionName()))
-            propertyAccessExpression.setPossibleSetterOverloads(*setterFunctions);
-        if (auto* anderFunctions = m_nameContext.getFunctions(propertyAccessExpression.anderFunctionName()))
-            propertyAccessExpression.setPossibleAnderOverloads(*anderFunctions);
-    }
     Visitor::visit(propertyAccessExpression);
 }
 
@@ -224,26 +229,6 @@ void NameResolver::visit(AST::DotExpression& dotExpression)
 
 void NameResolver::visit(AST::CallExpression& callExpression)
 {
-    if (m_isResolvingCalls) {
-        if (!callExpression.hasOverloads()) {
-            if (auto* functions = m_nameContext.getFunctions(callExpression.name()))
-                callExpression.setOverloads(*functions);
-            else {
-                if (auto* types = m_nameContext.getTypes(callExpression.name())) {
-                    if (types->size() == 1) {
-                        if (auto* functions = m_nameContext.getFunctions("operator cast"_str)) {
-                            callExpression.setCastData((*types)[0].get());
-                            callExpression.setOverloads(*functions);
-                        }
-                    }
-                }
-            }
-        }
-        if (!callExpression.hasOverloads()) {
-            setError();
-            return;
-        }
-    }
     Visitor::visit(callExpression);
 }
 
@@ -318,20 +303,6 @@ bool resolveTypeNamesInFunctions(Program& program, NameResolver& nameResolver)
     return true;
 }
 
-bool resolveCallsInFunctions(Program& program, NameResolver& nameResolver)
-{
-    nameResolver.setIsResolvingCalls(true);
-    for (auto& functionDefinition : program.functionDefinitions()) {
-        nameResolver.setCurrentFunctionDefinition(&functionDefinition);
-        nameResolver.checkErrorAndVisit(functionDefinition);
-        if (nameResolver.error())
-            return false;
-    }
-    nameResolver.setCurrentFunctionDefinition(nullptr);
-    nameResolver.setIsResolvingCalls(false);
-    return true;
-}
-
 } // namespace WHLSL
 
 } // namespace WebCore