Files
UnrealEngineUWP/Engine/Source/Programs/UnrealHeaderTool/Private/ParserHelper.cpp
Robert Manuszewski f9cdeb96cd Copying //UE4/Dev-Core to //UE4/Main
==========================
MAJOR FEATURES + CHANGES
==========================

Change 2717513 on 2015/10/06 by Robert.Manuszewski@Robert_Manuszewski_EGUK_M1

	GC and WeakObjectPtr performance optimizations.

	- Moved some of the EObjectFlags to EInternalObjectFlags and merged them with FUObjectArray
	- Moved WeakObjectPtr serial numbersto FUObjectArray
	- Added pre-allocated UObject array

Change 2716517 on 2015/10/05 by Robert.Manuszewski@Robert_Manuszewski_EGUK_M1

	Make SavePackage thread safe UObject-wise so that StaticFindObject etc can't run in parallel when packages are being saved.

Change 2721142 on 2015/10/08 by Mikolaj.Sieluzycki@Dev-Core_D0920

	UHT will now use makefiles to speed up iterative runs.

Change 2726320 on 2015/10/13 by Jaroslaw.Palczynski@jaroslaw.palczynski_D1732_2963

	Hot-reload performance optimizations:
	1. Got rid of redundant touched BPs optimization (which was necessary before major HR fixes submitted earlier).
	2. Parallelized search for old CDOs referencers.

Change 2759032 on 2015/11/09 by Graeme.Thornton@GThornton_DesktopMaster

	Dependency preloading improvements
	 - Asset registry dependencies now resolve asset redirectors
	 - Rearrange runtime loading to put dependency preloads within BeginLoad/EndLoad for the source package

Change 2754342 on 2015/11/04 by Robert.Manuszewski@Robert_Manuszewski_Stream1

	Allow UnfocusedVolumeMultiplier to be set programmatically

Change 2764008 on 2015/11/12 by Robert.Manuszewski@Robert_Manuszewski_Stream1

	When cooking, don't add imports that are outers of objects excluded from the current cook target.

Change 2755562 on 2015/11/05 by Steve.Robb@Dev-Core

	Inline storage for TFunction.
	Fix for delegate inline storage on Win64.
	Some build fixes.
	Visualizer fixes for new TFunction format.

Change 2735084 on 2015/10/20 by Jaroslaw.Surowiec@Stream.1.JarekSurowiec

	CrashReporter Web - Search by Platform
	Added initial support for streams (GetBranchesAsListItems, CopyToJira)

Change 2762387 on 2015/11/11 by Steve.Robb@Dev-Core

	Unnecessary allocation removed when loading empty files in FFileHelper::LoadFileToString.

Change 2762632 on 2015/11/11 by Steve.Robb@Dev-Core

	Some TSet function optimisations:

	Avoiding unnecessary hashing of function arguments if the container is empty (rather than the hash being empty, which is not necessarily equivalent).
	Taking local copies of HashSize during iterations.

Change 2762936 on 2015/11/11 by Steve.Robb@Dev-Core

	BulkData zero byte allocations are now handled by an RAII object which owns the memory.

Change 2765758 on 2015/11/13 by Steve.Robb@Dev-Core

	FName::operator== and != optimised to be a single comparison.

Change 2757195 on 2015/11/06 by Jaroslaw.Surowiec@Stream.1.JarekSurowiec

	PR #1305: Improvements in CrashReporter for Symbol Server usage (Contributed by bozaro)

Change 2760778 on 2015/11/10 by Jaroslaw.Surowiec@Stream.1.JarekSurowiec

	PR #1725: Fixed typos in ProfilerCommon.h; Added comments (Contributed by BGR360)

	Also fixed starting condition.

Change 2739804 on 2015/10/23 by Robert.Manuszewski@Robert_Manuszewski_Stream1

	PR #1470: [UObjectGlobals] Do not overwrite instanced subobjects with ones from CDO (Contributed by slonopotamus)

Change 2744733 on 2015/10/28 by Steve.Robb@Dev-Core

	PR #1540 - Specifying a different Saved folder at launch through a command line parameter

	Integrated and optimized.

#lockdown Nick.Penwarden

[CL 2772222 by Robert Manuszewski in Main branch]
2015-11-18 16:20:49 -05:00

