Files
UnrealEngineUWP/Engine/Source/Programs/UnrealHeaderTool/Private/UnrealSourceFile.cpp
Jaroslaw Palczynski 82a72ea4d2 UE-11425: GitHub 896 : Update UnrealSourceFile Macros to work correctly for project files.
GitHub PR #896

[CL 2487551 by Jaroslaw Palczynski in Main branch]
2015-03-23 03:55:53 -04:00

135 lines
3.0 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "UnrealHeaderTool.h"
#include "UnrealSourceFile.h"
#include "ParserHelper.h"
void FUnrealSourceFile::AddDefinedClass(UClass* Class)
{
DefinedClasses.Add(Class);
}
FString FUnrealSourceFile::GetFileId() const
{
FString StdFilename = Filename;
FPaths::MakeStandardFilename(StdFilename);
bool RelativePath = FPaths::IsRelative(StdFilename);
if (!RelativePath)
{
// If path is still absolute that means MakeStandardFilename has failed
// In this case make it relative to the current project.
RelativePath = FPaths::MakePathRelativeTo(StdFilename, *FPaths::GetPath(FPaths::GetProjectFilePath()));
}
// If the path has passed either MakeStandardFilename or MakePathRelativeTo it should be using internal path seperators
if (RelativePath)
{
// Remove any preceding parent directory paths
while (StdFilename.RemoveFromStart(TEXT("../")));
}
FStringOutputDevice Out;
for (auto Char : StdFilename)
{
if (FChar::IsAlnum(Char))
{
Out.AppendChar(Char);
}
else
{
Out.AppendChar('_');
}
}
return Out;
}
FString FUnrealSourceFile::GetStrippedFilename() const
{
return FPaths::GetBaseFilename(Filename);
}
FString FUnrealSourceFile::GetGeneratedMacroName(FClassMetaData* ClassData, const TCHAR* Suffix) const
{
return GetGeneratedMacroName(ClassData->GetGeneratedBodyLine(), Suffix);
}
FString FUnrealSourceFile::GetGeneratedMacroName(int32 LineNumber, const TCHAR* Suffix) const
{
if (Suffix != nullptr)
{
return FString::Printf(TEXT("%s_%d%s"), *GetFileId(), LineNumber, Suffix);
}
return FString::Printf(TEXT("%s_%d"), *GetFileId(), LineNumber);
}
FString FUnrealSourceFile::GetGeneratedBodyMacroName(int32 LineNumber, bool bLegacy) const
{
return GetGeneratedMacroName(LineNumber, *FString::Printf(TEXT("%s%s"), TEXT("_GENERATED_BODY"), bLegacy ? TEXT("_LEGACY") : TEXT("")));
}
void FUnrealSourceFile::SetGeneratedFilename(FString GeneratedFilename)
{
this->GeneratedFilename = MoveTemp(GeneratedFilename);
}
void FUnrealSourceFile::SetHasChanged(bool bHasChanged)
{
this->bHasChanged = bHasChanged;
}
void FUnrealSourceFile::SetModuleRelativePath(FString ModuleRelativePath)
{
this->ModuleRelativePath = MoveTemp(ModuleRelativePath);
}
void FUnrealSourceFile::SetIncludePath(FString IncludePath)
{
this->IncludePath = MoveTemp(IncludePath);
}
const FString& FUnrealSourceFile::GetContent() const
{
return Content;
}
void FUnrealSourceFile::MarkDependenciesResolved()
{
bDependenciesResolved = true;
}
bool FUnrealSourceFile::AreDependenciesResolved() const
{
return bDependenciesResolved;
}
void FUnrealSourceFile::MarkAsParsed()
{
bParsed = true;
}
bool FUnrealSourceFile::IsParsed() const
{
return bParsed;
}
bool FUnrealSourceFile::HasChanged() const
{
return bHasChanged;
}
FString FUnrealSourceFile::GetAPI() const
{
return FPackageName::GetShortName(Package).ToUpper();
}
FString FUnrealSourceFile::GetFileDefineName() const
{
return FString::Printf(TEXT("%s_%s_generated_h"), *GetAPI(), *GetStrippedFilename());
}