diff options
author | Lioncash <mathew1800@gmail.com> | 2019-10-18 02:07:57 +0200 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2019-10-18 02:29:00 +0200 |
commit | a2eccbf075ea686cb54d7ebce719cf9ad6cf551b (patch) | |
tree | 05b265fb0f7514e405fbe402fccea4fd2127986e /src/video_core | |
parent | video_core/shader/ast: Make Indent() private (diff) | |
download | yuzu-a2eccbf075ea686cb54d7ebce719cf9ad6cf551b.tar yuzu-a2eccbf075ea686cb54d7ebce719cf9ad6cf551b.tar.gz yuzu-a2eccbf075ea686cb54d7ebce719cf9ad6cf551b.tar.bz2 yuzu-a2eccbf075ea686cb54d7ebce719cf9ad6cf551b.tar.lz yuzu-a2eccbf075ea686cb54d7ebce719cf9ad6cf551b.tar.xz yuzu-a2eccbf075ea686cb54d7ebce719cf9ad6cf551b.tar.zst yuzu-a2eccbf075ea686cb54d7ebce719cf9ad6cf551b.zip |
Diffstat (limited to 'src/video_core')
-rw-r--r-- | src/video_core/shader/ast.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/video_core/shader/ast.cpp b/src/video_core/shader/ast.cpp index f409706cc..9ef1d0a78 100644 --- a/src/video_core/shader/ast.cpp +++ b/src/video_core/shader/ast.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include <string> +#include <string_view> #include <fmt/format.h> @@ -263,7 +264,9 @@ public: } void operator()(const ASTIfElse& ast) { - inner += Indent() + "else {\n"; + inner += Indent(); + inner += "else {\n"; + scope++; ASTNode current = ast.nodes.GetFirst(); while (current) { @@ -271,15 +274,18 @@ public: current = current->GetNext(); } scope--; - inner += Indent() + "}\n"; + + inner += Indent(); + inner += "}\n"; } void operator()(const ASTBlockEncoded& ast) { inner += fmt::format("{}Block({}, {});\n", Indent(), ast.start, ast.end); } - void operator()(const ASTBlockDecoded& ast) { - inner += Indent() + "Block;\n"; + void operator()([[maybe_unused]] const ASTBlockDecoded& ast) { + inner += Indent(); + inner += "Block;\n"; } void operator()(const ASTVarSet& ast) { @@ -335,22 +341,26 @@ public: } private: - std::string& Indent() { - if (memo_scope == scope) { - return tabs_memo; + std::string_view Indent() { + if (space_segment_scope == scope) { + return space_segment; } - tabs_memo = tabs.substr(0, scope * 2); - memo_scope = scope; - return tabs_memo; + + // Ensure that we don't exceed our view. + ASSERT(scope * 2 < spaces.size()); + + space_segment = spaces.substr(0, scope * 2); + space_segment_scope = scope; + return space_segment; } std::string inner{}; - u32 scope{}; + std::string_view space_segment; - std::string tabs_memo{}; - u32 memo_scope{}; + u32 scope{}; + u32 space_segment_scope{}; - static constexpr std::string_view tabs{" "}; + static constexpr std::string_view spaces{" "}; }; std::string ASTManager::Print() { |