Files
UnrealEngineUWP/Engine/Source/Programs/UnrealHeaderTool/Private/HeaderParser.h
Ben Marsh 3de35115ca Copying //UE4/Dev-Core to //UE4/Dev-Main (Source: //UE4/Dev-Core @ 3283640)
#lockdown Nick.Penwarden
#rb none

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3229011 on 2016/12/09 by Steve.Robb

	Licensee version updated in FWorldTileInfo::Read().

	https://udn.unrealengine.com/questions/325874/fworldtileinfo-not-passing-fileversionlicenseeue4.html

Change 3230493 on 2016/12/12 by Robert.Manuszewski

	Adding a check against assembling the reference token stream while streaming without locking GC.

Change 3230515 on 2016/12/12 by Steve.Robb

	GetStaticEnum and GetStaticStruct removed.
	Various generated code tidy-ups.

Change 3230522 on 2016/12/12 by Steve.Robb

	UHT no longer complains about bases with different prefixes.
	References to obsolete DependsOn removed.

Change 3230528 on 2016/12/12 by Steve.Robb

	ReferenceChainSearch tidyups.

Change 3234235 on 2016/12/14 by Robert.Manuszewski

	PR #2695: fix comments (Contributed by wyhily2010)

Change 3234237 on 2016/12/14 by Robert.Manuszewski

	PR #2614: [GenericPlatformFile] New Function, GetTimeStampLocal, returns file time stamp in local time instead of UTC   Rama (Contributed by EverNewJoy)

Change 3236214 on 2016/12/15 by Robert.Manuszewski

	PR# 1988 : Allow absolute path in -UserDir=<Path> argument (contributed by bozaro)

Change 3236582 on 2016/12/15 by Robert.Manuszewski

	Allow commandline use in shipping builds

	#jira UE-24613

Change 3236591 on 2016/12/15 by Robert.Manuszewski

	Removed unnecessary console variable logspam

	#jira UE-24614

Change 3236737 on 2016/12/15 by Steve.Robb

	Fixes to non-contiguous enums in OSS.

Change 3239686 on 2016/12/19 by Chris.Wood

	Fixed CompressionHelper method UE4CompressFileGZIP() that leaked a file handle when a compression error occurred (CRP v1.2.12)
	[UE-39910] - CrashReportProcess leaks file handles and doesn't cleanup folders after compression fails during output to S3

Change 3240687 on 2016/12/20 by Chris.Wood

	Improved CrashReportProcess retry logic to avoid stuck threads when CRW fails to add crashes (CRP 1.2.13)
	[UE-39941] - Improve CrashReportProcess retry logic when CR website returns failed response to AddCrash Request

Change 3246347 on 2017/01/04 by Steve.Robb

	Readability, debuggability and standards improvements.

Change 3249122 on 2017/01/06 by Steve.Robb

	Generic FPaths::Combine, allowing a mix of string argument types and unlimited arity.

Change 3249580 on 2017/01/06 by Steve.Robb

	Fix for TArray::HeapSort when array contains pointers.

	See: https://answers.unrealengine.com/questions/545533/bug-heapsort-with-tarray-of-pointers-fails-to-comp.html

Change 3250593 on 2017/01/09 by Robert.Manuszewski

	PR #3046: UE-39578: Added none to invalid filenames (Contributed by projectgheist)

Change 3250596 on 2017/01/09 by Robert.Manuszewski

	PR #3094: Fixing typo in comments for LODColoration in BaseEngine.ini - UE-40196 (Contributed by sanjay-nambiar)

Change 3250599 on 2017/01/09 by Robert.Manuszewski

	PR #3096: Fixed Log message in ExclusiveLoadPackageTimeTracker : UE-37583 (Contributed by sanjay-nambiar)

Change 3250863 on 2017/01/09 by Steve.Robb

	Build configuration option to force the use of the Debug version of UnrealHeaderTool.

Change 3250994 on 2017/01/09 by Ben.Zeigler

	Remove bad or redundant ini redirects. These did not work with the old system but were silently ignored, my new system throws warnings about them

Change 3251000 on 2017/01/09 by Ben.Zeigler

	#jira UE-39599 Add FCoreRedirects which replaces and unifies the redirect systems in LinkerLoad, K2Node, Enum, and TaggedProperty. This fixes various bugs and makes things uniform.
	It will parse the previous ini files, or load out of a [CoreRedirects] section in any loaded ini file
	The old redirect system can be re-enabled by setting USE_CORE_REDIRECTS to 0 in CoreRedirects.h. This will be removed eventually
	Some refactors to pass in information needed by the new system that the old system didn't need
	Add LoadTimeVerbose stats for processing redirects and enable that group during -LoadTimeFile

Change 3253580 on 2017/01/11 by Graeme.Thornton

	Added some validation of the class index in exportmap entries

	#jira UE-37873

