Skip to content

Commit

Permalink
Support Attribute as well
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed May 28, 2020
1 parent 9ea8fe0 commit 0252593
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
37 changes: 14 additions & 23 deletions include/verilogAST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,19 @@ class NumericLiteral : public Expression {

NumericLiteral(std::string value, unsigned int size, bool _signed,
Radix radix)
: value(value),
size(size),
_signed(_signed),
radix(radix){};
: value(value), size(size), _signed(_signed), radix(radix){};

NumericLiteral(std::string value, unsigned int size, bool _signed)
: value(value),
size(size),
_signed(_signed),
radix(Radix::DECIMAL){};
: value(value), size(size), _signed(_signed), radix(Radix::DECIMAL){};

NumericLiteral(std::string value, unsigned int size)
: value(value),
size(size),
_signed(false),
radix(Radix::DECIMAL){};
: value(value), size(size), _signed(false), radix(Radix::DECIMAL){};

NumericLiteral(std::string value)
: value(value),
size(32),
_signed(false),
radix(Radix::DECIMAL){};
: value(value), size(32), _signed(false), radix(Radix::DECIMAL){};

NumericLiteral(std::string value, Radix radix)
: value(value),
size(32),
_signed(false),
radix(radix){};
: value(value), size(32), _signed(false), radix(radix){};

std::string toString() override;
auto clone() const { return std::unique_ptr<NumericLiteral>(clone_impl()); }
Expand Down Expand Up @@ -237,10 +222,12 @@ class Slice : public Expression {
};

class Index : public Expression {
std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Slice>>
std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Attribute>,
std::unique_ptr<Slice>>
clone_index_value() const {
return std::visit(
[](auto&& value) -> std::variant<std::unique_ptr<Identifier>,
std::unique_ptr<Attribute>,
std::unique_ptr<Slice>> {
return value->clone();
},
Expand All @@ -253,10 +240,14 @@ class Index : public Expression {
};

public:
std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Slice>> value;
std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Attribute>,
std::unique_ptr<Slice>>
value;
std::unique_ptr<Expression> index;

Index(std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Slice>> value,
Index(std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Attribute>,
std::unique_ptr<Slice>>
value,
std::unique_ptr<Expression> index)
: value(std::move(value)), index(std::move(index)){};

Expand Down
5 changes: 5 additions & 0 deletions tests/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ TEST(BasicTests, TestString) {
TEST(BasicTests, TestIndex) {
vAST::Index index(vAST::make_id("x"), vAST::make_num("0"));
EXPECT_EQ(index.toString(), "x[0]");

vAST::Index index2(
std::make_unique<vAST::Slice>(vAST::make_id("x"), vAST::make_num("3"),
vAST::make_num("0")),
vAST::make_num("0"));
EXPECT_EQ(index2.toString(), "x[3:0][0]");

vAST::Index index3(std::make_unique<vAST::Attribute>(vAST::make_id("x"), "y"),
vAST::make_num("0"));
EXPECT_EQ(index3.toString(), "x.y[0]");
}

TEST(BasicTests, TestSlice) {
Expand Down

0 comments on commit 0252593

Please sign in to comment.