Files
UnrealEngineUWP/Engine/Source/Developer/ShaderCompilerCommon/Private/HlslAST.cpp

1442 lines
27 KiB
C++
Raw Normal View History

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
HlslAST.cpp - Abstract Syntax Tree implementation for HLSL.
=============================================================================*/
#include "HlslAST.h"
namespace CrossCompiler
{
namespace AST
{
static void WriteOptionArraySize(FASTWriter& Writer, bool bIsArray, const TLinearArray<FExpression*>& ArraySize)
{
if (bIsArray && ArraySize.Num() == 0)
{
Writer << TEXT("[]");
}
else
{
for (const auto* Dimension : ArraySize)
{
Writer << (TCHAR)'[';
Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main) #lockdown Ben.Marsh ========================== MAJOR FEATURES + CHANGES ========================== Change 2762805 on 2015/11/11 by Bob.Tellez #UE4 Material editor optimization. FindShaderTypeByName now uses the precreated map to look up types by name. Also changed GetRepresentativeShaderTypesAndDescriptions to return a map. #rb Daniel.Wright Change 2763372 on 2015/11/11 by Marcus.Wassmer Auto events around ComputeFenceWaits No transition ensure in parallel mode. #rb Rolando.Caloca Change 2764204 on 2015/11/12 by Rolando.Caloca DevRendering - Removed reference counting on pipelines as it's not needed - Shadermap of shader types no longer owns the unique shaders per pipeline, the pipelines do - Added shader pipeline dependencies and shortened ddc entry - Dumped stats now show # shared pipelines - Added IMPLEMENT_SHADERPIPELINE_TYPE_* macros #rb Marcus.Wassmer Change 2764409 on 2015/11/12 by Marcus.Wassmer Event based GPU frame waiting. #rb Gil.Gribb Change 2764474 on 2015/11/12 by Gil.Gribb UE4 - Optimize speed tree stuff in FLocalVertexFactory::SetMesh Change 2765900 on 2015/11/13 by Marcus.Wassmer Move PS4 system event checking onto a task thread. Saves ~.1ms on gamethread #rb Lee.Clark Change 2768478 on 2015/11/16 by Marcus.Wassmer Remove flushes when locking single-mip 2d textures for writeonly on PS4 #rb Gil.Gribb #codereview Lee.Clark Change 2769532 on 2015/11/17 by Chris.Bunner Discard outdated vertex paint data when loading static mesh components. UE-22603 #rb Rolando.Caloca Change 2770002 on 2015/11/17 by Rolando.Caloca DevRendering - Prep for reentrant calls for D3D & PS4 shader compilers - Added r.D3DDumpAMDCodeXLFile to enable writing out a batch file for AMD cards (it was always generating this, now it's optional) - defaults to 1, enabled - Added r.D3DCheckShadersForDouble to enable checking for doubles when compiling shaders, speeds up a tiny bit when disabling - defaults to 1, enabled - Fixed PS4's InitFastMathDetection(), was always testing for this #rb Marcus.Wassmer #codereview Lee.Clark Change 2770103 on 2015/11/17 by Daniel.Wright Added SourceCubemapAngle to sky lights, so the incoming lighting can be rotated [CL 2771408 by Nick Penwarden in Main branch]
2015-11-18 09:31:10 -05:00
if (Dimension)
{
Dimension->Write(Writer);
}
Writer << (TCHAR)']';
}
}
}
#if 0
FNode::FNode()/* :
Prev(nullptr),
Next(nullptr)*/
{
}
#endif // 0
FNode::FNode(FLinearAllocator* Allocator, const FSourceInfo& InInfo) :
SourceInfo(InInfo),
Attributes(Allocator)/*,
Prev(nullptr),
Next(nullptr)*/
{
}
void FASTWriter::DoIndent()
{
int32 N = Indent;
while (--N >= 0)
{
(*this) << (TCHAR)'\t';
}
}
void FNode::WriteAttributes(FASTWriter& Writer) const
{
if (Attributes.Num() > 0)
{
for (auto* Attr : Attributes)
{
Attr->Write(Writer);
}
Writer << (TCHAR)' ';
}
}
Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main) #lockdown nick.penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2771498 on 2015/11/18 by Rolando.Caloca DevRendering - HlslParser - Do not crash if an unknown preprocessor directive is found; add proper support for #pragma #codereview Marcus.Wassmer Change 2771600 on 2015/11/18 by Rolando.Caloca DevRendering - SCW - Added support for running the platform shader compiler for one usf file off the dumped usf Usage: ShaderCompileWorker -directcompile FILENAME.USF -entry=EntryPoint -format=PCD3D_SM5/SF_PS4/etc -vs/-ps/-gs/-hs/-ds/-cs -Also removed old communication enum from SCW #rb Daniel.Wright Change 2771647 on 2015/11/18 by Rolando.Caloca DevRendering - HlslParser - Refactored removed unused outputs code in prep for reusing a lot of this code - Entry point string now gets modified to the optimized one - Fixed parser allocator when requesting pages bigger than PageSize #rb Chris.Bunner Change 2772133 on 2015/11/18 by Chris.Bunner Removed physics shape type zeroing on Speedtree import. UE-23285 #rb Ori.Cohen Change 2772225 on 2015/11/18 by Rolando.Caloca DevRendering - Hlsl - Support for removing unused inputs on pixel shaders - Fix some shadow variable warnings #rb Chris.Bunner, Nick.Penwarden Change 2772469 on 2015/11/18 by Daniel.Wright Fixed SCW always exiting after compiling a long shader, now checks idle time starting from the end of the last compile task Automated smoke tests aren't run in standalone programs which are frequently launched as they increase the startup time (doubles startup time of SCW as shown in sampling profile) #rb Rolando.Caloca Change 2772471 on 2015/11/18 by Daniel.Wright Particle SubUV cutouts * A new asset type 'SubUV Animation' precomputes bounding geometry for every frame of a SubUV texture animation. * Particle emitters with a SubUV module can then use this SubUV Animation to render with much tigher bounding geometry to reduce overdraw. * GPU performance savings depend on how much empty space (zero alpha) existed in the texture. Measured a reduction of 2-3x GPU time on a smoke effect. * This only works if the material does not modify opacity to reveal areas with zero texture alpha Change 2772483 on 2015/11/18 by Marcus.Wassmer Filtering options on UnrealPak -list #rb Josh.Adams Change 2772644 on 2015/11/18 by Daniel.Wright Integrate - Temporal AA dithering is only enabled if outputting to a low precision format #rb Nick.Penwarden Change 2773336 on 2015/11/19 by Rolando.Caloca DevRendering - PS4 shaders - Added input/output attribute information when r.PS4StripExtraShaderBinaryData=0 #rb Marcus.Wassmer Change 2773476 on 2015/11/19 by Rolando.Caloca DevRendering - PS4 Shader attribute export stats Run using r.PS4DumpExportStats 1 in the console - Also fixed non-vertex shaders not getting optional data #codereview Marcus.Wassmer Change 2773865 on 2015/11/19 by Gil.Gribb UE4 - Added an FName churn tracker. Change 2773900 on 2015/11/19 by Rolando.Caloca DevRendering - Fix sharing shaders for material & mesh shaders #rb Marcus.Wassmer Change 2774277 on 2015/11/19 by Gil.Gribb UE4 - Did minor optimizations to the PS4 RHI and drawlists. Change 2774421 on 2015/11/19 by Olaf.Piesche Fix #2 for UE-23325 - separate translucency materials don't show in static mesh editor #codereview Martin.Mittring Change 2774447 on 2015/11/19 by Rolando.Caloca DevRendering - Velocity and Depth shader pipelines #rb Marcus.Wassmer Change 2774603 on 2015/11/19 by Marcus.Wassmer Windowed vsync for ps4 #rb Rolando.Caloca Change 2775650 on 2015/11/20 by Rolando.Caloca DevRendering - Added two utility overloads per UDN suggestion #codereview Gil.Gribb Change 2775798 on 2015/11/20 by David.Hill Adding a new AutoExposure method #rb Martin.Mittring Change 2776345 on 2015/11/20 by Daniel.Wright Capsule shadows for movable skylight * Gathers capsule occlusion along the unoccluded sky cone computed by Distance Field Ambient Occlusion * Requires DFAO to be enabled at the moment * Some serious artifacts remaining in indoor scenarios, as the unoccluded sky direction is not continuous Change 2777033 on 2015/11/22 by Uriel.Doyon Enabled SceneTextures node validation when material domain is DeferredDecal #review Martin.Mittring #jira UE-23141 Change 2778618 on 2015/11/23 by Daniel.Wright
2015-12-10 21:55:37 -05:00
FPragma::FPragma(FLinearAllocator* InAllocator, const TCHAR* InPragma, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo)
{
Pragma = InAllocator->Strdup(InPragma);
}
void FPragma::Write(FASTWriter& Writer) const
{
Writer << Pragma << TEXT("\n");
}
FExpression::FExpression(FLinearAllocator* InAllocator, EOperators InOperator, FExpression* E0, FExpression* E1, FExpression* E2, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Operator(InOperator),
Identifier(nullptr),
Expressions(InAllocator)
{
SubExpressions[0] = E0;
SubExpressions[1] = E1;
SubExpressions[2] = E2;
TypeSpecifier = 0;
}
void FExpression::WriteOperator(FASTWriter& Writer) const
{
switch (Operator)
{
case EOperators::Plus:
Writer << TEXT("+");
break;
Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main) #lockdown Ben.Marsh ========================== MAJOR FEATURES + CHANGES ========================== Change 2762805 on 2015/11/11 by Bob.Tellez #UE4 Material editor optimization. FindShaderTypeByName now uses the precreated map to look up types by name. Also changed GetRepresentativeShaderTypesAndDescriptions to return a map. #rb Daniel.Wright Change 2763372 on 2015/11/11 by Marcus.Wassmer Auto events around ComputeFenceWaits No transition ensure in parallel mode. #rb Rolando.Caloca Change 2764204 on 2015/11/12 by Rolando.Caloca DevRendering - Removed reference counting on pipelines as it's not needed - Shadermap of shader types no longer owns the unique shaders per pipeline, the pipelines do - Added shader pipeline dependencies and shortened ddc entry - Dumped stats now show # shared pipelines - Added IMPLEMENT_SHADERPIPELINE_TYPE_* macros #rb Marcus.Wassmer Change 2764409 on 2015/11/12 by Marcus.Wassmer Event based GPU frame waiting. #rb Gil.Gribb Change 2764474 on 2015/11/12 by Gil.Gribb UE4 - Optimize speed tree stuff in FLocalVertexFactory::SetMesh Change 2765900 on 2015/11/13 by Marcus.Wassmer Move PS4 system event checking onto a task thread. Saves ~.1ms on gamethread #rb Lee.Clark Change 2768478 on 2015/11/16 by Marcus.Wassmer Remove flushes when locking single-mip 2d textures for writeonly on PS4 #rb Gil.Gribb #codereview Lee.Clark Change 2769532 on 2015/11/17 by Chris.Bunner Discard outdated vertex paint data when loading static mesh components. UE-22603 #rb Rolando.Caloca Change 2770002 on 2015/11/17 by Rolando.Caloca DevRendering - Prep for reentrant calls for D3D & PS4 shader compilers - Added r.D3DDumpAMDCodeXLFile to enable writing out a batch file for AMD cards (it was always generating this, now it's optional) - defaults to 1, enabled - Added r.D3DCheckShadersForDouble to enable checking for doubles when compiling shaders, speeds up a tiny bit when disabling - defaults to 1, enabled - Fixed PS4's InitFastMathDetection(), was always testing for this #rb Marcus.Wassmer #codereview Lee.Clark Change 2770103 on 2015/11/17 by Daniel.Wright Added SourceCubemapAngle to sky lights, so the incoming lighting can be rotated [CL 2771408 by Nick Penwarden in Main branch]
2015-11-18 09:31:10 -05:00
case EOperators::Minus:
Writer << TEXT("-");
break;
case EOperators::Assign:
Writer << TEXT("=");
break;
case EOperators::AddAssign:
Writer << TEXT("+=");
break;
case EOperators::SubAssign:
Writer << TEXT("-=");
break;
case EOperators::MulAssign:
Writer << TEXT("*=");
break;
case EOperators::DivAssign:
Writer << TEXT("/=");
break;
case EOperators::ModAssign:
Writer << TEXT("%=");
break;
case EOperators::RSAssign:
Writer << TEXT(">>=");
break;
case EOperators::LSAssign:
Writer << TEXT("<<=");
break;
case EOperators::AndAssign:
Writer << TEXT("&=");
break;
case EOperators::OrAssign:
Writer << TEXT("|=");
break;
case EOperators::XorAssign:
Writer << TEXT("^=");
break;
case EOperators::Conditional:
Writer << TEXT("?");
break;
case EOperators::LogicOr:
Writer << TEXT("||");
break;
case EOperators::LogicAnd:
Writer << TEXT("&&");
break;
case EOperators::LogicNot:
Writer << TEXT("!");
break;
case EOperators::BitOr:
Writer << TEXT("|");
break;
case EOperators::BitXor:
Writer << TEXT("^");
break;
case EOperators::BitAnd:
Writer << TEXT("&");
break;
Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main) #lockdown Ben.Marsh ========================== MAJOR FEATURES + CHANGES ========================== Change 2762805 on 2015/11/11 by Bob.Tellez #UE4 Material editor optimization. FindShaderTypeByName now uses the precreated map to look up types by name. Also changed GetRepresentativeShaderTypesAndDescriptions to return a map. #rb Daniel.Wright Change 2763372 on 2015/11/11 by Marcus.Wassmer Auto events around ComputeFenceWaits No transition ensure in parallel mode. #rb Rolando.Caloca Change 2764204 on 2015/11/12 by Rolando.Caloca DevRendering - Removed reference counting on pipelines as it's not needed - Shadermap of shader types no longer owns the unique shaders per pipeline, the pipelines do - Added shader pipeline dependencies and shortened ddc entry - Dumped stats now show # shared pipelines - Added IMPLEMENT_SHADERPIPELINE_TYPE_* macros #rb Marcus.Wassmer Change 2764409 on 2015/11/12 by Marcus.Wassmer Event based GPU frame waiting. #rb Gil.Gribb Change 2764474 on 2015/11/12 by Gil.Gribb UE4 - Optimize speed tree stuff in FLocalVertexFactory::SetMesh Change 2765900 on 2015/11/13 by Marcus.Wassmer Move PS4 system event checking onto a task thread. Saves ~.1ms on gamethread #rb Lee.Clark Change 2768478 on 2015/11/16 by Marcus.Wassmer Remove flushes when locking single-mip 2d textures for writeonly on PS4 #rb Gil.Gribb #codereview Lee.Clark Change 2769532 on 2015/11/17 by Chris.Bunner Discard outdated vertex paint data when loading static mesh components. UE-22603 #rb Rolando.Caloca Change 2770002 on 2015/11/17 by Rolando.Caloca DevRendering - Prep for reentrant calls for D3D & PS4 shader compilers - Added r.D3DDumpAMDCodeXLFile to enable writing out a batch file for AMD cards (it was always generating this, now it's optional) - defaults to 1, enabled - Added r.D3DCheckShadersForDouble to enable checking for doubles when compiling shaders, speeds up a tiny bit when disabling - defaults to 1, enabled - Fixed PS4's InitFastMathDetection(), was always testing for this #rb Marcus.Wassmer #codereview Lee.Clark Change 2770103 on 2015/11/17 by Daniel.Wright Added SourceCubemapAngle to sky lights, so the incoming lighting can be rotated [CL 2771408 by Nick Penwarden in Main branch]
2015-11-18 09:31:10 -05:00
case EOperators::BitNeg:
Writer << TEXT("~");
break;
case EOperators::Equal:
Writer << TEXT("==");
break;
case EOperators::NEqual:
Writer << TEXT("!=");
break;
case EOperators::Less:
Writer << TEXT("<");
break;
case EOperators::Greater:
Writer << TEXT(">");
break;
case EOperators::LEqual:
Writer << TEXT("<=");
break;
case EOperators::GEqual:
Writer << TEXT(">=");
break;
case EOperators::LShift:
Writer << TEXT("<<");
break;
case EOperators::RShift:
Writer << TEXT(">>");
break;
case EOperators::Add:
Writer << TEXT("+");
break;
case EOperators::Sub:
Writer << TEXT("-");
break;
case EOperators::Mul:
Writer << TEXT("*");
break;
case EOperators::Div:
Writer << TEXT("/");
break;
case EOperators::Mod:
Writer << TEXT("%");
break;
case EOperators::PreInc:
Writer << TEXT("++");
break;
case EOperators::PreDec:
Writer << TEXT("--");
break;
case EOperators::Identifier:
Writer << Identifier;
break;
case EOperators::UintConstant:
case EOperators::BoolConstant:
Writer << UintConstant;
break;
case EOperators::FloatConstant:
Writer << FloatConstant;
break;
case EOperators::InitializerList:
// Nothing...
break;
case EOperators::PostInc:
case EOperators::PostDec:
case EOperators::FieldSelection:
case EOperators::ArrayIndex:
break;
case EOperators::TypeCast:
Writer << (TCHAR)'(';
TypeSpecifier->Write(Writer);
Writer << TEXT(")");
break;
default:
Writer << TEXT("*MISSING_");
Writer << (uint32)Operator;
Writer << (TCHAR)'*';
Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main) #lockdown Ben.Marsh ========================== MAJOR FEATURES + CHANGES ========================== Change 2762805 on 2015/11/11 by Bob.Tellez #UE4 Material editor optimization. FindShaderTypeByName now uses the precreated map to look up types by name. Also changed GetRepresentativeShaderTypesAndDescriptions to return a map. #rb Daniel.Wright Change 2763372 on 2015/11/11 by Marcus.Wassmer Auto events around ComputeFenceWaits No transition ensure in parallel mode. #rb Rolando.Caloca Change 2764204 on 2015/11/12 by Rolando.Caloca DevRendering - Removed reference counting on pipelines as it's not needed - Shadermap of shader types no longer owns the unique shaders per pipeline, the pipelines do - Added shader pipeline dependencies and shortened ddc entry - Dumped stats now show # shared pipelines - Added IMPLEMENT_SHADERPIPELINE_TYPE_* macros #rb Marcus.Wassmer Change 2764409 on 2015/11/12 by Marcus.Wassmer Event based GPU frame waiting. #rb Gil.Gribb Change 2764474 on 2015/11/12 by Gil.Gribb UE4 - Optimize speed tree stuff in FLocalVertexFactory::SetMesh Change 2765900 on 2015/11/13 by Marcus.Wassmer Move PS4 system event checking onto a task thread. Saves ~.1ms on gamethread #rb Lee.Clark Change 2768478 on 2015/11/16 by Marcus.Wassmer Remove flushes when locking single-mip 2d textures for writeonly on PS4 #rb Gil.Gribb #codereview Lee.Clark Change 2769532 on 2015/11/17 by Chris.Bunner Discard outdated vertex paint data when loading static mesh components. UE-22603 #rb Rolando.Caloca Change 2770002 on 2015/11/17 by Rolando.Caloca DevRendering - Prep for reentrant calls for D3D & PS4 shader compilers - Added r.D3DDumpAMDCodeXLFile to enable writing out a batch file for AMD cards (it was always generating this, now it's optional) - defaults to 1, enabled - Added r.D3DCheckShadersForDouble to enable checking for doubles when compiling shaders, speeds up a tiny bit when disabling - defaults to 1, enabled - Fixed PS4's InitFastMathDetection(), was always testing for this #rb Marcus.Wassmer #codereview Lee.Clark Change 2770103 on 2015/11/17 by Daniel.Wright Added SourceCubemapAngle to sky lights, so the incoming lighting can be rotated [CL 2771408 by Nick Penwarden in Main branch]
2015-11-18 09:31:10 -05:00
checkf(0, TEXT("Unhandled AST Operator %d!"), Operator);
break;
}
}
void FExpression::Write(FASTWriter& Writer) const
{
switch (Operator)
{
case EOperators::Conditional:
Writer << (TCHAR)'(';
SubExpressions[0]->Write(Writer);
Writer << TEXT(" ? ");
SubExpressions[1]->Write(Writer);
Writer << TEXT(" : ");
SubExpressions[2]->Write(Writer);
Writer << TEXT(")");
break;
default:
Writer << TEXT("*MISSING_");
Writer << (uint32)Operator;
Writer << (TCHAR)'*';
Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main) #lockdown Ben.Marsh ========================== MAJOR FEATURES + CHANGES ========================== Change 2762805 on 2015/11/11 by Bob.Tellez #UE4 Material editor optimization. FindShaderTypeByName now uses the precreated map to look up types by name. Also changed GetRepresentativeShaderTypesAndDescriptions to return a map. #rb Daniel.Wright Change 2763372 on 2015/11/11 by Marcus.Wassmer Auto events around ComputeFenceWaits No transition ensure in parallel mode. #rb Rolando.Caloca Change 2764204 on 2015/11/12 by Rolando.Caloca DevRendering - Removed reference counting on pipelines as it's not needed - Shadermap of shader types no longer owns the unique shaders per pipeline, the pipelines do - Added shader pipeline dependencies and shortened ddc entry - Dumped stats now show # shared pipelines - Added IMPLEMENT_SHADERPIPELINE_TYPE_* macros #rb Marcus.Wassmer Change 2764409 on 2015/11/12 by Marcus.Wassmer Event based GPU frame waiting. #rb Gil.Gribb Change 2764474 on 2015/11/12 by Gil.Gribb UE4 - Optimize speed tree stuff in FLocalVertexFactory::SetMesh Change 2765900 on 2015/11/13 by Marcus.Wassmer Move PS4 system event checking onto a task thread. Saves ~.1ms on gamethread #rb Lee.Clark Change 2768478 on 2015/11/16 by Marcus.Wassmer Remove flushes when locking single-mip 2d textures for writeonly on PS4 #rb Gil.Gribb #codereview Lee.Clark Change 2769532 on 2015/11/17 by Chris.Bunner Discard outdated vertex paint data when loading static mesh components. UE-22603 #rb Rolando.Caloca Change 2770002 on 2015/11/17 by Rolando.Caloca DevRendering - Prep for reentrant calls for D3D & PS4 shader compilers - Added r.D3DDumpAMDCodeXLFile to enable writing out a batch file for AMD cards (it was always generating this, now it's optional) - defaults to 1, enabled - Added r.D3DCheckShadersForDouble to enable checking for doubles when compiling shaders, speeds up a tiny bit when disabling - defaults to 1, enabled - Fixed PS4's InitFastMathDetection(), was always testing for this #rb Marcus.Wassmer #codereview Lee.Clark Change 2770103 on 2015/11/17 by Daniel.Wright Added SourceCubemapAngle to sky lights, so the incoming lighting can be rotated [CL 2771408 by Nick Penwarden in Main branch]
2015-11-18 09:31:10 -05:00
checkf(0, TEXT("Unhandled AST Operator %d!"), Operator);
break;
}
}
FExpression::~FExpression()
{
for (auto* Expr : Expressions)
{
if (Expr)
{
delete Expr;
}
}
for (int32 Index = 0; Index < 3; ++Index)
{
if (SubExpressions[Index])
{
delete SubExpressions[Index];
}
else
{
break;
}
}
}
FUnaryExpression::FUnaryExpression(FLinearAllocator* InAllocator, EOperators InOperator, FExpression* Expr, const FSourceInfo& InInfo) :
FExpression(InAllocator, InOperator, Expr, nullptr, nullptr, InInfo)
{
}
void FUnaryExpression::Write(FASTWriter& Writer) const
{
WriteOperator(Writer);
if (SubExpressions[0])
{
if (Writer.ExpressionScope != 0)
{
Writer << (TCHAR)'(';
}
++Writer.ExpressionScope;
SubExpressions[0]->Write(Writer);
--Writer.ExpressionScope;
if (Writer.ExpressionScope != 0)
{
Writer << (TCHAR)')';
}
}
// Suffix
switch (Operator)
{
case EOperators::PostInc:
Writer << TEXT("++");
break;
case EOperators::PostDec:
Writer << TEXT("--");
break;
case EOperators::FieldSelection:
Writer << (TCHAR)'.';
Writer << Identifier;
break;
default:
break;
}
}
bool FUnaryExpression::GetConstantIntValue(int32& OutValue) const
{
if (IsConstant())
{
OutValue = (int32)GetUintConstantValue();
return true;
}
return false;
}
FBinaryExpression::FBinaryExpression(FLinearAllocator* InAllocator, EOperators InOperator, FExpression* E0, FExpression* E1, const FSourceInfo& InInfo) :
FExpression(InAllocator, InOperator, E0, E1, nullptr, InInfo)
{
}
void FBinaryExpression::Write(FASTWriter& Writer) const
{
switch (Operator)
{
case EOperators::ArrayIndex:
Writer << (TCHAR)'(';
SubExpressions[0]->Write(Writer);
Writer << TEXT(")");
Writer << (TCHAR)'[';
SubExpressions[1]->Write(Writer);
Writer << TEXT("]");
break;
default:
if (Writer.ExpressionScope != 0)
{
Writer << (TCHAR)'(';
}
++Writer.ExpressionScope;
SubExpressions[0]->Write(Writer);
Writer << (TCHAR)' ';
WriteOperator(Writer);
Writer << (TCHAR)' ';
SubExpressions[1]->Write(Writer);
--Writer.ExpressionScope;
if (Writer.ExpressionScope != 0)
{
Writer << (TCHAR)')';
}
break;
}
}
bool FBinaryExpression::GetConstantIntValue(int32& OutValue) const
{
int32 LHS = 0;
int32 RHS = 0;
if (!SubExpressions[0]->GetConstantIntValue(LHS) || !SubExpressions[1]->GetConstantIntValue(RHS))
{
return false;
}
switch (Operator)
{
default:
return false;
case EOperators::LogicOr: OutValue = LHS || RHS; break;
case EOperators::LogicAnd: OutValue = LHS && RHS; break;
case EOperators::BitOr: OutValue = LHS | RHS; break;
case EOperators::BitXor: OutValue = LHS ^ RHS; break;
case EOperators::BitAnd: OutValue = LHS ^ RHS; break;
case EOperators::Equal: OutValue = LHS == RHS; break;
case EOperators::NEqual: OutValue = LHS != RHS; break;
case EOperators::Less: OutValue = LHS < RHS; break;
case EOperators::Greater: OutValue = LHS > RHS; break;
case EOperators::LEqual: OutValue = LHS <= RHS; break;
case EOperators::GEqual: OutValue = LHS >= RHS; break;
case EOperators::LShift: OutValue = LHS << RHS; break;
case EOperators::RShift: OutValue = LHS >> RHS; break;
case EOperators::Add: OutValue = LHS + RHS; break;
case EOperators::Sub: OutValue = LHS - RHS; break;
case EOperators::Mul: OutValue = LHS * RHS; break;
case EOperators::Div: OutValue = LHS / RHS; break;
case EOperators::Mod: OutValue = LHS % RHS; break;
}
return true;
}
FExpressionStatement::FExpressionStatement(FLinearAllocator* InAllocator, FExpression* InExpr, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Expression(InExpr)
{
}
void FExpressionStatement::Write(FASTWriter& Writer) const
{
Writer.DoIndent();
Expression->Write(Writer);
Writer << TEXT(";\n");
}
FExpressionStatement::~FExpressionStatement()
{
if (Expression)
{
delete Expression;
}
}
FCompoundStatement::FCompoundStatement(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Statements(InAllocator)
{
}
void FCompoundStatement::Write(FASTWriter& Writer) const
{
Writer.DoIndent();
Writer << TEXT("{\n");
for (auto* Statement : Statements)
{
FASTWriterIncrementScope Scope(Writer);
Statement->Write(Writer);
}
Writer.DoIndent();
Writer << TEXT("}\n");
}
FCompoundStatement::~FCompoundStatement()
{
for (auto* Statement : Statements)
{
if (Statement)
{
delete Statement;
}
}
}
FFunctionDefinition::FFunctionDefinition(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Prototype(nullptr),
Body(nullptr)
{
}
void FFunctionDefinition::Write(FASTWriter& Writer) const
{
WriteAttributes(Writer);
Prototype->Write(Writer);
if (Body)
{
Body->Write(Writer);
}
}
FFunctionDefinition::~FFunctionDefinition()
{
delete Prototype;
delete Body;
}
FFunction::FFunction(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
ReturnType(nullptr),
Identifier(nullptr),
ReturnSemantic(nullptr),
Parameters(InAllocator)
{
}
void FFunction::Write(FASTWriter& Writer) const
{
WriteAttributes(Writer);
Writer << TEXT("\n");
ReturnType->Write(Writer);
Writer << (TCHAR)' ';
Writer << Identifier;
Writer << (TCHAR)'(';
bool bFirst = true;
if (Parameters.Num() > 2)
{
for (auto* Param : Parameters)
{
if (bFirst)
{
bFirst = false;
}
else
{
Writer << TEXT(",\n\t");
}
Param->Write(Writer);
}
}
else
{
for (auto* Param : Parameters)
{
if (bFirst)
{
bFirst = false;
}
else
{
Writer << TEXT(", ");
}
Param->Write(Writer);
}
}
Writer << TEXT(")");
if (ReturnSemantic && *ReturnSemantic)
{
Writer << TEXT(" : ") << ReturnSemantic;
}
Writer << TEXT("\n");
}
FFunction::~FFunction()
{
for (auto* Param : Parameters)
{
delete Param;
}
}
FJumpStatement::FJumpStatement(FLinearAllocator* InAllocator, EJumpType InType, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Type(InType),
OptionalExpression(nullptr)
{
}
void FJumpStatement::Write(FASTWriter& Writer) const
{
Writer.DoIndent();
switch (Type)
{
case EJumpType::Return:
Writer << TEXT("return");
break;
case EJumpType::Break:
Writer << TEXT("break");
break;
case EJumpType::Continue:
Writer << TEXT("continue");
break;
default:
Writer << TEXT("*MISSING_");
Writer << (uint32)Type;
Writer << (TCHAR)'*';
Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main) #lockdown Ben.Marsh ========================== MAJOR FEATURES + CHANGES ========================== Change 2762805 on 2015/11/11 by Bob.Tellez #UE4 Material editor optimization. FindShaderTypeByName now uses the precreated map to look up types by name. Also changed GetRepresentativeShaderTypesAndDescriptions to return a map. #rb Daniel.Wright Change 2763372 on 2015/11/11 by Marcus.Wassmer Auto events around ComputeFenceWaits No transition ensure in parallel mode. #rb Rolando.Caloca Change 2764204 on 2015/11/12 by Rolando.Caloca DevRendering - Removed reference counting on pipelines as it's not needed - Shadermap of shader types no longer owns the unique shaders per pipeline, the pipelines do - Added shader pipeline dependencies and shortened ddc entry - Dumped stats now show # shared pipelines - Added IMPLEMENT_SHADERPIPELINE_TYPE_* macros #rb Marcus.Wassmer Change 2764409 on 2015/11/12 by Marcus.Wassmer Event based GPU frame waiting. #rb Gil.Gribb Change 2764474 on 2015/11/12 by Gil.Gribb UE4 - Optimize speed tree stuff in FLocalVertexFactory::SetMesh Change 2765900 on 2015/11/13 by Marcus.Wassmer Move PS4 system event checking onto a task thread. Saves ~.1ms on gamethread #rb Lee.Clark Change 2768478 on 2015/11/16 by Marcus.Wassmer Remove flushes when locking single-mip 2d textures for writeonly on PS4 #rb Gil.Gribb #codereview Lee.Clark Change 2769532 on 2015/11/17 by Chris.Bunner Discard outdated vertex paint data when loading static mesh components. UE-22603 #rb Rolando.Caloca Change 2770002 on 2015/11/17 by Rolando.Caloca DevRendering - Prep for reentrant calls for D3D & PS4 shader compilers - Added r.D3DDumpAMDCodeXLFile to enable writing out a batch file for AMD cards (it was always generating this, now it's optional) - defaults to 1, enabled - Added r.D3DCheckShadersForDouble to enable checking for doubles when compiling shaders, speeds up a tiny bit when disabling - defaults to 1, enabled - Fixed PS4's InitFastMathDetection(), was always testing for this #rb Marcus.Wassmer #codereview Lee.Clark Change 2770103 on 2015/11/17 by Daniel.Wright Added SourceCubemapAngle to sky lights, so the incoming lighting can be rotated [CL 2771408 by Nick Penwarden in Main branch]
2015-11-18 09:31:10 -05:00
checkf(0, TEXT("Unhandled AST jump type %d!"), Type);
break;
}
if (OptionalExpression)
{
Writer << TEXT(" ");
OptionalExpression->Write(Writer);
}
Writer << TEXT(";\n");
}
FJumpStatement::~FJumpStatement()
{
if (OptionalExpression)
{
delete OptionalExpression;
}
}
FSelectionStatement::FSelectionStatement(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Condition(nullptr),
ThenStatement(nullptr),
ElseStatement(nullptr)
{
}
void FSelectionStatement::Write(FASTWriter& Writer) const
{
Writer.DoIndent();
WriteAttributes(Writer);
Writer << TEXT("if (");
Condition->Write(Writer);
Writer << TEXT(")\n");
ThenStatement->Write(Writer);
if (ElseStatement)
{
Writer.DoIndent();
Writer << TEXT("else\n");
ElseStatement->Write(Writer);
}
}
FSelectionStatement::~FSelectionStatement()
{
delete Condition;
delete ThenStatement;
if (ElseStatement)
{
delete ElseStatement;
}
}
FTypeSpecifier::FTypeSpecifier(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
TypeName(nullptr),
InnerType(nullptr),
Structure(nullptr),
TextureMSNumSamples(1),
PatchSize(0),
bIsArray(false),
//bIsUnsizedArray(false),
ArraySize(nullptr)
{
}
void FTypeSpecifier::Write(FASTWriter& Writer) const
{
if (Structure)
{
Structure->Write(Writer);
}
else
{
Writer << TypeName;
if (TextureMSNumSamples > 1)
{
Writer << (TCHAR)'<';
Writer << InnerType;
Writer << TEXT(", ");
Writer << (uint32)TextureMSNumSamples;
Writer << (TCHAR)'>';
}
else if (InnerType && *InnerType)
{
Writer << (TCHAR)'<';
Writer << InnerType;
Writer << (TCHAR)'>';
}
}
if (bIsArray)
{
Writer << TEXT("[ ");
if (ArraySize)
{
ArraySize->Write(Writer);
}
printf("]");
}
}
FTypeSpecifier::~FTypeSpecifier()
{
if (Structure)
{
delete Structure;
}
if (ArraySize)
{
delete ArraySize;
}
}
FCBufferDeclaration::FCBufferDeclaration(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Name(nullptr),
Declarations(InAllocator)
{
}
void FCBufferDeclaration::Write(FASTWriter& Writer) const
{
Writer.DoIndent();
Writer << TEXT("cbuffer ");
Writer << Name;
Writer << (TCHAR)'\n';
Writer.DoIndent();
Writer << TEXT("{\n");
for (auto* Declaration : Declarations)
{
FASTWriterIncrementScope Scope(Writer);
Declaration->Write(Writer);
}
Writer.DoIndent();
Writer << TEXT("}\n\n");
}
FCBufferDeclaration::~FCBufferDeclaration()
{
for (auto* Decl : Declarations)
{
delete Decl;
}
}
FTypeQualifier::FTypeQualifier()
{
Raw = 0;
}
void FTypeQualifier::Write(FASTWriter& Writer) const
{
if (bConstant)
{
Writer << TEXT("const ");
}
if (bIsStatic)
{
Writer << TEXT("static ");
}
if (bShared)
{
Writer << TEXT("groupshared ");
}
else if (bIn && bOut)
{
Writer << TEXT("inout ");
}
else if (bIn)
{
Writer << TEXT("in ");
}
else if (bOut)
{
Writer << TEXT("out ");
}
if (bLinear)
{
Writer << TEXT("linear ");
}
if (bCentroid)
{
Writer << TEXT("centroid ");
}
if (bNoInterpolation)
{
Writer << TEXT("nointerpolation ");
}
if (bNoPerspective)
{
Writer << TEXT("noperspective ");
}
if (bSample)
{
Writer << TEXT("sample ");
}
if (bRowMajor)
{
Writer << TEXT("row_major ");
}
}
FFullySpecifiedType::FFullySpecifiedType(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Specifier(nullptr)
{
}
void FFullySpecifiedType::Write(FASTWriter& Writer) const
{
Qualifier.Write(Writer);
Specifier->Write(Writer);
}
FFullySpecifiedType::~FFullySpecifiedType()
{
delete Specifier;
}
FDeclaration::FDeclaration(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Identifier(nullptr),
Semantic(nullptr),
bIsArray(false),
ArraySize(InAllocator),
Initializer(nullptr)
{
}
void FDeclaration::Write(FASTWriter& Writer) const
{
WriteAttributes(Writer);
Writer << Identifier;
WriteOptionArraySize(Writer, bIsArray, ArraySize);
if (Initializer)
{
Writer << TEXT(" = ");
Initializer->Write(Writer);
}
if (Semantic && *Semantic)
{
Writer << TEXT(" : ") << Semantic;
}
}
FDeclaration::~FDeclaration()
{
for (auto* Expr : ArraySize)
{
delete Expr;
}
if (Initializer)
{
delete Initializer;
}
}
FDeclaratorList::FDeclaratorList(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Type(nullptr),
Declarations(InAllocator)
{
}
void FDeclaratorList::Write(FASTWriter& Writer) const
{
Writer.DoIndent();
WriteAttributes(Writer);
if (Type)
{
Type->Write(Writer);
Writer << TEXT(" ");
}
bool bFirst = true;
for (auto* Decl : Declarations)
{
if (bFirst)
{
bFirst = false;
}
else
{
Writer << TEXT(", ");
}
Decl->Write(Writer);
}
Writer << TEXT(";\n");
}
FDeclaratorList::~FDeclaratorList()
{
delete Type;
for (auto* Decl : Declarations)
{
delete Decl;
}
}
FInitializerListExpression::FInitializerListExpression(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FExpression(InAllocator, EOperators::InitializerList, nullptr, nullptr, nullptr, InInfo)
{
}
void FInitializerListExpression::Write(FASTWriter& Writer) const
{
Writer << TEXT("{");
bool bFirst = true;
for (auto* Expr : Expressions)
{
if (bFirst)
{
bFirst = false;
}
else
{
Writer << TEXT(", ");
}
Expr->Write(Writer);
}
Writer << TEXT("}");
}
FParameterDeclarator::FParameterDeclarator(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Type(nullptr),
Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main) #lockdown Ben.Marsh ========================== MAJOR FEATURES + CHANGES ========================== Change 2762805 on 2015/11/11 by Bob.Tellez #UE4 Material editor optimization. FindShaderTypeByName now uses the precreated map to look up types by name. Also changed GetRepresentativeShaderTypesAndDescriptions to return a map. #rb Daniel.Wright Change 2763372 on 2015/11/11 by Marcus.Wassmer Auto events around ComputeFenceWaits No transition ensure in parallel mode. #rb Rolando.Caloca Change 2764204 on 2015/11/12 by Rolando.Caloca DevRendering - Removed reference counting on pipelines as it's not needed - Shadermap of shader types no longer owns the unique shaders per pipeline, the pipelines do - Added shader pipeline dependencies and shortened ddc entry - Dumped stats now show # shared pipelines - Added IMPLEMENT_SHADERPIPELINE_TYPE_* macros #rb Marcus.Wassmer Change 2764409 on 2015/11/12 by Marcus.Wassmer Event based GPU frame waiting. #rb Gil.Gribb Change 2764474 on 2015/11/12 by Gil.Gribb UE4 - Optimize speed tree stuff in FLocalVertexFactory::SetMesh Change 2765900 on 2015/11/13 by Marcus.Wassmer Move PS4 system event checking onto a task thread. Saves ~.1ms on gamethread #rb Lee.Clark Change 2768478 on 2015/11/16 by Marcus.Wassmer Remove flushes when locking single-mip 2d textures for writeonly on PS4 #rb Gil.Gribb #codereview Lee.Clark Change 2769532 on 2015/11/17 by Chris.Bunner Discard outdated vertex paint data when loading static mesh components. UE-22603 #rb Rolando.Caloca Change 2770002 on 2015/11/17 by Rolando.Caloca DevRendering - Prep for reentrant calls for D3D & PS4 shader compilers - Added r.D3DDumpAMDCodeXLFile to enable writing out a batch file for AMD cards (it was always generating this, now it's optional) - defaults to 1, enabled - Added r.D3DCheckShadersForDouble to enable checking for doubles when compiling shaders, speeds up a tiny bit when disabling - defaults to 1, enabled - Fixed PS4's InitFastMathDetection(), was always testing for this #rb Marcus.Wassmer #codereview Lee.Clark Change 2770103 on 2015/11/17 by Daniel.Wright Added SourceCubemapAngle to sky lights, so the incoming lighting can be rotated [CL 2771408 by Nick Penwarden in Main branch]
2015-11-18 09:31:10 -05:00
Identifier(nullptr),
Semantic(nullptr),
bIsArray(false),
ArraySize(InAllocator),
DefaultValue(nullptr)
{
}
void FParameterDeclarator::Write(FASTWriter& Writer) const
{
WriteAttributes(Writer);
Type->Write(Writer);
Writer << (TCHAR)' ' << Identifier;
WriteOptionArraySize(Writer, bIsArray, ArraySize);
if (Semantic && *Semantic)
{
Writer << TEXT(" : ") << Semantic;
}
if (DefaultValue)
{
Writer << TEXT(" = ");
DefaultValue->Write(Writer);
}
}
FParameterDeclarator* FParameterDeclarator::CreateFromDeclaratorList(FDeclaratorList* List, FLinearAllocator* Allocator)
{
check(List);
check(List->Declarations.Num() == 1);
auto* Source = (FDeclaration*)List->Declarations[0];
auto* New = new(Allocator) FParameterDeclarator(Allocator, Source->SourceInfo);
New->Type = List->Type;
New->Identifier = Source->Identifier;
New->Semantic = Source->Semantic;
New->bIsArray = Source->bIsArray;
New->ArraySize = Source->ArraySize;
New->DefaultValue = Source->Initializer;
return New;
}
FParameterDeclarator::~FParameterDeclarator()
{
delete Type;
for (auto* Expr : ArraySize)
{
delete Expr;
}
if (DefaultValue)
{
delete DefaultValue;
}
}
FIterationStatement::FIterationStatement(FLinearAllocator* InAllocator, const FSourceInfo& InInfo, EIterationType InType) :
FNode(InAllocator, InInfo),
Type(InType),
InitStatement(nullptr),
Condition(nullptr),
RestExpression(nullptr),
Body(nullptr)
{
}
void FIterationStatement::Write(FASTWriter& Writer) const
{
Writer.DoIndent();
WriteAttributes(Writer);
switch (Type)
{
case EIterationType::For:
Writer << TEXT("for (");
if (InitStatement)
{
InitStatement->Write(Writer);
{
FASTWriterIncrementScope Scope(Writer);
Writer.DoIndent();
}
}
else
{
Writer << TEXT("; ");
}
if (Condition)
{
Condition->Write(Writer);
}
Writer << TEXT(";");
if (RestExpression)
{
RestExpression->Write(Writer);
}
Writer << TEXT(")\n");
if (Body)
{
FASTWriterIncrementScope Scope(Writer);
Body->Write(Writer);
}
else
{
Writer.DoIndent();
Writer << TEXT("{\n");
Writer.DoIndent();
Writer << TEXT("}\n");
}
break;
case EIterationType::While:
Writer << TEXT("while (");
Condition->Write(Writer);
Writer << TEXT(")\n");
Writer.DoIndent();
Writer << TEXT("{\n");
if (Body)
{
FASTWriterIncrementScope Scope(Writer);
Body->Write(Writer);
}
Writer.DoIndent();
Writer << TEXT("}\n");
break;
case EIterationType::DoWhile:
Writer << TEXT("do\n");
Writer.DoIndent();
Writer << TEXT("{\n");
if (Body)
{
FASTWriterIncrementScope Scope(Writer);
Body->Write(Writer);
}
Writer.DoIndent();
Writer << TEXT("}\n");
Writer.DoIndent();
Writer << TEXT("while (");
Condition->Write(Writer);
Writer << TEXT(");\n");
break;
default:
Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main) #lockdown Ben.Marsh ========================== MAJOR FEATURES + CHANGES ========================== Change 2762805 on 2015/11/11 by Bob.Tellez #UE4 Material editor optimization. FindShaderTypeByName now uses the precreated map to look up types by name. Also changed GetRepresentativeShaderTypesAndDescriptions to return a map. #rb Daniel.Wright Change 2763372 on 2015/11/11 by Marcus.Wassmer Auto events around ComputeFenceWaits No transition ensure in parallel mode. #rb Rolando.Caloca Change 2764204 on 2015/11/12 by Rolando.Caloca DevRendering - Removed reference counting on pipelines as it's not needed - Shadermap of shader types no longer owns the unique shaders per pipeline, the pipelines do - Added shader pipeline dependencies and shortened ddc entry - Dumped stats now show # shared pipelines - Added IMPLEMENT_SHADERPIPELINE_TYPE_* macros #rb Marcus.Wassmer Change 2764409 on 2015/11/12 by Marcus.Wassmer Event based GPU frame waiting. #rb Gil.Gribb Change 2764474 on 2015/11/12 by Gil.Gribb UE4 - Optimize speed tree stuff in FLocalVertexFactory::SetMesh Change 2765900 on 2015/11/13 by Marcus.Wassmer Move PS4 system event checking onto a task thread. Saves ~.1ms on gamethread #rb Lee.Clark Change 2768478 on 2015/11/16 by Marcus.Wassmer Remove flushes when locking single-mip 2d textures for writeonly on PS4 #rb Gil.Gribb #codereview Lee.Clark Change 2769532 on 2015/11/17 by Chris.Bunner Discard outdated vertex paint data when loading static mesh components. UE-22603 #rb Rolando.Caloca Change 2770002 on 2015/11/17 by Rolando.Caloca DevRendering - Prep for reentrant calls for D3D & PS4 shader compilers - Added r.D3DDumpAMDCodeXLFile to enable writing out a batch file for AMD cards (it was always generating this, now it's optional) - defaults to 1, enabled - Added r.D3DCheckShadersForDouble to enable checking for doubles when compiling shaders, speeds up a tiny bit when disabling - defaults to 1, enabled - Fixed PS4's InitFastMathDetection(), was always testing for this #rb Marcus.Wassmer #codereview Lee.Clark Change 2770103 on 2015/11/17 by Daniel.Wright Added SourceCubemapAngle to sky lights, so the incoming lighting can be rotated [CL 2771408 by Nick Penwarden in Main branch]
2015-11-18 09:31:10 -05:00
checkf(0, TEXT("Unhandled AST iteration type %d!"), Type);
break;
}
}
FIterationStatement::~FIterationStatement()
{
if (InitStatement)
{
delete InitStatement;
}
if (Condition)
{
delete Condition;
}
if (RestExpression)
{
delete RestExpression;
}
if (Body)
{
delete Body;
}
}
FFunctionExpression::FFunctionExpression(FLinearAllocator* InAllocator, const FSourceInfo& InInfo, FExpression* Callee) :
FExpression(InAllocator, EOperators::FunctionCall, Callee, nullptr, nullptr, InInfo)
{
}
void FFunctionExpression::Write(FASTWriter& Writer) const
{
SubExpressions[0]->Write(Writer);
Writer << (TCHAR)'(';
bool bFirst = true;
for (auto* Expr : Expressions)
{
if (bFirst)
{
bFirst = false;
}
else
{
Writer << TEXT(", ");
}
Expr->Write(Writer);
}
Writer << TEXT(")");
}
FSwitchStatement::FSwitchStatement(FLinearAllocator* InAllocator, const FSourceInfo& InInfo, FExpression* InCondition, FSwitchBody* InBody) :
FNode(InAllocator, InInfo),
Condition(InCondition),
Body(InBody)
{
}
void FSwitchStatement::Write(FASTWriter& Writer) const
{
Writer.DoIndent();
Writer << TEXT("switch (");
Condition->Write(Writer);
Writer << TEXT(")\n");
Body->Write(Writer);
}
FSwitchStatement::~FSwitchStatement()
{
delete Condition;
delete Body;
}
FSwitchBody::FSwitchBody(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
CaseList(nullptr)
{
}
void FSwitchBody::Write(FASTWriter& Writer) const
{
Writer.DoIndent();
Writer << TEXT("{\n");
{
FASTWriterIncrementScope Scope(Writer);
CaseList->Write(Writer);
}
Writer.DoIndent();
Writer << TEXT("}\n");
}
FSwitchBody::~FSwitchBody()
{
delete CaseList;
}
FCaseLabel::FCaseLabel(FLinearAllocator* InAllocator, const FSourceInfo& InInfo, AST::FExpression* InExpression) :
FNode(InAllocator, InInfo),
TestExpression(InExpression)
{
}
void FCaseLabel::Write(FASTWriter& Writer) const
{
Writer.DoIndent();
if (TestExpression)
{
Writer << TEXT("case ");
TestExpression->Write(Writer);
}
else
{
Writer << TEXT("default");
}
Writer << TEXT(":\n");
}
FCaseLabel::~FCaseLabel()
{
if (TestExpression)
{
delete TestExpression;
}
}
FCaseStatement::FCaseStatement(FLinearAllocator* InAllocator, const FSourceInfo& InInfo, FCaseLabelList* InLabels) :
FNode(InAllocator, InInfo),
Labels(InLabels),
Statements(InAllocator)
{
}
void FCaseStatement::Write(FASTWriter& Writer) const
{
Labels->Write(Writer);
if (Statements.Num() > 1)
{
Writer.DoIndent();
Writer << TEXT("{\n");
for (auto* Statement : Statements)
{
FASTWriterIncrementScope Scope(Writer);
Statement->Write(Writer);
}
Writer.DoIndent();
Writer << TEXT("}\n");
}
else if (Statements.Num() > 0)
{
FASTWriterIncrementScope Scope(Writer);
Statements[0]->Write(Writer);
}
}
FCaseStatement::~FCaseStatement()
{
delete Labels;
for (auto* Statement : Statements)
{
if (Statement)
{
delete Statement;
}
}
}
FCaseLabelList::FCaseLabelList(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Labels(InAllocator)
{
}
void FCaseLabelList::Write(FASTWriter& Writer) const
{
for (auto* Label : Labels)
{
Label->Write(Writer);
}
}
FCaseLabelList::~FCaseLabelList()
{
for (auto* Label : Labels)
{
delete Label;
}
}
FCaseStatementList::FCaseStatementList(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Cases(InAllocator)
{
}
void FCaseStatementList::Write(FASTWriter& Writer) const
{
for (auto* Case : Cases)
{
Case->Write(Writer);
}
}
FCaseStatementList::~FCaseStatementList()
{
for (auto* Case : Cases)
{
delete Case;
}
}
FStructSpecifier::FStructSpecifier(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
Name(nullptr),
ParentName(nullptr),
Declarations(InAllocator)
{
}
void FStructSpecifier::Write(FASTWriter& Writer) const
{
Writer << TEXT("struct ");
Writer << (Name ? Name : TEXT(""));
if (ParentName && *ParentName)
{
Writer << TEXT(" : ");
Writer << ParentName;
}
Writer << (TCHAR)'\n';
Writer.DoIndent();
Writer << TEXT("{\n");
for (auto* Decl : Declarations)
{
FASTWriterIncrementScope Scope(Writer);
Decl->Write(Writer);
}
Writer.DoIndent();
Writer << TEXT("}");
}
FStructSpecifier::~FStructSpecifier()
{
for (auto* Decl : Declarations)
{
delete Decl;
}
}
FAttribute::FAttribute(FLinearAllocator* InAllocator, const FSourceInfo& InInfo, const TCHAR* InName) :
FNode(InAllocator, InInfo),
Name(InName),
Arguments(InAllocator)
{
}
void FAttribute::Write(FASTWriter& Writer) const
{
Writer << (TCHAR)'[';
Writer << Name;
bool bFirst = true;
for (auto* Arg : Arguments)
{
if (bFirst)
{
Writer << (TCHAR)'(';
bFirst = false;
}
else
{
Writer << TEXT(", ");
}
Arg->Write(Writer);
}
if (!bFirst)
{
Writer << TEXT(")");
}
Writer << TEXT("]");
}
FAttribute::~FAttribute()
{
for (auto* Arg : Arguments)
{
delete Arg;
}
}
FAttributeArgument::FAttributeArgument(FLinearAllocator* InAllocator, const FSourceInfo& InInfo) :
FNode(InAllocator, InInfo),
StringArgument(nullptr),
ExpressionArgument(nullptr)
{
}
void FAttributeArgument::Write(FASTWriter& Writer) const
{
if (ExpressionArgument)
{
ExpressionArgument->Write(Writer);
}
else
{
Writer << (TCHAR)'"';
Writer << StringArgument;
Writer << (TCHAR)'"';
}
}
FAttributeArgument::~FAttributeArgument()
{
if (ExpressionArgument)
{
delete ExpressionArgument;
}
}
}
}