Change 3253777 on 2017/01/11 by Graeme.Thornton

	Increase SerialSize and SerialOffset in FObjectExport to 64bits, to handle super large files

	#jira UE-39946

Change 3257750 on 2017/01/13 by Ben.Zeigler

	Fix issue where incorrectly set up animation node redirects (were ActiveClassRedirects, should have been ActiveStructRedirects) didn't work in the new redirect system because it validated more.
	Added backward compatibilty code and fixed some conflicts in the ini.

Change 3261176 on 2017/01/17 by Ben.Zeigler

	#jira UE-40746 Fix redundant ini redirect
	#jira UE-40725 Fix section of Match3 defaultengine.ini that appears to have been accidentally duplicated from baseengine.ini several years ago

Change 3261915 on 2017/01/18 by Steve.Robb

	Fixes to localized printf formats.

Change 3262142 on 2017/01/18 by Ben.Zeigler

	Remove runtime code for old ActiveClassRedirects and related systems.
	It was already disabled and the old ini format is still parsed and converted to FCoreRedirects at runtime so there should be no functionality change.
	Merged the deprecated tagged property and enum redirect ini parsing into LinkerLoad, and remove the RemapImports step entirely as it's part of FixupImportMap.

Change 3263596 on 2017/01/19 by Gil.Gribb

	UE4 - Fixed many bugs with the event driven loader and allowed it to work at boot time.

Change 3263597 on 2017/01/19 by Gil.Gribb

	UE4 - Allowed UnrealPak to do a better job with EDL pak files when the order provided is old or from the cooker. Several minor tweaks to low level async IO stuff in support of switch experiments.

Change 3263922 on 2017/01/19 by Gil.Gribb

	UE4 - Fixed a bug with nativized blueprints that was introduced with the boot time EDL changes.

Change 3264131 on 2017/01/19 by Robert.Manuszewski

	Simple app to test hard to repro bugs

Change 3264849 on 2017/01/19 by Ben.Zeigler

	Change FParse::Value to treat ) like , for parsing to handle config parsing struct format. This fixes cases where lines end with bool or FName variables that aren't written out quoted:
	+ClassRedirects=(OldName="LandscapeProxy",NewName="LandscapeStreamingProxy",InstanceOnly=True)

Change 3265232 on 2017/01/19 by Ben.Zeigler

	#jira UE-39599 Finish class redirect refactor by cleaning up BaseEngine.ini
	Move plugin-specific redirects to new plugin ini files
	Move all redirects from BaseEngine.ini prior to 4.11 to native registration in FCoreRedirects. Needed to split up functions to avoid long compile times
	Move all redirects after 4.11 to new ini format
	Some related blueprint fixup code changes, these weren't cooperating well with some ini redirects

Change 3265490 on 2017/01/20 by Steve.Robb

	Prevent engine reinstancing on hot reload.

	#jira UE-40765

Change 3265593 on 2017/01/20 by Gil.Gribb

	UE4 - Stored a copy of the callback in async read request so that we don't need to worry about lifetime so we can capture variables as needed. Also fixed race in audio streaming.

Change 3266003 on 2017/01/20 by Gil.Gribb

	UE4 - Fixed bug which would cause a fatal error when cooking subobjects that were pending kill.

Change 3267433 on 2017/01/22 by Gil.Gribb

	UE4 - Fixed a bug with EDL at boot time which caused a fatal error with unfired imports.

Change 3267677 on 2017/01/23 by Steve.Robb

	Fix for whitespace before UCLASS() causing compile errors.

	#jira UE-24110

Change 3267685 on 2017/01/23 by Steve.Robb

	First pass of fixes to printf-style calls to only use TCHAR[] specifiers.

Change 3267746 on 2017/01/23 by Steven.Hutton

	Resolve offline work

	Changes to repositories to support better handling of db connections.

Change 3267865 on 2017/01/23 by Steve.Robb

	Clarification of TArray::FindLastByPredicate() and FString::FindLastCharByPredicate().

	#fyi nick.darnell

Change 3268075 on 2017/01/23 by Gil.Gribb

	UE4 - Fixed another bug with RF_PendingKill subobjects and the new loader.

Change 3268447 on 2017/01/23 by Gil.Gribb

	Fortnite - Removed calls to ::StaticClass() before main starts; this is not allowed.

Change 3269491 on 2017/01/24 by Gil.Gribb

	UE4 - Cancelling async loading with the EDL loader now prints a warning and does a flush instead.

Change 3269492 on 2017/01/24 by Gil.Gribb

	UE4 - Suppressed a few EDL cook wanrings.

Change 3270085 on 2017/01/24 by Gil.Gribb

	UE4 - Remove pak highwater spam.

Change 3270089 on 2017/01/24 by Gil.Gribb

	UE4 - fix random bug with memory counting and some vertex buffer