322 lines
8.1 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "UnrealHeaderTool.h"
#include "ParserHelper.h"
#include "DefaultValueHelper.h"
#include "UHTMakefile/UHTMakefile.h"
/////////////////////////////////////////////////////
// FClassMetaData
/**
* Finds the metadata for the property specified
*
* @param Prop the property to search for
*
* @return pointer to the metadata for the property specified, or NULL
* if the property doesn't exist in the list (for example, if it
* is declared in a package that is already compiled and has had its
* source stripped)
*/
FTokenData* FClassMetaData::FindTokenData( UProperty* Prop )
{
check(Prop);
FTokenData* Result = nullptr;
UObject* Outer = Prop->GetOuter();
UClass* OuterClass = nullptr;
if (Outer->IsA<UStruct>())
{
Result = GlobalPropertyData.Find(Prop);
if (Result == nullptr)
{
OuterClass = Cast<UClass>(Outer);
if (Result == nullptr && OuterClass != nullptr && OuterClass->GetSuperClass() != OuterClass)
{
OuterClass = OuterClass->GetSuperClass();
}
}
}
else
{
UFunction* OuterFunction = Cast<UFunction>(Outer);
if ( OuterFunction != NULL )
{
// function parameter, return, or local property
FFunctionData* FuncData = nullptr;
if (FFunctionData::TryFindForFunction(OuterFunction, FuncData))
{
FPropertyData& FunctionParameters = FuncData->GetParameterData();
Result = FunctionParameters.Find(Prop);
if ( Result == NULL )
{
Result = FuncData->GetReturnTokenData();
}
}
else
{
OuterClass = OuterFunction->GetOwnerClass();
}
}
else
{
// struct property
UScriptStruct* OuterStruct = Cast<UScriptStruct>(Outer);
check(OuterStruct != NULL);
OuterClass = OuterStruct->GetOwnerClass();
}
}
if (Result == nullptr && OuterClass != nullptr)
{
FClassMetaData* SuperClassData = GScriptHelper.FindClassData(OuterClass);
if (SuperClassData && SuperClassData != this)
{
Result = SuperClassData->FindTokenData(Prop);
}
}
return Result;
}
void FClassMetaData::AddInheritanceParent(const FString& InParent, FUHTMakefile& UHTMakefile, FUnrealSourceFile* UnrealSourceFile)
{
MultipleInheritanceParents.Add(new FMultipleInheritanceBaseClass(InParent));
UHTMakefile.AddMultipleInheritanceBaseClass(UnrealSourceFile, MultipleInheritanceParents.Last());
}
void FClassMetaData::AddInheritanceParent(UClass* ImplementedInterfaceClass, FUHTMakefile& UHTMakefile, FUnrealSourceFile* UnrealSourceFile)
{
MultipleInheritanceParents.Add(new FMultipleInheritanceBaseClass(ImplementedInterfaceClass));
UHTMakefile.AddMultipleInheritanceBaseClass(UnrealSourceFile, MultipleInheritanceParents.Last());
}
/////////////////////////////////////////////////////
// FPropertyBase
const TCHAR* FPropertyBase::GetPropertyTypeText( EPropertyType Type )
{
switch ( Type )
{
CASE_TEXT(CPT_None);
CASE_TEXT(CPT_Byte);
CASE_TEXT(CPT_Int8);
CASE_TEXT(CPT_Int16);
CASE_TEXT(CPT_Int);
CASE_TEXT(CPT_Int64);
CASE_TEXT(CPT_UInt16);
CASE_TEXT(CPT_UInt32);
CASE_TEXT(CPT_UInt64);
CASE_TEXT(CPT_Bool);
CASE_TEXT(CPT_Bool8);
CASE_TEXT(CPT_Bool16);
CASE_TEXT(CPT_Bool32);
CASE_TEXT(CPT_Bool64);
CASE_TEXT(CPT_Float);
CASE_TEXT(CPT_Double);
CASE_TEXT(CPT_ObjectReference);
CASE_TEXT(CPT_Interface);
CASE_TEXT(CPT_Name);
CASE_TEXT(CPT_Delegate);
CASE_TEXT(CPT_Range);
CASE_TEXT(CPT_Struct);
CASE_TEXT(CPT_Vector);
CASE_TEXT(CPT_Rotation);
CASE_TEXT(CPT_String);
CASE_TEXT(CPT_Text);
CASE_TEXT(CPT_MulticastDelegate);
CASE_TEXT(CPT_AssetObjectReference);
CASE_TEXT(CPT_WeakObjectReference);
CASE_TEXT(CPT_LazyObjectReference);
CASE_TEXT(CPT_Map);
CASE_TEXT(CPT_MAX);
}
return TEXT("");
}
/////////////////////////////////////////////////////
// FToken
/**
* Copies the properties from this token into another.
*
* @param Other the token to copy this token's properties to.
*/
void FToken::Clone( const FToken& Other )
{
// none of FPropertyBase's members require special handling
(FPropertyBase&)*this = (FPropertyBase&)Other;
TokenType = Other.TokenType;
TokenName = Other.TokenName;
StartPos = Other.StartPos;
StartLine = Other.StartLine;
TokenProperty = Other.TokenProperty;
FCString::Strncpy(Identifier, Other.Identifier, NAME_SIZE);
FMemory::Memcpy(String, Other.String, sizeof(String));
}
/////////////////////////////////////////////////////
// FAdvancedDisplayParameterHandler
FAdvancedDisplayParameterHandler::FAdvancedDisplayParameterHandler(const TMap<FName, FString>* MetaData)
: NumberLeaveUnmarked(-1), AlreadyLeft(0), bUseNumber(false)
{
if(MetaData)
{
const FString* FoundString = MetaData->Find(FName(TEXT("AdvancedDisplay")));
if(FoundString)
{
FoundString->ParseIntoArray(ParametersNames, TEXT(","), true);
for(int32 NameIndex = 0; NameIndex < ParametersNames.Num();)
{
FString& ParameterName = ParametersNames[NameIndex];
ParameterName.Trim();
ParameterName.TrimTrailing();
if(ParameterName.IsEmpty())
{
ParametersNames.RemoveAtSwap(NameIndex);
}
else
{
++NameIndex;
}
}
if(1 == ParametersNames.Num())
{
bUseNumber = FDefaultValueHelper::ParseInt(ParametersNames[0], NumberLeaveUnmarked);
}
}
}
}
bool FAdvancedDisplayParameterHandler::ShouldMarkParameter(const FString& ParameterName)
{
if(bUseNumber)
{
if(NumberLeaveUnmarked < 0)
{
return false;
}
if(AlreadyLeft < NumberLeaveUnmarked)
{
AlreadyLeft++;
return false;
}
return true;
}
return ParametersNames.Contains(ParameterName);
}
bool FAdvancedDisplayParameterHandler::CanMarkMore() const
{
return bUseNumber ? (NumberLeaveUnmarked > 0) : (0 != ParametersNames.Num());
}
TMap<UFunction*, TUniqueObj<FFunctionData> > FFunctionData::FunctionDataMap;
FFunctionData* FFunctionData::FindForFunction(UFunction* Function)
{
TUniqueObj<FFunctionData>* Output = FunctionDataMap.Find(Function);
check(Output);
return &(*Output).Get();
}
FFunctionData* FFunctionData::Add(UFunction* Function)
{
TUniqueObj<FFunctionData>& Output = FunctionDataMap.Add(Function);
return &Output.Get();
}
FFunctionData* FFunctionData::Add(const FFuncInfo& FunctionInfo)
{
TUniqueObj<FFunctionData>& Output = FunctionDataMap.Emplace(FunctionInfo.FunctionReference, FunctionInfo);
return &Output.Get();
}
bool FFunctionData::TryFindForFunction(UFunction* Function, FFunctionData*& OutData)
{
TUniqueObj<FFunctionData>* Output = FunctionDataMap.Find(Function);
if (!Output)
{
return false;
}
OutData = &(*Output).Get();
return true;
}
FClassMetaData* FCompilerMetadataManager::AddClassData(UStruct* Struct, FUHTMakefile& UHTMakefile, FUnrealSourceFile* UnrealSourceFile)
{
TScopedPointer<FClassMetaData>* pClassData = Find(Struct);
if (pClassData == NULL)
{
pClassData = &Emplace(Struct, new FClassMetaData());
if (UnrealSourceFile)
{
UHTMakefile.AddClassMetaData(UnrealSourceFile, *pClassData);
}
}
return *pClassData;
}
FTokenData* FPropertyData::Set(UProperty* InKey, const FTokenData& InValue, FUHTMakefile& UHTMakefile, FUnrealSourceFile* UnrealSourceFile)
{
FTokenData* Result = NULL;
TSharedPtr<FTokenData>* pResult = Super::Find(InKey);
if (pResult != NULL)
{
Result = pResult->Get();
*Result = FTokenData(InValue);
}
else
{
pResult = &Super::Emplace(InKey, new FTokenData(InValue));
Result = pResult->Get();
UHTMakefile.AddPropertyDataEntry(UnrealSourceFile, *pResult, InKey);
}
return Result;
}
const TCHAR* FNameLookupCPP::GetNameCPP(UStruct* Struct, bool bForceInterface /*= false */)
{
TCHAR* NameCPP = StructNameMap.FindRef(Struct);
if (NameCPP && !bForceInterface)
{
return NameCPP;
}
FString DesiredStructName = Struct->GetName();
FString TempName = FString(bForceInterface ? TEXT("I") : Struct->GetPrefixCPP()) + DesiredStructName;
int32 StringLength = TempName.Len();
NameCPP = new TCHAR[StringLength + 1];
FCString::Strcpy(NameCPP, StringLength + 1, *TempName);
NameCPP[StringLength] = 0;
if (bForceInterface)
{
InterfaceAllocations.Add(NameCPP);
UHTMakefile->AddInterfaceAllocation(UnrealSourceFile, NameCPP);
}
else
{
StructNameMap.Add(Struct, NameCPP);
UHTMakefile->AddStructNameMapEntry(UnrealSourceFile, Struct, NameCPP);
}
return NameCPP;
}