Files
UnrealEngineUWP/Engine/Source/Programs/UnrealHeaderTool/Private/Scope.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

192 lines
4.0 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "UnrealHeaderTool.h"
#include "ParserHelper.h"
#include "Scope.h"
#include "UHTMakefile/UHTMakefile.h"
extern FCompilerMetadataManager GScriptHelper;
FScope::FScope(FScope* InParent)
: Parent(InParent)
{ }
FScope::FScope()
: Parent(nullptr)
{
}
void FScope::AddType(UField* Type)
{
TypeMap.Add(Type->GetFName(), Type);
}
/**
* Dispatch type to one of three arrays Enums, Structs and DelegateFunctions.
*
* @param Type Input type.
* @param Enums (Output parameter) Array to fill with enums.
* @param Structs (Output parameter) Array to fill with structs.
* @param DelegateFunctions (Output parameter) Array to fill with delegate functions.
*/
void DispatchType(UField* Type, TArray<UEnum*> &Enums, TArray<UScriptStruct*> &Structs, TArray<UDelegateFunction*> &DelegateFunctions)
{
UClass* TypeClass = Type->GetClass();
if (TypeClass == UClass::StaticClass() || TypeClass == UStruct::StaticClass())
{
// Inner scopes.
FScope::GetTypeScope((UStruct*)Type)->SplitTypesIntoArrays(Enums, Structs, DelegateFunctions);
}
else if (TypeClass == UEnum::StaticClass())
{
UEnum* Enum = (UEnum*)Type;
Enums.Add(Enum);
}
else if (TypeClass == UScriptStruct::StaticClass())
{
UScriptStruct* Struct = (UScriptStruct*)Type;
Structs.Add(Struct);
}
else if (TypeClass == UDelegateFunction::StaticClass())
{
bool bAdded = false;
UDelegateFunction* Function = (UDelegateFunction*)Type;
if (Function->GetSuperFunction() == NULL)
{
DelegateFunctions.Add(Function);
bAdded = true;
}
check(bAdded);
}
}
void FScope::SplitTypesIntoArrays(TArray<UEnum*>& Enums, TArray<UScriptStruct*>& Structs, TArray<UDelegateFunction*>& DelegateFunctions)
{
for (auto& TypePair : TypeMap)
{
auto* Type = TypePair.Value;
DispatchType(Type, Enums, Structs, DelegateFunctions);
}
}
TSharedRef<FScope> FScope::GetTypeScope(UStruct* Type)
{
auto* ScopeRefPtr = ScopeMap.Find(Type);
if (!ScopeRefPtr)
{
FError::Throwf(TEXT("Couldn't find scope for the type %s."), *Type->GetName());
}
return *ScopeRefPtr;
}
TSharedRef<FScope> FScope::AddTypeScope(UStruct* Type, FScope* ParentScope, FUnrealSourceFile* UnrealSourceFile, FUHTMakefile& UHTMakefile)
{
FStructScope* ScopePtr = new FStructScope(Type, ParentScope);
TSharedRef<FScope> Scope = MakeShareable(ScopePtr);
ScopeMap.Add(Type, Scope);
UHTMakefile.AddStructScope(UnrealSourceFile, ScopePtr);
return Scope;
}
UField* FScope::FindTypeByName(FName Name)
{
auto TypeIterator = TDeepScopeTypeIterator<UField, false>(this);
while (TypeIterator.MoveNext())
{
auto* Type = *TypeIterator;
if (Type->GetFName() == Name)
{
return Type;
}
}
return nullptr;
}
const UField* FScope::FindTypeByName(FName Name) const
{
auto TypeIterator = GetTypeIterator();
while (TypeIterator.MoveNext())
{
auto* Type = *TypeIterator;
if (Type->GetFName() == Name)
{
return Type;
}
}
return nullptr;
}
bool FScope::ContainsType(UField* Type)
{
return FindTypeByName(Type->GetFName()) != nullptr;
}
bool FScope::IsFileScope() const
{
return Parent == nullptr;
}
bool FScope::ContainsTypes() const
{
return TypeMap.Num() > 0;
}
FFileScope* FScope::GetFileScope()
{
FScope* CurrentScope = this;
while (!CurrentScope->IsFileScope())
{
CurrentScope = const_cast<FScope*>(CurrentScope->GetParent());
}
return CurrentScope->AsFileScope();
}
TMap<UStruct*, TSharedRef<FScope> > FScope::ScopeMap;
FFileScope::FFileScope(FName InName, FUnrealSourceFile* InSourceFile)
: SourceFile(InSourceFile), Name(InName)
{ }
void FFileScope::IncludeScope(FFileScope* IncludedScope)
{
IncludedScopes.Add(IncludedScope);
}
FUnrealSourceFile* FFileScope::GetSourceFile() const
{
return SourceFile;
}
FName FFileScope::GetName() const
{
return Name;
}
UStruct* FStructScope::GetStruct() const
{
return Struct;
}
FName FStructScope::GetName() const
{
return Struct->GetFName();
}
FStructScope::FStructScope(UStruct* InStruct, FScope* InParent)
: FScope(InParent), Struct(InStruct)
{
}