You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 3315219 on 2017/02/21 by Steve.Robb Fix for FObjectAndNameAsStringProxyArchive when serializing a TWeakObjectPtr. Change 3315285 on 2017/02/21 by Steve.Robb Explicitly pass string builder into code generation functions. Change 3315341 on 2017/02/21 by Ben.Marsh UAT: Clean up some formatting in StreamCopyDescription output - remove #fyi lines, exclude merge commits, and remove some blank lines. Change 3315350 on 2017/02/21 by Ben.Marsh Fix shared resource files not being rebuilt if the version header changes. Change 3315823 on 2017/02/21 by Ben.Marsh UAT: Use a class derived from AutomationException to return information specific to commandlets failing, rather than putting it in the base class. Change 3315826 on 2017/02/21 by Ben.Marsh UAT: Move Distiller class from general use in UAT; FileFilter provides a much safer and fully featured implementation of the same concepts. Change 3315857 on 2017/02/21 by Ben.Marsh UBT: Remove the StripBaseDirectory() and MakeRerootedFilePath() utility functions from UBT. These operations can now be done more safely with FileReference objects. Change 3315942 on 2017/02/21 by Ben.Marsh UBT: Convert FileFilter to use FileReference and DirectoryReference arguments everywhere. Change3316236on 2017/02/22 by Maciej.Mroz #jira UE-42045 Nativization Fixed Warning: TEnumAsByte is not intended for use with enum Change 3316253 on 2017/02/22 by Robert.Manuszewski Fixes for the async log file writer hangs and crashes. - potential fix for the logging system hang when running out of disk space while flushing log - fix for unexpected concurrency assert when flushing the log buffer to disk Change3316293on 2017/02/22 by Steve.Robb GetTypeHash and lexicographical comparison operators (operator<() etc.) for TTuple. Change 3316342 on 2017/02/22 by Maciej.Mroz Nativization: Wrappers (stubs) required only by other wrappers are properly generated. #codereview: Mike.Beach Change 3316344 on 2017/02/22 by Maciej.Mroz Fixed crash in nativized Odin Async loading properly handles nativized structs. Change 3316359 on 2017/02/22 by Steve.Robb GitHub #3287 : Ignore #pragma in USTRUCTs #jira UE-42248 Change 3316389 on 2017/02/22 by Matthew.Griffin Switched Installed Engine Filters to multiline properties to make them more readable Added Oodle to list of excluded plugins #jira UE-42030 Change 3316392 on 2017/02/22 by Ben.Marsh UBT: Split out FileReference/DirectoryReference classes into their own file. Change 3316394 on 2017/02/22 by Ben.Marsh UBT: Move FileReference/DirectoryReference extension methods into the appropriate file. Change 3316411 on 2017/02/22 by Ben.Marsh UAT: Remove file functions that take multiple arguments. There's not really a compelling use case for these to exist over looping from the calling code. Change 3316446 on 2017/02/22 by Ben.Marsh UAT: Try disabling function name prefix to log output from UAT, to see if it improves readability. Function names are still included in the log file for debugging. Change 3316575 on 2017/02/22 by Ben.Marsh UAT: Remove unused functionality for dealing with labels, and output a more human readable list of P4 settings at startup. Change 3318481 on 2017/02/22 by Steve.Robb Use of FMath::IsPowerOfTwo in check. Static assert to ensure that an inline set allocator will have a hash size of a power of two. Change 3318496 on 2017/02/22 by Steve.Robb Fix for TSet visualizers. Change 3318919 on 2017/02/23 by Steve.Robb Fix for hot reloading UScriptStruct-derived objects in a module, where the CDOs of these objects haven't had PrepareCppStructOps() called on them. #jira UE-42178 Change 3318942 on 2017/02/23 by Steve.Robb Removal of a redundant insertion which can cause problems on reallocation of the map. Change 3319010 on 2017/02/23 by Ben.Marsh UBT: Fix exception when a file that was previously part of the working set is deleted. Change 3319134 on 2017/02/23 by Robert.Manuszewski Better fix for a deadlock when flushing log while it's already being flushed due to flush timer on the async log writer thread. Change 3319249 on 2017/02/23 by Matthew.Griffin Added a function to check if running with debug game libs instead of checking command line in multiple places Added -RunConfig parameter, which has equivalent result to -debug if value of parameter starts with 'debug' Added -RunConfig=$(Configuration) as a default commandline argument for Mac so that editor can use debug game libs Removed -Shipping argument from VCProject generation as it's not used anymore Change 3319253 on 2017/02/23 by Maciej.Mroz #jira UE-41846 New mechanism to gather modules necessary for Nativized Assets. The modules are listed based on included headers. Previously the dependencies was gathered only in FBlueprintNativeCodeGenManifest::GatherModuleDependencies. Change3319591on 2017/02/23 by Ben.Marsh Don't strip prefixes beginning with WARNING: or ERROR: using the Postp filter. Change 3320357 on 2017/02/23 by Steven.Hutton Slight changes to Add Crash method - Returning select fields instead of entity objects in queries for perf reasons. Change 3320361 on 2017/02/23 by Steven.Hutton Performance improvements subsequent to the recent database changes. Change 3320446 on 2017/02/23 by Steven.Hutton adding my temporary performance tracker class - reports to a private slack channel with add crash performance data. Change 3320479 on 2017/02/23 by Ben.Marsh Fix CIS errors. Change 3320576 on 2017/02/23 by Jin.Zhang Update CrashReporter to use AWS Change 3320742 on 2017/02/23 by Jin.Zhang Merging crash caching Change 3321119 on 2017/02/24 by Robert.Manuszewski DLL injection protection support for non-monolithic builds Change 3323308 on 2017/02/27 by Matthew.Griffin Moved compilation of SwarmInterface after its dependencies so that we will see a build failure immediately if they change version in future Change 3323423 on 2017/02/27 by Chad.Garyet Adding a script to check and warn about csproj targeted .net versions being mismatched #JIRA UE-39624 Change 3323442 on 2017/02/27 by Ben.Marsh UBT: Output an error if an engine module references a game module. Change 3323743 on 2017/02/27 by Ben.Marsh PR #3303: Resolved PVS scan issues (Contributed by projectgheist) Change 3323748 on 2017/02/27 by Ben.Marsh Convert whitespace to tabs. Change 3324851 on 2017/02/28 by Chris.Wood Add Odin symbol locations to engine config for MDD on CR server. NotForLicensees Change 3324979 on 2017/02/28 by Gil.Gribb Fixed bad merge of priority change in the EDL. Change 3326889 on 2017/03/01 by Steven.Hutton Update to buggs controller to generate faster queries. Change 3326910 on 2017/03/01 by Robert.Manuszewski Removing legacy #if from PackageFileSummary. Change 3327118 on 2017/03/01 by Gil.Gribb UE4 - Fixed race that resulted in a memory leak when reading compressed paks. Change 3327633 on 2017/03/01 by Gil.Gribb UE4 - Added a cvar to control the pak precacher thottle. Change 3327674 on 2017/03/01 by Steve.Robb Unified boilerplate between all generated code files. Change 3328544 on 2017/03/01 by Chris.Wood CrashReportProcess.config update (CRP v1.2.17) Tweaks to a few values. Update website URL to explicitly point to old, non-cloud site on devweb-02. Change 3328714 on 2017/03/01 by Chris.Wood Correct CRP config regression. Point website at new cloud site. Still v1.2.17 Change3329192on 2017/03/02 by Matthew.Griffin Added Shared Build Id file to the list of Precompiled Build Dependencies in a target receipt so that it's brought into an installed build Change 3329285 on 2017/03/02 by Ben.Marsh UGS: Allow a project to specify a filters for the streams that should be displayed for fast-switching to. The QuickSelectStreamList seting in the [Options] section of the project settings references a depot path containing a list of strings used to filter the stream list. An option is shown to switch back to showing all available streams, if desired. Change 3330636 on 2017/03/02 by Ben.Marsh UBT: Bump version number of C++ include cache to force it to be rebuilt with additional include information for the default RC files. Change 3331262 on 2017/03/03 by Robert.Manuszewski Merging Dev-LoadTimes to Dev-Core (Garbage Collection performance improvements) - Improved GC multithreading - Improved BeginDestroy performance - Introduced ULevelActorCluster for StaticMeshActor and ReflectionCapture actor clustering (can be toggled through project settings or console command gc.ActorClusterEnabled) - A few improvements to AddReferencedObjects functions - Misc improvements to GC code - Garbage Collector now properly handles clusters which had their objects marked as pending kill - Blueprints can now create clusters too (can be toggled through project settings or console command gc.BlueprintClusteringEnabled, defaults to disabled) Change 3331285 on 2017/03/03 by Robert.Manuszewski A few fixes for the previous check-in. Change 3332001 on 2017/03/03 by Ben.Marsh UBT: Add support for generating a UDN file containing the valid settings for BuildConfiguration.xml. Pass -configdoc=<filename> on the command line to generate such a file. Change 3332022 on 2017/03/03 by Ben.Marsh Update documentation for where to find the BuildConfiguration settings. Change 3332031 on 2017/03/03 by Ben.Marsh Remove documentation for Windows XP support; it has been removed in the 4.16 release. Change 3332256 on 2017/03/03 by Ben.Marsh UBT: Add support for generating a UDN page containing module and target settings. Change 3332458 on 2017/03/03 by Ben.Marsh UBT: Improvements to generated documentation. Change 3332459 on 2017/03/03 by Ben.Marsh Add generated documentation for .target.cs files, .build.cs files, and BuildConfiguration.xml files. Change 3332460 on 2017/03/03 by Ben.Marsh UBT: Make LinkTypePrivate actually private, so it doesn't show up in the docs. Change 3332899 on 2017/03/06 by Robert.Manuszewski Making sure actor clustering is not used in the editor (fix for actors being deleted when GC runs in the editor) #jira UE-42548 Change 3332955 on 2017/03/06 by Maciej.Mroz Nativization distinguishes client and server platform: - Separated lists on additional assets, additional modules, excluded assets, excluded modules, excluded paths (in config) - Context (compilation options, nativization options and platform) is deliveren to BPCOmpilerCppBackend in FCompilerNativizationOptions struct. - Wrappers (for unconverted BPs) are created only when they are directly called. - Fortnite dedicated server can be nativized Change 3332990 on 2017/03/06 by Ben.Marsh UBT: Add more comprehensive wrapper methods for System.IO.File and System.IO.Directory to FileReference and DirectoryReference. Change 3333032 on 2017/03/06 by Ben.Marsh Documentation for build tools Change 3333037 on 2017/03/06 by Ben.Marsh Add a build step to extract UAT and UBT documentation from XML comments. Change 3333089 on 2017/03/06 by Ben.Marsh UAT: Re-enable logging the calling function to the console in UAT. Needs a pass for readability first. Change 3333651 on 2017/03/06 by Gil.Gribb UE4 - Fix a werid recursive situation where StaticLoadObject could return an object that has not finished loading. Also produces a fatal error if this sometimes happens. EDL only. Change 3335236 on 2017/03/07 by Ben.Marsh UGS: Set the sync changelist separately to the compatibility changelist. Change 3335261 on 2017/03/07 by Gil.Gribb UE4 - Fixed batched render fences when BeginDestroy calls FlushRenderingCommands. Change 3335740 on 2017/03/07 by Gil.Gribb maybe fix static analysis warning Change 3335945 on 2017/03/07 by Steve.Robb Move FFindInstancedReferenceSubobjectHelper code out of header. Add map/set property support to allow instanced members of these container types to be handled during CPFUO. https://udn.unrealengine.com/questions/349232/tmap-with-instanced-object-as-value-gets-cleared-o.html Change 3336693 on 2017/03/07 by Ben.Marsh UBT: Use shared PCHs for game plugins by default, to reduce time spent generating individual PCHs. Change3336694on 2017/03/07 by Steve.Robb Static assert added to TMap to prevent the use of keys which don't implement a GetTypeHash. Fixes to types which relied on implicit conversions when calling GetTypeHash. Workaround in SAssetView.h and PropertyEditorModule.h for an apparent VC bug where the compiler wrongly instantiates TPointerIsConvertibleFromTo for certain forward-declared types, causing future TSharedPtr conversions to fail. #jira UE-42441 Change 3336698 on 2017/03/07 by Steve.Robb Hardcoded endpoint handling replaced with a generic string. Obsolete .proto and .java code generation removed. Change 3336811 on 2017/03/07 by Wes.Hunt Add a game blacklist to the crash report processor. Fixed a syntax error in Config.cs, added a XML comment to shut up a warning. Change 3336973 on 2017/03/08 by Steve.Robb Fix for missing GetTypeHash in a plugin. Change 3336996 on 2017/03/08 by Steve.Robb Significant refactor of code generation, to try and make data flow more apparent. Change 3337571 on 2017/03/08 by Steve.Robb CIS fixes for missing GetTypeHash functions. Non-unity fix. Change 3337588 on 2017/03/08 by Gil.Gribb UE4 - Fixed obscure check with flushing rhi resources. Change 3337620 on 2017/03/08 by Steve.Robb WITH_HOT_RELOAD_CTORS macros removed. UseVTableConstructors config option removed. Change 3339369 on 2017/03/09 by Steve.Robb GetTypeHash overload for nn::account::Uid. Change 3339464 on 2017/03/09 by Daniel.Lamb Fixed assert in 4.15 to do with trying to gather dependency info from invalid packages. #jira UE-42583 #test Editor + Cook + Run shootergame Change 3339465 on 2017/03/09 by Maciej.Mroz Fixed serialization issue, after UserDefinedEnum was used in EnumProperty. Change 3339469 on 2017/03/09 by Maciej.Mroz Fixed Nativization problem, when default value is passed as non-const reference. Change 3340178 on 2017/03/09 by Daniel.Lamb Added support for in memory only packages. The Cooker ignores these and added core functions to recognize these packages. Other systems will need to add support where nessisary. Change 3341002 on 2017/03/10 by Maciej.Mroz Nativization: Fixed FFindHeadersToInclude. Headers necessary for owners of subobjects are properly included. Change 3341076 on 2017/03/10 by Steve.Robb Fix for FBakedTextureSourceInfo move semantics. #jira UE-42658 Change 3341160 on 2017/03/10 by Gil.Gribb UE4 - Fix hazard with SetMaterialUsage from a thread. Change 3341409 on 2017/03/10 by Steve.Robb Reduction of the generated code size for StaticRegisterNatives functions. Change 3341523 on 2017/03/10 by Steve.Robb Code generation simplified. Change 3341800 on 2017/03/10 by Ben.Marsh UnrealVS: Fix UnrealVS compatibility with RTM version of Visual Studio 2017. 2017 toolchain for extensions is no longer able to build <= 2015 extensions due to validation of the VSIX manifest, so create a separate solution for it. Change 3342034 on 2017/03/10 by Ben.Marsh Fix compiler setting not being loaded correctly into the Windows target settings dialog. #jira UE-42746 Change 3342041 on 2017/03/10 by Ben.Marsh Fix -ErrorOnEngineContentUse not being set in the cooker options correctly. Change 3342094 on 2017/03/10 by Steve.Robb Fix to deteministic name order during code generation. Change 3342251 on 2017/03/10 by Daniel.Lamb Integrate fix for resave lightmaps commandlet when upgrading from no mapbuilddatapackages to mapbuilddatapackages. #thanks Tim.Hagberg #test None Change 3342961 on 2017/03/13 by Robert.Manuszewski Fixing memory leak when playing while running -nullrhi on the commandline in cooked games caused by shader resources not being destroyed. #jira FORT-38977 Change 3343022 on 2017/03/13 by Steve.Robb GetTypeHash fixes for FUniqueNetIdLive. #jira UE-42788 Change 3343448 on 2017/03/13 by Steve.Robb Compiled-in defer object order fixed. Debuggability of the deferred registration map improved. #jira UE-42828 [CL 3345747 by Ben Marsh in Main branch]
1351 lines
54 KiB
C++
1351 lines
54 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "BlueprintCompilerCppBackendBase.h"
|
|
#include "UObject/UnrealType.h"
|
|
#include "Engine/BlueprintGeneratedClass.h"
|
|
#include "Misc/Paths.h"
|
|
#include "UObject/Interface.h"
|
|
#include "Engine/Blueprint.h"
|
|
#include "Kismet/BlueprintFunctionLibrary.h"
|
|
#include "Animation/AnimBlueprintGeneratedClass.h"
|
|
#include "Engine/UserDefinedEnum.h"
|
|
#include "Engine/UserDefinedStruct.h"
|
|
#include "K2Node_Event.h"
|
|
#include "K2Node_CallFunction.h"
|
|
#include "K2Node_CreateDelegate.h"
|
|
#include "SourceCodeNavigation.h"
|
|
#include "IBlueprintCompilerCppBackendModule.h"
|
|
#include "BlueprintCompilerCppBackendGatherDependencies.h"
|
|
#include "BlueprintCompilerCppBackendUtils.h"
|
|
#include "Kismet2/BlueprintEditorUtils.h"
|
|
#include "Animation/AnimNodeBase.h"
|
|
|
|
TArray<class UFunction*> IBlueprintCompilerCppBackendModule::CollectBoundFunctions(class UBlueprint* BP)
|
|
{
|
|
// it would be clean to recover info about delegates from bytecode, but then the owner class is unknown, that's why we check the nodes.
|
|
TArray<class UFunction*> Result;
|
|
check(BP);
|
|
TArray<UEdGraph*> Graphs;
|
|
BP->GetAllGraphs(Graphs);
|
|
for (UEdGraph* Graph : Graphs)
|
|
{
|
|
if (!Graph)
|
|
{
|
|
continue;
|
|
}
|
|
for (UEdGraphNode* Node : Graph->Nodes)
|
|
{
|
|
FName FunctionName = NAME_None;
|
|
UClass* FunctionOwnerClass = nullptr;
|
|
if (UK2Node_CreateDelegate* CreateDelegate = Cast<UK2Node_CreateDelegate>(Node))
|
|
{
|
|
FunctionName = CreateDelegate->GetFunctionName();
|
|
FunctionOwnerClass = CreateDelegate->GetScopeClass(true);
|
|
}
|
|
else if (UK2Node_Event* EventNode = Cast<UK2Node_Event>(Node))
|
|
{
|
|
UEdGraphPin* DelegateOutPin = EventNode->FindPin(UK2Node_Event::DelegateOutputName);
|
|
if (DelegateOutPin && DelegateOutPin->LinkedTo.Num())
|
|
{
|
|
FunctionOwnerClass = BP->GeneratedClass;
|
|
FunctionName = EventNode->GetFunctionName();
|
|
}
|
|
}
|
|
|
|
FunctionOwnerClass = FunctionOwnerClass ? FunctionOwnerClass->GetAuthoritativeClass() : nullptr;
|
|
UFunction* Func = FunctionOwnerClass ? FunctionOwnerClass->FindFunctionByName(FunctionName) : nullptr;
|
|
Func = Func ? FEmitHelper::GetOriginalFunction(Func) : nullptr;
|
|
if (Func)
|
|
{
|
|
Result.Add(Func);
|
|
}
|
|
}
|
|
}
|
|
|
|
return Result;
|
|
}
|
|
|
|
void FBlueprintCompilerCppBackendBase::EmitStructProperties(FEmitterLocalContext& EmitterContext, UStruct* SourceClass)
|
|
{
|
|
// Emit class variables
|
|
for (TFieldIterator<UProperty> It(SourceClass, EFieldIteratorFlags::ExcludeSuper); It; ++It)
|
|
{
|
|
UProperty* Property = *It;
|
|
check(Property);
|
|
FString PropertyMacro(TEXT("UPROPERTY("));
|
|
{
|
|
TArray<FString> Tags = FEmitHelper::ProperyFlagsToTags(Property->PropertyFlags, nullptr != Cast<UClass>(SourceClass));
|
|
Tags.Emplace(FEmitHelper::HandleRepNotifyFunc(Property));
|
|
Tags.Emplace(FEmitHelper::HandleMetaData(Property, false));
|
|
Tags.Remove(FString());
|
|
|
|
FString AllTags;
|
|
FEmitHelper::ArrayToString(Tags, AllTags, TEXT(", "));
|
|
PropertyMacro += AllTags;
|
|
}
|
|
PropertyMacro += TEXT(")");
|
|
EmitterContext.Header.AddLine(PropertyMacro);
|
|
|
|
const FString CppDeclaration = EmitterContext.ExportCppDeclaration(Property, EExportedDeclaration::Member, EPropertyExportCPPFlags::CPPF_CustomTypeName | EPropertyExportCPPFlags::CPPF_BlueprintCppBackend | EPropertyExportCPPFlags::CPPF_NoConst);
|
|
EmitterContext.Header.AddLine(CppDeclaration + TEXT(";"));
|
|
}
|
|
}
|
|
|
|
void FBlueprintCompilerCppBackendBase::DeclareDelegates(FEmitterLocalContext& EmitterContext, TIndirectArray<FKismetFunctionContext>& Functions)
|
|
{
|
|
// MC DELEGATE DECLARATION
|
|
{
|
|
FEmitHelper::EmitMulticastDelegateDeclarations(EmitterContext);
|
|
}
|
|
|
|
// GATHER ALL SC DELEGATES
|
|
{
|
|
TArray<UDelegateProperty*> Delegates;
|
|
for (TFieldIterator<UDelegateProperty> It(EmitterContext.GetCurrentlyGeneratedClass(), EFieldIteratorFlags::ExcludeSuper); It; ++It)
|
|
{
|
|
Delegates.Add(*It);
|
|
}
|
|
|
|
for (auto& FuncContext : Functions)
|
|
{
|
|
for (TFieldIterator<UDelegateProperty> It(FuncContext.Function, EFieldIteratorFlags::ExcludeSuper); It; ++It)
|
|
{
|
|
Delegates.Add(*It);
|
|
}
|
|
}
|
|
|
|
TArray<UFunction*> SCDelegateSignaturesWithoutType;
|
|
// Don't declare signatures, that are already declared in a native class
|
|
for (int32 I = 0; I < Delegates.Num();)
|
|
{
|
|
auto Delegate = Delegates[I];
|
|
auto DelegateSignature = Delegate ? Delegate->SignatureFunction : nullptr;
|
|
auto DelegateSignatureOwner = DelegateSignature ? DelegateSignature->GetOwnerStruct() : nullptr;
|
|
if (DelegateSignatureOwner && DelegateSignatureOwner->HasAnyInternalFlags(EInternalObjectFlags::Native))
|
|
{
|
|
if (DelegateSignature->HasAllFunctionFlags(FUNC_MulticastDelegate))
|
|
{
|
|
SCDelegateSignaturesWithoutType.AddUnique(DelegateSignature);
|
|
}
|
|
Delegates.RemoveAtSwap(I);
|
|
}
|
|
else
|
|
{
|
|
I++;
|
|
}
|
|
}
|
|
|
|
// remove duplicates, n^2, but n is small:
|
|
for (int32 I = 0; I < Delegates.Num(); ++I)
|
|
{
|
|
UFunction* TargetFn = Delegates[I]->SignatureFunction;
|
|
for (int32 J = I + 1; J < Delegates.Num();)
|
|
{
|
|
if (TargetFn == Delegates[J]->SignatureFunction)
|
|
{
|
|
// swap erase:
|
|
Delegates[J] = Delegates[Delegates.Num() - 1];
|
|
Delegates.RemoveAt(Delegates.Num() - 1);
|
|
}
|
|
else
|
|
{
|
|
J++;
|
|
}
|
|
}
|
|
}
|
|
|
|
int32 UniqeSCDelegateIndex = 0;
|
|
for (UFunction* SCDelegateSignature : SCDelegateSignaturesWithoutType)
|
|
{
|
|
FString SCType = FString::Printf(TEXT("F__%s__SC_%d"), *FEmitHelper::GetCppName(SCDelegateSignature), UniqeSCDelegateIndex);
|
|
UniqeSCDelegateIndex++;
|
|
FEmitHelper::EmitSinglecastDelegateDeclarations_Inner(EmitterContext, SCDelegateSignature, SCType);
|
|
EmitterContext.MCDelegateSignatureToSCDelegateType.Add(SCDelegateSignature, SCType);
|
|
}
|
|
|
|
FEmitHelper::EmitSinglecastDelegateDeclarations(EmitterContext, Delegates);
|
|
}
|
|
}
|
|
|
|
struct FIncludeHeaderHelper
|
|
{
|
|
static void EmitIncludeHeader(FCodeText& Dst, const TCHAR* Message, bool bAddDotH)
|
|
{
|
|
Dst.AddLine(FString::Printf(TEXT("#include \"%s%s\""), Message, bAddDotH ? TEXT(".h") : TEXT("")));
|
|
}
|
|
|
|
static void EmitInner(FCodeText& Dst, const TSet<UField*>& Src, const TSet<UField*>& Declarations, TSet<FString>& AlreadyIncluded)
|
|
{
|
|
auto EngineSourceDir = FPaths::EngineSourceDir();
|
|
auto GameSourceDir = FPaths::GameSourceDir();
|
|
|
|
for (UField* Field : Src)
|
|
{
|
|
if (!Field)
|
|
{
|
|
continue;
|
|
}
|
|
const bool bWantedType = Field->IsA<UBlueprintGeneratedClass>() || Field->IsA<UUserDefinedEnum>() || Field->IsA<UUserDefinedStruct>();
|
|
|
|
// Wanted no-native type, that will be converted
|
|
if (bWantedType)
|
|
{
|
|
// @TODO: Need to query if this asset will actually be converted
|
|
|
|
const FString Name = Field->GetPathName();
|
|
bool bAlreadyIncluded = false;
|
|
AlreadyIncluded.Add(Name, &bAlreadyIncluded);
|
|
if (!bAlreadyIncluded)
|
|
{
|
|
const FString GeneratedFilename = FEmitHelper::GetBaseFilename(Field);
|
|
FIncludeHeaderHelper::EmitIncludeHeader(Dst, *GeneratedFilename, true);
|
|
}
|
|
}
|
|
// headers for native items
|
|
else
|
|
{
|
|
FString PackPath;
|
|
if (FSourceCodeNavigation::FindClassHeaderPath(Field, PackPath))
|
|
{
|
|
if (!PackPath.RemoveFromStart(EngineSourceDir))
|
|
{
|
|
if (!PackPath.RemoveFromStart(GameSourceDir))
|
|
{
|
|
PackPath = FPaths::GetCleanFilename(PackPath);
|
|
}
|
|
}
|
|
bool bAlreadyIncluded = false;
|
|
AlreadyIncluded.Add(PackPath, &bAlreadyIncluded);
|
|
if (!bAlreadyIncluded)
|
|
{
|
|
FIncludeHeaderHelper::EmitIncludeHeader(Dst, *PackPath, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (auto Type : Declarations)
|
|
{
|
|
if (auto ForwardDeclaredType = Cast<UClass>(Type))
|
|
{
|
|
Dst.AddLine(FString::Printf(TEXT("class %s;"), *FEmitHelper::GetCppName(ForwardDeclaredType)));
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
/*
|
|
* This struct adds included headers of necessary wrappers (for unconverted BPs). The list of needed wrappers is filled while generating the code. See FEmitterLocalContext::MarkUnconvertedClassAsNecessary.
|
|
*/
|
|
struct FIncludedUnconvertedWrappers
|
|
{
|
|
FEmitterLocalContext& Context;
|
|
bool bInludeInBody;
|
|
|
|
static const TCHAR* Placeholder()
|
|
{
|
|
return TEXT("//PlaceholderForUnconvertedWrappersInlude");
|
|
}
|
|
|
|
static void AddPlaceholder(FEmitterLocalContext& InContext, bool bInInludeInBody)
|
|
{
|
|
(bInInludeInBody ? InContext.Body : InContext.Header).AddLine(Placeholder());
|
|
}
|
|
|
|
static void FillPlaceholder(FEmitterLocalContext& InContext, bool bInInludeInBody)
|
|
{
|
|
FCodeText AdditionalIncludes;
|
|
TSet<FString> DummyStrSet;
|
|
FIncludeHeaderHelper::EmitInner(AdditionalIncludes, InContext.UsedUnconvertedWrapper, TSet<UField*>{}, DummyStrSet);
|
|
(bInInludeInBody ? InContext.Body : InContext.Header).Result.ReplaceInline(Placeholder(), *AdditionalIncludes.Result);
|
|
}
|
|
|
|
FIncludedUnconvertedWrappers(FEmitterLocalContext& InContext, bool bInInludeInBody)
|
|
: Context(InContext)
|
|
, bInludeInBody(bInInludeInBody)
|
|
{
|
|
AddPlaceholder(Context, bInludeInBody);
|
|
}
|
|
|
|
~FIncludedUnconvertedWrappers()
|
|
{
|
|
FillPlaceholder(Context, bInludeInBody);
|
|
}
|
|
};
|
|
|
|
FString FBlueprintCompilerCppBackendBase::GenerateCodeFromClass(UClass* SourceClass, TIndirectArray<FKismetFunctionContext>& Functions, bool bGenerateStubsOnly, const FCompilerNativizationOptions& NativizationOptions, FString& OutCppBody)
|
|
{
|
|
CleanBackend();
|
|
for (auto& FunctionContext : Functions)
|
|
{
|
|
if (FunctionContext.bIsUbergraph)
|
|
{
|
|
UberGraphContext = &FunctionContext;
|
|
for (int32 ExecutionGroupIndex = 0; ExecutionGroupIndex < FunctionContext.UnsortedSeparateExecutionGroups.Num(); ++ExecutionGroupIndex)
|
|
{
|
|
TSet<UEdGraphNode*>& ExecutionGroup = FunctionContext.UnsortedSeparateExecutionGroups[ExecutionGroupIndex];
|
|
for (UEdGraphNode* LocNode : ExecutionGroup)
|
|
{
|
|
TArray<FBlueprintCompiledStatement*>* LocStatementsPtr = FunctionContext.StatementsPerNode.Find(LocNode);
|
|
if (ensure(LocStatementsPtr))
|
|
{
|
|
for (FBlueprintCompiledStatement* LocStatement : *LocStatementsPtr)
|
|
{
|
|
UberGraphStatementToExecutionGroup.Add(LocStatement, ExecutionGroupIndex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
// use GetBaseFilename() so that we can coordinate #includes and filenames
|
|
auto CleanCppClassName = FEmitHelper::GetBaseFilename(SourceClass);
|
|
auto CppClassName = FEmitHelper::GetCppName(SourceClass);
|
|
|
|
FGatherConvertedClassDependencies Dependencies(SourceClass, NativizationOptions);
|
|
FNativizationSummaryHelper::RegisterRequiredModules(NativizationOptions.PlatformName, Dependencies.RequiredModuleNames);
|
|
FEmitterLocalContext EmitterContext(Dependencies, NativizationOptions);
|
|
|
|
UClass* OriginalSourceClass = Dependencies.FindOriginalClass(SourceClass);
|
|
ensure(OriginalSourceClass != SourceClass);
|
|
|
|
FNativizationSummaryHelper::RegisterClass(OriginalSourceClass);
|
|
|
|
EmitFileBeginning(CleanCppClassName, EmitterContext);
|
|
|
|
const TCHAR* PlaceholderForInlinedStructInlude = TEXT("//PlaceholderForInlinedStructInlude");
|
|
const bool bIsInterface = SourceClass->IsChildOf<UInterface>();
|
|
if (!bIsInterface)
|
|
{
|
|
EmitterContext.Body.AddLine(PlaceholderForInlinedStructInlude);
|
|
}
|
|
|
|
const bool bHasStaticSearchableValues = FBackendHelperStaticSearchableValues::HasSearchableValues(SourceClass);
|
|
|
|
{
|
|
FIncludedUnconvertedWrappers IncludedUnconvertedWrappers(EmitterContext, true);
|
|
|
|
// C4883 is a strange error (for big functions), introduced in VS2015 update 2
|
|
FDisableUnwantedWarningOnScope DisableUnwantedWarningOnScope(EmitterContext.Body);
|
|
|
|
// Class declaration
|
|
if (bIsInterface)
|
|
{
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("UINTERFACE(Blueprintable, %s)"), *FEmitHelper::ReplaceConvertedMetaData(OriginalSourceClass)));
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("class %s : public UInterface"), *FEmitHelper::GetCppName(SourceClass, true)));
|
|
EmitterContext.Header.AddLine(TEXT("{"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("GENERATED_BODY()"));
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("};"));
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("class %s"), *CppClassName));
|
|
}
|
|
else
|
|
{
|
|
TArray<FString> AdditionalMD;
|
|
const FString ReplaceConvertedMD = FEmitHelper::GenerateReplaceConvertedMD(OriginalSourceClass);
|
|
if (!ReplaceConvertedMD.IsEmpty())
|
|
{
|
|
AdditionalMD.Add(ReplaceConvertedMD);
|
|
}
|
|
|
|
if (bHasStaticSearchableValues)
|
|
{
|
|
AdditionalMD.Add(FBackendHelperStaticSearchableValues::GenerateClassMetaData(SourceClass));
|
|
}
|
|
|
|
// AdditionalMD.Add(FString::Printf(TEXT("CustomDynamicClassInitialization=\"%s::__CustomDynamicClassInitialization\""), *CppClassName));
|
|
const FString DefinedConfigName = (OriginalSourceClass->ClassConfigName == NAME_None) ? FString() : FString::Printf(TEXT("config=%s, "), *OriginalSourceClass->ClassConfigName.ToString());
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("UCLASS(%s%s%s)")
|
|
, *DefinedConfigName
|
|
, (!SourceClass->IsChildOf<UBlueprintFunctionLibrary>()) ? TEXT("Blueprintable, BlueprintType, ") : TEXT("")
|
|
, *FEmitHelper::HandleMetaData(nullptr, false, &AdditionalMD)));
|
|
|
|
UClass* SuperClass = SourceClass->GetSuperClass();
|
|
FString ClassDefinition = FString::Printf(TEXT("class %s : public %s"), *CppClassName, *FEmitHelper::GetCppName(SuperClass));
|
|
|
|
for (auto& ImplementedInterface : SourceClass->Interfaces)
|
|
{
|
|
if (ImplementedInterface.Class)
|
|
{
|
|
ClassDefinition += FString::Printf(TEXT(", public %s"), *FEmitHelper::GetCppName(ImplementedInterface.Class));
|
|
}
|
|
}
|
|
EmitterContext.Header.AddLine(ClassDefinition);
|
|
}
|
|
|
|
// Begin scope
|
|
EmitterContext.Header.AddLine(TEXT("{"));
|
|
EmitterContext.Header.AddLine(TEXT("public:"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("GENERATED_BODY()"));
|
|
|
|
DeclareDelegates(EmitterContext, Functions);
|
|
|
|
EmitStructProperties(EmitterContext, SourceClass);
|
|
|
|
{
|
|
IBlueprintCompilerCppBackendModule& BackEndModule = (IBlueprintCompilerCppBackendModule&)IBlueprintCompilerCppBackendModule::Get();
|
|
TSharedPtr<FNativizationSummary> NativizationSummary = BackEndModule.NativizationSummary();
|
|
if (NativizationSummary.IsValid())
|
|
{
|
|
for (TFieldIterator<UProperty> It(SourceClass, EFieldIteratorFlags::ExcludeSuper); It; ++It)
|
|
{
|
|
UProperty* Property = *It;
|
|
if (Property && Property->HasAllPropertyFlags(CPF_Transient | CPF_DuplicateTransient))
|
|
{
|
|
NativizationSummary->MemberVariablesFromGraph++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TSharedPtr<FGatherConvertedClassDependencies> ParentDependencies;
|
|
// Emit function declarations and definitions (writes to header and body simultaneously)
|
|
if (!bIsInterface)
|
|
{
|
|
UBlueprintGeneratedClass* BPGC = CastChecked<UBlueprintGeneratedClass>(EmitterContext.GetCurrentlyGeneratedClass());
|
|
UBlueprintGeneratedClass* ParentBPGC = Cast<UBlueprintGeneratedClass>(BPGC->GetSuperClass());
|
|
ParentDependencies = TSharedPtr<FGatherConvertedClassDependencies>( ParentBPGC
|
|
? new FGatherConvertedClassDependencies(ParentBPGC, NativizationOptions)
|
|
: nullptr);
|
|
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("%s(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());"), *CppClassName));
|
|
EmitterContext.Header.AddLine(TEXT("virtual void PostLoadSubobjects(FObjectInstancingGraph* OuterInstanceGraph) override;"));
|
|
EmitterContext.Header.AddLine(TEXT("static void __CustomDynamicClassInitialization(UDynamicClass* InDynamicClass);"));
|
|
|
|
EmitterContext.Header.AddLine(TEXT("static void __StaticDependenciesAssets(TArray<FBlueprintDependencyData>& AssetsToLoad);"));
|
|
EmitterContext.Header.AddLine(TEXT("static void __StaticDependencies_DirectlyUsedAssets(TArray<FBlueprintDependencyData>& AssetsToLoad);"));
|
|
if (bHasStaticSearchableValues)
|
|
{
|
|
FBackendHelperStaticSearchableValues::EmitFunctionDeclaration(EmitterContext);
|
|
FBackendHelperStaticSearchableValues::EmitFunctionDefinition(EmitterContext);
|
|
}
|
|
FEmitDefaultValueHelper::GenerateConstructor(EmitterContext);
|
|
FEmitDefaultValueHelper::GenerateCustomDynamicClassInitialization(EmitterContext, ParentDependencies);
|
|
}
|
|
|
|
// Create the state map
|
|
for (int32 i = 0; i < Functions.Num(); ++i)
|
|
{
|
|
StateMapPerFunction.Add(FFunctionLabelInfo());
|
|
FunctionIndexMap.Add(&Functions[i], i);
|
|
}
|
|
|
|
for (int32 i = 0; i < Functions.Num(); ++i)
|
|
{
|
|
if (Functions[i].IsValid())
|
|
{
|
|
ConstructFunction(Functions[i], EmitterContext, bGenerateStubsOnly);
|
|
}
|
|
}
|
|
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("public:"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
|
|
FBackendHelperUMG::WidgetFunctionsInHeader(EmitterContext);
|
|
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("};"));
|
|
|
|
if (!bIsInterface)
|
|
{
|
|
// must be called after GenerateConstructor and GenerateCustomDynamicClassInitialization and other functions implementation
|
|
// now we knows which assets are directly used in source code
|
|
FEmitDefaultValueHelper::AddStaticFunctionsForDependencies(EmitterContext, ParentDependencies, NativizationOptions);
|
|
FEmitDefaultValueHelper::AddRegisterHelper(EmitterContext);
|
|
}
|
|
|
|
FEmitHelper::EmitLifetimeReplicatedPropsImpl(EmitterContext);
|
|
}
|
|
|
|
if (!bIsInterface)
|
|
{
|
|
FCodeText AdditionalIncludes;
|
|
TSet<FString> DummyStrSet;
|
|
FIncludeHeaderHelper::EmitInner(AdditionalIncludes, EmitterContext.StructsUsedAsInlineValues, TSet<UField*>{}, DummyStrSet);
|
|
EmitterContext.Body.Result.ReplaceInline(PlaceholderForInlinedStructInlude, *AdditionalIncludes.Result);
|
|
}
|
|
|
|
CleanBackend();
|
|
|
|
OutCppBody = EmitterContext.Body.Result;
|
|
return EmitterContext.Header.Result;
|
|
}
|
|
|
|
static void PropertiesUsedByStatement(FBlueprintCompiledStatement* Statement, TSet<UProperty*>& Properties)
|
|
{
|
|
if (Statement)
|
|
{
|
|
for (FBPTerminal* Terminal : Statement->RHS)
|
|
{
|
|
if (Terminal)
|
|
{
|
|
Properties.Add(Terminal->AssociatedVarProperty);
|
|
PropertiesUsedByStatement(Terminal->InlineGeneratedParameter, Properties);
|
|
}
|
|
}
|
|
|
|
if (Statement->FunctionContext)
|
|
{
|
|
Properties.Add(Statement->FunctionContext->AssociatedVarProperty);
|
|
PropertiesUsedByStatement(Statement->FunctionContext->InlineGeneratedParameter, Properties);
|
|
}
|
|
|
|
if (Statement->LHS)
|
|
{
|
|
Properties.Add(Statement->LHS->AssociatedVarProperty);
|
|
PropertiesUsedByStatement(Statement->LHS->InlineGeneratedParameter, Properties);
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Emits local variable declarations for a function */
|
|
static void DeclareLocalVariables(FEmitterLocalContext& EmitterContext, TArray<UProperty*>& LocalVariables, FKismetFunctionContext& FunctionContext, int32 ExecutionGroup)
|
|
{
|
|
const bool bUseExecutionGroup = ExecutionGroup >= 0;
|
|
TSet<UProperty*> PropertiesUsedByCurrentExecutionGroup;
|
|
if (bUseExecutionGroup)
|
|
{
|
|
for (UEdGraphNode* Node : FunctionContext.UnsortedSeparateExecutionGroups[ExecutionGroup])
|
|
{
|
|
TArray<FBlueprintCompiledStatement*>* StatementList = FunctionContext.StatementsPerNode.Find(Node);
|
|
if (StatementList)
|
|
{
|
|
for (FBlueprintCompiledStatement* Statement : *StatementList)
|
|
{
|
|
PropertiesUsedByStatement(Statement, PropertiesUsedByCurrentExecutionGroup);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int32 i = 0; i < LocalVariables.Num(); ++i)
|
|
{
|
|
UProperty* LocalVariable = LocalVariables[i];
|
|
if (!bUseExecutionGroup || PropertiesUsedByCurrentExecutionGroup.Contains(LocalVariable))
|
|
{
|
|
const FString CppDeclaration = EmitterContext.ExportCppDeclaration(LocalVariable, EExportedDeclaration::Local, EPropertyExportCPPFlags::CPPF_CustomTypeName | EPropertyExportCPPFlags::CPPF_BlueprintCppBackend | EPropertyExportCPPFlags::CPPF_NoConst);
|
|
UStructProperty* StructProperty = Cast<UStructProperty>(LocalVariable);
|
|
const TCHAR* EmptyDefaultConstructor = FEmitHelper::EmptyDefaultConstructor(StructProperty ? StructProperty->Struct : nullptr);
|
|
EmitterContext.AddLine(CppDeclaration + EmptyDefaultConstructor + TEXT(";"));
|
|
}
|
|
}
|
|
}
|
|
|
|
void FBlueprintCompilerCppBackendBase::ConstructFunction(FKismetFunctionContext& FunctionContext, FEmitterLocalContext& EmitterContext, bool bGenerateStubOnly)
|
|
{
|
|
if (FunctionContext.IsDelegateSignature())
|
|
{
|
|
return;
|
|
}
|
|
|
|
TArray<UProperty*> LocalVariables;
|
|
TArray<UProperty*> ArgumentList;
|
|
// Split the function property list into arguments, a return value (if any), and local variable declarations
|
|
for (UProperty* Property : TFieldRange<UProperty>(FunctionContext.Function))
|
|
{
|
|
const bool bNeedLocalVariable = !Property->HasAnyPropertyFlags(CPF_Parm) || Property->HasAnyPropertyFlags(CPF_ReturnParm);
|
|
TArray<UProperty*>& PropertyDest = bNeedLocalVariable ? LocalVariables : ArgumentList;
|
|
PropertyDest.Add(Property);
|
|
}
|
|
|
|
static const FBoolConfigValueHelper UsePRAGMA_DISABLE_OPTIMIZATION(TEXT("BlueprintNativizationSettings"), TEXT("bUsePRAGMA_DISABLE_OPTIMIZATION"));
|
|
if (FunctionContext.bIsUbergraph && UsePRAGMA_DISABLE_OPTIMIZATION)
|
|
{
|
|
EmitterContext.AddLine(TEXT("PRAGMA_DISABLE_OPTIMIZATION"));
|
|
}
|
|
|
|
TArray<FString> BodyFunctionsDeclaration = ConstructFunctionDeclaration(EmitterContext, FunctionContext, ArgumentList);
|
|
ensure((BodyFunctionsDeclaration.Num() == FunctionContext.UnsortedSeparateExecutionGroups.Num())
|
|
|| ((1 == BodyFunctionsDeclaration.Num()) && (0 == FunctionContext.UnsortedSeparateExecutionGroups.Num())));
|
|
|
|
const bool bIsConstFunction = FunctionContext.Function->HasAllFunctionFlags(FUNC_Const);
|
|
const bool bUseInnerFunctionImplementation = bIsConstFunction && !FunctionContext.Function->HasAnyFunctionFlags(FUNC_Static);
|
|
if (bUseInnerFunctionImplementation)
|
|
{
|
|
ensure(0 == FunctionContext.UnsortedSeparateExecutionGroups.Num());
|
|
ensure(1 == BodyFunctionsDeclaration.Num());
|
|
const FString InnerImplementationFunctionName = FString::Printf(TEXT("%s_Inner_%d")
|
|
, *FEmitHelper::GetCppName(FunctionContext.Function)
|
|
, FEmitHelper::GetInheritenceLevel(FunctionContext.Function->GetOwnerStruct()));
|
|
|
|
const FString ReturnType = GenerateReturnType(EmitterContext, FunctionContext.Function);
|
|
const FString ArgList = GenerateArgList(EmitterContext, ArgumentList);
|
|
const FString ArgListNoTypes = GenerateArgList(EmitterContext, ArgumentList, true);
|
|
const FString ClassCppName = FEmitHelper::GetCppName(EmitterContext.GetCurrentlyGeneratedClass());
|
|
|
|
// Inner header declaration
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("%s %s%s;")
|
|
, *ReturnType, *InnerImplementationFunctionName, *ArgList));
|
|
|
|
// Function original declaration
|
|
EmitterContext.AddLine(BodyFunctionsDeclaration[0]);
|
|
//Original implementation
|
|
EmitterContext.AddLine(TEXT("{"));
|
|
EmitterContext.IncreaseIndent();
|
|
EmitterContext.AddLine(FString::Printf(TEXT("%sconst_cast<%s*>(this)->%s%s;")
|
|
, FunctionContext.Function->GetReturnProperty() ? TEXT("return ") : TEXT("")
|
|
, *ClassCppName
|
|
, *InnerImplementationFunctionName
|
|
, *ArgListNoTypes));
|
|
EmitterContext.DecreaseIndent();
|
|
EmitterContext.AddLine(TEXT("}"));
|
|
|
|
// Inner body declaration
|
|
EmitterContext.AddLine(FString::Printf(TEXT("%s %s::%s%s")
|
|
, *ReturnType, *ClassCppName, *InnerImplementationFunctionName, *ArgList));
|
|
|
|
}
|
|
const bool bManyExecutionGroups = FunctionContext.UnsortedSeparateExecutionGroups.Num() > 0;
|
|
for (int32 ExecutionGroupIndex = bManyExecutionGroups ? 0 : -1; ExecutionGroupIndex < FunctionContext.UnsortedSeparateExecutionGroups.Num(); ExecutionGroupIndex++)
|
|
{
|
|
if (!bUseInnerFunctionImplementation)
|
|
{
|
|
EmitterContext.AddLine(BodyFunctionsDeclaration[bManyExecutionGroups ? ExecutionGroupIndex : 0]);
|
|
}
|
|
// Start the body of the implementation
|
|
EmitterContext.AddLine(TEXT("{"));
|
|
EmitterContext.IncreaseIndent();
|
|
if (!bGenerateStubOnly)
|
|
{
|
|
for (UProperty* Property : ArgumentList)
|
|
{
|
|
if (FEmitHelper::PropertyForConstCast(Property))
|
|
{
|
|
const uint32 ExportFlags = EPropertyExportCPPFlags::CPPF_CustomTypeName | EPropertyExportCPPFlags::CPPF_BlueprintCppBackend | EPropertyExportCPPFlags::CPPF_NoConst | EPropertyExportCPPFlags::CPPF_NoRef;
|
|
const FString NoConstNoRefType = EmitterContext.ExportCppDeclaration(Property, EExportedDeclaration::Parameter, ExportFlags, FEmitterLocalContext::EPropertyNameInDeclaration::Skip);
|
|
const FString TypeDefName = FString(TEXT("T")) + EmitterContext.GenerateUniqueLocalName();
|
|
EmitterContext.AddLine(FString::Printf(TEXT("typedef %s %s;"), *NoConstNoRefType, *TypeDefName));
|
|
|
|
const FString ParamName = FEmitHelper::GetCppName(Property);
|
|
EmitterContext.AddLine(FString::Printf(TEXT("%s& %s = *const_cast<%s *>(&%s__const);"), *TypeDefName, *ParamName, *TypeDefName, *ParamName));
|
|
}
|
|
}
|
|
const int32 ExecutionGroup = bManyExecutionGroups ? ExecutionGroupIndex : -1;
|
|
DeclareLocalVariables(EmitterContext, LocalVariables, FunctionContext, ExecutionGroup);
|
|
ConstructFunctionBody(EmitterContext, FunctionContext, ExecutionGroup);
|
|
}
|
|
|
|
if (UProperty* ReturnValue = FunctionContext.Function->GetReturnProperty())
|
|
{
|
|
EmitterContext.AddLine(FString::Printf(TEXT("return %s;"), *FEmitHelper::GetCppName(ReturnValue)));
|
|
}
|
|
|
|
EmitterContext.DecreaseIndent();
|
|
EmitterContext.AddLine(TEXT("}"));
|
|
}
|
|
|
|
if (FunctionContext.bIsUbergraph && UsePRAGMA_DISABLE_OPTIMIZATION)
|
|
{
|
|
EmitterContext.AddLine(TEXT("PRAGMA_ENABLE_OPTIMIZATION"));
|
|
}
|
|
}
|
|
|
|
TArray<FString> FBlueprintCompilerCppBackendBase::ConstructFunctionDeclaration(FEmitterLocalContext &EmitterContext, FKismetFunctionContext &FunctionContext, TArray<UProperty*> &ArgumentList)
|
|
{
|
|
FString FunctionHeaderName = FEmitHelper::GetCppName(FunctionContext.Function);
|
|
FString FunctionBodyName = FunctionHeaderName;
|
|
const bool bStaticFunction = FunctionContext.Function->HasAllFunctionFlags(FUNC_Static);
|
|
const bool bInInterface = FunctionContext.Function->GetOwnerClass()->IsChildOf<UInterface>();
|
|
bool bAddConst = false;
|
|
bool bIsOverride = false;
|
|
bool bIsVirtual = !bInInterface && !bStaticFunction && !FunctionContext.IsEventGraph();
|
|
|
|
FString MacroUFUNCTION;
|
|
{
|
|
UFunction* const Function = FunctionContext.Function;
|
|
UFunction* const OriginalFunction = FEmitHelper::GetOriginalFunction(Function);
|
|
TArray<FString> AdditionalMetaData;
|
|
TArray<FString> AdditionalTags;
|
|
bool bGenerateAsNativeEventImplementation = false;
|
|
const bool bNetImplementation = !bInInterface && Function->HasAllFunctionFlags(FUNC_Net) && !Function->HasAnyFunctionFlags(FUNC_NetResponse);
|
|
|
|
const UBlueprintGeneratedClass* const OriginalFuncOwnerAsBPGC = Cast<UBlueprintGeneratedClass>(OriginalFunction->GetOwnerClass());
|
|
const bool bBPInterfaceImplementation = OriginalFuncOwnerAsBPGC && OriginalFuncOwnerAsBPGC->IsChildOf<UInterface>();
|
|
|
|
if (bInInterface)
|
|
{
|
|
AdditionalTags.Emplace(TEXT("BlueprintImplementableEvent"));
|
|
}
|
|
else if (bNetImplementation)
|
|
{
|
|
FunctionBodyName = FunctionHeaderName + TEXT("_Implementation");
|
|
}
|
|
else if (FEmitHelper::ShouldHandleAsNativeEvent(Function))
|
|
{
|
|
bGenerateAsNativeEventImplementation = true;
|
|
FunctionBodyName = FunctionHeaderName = FEmitHelper::GetCppName(OriginalFunction) + TEXT("_Implementation");
|
|
bAddConst = OriginalFunction->HasAllFunctionFlags(FUNC_Const);
|
|
}
|
|
else if (FEmitHelper::ShouldHandleAsImplementableEvent(Function) || bBPInterfaceImplementation)
|
|
{
|
|
//The function "bpf__BIE__pf" should never be called directly. Only via function "BIE" with generated implementation.
|
|
bIsVirtual = false;
|
|
AdditionalMetaData.Emplace(TEXT("CppFromBpEvent"));
|
|
}
|
|
|
|
ensure(!bIsVirtual || Function->IsSignatureCompatibleWith(OriginalFunction));
|
|
bIsOverride = bGenerateAsNativeEventImplementation || (bIsVirtual && (Function != OriginalFunction));
|
|
|
|
auto PreliminaryConditionsToSkipMacroUFUNC = [](UFunction* InFunction) -> bool
|
|
{
|
|
check(InFunction);
|
|
return !FEmitHelper::ShouldHandleAsNativeEvent(InFunction)
|
|
&& !FEmitHelper::ShouldHandleAsImplementableEvent(InFunction)
|
|
&& !InFunction->GetOwnerClass()->IsChildOf<UInterface>()
|
|
&& !InFunction->HasAnyFunctionFlags(FUNC_Exec | FUNC_Static | FUNC_Native
|
|
| FUNC_Net | FUNC_NetServer | FUNC_NetClient | FUNC_NetMulticast | FUNC_NetReliable
|
|
| FUNC_BlueprintAuthorityOnly | FUNC_BlueprintCosmetic | FUNC_NetValidate
|
|
| FUNC_MulticastDelegate | FUNC_Delegate);
|
|
};
|
|
|
|
auto FunctionIsBoundToAnyDelegate = [](UFunction* InFunction)
|
|
{
|
|
check(InFunction);
|
|
IBlueprintCompilerCppBackendModule& BackEndModule = (IBlueprintCompilerCppBackendModule&)IBlueprintCompilerCppBackendModule::Get();
|
|
auto& IsFunctionUsedInADelegate = BackEndModule.GetIsFunctionUsedInADelegateCallback();
|
|
return ensure(IsFunctionUsedInADelegate.IsBound()) ? IsFunctionUsedInADelegate.Execute(InFunction) : true;
|
|
};
|
|
|
|
auto IsFunctionUsedByReplication = [](UFunction* InFunction)
|
|
{
|
|
check(InFunction);
|
|
for (UProperty* Prop : TFieldRange<UProperty>(InFunction->GetOwnerClass(), EFieldIteratorFlags::ExcludeSuper))
|
|
{
|
|
if (Prop && FEmitHelper::HasAllFlags(Prop->PropertyFlags, CPF_Net | CPF_RepNotify) && (Prop->RepNotifyFunc == InFunction->GetFName()))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
static const FBoolConfigValueHelper TryToSkipMacroUFUNC(TEXT("BlueprintNativizationSettings"), TEXT("bSkipUFUNCTION"));
|
|
const bool bTryToSkipMacroUFUNC = TryToSkipMacroUFUNC; // should be enabled only when all BP are compiled.
|
|
const bool bSkipMacro = bTryToSkipMacroUFUNC
|
|
&& !FunctionContext.bIsUbergraph // uber-graph is necessary for latent actions
|
|
&& PreliminaryConditionsToSkipMacroUFUNC(Function)
|
|
&& ((Function == OriginalFunction) || PreliminaryConditionsToSkipMacroUFUNC(OriginalFunction))
|
|
&& !IsFunctionUsedByReplication(Function)
|
|
&& !FunctionIsBoundToAnyDelegate(OriginalFunction);
|
|
|
|
if (bNetImplementation && bIsOverride)
|
|
{
|
|
FunctionHeaderName = FunctionBodyName;
|
|
}
|
|
else if (!bGenerateAsNativeEventImplementation && !bSkipMacro)
|
|
{
|
|
MacroUFUNCTION = FEmitHelper::EmitUFuntion(Function, AdditionalTags, AdditionalMetaData);
|
|
}
|
|
}
|
|
|
|
const bool bManyExecutionGroups = FunctionContext.UnsortedSeparateExecutionGroups.Num() > 0;
|
|
|
|
TArray<FString> Result;
|
|
for (int32 ExecutionGroupIndex = bManyExecutionGroups ? 0 : -1; ExecutionGroupIndex < FunctionContext.UnsortedSeparateExecutionGroups.Num(); ExecutionGroupIndex++)
|
|
{
|
|
bool bNeedMacro = true;
|
|
if (bManyExecutionGroups)
|
|
{
|
|
bNeedMacro = false;
|
|
for (UEdGraphNode* NodeIt : FunctionContext.UnsortedSeparateExecutionGroups[ExecutionGroupIndex])
|
|
{
|
|
UK2Node_CallFunction* CallFuncNode = Cast<UK2Node_CallFunction>(NodeIt);
|
|
if (CallFuncNode && CallFuncNode->IsLatentFunction())
|
|
{
|
|
bNeedMacro = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (!MacroUFUNCTION.IsEmpty() && bNeedMacro)
|
|
{
|
|
const FString OldExecutionFunctionName = UEdGraphSchema_K2::FN_ExecuteUbergraphBase.ToString() + TEXT("_") + FunctionContext.Blueprint->GetName();
|
|
const FString NewExecutionFunctionName = OldExecutionFunctionName + FString::Printf(TEXT("_%d"), ExecutionGroupIndex);
|
|
const FString LocMacroUFUNCTION = bManyExecutionGroups
|
|
? MacroUFUNCTION.Replace(*OldExecutionFunctionName, *NewExecutionFunctionName)
|
|
: MacroUFUNCTION;
|
|
EmitterContext.Header.AddLine(LocMacroUFUNCTION);
|
|
}
|
|
|
|
const FString ReturnType = GenerateReturnType(EmitterContext, FunctionContext.Function);
|
|
const FString ArgList = GenerateArgList(EmitterContext, ArgumentList);
|
|
const FString FunctionNamePostfix = (-1 == ExecutionGroupIndex) ? FString() : FString::Printf(TEXT("_%d"), ExecutionGroupIndex);
|
|
|
|
Result.Add(FString::Printf(TEXT("%s %s::%s%s%s%s")
|
|
, *ReturnType
|
|
, *FEmitHelper::GetCppName(EmitterContext.GetCurrentlyGeneratedClass())
|
|
, *FunctionBodyName
|
|
, *FunctionNamePostfix
|
|
, *ArgList
|
|
, bAddConst ? TEXT(" const") : TEXT("")));
|
|
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("%s%s%s %s%s%s%s%s;")
|
|
, bStaticFunction ? TEXT("static ") : TEXT("")
|
|
, bIsVirtual ? TEXT("virtual ") : TEXT("")
|
|
, *ReturnType
|
|
, *FunctionHeaderName
|
|
, *FunctionNamePostfix
|
|
, *ArgList
|
|
, bAddConst ? TEXT(" const") : TEXT("")
|
|
, bIsOverride ? TEXT(" override") : TEXT("")));
|
|
}
|
|
return Result;
|
|
}
|
|
|
|
FString FBlueprintCompilerCppBackendBase::GenerateArgList(const FEmitterLocalContext &EmitterContext, const TArray<UProperty*> &ArgumentList, bool bOnlyParamName)
|
|
{
|
|
FString ArgListStr = TEXT("(");
|
|
for (int32 i = 0; i < ArgumentList.Num(); ++i)
|
|
{
|
|
UProperty* ArgProperty = ArgumentList[i];
|
|
|
|
if (i > 0)
|
|
{
|
|
ArgListStr += TEXT(", ");
|
|
}
|
|
|
|
const FString NamePostFix = FEmitHelper::PropertyForConstCast(ArgProperty) ? TEXT("__const") : TEXT("");
|
|
if (bOnlyParamName)
|
|
{
|
|
ArgListStr += FEmitHelper::GetCppName(ArgProperty) + NamePostFix;
|
|
}
|
|
else
|
|
{
|
|
if (ArgProperty->HasAnyPropertyFlags(CPF_OutParm))
|
|
{
|
|
ArgListStr += TEXT("/*out*/ ");
|
|
}
|
|
ArgListStr += EmitterContext.ExportCppDeclaration(ArgProperty
|
|
, EExportedDeclaration::Parameter
|
|
, EPropertyExportCPPFlags::CPPF_CustomTypeName | EPropertyExportCPPFlags::CPPF_BlueprintCppBackend | EPropertyExportCPPFlags::CPPF_ArgumentOrReturnValue
|
|
, FEmitterLocalContext::EPropertyNameInDeclaration::Regular
|
|
, NamePostFix);
|
|
}
|
|
}
|
|
ArgListStr += TEXT(")");
|
|
return ArgListStr;
|
|
}
|
|
|
|
FString FBlueprintCompilerCppBackendBase::GenerateReturnType(const FEmitterLocalContext &EmitterContext, const UFunction* Function)
|
|
{
|
|
UProperty* ReturnValue = Function->GetReturnProperty();
|
|
if (ReturnValue)
|
|
{
|
|
const uint32 LocalExportCPPFlags = EPropertyExportCPPFlags::CPPF_CustomTypeName
|
|
| EPropertyExportCPPFlags::CPPF_NoConst
|
|
| EPropertyExportCPPFlags::CPPF_NoRef
|
|
| EPropertyExportCPPFlags::CPPF_NoStaticArray
|
|
| EPropertyExportCPPFlags::CPPF_BlueprintCppBackend
|
|
| EPropertyExportCPPFlags::CPPF_ArgumentOrReturnValue;
|
|
return EmitterContext.ExportCppDeclaration(ReturnValue, EExportedDeclaration::Parameter, LocalExportCPPFlags, FEmitterLocalContext::EPropertyNameInDeclaration::Skip);
|
|
}
|
|
return TEXT("void");
|
|
}
|
|
|
|
void FBlueprintCompilerCppBackendBase::ConstructFunctionBody(FEmitterLocalContext& EmitterContext, FKismetFunctionContext &FunctionContext, int32 ExecutionGroup)
|
|
{
|
|
if (FunctionContext.UnsortedSeparateExecutionGroups.Num() && (ExecutionGroup < 0))
|
|
{
|
|
// use only for latent actions..
|
|
return;
|
|
}
|
|
|
|
// Run thru code looking only at things marked as jump targets, to make sure the jump targets are ordered in order of appearance in the linear execution list
|
|
// Emit code in the order specified by the linear execution list (the first node is always the entry point for the function)
|
|
for (int32 NodeIndex = 0; NodeIndex < FunctionContext.LinearExecutionList.Num(); ++NodeIndex)
|
|
{
|
|
UEdGraphNode* StatementNode = FunctionContext.LinearExecutionList[NodeIndex];
|
|
TArray<FBlueprintCompiledStatement*>* StatementList = FunctionContext.StatementsPerNode.Find(StatementNode);
|
|
|
|
if (StatementList != NULL)
|
|
{
|
|
for (int32 StatementIndex = 0; StatementIndex < StatementList->Num(); ++StatementIndex)
|
|
{
|
|
FBlueprintCompiledStatement& Statement = *((*StatementList)[StatementIndex]);
|
|
|
|
if (Statement.bIsJumpTarget)
|
|
{
|
|
// Just making sure we number them in order of appearance, so jump statements don't influence the order
|
|
const int32 StateNum = StatementToStateIndex(FunctionContext, &Statement);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool bIsFunctionNotReducible = InnerFunctionImplementation(FunctionContext, EmitterContext, ExecutionGroup);
|
|
if (!bIsFunctionNotReducible)
|
|
{
|
|
FNativizationSummaryHelper::ReducibleFunciton(EmitterContext.Dependencies.FindOriginalClass(EmitterContext.GetCurrentlyGeneratedClass()));
|
|
}
|
|
}
|
|
|
|
void FBlueprintCompilerCppBackendBase::GenerateCodeFromEnum(UUserDefinedEnum* SourceEnum, FString& OutHeaderCode, FString& OutCPPCode)
|
|
{
|
|
check(SourceEnum);
|
|
FCodeText Header;
|
|
Header.AddLine(TEXT("#pragma once"));
|
|
const FString EnumCppName = *FEmitHelper::GetCppName(SourceEnum);
|
|
// use GetBaseFilename() so that we can coordinate #includes and filenames
|
|
Header.AddLine(FString::Printf(TEXT("#include \"%s.generated.h\""), *FEmitHelper::GetBaseFilename(SourceEnum)));
|
|
Header.AddLine(FString::Printf(TEXT("UENUM(BlueprintType, %s )"), *FEmitHelper::ReplaceConvertedMetaData(SourceEnum)));
|
|
Header.AddLine(FString::Printf(TEXT("enum class %s : uint8"), *EnumCppName));
|
|
Header.AddLine(TEXT("{"));
|
|
Header.IncreaseIndent();
|
|
|
|
auto EnumItemName = [&](int32 InIndex)
|
|
{
|
|
const int64 ElemValue = SourceEnum->GetValueByIndex(InIndex);
|
|
if (ElemValue == SourceEnum->GetMaxEnumValue())
|
|
{
|
|
return FString::Printf(TEXT("%s_MAX"), *EnumCppName);
|
|
}
|
|
return SourceEnum->GetNameStringByIndex(InIndex);
|
|
};
|
|
|
|
for (int32 Index = 0; Index < SourceEnum->NumEnums(); ++Index)
|
|
{
|
|
const FString ElemCppName = EnumItemName(Index);
|
|
const int64 ElemValue = SourceEnum->GetValueByIndex(Index);
|
|
|
|
const FString& DisplayNameMD = SourceEnum->GetMetaData(TEXT("DisplayName"), ElemValue);// TODO: value or index?
|
|
const FString MetaDisplayName = DisplayNameMD.IsEmpty() ? FString() : FString::Printf(TEXT("DisplayName = \"%s\","), *DisplayNameMD.ReplaceCharWithEscapedChar());
|
|
const FString MetaOverrideName = FString::Printf(TEXT("OverrideName = \"%s\""), *SourceEnum->GetNameByIndex(Index).ToString());
|
|
Header.AddLine(FString::Printf(TEXT("%s = %lld UMETA(%s%s),"), *ElemCppName, ElemValue, *MetaDisplayName, *MetaOverrideName));
|
|
}
|
|
|
|
Header.DecreaseIndent();
|
|
Header.AddLine(TEXT("};"));
|
|
|
|
Header.AddLine(FString::Printf(TEXT("FText %s__GetUserFriendlyName(int32 InValue);"), *EnumCppName));
|
|
|
|
OutHeaderCode = MoveTemp(Header.Result);
|
|
|
|
FCodeText Body;
|
|
|
|
const FString PCHFilename = FEmitHelper::GetPCHFilename();
|
|
if (!PCHFilename.IsEmpty())
|
|
{
|
|
Body.AddLine(FString::Printf(TEXT("#include \"%s\""), *PCHFilename));
|
|
}
|
|
else
|
|
{
|
|
// Used when generated code is not in a separate module
|
|
const FString MainHeaderFilename = FEmitHelper::GetGameMainHeaderFilename();
|
|
if (!MainHeaderFilename.IsEmpty())
|
|
{
|
|
Body.AddLine(FString::Printf(TEXT("#include \"%s\""), *MainHeaderFilename));
|
|
}
|
|
}
|
|
|
|
Body.AddLine(FString::Printf(TEXT("#include \"%s.h\""), *FEmitHelper::GetBaseFilename(SourceEnum)));
|
|
|
|
// generate implementation of GetUserFriendlyName:
|
|
Body.AddLine(FString::Printf(TEXT("FText %s__GetUserFriendlyName(int32 InValue)"), *EnumCppName, *EnumCppName));
|
|
Body.AddLine(TEXT("{"));
|
|
Body.IncreaseIndent();
|
|
|
|
Body.AddLine(TEXT("FText Text;"));
|
|
Body.AddLine(FString::Printf(TEXT("const auto EnumValue = static_cast<%s>(InValue);"), *EnumCppName));
|
|
Body.AddLine(TEXT("switch(EnumValue)"));
|
|
Body.AddLine(TEXT("{"));
|
|
Body.IncreaseIndent();
|
|
for (int32 Index = 0; Index < SourceEnum->NumEnums(); ++Index)
|
|
{
|
|
const FString ElemName = EnumItemName(Index);
|
|
FString DisplayNameStr;
|
|
FTextStringHelper::WriteToString(DisplayNameStr, SourceEnum->GetDisplayNameTextByIndex(Index));
|
|
Body.AddLine(FString::Printf(TEXT("case %s::%s: FTextStringHelper::%s(TEXT(\"%s\"), Text); break;")
|
|
, *EnumCppName, *ElemName
|
|
, GET_FUNCTION_NAME_STRING_CHECKED(FTextStringHelper, ReadFromString)
|
|
, *DisplayNameStr.ReplaceCharWithEscapedChar()));
|
|
}
|
|
|
|
Body.AddLine(TEXT("default: ensure(false);"));
|
|
Body.DecreaseIndent();
|
|
Body.AddLine(TEXT("};"));
|
|
|
|
Body.AddLine(TEXT("return Text;"));
|
|
Body.DecreaseIndent();
|
|
Body.AddLine(TEXT("};"));
|
|
|
|
OutCPPCode = MoveTemp(Body.Result);
|
|
}
|
|
|
|
FString FBlueprintCompilerCppBackendBase::GenerateCodeFromStruct(UUserDefinedStruct* SourceStruct, const FCompilerNativizationOptions& NativizationOptions)
|
|
{
|
|
check(SourceStruct);
|
|
FGatherConvertedClassDependencies Dependencies(SourceStruct, NativizationOptions);
|
|
FNativizationSummaryHelper::RegisterRequiredModules(NativizationOptions.PlatformName, Dependencies.RequiredModuleNames);
|
|
FEmitterLocalContext EmitterContext(Dependencies, NativizationOptions);
|
|
// use GetBaseFilename() so that we can coordinate #includes and filenames
|
|
EmitFileBeginning(FEmitHelper::GetBaseFilename(SourceStruct), EmitterContext, true, true);
|
|
{
|
|
FIncludedUnconvertedWrappers IncludedUnconvertedWrappers(EmitterContext, false);
|
|
const FString CppStructName = FEmitHelper::GetCppName(SourceStruct);
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("USTRUCT(BlueprintType, %s)"), *FEmitHelper::ReplaceConvertedMetaData(SourceStruct)));
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("struct %s"), *CppStructName));
|
|
EmitterContext.Header.AddLine(TEXT("{"));
|
|
EmitterContext.Header.AddLine(TEXT("public:"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("GENERATED_BODY()"));
|
|
EmitStructProperties(EmitterContext, SourceStruct);
|
|
|
|
FEmitDefaultValueHelper::GenerateGetDefaultValue(SourceStruct, EmitterContext);
|
|
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("bool operator== (const %s& __Other) const"), *CppStructName));
|
|
EmitterContext.Header.AddLine(TEXT("{"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("return %s::StaticStruct()->%s(this, &__Other, 0);"), *CppStructName, GET_FUNCTION_NAME_STRING_CHECKED(UScriptStruct, CompareScriptStruct)));
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("};"));
|
|
|
|
// Provide GetTypeHash if the struct is hashable:
|
|
if (FBlueprintEditorUtils::StructHasGetTypeHash(SourceStruct))
|
|
{
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("friend uint32 GetTypeHash(const %s& __Other) { return UUserDefinedStruct::GetUserDefinedStructTypeHash( &__Other, %s::StaticStruct()); }"), *CppStructName, *CppStructName));
|
|
}
|
|
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("};"));
|
|
}
|
|
|
|
return EmitterContext.Header.Result;
|
|
}
|
|
|
|
FString FBlueprintCompilerCppBackendBase::GenerateWrapperForClass(UClass* SourceClass, const FCompilerNativizationOptions& NativizationOptions)
|
|
{
|
|
FGatherConvertedClassDependencies Dependencies(SourceClass, NativizationOptions);
|
|
FNativizationSummaryHelper::RegisterRequiredModules(NativizationOptions.PlatformName, Dependencies.RequiredModuleNames);
|
|
FEmitterLocalContext EmitterContext(Dependencies, NativizationOptions);
|
|
|
|
UBlueprintGeneratedClass* BPGC = Cast<UBlueprintGeneratedClass>(SourceClass);
|
|
|
|
TArray<UFunction*> FunctionsToGenerate;
|
|
for (auto Func : TFieldRange<UFunction>(SourceClass, EFieldIteratorFlags::ExcludeSuper))
|
|
{
|
|
if (!Func->HasAnyFunctionFlags(FUNC_BlueprintCallable | FUNC_BlueprintPure))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (BPGC && (Func == BPGC->UberGraphFunction))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Exclude native events.. Unexpected.
|
|
// Exclude delegate signatures.
|
|
static const FName __UCSName(TEXT("UserConstructionScript"));
|
|
if (__UCSName == Func->GetFName())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
FunctionsToGenerate.Add(Func);
|
|
}
|
|
|
|
TArray<UMulticastDelegateProperty*> MCDelegateProperties;
|
|
for (auto MCDelegateProp : TFieldRange<UMulticastDelegateProperty>(SourceClass, EFieldIteratorFlags::ExcludeSuper))
|
|
{
|
|
MCDelegateProperties.Add(MCDelegateProp);
|
|
}
|
|
|
|
const bool bGenerateAnyMCDelegateProperty = (0 != MCDelegateProperties.Num());
|
|
|
|
FString ParentStruct;
|
|
UClass* SuperClassToUse = SourceClass->GetSuperClass();
|
|
{
|
|
static const FBoolConfigValueHelper DontNativizeDataOnlyBP(TEXT("BlueprintNativizationSettings"), TEXT("bDontNativizeDataOnlyBP"));
|
|
if (DontNativizeDataOnlyBP)
|
|
{
|
|
// Find first Native or Converted Or Not Data Only class
|
|
for (; SuperClassToUse; SuperClassToUse = SuperClassToUse->GetSuperClass())
|
|
{
|
|
if (SuperClassToUse->HasAnyClassFlags(CLASS_Native))
|
|
{
|
|
break;
|
|
}
|
|
UBlueprintGeneratedClass* SuperBPGC = Cast<UBlueprintGeneratedClass>(SuperClassToUse);
|
|
if (SuperBPGC && Dependencies.WillClassBeConverted(SuperBPGC))
|
|
{
|
|
break;
|
|
}
|
|
else if (SuperBPGC)
|
|
{
|
|
UBlueprint* SuperBP = Cast<UBlueprint>(SuperBPGC->ClassGeneratedBy);
|
|
if (!ensure(SuperBP) || !FBlueprintEditorUtils::IsDataOnlyBlueprint(SuperBP))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
UBlueprintGeneratedClass* SuperBPGC = Cast<UBlueprintGeneratedClass>(SuperClassToUse);
|
|
if (SuperBPGC && !Dependencies.WillClassBeConverted(SuperBPGC))
|
|
{
|
|
ParentStruct = FString::Printf(TEXT("FUnconvertedWrapper__%s"), *FEmitHelper::GetCppName(SuperBPGC));
|
|
EmitterContext.MarkUnconvertedClassAsNecessary(SuperBPGC);
|
|
}
|
|
else
|
|
{
|
|
ParentStruct = FString::Printf(TEXT("FUnconvertedWrapper<%s>"), *FEmitHelper::GetCppName(SuperClassToUse));
|
|
}
|
|
}
|
|
|
|
// Include standard stuff
|
|
EmitFileBeginning(FEmitHelper::GetBaseFilename(SourceClass), EmitterContext, bGenerateAnyMCDelegateProperty, true, true, SuperClassToUse);
|
|
|
|
{
|
|
FIncludedUnconvertedWrappers IncludedUnconvertedWrappers(EmitterContext, false);
|
|
|
|
// DELEGATES
|
|
const FString DelegatesClassName = FString::Printf(TEXT("U__Delegates__%s"), *FEmitHelper::GetCppName(SourceClass));
|
|
auto GenerateMulticastDelegateTypeName = [](UMulticastDelegateProperty* MCDelegateProp) -> FString
|
|
{
|
|
return FString::Printf(TEXT("F__MulticastDelegate__%s"), *FEmitHelper::GetCppName(MCDelegateProp));
|
|
};
|
|
if (bGenerateAnyMCDelegateProperty)
|
|
{
|
|
EmitterContext.Header.AddLine(TEXT("UCLASS()"));
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("class %s : public UObject"), *DelegatesClassName));
|
|
EmitterContext.Header.AddLine(TEXT("{"));
|
|
EmitterContext.Header.AddLine(TEXT("public:"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("GENERATED_BODY()"));
|
|
for (auto MCDelegateProp : MCDelegateProperties)
|
|
{
|
|
FString ParamNumberStr, Parameters;
|
|
FEmitHelper::ParseDelegateDetails(EmitterContext, MCDelegateProp->SignatureFunction, Parameters, ParamNumberStr);
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("DECLARE_DYNAMIC_MULTICAST_DELEGATE%s(%s%s);"), *ParamNumberStr, *GenerateMulticastDelegateTypeName(MCDelegateProp), *Parameters));
|
|
}
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("};"));
|
|
}
|
|
|
|
// Begin the struct
|
|
const FString WrapperName = FString::Printf(TEXT("FUnconvertedWrapper__%s"), *FEmitHelper::GetCppName(SourceClass));
|
|
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("struct %s : public %s"), *WrapperName, *ParentStruct));
|
|
EmitterContext.Header.AddLine(TEXT("{"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
|
|
// Constructor
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("%s(const %s* __InObject) : %s(__InObject){}"), *WrapperName, *FEmitHelper::GetCppName(EmitterContext.GetFirstNativeOrConvertedClass(SourceClass)), *ParentStruct));
|
|
|
|
static const FBoolConfigValueHelper UseStaticVariables(TEXT("BlueprintNativizationSettings"), TEXT("bUseStaticVariablesInWrappers"));
|
|
const bool bUseStaticVariables = UseStaticVariables;
|
|
|
|
// PROPERTIES:
|
|
for (auto Property : TFieldRange<UProperty>(SourceClass, EFieldIteratorFlags::ExcludeSuper))
|
|
{
|
|
if (BPGC && (Property == BPGC->UberGraphFramePointerProperty))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (Cast<UAnimBlueprintGeneratedClass>(BPGC))
|
|
{
|
|
// Dont generate Getters for inner properties
|
|
UStructProperty* StructProperty = Cast<UStructProperty>(Property);
|
|
UScriptStruct* InnerStruct = StructProperty ? StructProperty->Struct : nullptr;
|
|
if (InnerStruct && InnerStruct->IsChildOf(FAnimNode_Base::StaticStruct()))
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
|
|
//TODO: check if the property is really used?
|
|
const FString TypeDeclaration = Property->IsA<UMulticastDelegateProperty>()
|
|
? FString::Printf(TEXT("%s::%s"), *DelegatesClassName, *GenerateMulticastDelegateTypeName(CastChecked<UMulticastDelegateProperty>(Property)))
|
|
: EmitterContext.ExportCppDeclaration(Property
|
|
, EExportedDeclaration::Parameter
|
|
, EPropertyExportCPPFlags::CPPF_CustomTypeName | EPropertyExportCPPFlags::CPPF_BlueprintCppBackend | EPropertyExportCPPFlags::CPPF_NoRef | EPropertyExportCPPFlags::CPPF_NoConst
|
|
, FEmitterLocalContext::EPropertyNameInDeclaration::Skip);
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("FORCENOINLINE %s& GetRef__%s()"), *TypeDeclaration, *UnicodeToCPPIdentifier(Property->GetName(), false, nullptr)));
|
|
EmitterContext.Header.AddLine(TEXT("{"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
if (bUseStaticVariables)
|
|
{
|
|
EmitterContext.Header.AddLine(TEXT("static TWeakObjectPtr<UProperty> __PropertyPtr{};"));
|
|
EmitterContext.Header.AddLine(TEXT("const UProperty* __Property = __PropertyPtr.Get();"));
|
|
EmitterContext.Header.AddLine(TEXT("if (nullptr == __Property)"));
|
|
EmitterContext.Header.AddLine(TEXT("{"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("__Property = GetClass()->%s(FName(TEXT(\"%s\")));"), GET_FUNCTION_NAME_STRING_CHECKED(UClass, FindPropertyByName), *Property->GetName()));
|
|
EmitterContext.Header.AddLine(TEXT("check(__Property);"));
|
|
EmitterContext.Header.AddLine(TEXT("__PropertyPtr = __Property;"));
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("}"));
|
|
}
|
|
else
|
|
{
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("const UProperty* __Property = GetClass()->%s(FName(TEXT(\"%s\")));"), GET_FUNCTION_NAME_STRING_CHECKED(UClass, FindPropertyByName), *Property->GetName()));
|
|
}
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("return *(__Property->ContainerPtrToValuePtr<%s>(__Object));"), *TypeDeclaration));
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("}"));
|
|
}
|
|
|
|
// FUNCTIONS:
|
|
for (auto Func : FunctionsToGenerate)
|
|
{
|
|
TArray<FString> FuncParameters;
|
|
const FString ParamNameInStructPostfix(TEXT("_"));
|
|
const FString FuncCppName = FEmitHelper::GetCppName(Func);
|
|
FString DelareFunction = FString::Printf(TEXT("FORCENOINLINE void %s("), *FuncCppName);
|
|
FString RawParameterList;
|
|
{
|
|
bool bFirst = true;
|
|
for (TFieldIterator<UProperty> It(Func); It; ++It)
|
|
{
|
|
UProperty* Property = *It;
|
|
if (!Property || !Property->HasAnyPropertyFlags(CPF_Parm))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!bFirst)
|
|
{
|
|
DelareFunction += TEXT(", ");
|
|
RawParameterList += TEXT(", ");
|
|
}
|
|
else
|
|
{
|
|
bFirst = false;
|
|
}
|
|
|
|
if (Property->HasAnyPropertyFlags(CPF_OutParm))
|
|
{
|
|
DelareFunction += TEXT("/*out*/ ");
|
|
}
|
|
|
|
DelareFunction += EmitterContext.ExportCppDeclaration(Property, EExportedDeclaration::Parameter, EPropertyExportCPPFlags::CPPF_CustomTypeName | EPropertyExportCPPFlags::CPPF_BlueprintCppBackend);
|
|
FString ParamAsStructMember;
|
|
|
|
{ // copied from FNativeClassHeaderGenerator::ExportEventParm
|
|
bool bEmitConst = Property->HasAnyPropertyFlags(CPF_ConstParm) && Property->IsA<UObjectProperty>();
|
|
const bool bIsConstParam = (Property->IsA(UInterfaceProperty::StaticClass()) && !Property->HasAllPropertyFlags(CPF_OutParm));
|
|
const bool bIsOnConstClass = (Property->IsA(UObjectProperty::StaticClass()) && ((UObjectProperty*)Property)->PropertyClass != NULL && ((UObjectProperty*)Property)->PropertyClass->HasAnyClassFlags(CLASS_Const));
|
|
if (bIsConstParam || bIsOnConstClass)
|
|
{
|
|
bEmitConst = false; // ExportCppDeclaration will do it for us
|
|
}
|
|
|
|
if (bEmitConst)
|
|
{
|
|
ParamAsStructMember = TEXT("const ");
|
|
}
|
|
}
|
|
ParamAsStructMember += EmitterContext.ExportCppDeclaration(Property
|
|
, EExportedDeclaration::Local
|
|
, EPropertyExportCPPFlags::CPPF_CustomTypeName | EPropertyExportCPPFlags::CPPF_BlueprintCppBackend
|
|
, FEmitterLocalContext::EPropertyNameInDeclaration::Regular
|
|
, ParamNameInStructPostfix);
|
|
FuncParameters.Emplace(ParamAsStructMember);
|
|
RawParameterList += UnicodeToCPPIdentifier(Property->GetName(), Property->HasAnyPropertyFlags(CPF_Deprecated), TEXT("bpp__"));
|
|
}
|
|
}
|
|
DelareFunction += TEXT(")");
|
|
EmitterContext.Header.AddLine(DelareFunction);
|
|
EmitterContext.Header.AddLine(TEXT("{"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
|
|
if (bUseStaticVariables)
|
|
{
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("static const FName __FunctionName(TEXT(\"%s\"));"), *Func->GetName()));
|
|
}
|
|
const FString FuncNameStr = bUseStaticVariables ? TEXT("__FunctionName") : FString::Printf(TEXT("FName(TEXT(\"%s\"))"), *Func->GetName());
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("UFunction* __Function = __Object->%s(%s);"), GET_FUNCTION_NAME_STRING_CHECKED(UObject, FindFunctionChecked), *FuncNameStr));
|
|
|
|
const FString FuncParametersStructName = FuncParameters.Num() ? (FuncCppName + TEXT("_Parameters")) : FString();
|
|
if (FuncParameters.Num())
|
|
{
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("struct %s"), *FuncParametersStructName));
|
|
EmitterContext.Header.AddLine(TEXT("{"));
|
|
EmitterContext.Header.IncreaseIndent();
|
|
for (FString& Param : FuncParameters)
|
|
{
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("%s;"), *Param));
|
|
}
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("};"));
|
|
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("%s __Parameters { %s };"), *FuncParametersStructName, *RawParameterList));
|
|
}
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("__Object->%s(__Function, %s);"), GET_FUNCTION_NAME_STRING_CHECKED(UObject, ProcessEvent), FuncParameters.Num() ? TEXT("&__Parameters") : TEXT("nullptr")));
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("}"));
|
|
}
|
|
|
|
// close struct
|
|
EmitterContext.Header.DecreaseIndent();
|
|
EmitterContext.Header.AddLine(TEXT("};"));
|
|
}
|
|
return EmitterContext.Header.Result;
|
|
}
|
|
|
|
void FBlueprintCompilerCppBackendBase::EmitFileBeginning(const FString& CleanName, FEmitterLocalContext& EmitterContext, bool bIncludeGeneratedH, bool bIncludeCodeHelpersInHeader, bool bFullyIncludedDeclaration, UField* AdditionalFieldToIncludeInHeader)
|
|
{
|
|
EmitterContext.Header.AddLine(TEXT("#pragma once"));
|
|
|
|
const FString PCHFilename = FEmitHelper::GetPCHFilename();
|
|
if (!PCHFilename.IsEmpty())
|
|
{
|
|
FIncludeHeaderHelper::EmitIncludeHeader(EmitterContext.Body, *PCHFilename, false);
|
|
}
|
|
else
|
|
{
|
|
// Used when generated code is not in a separate module
|
|
const FString MainHeaderFilename = FEmitHelper::GetGameMainHeaderFilename();
|
|
if (!MainHeaderFilename.IsEmpty())
|
|
{
|
|
FIncludeHeaderHelper::EmitIncludeHeader(EmitterContext.Body, *MainHeaderFilename, false);
|
|
}
|
|
}
|
|
FIncludeHeaderHelper::EmitIncludeHeader(EmitterContext.Body, *CleanName, true);
|
|
FIncludeHeaderHelper::EmitIncludeHeader(bIncludeCodeHelpersInHeader ? EmitterContext.Header : EmitterContext.Body, TEXT("GeneratedCodeHelpers"), true);
|
|
FIncludeHeaderHelper::EmitIncludeHeader(EmitterContext.Header, TEXT("Blueprint/BlueprintSupport"), true);
|
|
|
|
FBackendHelperUMG::AdditionalHeaderIncludeForWidget(EmitterContext);
|
|
FBackendHelperAnim::AddHeaders(EmitterContext);
|
|
|
|
TSet<FString> AlreadyIncluded;
|
|
AlreadyIncluded.Add(CleanName);
|
|
|
|
TSet<UField*> IncludeInBody = EmitterContext.Dependencies.IncludeInBody;
|
|
TSet<UField*> IncludeInHeader = EmitterContext.Dependencies.IncludeInHeader;
|
|
if (AdditionalFieldToIncludeInHeader)
|
|
{
|
|
IncludeInHeader.Add(AdditionalFieldToIncludeInHeader);
|
|
}
|
|
FIncludeHeaderHelper::EmitInner(EmitterContext.Header, IncludeInHeader, bFullyIncludedDeclaration ? TSet<UField*>() : EmitterContext.Dependencies.DeclareInHeader, AlreadyIncluded);
|
|
if (bFullyIncludedDeclaration)
|
|
{
|
|
FIncludeHeaderHelper::EmitInner(EmitterContext.Header, EmitterContext.Dependencies.DeclareInHeader, TSet<UField*>(), AlreadyIncluded);
|
|
}
|
|
else
|
|
{
|
|
IncludeInBody.Append(EmitterContext.Dependencies.DeclareInHeader);
|
|
}
|
|
FIncludeHeaderHelper::EmitInner(EmitterContext.Body, IncludeInBody, TSet<UField*>(), AlreadyIncluded);
|
|
|
|
if (bIncludeGeneratedH)
|
|
{
|
|
EmitterContext.Header.AddLine(FString::Printf(TEXT("#include \"%s.generated.h\""), *CleanName));
|
|
}
|
|
}
|
|
|
|
void FBlueprintCompilerCppBackendBase::CleanBackend()
|
|
{
|
|
StateMapPerFunction.Empty();
|
|
FunctionIndexMap.Empty();
|
|
UberGraphContext = nullptr;
|
|
UberGraphStatementToExecutionGroup.Empty();
|
|
}
|