Support destructors and save the kind in QualifiedType

This commit is contained in:
Duncan Ogilvie 2023-04-16 14:57:33 +02:00
parent 4c4077646b
commit e497cb87d3
4 changed files with 160 additions and 116 deletions

View File

@ -1,55 +1,55 @@
struct TTD::Replay::IReplayEngine struct TTD::Replay::IReplayEngine
{ {
virtual void const * TTD::Replay::ReplayEngine::UnsafeAsInterface(struct _GUID const &) const = 0; virtual void const * UnsafeAsInterface(struct _GUID const &) const = 0;
virtual void * TTD::Replay::ReplayEngine::UnsafeAsInterface(struct _GUID const &) = 0; virtual void * UnsafeAsInterface(struct _GUID const &) = 0;
virtual enum Nirvana::GuestAddress TTD::Replay::ReplayEngine::GetPebAddress() const = 0; virtual enum Nirvana::GuestAddress GetPebAddress() const = 0;
virtual struct TTD::SystemInfo const & TTD::Replay::ReplayEngine::GetSystemInfo() const = 0; virtual struct TTD::SystemInfo const & GetSystemInfo() const = 0;
virtual struct TTD::Replay::PositionRange const & TTD::Replay::ReplayEngine::GetLifetime() const = 0; virtual struct TTD::Replay::PositionRange const & GetLifetime() const = 0;
virtual struct TTD::Replay::Position const & TTD::Replay::ReplayEngine::GetLastPosition() const = 0; virtual struct TTD::Replay::Position const & GetLastPosition() const = 0;
virtual struct TTD::Replay::Position const & TTD::Replay::ReplayEngine::GetFirstPosition() const = 0; virtual struct TTD::Replay::Position const & GetFirstPosition() const = 0;
virtual enum TTD::Replay::RecordingType TTD::Replay::ReplayEngine::GetRecordingType() const = 0; virtual enum TTD::Replay::RecordingType GetRecordingType() const = 0;
virtual struct TTD::Replay::ThreadInfo const & TTD::Replay::ReplayEngine::GetThreadInfo(enum TTD::Replay::UniqueThreadId) const = 0; virtual struct TTD::Replay::ThreadInfo const & GetThreadInfo(enum TTD::Replay::UniqueThreadId) const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetThreadCount() const = 0; virtual uint64_t GetThreadCount() const = 0;
virtual struct TTD::Replay::ThreadInfo const * TTD::Replay::ReplayEngine::GetThreadList() const = 0; virtual struct TTD::Replay::ThreadInfo const * GetThreadList() const = 0;
virtual uint64_t const * TTD::Replay::ReplayEngine::GetThreadFirstPositionIndex() const = 0; virtual uint64_t const * GetThreadFirstPositionIndex() const = 0;
virtual uint64_t const * TTD::Replay::ReplayEngine::GetThreadLastPositionIndex() const = 0; virtual uint64_t const * GetThreadLastPositionIndex() const = 0;
virtual uint64_t const * TTD::Replay::ReplayEngine::GetThreadLifetimeFirstPositionIndex() const = 0; virtual uint64_t const * GetThreadLifetimeFirstPositionIndex() const = 0;
virtual uint64_t const * TTD::Replay::ReplayEngine::GetThreadLifetimeLastPositionIndex() const = 0; virtual uint64_t const * GetThreadLifetimeLastPositionIndex() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetThreadCreatedEventCount() const = 0; virtual uint64_t GetThreadCreatedEventCount() const = 0;
virtual struct TTD::Replay::ThreadCreatedEvent const * TTD::Replay::ReplayEngine::GetThreadCreatedEventList() const = 0; virtual struct TTD::Replay::ThreadCreatedEvent const * GetThreadCreatedEventList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetThreadTerminatedEventCount() const = 0; virtual uint64_t GetThreadTerminatedEventCount() const = 0;
virtual struct TTD::Replay::ThreadTerminatedEvent const * TTD::Replay::ReplayEngine::GetThreadTerminatedEventList() const = 0; virtual struct TTD::Replay::ThreadTerminatedEvent const * GetThreadTerminatedEventList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetModuleCount() const = 0; virtual uint64_t GetModuleCount() const = 0;
virtual struct TTD::Replay::Module const * TTD::Replay::ReplayEngine::GetModuleList() const = 0; virtual struct TTD::Replay::Module const * GetModuleList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetModuleInstanceCount() const = 0; virtual uint64_t GetModuleInstanceCount() const = 0;
virtual struct TTD::Replay::ModuleInstance const * TTD::Replay::ReplayEngine::GetModuleInstanceList() const = 0; virtual struct TTD::Replay::ModuleInstance const * GetModuleInstanceList() const = 0;
virtual uint64_t const * TTD::Replay::ReplayEngine::GetModuleInstanceUnloadIndex() const = 0; virtual uint64_t const * GetModuleInstanceUnloadIndex() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetModuleLoadedEventCount() const = 0; virtual uint64_t GetModuleLoadedEventCount() const = 0;
virtual struct TTD::Replay::ModuleLoadedEvent const * TTD::Replay::ReplayEngine::GetModuleLoadedEventList() const = 0; virtual struct TTD::Replay::ModuleLoadedEvent const * GetModuleLoadedEventList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetModuleUnloadedEventCount() const = 0; virtual uint64_t GetModuleUnloadedEventCount() const = 0;
virtual struct TTD::Replay::ModuleUnloadedEvent const * TTD::Replay::ReplayEngine::GetModuleUnloadedEventList() const = 0; virtual struct TTD::Replay::ModuleUnloadedEvent const * GetModuleUnloadedEventList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetExceptionEventCount() const = 0; virtual uint64_t GetExceptionEventCount() const = 0;
virtual struct TTD::Replay::ExceptionEvent const * TTD::Replay::ReplayEngine::GetExceptionEventList() const = 0; virtual struct TTD::Replay::ExceptionEvent const * GetExceptionEventList() const = 0;
virtual struct TTD::Replay::ExceptionEvent const * TTD::Replay::ReplayEngine::GetExceptionAtOrAfterPosition(struct TTD::Replay::Position const &) const = 0; virtual struct TTD::Replay::ExceptionEvent const * GetExceptionAtOrAfterPosition(struct TTD::Replay::Position const &) const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetKeyframeCount() const = 0; virtual uint64_t GetKeyframeCount() const = 0;
virtual struct TTD::Replay::Position const * TTD::Replay::ReplayEngine::GetKeyframeList() const = 0; virtual struct TTD::Replay::Position const * GetKeyframeList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetRecordClientCount() const = 0; virtual uint64_t GetRecordClientCount() const = 0;
virtual struct TTD::Replay::RecordClient const * TTD::Replay::ReplayEngine::GetRecordClientList() const = 0; virtual struct TTD::Replay::RecordClient const * GetRecordClientList() const = 0;
virtual struct TTD::Replay::RecordClient const & TTD::Replay::ReplayEngine::GetRecordClient(enum TTD::RecordClientId) const = 0; virtual struct TTD::Replay::RecordClient const & GetRecordClient(enum TTD::RecordClientId) const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetCustomEventCount() const = 0; virtual uint64_t GetCustomEventCount() const = 0;
virtual struct TTD::Replay::CustomEvent const * TTD::Replay::ReplayEngine::GetCustomEventList() const = 0; virtual struct TTD::Replay::CustomEvent const * GetCustomEventList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetActivityCount() const = 0; virtual uint64_t GetActivityCount() const = 0;
virtual struct TTD::Replay::Activity const * TTD::Replay::ReplayEngine::GetActivityList() const = 0; virtual struct TTD::Replay::Activity const * GetActivityList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetIslandCount() const = 0; virtual uint64_t GetIslandCount() const = 0;
virtual struct TTD::Replay::Island const * TTD::Replay::ReplayEngine::GetIslandList() const = 0; virtual struct TTD::Replay::Island const * GetIslandList() const = 0;
virtual class TTD::Replay::ICursor * TTD::Replay::ReplayEngine::NewCursor(struct _GUID const &) = 0; virtual class TTD::Replay::ICursor * NewCursor(struct _GUID const &) = 0;
virtual enum TTD::Replay::IndexStatus TTD::Replay::ReplayEngine::BuildIndex(void (*)(void const *, struct TTD::Replay::IndexBuildProgressType const *), void const *, enum TTD::Replay::IndexBuildFlags) = 0; virtual enum TTD::Replay::IndexStatus BuildIndex(void (*)(void const *, struct TTD::Replay::IndexBuildProgressType const *), void const *, enum TTD::Replay::IndexBuildFlags) = 0;
virtual enum TTD::Replay::IndexStatus TTD::Replay::ReplayEngine::GetIndexStatus() const = 0; virtual enum TTD::Replay::IndexStatus GetIndexStatus() const = 0;
virtual struct TTD::Replay::IndexFileStats TTD::Replay::ReplayEngine::GetIndexFileStats() const = 0; virtual struct TTD::Replay::IndexFileStats GetIndexFileStats() const = 0;
virtual void TTD::Replay::ReplayEngine::RegisterDebugModeAndLogging(enum TTD::Replay::DebugModeType, class TTD::ErrorReporting *) = 0; virtual void RegisterDebugModeAndLogging(enum TTD::Replay::DebugModeType, class TTD::ErrorReporting *) = 0;
virtual class TTD::Replay::ICursorInternals * TTD::Replay::Cursor::GetInternals() = 0; virtual class TTD::Replay::IEngineInternals const * GetInternals() const = 0;
virtual class TTD::Replay::IEngineInternals const * TTD::Replay::ReplayEngine::GetInternals() const = 0; virtual class TTD::Replay::IEngineInternals * GetInternals() = 0;
virtual void * TTD::Replay::ReplayEngine::scalar_deleting_dtor(unsigned int) = 0; virtual ~IReplayEngine() = 0;
virtual void TTD::Replay::ReplayEngine::Destroy() = 0; virtual void Destroy() = 0;
virtual bool TTD::Replay::ReplayEngine::Initialize(wchar_t const *) = 0; virtual bool Initialize(wchar_t const *) = 0;
}; };

