Skip to content

Commit

Permalink
slang-reflect: Minor improvements of the code
Browse files Browse the repository at this point in the history
* Make use of std::views:keys
* Fix typo in a comment
  • Loading branch information
Sustrak committed Nov 13, 2024
1 parent 26f66eb commit 5890207
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions tools/reflect/src/SvEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "SvEnum.h"

#include <fmt/format.h>
#include <iostream>

void SvEnum::toCpp(HppFile& hppFile, std::string_view, const SvAliases&, bool) const {
auto underlyingType = [&] {
Expand Down Expand Up @@ -77,7 +76,7 @@ void SvEnum::toCpp(HppFile& hppFile, std::string_view, const SvAliases&, bool) c
hppFile.increaseIndent();
hppFile.addWithIndent("switch (__data.type) {\n");
hppFile.increaseIndent();
for (const auto& [name, value] : members)
for (const auto& name : members | std::views::keys)
hppFile.addWithIndent(fmt::format("case Type::{0}: os << \"{0}\"; break;\n", name));
hppFile.decreaseIndent();
hppFile.addWithIndent("}\n");
Expand Down
2 changes: 1 addition & 1 deletion tools/reflect/src/SvStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void SvStruct::toCpp(HppFile& hppFile, const std::string_view _namespace, const
hppFile.addWithIndent(fmt::format("operator {}() const {{\n", cppTypeStr));
hppFile.increaseIndent();
hppFile.addWithIndent(fmt::format("{} ret = 0;\n", cppTypeStr));
for (const auto& [name, _] : members) {
for (const auto& name : members | std::views::keys) {
hppFile.addWithIndent(
fmt::format("ret |= static_cast<{0}>({1}) << {1}_s;\n", cppTypeStr, name));
}
Expand Down
2 changes: 1 addition & 1 deletion tools/reflect/src/SvUnion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void SvUnion::toCpp(HppFile& hppFile, std::string_view _namespace, const SvAlias
// Create a sc bit vector to store the data of the Union
hppFile.addWithIndent(fmt::format("{} union_data;\n\n", cppTypeStr));

// Check if some headers needs to be included
// Check if some headers need to be included
for (const auto& member : type.getCanonicalType().as<slang::ast::Scope>().members()) {
const auto& variable = member.as<slang::ast::VariableSymbol>();

Expand Down

0 comments on commit 5890207

Please sign in to comment.