Integrating live coding feature (aka Live++) into UE4.
Allows fast iteration of C++ changes without restarting the application. To use, select the "Live Coding (Experimental)" mode from the drop down menu next to the editor's compile button, or type "LiveCoding" into the console for a monolithic build. Press Ctrl+Alt+F11 to find changes and compile.
Changes vs standalone Live++ version:
* UBT is used to execute builds. This allows standard UE4 adaptive unity mode, allows us to reuse object files when we do regular builds, supports using any build executor allowed by UBT (XGE, SNDBS, etc..).
* Adding new source files is supported.
* Custom visualizer for FNames is supported via a weakly linked symbol in a static library (Engine/Extras/NatvisHelpers).
* Settings are exposed in the editor's project settings dialog.
* Standalone application has been rewritten as a Slate app ("LiveCodingConsole"). There is an additional option to start the program as hidden, where it will not be visible until Ctrl+Alt+F11 is hit. Similarly, closing the window will hide it instead of closing the application.
* Does not require a standalone licensed version of Live++.
Known issues:
* Does not currently support class layout changes / object reinstancing
#rb none
[FYI] Marc.Audy, Stefan.Boberg, Nick.Penwarden
#jira
#ROBOMERGE-SOURCE: CL 5304722 in //UE4/Release-4.22/...
#ROBOMERGE-BOT: RELEASE (Release-4.22 -> Main)
[CL 5309051 by ben marsh in Main branch]
2019-03-05 18:49:25 -05:00
|
|
|
// Copyright 2011-2019 Molecular Matters GmbH, all rights reserved.
|
|
|
|
|
|
|
|
|
|
#include "LC_ImmutableString.h"
|
|
|
|
|
#include "LC_StringUtil.h"
|
|
|
|
|
#include "LC_Allocators.h"
|
|
|
|
|
#include "LC_Platform.h"
|
|
|
|
|
#include "LC_Logging.h"
|
|
|
|
|
#include "Windows/WindowsHWrapper.h"
|
|
|
|
|
#include "xxhash.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
static inline uint32_t Hash(const char* key, size_t length)
|
|
|
|
|
{
|
2019-07-16 08:43:32 -04:00
|
|
|
return XXH32(key, length * sizeof(char), 0u);
|
Integrating live coding feature (aka Live++) into UE4.
Allows fast iteration of C++ changes without restarting the application. To use, select the "Live Coding (Experimental)" mode from the drop down menu next to the editor's compile button, or type "LiveCoding" into the console for a monolithic build. Press Ctrl+Alt+F11 to find changes and compile.
Changes vs standalone Live++ version:
* UBT is used to execute builds. This allows standard UE4 adaptive unity mode, allows us to reuse object files when we do regular builds, supports using any build executor allowed by UBT (XGE, SNDBS, etc..).
* Adding new source files is supported.
* Custom visualizer for FNames is supported via a weakly linked symbol in a static library (Engine/Extras/NatvisHelpers).
* Settings are exposed in the editor's project settings dialog.
* Standalone application has been rewritten as a Slate app ("LiveCodingConsole"). There is an additional option to start the program as hidden, where it will not be visible until Ctrl+Alt+F11 is hit. Similarly, closing the window will hide it instead of closing the application.
* Does not require a standalone licensed version of Live++.
Known issues:
* Does not currently support class layout changes / object reinstancing
#rb none
[FYI] Marc.Audy, Stefan.Boberg, Nick.Penwarden
#jira
#ROBOMERGE-SOURCE: CL 5304722 in //UE4/Release-4.22/...
#ROBOMERGE-BOT: RELEASE (Release-4.22 -> Main)
[CL 5309051 by ben marsh in Main branch]
2019-03-05 18:49:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const char* Clone(const char* str, size_t length)
|
|
|
|
|
{
|
|
|
|
|
// account for null-terminator
|
|
|
|
|
const size_t sizeNeeded = (length + 1u) * sizeof(char);
|
|
|
|
|
|
|
|
|
|
char* memory = static_cast<char*>(LC_ALLOC(&g_immutableStringAllocator, sizeNeeded, 8u));
|
|
|
|
|
memcpy(memory, str, sizeof(char)*length);
|
|
|
|
|
memory[length] = '\0';
|
|
|
|
|
|
|
|
|
|
return memory;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
|
{
|
|
|
|
|
std::string ToAnsiString(const wchar_t* str, size_t length)
|
|
|
|
|
{
|
|
|
|
|
const int sizeNeeded = ::WideCharToMultiByte(CP_ACP, 0, str, static_cast<int>(length), NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
char* strTo = static_cast<char*>(_alloca(sizeNeeded * sizeof(char)));
|
|
|
|
|
|
|
|
|
|
::WideCharToMultiByte(CP_ACP, 0, str, static_cast<int>(length), strTo, sizeNeeded, NULL, NULL);
|
|
|
|
|
return std::string(strTo, static_cast<size_t>(sizeNeeded));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableString ToUtf8String(const wchar_t* str, size_t length)
|
|
|
|
|
{
|
|
|
|
|
const int sizeNeeded = ::WideCharToMultiByte(CP_UTF8, 0, str, static_cast<int>(length), NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
char* strTo = static_cast<char*>(_alloca(sizeNeeded * sizeof(char)));
|
|
|
|
|
|
|
|
|
|
::WideCharToMultiByte(CP_UTF8, 0, str, static_cast<int>(length), strTo, sizeNeeded, NULL, NULL);
|
|
|
|
|
return ImmutableString(strTo, static_cast<size_t>(sizeNeeded));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace string
|
|
|
|
|
{
|
|
|
|
|
ImmutableString ToUtf8String(const wchar_t* str)
|
|
|
|
|
{
|
|
|
|
|
return detail::ToUtf8String(str, wcslen(str));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableString ToUtf8String(const wchar_t* str, size_t count)
|
|
|
|
|
{
|
|
|
|
|
size_t length = 0u;
|
|
|
|
|
while ((str[length] != L'\0') && (length < count))
|
|
|
|
|
{
|
|
|
|
|
// find null-terminator
|
|
|
|
|
++length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return detail::ToUtf8String(str, length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableString ToUtf8String(const std::wstring& str)
|
|
|
|
|
{
|
|
|
|
|
return detail::ToUtf8String(str.c_str(), str.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string ToAnsiString(const ImmutableString& utf8Str)
|
|
|
|
|
{
|
|
|
|
|
const std::wstring& wideStr = ToWideString(utf8Str);
|
|
|
|
|
return detail::ToAnsiString(wideStr.c_str(), wideStr.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::wstring ToWideString(const ImmutableString& utf8Str)
|
|
|
|
|
{
|
|
|
|
|
return string::ToWideString(utf8Str.c_str(), utf8Str.GetLength());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableString::ImmutableString(void)
|
|
|
|
|
: m_data()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableString::ImmutableString(const char* str)
|
|
|
|
|
: ImmutableString(str, strlen(str))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableString::ImmutableString(const char* str, size_t length)
|
|
|
|
|
{
|
|
|
|
|
if (FitsIntoShortString(length))
|
|
|
|
|
{
|
|
|
|
|
memcpy(m_data.shortString.str, str, length);
|
|
|
|
|
m_data.shortString.str[length] = '\0';
|
|
|
|
|
m_data.shortString.length = static_cast<uint8_t>(length);
|
|
|
|
|
m_data.shortString.hash = Hash(str, length);
|
|
|
|
|
|
|
|
|
|
m_data.shortString.length |= ShortString::MSB_SET_MASK;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_data.longString.str = Clone(str, length);
|
|
|
|
|
m_data.longString.length = static_cast<uint32_t>(length);
|
|
|
|
|
m_data.longString.hash = Hash(str, length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableString::ImmutableString(const ImmutableString& other)
|
|
|
|
|
{
|
|
|
|
|
if (other.IsShortString())
|
|
|
|
|
{
|
|
|
|
|
m_data.shortString = other.m_data.shortString;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_data.longString.length = other.m_data.longString.length;
|
|
|
|
|
m_data.longString.str = other.m_data.longString.str ? Clone(other.m_data.longString.str, other.GetLength()) : nullptr;
|
|
|
|
|
m_data.longString.hash = other.m_data.longString.hash;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableString::ImmutableString(ImmutableString&& other)
|
|
|
|
|
: m_data(other.m_data)
|
|
|
|
|
{
|
|
|
|
|
other.m_data = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableString& ImmutableString::operator=(ImmutableString&& other)
|
|
|
|
|
{
|
|
|
|
|
LC_ASSERT(this != &other, "Impossible move assignment.");
|
|
|
|
|
|
|
|
|
|
Free();
|
|
|
|
|
|
|
|
|
|
m_data = other.m_data;
|
|
|
|
|
other.m_data = {};
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableString::~ImmutableString(void)
|
|
|
|
|
{
|
|
|
|
|
Free();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t ImmutableString::Find(char character) const
|
|
|
|
|
{
|
|
|
|
|
const uint32_t length = GetLength();
|
|
|
|
|
const char* str = c_str();
|
|
|
|
|
for (uint32_t i = 0u; i < length; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (str[i] == character)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NOT_FOUND;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ImmutableString::Free(void)
|
|
|
|
|
{
|
|
|
|
|
if (!IsShortString())
|
|
|
|
|
{
|
|
|
|
|
LC_FREE(&g_immutableStringAllocator, const_cast<char*>(m_data.longString.str), (GetLength() + 1u) * sizeof(char));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|