This repository was archived by the owner on Sep 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathFullySpecifiedTypeNode.cxx
199 lines (175 loc) · 7.19 KB
/
FullySpecifiedTypeNode.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//--------------------------------------------------------------
//
// Microsoft Edge Implementation
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files(the ""Software""),
// to deal in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
// OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//--------------------------------------------------------------
#include "PreComp.hxx"
#include "FullySpecifiedTypeNode.hxx"
#include "IStringStream.hxx"
#include "TypeSpecifierNode.hxx"
#include "InitDeclaratorListNode.hxx"
#include "GLSL.tab.h"
MtDefine(FullySpecifiedTypeNode, CGLSLParser, "FullySpecifiedTypeNode");
//+----------------------------------------------------------------------------
//
// Function: Constructor
//
//-----------------------------------------------------------------------------
FullySpecifiedTypeNode::FullySpecifiedTypeNode() :
_typeQual(NO_QUALIFIER)
{
}
//+----------------------------------------------------------------------------
//
// Function: Initialize
//
//-----------------------------------------------------------------------------
HRESULT FullySpecifiedTypeNode::Initialize(
__in CGLSLParser* pParser, // The parser that owns the tree
int typeQual, // The type qualifier (const, attribute, etc)
__in ParseTreeNode* pSpec // The type specifier
)
{
ParseTreeNode::Initialize(pParser);
_typeQual = typeQual;
return AppendChild(pSpec);
}
//+----------------------------------------------------------------------------
//
// Function: InitializeAsCloneCollection
//
// Synopsis: Initialize from another node, given the collection
//
//-----------------------------------------------------------------------------
HRESULT FullySpecifiedTypeNode::InitializeAsCloneCollection(
__in CollectionNode* pOriginalColl, // Node being cloned
__inout CModernParseTreeNodeArray &rgChildClones // Clones of children
)
{
CHK_START;
FullySpecifiedTypeNode* pOriginal = pOriginalColl->GetAs<FullySpecifiedTypeNode>();
_typeQual = pOriginal->_typeQual;
// Add the clone child
CHK(AppendChild(rgChildClones[0]));
CHK_RETURN;
}
//+----------------------------------------------------------------------------
//
// Function: VerifySelf
//
// Synopsis: If the parent is an InitDeclList, propagate the type from
// the (now verified) type specifier node to the parent InitDeclList
//
//-----------------------------------------------------------------------------
HRESULT FullySpecifiedTypeNode::VerifySelf()
{
CHK_START;
if (GetParent()->GetParseNodeType() == ParseNodeType::initDeclaratorList)
{
// If our parent is a InitDeclList, cache the specified (but not fully formed due to arrayness)
// type so that siblings (InitDeclListEntryNodes) can create the correct types for themselves.
TSmartPointer<GLSLType> spTypeFromSpecifier;
TypeSpecifierNode* pTypeSpecifier = GetTypeSpecifierNode();
CHK(pTypeSpecifier->GetType(&spTypeFromSpecifier));
InitDeclaratorListNode* pDeclList = GetParent()->GetAs<InitDeclaratorListNode>();
pDeclList->SetSpecifiedType(spTypeFromSpecifier);
// Also cache the precision qualifier from the specified type
pDeclList->SetPrecisionQualifier(pTypeSpecifier->GetComputedPrecision());
}
CHK_RETURN;
}
//+----------------------------------------------------------------------------
//
// Function: OutputHLSL
//
// Synopsis: Output HLSL for this node of the tree
//
// Attribute and varying are moved into a special struct, so we
// don't need to do anything with them. That just leaves uniform
// and const.
//
//-----------------------------------------------------------------------------
HRESULT FullySpecifiedTypeNode::OutputHLSL(__in IStringStream* pOutput)
{
CHK_START;
bool fGlobalScope = false;
if (GetParent()->GetParseNodeType() == ParseNodeType::initDeclaratorList)
{
InitDeclaratorListNode* pDeclList = GetParent()->GetAs<InitDeclaratorListNode>();
fGlobalScope = pDeclList->IsGlobalScope();
AssertSz(pDeclList->GetIdentifierCount() > 0, "We should not be outputting a type for a InitDeclaratorList that has no identifiers");
}
// We ignore all qualifiers other than const when it comes to doing this
// output. Attributes and varyings get moved into another place and that
// effectively translates them. Uniforms (both declared as such in GLSL,
// and implemention variables that are HLSL_UNIFORM) stay as globals and
// we don't want to touch them either.
if (_typeQual == CONST_TOK || _typeQual == NO_QUALIFIER)
{
// Globals need to be static in HLSL, if indeed this type
// is declaring a variable (declaration list has identifiers).
if (fGlobalScope)
{
CHK(pOutput->WriteString("static "));
}
if (_typeQual == CONST_TOK)
{
CHK(pOutput->WriteString("const "));
}
}
// Just translate the type specifier
CHK(GetChild(0)->OutputHLSL(pOutput));
CHK_RETURN;
}
//+----------------------------------------------------------------------------
//
// Function: GetFullySpecifiedTypeNode
//
// Synopsis: Type safe accessor for the fully specified type node.
//
//-----------------------------------------------------------------------------
TypeSpecifierNode* FullySpecifiedTypeNode::GetTypeSpecifierNode() const
{
return GetChild(0)->GetAs<TypeSpecifierNode>();
}
//+----------------------------------------------------------------------------
//
// Function: GetType
//
// Synopsis: Get the type that this node is specifying.
//
//-----------------------------------------------------------------------------
HRESULT FullySpecifiedTypeNode::GetType(__deref_out GLSLType** ppType) const
{
return GetTypeSpecifierNode()->GetType(ppType);
}
//+----------------------------------------------------------------------------
//
// Function: GetDumpString
//
//-----------------------------------------------------------------------------
HRESULT FullySpecifiedTypeNode::GetDumpString(__in IStringStream* pOutput)
{
return pOutput->WriteFormat(1024, "FullySpecifiedTypeNode typeQual=%d", _typeQual);
}