From 6740a7462656447b91c03b0d645ad41b541e77e2 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 10 Nov 2019 11:00:27 +0000 Subject: [PATCH] Improve FAST_BER_ALIAS --- include/fast_ber/compiler/CompilerTypes.hpp | 5 ++++- include/fast_ber/util/Alias.hpp | 18 +++++++++--------- src/compiler/CompilerMain.cpp | 14 +++++++------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/include/fast_ber/compiler/CompilerTypes.hpp b/include/fast_ber/compiler/CompilerTypes.hpp index e1861603..86b1453a 100644 --- a/include/fast_ber/compiler/CompilerTypes.hpp +++ b/include/fast_ber/compiler/CompilerTypes.hpp @@ -403,7 +403,10 @@ struct Identifier Class class_; int64_t tag_number; - std::string name() const { return "Id<" + to_string(class_, true) + ", " + std::to_string(tag_number) + ">"; } + std::string name() const + { + return "ImplicitIdentifier<" + to_string(class_, true) + ", " + std::to_string(tag_number) + ">"; + } }; struct TaggingInfo diff --git a/include/fast_ber/util/Alias.hpp b/include/fast_ber/util/Alias.hpp index 2348b53e..94fbfd0e 100644 --- a/include/fast_ber/util/Alias.hpp +++ b/include/fast_ber/util/Alias.hpp @@ -1,14 +1,14 @@ #pragma once -#define FAST_BER_ALIAS(X, Y) \ - struct X : Y \ +#define FAST_BER_ALIAS(X, ...) \ + struct X : __VA_ARGS__ \ { \ - using Y::Y; \ + using AliasedType = __VA_ARGS__; \ + using AliasedType::AliasedType; \ X() = default; \ - X(const Y& y) : Y(y) {} \ - X(Y&& y) : Y(std::move(y)) {} \ - using Id = fast_ber::Identifier; \ - using AliasedType = Y; \ - Y& get_base() { return *this; } \ - const Y& get_base() const { return *this; } \ + X(const AliasedType& y) : AliasedType(y) {} \ + X(AliasedType&& y) : AliasedType(std::move(y)) {} \ + using Id = fast_ber::Identifier; \ + AliasedType& get_base() { return *this; } \ + const AliasedType& get_base() const { return *this; } \ } diff --git a/src/compiler/CompilerMain.cpp b/src/compiler/CompilerMain.cpp index 7a25098f..ba6cb974 100644 --- a/src/compiler/CompilerMain.cpp +++ b/src/compiler/CompilerMain.cpp @@ -32,22 +32,22 @@ std::string create_type_assignment(const std::string& name, const Type& assignme { if (is_set(assignment_type) || is_sequence(assignment_type)) { - return "struct " + name + type_as_string(assignment_type, module, tree); + std::string res; + + res += "struct " + name + type_as_string(assignment_type, module, tree); + return res; } else if (is_enumerated(assignment_type)) { std::string output; output += "enum class " + name + "Values" + type_as_string(assignment_type, module, tree); - output += "using " + name + "_INTERNAL = " + "Enumerated<" + name + "Values>" + ";\n"; - output += "FAST_BER_ALIAS(" + name + "," + name + "_INTERNAL);\n"; + output += "FAST_BER_ALIAS(" + name + ", " + "Enumerated<" + name + "Values>);"; + return output; } else { - std::string output; - output += "using " + name + "_INTERNAL = " + type_as_string(assignment_type, module, tree) + ";\n"; - output += "FAST_BER_ALIAS(" + name + "," + name + "_INTERNAL);\n"; - return output; + return "FAST_BER_ALIAS(" + name + ", " + type_as_string(assignment_type, module, tree) + ");\n"; } }