Files
UnrealEngineUWP/Engine/Source/Programs/UnrealHeaderTool/Private/Classes.cpp

215 lines
5.8 KiB
C++
Raw Normal View History

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "Classes.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "UnrealHeaderTool.h"
#include "UObject/ErrorException.h"
#include "UObject/Package.h"
#include "Templates/Casts.h"
#include "UObject/ObjectRedirector.h"
#include "StringUtils.h"
namespace
{
/**
* Returns True if the given class name includes a valid Unreal prefix and matches based on the given class.
*
* @param InNameToCheck - Name w/ potential prefix to check
* @param OriginalClass - Class to check against
*/
bool ClassNameHasValidPrefix(const FString InNameToCheck, const FClass* OriginalClass)
{
bool bIsLabledDeprecated;
GetClassPrefix( InNameToCheck, bIsLabledDeprecated );
// If the class is labeled deprecated, don't try to resolve it during header generation, valid results can't be guaranteed.
if (bIsLabledDeprecated)
{
return true;
}
const FString OriginalClassName = OriginalClass->GetNameWithPrefix();
bool bNamesMatch = (InNameToCheck == OriginalClassName);
if (!bNamesMatch)
{
//@TODO: UCREMOVAL: I/U interface hack - Ignoring prefixing for this call
if (OriginalClass->HasAnyClassFlags(CLASS_Interface))
{
bNamesMatch = InNameToCheck.Mid(1) == OriginalClassName.Mid(1);
}
}
return bNamesMatch;
}
}
FClasses::FClasses(UPackage* InPackage)
: UObjectClass((FClass*)UObject::StaticClass())
, ClassTree (UObjectClass)
{
for (UClass* Class : TObjectRange<UClass>())
{
if (Class->IsIn(InPackage))
{
ClassTree.AddClass(Class);
}
}
}
FClass* FClasses::GetRootClass() const
{
return UObjectClass;
}
bool FClasses::IsDependentOn(const FClass* Suspect, const FClass* Source) const
{
check(Suspect != Source);
TSet<const FClass*> VisitedDpendencies;
return IsDependentOn(Suspect, Source, VisitedDpendencies);
}
bool FClasses::IsDependentOn(const FClass* Suspect, const FClass* Source, TSet<const FClass*>& VisitedDpendencies) const
{
// Children are all implicitly dependent on their parent, that is, children require their parent
// to be compiled first therefore if the source is a parent of the suspect, the suspect is
// dependent on the source.
if (Suspect->IsChildOf(Source))
{
return true;
}
// Prevent circular #includes from causing inifinite recursion
// Note that although it may mean there's a circular dependency somewhere, it does not
// necessarily mean it's the one we're looking for
if (VisitedDpendencies.Contains(Suspect))
{
return false;
}
else
{
VisitedDpendencies.Add(Suspect);
}
return false;
}
FClass* FClasses::FindClass(const TCHAR* ClassName) const
{
check(ClassName);
UObject* ClassPackage = ANY_PACKAGE;
if (UClass* Result = FindObject<UClass>(ClassPackage, ClassName))
return (FClass*)Result;
if (UObjectRedirector* RenamedClassRedirector = FindObject<UObjectRedirector>(ClassPackage, ClassName))
return (FClass*)CastChecked<UClass>(RenamedClassRedirector->DestinationObject);
return nullptr;
}
TArray<FClass*> FClasses::GetDerivedClasses(FClass* Parent) const
{
const FClassTree* ClassLeaf = ClassTree.FindNode(Parent);
TArray<const FClassTree*> ChildLeaves;
ClassLeaf->GetChildClasses(ChildLeaves);
TArray<FClass*> Result;
for (auto Node : ChildLeaves)
{
Result.Add((FClass*)Node->GetClass());
}
return Result;
}
FClass* FClasses::FindAnyClass(const TCHAR* ClassName) const
{
check(ClassName);
return (FClass*)FindObject<UClass>(ANY_PACKAGE, ClassName);
}
FClass* FClasses::FindScriptClass(const FString& InClassName) const
{
FString ErrorMsg;
return FindScriptClass(InClassName, ErrorMsg);
}
FClass* FClasses::FindScriptClassOrThrow(const FString& InClassName) const
{
FString ErrorMsg;
if (FClass* Result = FindScriptClass(InClassName, ErrorMsg))
{
return Result;
}
FError::Throwf(*ErrorMsg);
// Unreachable, but compiler will warn otherwise because FError::Throwf isn't declared noreturn
return 0;
}
FClass* FClasses::FindScriptClass(const FString& InClassName, FString& OutErrorMsg) const
{
// Strip the class name of its prefix and then do a search for the class
FString ClassNameStripped = GetClassNameWithPrefixRemoved(InClassName);
if (FClass* FoundClass = FindClass(*ClassNameStripped))
{
// If the class was found with the stripped class name, verify that the correct prefix was used and throw an error otherwise
if (!ClassNameHasValidPrefix(InClassName, FoundClass))
{
OutErrorMsg = FString::Printf(TEXT("Class '%s' has an incorrect prefix, expecting '%s'"), *InClassName, *FoundClass->GetNameWithPrefix());
return NULL;
}
return (FClass*)FoundClass;
}
// Couldn't find the class with a class name stripped of prefix (or a prefix was not found)
// See if the prefix was forgotten by trying to find the class with the given identifier
if (FClass* FoundClass = FindClass(*InClassName))
{
// If the class was found with the given identifier, the user forgot to use the correct Unreal prefix
OutErrorMsg = FString::Printf(TEXT("Class '%s' is missing a prefix, expecting '%s'"), *InClassName, *FoundClass->GetNameWithPrefix());
}
else
{
// If the class was still not found, it wasn't a valid identifier
OutErrorMsg = FString::Printf(TEXT("Class '%s' not found."), *InClassName );
}
return NULL;
}
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
TArray<FClass*> FClasses::GetClassesInPackage(const UPackage* InPackage) const
{
TArray<FClass*> Result;
Result.Add(UObjectClass);
// This cast is evil, but it'll work until we get TArray covariance. ;-)
ClassTree.GetChildClasses((TArray<UClass*>&)Result, [=](const UClass* Class) { return InPackage == ANY_PACKAGE || Class->GetOuter() == InPackage; }, true);
return Result;
}
#if WIP_UHT_REFACTOR
void FClasses::ChangeParentClass(FClass* Class)
{
ClassTree.ChangeParentClass(Class);
}
bool FClasses::ContainsClass(const FClass* Class) const
{
return !!ClassTree.FindNode(const_cast<FClass*>(Class));
}
void FClasses::Validate()
{
ClassTree.Validate();
}
#endif