Change 3271246 on 2017/01/25 by Chris.Wood

	Fixed CrashReportProcess pipeline for Mac and Linux crashes lacking machine Ids (CRP v1.2.14)
	[UE-40605] - Machine ID is not being shown on the crashreporter website

Change 3271827 on 2017/01/25 by Steve.Robb

	C4946 warning disabled in third party headers (triggers in Clang/LLVM).

Change 3271874 on 2017/01/25 by Steve.Robb

	Fix for missing error check after header preparsing.

Change 3271911 on 2017/01/25 by Steve.Robb

	ObjectMacros.h now automatically included by generated headers.

	#fyi jamie.dale

Change 3273125 on 2017/01/26 by Steve.Robb

	Check to ensure that a .generated.h header is included by headers which have exported types, to avoid crazy compiler errors.

	#fyi james.golding

Change 3273209 on 2017/01/26 by Steve.Robb

	UnrealCodeAnalyzer compilation fixes.

Change 3274917 on 2017/01/27 by Steve.Robb

	GC disabled when recompiling child BPs, as is already the case for the parent (CL# 2731120).
	Now-unused field removed.

Change 3279091 on 2017/01/31 by Ben.Marsh

	UBT: Remove code paths which assume relative paths based on a particular CWD. Use the absolute paths stored in UnrealBuildTool.RootDirectory/UnrealBuildTool.EngineDirectory instead.

Change 3279195 on 2017/01/31 by Gil.Gribb

	Turned EDL on for orion

Change 3279493 on 2017/01/31 by Ben.Zeigler

	#jira UE-41341 Redo redirector fixups that got undone in merge from Main

Change 3280284 on 2017/01/31 by Ben.Zeigler

	#jira UE-41357 Fix typo in vehicle redirect. Also fix base crash when converting old content with nodes that don't exist.
	Fix issues with loading plugin ini files. They weren't properly "diffing" against the base/default source file so my redirect typo fix didn't propagate.
	Some general config system refactors on Josh's advice, and make base.ini optional if reading out of a non-standard engine directory
	Engine plugin ini are now BasePlugin.ini, game plugins are still DefaultPlugin.ini.
	Fix crash when loading old content pointing to nonexistent node type. It will still error/ensure but won't crash.

Change 3280299 on 2017/01/31 by Gil.Gribb

	possibly fix edl at boot with orion server....though was no-repro

Change 3280386 on 2017/01/31 by Ben.Zeigler

	Header include fixes for -nopch, fixes incremental build

Change 3280557 on 2017/01/31 by Ben.Zeigler

	Fix Config crash. FConfigFile's copy constructor is apparently not safe and resulted in garbage memory in some cases

Change 3280817 on 2017/02/01 by Steve.Robb

	Unused SmartCastProperty removed.

Change 3280897 on 2017/02/01 by Chris.Wood

	Improved CRP shutdown code to abort AddCrash requests when cancel is requested (CRP v1.2.15)
	[UE-41338] - Fix CRP shutdown when website isn't accepting new crashes

	Also, improved shutdown code to try to avoid occassional exception when writing out the report index. Looks like it isn't shutting down worker threads cleanly sometimes. Added more logging to this too.

Change 3280989 on 2017/02/01 by Gil.Gribb

	New unrealpak binaries

Change 3281416 on 2017/02/01 by Michael.Trepka

	Updated UnrealPak binaries for Mac

Change 3282457 on 2017/02/01 by Ben.Zeigler

	#jira UE-41425 Protect against issues with streamable manager requests recursively completing by caching the array locally.
	This code is safer in general in my local version so just doing a quick fix for now

Change 3282619 on 2017/02/01 by Arciel.Rekman

	Linux: update UnrealPak.

[CL 3283649 by Ben Marsh in Main branch]
2017-02-02 14:41:50 -05:00

769 lines
25 KiB
C++

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "ParserHelper.h"
#include "BaseParser.h"
#include "Misc/CompilationResult.h"
#include "Scope.h"
class UClass;
enum class EGeneratedCodeVersion : uint8;
class FFeedbackContext;
class UPackage;
struct FManifestModule;
class IScriptGeneratorPluginInterface;
class FStringOutputDevice;
class UProperty;
class FUnrealSourceFile;
class UFunction;
class UEnum;
class UScriptStruct;
class UDelegateFunction;
class UStruct;
class FClass;
class FClasses;
class FScope;
class FHeaderProvider;
class FUHTMakefile;
extern double GPluginOverheadTime;
extern double GHeaderCodeGenTime;
/*-----------------------------------------------------------------------------
Constants & types.
-----------------------------------------------------------------------------*/
enum {MAX_NEST_LEVELS = 16};
/* Code nesting types. */
enum class ENestType
{
GlobalScope,
Class,
FunctionDeclaration,
Interface,
NativeInterface
};
/** Types of statements to allow within a particular nesting block. */
enum class ENestAllowFlags
{
None = 0,
Function = 1, // Allow Event declarations at this level.
VarDecl = 2, // Allow variable declarations at this level.
Class = 4, // Allow class definition heading.
Return = 8, // Allow 'return' within a function.
TypeDecl = 16, // Allow declarations which do not affect memory layout, such as structs, enums, and consts, but not implicit delegates
ImplicitDelegateDecl = 32, // Allow implicit delegates (i.e. those not decorated with UDELEGATE) to be declared
};
ENUM_CLASS_FLAGS(ENestAllowFlags)
namespace EDelegateSpecifierAction
{
enum Type
{
DontParse,
Parse
};
}
/** The category of variable declaration being parsed */
namespace EVariableCategory
{
enum Type
{
RegularParameter,
ReplicatedParameter,
Return,
Member
};
}
/** Information for a particular nesting level. */
class FNestInfo
{
/** Link to the stack node. */
FScope* Scope;
public:
/**
* Gets nesting scope.
*/
FScope* GetScope() const
{
return Scope;
}
/**
* Sets nesting scope.
*/
void SetScope(FScope* InScope)
{
this->Scope = InScope;
}
/** Statement that caused the nesting. */
ENestType NestType;
/** Types of statements to allow at this nesting level. */
ENestAllowFlags Allow;
};
struct FIndexRange
{
int32 StartIndex;
int32 Count;
};
struct ClassDefinitionRange
{
ClassDefinitionRange(const TCHAR* InStart, const TCHAR* InEnd)
: Start(InStart)
, End(InEnd)
, bHasGeneratedBody(false)
{ }
ClassDefinitionRange()
: Start(nullptr)
, End(nullptr)
, bHasGeneratedBody(false)
{ }
void Validate()
{
if (End <= Start)
{
FError::Throwf(TEXT("The class definition range is invalid. Most probably caused by previous parsing error."));
}
}
const TCHAR* Start;
const TCHAR* End;
bool bHasGeneratedBody;
};
extern TMap<UClass*, ClassDefinitionRange> ClassDefinitionRanges;
/////////////////////////////////////////////////////
// FHeaderParser
//
// Header parser class. Extracts metadata from annotated C++ headers and gathers enough
// information to autogenerate additional headers and other boilerplate code.
//
class FHeaderParser : public FBaseParser, public FContextSupplier
{
public:
// Default version of generated code. Defaults to oldest possible, unless specified otherwise in config.
static EGeneratedCodeVersion DefaultGeneratedCodeVersion;
// Compute the function parameter size and save the return offset
static void ComputeFunctionParametersSize(UClass* InClass);
// Parse all headers for classes that are inside LimitOuter.
static ECompilationResult::Type ParseAllHeadersInside(
FClasses& ModuleClasses,
FFeedbackContext* Warn,
UPackage* LimitOuter,
const FManifestModule& Module,
TArray<class IScriptGeneratorPluginInterface*>& ScriptPlugins
#if WITH_HOT_RELOAD_CTORS
, bool bExportVTableConstructors
#endif // WITH_HOT_RELOAD_CTORS
, FUHTMakefile& UHTMakefile
);
// Performs a preliminary parse of the text in the specified buffer, pulling out:
// Class name and parent class name
// Is it an interface
// The list of other classes/interfaces it is dependent on
//
// It also splits the buffer up into:
// ScriptText (text outside of #if CPP and #if DEFAULTS blocks)
static void SimplifiedClassParse(const TCHAR* Filename, const TCHAR* Buffer, TArray<FSimplifiedParsingClassInfo>& OutParsedClassArray, TArray<FHeaderProvider>& DependentOn, FStringOutputDevice& ScriptText);
/**
* Returns True if the given class name includes a valid Unreal prefix and matches up with the given original class Name.
*
* @param InNameToCheck - Name w/ potential prefix to check
* @param OriginalClassName - Name of class w/ no prefix to check against
*/
static bool ClassNameHasValidPrefix(const FString InNameToCheck, const FString OriginalClassName);
/**
* Tries to convert the header file name to a class name (with 'U' prefix)
*
* @param HeaderFilename Filename.
* @param OutClass The resulting class name (if successfull)
* @return true if the filename was a header filename (.h), false otherwise (in which case OutClassName is unmodified).
*/
static bool DependentClassNameFromHeader(const TCHAR* HeaderFilename, FString& OutClassName);
/**
* Transforms CPP-formated string containing default value, to inner formated string
* If it cannot be transformed empty string is returned.
*
* @param Property The property that owns the default value.
* @param CppForm A CPP-formated string.
* @param out InnerForm Inner formated string
* @return true on success, false otherwise.
*/
static bool DefaultValueStringCppFormatToInnerFormat(const UProperty* Property, const FString& CppForm, FString &InnerForm);
/**
* Parse Class's annotated headers and optionally its child classes. Marks the class as CLASS_Parsed.
*
* @param AllClasses the class tree containing all classes in the current package
* @param HeaderParser the header parser
* @param SourceFile Source file info.
*
* @return Result enumeration.
*/
static ECompilationResult::Type ParseHeaders(FClasses& AllClasses, FHeaderParser& HeaderParser, FUnrealSourceFile* SourceFile, FUHTMakefile& UHTMakefile);
protected:
friend struct FScriptLocation;
// For compiling messages and errors.
FFeedbackContext* Warn;
// Filename currently being parsed
FString Filename;
// Makefile to which parsing intermediate data will be saved.
FUHTMakefile& UHTMakefile;
// Was the first include in the file a validly formed auto-generated header include?
bool bSpottedAutogeneratedHeaderInclude;
// Current nest level, starts at 0.
int32 NestLevel;
// Top nesting level.
FNestInfo* TopNest;
/**
* Gets current nesting scope.
*/
FScope* GetCurrentScope() const
{
return TopNest->GetScope();
}
/**
* Gets current file scope.
*/
FFileScope* GetCurrentFileScope() const
{
int32 Index = 0;
if (!TopNest)
{
check(!NestLevel);
return nullptr;
}
while (TopNest[Index].NestType != ENestType::GlobalScope)
{
--Index;
}
return (FFileScope*)TopNest[Index].GetScope();
}
/**
* Gets current source file.
*/
FUnrealSourceFile* GetCurrentSourceFile() const
{
return CurrentSourceFile;
}
void SetCurrentSourceFile(FUnrealSourceFile* UnrealSourceFile)
{
CurrentSourceFile = UnrealSourceFile;
}
/**
* Gets current class scope.
*/
FStructScope* GetCurrentClassScope() const
{
check(TopNest->NestType == ENestType::Class || TopNest->NestType == ENestType::Interface || TopNest->NestType == ENestType::NativeInterface);
return (FStructScope*)TopNest->GetScope();
}
/**
* Tells if parser is currently in a class.
*/
bool IsInAClass() const
{
int32 Index = 0;
while (TopNest[Index].NestType != ENestType::GlobalScope)
{
if (TopNest[Index].NestType == ENestType::Class || TopNest->NestType == ENestType::Interface || TopNest->NestType == ENestType::NativeInterface)
{
return true;
}
--Index;
}
return false;
}
/**
* Gets current class.
*/
UClass* GetCurrentClass() const
{
return (UClass*)GetCurrentClassScope()->GetStruct();
}
/**
* Gets current class's metadata.
*/
FClassMetaData* GetCurrentClassData()
{
return GScriptHelper.FindClassData(GetCurrentClass());
}
// Information about all nesting levels.
FNestInfo Nest[MAX_NEST_LEVELS];
// enum for complier directives used to build up the directive stack
struct ECompilerDirective
{
enum Type
{
// this directive is insignificant and does not change the code generation at all
Insignificant = 0,
// this indicates we are in a WITH_EDITOR #if-Block
WithEditor = 1<<0,
// this indicates we are in a WITH_EDITORONLY_DATA #if-Block
WithEditorOnlyData = 1<<1,
};
};
/**
* Compiler directive nest in which the parser currently is
* NOTE: compiler directives are combined when more are added onto the stack, so
* checking the only the top of stack is enough to determine in which #if-Block(s) the current code
* is.
*
* ex. Stack.Num() == 1 while entering #if WITH_EDITOR:
* CompilerDirectiveStack[1] == CompilerDirectiveStack[0] | ECompilerDirective::WithEditor ==
* CompilerDirecitveStack[1] == CompilerDirectiveStack.Num()-1 | ECompilerDirective::WithEditor
*
* ex. Stack.Num() == 2 while entering #if WITH_EDITOR:
* CompilerDirectiveStack[3] == CompilerDirectiveStack[0] | CompilerDirectiveStack[1] | CompilerDirectiveStack[2] | ECompilerDirective::WithEditor ==
* CompilerDirecitveStack[3] == CompilerDirectiveStack.Num()-1 | ECompilerDirective::WithEditor
*/
TArray<uint32> CompilerDirectiveStack;
// Pushes the Directive specified to the CompilerDirectiveStack according to the rules described above
void FORCEINLINE PushCompilerDirective(ECompilerDirective::Type Directive)
{
CompilerDirectiveStack.Push(CompilerDirectiveStack.Num()>0 ? (CompilerDirectiveStack[CompilerDirectiveStack.Num()-1] | Directive) : Directive);
}
/**
* The starting class flags (i.e. the class flags that were set before the
* CLASS_RecompilerClear mask was applied) for the class currently being compiled
*/
uint32 PreviousClassFlags;
// For new-style classes, used to keep track of an unmatched {} pair
bool bEncounteredNewStyleClass_UnmatchedBrackets;
// Indicates that UCLASS/USTRUCT/UINTERFACE has already been parsed in this .h file..
bool bHaveSeenUClass;
// Indicates that a GENERATED_UCLASS_BODY or GENERATED_BODY has been found in the UClass.
bool bClassHasGeneratedBody;
// Indicates that a GENERATED_UINTERFACE_BODY has been found in the UClass.
bool bClassHasGeneratedUInterfaceBody;
// Indicates that a GENERATED_IINTERFACE_BODY has been found in the UClass.
bool bClassHasGeneratedIInterfaceBody;
// public, private, etc at the current parse spot
EAccessSpecifier CurrentAccessSpecifier;
////////////////////////////////////////////////////
// Special parsed struct names that do not require a prefix
TArray<FString> StructsWithNoPrefix;
// Special parsed struct names that have a 'T' prefix
TArray<FString> StructsWithTPrefix;
// Mapping from 'human-readable' macro substring to # of parameters for delegate declarations
// Index 0 is 1 parameter, Index 1 is 2, etc...
TArray<FString> DelegateParameterCountStrings;
// List of all used identifiers for net service function declarations (every function must be unique)
TMap<int32, FString> UsedRPCIds;
// List of all net service functions with undeclared response functions
TMap<int32, FString> RPCsNeedingHookup;
protected:
// Constructor.
FHeaderParser(FFeedbackContext* InWarn, FUHTMakefile& InUHTMakefile);
~FHeaderParser()
{
if ( FScriptLocation::Compiler == this )
{
FScriptLocation::Compiler = NULL;
}
}
// Returns true if the token is a dynamic delegate declaration
bool IsValidDelegateDeclaration(const FToken& Token) const;
// Returns true if the current token is a bitfield type
bool IsBitfieldProperty();
// Parse the parameter list of a function or delegate declaration
void ParseParameterList(FClasses& AllClasses, UFunction* Function, bool bExpectCommaBeforeName = false, TMap<FName, FString>* MetaData = NULL);
public:
// Throws if a specifier value wasn't provided
static void RequireSpecifierValue(const FPropertySpecifier& Specifier, bool bRequireExactlyOne = false);
static FString RequireExactlyOneSpecifierValue(const FPropertySpecifier& Specifier);
protected:
/**
* Parse rest of the module's source files.
*
* @param AllClasses The class tree containing all classes in the current package.
* @param ModulePackage Current package.
* @param HeaderParser The header parser.
* @param UHTMakefile Makefile to which parsing data is saved.
*
* @return Result enumeration.
*/
static ECompilationResult::Type ParseRestOfModulesSourceFiles(FClasses& AllClasses, UPackage* ModulePackage, FHeaderParser& HeaderParser, FUHTMakefile& UHTMakefile);
//@TODO: Remove this method
static void ParseClassName(const TCHAR* Temp, FString& ClassName);
/**
* @param Input An input string, expected to be a script comment.
* @return The input string, reformatted in such a way as to be appropriate for use as a tooltip.
*/
static FString FormatCommentForToolTip(const FString& Input);
/**
* Begins the process of exporting C++ class declarations for native classes in the specified package
*
* @param CurrentPackage The package being compiled.
* @param AllClasses The class tree for CurrentPackage.
* @param UHTMakefile Makefile to which parsing data is saved.
* @param Module Currently exported module.
*/
static void ExportNativeHeaders(
UPackage* CurrentPackage,
FClasses& AllClasses,
bool bAllowSaveExportedHeaders
#if WITH_HOT_RELOAD_CTORS
, bool bExportVTableConstructors
#endif // WITH_HOT_RELOAD_CTORS
, FUHTMakefile& UHTMakefile
, const FManifestModule& Module
);
// FContextSupplier interface.
virtual FString GetContext() override;
// End of FContextSupplier interface.
// High-level compiling functions.
/**
* Parses given source file.
*
* @param AllClasses The class tree for current package.
* @param SourceFile Source file to parse.
*
* @returns Compilation result enum.
*/
ECompilationResult::Type ParseHeader(FClasses& AllClasses, FUnrealSourceFile* SourceFile);
void CompileDirective(FClasses& AllClasses);
void FinalizeScriptExposedFunctions(UClass* Class);
UEnum* CompileEnum();
UScriptStruct* CompileStructDeclaration(FClasses& AllClasses);
bool CompileDeclaration(FClasses& AllClasses, TArray<UDelegateFunction*>& DelegatesToFixup, FToken& Token);
/** Skip C++ (noexport) declaration. */
bool SkipDeclaration(FToken& Token);
/** Similar to MatchSymbol() but will return to the exact location as on entry if the symbol was not found. */
bool SafeMatchSymbol(const TCHAR* Match);
void HandleOneInheritedClass(FClasses& AllClasses, UClass* Class, FString InterfaceName);
FClass* ParseClassNameDeclaration(FClasses& AllClasses, FString& DeclaredClassName, FString& RequiredAPIMacroIfPresent);
/** The property style of a variable declaration being parsed */
struct EPropertyDeclarationStyle
{
enum Type
{
None,
UPROPERTY
};
};
/**
* Resets current class data back to its defaults.
*/
void ResetClassData();
/**
* Create new function object based on given info structure.
*/
UFunction* CreateFunction(const FFuncInfo &FuncInfo) const;
/**
* Create new delegate function object based on given info structure.
*/
UDelegateFunction* CreateDelegateFunction(const FFuncInfo &FuncInfo) const;
void CompileClassDeclaration(FClasses& AllClasses);
UDelegateFunction* CompileDelegateDeclaration(FClasses& AllClasses, const TCHAR* DelegateIdentifier, EDelegateSpecifierAction::Type SpecifierAction = EDelegateSpecifierAction::DontParse);
void CompileFunctionDeclaration(FClasses& AllClasses);
void CompileVariableDeclaration (FClasses& AllClasses, UStruct* Struct);
void CompileInterfaceDeclaration(FClasses& AllClasses);
FClass* ParseInterfaceNameDeclaration(FClasses& AllClasses, FString& DeclaredInterfaceName, FString& RequiredAPIMacroIfPresent);
bool TryParseIInterfaceClass(FClasses& AllClasses);
bool CompileStatement(FClasses& AllClasses, TArray<UDelegateFunction*>& DelegatesToFixup);
// Checks to see if a particular kind of command is allowed on this nesting level.
bool IsAllowedInThisNesting(ENestAllowFlags AllowFlags);
// Make sure that a particular kind of command is allowed on this nesting level.
// If it's not, issues a compiler error referring to the token and the current
// nesting level.
void CheckAllow(const TCHAR* Thing, ENestAllowFlags AllowFlags);
UStruct* GetSuperScope( UStruct* CurrentScope, const FName& SearchName );
/**
* Find a field in the specified context. Starts with the specified scope, then iterates
* through the Outer chain until the field is found.
*
* @param InScope scope to start searching for the field in
* @param InIdentifier name of the field we're searching for
* @param bIncludeParents whether to allow searching in the scope of a parent struct
* @param FieldClass class of the field to search for. used to e.g. search for functions only
* @param Thing hint text that will be used in the error message if an error is encountered
*
* @return a pointer to a UField with a name matching InIdentifier, or NULL if it wasn't found
*/
UField* FindField( UStruct* InScope, const TCHAR* InIdentifier, bool bIncludeParents=true, UClass* FieldClass=UField::StaticClass(), const TCHAR* Thing=NULL );
void SkipStatements( int32 SubCount, const TCHAR* ErrorTag );
/**
* Parses a variable or return value declaration and determines the variable type and property flags.
*
* @param AllClasses the class tree for CurrentPackage
* @param Scope struct to create the property in
* @param VarProperty will be filled in with type and property flag data for the property declaration that was parsed
* @param Disallow contains a mask of variable modifiers that are disallowed in this context
* @param OuterPropertyType only specified when compiling the inner properties for arrays or maps. corresponds to the FToken for the outer property declaration.
* @param PropertyDeclarationStyle if the variable is defined with a UPROPERTY
* @param VariableCategory what kind of variable is being parsed
* @param ParsedVarIndexRange The source text [Start, End) index range for the parsed type.
*/
void GetVarType(
FClasses& AllClasses,
FScope* Scope,
FPropertyBase& VarProperty,
uint64 Disallow,
FToken* OuterPropertyType,
EPropertyDeclarationStyle::Type PropertyDeclarationStyle,
EVariableCategory::Type VariableCategory,
FIndexRange* ParsedVarIndexRange = nullptr);
/**
* Parses a variable name declaration and creates a new UProperty object.
*
* @param Scope struct to create the property in
* @param VarProperty type and propertyflag info for the new property (inout)
* @param VariableCategory what kind of variable is being created
*
* @return a pointer to the new UProperty if successful, or NULL if there was no property to parse
*/
UProperty* GetVarNameAndDim(
UStruct* Struct,
FToken& VarProperty,
EVariableCategory::Type VariableCategory);
/**
* Returns whether the specified class can be referenced from the class currently being compiled.
*
* @param Scope The scope we are currently parsing.
* @param CheckClass The class we want to reference.
*
* @return true if the specified class is an intrinsic type or if the class has successfully been parsed
*/
bool AllowReferenceToClass(UStruct* Scope, UClass* CheckClass) const;
/**
* @return true if Scope has UProperty objects in its list of fields
*/
static bool HasMemberProperties( const UStruct* Scope );
/**
* Parses optional metadata text.
*
* @param MetaData the metadata map to store parsed metadata in
* @param FieldName the field being parsed (used for logging)
*
* @return true if metadata was specified
*/
void ParseFieldMetaData(TMap<FName, FString>& MetaData, const TCHAR* FieldName);
/**
* Formats the current comment, if any, and adds it to the metadata as a tooltip.
*
* @param MetaData the metadata map to store the tooltip in
*/
void AddFormattedPrevCommentAsTooltipMetaData(TMap<FName, FString>& MetaData);
/**
* Tries to parse the token as an access protection specifier (public:, protected:, or private:)
*
* @return EAccessSpecifier this is, or zero if it is none
*/
EAccessSpecifier ParseAccessProtectionSpecifier(FToken& Token);
const TCHAR* NestTypeName( ENestType NestType );
FClass* GetQualifiedClass(const FClasses& AllClasses, const TCHAR* Thing);
/**
* Increase the nesting level, setting the new top nesting level to
* the one specified. If pushing a function or state and it overrides a similar
* thing declared on a lower nesting level, verifies that the override is legal.
*
* @param NestType the new nesting type
* @param InNode @todo
*/
void PushNest(ENestType NestType, UStruct* InNode, FUnrealSourceFile* SourceFile = nullptr);
void PopNest(ENestType NestType, const TCHAR* Descr);
/**
* Tasks that need to be done after popping function declaration
* from parsing stack.
*
* @param AllClasses The class tree for current package.
* @param PoppedFunction Function that have just been popped.
*/
void PostPopFunctionDeclaration(FClasses& AllClasses, UFunction* PoppedFunction);
/**
* Tasks that need to be done after popping interface definition
* from parsing stack.
*
* @param AllClasses The class tree for current package.
* @param CurrentInterface Interface that have just been popped.
*/
void PostPopNestInterface(FClasses& AllClasses, UClass* CurrentInterface);
/**
* Tasks that need to be done after popping class definition
* from parsing stack.
*
* @param CurrentClass Class that have just been popped.
*/
void PostPopNestClass(UClass* CurrentClass);
/**
* Binds all delegate properties declared in ValidationScope the delegate functions specified in the variable declaration, verifying that the function is a valid delegate
* within the current scope. This must be done once the entire class has been parsed because instance delegate properties must be declared before the delegate declaration itself.
*
* @todo: this function will no longer be required once the post-parse fixup phase is added (TTPRO #13256)
*
* @param AllClasses the class tree for CurrentPackage
* @param Struct the struct to validate delegate properties for
* @param Scope the current scope
* @param DelegateCache cached map of delegates that have already been found; used for faster lookup.
*/
void FixupDelegateProperties(FClasses& AllClasses, UStruct* ValidationScope, FScope& Scope, TMap<FName, UFunction*>& DelegateCache);
/**
* Verifies that all specified class's UProperties with CFG_RepNotify have valid callback targets with no parameters nor return values
*
* @param TargetClass class to verify rep notify properties for
*/
void VerifyRepNotifyCallbacks( UClass* TargetClass );
// Retry functions.
void InitScriptLocation( FScriptLocation& Retry );
void ReturnToLocation( const FScriptLocation& Retry, bool Binary=1, bool Text=1 );
/**
* If the property has already been seen during compilation, then return add. If not,
* then return replace so that INI files don't mess with header exporting
*
* @param PropertyName the string token for the property
*
* @return FNAME_Replace_Not_Safe_For_Threading or FNAME_Add
*/
EFindName GetFindFlagForPropertyName(const TCHAR* PropertyName);
static void ValidatePropertyIsDeprecatedIfNecessary(FPropertyBase& VarProperty, FToken* OuterPropertyType);
private:
// Source file currently parsed by UHT.
FUnrealSourceFile* CurrentSourceFile;
// Module currently parsed by UHT.
const FManifestModule* CurrentlyParsedModule;
/**
* Tries to match constructor parameter list. Assumes that constructor
* name is already matched.
*
* If fails it reverts all parsing done.
*
* @param Token Token to start parsing from.
*
* @returns True if matched. False otherwise.
*/
bool TryToMatchConstructorParameterList(FToken Token);
void SkipDeprecatedMacroIfNecessary();
// Parses possible version declaration in generated code, e.g. GENERATED_BODY(<some_version>).
void CompileVersionDeclaration(UStruct* Struct);
};
/////////////////////////////////////////////////////
// FHeaderPreParser
class FHeaderPreParser : public FBaseParser
{
public:
FHeaderPreParser()
{
}
void ParseClassDeclaration(
const TCHAR* Filename,
const TCHAR* InputText,
int32 InLineNumber,
const TCHAR*
StartingMatchID,
FName& out_StrippedClassName,
FString& out_ClassName,
FString& out_BaseClassName,
TArray<FHeaderProvider>& out_ClassNames,
const TArray<FSimplifiedParsingClassInfo>& ParsedClassArray
);
};