-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: format the stack frame' labels in a nicer way
- Loading branch information
Showing
4 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include RIGCVM_PCH | ||
|
||
namespace rigc::vm | ||
{ | ||
|
||
auto formatStackFrameLabel(ParserNode const&) -> std::string; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include RIGCVM_PCH | ||
|
||
#include <RigCVM/VM.hpp> | ||
#include <RigCVM/DevServer/Utils.hpp> | ||
|
||
#include <numeric> | ||
#include <functional> | ||
|
||
namespace { | ||
|
||
auto formatFunctionSignature(rigc::ParserNode const& node) { | ||
using namespace rigc; | ||
using namespace rigc::vm; | ||
|
||
auto const* const name = findElem<rigc::Name>(node); | ||
auto const* const params = findElem<rigc::FunctionParams>(node); | ||
auto const* const returnType = findElem<rigc::ExplicitReturnType>(node); | ||
|
||
// name(arg1: type, arg2: type): return_type | ||
return name->string() | ||
+ (params ? params->string() : "()") | ||
+ (returnType ? ": " : "") | ||
+ (returnType ? returnType->string() : ""); | ||
} | ||
|
||
auto stripWhitespace(std::string& str) { | ||
auto const prefixIt = rg::find_if(str, [](char c) { return std::isalpha(c); }); | ||
|
||
auto const begin = rg::begin(str); | ||
auto const end = begin + (prefixIt - begin); | ||
|
||
str.erase(begin, end); | ||
} | ||
|
||
auto formatCodeBlock(rigc::ParserNode const& node) { | ||
using namespace std::string_view_literals; | ||
|
||
auto static constexpr maxLabelNameLen = 20; | ||
auto static constexpr overflowIndicator = "..."sv; | ||
auto static constexpr overflowIndicatorLen = overflowIndicator.length(); | ||
auto static constexpr maxAllowedLen = maxLabelNameLen - overflowIndicatorLen; | ||
|
||
auto nodeString = node.string(); | ||
|
||
if (node.is_type<rigc::CodeBlock>()) { | ||
stripWhitespace(nodeString); | ||
} | ||
|
||
if(nodeString.length() > maxLabelNameLen) { | ||
return | ||
nodeString.substr(0, maxAllowedLen) | ||
+ std::string(overflowIndicator); | ||
} else { | ||
return nodeString; | ||
} | ||
} | ||
|
||
} | ||
|
||
namespace rigc::vm { | ||
|
||
auto formatStackFrameLabel(ParserNode const& node) -> std::string { | ||
auto const isFunctionDefinition = node.is_type<rigc::FunctionDefinition>(); | ||
|
||
if(isFunctionDefinition) { | ||
return formatFunctionSignature(node); | ||
} else { | ||
return formatCodeBlock(node); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters