1 | /* |
2 | * Copyright (C) 2019 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(WEBGPU) |
29 | |
30 | #include "WHLSLNameContext.h" |
31 | #include "WHLSLVisitor.h" |
32 | #include <wtf/HashSet.h> |
33 | |
34 | namespace WebCore { |
35 | |
36 | namespace WHLSL { |
37 | |
38 | class Program; |
39 | |
40 | class NameResolver : public Visitor { |
41 | public: |
42 | NameResolver(NameContext&); |
43 | |
44 | virtual ~NameResolver() = default; |
45 | |
46 | void visit(AST::FunctionDefinition&) override; |
47 | |
48 | void setCurrentFunctionDefinition(AST::FunctionDefinition* functionDefinition) |
49 | { |
50 | m_currentFunction = functionDefinition; |
51 | } |
52 | |
53 | private: |
54 | void visit(AST::TypeReference&) override; |
55 | void visit(AST::Block&) override; |
56 | void visit(AST::IfStatement&) override; |
57 | void visit(AST::WhileLoop&) override; |
58 | void visit(AST::DoWhileLoop&) override; |
59 | void visit(AST::ForLoop&) override; |
60 | void visit(AST::VariableDeclaration&) override; |
61 | void visit(AST::VariableReference&) override; |
62 | void visit(AST::Return&) override; |
63 | void visit(AST::PropertyAccessExpression&) override; |
64 | void visit(AST::DotExpression&) override; |
65 | void visit(AST::CallExpression&) override; |
66 | void visit(AST::EnumerationMemberLiteral&) override; |
67 | |
68 | NameContext& m_nameContext; |
69 | HashSet<AST::TypeReference*> m_typeReferences; |
70 | AST::FunctionDefinition* m_currentFunction { nullptr }; |
71 | }; |
72 | |
73 | bool resolveNamesInTypes(Program&, NameResolver&); |
74 | bool resolveNamesInFunctions(Program&, NameResolver&); |
75 | |
76 | } // namespace WHLSL |
77 | |
78 | } // namespace WebCore |
79 | |
80 | #endif // ENABLE(WEBGPU) |
81 | |