[WHLSL] Implement parser AST nodes
[WebKit-https.git] / Source / WebCore / Modules / webgpu / WHLSL / WHLSLProgram.h
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 "WHLSLEnumerationDefinition.h"
31 #include "WHLSLFunctionDefinition.h"
32 #include "WHLSLNativeFunctionDeclaration.h"
33 #include "WHLSLNativeTypeDeclaration.h"
34 #include "WHLSLStructureDefinition.h"
35 #include "WHLSLTypeDefinition.h"
36 #include <wtf/Vector.h>
37
38 namespace WebCore {
39
40 namespace WHLSL {
41
42 class Program {
43 public:
44     Program() = default;
45     Program(Program&&) = default;
46
47     bool append(AST::TypeDefinition&& typeDefinition)
48     {
49         m_typeDefinitions.append(makeUniqueRef<AST::TypeDefinition>(WTFMove(typeDefinition)));
50         return true;
51     }
52
53     bool append(AST::StructureDefinition&& structureDefinition)
54     {
55         m_structureDefinitions.append(makeUniqueRef<AST::StructureDefinition>(WTFMove(structureDefinition)));
56         return true;
57     }
58
59     bool append(AST::EnumerationDefinition&& enumerationDefinition)
60     {
61         m_enumerationDefinitions.append(makeUniqueRef<AST::EnumerationDefinition>(WTFMove(enumerationDefinition)));
62         return true;
63     }
64
65     bool append(AST::FunctionDefinition&& functionDefinition)
66     {
67         m_functionDefinitions.append(makeUniqueRef<AST::FunctionDefinition>(WTFMove(functionDefinition)));
68         return true;
69     }
70
71     bool append(AST::NativeFunctionDeclaration&& nativeFunctionDeclaration)
72     {
73         m_nativeFunctionDeclarations.append(makeUniqueRef<AST::NativeFunctionDeclaration>(WTFMove(nativeFunctionDeclaration)));
74         return true;
75     }
76
77     bool append(AST::NativeTypeDeclaration&& nativeTypeDeclaration)
78     {
79         m_nativeTypeDeclarations.append(makeUniqueRef<AST::NativeTypeDeclaration>(WTFMove(nativeTypeDeclaration)));
80         return true;
81     }
82
83     Vector<UniqueRef<AST::TypeDefinition>>& typeDefinitions() { return m_typeDefinitions; }
84     Vector<UniqueRef<AST::StructureDefinition>>& structureDefinitions() { return m_structureDefinitions; }
85     Vector<UniqueRef<AST::EnumerationDefinition>>& enumerationDefinitions() { return m_enumerationDefinitions; }
86     const Vector<UniqueRef<AST::FunctionDefinition>>& functionDefinitions() const { return m_functionDefinitions; }
87     Vector<UniqueRef<AST::FunctionDefinition>>& functionDefinitions() { return m_functionDefinitions; }
88     const Vector<UniqueRef<AST::NativeFunctionDeclaration>>& nativeFunctionDeclarations() const { return m_nativeFunctionDeclarations; }
89     Vector<UniqueRef<AST::NativeFunctionDeclaration>>& nativeFunctionDeclarations() { return m_nativeFunctionDeclarations; }
90     Vector<UniqueRef<AST::NativeTypeDeclaration>>& nativeTypeDeclarations() { return m_nativeTypeDeclarations; }
91
92 private:
93     Vector<UniqueRef<AST::TypeDefinition>> m_typeDefinitions;
94     Vector<UniqueRef<AST::StructureDefinition>> m_structureDefinitions;
95     Vector<UniqueRef<AST::EnumerationDefinition>> m_enumerationDefinitions;
96     Vector<UniqueRef<AST::FunctionDefinition>> m_functionDefinitions;
97     Vector<UniqueRef<AST::NativeFunctionDeclaration>> m_nativeFunctionDeclarations;
98     Vector<UniqueRef<AST::NativeTypeDeclaration>> m_nativeTypeDeclarations;
99 };
100
101 }
102
103 }
104
105 #endif