Skip to content

Commit

Permalink
Improve FAST_BER_ALIAS
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam committed Nov 10, 2019
1 parent 2003de3 commit 6740a74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
5 changes: 4 additions & 1 deletion include/fast_ber/compiler/CompilerTypes.hpp
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions 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<Y>; \
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>; \
AliasedType& get_base() { return *this; } \
const AliasedType& get_base() const { return *this; } \
}
14 changes: 7 additions & 7 deletions src/compiler/CompilerMain.cpp
Expand Up @@ -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";
}
}

Expand Down

0 comments on commit 6740a74

Please sign in to comment.