UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TypeVariable.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2// uLang Compiler Public API
3
4#pragma once
5
13
14namespace uLang
15{
16// Forward declarations.
17class CDataDefinition;
18class CExprDefinition;
19
21{
22public:
23 static const CDefinition::EKind StaticDefinitionKind = CDefinition::EKind::TypeVariable;
24 static const ETypeKind StaticTypeKind = ETypeKind::Variable;
25
26 // A parameter `X` of type `type(A, B)` is encoded as
27 // @code
28 // :type(Y, Y) where Y:type(A, Z), Z:type(Y, B)
29 // @endcode
30 // with all uses resolving to `Z`. Upon instantiation,
31 // @code
32 // :type(Y, Y)
33 // @endcode
34 // is rewritten to effectively
35 // @code
36 // :type(Y, Z)
37 // @endcode
38 // Any negative uses (outside of the negative use above) is replaced with
39 // `Y`, while positive uses (again, outside of the above) are replaced with
40 // `Z`. `_ExplicitParam` points to the corresponding data definition. of the
41 // original explicit argument.
43 // `_NegativeTypeVariable` points to `Y` in the original encoding.
44 // `_ExplicitParam->_ImplicitParam` can be used to access `Z`.
46
47 CTypeVariable(const CSymbol& Name, const CTypeBase* NegativeType, const CTypeBase* PositiveType, CScope& EnclosingScope)
50 , _NegativeType{NegativeType}
51 , _PositiveType{PositiveType}
52 {
53 }
54
55 const CTypeBase* GetNegativeType() const { return _NegativeType; }
56 void SetNegativeType(const CTypeBase* NegativeType) { _NegativeType = NegativeType; }
57
58 const CTypeBase* GetPositiveType() const { return _PositiveType; }
59 void SetPositiveType(const CTypeBase* PositiveType) { _PositiveType = PositiveType; }
60
61 virtual EComparability GetComparability() const override
62 {
64 return TypeType ? TypeType->PositiveType()->GetNormalType().GetComparability() : EComparability::Incomparable;
65 }
66
67 // CNominalType interface.
68 virtual const CDefinition* Definition() const override { return this; }
69
70 // CTypeBase interface.
75 virtual bool CanBeCustomAccessorDataType() const override { return false; };
76
77 // CDefinition interface.
80
82 CExprDefinition* GetIrNode(bool bForce = false) const { return static_cast<CExprDefinition*>(CDefinition::GetIrNode(bForce)); }
83
84 virtual bool IsPersistenceCompatConstraint() const override { return false; }
85
86 virtual bool IsPersistable() const override { return false; }
87
88 virtual bool IsExplicitlyCastable() const override
89 {
90 if (!_PositiveType)
91 {
92 return false;
93 }
94 const CTypeType* TypeType = _PositiveType->GetNormalType().AsNullable<CTypeType>();
95 if (!TypeType)
96 {
97 return false;
98 }
99 if (TypeType->IsCastableSubtype())
100 {
101 return true;
102 }
103 return false;
104 }
105
106 virtual bool IsExplicitlyConcrete() const override
107 {
108 if (!_PositiveType)
109 {
110 return false;
111 }
112 const CTypeType* TypeType = _PositiveType->GetNormalType().AsNullable<CTypeType>();
113 if (!TypeType)
114 {
115 return false;
116 }
117 if (TypeType->IsConcreteSubtype())
118 {
119 return true;
120 }
121 return false;
122 }
123
124private:
125 const CTypeBase* _NegativeType = nullptr;
126 const CTypeBase* _PositiveType = nullptr;
127};
128}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition DataDefinition.h:41
const CTypeVariable * _ImplicitParam
Definition DataDefinition.h:53
Definition Definition.h:131
void SetAstNode(CExpressionBase *AstNode)
Definition Definition.h:329
CExpressionBase * GetAstNode() const
Definition Definition.h:231
EKind
Definition Definition.h:135
void SetIrNode(CExpressionBase *IrNode)
Definition Definition.h:334
CExpressionBase * GetIrNode(bool bForce=false) const
Definition Definition.h:232
Definition Expression.h:1249
ULANG_FORCEINLINE CUTF8StringView AsNameStringView() const
Definition Named.h:44
Class defining instance and class objects.
Definition SemanticTypes.h:608
TType * AsNullable()
Definition SemanticTypes.h:233
Definition SemanticScope.h:73
Symbol representing a text string with an associated id.
Definition Symbol.h:98
Base class for all types.
Definition SemanticTypes.h:138
virtual const CNormalType & GetNormalType() const =0
CSemanticProgram & GetProgram() const
Definition SemanticTypes.h:143
Definition SemanticTypes.h:381
Definition TypeVariable.h:21
static const CDefinition::EKind StaticDefinitionKind
Definition TypeVariable.h:23
const CTypeBase * GetNegativeType() const
Definition TypeVariable.h:55
CTypeVariable(const CSymbol &Name, const CTypeBase *NegativeType, const CTypeBase *PositiveType, CScope &EnclosingScope)
Definition TypeVariable.h:47
virtual const CDefinition * Definition() const override
Definition TypeVariable.h:68
virtual EComparability GetComparability() const override
Definition TypeVariable.h:61
void SetNegativeType(const CTypeBase *NegativeType)
Definition TypeVariable.h:56
virtual bool IsPersistable() const override
Definition TypeVariable.h:86
const CTypeBase * GetPositiveType() const
Definition TypeVariable.h:58
CExprDefinition * GetIrNode(bool bForce=false) const
Definition TypeVariable.h:82
virtual bool CanBeCustomAccessorDataType() const override
Definition TypeVariable.h:75
void SetIrNode(CExprDefinition *AstNode)
Definition TypeVariable.h:81
void SetPositiveType(const CTypeBase *PositiveType)
Definition TypeVariable.h:59
const CTypeVariable * _NegativeTypeVariable
Definition TypeVariable.h:45
CExprDefinition * GetAstNode() const
Definition TypeVariable.h:79
void SetAstNode(CExprDefinition *AstNode)
Definition TypeVariable.h:78
static const ETypeKind StaticTypeKind
Definition TypeVariable.h:24
const CDataDefinition * _ExplicitParam
Definition TypeVariable.h:42
virtual CUTF8String AsCodeRecursive(ETypeSyntaxPrecedence OuterPrecedence, TArray< const CFlowType * > &VisitedFlowTypes, bool bLinkable, ETypeStringFlag Flag) const override
Definition TypeVariable.h:71
virtual bool IsExplicitlyCastable() const override
Definition TypeVariable.h:88
virtual bool IsPersistenceCompatConstraint() const override
Definition TypeVariable.h:84
virtual bool IsExplicitlyConcrete() const override
Definition TypeVariable.h:106
Definition Array.h:51
Definition VVMEngineEnvironment.h:23
ETypeSyntaxPrecedence
Definition SemanticTypes.h:100
ETypeKind
Definition SemanticTypes.h:92
ETypeStringFlag
Definition SemanticTypes.h:121
EComparability
Definition SemanticTypes.h:113