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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
|
// slang-ast-type.h
#pragma once
#include "slang-ast-base.h"
namespace Slang {
// Syntax class definitions for types.
// The type of a reference to an overloaded name
class OverloadGroupType : public Type
{
SLANG_AST_CLASS(OverloadGroupType)
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
Type* _createCanonicalTypeOverride();
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
};
// The type of an initializer-list expression (before it has
// been coerced to some other type)
class InitializerListType : public Type
{
SLANG_AST_CLASS(InitializerListType)
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
Type* _createCanonicalTypeOverride();
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
};
// The type of an expression that was erroneous
class ErrorType : public Type
{
SLANG_AST_CLASS(ErrorType)
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
Type* _createCanonicalTypeOverride();
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff);
};
// A type that takes the form of a reference to some declaration
class DeclRefType : public Type
{
SLANG_AST_CLASS(DeclRefType)
DeclRef<Decl> declRef;
static DeclRefType* create(ASTBuilder* astBuilder, DeclRef<Decl> declRef);
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
Type* _createCanonicalTypeOverride();
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff);
protected:
DeclRefType( DeclRef<Decl> declRef)
: declRef(declRef)
{}
};
// Base class for types that can be used in arithmetic expressions
class ArithmeticExpressionType : public DeclRefType
{
SLANG_ABSTRACT_AST_CLASS(ArithmeticExpressionType)
BasicExpressionType* getScalarType();
// Overrides should be public so base classes can access
BasicExpressionType* _getScalarTypeOverride();
};
class BasicExpressionType : public ArithmeticExpressionType
{
SLANG_AST_CLASS(BasicExpressionType)
BaseType baseType;
// Overrides should be public so base classes can access
Type* _createCanonicalTypeOverride();
bool _equalsImplOverride(Type* type);
BasicExpressionType* _getScalarTypeOverride();
protected:
BasicExpressionType(
Slang::BaseType baseType)
: baseType(baseType)
{}
};
// Base type for things that are built in to the compiler,
// and will usually have special behavior or a custom
// mapping to the IR level.
class BuiltinType : public DeclRefType
{
SLANG_ABSTRACT_AST_CLASS(BuiltinType)
};
class FeedbackType : public BuiltinType
{
SLANG_AST_CLASS(FeedbackType)
enum class Kind : uint8_t
{
MinMip, /// SAMPLER_FEEDBACK_MIN_MIP
MipRegionUsed, /// SAMPLER_FEEDBACK_MIP_REGION_USED
};
Kind kind;
};
// Resources that contain "elements" that can be fetched
class ResourceType : public BuiltinType
{
SLANG_ABSTRACT_AST_CLASS(ResourceType)
// The type that results from fetching an element from this resource
Type* elementType = nullptr;
// Shape and access level information for this resource type
TextureFlavor flavor;
TextureFlavor::Shape getBaseShape()
{
return flavor.getBaseShape();
}
bool isMultisample() { return flavor.isMultisample(); }
bool isArray() { return flavor.isArray(); }
SlangResourceShape getShape() const { return flavor.getShape(); }
SlangResourceAccess getAccess() { return flavor.getAccess(); }
};
class TextureTypeBase : public ResourceType
{
SLANG_ABSTRACT_AST_CLASS(TextureTypeBase)
protected:
TextureTypeBase(TextureFlavor inFlavor, Type* inElementType)
{
elementType = inElementType;
flavor = inFlavor;
}
};
class TextureType : public TextureTypeBase
{
SLANG_AST_CLASS(TextureType)
protected:
TextureType(TextureFlavor flavor, Type* elementType)
: TextureTypeBase(flavor, elementType)
{}
};
// This is a base type for texture/sampler pairs,
// as they exist in, e.g., GLSL
class TextureSamplerType : public TextureTypeBase
{
SLANG_AST_CLASS(TextureSamplerType)
protected:
TextureSamplerType(TextureFlavor flavor, Type* elementType)
: TextureTypeBase(flavor, elementType)
{}
};
// This is a base type for `image*` types, as they exist in GLSL
class GLSLImageType : public TextureTypeBase
{
SLANG_AST_CLASS(GLSLImageType)
protected:
GLSLImageType(
TextureFlavor flavor,
Type* elementType)
: TextureTypeBase(flavor, elementType)
{}
};
class SamplerStateType : public BuiltinType
{
SLANG_AST_CLASS(SamplerStateType)
// What flavor of sampler state is this
SamplerStateFlavor flavor;
};
// Other cases of generic types known to the compiler
class BuiltinGenericType : public BuiltinType
{
SLANG_AST_CLASS(BuiltinGenericType)
Type* elementType = nullptr;
Type* getElementType() { return elementType; }
};
// Types that behave like pointers, in that they can be
// dereferenced (implicitly) to access members defined
// in the element type.
class PointerLikeType : public BuiltinGenericType
{
SLANG_AST_CLASS(PointerLikeType)
};
// HLSL buffer-type resources
class HLSLStructuredBufferTypeBase : public BuiltinGenericType
{
SLANG_AST_CLASS(HLSLStructuredBufferTypeBase)
};
class HLSLStructuredBufferType : public HLSLStructuredBufferTypeBase
{
SLANG_AST_CLASS(HLSLStructuredBufferType)
};
class HLSLRWStructuredBufferType : public HLSLStructuredBufferTypeBase
{
SLANG_AST_CLASS(HLSLRWStructuredBufferType)
};
class HLSLRasterizerOrderedStructuredBufferType : public HLSLStructuredBufferTypeBase
{
SLANG_AST_CLASS(HLSLRasterizerOrderedStructuredBufferType)
};
class UntypedBufferResourceType : public BuiltinType
{
SLANG_AST_CLASS(UntypedBufferResourceType)
};
class HLSLByteAddressBufferType : public UntypedBufferResourceType
{
SLANG_AST_CLASS(HLSLByteAddressBufferType)
};
class HLSLRWByteAddressBufferType : public UntypedBufferResourceType
{
SLANG_AST_CLASS(HLSLRWByteAddressBufferType)
};
class HLSLRasterizerOrderedByteAddressBufferType : public UntypedBufferResourceType
{
SLANG_AST_CLASS(HLSLRasterizerOrderedByteAddressBufferType)
};
class RaytracingAccelerationStructureType : public UntypedBufferResourceType
{
SLANG_AST_CLASS(RaytracingAccelerationStructureType)
};
class HLSLAppendStructuredBufferType : public HLSLStructuredBufferTypeBase
{
SLANG_AST_CLASS(HLSLAppendStructuredBufferType)
};
class HLSLConsumeStructuredBufferType : public HLSLStructuredBufferTypeBase
{
SLANG_AST_CLASS(HLSLConsumeStructuredBufferType)
};
class HLSLPatchType : public BuiltinType
{
SLANG_AST_CLASS(HLSLPatchType)
Type* getElementType();
IntVal* getElementCount();
};
class HLSLInputPatchType : public HLSLPatchType
{
SLANG_AST_CLASS(HLSLInputPatchType)
};
class HLSLOutputPatchType : public HLSLPatchType
{
SLANG_AST_CLASS(HLSLOutputPatchType)
};
// HLSL geometry shader output stream types
class HLSLStreamOutputType : public BuiltinGenericType
{
SLANG_AST_CLASS(HLSLStreamOutputType)
};
class HLSLPointStreamType : public HLSLStreamOutputType
{
SLANG_AST_CLASS(HLSLPointStreamType)
};
class HLSLLineStreamType : public HLSLStreamOutputType
{
SLANG_AST_CLASS(HLSLLineStreamType)
};
class HLSLTriangleStreamType : public HLSLStreamOutputType
{
SLANG_AST_CLASS(HLSLTriangleStreamType)
};
//
class GLSLInputAttachmentType : public BuiltinType
{
SLANG_AST_CLASS(GLSLInputAttachmentType)
};
// Base class for types used when desugaring parameter block
// declarations, includeing HLSL `cbuffer` or GLSL `uniform` blocks.
class ParameterGroupType : public PointerLikeType
{
SLANG_AST_CLASS(ParameterGroupType)
};
class UniformParameterGroupType : public ParameterGroupType
{
SLANG_AST_CLASS(UniformParameterGroupType)
};
class VaryingParameterGroupType : public ParameterGroupType
{
SLANG_AST_CLASS(VaryingParameterGroupType)
};
// type for HLSL `cbuffer` declarations, and `ConstantBuffer<T>`
// ALso used for GLSL `uniform` blocks.
class ConstantBufferType : public UniformParameterGroupType
{
SLANG_AST_CLASS(ConstantBufferType)
};
// type for HLSL `tbuffer` declarations, and `TextureBuffer<T>`
class TextureBufferType : public UniformParameterGroupType
{
SLANG_AST_CLASS(TextureBufferType)
};
// type for GLSL `in` and `out` blocks
class GLSLInputParameterGroupType : public VaryingParameterGroupType
{
SLANG_AST_CLASS(GLSLInputParameterGroupType)
};
class GLSLOutputParameterGroupType : public VaryingParameterGroupType
{
SLANG_AST_CLASS(GLSLOutputParameterGroupType)
};
// type for GLLSL `buffer` blocks
class GLSLShaderStorageBufferType : public UniformParameterGroupType
{
SLANG_AST_CLASS(GLSLShaderStorageBufferType)
};
// type for Slang `ParameterBlock<T>` type
class ParameterBlockType : public UniformParameterGroupType
{
SLANG_AST_CLASS(ParameterBlockType)
};
class ArrayExpressionType : public Type
{
SLANG_AST_CLASS(ArrayExpressionType)
Type* baseType = nullptr;
IntVal* arrayLength = nullptr;
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
Type* _createCanonicalTypeOverride();
bool _equalsImplOverride(Type* type);
Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff);
HashCode _getHashCodeOverride();
};
// The "type" of an expression that resolves to a type.
// For example, in the expression `float(2)` the sub-expression,
// `float` would have the type `TypeType(float)`.
class TypeType : public Type
{
SLANG_AST_CLASS(TypeType)
// The type that this is the type of...
Type* type = nullptr;
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
Type* _createCanonicalTypeOverride();
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
protected:
TypeType(Type* type)
: type(type)
{}
};
// A vector type, e.g., `vector<T,N>`
class VectorExpressionType : public ArithmeticExpressionType
{
SLANG_AST_CLASS(VectorExpressionType)
// The type of vector elements.
// As an invariant, this should be a basic type or an alias.
Type* elementType = nullptr;
// The number of elements
IntVal* elementCount = nullptr;
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
BasicExpressionType* _getScalarTypeOverride();
};
// A matrix type, e.g., `matrix<T,R,C>`
class MatrixExpressionType : public ArithmeticExpressionType
{
SLANG_AST_CLASS(MatrixExpressionType)
Type* getElementType();
IntVal* getRowCount();
IntVal* getColumnCount();
Type* getRowType();
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
BasicExpressionType* _getScalarTypeOverride();
private:
Type* rowType = nullptr;
};
// The built-in `String` type
class StringType : public BuiltinType
{
SLANG_AST_CLASS(StringType)
};
// The built-in `__Dynamic` type
class DynamicType : public BuiltinType
{
SLANG_AST_CLASS(DynamicType)
};
// Type built-in `__EnumType` type
class EnumTypeType : public BuiltinType
{
SLANG_AST_CLASS(EnumTypeType)
// TODO: provide accessors for the declaration, the "tag" type, etc.
};
// Base class for types that map down to
// simple pointers as part of code generation.
class PtrTypeBase : public BuiltinType
{
SLANG_AST_CLASS(PtrTypeBase)
// Get the type of the pointed-to value.
Type* getValueType();
};
// A true (user-visible) pointer type, e.g., `T*`
class PtrType : public PtrTypeBase
{
SLANG_AST_CLASS(PtrType)
};
// A type that represents the behind-the-scenes
// logical pointer that is passed for an `out`
// or `in out` parameter
class OutTypeBase : public PtrTypeBase
{
SLANG_AST_CLASS(OutTypeBase)
};
// The type for an `out` parameter, e.g., `out T`
class OutType : public OutTypeBase
{
SLANG_AST_CLASS(OutType)
};
// The type for an `in out` parameter, e.g., `in out T`
class InOutType : public OutTypeBase
{
SLANG_AST_CLASS(InOutType)
};
// The type for an `ref` parameter, e.g., `ref T`
class RefType : public PtrTypeBase
{
SLANG_AST_CLASS(RefType)
};
// A type alias of some kind (e.g., via `typedef`)
class NamedExpressionType : public Type
{
SLANG_AST_CLASS(NamedExpressionType)
DeclRef<TypeDefDecl> declRef;
Type* innerType = nullptr;
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
Type* _createCanonicalTypeOverride();
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
protected:
NamedExpressionType(
DeclRef<TypeDefDecl> declRef)
: declRef(declRef)
{}
};
// A function type is defined by its parameter types
// and its result type.
class FuncType : public Type
{
SLANG_AST_CLASS(FuncType)
// TODO: We may want to preserve parameter names
// in the list here, just so that we can print
// out friendly names when printing a function
// type, even if they don't affect the actual
// semantic type underneath.
List<Type*> paramTypes;
Type* resultType = nullptr;
UInt getParamCount() { return paramTypes.getCount(); }
Type* getParamType(UInt index) { return paramTypes[index]; }
Type* getResultType() { return resultType; }
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
Type* _createCanonicalTypeOverride();
Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff);
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
};
// The "type" of an expression that names a generic declaration.
class GenericDeclRefType : public Type
{
SLANG_AST_CLASS(GenericDeclRefType)
DeclRef<GenericDecl> declRef;
DeclRef<GenericDecl> const& getDeclRef() const { return declRef; }
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
Type* _createCanonicalTypeOverride();
protected:
GenericDeclRefType(
DeclRef<GenericDecl> declRef)
: declRef(declRef)
{}
};
// The "type" of a reference to a module or namespace
class NamespaceType : public Type
{
SLANG_AST_CLASS(NamespaceType)
DeclRef<NamespaceDeclBase> declRef;
DeclRef<NamespaceDeclBase> const& getDeclRef() const { return declRef; }
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
Type* _createCanonicalTypeOverride();
};
// The concrete type for a value wrapped in an existential, accessible
// when the existential is "opened" in some context.
class ExtractExistentialType : public Type
{
SLANG_AST_CLASS(ExtractExistentialType)
DeclRef<VarDeclBase> declRef;
// A reference to the original interface this type is known
// to be a subtype of.
//
Type* originalInterfaceType;
DeclRef<InterfaceDecl> originalInterfaceDeclRef;
// Following fields will not be reflected (and thus won't be serialized, etc.)
SLANG_UNREFLECTED
// A cached decl-ref to the original interface above, with
// a this-type substitution that refers to the type extracted here.
//
// This field is optional and can be filled in on-demand. It does *not*
// represent part of the logical value of this `Type`, and should not
// be serialized, included in hashes, etc.
//
DeclRef<InterfaceDecl> cachedSpecializedInterfaceDeclRef;
// A cached pointer to a witness that shows how this type is a subtype
// of `originalInterfaceType`.
//
SubtypeWitness* cachedSubtypeWitness = nullptr;
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
Type* _createCanonicalTypeOverride();
Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff);
/// Get a witness that shows how this type is a subtype of `originalInterfaceType`.
///
/// This operation may create the witness on demand and cache it.
///
SubtypeWitness* getSubtypeWitness();
/// Get a interface decl-ref for the original interface specialized to this type
/// (using a type-type substitution).
///
/// This operation may create the decl-ref on demand and cache it.
///
DeclRef<InterfaceDecl> getSpecializedInterfaceDeclRef();
};
/// A tagged union of zero or more other types.
class TaggedUnionType : public Type
{
SLANG_AST_CLASS(TaggedUnionType)
/// The distinct "cases" the tagged union can store.
///
/// For each type in this array, the array index is the
/// tag value for that case.
///
List<Type*> caseTypes;
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
Type* _createCanonicalTypeOverride();
Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff);
};
class ExistentialSpecializedType : public Type
{
SLANG_AST_CLASS(ExistentialSpecializedType)
Type* baseType = nullptr;
ExpandedSpecializationArgs args;
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
Type* _createCanonicalTypeOverride();
Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff);
};
/// The type of `this` within a polymorphic declaration
class ThisType : public Type
{
SLANG_AST_CLASS(ThisType)
DeclRef<InterfaceDecl> interfaceDeclRef;
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
Type* _createCanonicalTypeOverride();
Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff);
};
/// The type of `A & B` where `A` and `B` are types
///
/// A value `v` is of type `A & B` if it is both of type `A` and of type `B`.
class AndType : public Type
{
SLANG_AST_CLASS(AndType)
Type* left;
Type* right;
// Overrides should be public so base classes can access
void _toTextOverride(StringBuilder& out);
bool _equalsImplOverride(Type* type);
HashCode _getHashCodeOverride();
Type* _createCanonicalTypeOverride();
Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff);
};
} // namespace Slang
|