type_graph: provide inputName for all types

Type Graph deduplicates and modifies names to better fit the generated
code, for example `int32_t[4]` becomes `OIArray<int32_t, 4>` and `struct
MyStruct` might become `struct MyStruct_0`.

Add an `inputName` which better represents the original input code which
can be used when building the tree.
This commit is contained in:
Jake Hillion 2023-08-11 07:09:23 -07:00 committed by Jake Hillion
parent 373dbe8f6c
commit c62fbe371d
9 changed files with 266 additions and 52 deletions

View File

@ -132,8 +132,10 @@ void AddPadding::addPadding(uint64_t paddingStartBits,
// Pad with an array of bytes
uint64_t paddingStartByte = (paddingStartBits + 7) / 8;
auto& paddingArray = typeGraph_.makeType<Array>(primitive, paddingBytes);
paddedMembers.emplace_back(paddingArray, MemberPrefix,
paddingStartByte * 8);
// Set inputName to an empty string as it has no name in the input
auto& m =
paddedMembers.emplace_back(paddingArray, "", paddingStartByte * 8);
m.name = MemberPrefix;
}
}

View File

@ -106,14 +106,28 @@ void NameGen::visit(Container& c) {
}
std::string name = c.name();
removeTemplateParams(name);
std::string inputName{c.inputName()};
name.push_back('<');
removeTemplateParams(name);
removeTemplateParams(inputName);
name += '<';
inputName += '<';
bool first = true;
for (const auto& param : c.templateParams) {
if (!first) {
name += ", ";
inputName += ", ";
}
first = false;
if (param.value) {
name += *param.value;
inputName += *param.value;
} else {
name += param.type().name();
inputName += param.type().inputName();
// The "const" keyword must come after the type name so that pointers are
// handled correctly.
//
@ -122,15 +136,16 @@ void NameGen::visit(Container& c) {
// meaning pointer to const Foo.
if (param.qualifiers[Qualifier::Const]) {
name += " const";
inputName += " const";
}
}
name += ", ";
}
name.pop_back();
name.pop_back();
name.push_back('>');
name += '>';
inputName += '>';
c.setName(name);
c.setInputName(inputName);
}
void NameGen::visit(Enum& e) {
@ -140,8 +155,12 @@ void NameGen::visit(Enum& e) {
}
void NameGen::visit(Array& a) {
accept(a.elementType());
RecursiveVisitor::visit(a);
a.regenerateName();
std::string name{a.elementType().inputName()};
name += "[" + std::to_string(a.len()) + "]";
a.setInputName(name);
}
void NameGen::visit(Typedef& td) {
@ -164,12 +183,15 @@ void NameGen::visit(Typedef& td) {
}
void NameGen::visit(Pointer& p) {
accept(p.pointeeType());
RecursiveVisitor::visit(p);
p.regenerateName();
std::string inputName{p.pointeeType().inputName()};
inputName += '*';
p.setInputName(inputName);
}
void NameGen::visit(DummyAllocator& d) {
accept(d.allocType());
RecursiveVisitor::visit(d);
d.regenerateName();
}

View File

@ -52,8 +52,11 @@ void Printer::visit(const Class& c) {
kind = "Union";
break;
}
out_ << kind << ": " << c.name() << " (size: " << c.size()
<< align_str(c.align());
std::string name = c.name();
out_ << kind << ": " << name;
if (auto inp = c.inputName(); inp != name)
out_ << " [" << inp << "]";
out_ << " (size: " << c.size() << align_str(c.align());
if (c.packed()) {
out_ << ", packed";
}
@ -106,7 +109,10 @@ void Printer::visit(const Array& a) {
if (prefix(&a))
return;
out_ << "Array: (length: " << a.len() << ")" << std::endl;
out_ << "Array: ";
if (auto inp = a.inputName(); !inp.empty())
out_ << "[" << inp << "] ";
out_ << "(length: " << a.len() << ")" << std::endl;
print(a.elementType());
}
@ -114,7 +120,11 @@ void Printer::visit(const Typedef& td) {
if (prefix(&td))
return;
out_ << "Typedef: " << td.name() << std::endl;
auto name = td.name();
out_ << "Typedef: " << name;
if (auto inp = td.inputName(); inp != name)
out_ << " [" << inp << "]";
out_ << std::endl;
print(td.underlyingType());
}
@ -122,20 +132,25 @@ void Printer::visit(const Pointer& p) {
if (prefix(&p))
return;
out_ << "Pointer" << std::endl;
out_ << "Pointer";
if (auto inp = p.inputName(); !inp.empty())
out_ << " [" << inp << "]";
out_ << std::endl;
print(p.pointeeType());
}
void Printer::visit(const Dummy& d) {
prefix();
out_ << "Dummy (size: " << d.size() << align_str(d.align()) << ")"
<< std::endl;
out_ << "Dummy ";
out_ << "[" << d.inputName() << "] ";
out_ << "(size: " << d.size() << align_str(d.align()) << ")" << std::endl;
}
void Printer::visit(const DummyAllocator& d) {
prefix();
out_ << "DummyAllocator (size: " << d.size() << align_str(d.align()) << ")"
<< std::endl;
out_ << "DummyAllocator ";
out_ << "[" << d.inputName() << "] ";
out_ << "(size: " << d.size() << align_str(d.align()) << ")" << std::endl;
print(d.allocType());
}
@ -183,8 +198,10 @@ void Printer::print_parent(const Parent& parent) {
void Printer::print_member(const Member& member) {
depth_++;
prefix();
out_ << "Member: " << member.name
<< " (offset: " << static_cast<double>(member.bitOffset) / 8;
out_ << "Member: " << member.name;
if (member.inputName != member.name && !member.inputName.empty())
out_ << " [" << member.inputName << "]";
out_ << " (offset: " << static_cast<double>(member.bitOffset) / 8;
out_ << align_str(member.align);
if (member.bitsize != 0) {
out_ << ", bitsize: " << member.bitsize;

View File

@ -100,11 +100,12 @@ void TypeIdentifier::visit(Container& c) {
auto* allocator = dynamic_cast<Class*>(
&param.type()); // TODO please don't do this...
Type& typeToAllocate = allocator->templateParams.at(0).type();
auto& dummy = typeGraph_.makeType<DummyAllocator>(typeToAllocate, size,
param.type().align());
auto& dummy = typeGraph_.makeType<DummyAllocator>(
typeToAllocate, size, param.type().align(), allocator->name());
c.templateParams[i] = dummy;
} else {
auto& dummy = typeGraph_.makeType<Dummy>(size, param.type().align());
auto& dummy = typeGraph_.makeType<Dummy>(size, param.type().align(),
param.type().name());
c.templateParams[i] = dummy;
}
}

View File

@ -33,6 +33,7 @@
#include <map>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "oi/ContainerInfo.h"
@ -82,6 +83,8 @@ class Type {
virtual void accept(ConstVisitor& v) const = 0;
virtual const std::string& name() const = 0;
// Return the name as described in the input code for textual representation.
virtual std::string_view inputName() const = 0;
virtual size_t size() const = 0;
virtual uint64_t align() const = 0;
virtual NodeId id() const = 0;
@ -95,10 +98,14 @@ class Type {
class Member {
public:
Member(Type& type,
const std::string& name,
const std::string& name_,
uint64_t bitOffset,
uint64_t bitsize = 0)
: type_(type), name(name), bitOffset(bitOffset), bitsize(bitsize) {
: type_(type),
name(name_),
inputName(name_),
bitOffset(bitOffset),
bitsize(bitsize) {
}
Type& type() const {
@ -110,6 +117,7 @@ class Member {
public:
std::string name;
std::string inputName;
uint64_t bitOffset;
uint64_t bitsize;
uint64_t align = 0;
@ -186,7 +194,8 @@ class Class : public Type {
std::string fqName,
size_t size,
int virtuality = 0)
: name_(std::move(name)),
: name_(name),
inputName_(std::move(name)),
fqName_(std::move(fqName)),
size_(size),
kind_(kind),
@ -214,6 +223,10 @@ class Class : public Type {
return name_;
}
virtual std::string_view inputName() const override {
return inputName_;
}
void setName(std::string name) {
name_ = std::move(name);
}
@ -261,6 +274,7 @@ class Class : public Type {
private:
std::string name_;
std::string inputName_;
std::string fqName_;
size_t size_;
uint64_t align_ = 0;
@ -275,6 +289,7 @@ class Container : public Type {
Container(NodeId id, const ContainerInfo& containerInfo, size_t size)
: containerInfo_(containerInfo),
name_(containerInfo.typeName),
inputName_(containerInfo.typeName),
size_(size),
id_(id) {
}
@ -295,6 +310,14 @@ class Container : public Type {
name_ = std::move(name);
}
virtual std::string_view inputName() const override {
return inputName_;
}
void setInputName(std::string name) {
inputName_ = std::move(name);
}
virtual size_t size() const override {
return size_;
}
@ -325,6 +348,7 @@ class Container : public Type {
private:
std::string name_;
std::string inputName_;
size_t size_;
NodeId id_ = -1;
};
@ -334,7 +358,8 @@ class Enum : public Type {
explicit Enum(std::string name,
size_t size,
std::map<int64_t, std::string> enumerators = {})
: name_(std::move(name)),
: name_(name),
inputName_(std::move(name)),
size_(size),
enumerators_(std::move(enumerators)) {
}
@ -347,6 +372,10 @@ class Enum : public Type {
return name_;
}
virtual std::string_view inputName() const override {
return inputName_;
}
void setName(std::string name) {
name_ = std::move(name);
}
@ -369,6 +398,7 @@ class Enum : public Type {
private:
std::string name_;
std::string inputName_;
size_t size_;
std::map<int64_t, std::string> enumerators_;
};
@ -393,6 +423,14 @@ class Array : public Type {
std::to_string(len_) + ">";
}
virtual std::string_view inputName() const override {
return inputName_;
}
void setInputName(std::string name) {
inputName_ = std::move(name);
}
virtual size_t size() const override {
return len_ * elementType_.size();
}
@ -415,6 +453,7 @@ class Array : public Type {
private:
Type& elementType_;
std::string inputName_;
size_t len_;
NodeId id_ = -1;
@ -455,6 +494,9 @@ class Primitive : public Type {
virtual const std::string& name() const override {
return name_;
}
virtual std::string_view inputName() const override {
return name_;
}
virtual size_t size() const override;
virtual uint64_t align() const override {
return size();
@ -476,7 +518,10 @@ class Primitive : public Type {
class Typedef : public Type {
public:
explicit Typedef(NodeId id, std::string name, Type& underlyingType)
: name_(std::move(name)), underlyingType_(underlyingType), id_(id) {
: name_(name),
inputName_(std::move(name)),
underlyingType_(underlyingType),
id_(id) {
}
static inline constexpr bool has_node_id = true;
@ -487,6 +532,10 @@ class Typedef : public Type {
return name_;
}
virtual std::string_view inputName() const override {
return inputName_;
}
void setName(std::string name) {
name_ = std::move(name);
}
@ -509,6 +558,7 @@ class Typedef : public Type {
private:
std::string name_;
std::string inputName_;
Type& underlyingType_;
NodeId id_ = -1;
};
@ -532,6 +582,14 @@ class Pointer : public Type {
name_ = pointeeType_.name() + "*";
}
virtual std::string_view inputName() const override {
return inputName_;
}
void setInputName(std::string name) {
inputName_ = std::move(name);
}
virtual size_t size() const override {
return sizeof(uintptr_t);
}
@ -550,6 +608,7 @@ class Pointer : public Type {
private:
Type& pointeeType_;
std::string inputName_;
NodeId id_ = -1;
std::string name_;
@ -562,11 +621,12 @@ class Pointer : public Type {
*/
class Dummy : public Type {
public:
explicit Dummy(size_t size, uint64_t align)
explicit Dummy(size_t size, uint64_t align, std::string inputName)
: size_(size),
align_(align),
name_(std::string{"DummySizedOperator<"} + std::to_string(size) + ", " +
std::to_string(align) + ">") {
std::to_string(align) + ">"),
inputName_(std::move(inputName)) {
}
static inline constexpr bool has_node_id = false;
@ -577,6 +637,10 @@ class Dummy : public Type {
return name_;
}
virtual std::string_view inputName() const override {
return inputName_;
}
virtual size_t size() const override {
return size_;
}
@ -594,6 +658,7 @@ class Dummy : public Type {
uint64_t align_;
std::string name_;
std::string inputName_;
};
/*
@ -604,8 +669,14 @@ class Dummy : public Type {
*/
class DummyAllocator : public Type {
public:
explicit DummyAllocator(Type& type, size_t size, uint64_t align)
: type_(type), size_(size), align_(align) {
explicit DummyAllocator(Type& type,
size_t size,
uint64_t align,
std::string inputName)
: type_(type),
size_(size),
align_(align),
inputName_(std::move(inputName)) {
regenerateName();
}
@ -622,6 +693,10 @@ class DummyAllocator : public Type {
std::to_string(size_) + ", " + std::to_string(align_) + ">";
}
virtual std::string_view inputName() const override {
return inputName_;
}
virtual size_t size() const override {
return size_;
}
@ -644,6 +719,7 @@ class DummyAllocator : public Type {
uint64_t align_;
std::string name_;
std::string inputName_;
};
Type& stripTypedefs(Type& type);

View File

@ -151,6 +151,14 @@ std::optional<std::string_view> tryParseStringValue(std::string_view& input,
return val;
}
std::optional<std::string_view> tryParseInputName(std::string_view input) {
auto left = input.find_first_of('[');
auto right = input.find_last_of(']');
if (left == std::string_view::npos || right == std::string_view::npos)
return {};
return input.substr(left + 1, right - left - 1);
}
NodeId getId(std::string_view str, size_t* idLen = nullptr) {
if (idLen)
*idLen = 0;
@ -286,12 +294,15 @@ Type& TypeGraphParser::parseType(std::string_view& input, size_t rootIndent) {
} else if (nodeTypeName == "Dummy") {
// Format: "Dummy (size: 4)"
auto size = parseNumericAttribute(line, nodeTypeName, "size: ");
type = &typeGraph_.makeType<Dummy>(size, 0);
std::string inputName{*tryParseInputName(line)};
type = &typeGraph_.makeType<Dummy>(size, 0, inputName);
} else if (nodeTypeName == "DummyAllocator") {
// Format: "DummyAllocator (size: 8)"
auto size = parseNumericAttribute(line, nodeTypeName, "size: ");
std::string inputName{*tryParseInputName(line)};
auto& typeToAlloc = parseType(input, indent + 2);
type = &typeGraph_.makeType<DummyAllocator>(typeToAlloc, size, 0);
type =
&typeGraph_.makeType<DummyAllocator>(typeToAlloc, size, 0, inputName);
} else {
throw TypeGraphParserError{"Unsupported node type: " +
std::string{nodeTypeName}};

View File

@ -63,7 +63,7 @@ TEST(CodeGenTest, TransformContainerAllocator) {
Param
Primitive: int32_t
Param
DummyAllocator (size: 8)
DummyAllocator [MyAlloc] (size: 8)
Primitive: int32_t
)");
}
@ -98,7 +98,7 @@ TEST(CodeGenTest, TransformContainerAllocatorParamInParent) {
Param
Primitive: int32_t
Param
DummyAllocator (size: 0)
DummyAllocator [MyAlloc<std::pair<const int, int>>] (size: 0)
[3] Container: std::pair<int32_t const, int32_t> (size: 8)
Param
Primitive: int32_t
@ -121,16 +121,16 @@ TEST(CodeGenTest, RemovedMemberAlignment) {
Primitive: int8_t
)",
R"(
[0] Class: MyClass_0 (size: 24, align: 8)
Member: a_0 (offset: 0, align: 1)
[0] Class: MyClass_0 [MyClass] (size: 24, align: 8)
Member: a_0 [a] (offset: 0, align: 1)
Primitive: int8_t
Member: __oi_padding_1 (offset: 1)
[1] Array: (length: 15)
[1] Array: [int8_t[15]] (length: 15)
Primitive: int8_t
Member: c_2 (offset: 16, align: 1)
Member: c_2 [c] (offset: 16, align: 1)
Primitive: int8_t
Member: __oi_padding_3 (offset: 17)
[2] Array: (length: 7)
[2] Array: [int8_t[7]] (length: 7)
Primitive: int8_t
)");
}
@ -144,9 +144,9 @@ TEST(CodeGenTest, UnionMembersAlignment) {
Primitive: int64_t
)",
R"(
[0] Union: MyUnion_0 (size: 8, align: 8)
[0] Union: MyUnion_0 [MyUnion] (size: 8, align: 8)
Member: __oi_padding_0 (offset: 0)
[1] Array: (length: 8)
[1] Array: [int8_t[8]] (length: 8)
Primitive: int8_t
)");
}

View File

@ -19,6 +19,8 @@ TEST(NameGenTest, ClassParams) {
EXPECT_EQ(myclass.name(), "MyClass_0");
EXPECT_EQ(myparam1.name(), "MyParam_1");
EXPECT_EQ(myparam2.name(), "MyParam_2");
EXPECT_EQ(myclass.inputName(), "MyClass<MyParam, MyParam>");
}
TEST(NameGenTest, ClassContainerParam) {
@ -34,6 +36,8 @@ TEST(NameGenTest, ClassContainerParam) {
EXPECT_EQ(myclass.name(), "MyClass_0");
EXPECT_EQ(myparam.name(), "std::vector<int32_t>");
EXPECT_EQ(myclass.inputName(), "MyClass");
}
TEST(NameGenTest, ClassParents) {
@ -49,6 +53,10 @@ TEST(NameGenTest, ClassParents) {
EXPECT_EQ(myclass.name(), "MyClass_0");
EXPECT_EQ(myparent1.name(), "MyParent_1");
EXPECT_EQ(myparent2.name(), "MyParent_2");
EXPECT_EQ(myclass.inputName(), "MyClass");
EXPECT_EQ(myparent1.inputName(), "MyParent");
EXPECT_EQ(myparent2.inputName(), "MyParent");
}
TEST(NameGenTest, ClassMembers) {
@ -68,6 +76,12 @@ TEST(NameGenTest, ClassMembers) {
EXPECT_EQ(myclass.members[1].name, "mem_1");
EXPECT_EQ(mymember1.name(), "MyMember_1");
EXPECT_EQ(mymember2.name(), "MyMember_2");
EXPECT_EQ(myclass.inputName(), "MyClass");
EXPECT_EQ(myclass.members[0].inputName, "mem");
EXPECT_EQ(myclass.members[1].inputName, "mem");
EXPECT_EQ(mymember1.inputName(), "MyMember");
EXPECT_EQ(mymember2.inputName(), "MyMember");
}
TEST(NameGenTest, ClassMemberInvalidChar) {
@ -81,6 +95,9 @@ TEST(NameGenTest, ClassMemberInvalidChar) {
EXPECT_EQ(myclass.name(), "MyClass_0");
EXPECT_EQ(myclass.members[0].name, "mem$Nope_0");
EXPECT_EQ(myclass.inputName(), "MyClass");
EXPECT_EQ(myclass.members[0].inputName, "mem.Nope");
}
TEST(NameGenTest, ClassChildren) {
@ -96,6 +113,10 @@ TEST(NameGenTest, ClassChildren) {
EXPECT_EQ(myclass.name(), "MyClass_0");
EXPECT_EQ(mychild1.name(), "MyChild_1");
EXPECT_EQ(mychild2.name(), "MyChild_2");
EXPECT_EQ(myclass.inputName(), "MyClass");
EXPECT_EQ(mychild1.inputName(), "MyChild");
EXPECT_EQ(mychild2.inputName(), "MyChild");
}
TEST(NameGenTest, ContainerParams) {
@ -111,6 +132,10 @@ TEST(NameGenTest, ContainerParams) {
EXPECT_EQ(myparam1.name(), "MyParam_0");
EXPECT_EQ(myparam2.name(), "MyParam_1");
EXPECT_EQ(mycontainer.name(), "std::vector<MyParam_0, MyParam_1>");
EXPECT_EQ(myparam1.inputName(), "MyParam");
EXPECT_EQ(myparam2.inputName(), "MyParam");
EXPECT_EQ(mycontainer.inputName(), "std::vector<MyParam, MyParam>");
}
TEST(NameGenTest, ContainerParamsDuplicates) {
@ -124,6 +149,9 @@ TEST(NameGenTest, ContainerParamsDuplicates) {
EXPECT_EQ(myparam.name(), "MyParam_0");
EXPECT_EQ(mycontainer.name(), "std::vector<MyParam_0, MyParam_0>");
EXPECT_EQ(myparam.inputName(), "MyParam");
EXPECT_EQ(mycontainer.inputName(), "std::vector<MyParam, MyParam>");
}
TEST(NameGenTest, ContainerParamsDuplicatesDeep) {
@ -143,6 +171,11 @@ TEST(NameGenTest, ContainerParamsDuplicatesDeep) {
EXPECT_EQ(mycontainer1.name(), "std::vector<MyParam_0>");
EXPECT_EQ(mycontainer2.name(),
"std::vector<MyParam_0, std::vector<MyParam_0>>");
EXPECT_EQ(myparam.inputName(), "MyParam");
EXPECT_EQ(mycontainer1.inputName(), "std::vector<MyParam>");
EXPECT_EQ(mycontainer2.inputName(),
"std::vector<MyParam, std::vector<MyParam>>");
}
TEST(NameGenTest, ContainerParamsDuplicatesAcrossContainers) {
@ -166,6 +199,12 @@ TEST(NameGenTest, ContainerParamsDuplicatesAcrossContainers) {
EXPECT_EQ(myparam3.name(), "MyParam_2");
EXPECT_EQ(mycontainer1.name(), "std::vector<MyParam_0, MyParam_1>");
EXPECT_EQ(mycontainer2.name(), "std::vector<MyParam_1, MyParam_2>");
EXPECT_EQ(myparam1.inputName(), "MyParam");
EXPECT_EQ(myparam2.inputName(), "MyParam");
EXPECT_EQ(myparam3.inputName(), "MyParam");
EXPECT_EQ(mycontainer1.inputName(), "std::vector<MyParam, MyParam>");
EXPECT_EQ(mycontainer2.inputName(), "std::vector<MyParam, MyParam>");
}
TEST(NameGenTest, ContainerParamsConst) {
@ -189,6 +228,12 @@ TEST(NameGenTest, ContainerParamsConst) {
EXPECT_EQ(myparam3.name(), "PtrParam_2*");
EXPECT_EQ(mycontainer.name(),
"std::vector<MyConstParam_0 const, MyParam_1, PtrParam_2* const>");
EXPECT_EQ(myparam1.inputName(), "MyConstParam");
EXPECT_EQ(myparam2.inputName(), "MyParam");
EXPECT_EQ(myparam3.inputName(), "PtrParam*");
EXPECT_EQ(mycontainer.inputName(),
"std::vector<MyConstParam const, MyParam, PtrParam* const>");
}
TEST(NameGenTest, ContainerNoParams) {
@ -198,6 +243,7 @@ TEST(NameGenTest, ContainerNoParams) {
nameGen.generateNames({mycontainer});
EXPECT_EQ(mycontainer.name(), "std::vector");
EXPECT_EQ(mycontainer.inputName(), "std::vector");
}
TEST(NameGenTest, ContainerParamsValue) {
@ -215,6 +261,10 @@ TEST(NameGenTest, ContainerParamsValue) {
EXPECT_EQ(myint.name(), "int32_t");
EXPECT_EQ(myenum.name(), "MyEnum_0");
EXPECT_EQ(mycontainer.name(), "std::vector<123, MyEnum::OptionC>");
EXPECT_EQ(myint.inputName(), "int32_t");
EXPECT_EQ(myenum.inputName(), "MyEnum");
EXPECT_EQ(mycontainer.inputName(), "std::vector<123, MyEnum::OptionC>");
}
TEST(NameGenTest, Enum) {
@ -226,6 +276,9 @@ TEST(NameGenTest, Enum) {
EXPECT_EQ(myenum0.name(), "MyEnum_0");
EXPECT_EQ(myenum1.name(), "MyEnum_1");
EXPECT_EQ(myenum0.inputName(), "MyEnum");
EXPECT_EQ(myenum1.inputName(), "MyEnum");
}
TEST(NameGenTest, Array) {
@ -245,6 +298,11 @@ TEST(NameGenTest, Array) {
EXPECT_EQ(myparam2.name(), "MyParam_1");
EXPECT_EQ(mycontainer.name(), "std::vector<MyParam_0, MyParam_1>");
EXPECT_EQ(myarray.name(), "OIArray<std::vector<MyParam_0, MyParam_1>, 5>");
EXPECT_EQ(myparam1.inputName(), "MyParam");
EXPECT_EQ(myparam2.inputName(), "MyParam");
EXPECT_EQ(mycontainer.inputName(), "std::vector<MyParam, MyParam>");
EXPECT_EQ(myarray.inputName(), "std::vector<MyParam, MyParam>[5]");
}
TEST(NameGenTest, Typedef) {
@ -264,6 +322,11 @@ TEST(NameGenTest, Typedef) {
EXPECT_EQ(myparam2.name(), "MyParam_2");
EXPECT_EQ(mycontainer.name(), "std::vector<MyParam_1, MyParam_2>");
EXPECT_EQ(mytypedef.name(), "MyTypedef_0");
EXPECT_EQ(myparam1.inputName(), "MyParam");
EXPECT_EQ(myparam2.inputName(), "MyParam");
EXPECT_EQ(mycontainer.inputName(), "std::vector<MyParam, MyParam>");
EXPECT_EQ(mytypedef.inputName(), "MyTypedef");
}
TEST(NameGenTest, TypedefAliasTemplate) {
@ -274,6 +337,7 @@ TEST(NameGenTest, TypedefAliasTemplate) {
nameGen.generateNames({mytypedef});
EXPECT_EQ(mytypedef.name(), "MyTypedef_0");
EXPECT_EQ(mytypedef.inputName(), "MyTypedef<ParamA, ParamB>");
}
TEST(NameGenTest, Pointer) {
@ -293,15 +357,21 @@ TEST(NameGenTest, Pointer) {
EXPECT_EQ(myparam2.name(), "MyParam_1");
EXPECT_EQ(mycontainer.name(), "std::vector<MyParam_0, MyParam_1>");
EXPECT_EQ(mypointer.name(), "std::vector<MyParam_0, MyParam_1>*");
EXPECT_EQ(myparam1.inputName(), "MyParam");
EXPECT_EQ(myparam2.inputName(), "MyParam");
EXPECT_EQ(mycontainer.inputName(), "std::vector<MyParam, MyParam>");
EXPECT_EQ(mypointer.inputName(), "std::vector<MyParam, MyParam>*");
}
TEST(NameGenTest, Dummy) {
auto dummy = Dummy{12, 34};
auto dummy = Dummy{12, 34, "InputName"};
NameGen nameGen;
nameGen.generateNames({dummy});
EXPECT_EQ(dummy.name(), "DummySizedOperator<12, 34>");
EXPECT_EQ(dummy.inputName(), "InputName");
}
TEST(NameGenTest, DummyAllocator) {
@ -312,7 +382,7 @@ TEST(NameGenTest, DummyAllocator) {
mycontainer.templateParams.push_back(myparam1);
mycontainer.templateParams.push_back(myparam2);
auto myalloc = DummyAllocator{mycontainer, 12, 34};
auto myalloc = DummyAllocator{mycontainer, 12, 34, "BigAllocator"};
NameGen nameGen;
nameGen.generateNames({myalloc});
@ -322,6 +392,11 @@ TEST(NameGenTest, DummyAllocator) {
EXPECT_EQ(mycontainer.name(), "std::vector<MyParam_0, MyParam_1>");
EXPECT_EQ(myalloc.name(),
"DummyAllocator<std::vector<MyParam_0, MyParam_1>, 12, 34>");
EXPECT_EQ(myparam1.inputName(), "MyParam");
EXPECT_EQ(myparam2.inputName(), "MyParam");
EXPECT_EQ(mycontainer.inputName(), "std::vector<MyParam, MyParam>");
EXPECT_EQ(myalloc.inputName(), "BigAllocator");
}
TEST(NameGenTest, Cycle) {
@ -336,6 +411,9 @@ TEST(NameGenTest, Cycle) {
EXPECT_EQ(classA.name(), "ClassA_0");
EXPECT_EQ(classB.name(), "ClassB_1");
EXPECT_EQ(classA.inputName(), "ClassA");
EXPECT_EQ(classB.inputName(), "ClassB");
}
TEST(NameGenTest, ContainerCycle) {
@ -349,6 +427,9 @@ TEST(NameGenTest, ContainerCycle) {
EXPECT_EQ(myclass.name(), "MyClass_0");
EXPECT_EQ(container.name(), "std::vector<MyClass_0>");
EXPECT_EQ(myclass.inputName(), "MyClass");
EXPECT_EQ(container.inputName(), "std::vector<MyClass>");
}
TEST(NameGenTest, AnonymousTypes) {
@ -364,4 +445,8 @@ TEST(NameGenTest, AnonymousTypes) {
EXPECT_EQ(myclass.name(), "__oi_anon_0");
EXPECT_EQ(myenum.name(), "__oi_anon_1");
EXPECT_EQ(mytypedef.name(), "__oi_anon_2");
EXPECT_EQ(myclass.inputName(), "");
EXPECT_EQ(myenum.inputName(), "");
EXPECT_EQ(mytypedef.inputName(), "");
}

View File

@ -23,7 +23,7 @@ TEST(TypeIdentifierTest, StubbedParam) {
Param
Primitive: int32_t
Param
Dummy (size: 4)
Dummy [MyParam] (size: 4)
Param
Primitive: int32_t
)");
@ -48,7 +48,7 @@ TEST(TypeIdentifierTest, Allocator) {
Param
Primitive: int32_t
Param
DummyAllocator (size: 8)
DummyAllocator [MyAlloc] (size: 8)
Primitive: int32_t
Param
Primitive: int32_t
@ -74,7 +74,7 @@ TEST(TypeIdentifierTest, AllocatorSize1) {
Param
Primitive: int32_t
Param
DummyAllocator (size: 0)
DummyAllocator [MyAlloc] (size: 0)
Primitive: int32_t
Param
Primitive: int32_t
@ -134,7 +134,7 @@ TEST(TypeIdentifierTest, DummyNotReplaced) {
Param
Primitive: int32_t
Param
Dummy (size: 22)
Dummy [InputName] (size: 22)
)");
}
@ -144,7 +144,7 @@ TEST(TypeIdentifierTest, DummyAllocatorNotReplaced) {
Param
Primitive: int32_t
Param
DummyAllocator (size: 22)
DummyAllocator [InputName] (size: 22)
Primitive: int32_t
)");
}