View File

@ -1,55 +1,55 @@
struct TTD::Replay::IReplayEngine struct TTD::Replay::IReplayEngine
{ {
virtual void const * TTD::Replay::ReplayEngine::UnsafeAsInterface(struct _GUID const &) const = 0; virtual void const * UnsafeAsInterface(struct _GUID const &) const = 0;
virtual void * TTD::Replay::ReplayEngine::UnsafeAsInterface(struct _GUID const &) = 0; virtual void * UnsafeAsInterface(struct _GUID const &) = 0;
virtual enum Nirvana::GuestAddress TTD::Replay::ReplayEngine::GetPebAddress() const = 0; virtual enum Nirvana::GuestAddress GetPebAddress() const = 0;
virtual struct TTD::SystemInfo const & TTD::Replay::ReplayEngine::GetSystemInfo() const = 0; virtual struct TTD::SystemInfo const & GetSystemInfo() const = 0;
virtual struct TTD::Replay::PositionRange const & TTD::Replay::ReplayEngine::GetLifetime() const = 0; virtual struct TTD::Replay::PositionRange const & GetLifetime() const = 0;
virtual struct TTD::Replay::Position const & TTD::Replay::ReplayEngine::GetLastPosition() const = 0; virtual struct TTD::Replay::Position const & GetLastPosition() const = 0;
virtual struct TTD::Replay::Position const & TTD::Replay::ReplayEngine::GetFirstPosition() const = 0; virtual struct TTD::Replay::Position const & GetFirstPosition() const = 0;
virtual enum TTD::Replay::RecordingType TTD::Replay::ReplayEngine::GetRecordingType() const = 0; virtual enum TTD::Replay::RecordingType GetRecordingType() const = 0;
virtual struct TTD::Replay::ThreadInfo const & TTD::Replay::ReplayEngine::GetThreadInfo(enum TTD::Replay::UniqueThreadId) const = 0; virtual struct TTD::Replay::ThreadInfo const & GetThreadInfo(enum TTD::Replay::UniqueThreadId) const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetThreadCount() const = 0; virtual uint64_t GetThreadCount() const = 0;
virtual struct TTD::Replay::ThreadInfo const * TTD::Replay::ReplayEngine::GetThreadList() const = 0; virtual struct TTD::Replay::ThreadInfo const * GetThreadList() const = 0;
virtual uint64_t const * TTD::Replay::ReplayEngine::GetThreadFirstPositionIndex() const = 0; virtual uint64_t const * GetThreadFirstPositionIndex() const = 0;
virtual uint64_t const * TTD::Replay::ReplayEngine::GetThreadLastPositionIndex() const = 0; virtual uint64_t const * GetThreadLastPositionIndex() const = 0;
virtual uint64_t const * TTD::Replay::ReplayEngine::GetThreadLifetimeFirstPositionIndex() const = 0; virtual uint64_t const * GetThreadLifetimeFirstPositionIndex() const = 0;
virtual uint64_t const * TTD::Replay::ReplayEngine::GetThreadLifetimeLastPositionIndex() const = 0; virtual uint64_t const * GetThreadLifetimeLastPositionIndex() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetThreadCreatedEventCount() const = 0; virtual uint64_t GetThreadCreatedEventCount() const = 0;
virtual struct TTD::Replay::ThreadCreatedEvent const * TTD::Replay::ReplayEngine::GetThreadCreatedEventList() const = 0; virtual struct TTD::Replay::ThreadCreatedEvent const * GetThreadCreatedEventList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetThreadTerminatedEventCount() const = 0; virtual uint64_t GetThreadTerminatedEventCount() const = 0;
virtual struct TTD::Replay::ThreadTerminatedEvent const * TTD::Replay::ReplayEngine::GetThreadTerminatedEventList() const = 0; virtual struct TTD::Replay::ThreadTerminatedEvent const * GetThreadTerminatedEventList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetModuleCount() const = 0; virtual uint64_t GetModuleCount() const = 0;
virtual struct TTD::Replay::Module const * TTD::Replay::ReplayEngine::GetModuleList() const = 0; virtual struct TTD::Replay::Module const * GetModuleList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetModuleInstanceCount() const = 0; virtual uint64_t GetModuleInstanceCount() const = 0;
virtual struct TTD::Replay::ModuleInstance const * TTD::Replay::ReplayEngine::GetModuleInstanceList() const = 0; virtual struct TTD::Replay::ModuleInstance const * GetModuleInstanceList() const = 0;
virtual uint64_t const * TTD::Replay::ReplayEngine::GetModuleInstanceUnloadIndex() const = 0; virtual uint64_t const * GetModuleInstanceUnloadIndex() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetModuleLoadedEventCount() const = 0; virtual uint64_t GetModuleLoadedEventCount() const = 0;
virtual struct TTD::Replay::ModuleLoadedEvent const * TTD::Replay::ReplayEngine::GetModuleLoadedEventList() const = 0; virtual struct TTD::Replay::ModuleLoadedEvent const * GetModuleLoadedEventList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetModuleUnloadedEventCount() const = 0; virtual uint64_t GetModuleUnloadedEventCount() const = 0;
virtual struct TTD::Replay::ModuleUnloadedEvent const * TTD::Replay::ReplayEngine::GetModuleUnloadedEventList() const = 0; virtual struct TTD::Replay::ModuleUnloadedEvent const * GetModuleUnloadedEventList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetExceptionEventCount() const = 0; virtual uint64_t GetExceptionEventCount() const = 0;
virtual struct TTD::Replay::ExceptionEvent const * TTD::Replay::ReplayEngine::GetExceptionEventList() const = 0; virtual struct TTD::Replay::ExceptionEvent const * GetExceptionEventList() const = 0;
virtual struct TTD::Replay::ExceptionEvent const * TTD::Replay::ReplayEngine::GetExceptionAtOrAfterPosition(struct TTD::Replay::Position const &) const = 0; virtual struct TTD::Replay::ExceptionEvent const * GetExceptionAtOrAfterPosition(struct TTD::Replay::Position const &) const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetKeyframeCount() const = 0; virtual uint64_t GetKeyframeCount() const = 0;
virtual struct TTD::Replay::Position const * TTD::Replay::ReplayEngine::GetKeyframeList() const = 0; virtual struct TTD::Replay::Position const * GetKeyframeList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetRecordClientCount() const = 0; virtual uint64_t GetRecordClientCount() const = 0;
virtual struct TTD::Replay::RecordClient const * TTD::Replay::ReplayEngine::GetRecordClientList() const = 0; virtual struct TTD::Replay::RecordClient const * GetRecordClientList() const = 0;
virtual struct TTD::Replay::RecordClient const & TTD::Replay::ReplayEngine::GetRecordClient(enum TTD::RecordClientId) const = 0; virtual struct TTD::Replay::RecordClient const & GetRecordClient(enum TTD::RecordClientId) const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetCustomEventCount() const = 0; virtual uint64_t GetCustomEventCount() const = 0;
virtual struct TTD::Replay::CustomEvent const * TTD::Replay::ReplayEngine::GetCustomEventList() const = 0; virtual struct TTD::Replay::CustomEvent const * GetCustomEventList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetActivityCount() const = 0; virtual uint64_t GetActivityCount() const = 0;
virtual struct TTD::Replay::Activity const * TTD::Replay::ReplayEngine::GetActivityList() const = 0; virtual struct TTD::Replay::Activity const * GetActivityList() const = 0;
virtual uint64_t TTD::Replay::ReplayEngine::GetIslandCount() const = 0; virtual uint64_t GetIslandCount() const = 0;
virtual struct TTD::Replay::Island const * TTD::Replay::ReplayEngine::GetIslandList() const = 0; virtual struct TTD::Replay::Island const * GetIslandList() const = 0;
virtual class TTD::Replay::ICursor * TTD::Replay::ReplayEngine::NewCursor(struct _GUID const &) = 0; virtual class TTD::Replay::ICursor * NewCursor(struct _GUID const &) = 0;
virtual enum TTD::Replay::IndexStatus TTD::Replay::ReplayEngine::BuildIndex(void (*)(void const *, struct TTD::Replay::IndexBuildProgressType const *), void const *, enum TTD::Replay::IndexBuildFlags) = 0; virtual enum TTD::Replay::IndexStatus BuildIndex(void (*)(void const *, struct TTD::Replay::IndexBuildProgressType const *), void const *, enum TTD::Replay::IndexBuildFlags) = 0;
virtual enum TTD::Replay::IndexStatus TTD::Replay::ReplayEngine::GetIndexStatus() const = 0; virtual enum TTD::Replay::IndexStatus GetIndexStatus() const = 0;
virtual struct TTD::Replay::IndexFileStats TTD::Replay::ReplayEngine::GetIndexFileStats() const = 0; virtual struct TTD::Replay::IndexFileStats GetIndexFileStats() const = 0;
virtual void TTD::Replay::ReplayEngine::RegisterDebugModeAndLogging(enum TTD::Replay::DebugModeType, class TTD::ErrorReporting *) = 0; virtual void RegisterDebugModeAndLogging(enum TTD::Replay::DebugModeType, class TTD::ErrorReporting *) = 0;
virtual class TTD::Replay::ICursorInternals * TTD::Replay::Cursor::GetInternals() = 0; virtual class TTD::Replay::IEngineInternals const * GetInternals() const = 0;
virtual class TTD::Replay::IEngineInternals const * TTD::Replay::ReplayEngine::GetInternals() const = 0; virtual class TTD::Replay::IEngineInternals * GetInternals() = 0;
virtual void * TTD::Replay::ReplayEngine::scalar_deleting_dtor(unsigned int) = 0; virtual ~IReplayEngine() = 0;
virtual void TTD::Replay::ReplayEngine::Destroy() = 0; virtual void Destroy() = 0;
virtual bool TTD::Replay::ReplayEngine::Initialize(wchar_t const *) = 0; virtual bool Initialize(wchar_t const *) = 0;
}; };

