Support CV qualifiers in function pointer types

This commit is contained in:
Duncan Ogilvie 2023-04-16 16:17:52 +02:00
parent e497cb87d3
commit b92d01f5c8
4 changed files with 133 additions and 119 deletions

View File

@ -23,6 +23,7 @@ DEF_KEYWORD(typedef)
DEF_KEYWORD(sizeof)
DEF_KEYWORD(union)
DEF_KEYWORD(const)
DEF_KEYWORD(volatile)
DEF_KEYWORD(void)
DEF_KEYWORD(signed)

View File

@ -1,55 +1,59 @@
struct TTD::Replay::IReplayEngine
struct TTD::Replay::ICursor
{
virtual struct TTD::Replay::MemoryRange QueryMemoryRange(enum Nirvana::GuestAddress, enum TTD::Replay::QueryMemoryPolicy) const = 0;
virtual struct TTD::Replay::MemoryBuffer QueryMemoryBuffer(enum Nirvana::GuestAddress, struct TTD::TBufferViewT, enum TTD::Replay::QueryMemoryPolicy) const = 0;
virtual struct TTD::Replay::MemoryBufferWithRanges QueryMemoryBufferWithRanges(enum Nirvana::GuestAddress, struct TTD::TBufferViewT, uint64_t, struct TTD::Replay::MemoryRange *, enum TTD::Replay::QueryMemoryPolicy) const = 0;
virtual void SetDefaultMemoryPolicy(enum TTD::Replay::QueryMemoryPolicy) = 0;
virtual enum TTD::Replay::QueryMemoryPolicy GetDefaultMemoryPolicy() const = 0;
virtual void * UnsafeGetReplayEngine(struct _GUID const &) const = 0;
virtual void const * UnsafeAsInterface(struct _GUID const &) const = 0;
virtual void * UnsafeAsInterface(struct _GUID const &) = 0;
virtual enum Nirvana::GuestAddress GetPebAddress() const = 0;
virtual struct TTD::SystemInfo const & GetSystemInfo() const = 0;
virtual struct TTD::Replay::PositionRange const & GetLifetime() const = 0;
virtual struct TTD::Replay::Position const & GetLastPosition() const = 0;
virtual struct TTD::Replay::Position const & GetFirstPosition() const = 0;
virtual enum TTD::Replay::RecordingType GetRecordingType() const = 0;
virtual struct TTD::Replay::ThreadInfo const & GetThreadInfo(enum TTD::Replay::UniqueThreadId) const = 0;
virtual uint64_t GetThreadCount() const = 0;
virtual struct TTD::Replay::ThreadInfo const * GetThreadList() const = 0;
virtual uint64_t const * GetThreadFirstPositionIndex() const = 0;
virtual uint64_t const * GetThreadLastPositionIndex() const = 0;
virtual uint64_t const * GetThreadLifetimeFirstPositionIndex() const = 0;
virtual uint64_t const * GetThreadLifetimeLastPositionIndex() const = 0;
virtual uint64_t GetThreadCreatedEventCount() const = 0;
virtual struct TTD::Replay::ThreadCreatedEvent const * GetThreadCreatedEventList() const = 0;
virtual uint64_t GetThreadTerminatedEventCount() const = 0;
virtual struct TTD::Replay::ThreadTerminatedEvent const * GetThreadTerminatedEventList() const = 0;
virtual struct TTD::Replay::ThreadInfo const & GetThreadInfo(enum TTD::ThreadId) const = 0;
virtual enum Nirvana::GuestAddress GetTebAddress(enum TTD::ThreadId) const = 0;
virtual struct TTD::Replay::Position const & GetPosition(enum TTD::ThreadId) const = 0;
virtual struct TTD::Replay::Position const & GetPreviousPosition(enum TTD::ThreadId) const = 0;
virtual enum Nirvana::GuestAddress GetProgramCounter(enum TTD::ThreadId) const = 0;
virtual enum Nirvana::GuestAddress GetStackPointer(enum TTD::ThreadId) const = 0;
virtual enum Nirvana::GuestAddress GetFramePointer(enum TTD::ThreadId) const = 0;
virtual uint64_t GetBasicReturnValue(enum TTD::ThreadId) const = 0;
virtual union TTD::Replay::RegisterContext GetCrossPlatformContext(enum TTD::ThreadId) const = 0;
virtual union TTD::Replay::ExtendedRegisterContext GetAvxExtendedContext(enum TTD::ThreadId) const = 0;
virtual uint64_t GetModuleCount() const = 0;
virtual struct TTD::Replay::Module const * GetModuleList() const = 0;
virtual uint64_t GetModuleInstanceCount() const = 0;
virtual struct TTD::Replay::ModuleInstance const * GetModuleInstanceList() const = 0;
virtual uint64_t const * GetModuleInstanceUnloadIndex() const = 0;
virtual uint64_t GetModuleLoadedEventCount() const = 0;
virtual struct TTD::Replay::ModuleLoadedEvent const * GetModuleLoadedEventList() const = 0;
virtual uint64_t GetModuleUnloadedEventCount() const = 0;
virtual struct TTD::Replay::ModuleUnloadedEvent const * GetModuleUnloadedEventList() const = 0;
virtual uint64_t GetExceptionEventCount() const = 0;
virtual struct TTD::Replay::ExceptionEvent const * GetExceptionEventList() const = 0;
virtual struct TTD::Replay::ExceptionEvent const * GetExceptionAtOrAfterPosition(struct TTD::Replay::Position const &) const = 0;
virtual uint64_t GetKeyframeCount() const = 0;
virtual struct TTD::Replay::Position const * GetKeyframeList() const = 0;
virtual uint64_t GetRecordClientCount() const = 0;
virtual struct TTD::Replay::RecordClient const * GetRecordClientList() const = 0;
virtual struct TTD::Replay::RecordClient const & GetRecordClient(enum TTD::RecordClientId) const = 0;
virtual uint64_t GetCustomEventCount() const = 0;
virtual struct TTD::Replay::CustomEvent const * GetCustomEventList() const = 0;
virtual uint64_t GetActivityCount() const = 0;
virtual struct TTD::Replay::Activity const * GetActivityList() const = 0;
virtual uint64_t GetIslandCount() const = 0;
virtual struct TTD::Replay::Island const * GetIslandList() const = 0;
virtual class TTD::Replay::ICursor * NewCursor(struct _GUID const &) = 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 GetIndexStatus() const = 0;
virtual struct TTD::Replay::IndexFileStats GetIndexFileStats() const = 0;
virtual void RegisterDebugModeAndLogging(enum TTD::Replay::DebugModeType, class TTD::ErrorReporting *) = 0;
virtual class TTD::Replay::IEngineInternals const * GetInternals() const = 0;
virtual class TTD::Replay::IEngineInternals * GetInternals() = 0;
virtual ~IReplayEngine() = 0;
virtual struct TTD::Replay::ModuleInstance const * GetModuleList() const = 0;
virtual uint64_t GetThreadCount() const = 0;
virtual struct TTD::Replay::ActiveThreadInfo const * GetThreadList() const = 0;
virtual void SetEventMask(enum TTD::Replay::EventMask) = 0;
virtual enum TTD::Replay::EventMask GetEventMask() const = 0;
virtual void SetGapKindMask(enum TTD::Replay::GapKindMask) = 0;
virtual enum TTD::Replay::GapKindMask GetGapKindMask() const = 0;
virtual void SetGapEventMask(enum TTD::Replay::GapEventMask) = 0;
virtual enum TTD::Replay::GapEventMask GetGapEventMask() const = 0;
virtual void SetExceptionMask(enum TTD::Replay::ExceptionMask) = 0;
virtual enum TTD::Replay::ExceptionMask GetExceptionMask() const = 0;
virtual void SetReplayFlags(enum TTD::Replay::ReplayFlags) = 0;
virtual enum TTD::Replay::ReplayFlags GetReplayFlags() const = 0;
virtual bool AddMemoryWatchpoint(struct TTD::Replay::MemoryWatchpointData const &) = 0;
virtual bool RemoveMemoryWatchpoint(struct TTD::Replay::MemoryWatchpointData const &) = 0;
virtual bool AddPositionWatchpoint(struct TTD::Replay::PositionWatchpointData const &) = 0;
virtual bool RemovePositionWatchpoint(struct TTD::Replay::PositionWatchpointData const &) = 0;
virtual void Clear() = 0;
virtual void SetPosition(struct TTD::Replay::Position const &) = 0;
virtual void SetPositionOnThread(enum TTD::Replay::UniqueThreadId, struct TTD::Replay::Position const &) = 0;
virtual void SetMemoryWatchpointCallback(bool (*const)(uint64_t, struct TTD::Replay::ICursorView::MemoryWatchpointResult const &, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetPositionWatchpointCallback(bool (*const)(uint64_t, struct TTD::Replay::Position const &, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetGapEventCallback(bool (*const)(uint64_t, enum TTD::Replay::GapKind, enum TTD::Replay::GapEventType, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetThreadContinuityBreakCallback(void (*const)(uint64_t), uint64_t) = 0;
virtual void SetReplayProgressCallback(void (*const)(uint64_t, struct TTD::Replay::Position const &), uint64_t) = 0;
virtual void SetFallbackCallback(void (*const)(uint64_t, bool, enum Nirvana::GuestAddress, uint64_t, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetCallReturnCallback(void (*const)(uint64_t, enum Nirvana::GuestAddress, enum Nirvana::GuestAddress, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetIndirectJumpCallback(void (*const)(uint64_t, enum Nirvana::GuestAddress, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetRegisterChangedCallback(void (*const)(uint64_t, unsigned char, void const *, void const *, uint64_t, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual struct TTD::Replay::ICursorView::ReplayResult ReplayForward(struct TTD::Replay::Position, enum TTD::Replay::StepCount) = 0;
virtual struct TTD::Replay::ICursorView::ReplayResult ReplayBackward(struct TTD::Replay::Position, enum TTD::Replay::StepCount) = 0;
virtual void InterruptReplay() = 0;
virtual class TTD::Replay::ICursorInternals * GetInternals() = 0;
virtual class TTD::Replay::ICursorInternals const * GetInternals() const = 0;
virtual uint64_t GetInternalData(enum TTD::Replay::ICursorView::InternalDataId, void *, uint64_t) const = 0;
virtual ~ICursor() = 0;
virtual void Destroy() = 0;
virtual bool Initialize(wchar_t const *) = 0;
};

View File

@ -1,55 +1,59 @@
struct TTD::Replay::IReplayEngine
struct TTD::Replay::ICursor
{
virtual struct TTD::Replay::MemoryRange QueryMemoryRange(enum Nirvana::GuestAddress, enum TTD::Replay::QueryMemoryPolicy) const = 0;
virtual struct TTD::Replay::MemoryBuffer QueryMemoryBuffer(enum Nirvana::GuestAddress, struct TTD::TBufferViewT, enum TTD::Replay::QueryMemoryPolicy) const = 0;
virtual struct TTD::Replay::MemoryBufferWithRanges QueryMemoryBufferWithRanges(enum Nirvana::GuestAddress, struct TTD::TBufferViewT, uint64_t, struct TTD::Replay::MemoryRange *, enum TTD::Replay::QueryMemoryPolicy) const = 0;
virtual void SetDefaultMemoryPolicy(enum TTD::Replay::QueryMemoryPolicy) = 0;
virtual enum TTD::Replay::QueryMemoryPolicy GetDefaultMemoryPolicy() const = 0;
virtual void * UnsafeGetReplayEngine(struct _GUID const &) const = 0;
virtual void const * UnsafeAsInterface(struct _GUID const &) const = 0;
virtual void * UnsafeAsInterface(struct _GUID const &) = 0;
virtual enum Nirvana::GuestAddress GetPebAddress() const = 0;
virtual struct TTD::SystemInfo const & GetSystemInfo() const = 0;
virtual struct TTD::Replay::PositionRange const & GetLifetime() const = 0;
virtual struct TTD::Replay::Position const & GetLastPosition() const = 0;
virtual struct TTD::Replay::Position const & GetFirstPosition() const = 0;
virtual enum TTD::Replay::RecordingType GetRecordingType() const = 0;
virtual struct TTD::Replay::ThreadInfo const & GetThreadInfo(enum TTD::Replay::UniqueThreadId) const = 0;
virtual uint64_t GetThreadCount() const = 0;
virtual struct TTD::Replay::ThreadInfo const * GetThreadList() const = 0;
virtual uint64_t const * GetThreadFirstPositionIndex() const = 0;
virtual uint64_t const * GetThreadLastPositionIndex() const = 0;
virtual uint64_t const * GetThreadLifetimeFirstPositionIndex() const = 0;
virtual uint64_t const * GetThreadLifetimeLastPositionIndex() const = 0;
virtual uint64_t GetThreadCreatedEventCount() const = 0;
virtual struct TTD::Replay::ThreadCreatedEvent const * GetThreadCreatedEventList() const = 0;
virtual uint64_t GetThreadTerminatedEventCount() const = 0;
virtual struct TTD::Replay::ThreadTerminatedEvent const * GetThreadTerminatedEventList() const = 0;
virtual struct TTD::Replay::ThreadInfo const & GetThreadInfo(enum TTD::ThreadId) const = 0;
virtual enum Nirvana::GuestAddress GetTebAddress(enum TTD::ThreadId) const = 0;
virtual struct TTD::Replay::Position const & GetPosition(enum TTD::ThreadId) const = 0;
virtual struct TTD::Replay::Position const & GetPreviousPosition(enum TTD::ThreadId) const = 0;
virtual enum Nirvana::GuestAddress GetProgramCounter(enum TTD::ThreadId) const = 0;
virtual enum Nirvana::GuestAddress GetStackPointer(enum TTD::ThreadId) const = 0;
virtual enum Nirvana::GuestAddress GetFramePointer(enum TTD::ThreadId) const = 0;
virtual uint64_t GetBasicReturnValue(enum TTD::ThreadId) const = 0;
virtual union TTD::Replay::RegisterContext GetCrossPlatformContext(enum TTD::ThreadId) const = 0;
virtual union TTD::Replay::ExtendedRegisterContext GetAvxExtendedContext(enum TTD::ThreadId) const = 0;
virtual uint64_t GetModuleCount() const = 0;
virtual struct TTD::Replay::Module const * GetModuleList() const = 0;
virtual uint64_t GetModuleInstanceCount() const = 0;
virtual struct TTD::Replay::ModuleInstance const * GetModuleInstanceList() const = 0;
virtual uint64_t const * GetModuleInstanceUnloadIndex() const = 0;
virtual uint64_t GetModuleLoadedEventCount() const = 0;
virtual struct TTD::Replay::ModuleLoadedEvent const * GetModuleLoadedEventList() const = 0;
virtual uint64_t GetModuleUnloadedEventCount() const = 0;
virtual struct TTD::Replay::ModuleUnloadedEvent const * GetModuleUnloadedEventList() const = 0;
virtual uint64_t GetExceptionEventCount() const = 0;
virtual struct TTD::Replay::ExceptionEvent const * GetExceptionEventList() const = 0;
virtual struct TTD::Replay::ExceptionEvent const * GetExceptionAtOrAfterPosition(struct TTD::Replay::Position const &) const = 0;
virtual uint64_t GetKeyframeCount() const = 0;
virtual struct TTD::Replay::Position const * GetKeyframeList() const = 0;
virtual uint64_t GetRecordClientCount() const = 0;
virtual struct TTD::Replay::RecordClient const * GetRecordClientList() const = 0;
virtual struct TTD::Replay::RecordClient const & GetRecordClient(enum TTD::RecordClientId) const = 0;
virtual uint64_t GetCustomEventCount() const = 0;
virtual struct TTD::Replay::CustomEvent const * GetCustomEventList() const = 0;
virtual uint64_t GetActivityCount() const = 0;
virtual struct TTD::Replay::Activity const * GetActivityList() const = 0;
virtual uint64_t GetIslandCount() const = 0;
virtual struct TTD::Replay::Island const * GetIslandList() const = 0;
virtual class TTD::Replay::ICursor * NewCursor(struct _GUID const &) = 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 GetIndexStatus() const = 0;
virtual struct TTD::Replay::IndexFileStats GetIndexFileStats() const = 0;
virtual void RegisterDebugModeAndLogging(enum TTD::Replay::DebugModeType, class TTD::ErrorReporting *) = 0;
virtual class TTD::Replay::IEngineInternals const * GetInternals() const = 0;
virtual class TTD::Replay::IEngineInternals * GetInternals() = 0;
virtual ~IReplayEngine() = 0;
virtual struct TTD::Replay::ModuleInstance const * GetModuleList() const = 0;
virtual uint64_t GetThreadCount() const = 0;
virtual struct TTD::Replay::ActiveThreadInfo const * GetThreadList() const = 0;
virtual void SetEventMask(enum TTD::Replay::EventMask) = 0;
virtual enum TTD::Replay::EventMask GetEventMask() const = 0;
virtual void SetGapKindMask(enum TTD::Replay::GapKindMask) = 0;
virtual enum TTD::Replay::GapKindMask GetGapKindMask() const = 0;
virtual void SetGapEventMask(enum TTD::Replay::GapEventMask) = 0;
virtual enum TTD::Replay::GapEventMask GetGapEventMask() const = 0;
virtual void SetExceptionMask(enum TTD::Replay::ExceptionMask) = 0;
virtual enum TTD::Replay::ExceptionMask GetExceptionMask() const = 0;
virtual void SetReplayFlags(enum TTD::Replay::ReplayFlags) = 0;
virtual enum TTD::Replay::ReplayFlags GetReplayFlags() const = 0;
virtual bool AddMemoryWatchpoint(struct TTD::Replay::MemoryWatchpointData const &) = 0;
virtual bool RemoveMemoryWatchpoint(struct TTD::Replay::MemoryWatchpointData const &) = 0;
virtual bool AddPositionWatchpoint(struct TTD::Replay::PositionWatchpointData const &) = 0;
virtual bool RemovePositionWatchpoint(struct TTD::Replay::PositionWatchpointData const &) = 0;
virtual void Clear() = 0;
virtual void SetPosition(struct TTD::Replay::Position const &) = 0;
virtual void SetPositionOnThread(enum TTD::Replay::UniqueThreadId, struct TTD::Replay::Position const &) = 0;
virtual void SetMemoryWatchpointCallback(bool (*const)(uint64_t, struct TTD::Replay::ICursorView::MemoryWatchpointResult const &, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetPositionWatchpointCallback(bool (*const)(uint64_t, struct TTD::Replay::Position const &, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetGapEventCallback(bool (*const)(uint64_t, enum TTD::Replay::GapKind, enum TTD::Replay::GapEventType, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetThreadContinuityBreakCallback(void (*const)(uint64_t), uint64_t) = 0;
virtual void SetReplayProgressCallback(void (*const)(uint64_t, struct TTD::Replay::Position const &), uint64_t) = 0;
virtual void SetFallbackCallback(void (*const)(uint64_t, bool, enum Nirvana::GuestAddress, uint64_t, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetCallReturnCallback(void (*const)(uint64_t, enum Nirvana::GuestAddress, enum Nirvana::GuestAddress, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetIndirectJumpCallback(void (*const)(uint64_t, enum Nirvana::GuestAddress, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual void SetRegisterChangedCallback(void (*const)(uint64_t, unsigned char, void const *, void const *, uint64_t, class TTD::Replay::IThreadView const *), uint64_t) = 0;
virtual struct TTD::Replay::ICursorView::ReplayResult ReplayForward(struct TTD::Replay::Position, enum TTD::Replay::StepCount) = 0;
virtual struct TTD::Replay::ICursorView::ReplayResult ReplayBackward(struct TTD::Replay::Position, enum TTD::Replay::StepCount) = 0;
virtual void InterruptReplay() = 0;
virtual class TTD::Replay::ICursorInternals * GetInternals() = 0;
virtual class TTD::Replay::ICursorInternals const * GetInternals() const = 0;
virtual uint64_t GetInternalData(enum TTD::Replay::ICursorView::InternalDataId, void *, uint64_t) const = 0;
virtual ~ICursor() = 0;
virtual void Destroy() = 0;
virtual bool Initialize(wchar_t const *) = 0;
};

View File

@ -81,7 +81,7 @@ struct Parser
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
type = QualifiedType();
type = QualifiedType();
switch (kind)
{
case Lexer::tok_struct:
@ -109,10 +109,10 @@ struct Parser
const auto& t = tlist[i];
if (t.Is(Lexer::tok_const))
{
if(i == 0 || type.pointers.empty())
type.isConst = true;
else
type.pointers.back().isConst = true;
if (i == 0 || type.pointers.empty())
type.isConst = true;
else
type.pointers.back().isConst = true;
continue;
}
@ -166,10 +166,10 @@ struct Parser
return false;
}
if(!sawPointer)
type.name = stype;
if (!sawPointer)
type.name = stype;
type.pointers.emplace_back();
type.pointers.emplace_back();
// Apply the pointer to the type on the left
stype += '*';
@ -183,8 +183,8 @@ struct Parser
}
if (stype.empty())
__debugbreak();
if(!sawPointer)
type.name = stype;
if (!sawPointer)
type.name = stype;
return true;
}
@ -217,6 +217,9 @@ struct Parser
}
index++;
while (isToken(Lexer::tok_const) || isToken(Lexer::tok_volatile))
index++;
if (!isToken(Lexer::tok_identifier))
{
if (isToken(Lexer::tok_parclose))
@ -367,8 +370,10 @@ struct Parser
// Function pointer argument to a function
Function subfn;
subfn.typeonly = true;
if(!parseFunction(kind, tlist, subfn, true))
if (!parseFunction(kind, tlist, subfn, true))
{
return false;
}
kind = Lexer::tok_eof;
// Create fake tokens
@ -385,9 +390,9 @@ struct Parser
tlist.push_back(typeToken);
tlist.push_back(nameToken);
// Add the function to the model
subfn.name = typeToken.IdentifierStr;
model.functions.push_back(subfn);
// Add the function to the model
subfn.name = typeToken.IdentifierStr;
model.functions.push_back(subfn);
}
else
{
@ -556,9 +561,9 @@ struct Parser
tlist.push_back(typeToken);
tlist.push_back(nameToken);
// Add the function to the model
subfn.name = typeToken.IdentifierStr;
model.functions.push_back(subfn);
// Add the function to the model
subfn.name = typeToken.IdentifierStr;
model.functions.push_back(subfn);
return true;
}