[+] export AuParse::Parse[U/S]Int using const char*S as iterators

[*] Formatting/clean up
[*] Crinkling under Process
This commit is contained in:
Reece Wilson 2022-04-20 14:03:51 +01:00
parent 77a7b99c7c
commit 557fd2b574
6 changed files with 135 additions and 66 deletions

View File

@ -192,4 +192,7 @@ namespace Aurora::Parse
AUKN_SYM void SerializeToken(ParsableTag type, const ParseValue &value, AuString &str);
AUKN_SYM void Serialize(const ParsedObject &structure, AuString &ret);
AUKN_SYM AuResult<AuSInt> ParseSInt(const char *begin, const char *&end);
AUKN_SYM AuResult<AuUInt> ParseUInt(const char *begin, const char *&end);
}

View File

@ -4,6 +4,9 @@
File: Parser.cpp
Date: 2021-6-12
Author: Reece
Note: Horrible gen 1 parser.
I'm not removing or significantly improving this.
Just build around what works, could probably wrangle a command list parser on top.
***/
#include <Source/RuntimeInternal.hpp>
#include "Parser.hpp"
@ -50,7 +53,6 @@ namespace Aurora::Parse
};
}
template<size_t Z>
static AuFunction<bool(AuUInt8)> IsTerminating(ParseState &state, const AuUInt8(&arry)[Z])
{
@ -189,7 +191,7 @@ namespace Aurora::Parse
//SysAssert(!stringLevel, "Parsed tag of string type must end with \", got {}", out);
if (stringLevel)
{
AuLogWarn("Parsed tag of string type must end with \", got {}", out);
SysPushErrorSyntaxError("Parsed tag of string type must end with \", got {}", out);
return false;
}
@ -216,18 +218,18 @@ namespace Aurora::Parse
return (T(0) < val) - (val < T(0));
}
template <typename T>
bool ParseInt(const AuString &in, T &out)
template <typename T, typename Iterator>
bool ParseInt(Iterator begin, Iterator &end, T &out)
{
T res = 0;
T sign = 1;
out = 0;
auto itr = in.begin();
auto itr = begin;
if constexpr (AuIsSame_v<T, AuSInt>)
{
if (itr != in.end())
if (itr != end)
{
if (*itr == '-')
{
@ -237,8 +239,9 @@ namespace Aurora::Parse
}
}
int perf {};
for (;
(itr != in.end()) &&
(itr != end) &&
(*itr != '\0');
itr++)
{
@ -254,75 +257,61 @@ namespace Aurora::Parse
res *= 10;
res += static_cast<AuUInt>(*itr) - static_cast<AuUInt>('0');
if constexpr (AuIsSame_v<T, AuUInt>)
if ((perf++) >= 5)
{
if (old > res)
if constexpr (AuIsSame_v<T, AuUInt>)
{
SysPushErrorSyntaxError("Unsigned integer overflow: {}", in);
return false;
if (old > res)
{
SysPushErrorSyntaxError("Unsigned integer overflow: {}", AuString(begin, end));
end = itr;
return false;
}
}
}
else if constexpr (AuIsSame_v<T, AuSInt>)
{
if (SignBit(old) != SignBit(res))
else if constexpr (AuIsSame_v<T, AuSInt>)
{
SysPushErrorSyntaxError("Signed integer overflow: {}", in);
return false;
if (SignBit(old) != SignBit(res))
{
SysPushErrorSyntaxError("Signed integer overflow: {}", AuString(begin, end));
end = itr;
return false;
}
}
}
}
end = itr;
out = res * sign;
return true;
}
template <typename T>
bool ParseUInt(const AuString &in, T &out)
AUKN_SYM AuResult<AuUInt> ParseUInt(const char *begin, const char *&end)
{
auto temp = AuUInt{};
out = 0;
AuUInt temp{};
if (!ParseInt<AuUInt>(in, temp))
if (!ParseInt<AuUInt>(begin, end, temp))
{
return false;
return {};
}
if (temp > AuNumericLimits<T>::max())
{
return false;
}
out = temp;
return true;
return temp;
}
template <typename T>
bool ParseSInt(const AuString &in, T &out)
AUKN_SYM AuResult<AuSInt> ParseSInt(const char *begin, const char *&end)
{
auto temp = AuSInt{};
out = 0;
AuSInt temp{};
if (!ParseInt<AuSInt>(in, temp))
if (!ParseInt<AuSInt>(begin, end, temp))
{
return false;
return {};
}
if (temp > AuNumericLimits<T>::max())
{
return false;
}
if (temp < AuNumericLimits<T>::min())
{
return false;
}
out = temp;
return true;
return temp;
}
static bool ConsumeTokenPrimitiveish(ParseState &state, ParseContext &context, ParsableTag type, ParseValue &out)
{
AuCtorCode_t code;
AuString str;
if (!ConsumeStringifedToken(state, context, type, str))
@ -336,16 +325,16 @@ namespace Aurora::Parse
}
AuOptional<uuids::uuid> uuid;
auto end = str.end();
switch (type)
{
case ParsableTag::kParseUInt:
{
return ParseUInt(str, out.primitive.uint);
return ParseInt<AuUInt>(str.begin(), end, out.primitive.uint) && end == str.end();
}
case ParsableTag::kParseSInt:
{
return ParseSInt(str, out.primitive.sint);
return ParseInt<AuSInt>(str.begin(), end, out.primitive.sint) && end == str.end();
}
case ParsableTag::kParseNumber:
{
@ -354,7 +343,7 @@ namespace Aurora::Parse
case ParsableTag::kParseString:
case ParsableTag::kParseStringVararg:
{
out.string = str;
out.string = AuMove(str);
break;
}
case ParsableTag::kParseUUID:
@ -362,7 +351,7 @@ namespace Aurora::Parse
uuid = uuids::uuid::from_string(str);
if (!uuid.has_value())
{
AuLogWarn("Parse Error: invalid UUID {}", str);
SysPushErrorSyntaxError("Parse Error: invalid UUID {}", str);
return false;
}
out.UUID = uuid.value();
@ -370,17 +359,21 @@ namespace Aurora::Parse
}
case ParsableTag::kParseBoolean:
{
if ((str == "0") || (stricmp(str.c_str(), "false") == 0) || (stricmp(str.c_str(), "no") == 0))
if ((str == "0") ||
(stricmp(str.c_str(), "false") == 0) ||
(stricmp(str.c_str(), "no") == 0))
{
out.primitive.boolean = false;
}
else if ((str == "1") || (stricmp(str.c_str(), "true") == 0) || (stricmp(str.c_str(), "yes") == 0))
else if ((str == "1") ||
(stricmp(str.c_str(), "true") == 0) ||
(stricmp(str.c_str(), "yes") == 0))
{
out.primitive.boolean = true;
}
else
{
AuLogWarn("Parsed tag of boolean type wasn't parsable given the English string {}", str);
SysPushErrorSyntaxError("Parsed tag of boolean type wasn't parsable given the English string {}", str);
return false;
}
break;
@ -450,7 +443,7 @@ namespace Aurora::Parse
if (!ConsumeToken(state, context, ParsableTag::kParseUInt, arrayLengthBit))
{
AuLogWarn("Couldn't consume array length, label: {}, tag {}", parseBit.label, parseBit.tag);
SysPushErrorSyntaxError("Couldn't consume array length, label: {}, tag {}", parseBit.label, parseBit.tag);
return false;
}
@ -498,14 +491,18 @@ namespace Aurora::Parse
break;
}
AuLogWarn("Syntax error around: label: {}, tag {}", parseBit.label, parseBit.tag);
SysPushErrorSyntaxError("Syntax error around: label: {}, tag {}", parseBit.label, parseBit.tag);
return false;
}
if (parseBit.vararg || parseBit.array)
{
parsed.count++;
parsed.value.array.push_back(parsedSingle);
if (!AuTryInsert(parsed.value.array, parsedSingle))
{
SysPushErrorMem();
return false;
}
parsed.isArray = true;
}
else
@ -610,7 +607,10 @@ namespace Aurora::Parse
{
if (parsed.isArray)
{
ret += " ";
if (ret.size())
{
ret += " ";
}
ret += AuToString(parsed.count);
}
@ -618,7 +618,10 @@ namespace Aurora::Parse
for (int i = 0; ((i < parsed.count)); i++)
{
ret += " ";
if (ret.size())
{
ret += " ";
}
ParseValueEx parsedSingle = {};
ParseResult nestedresult = {};
@ -648,7 +651,5 @@ namespace Aurora::Parse
}
}
}
ret = ret.substr(1);
}
}