View File

@ -37,6 +37,7 @@ namespace Types
struct QualifiedType struct QualifiedType
{ {
std::string kind; // struct/class/union/enum
std::string name; // base name of the type std::string name; // base name of the type
bool isConst = false; // whether the base type is const bool isConst = false; // whether the base type is const
@ -71,7 +72,7 @@ namespace Types
std::string noconst() const std::string noconst() const
{ {
auto r = name; auto r = name;
for(const auto& ptr : pointers) for(size_t i = 0; i < pointers.size(); i++)
r += '*'; r += '*';
return r; return r;
} }

View File

@ -78,10 +78,27 @@ struct Parser
index++; index++;
} }
bool parseVariable(const std::vector<Lexer::TokenState>& tlist, QualifiedType& type, std::string& name) bool parseVariable(const std::vector<Lexer::TokenState>& tlist, QualifiedType& type, std::string& name, Lexer::Token kind)
{ {
std::string stype; // TODO: get rid of this variable std::string stype; // TODO: get rid of this variable
type = QualifiedType(); type = QualifiedType();
switch (kind)
{
case Lexer::tok_struct:
type.kind = "struct";
break;
case Lexer::tok_class:
type.kind = "class";
break;
case Lexer::tok_union:
type.kind = "union";
break;
case Lexer::tok_enum:
type.kind = "enum";
break;
default:
break;
}
name.clear(); name.clear();
bool sawPointer = false; bool sawPointer = false;
@ -171,7 +188,7 @@ struct Parser
return true; return true;
} }
bool parseFunction(std::vector<Lexer::TokenState>& rettypes, Function& fn, bool ptr) bool parseFunction(Lexer::Token retkind, std::vector<Lexer::TokenState>& rettypes, Function& fn, bool ptr)
{ {
if (rettypes.empty()) if (rettypes.empty())
{ {
@ -182,7 +199,7 @@ struct Parser
// TODO: calling conventions // TODO: calling conventions
std::string retname; std::string retname;
if (!parseVariable(rettypes, fn.rettype, retname)) if (!parseVariable(rettypes, fn.rettype, retname, retkind))
return false; return false;
if (ptr) if (ptr)
@ -243,14 +260,16 @@ struct Parser
fn.name = retname; fn.name = retname;
} }
auto kind = Lexer::tok_eof;
std::vector<Lexer::TokenState> tlist; std::vector<Lexer::TokenState> tlist;
auto startToken = curToken(); auto startToken = curToken();
auto finalizeArgument = [&]() auto finalizeArgument = [&]()
{ {
Member am; Member am;
if (!parseVariable(tlist, am.type, am.name)) if (!parseVariable(tlist, am.type, am.name, kind))
return false; return false;
fn.args.push_back(am); fn.args.push_back(am);
kind = Lexer::tok_eof;
tlist.clear(); tlist.clear();
startToken = curToken(); startToken = curToken();
return true; return true;
@ -268,6 +287,7 @@ struct Parser
{ {
if (tlist.empty() && getToken(index + 1).Token == Lexer::tok_identifier) if (tlist.empty() && getToken(index + 1).Token == Lexer::tok_identifier)
{ {
kind = curToken().Token;
index++; index++;
} }
else else
@ -347,8 +367,9 @@ struct Parser
// Function pointer argument to a function // Function pointer argument to a function
Function subfn; Function subfn;
subfn.typeonly = true; subfn.typeonly = true;
if(!parseFunction(tlist, subfn, true)) if(!parseFunction(kind, tlist, subfn, true))
return false; return false;
kind = Lexer::tok_eof;
// Create fake tokens // Create fake tokens
auto typeToken = tlist.back(); auto typeToken = tlist.back();
@ -401,6 +422,7 @@ struct Parser
{ {
Member m; Member m;
bool sawPointer = false; bool sawPointer = false;
auto kind = Lexer::tok_eof;
std::vector<Lexer::TokenState> tlist; std::vector<Lexer::TokenState> tlist;
auto startToken = curToken(); auto startToken = curToken();
@ -412,8 +434,9 @@ struct Parser
return false; return false;
} }
if (!parseVariable(tlist, m.type, m.name)) if (!parseVariable(tlist, m.type, m.name, kind))
return false; return false;
kind = Lexer::tok_eof;
if (m.type.name == "void" && !m.type.isPointer()) if (m.type.name == "void" && !m.type.isPointer())
{ {
@ -440,6 +463,7 @@ struct Parser
{ {
if (tlist.empty() && getToken(index + 1).Token == Lexer::tok_identifier) if (tlist.empty() && getToken(index + 1).Token == Lexer::tok_identifier)
{ {
kind = curToken().Token;
index++; index++;
} }
else else
@ -505,10 +529,11 @@ struct Parser
// Function pointer type // Function pointer type
Function subfn; Function subfn;
subfn.typeonly = true; subfn.typeonly = true;
if (!parseFunction(tlist, subfn, true)) if (!parseFunction(kind, tlist, subfn, true))
{ {
return false; return false;
} }
kind = Lexer::tok_eof;
if (!isToken(Lexer::tok_semic)) if (!isToken(Lexer::tok_semic))
{ {
@ -792,6 +817,7 @@ struct Parser
bool sawPointer = false; bool sawPointer = false;
std::vector<Lexer::TokenState> tlist; std::vector<Lexer::TokenState> tlist;
auto kind = Lexer::tok_eof;
while (!isToken(Lexer::tok_semic)) while (!isToken(Lexer::tok_semic))
{ {
if (isToken(Lexer::tok_eof)) if (isToken(Lexer::tok_eof))
@ -802,8 +828,9 @@ struct Parser
if (isStructLike()) if (isStructLike())
{ {
if (tlist.empty() && getToken(index + 1).Token == Lexer::tok_identifier) if (tlist.empty() && getToken(index + 1).Is(Lexer::tok_identifier))
{ {
kind = curToken().Token;
index++; index++;
} }
else else
@ -848,10 +875,11 @@ struct Parser
Function fn; Function fn;
fn.typeonly = true; fn.typeonly = true;
if (!parseFunction(tlist, fn, true)) if (!parseFunction(kind, tlist, fn, true))
{ {
return false; return false;
} }
kind = Lexer::tok_eof;
if (!isToken(Lexer::tok_semic)) if (!isToken(Lexer::tok_semic))
{ {
@ -880,7 +908,7 @@ struct Parser
} }
Member tm; Member tm;
if (!parseVariable(tlist, tm.type, tm.name)) if (!parseVariable(tlist, tm.type, tm.name, kind))
return false; return false;
model.types.push_back(tm); model.types.push_back(tm);
} }
@ -892,6 +920,7 @@ struct Parser
fn = {}; fn = {};
bool sawPointer = false; bool sawPointer = false;
auto kind = Lexer::tok_eof;
std::vector<Lexer::TokenState> tlist; std::vector<Lexer::TokenState> tlist;
while (!isToken(Lexer::tok_semic)) while (!isToken(Lexer::tok_semic))
{ {
@ -905,6 +934,7 @@ struct Parser
{ {
if (tlist.empty() && getToken(index + 1).Token == Lexer::tok_identifier) if (tlist.empty() && getToken(index + 1).Token == Lexer::tok_identifier)
{ {
kind = curToken().Token;
index++; index++;
} }
else else
@ -921,6 +951,18 @@ struct Parser
// Primitive type / name // Primitive type / name
tlist.push_back(t); tlist.push_back(t);
} }
else if (isTokenList({ Lexer::tok_op_neg, Lexer::tok_identifier }))
{
index++;
auto td = curToken();
index++;
// Destructor name
td.IdentifierStr = "~" + td.IdentifierStr;
auto tvoid = t;
tvoid.Token = Lexer::tok_void;
tlist.push_back(std::move(tvoid));
tlist.push_back(std::move(td));
}
else if (t.Is(Lexer::tok_op_mul) || t.Is(Lexer::tok_op_and)) else if (t.Is(Lexer::tok_op_mul) || t.Is(Lexer::tok_op_and))
{ {
// Pointer to the type on the left // Pointer to the type on the left
@ -946,10 +988,11 @@ struct Parser
index++; index++;
// Function pointer type // Function pointer type
if (!parseFunction(tlist, fn, false)) if (!parseFunction(kind, tlist, fn, false))
{ {
return false; return false;
} }
kind = Lexer::tok_eof;
if (!isToken(Lexer::tok_semic)) if (!isToken(Lexer::tok_semic))
{ {