Files
UnrealEngineUWP/Engine/Source/Programs/UnrealHeaderTool/Private/Scope.cpp
Tim Smith 2504290d2e Remove the compiler meta data manager.
Elimination of some quick to resolve type system lookups.

#rnx
#rb jonathan.adamczewski
#preflight 609e5a1dcbf9a40001fe9778

[CL 16328413 by Tim Smith in ue5-main branch]
2021-05-14 07:48:15 -04:00

173 lines
3.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Scope.h"
#include "UnrealHeaderTool.h"
#include "UObject/ErrorException.h"
#include "ParserHelper.h"
#include "UnrealTypeDefinitionInfo.h"
#include "ClassMaps.h"
FScope::FScope(FScope* InParent)
: Parent(InParent)
{ }
FScope::FScope()
: Parent(nullptr)
{
}
void FScope::AddType(FUnrealFieldDefinitionInfo& Type)
{
TypeMap.Add(Type.GetField()->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() || TypeClass == USparseDelegateFunction::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 (TPair<FName, FUnrealFieldDefinitionInfo*>& TypePair : TypeMap)
{
UField* Type = TypePair.Value->GetField();
DispatchType(Type, Enums, Structs, DelegateFunctions);
}
}
TSharedRef<FScope> FScope::GetTypeScope(UStruct* Type)
{
TSharedRef<FUnrealTypeDefinitionInfo>* TypeDef = GTypeDefinitionInfoMap.Find(Type);
if (TypeDef == nullptr)
{
FError::Throwf(TEXT("Couldn't find scope for the type %s."), *Type->GetName());
}
return (*TypeDef)->GetScope();
}
FUnrealFieldDefinitionInfo* FScope::FindTypeByName(FName Name)
{
if (!Name.IsNone())
{
TDeepScopeTypeIterator<FUnrealFieldDefinitionInfo, false> TypeIterator(this);
while (TypeIterator.MoveNext())
{
FUnrealFieldDefinitionInfo* Type = *TypeIterator;
if (Type->GetField()->GetFName() == Name)
{
return Type;
}
}
}
return nullptr;
}
const FUnrealFieldDefinitionInfo* FScope::FindTypeByName(FName Name) const
{
if (!Name.IsNone())
{
TScopeTypeIterator<FUnrealFieldDefinitionInfo, true> TypeIterator = GetTypeIterator();
while (TypeIterator.MoveNext())
{
FUnrealFieldDefinitionInfo* Type = *TypeIterator;
if (Type->GetField()->GetFName() == Name)
{
return Type;
}
}
}
return nullptr;
}
bool FScope::ContainsType(FUnrealFieldDefinitionInfo* Type)
{
return FindTypeByName(Type->GetField()->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();
}
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;
}
FName FStructScope::GetName() const
{
return Struct->GetFName();
}