View File

@ -1,7 +1,29 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ModuleInfo.Linux.cpp
Date: 2021-6-12
Date: 2022-4-20
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "ProcessMap.Linux.hpp"
#include "ProcessMap.hpp"
namespace Aurora::Process
{
void InitProcessMapLinux()
{
}
void DeinitProcessMapLinux()
{
}
void RescanMaps()
{
}
}

View File

@ -5,3 +5,12 @@
Date: 2021-6-12
Author: Reece
***/
#pragma once
namespace Aurora::Process
{
void RescanMaps();
void InitProcessMapLinux();
void DeinitProcessMapLinux();
}

View File

@ -16,6 +16,10 @@
#include "ProcessMap.NT.hpp"
#endif
#if defined(AURORA_IS_LINUX_DERIVED)
#include "ProcessMap.Linux.hpp"
#endif
namespace Aurora::Process
{
struct ModuleBasePairHash
@ -59,7 +63,12 @@ namespace Aurora::Process
static const auto kPageBufferPad = 20;
static AuThreadPrimitives::MutexUnique_t gMutexUnique;
static AuHashMap<ModuleBasePair, AuSPtr<PublicModule>, ModuleBasePairHash, ModuleBasePairEq> gModuleMap;
static AuHashMap<ModuleBasePair,
AuSPtr<PublicModule>,
ModuleBasePairHash, // TODO: this precede auhashcode
ModuleBasePairEq>
gModuleMap;
static AuList<Section> gOtherSections;
static AuUInt ToLowestPageAlignment(AuUInt in)
{
@ -162,6 +171,10 @@ namespace Aurora::Process
InitProcessMapNt();
#endif
#if defined(AURORA_IS_LINUX_DERIVED)
InitProcessMapLinux();
#endif
TryRescanSlow();
}
@ -170,6 +183,11 @@ namespace Aurora::Process
#if defined(AURORA_PLATFORM_WIN32)
MakeToolHelp32Snapshot();
#endif
#if defined(AURORA_IS_LINUX_DERIVED)
RescanMaps();
#endif
}
void DeinitProcessMap()
@ -179,6 +197,16 @@ namespace Aurora::Process
#if defined(AURORA_IS_MODERNNT_DERIVED)
DeinitProcessMapNt();
#endif
#if defined(AURORA_IS_LINUX_DERIVED)
DeinitProcessMapLinux();
#endif
}
void BorrowOtherSectionArray(const AuConsumer<AuList<Section>> &callback)
{
AU_LOCK_GUARD(gMutexUnique);
callback(gOtherSections);
}
AUKN_SYM AuOptional<Section> GetSection(AuUInt pointer)
@ -227,6 +255,7 @@ namespace Aurora::Process
AUKN_SYM Sections DumpExecutableAll()
{
AU_LOCK_GUARD(gMutexUnique);
try
{
Sections ret;
@ -234,6 +263,9 @@ namespace Aurora::Process
{
ret.insert(ret.end(), ptr->sections.begin(), ptr->sections.end());
}
ret.insert(ret.end(), gOtherSections.begin(), gOtherSections.end());
return ret;
}
catch (...)

View File

@ -15,6 +15,8 @@ namespace Aurora::Process
AuUInt modBase;
};
void BorrowOtherSectionArray(const AuConsumer<AuList<Section>> &callback);
PublicModule GetFromModuleCache(AuUInt handle);
void InsertModuleCache(const ModuleBasePair &pair, const AuSPtr<PublicModule> &mod);
void RemoveModuleCache(const ModuleBasePair &eitherOr);