Shipwright/ZAPDTR/ZAPD/ZString.cpp
Jeffrey Crowell d4c1c40c1d
add support for clang compiler (#592)
* hacks to align strings for clang... wow just wow

* start work to getting built with clang

* fix issues with struct constructors, all builds, doesn't link still

* fix some narrowing issues that clang complains about

* fix compliation of zapd

* fix null deref in VersionInfo

* builds with clang

* make stringbuilding use StringHelper instead of addition

* fix linking

* add CLANG SHIP overlay on clang built versions

* doesn't need to be volatile

* mark unknown strings as extern

* rename some stuff

* can't align extern

* hopefully fix compilation for everythign

* expandtab

* allow setting LD

* Revert "allow setting LD"

This reverts commit 711aba6db2.

maybe to use lld it should be a LDFLAG?

* -Wno-deprecated-declarations is required for newer versions of clang

on macOS 13 beta sdk, the version of apple clang requires this

* Add jenkins support for clang

* Forward CXX flags to stormlib compilation

* Move GCC only flags to check

* use exports to set multiarch setup

* Fix Jenkins forever

* use make instead of cmake --build

add some flags to build with clang-11 as well

* address review coments

- rework extraction to allow multi thread
- misc readability cleanup

* update makefile to add WARN on linux+clang

Co-authored-by: David Chavez <david@dcvz.io>
2022-07-10 10:51:12 -04:00

70 lines
1.5 KiB
C++

#include "ZString.h"
#include "Utils/File.h"
#include "Utils/StringHelper.h"
#include "ZFile.h"
REGISTER_ZFILENODE(String, ZString);
ZString::ZString(ZFile* nParent) : ZResource(nParent)
{
}
void ZString::ParseRawData()
{
size_t size = 0;
const auto& rawData = parent->GetRawData();
const auto& rawDataArr = rawData.data();
size_t rawDataSize = rawData.size();
for (size_t i = rawDataIndex; i < rawDataSize; ++i)
{
++size;
if (rawDataArr[i] == '\0')
{
break;
}
}
auto dataStart = rawData.begin() + rawDataIndex;
strData.assign(dataStart, dataStart + size);
}
Declaration* ZString::DeclareVar(const std::string& prefix, const std::string& bodyStr)
{
std::string auxName = name;
if (name == "")
auxName = GetDefaultName(prefix);
Declaration* decl =
parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(),
GetSourceTypeName(), auxName, 0, bodyStr);
decl->staticConf = staticConf;
return decl;
}
std::string ZString::GetBodySourceCode() const
{
return StringHelper::Sprintf("\t\"%s\"", strData.data());
}
std::string ZString::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix, std::set<std::string> *nameSet)
{
return StringHelper::Sprintf("#define %s_macro \"%s\"", name.c_str(), strData.data());
}
std::string ZString::GetSourceTypeName() const
{
return "char";
}
ZResourceType ZString::GetResourceType() const
{
return ZResourceType::String;
}
size_t ZString::GetRawDataSize() const
{
return strData.size();
}