From 11bb7ac348a7cf6ea3f2f60031a56a185e2a7325 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 3 Feb 2015 14:38:04 +0100 Subject: [PATCH] vhdlpp: Expression::write_to_stream becomes const. --- vhdlpp/expression.h | 46 ++++++++++++++++++------------------- vhdlpp/expression_stream.cc | 38 +++++++++++++++--------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/vhdlpp/expression.h b/vhdlpp/expression.h index 15983a25d..058533f86 100644 --- a/vhdlpp/expression.h +++ b/vhdlpp/expression.h @@ -87,7 +87,7 @@ class Expression : public LineInfo { // This virtual method writes a VHDL-accurate representation // of this expression to the designated stream. This is used // for writing parsed types to library files. - virtual void write_to_stream(std::ostream&fd) =0; + virtual void write_to_stream(std::ostream&fd) const =0; // The emit virtual method is called by architecture emit to // output the generated code for the expression. The derived @@ -163,7 +163,7 @@ class ExpUnary : public Expression { const VType*fit_type(Entity*ent, ScopeBase*scope, const VTypeArray*atype) const; protected: - inline void write_to_stream_operand1(std::ostream&fd) + inline void write_to_stream_operand1(std::ostream&fd) const { operand1_->write_to_stream(fd); } int emit_operand1(ostream&out, Entity*ent, ScopeBase*scope); @@ -197,9 +197,9 @@ class ExpBinary : public Expression { bool eval_operand1(ScopeBase*scope, int64_t&val) const; bool eval_operand2(ScopeBase*scope, int64_t&val) const; - inline void write_to_stream_operand1(std::ostream&out) + inline void write_to_stream_operand1(std::ostream&out) const { operand1_->write_to_stream(out); } - inline void write_to_stream_operand2(std::ostream&out) + inline void write_to_stream_operand2(std::ostream&out) const { operand2_->write_to_stream(out); } void dump_operands(ostream&out, int indent = 0) const; @@ -297,7 +297,7 @@ class ExpAggregate : public Expression { const VType*probe_type(Entity*ent, ScopeBase*scope) const; const VType*fit_type(Entity*ent, ScopeBase*scope, const VTypeArray*atype) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; @@ -330,7 +330,7 @@ class ExpArithmetic : public ExpBinary { } int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); virtual bool evaluate(ScopeBase*scope, int64_t&val) const; void dump(ostream&out, int indent = 0) const; @@ -355,7 +355,7 @@ class ExpAttribute : public Expression { const VType*probe_type(Entity*ent, ScopeBase*scope) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); // Some attributes can be evaluated at compile time bool evaluate(ScopeBase*scope, int64_t&val) const; @@ -378,7 +378,7 @@ class ExpBitstring : public Expression { const VType*fit_type(Entity*ent, ScopeBase*scope, const VTypeArray*atype) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; @@ -398,7 +398,7 @@ class ExpCharacter : public Expression { const VType*fit_type(Entity*ent, ScopeBase*scope, const VTypeArray*atype) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); bool is_primary(void) const; void dump(ostream&out, int indent = 0) const; @@ -426,7 +426,7 @@ class ExpConcat : public Expression { const VType*probe_type(Entity*ent, ScopeBase*scope) const; const VType*fit_type(Entity*ent, ScopeBase*scope, const VTypeArray*atype) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); virtual bool evaluate(ScopeBase*scope, int64_t&val) const; bool is_primary(void) const; @@ -473,7 +473,7 @@ class ExpConditional : public Expression { const VType*probe_type(Entity*ent, ScopeBase*scope) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; @@ -500,7 +500,7 @@ class ExpEdge : public ExpUnary { inline fun_t edge_fun() const { return fun_; } - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; @@ -524,7 +524,7 @@ class ExpFunc : public Expression { public: // Base methods int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; @@ -545,7 +545,7 @@ class ExpInteger : public Expression { const VType*probe_type(Entity*ent, ScopeBase*scope) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); int emit_package(std::ostream&out); bool is_primary(void) const { return true; } @@ -568,7 +568,7 @@ class ExpReal : public Expression { const VType*probe_type(Entity*ent, ScopeBase*scope) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); int emit_package(std::ostream&out); bool is_primary(void) const; @@ -595,7 +595,7 @@ class ExpLogical : public ExpBinary { inline fun_t logic_fun() const { return fun_; } int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; @@ -628,7 +628,7 @@ class ExpName : public Expression { const VType* probe_type(Entity*ent, ScopeBase*scope) const; const VType* fit_type(Entity*ent, ScopeBase*scope, const VTypeArray*host) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); bool is_primary(void) const; bool evaluate(ScopeBase*scope, int64_t&val) const; @@ -684,7 +684,7 @@ class ExpRelation : public ExpBinary { const VType* probe_type(Entity*ent, ScopeBase*scope) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; @@ -703,7 +703,7 @@ class ExpString : public Expression { const VType*fit_type(Entity*ent, ScopeBase*scope, const VTypeArray*atype) const; int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); bool is_primary(void) const; void dump(ostream&out, int indent = 0) const; @@ -724,7 +724,7 @@ class ExpUAbs : public ExpUnary { Expression*clone() const { return new ExpUAbs(peek_operand()->clone()); } - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; }; @@ -738,7 +738,7 @@ class ExpUNot : public ExpUnary { Expression*clone() const { return new ExpUNot(peek_operand()->clone()); } int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype); - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; }; @@ -757,7 +757,7 @@ class ExpCast : public Expression { inline int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*) { return base_->elaborate_expr(ent, scope, type_); } - void write_to_stream(std::ostream&fd); + void write_to_stream(std::ostream&fd) const; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; @@ -779,7 +779,7 @@ class ExpNew : public Expression { Expression*clone() const { return new ExpNew(size_->clone()); } // There is no 'new' in VHDL - do not emit anything - void write_to_stream(std::ostream&) {}; + void write_to_stream(std::ostream&) const {}; int emit(ostream&out, Entity*ent, ScopeBase*scope); void dump(ostream&out, int indent = 0) const; diff --git a/vhdlpp/expression_stream.cc b/vhdlpp/expression_stream.cc index 80864265e..992415df0 100644 --- a/vhdlpp/expression_stream.cc +++ b/vhdlpp/expression_stream.cc @@ -24,7 +24,7 @@ using namespace std; -void ExpAggregate::write_to_stream(ostream&fd) +void ExpAggregate::write_to_stream(ostream&fd) const { fd << "("; for (vector::const_iterator cur = elements_.begin() @@ -73,7 +73,7 @@ void ExpAggregate::choice_t::write_to_stream(ostream&fd) fd << "/* ERROR */"; } -void ExpArithmetic::write_to_stream(ostream&out) +void ExpArithmetic::write_to_stream(ostream&out) const { out << "("; write_to_stream_operand1(out); @@ -111,13 +111,13 @@ void ExpArithmetic::write_to_stream(ostream&out) out << ")"; } -void ExpAttribute::write_to_stream(ostream&fd) +void ExpAttribute::write_to_stream(ostream&fd) const { base_->write_to_stream(fd); fd << "'" << name_; } -void ExpBitstring::write_to_stream(ostream&fd) +void ExpBitstring::write_to_stream(ostream&fd) const { fd << "\""; for(vector::const_iterator it = value_.begin(); @@ -127,7 +127,7 @@ void ExpBitstring::write_to_stream(ostream&fd) fd << "\""; } -void ExpCharacter::write_to_stream(ostream&fd) +void ExpCharacter::write_to_stream(ostream&fd) const { char buf[4]; buf[0] = '\''; @@ -137,7 +137,7 @@ void ExpCharacter::write_to_stream(ostream&fd) fd << buf; } -void ExpConcat::write_to_stream(ostream&fd) +void ExpConcat::write_to_stream(ostream&fd) const { fd << "("; operand1_->write_to_stream(fd); @@ -146,21 +146,21 @@ void ExpConcat::write_to_stream(ostream&fd) fd << ")"; } -void ExpConditional::write_to_stream(ostream&) +void ExpConditional::write_to_stream(ostream&) const { ivl_assert(*this, !"Not supported"); } -void ExpEdge::write_to_stream(ostream&) +void ExpEdge::write_to_stream(ostream&) const { ivl_assert(*this, !"Not supported"); } -void ExpFunc::write_to_stream(ostream&fd) +void ExpFunc::write_to_stream(ostream&fd) const { const char*comma = ""; fd << name_ << "("; - for (vector::iterator cur = argv_.begin() + for (vector::const_iterator cur = argv_.begin() ; cur != argv_.end() ; ++cur) { fd << comma; (*cur)->write_to_stream(fd); @@ -169,22 +169,22 @@ void ExpFunc::write_to_stream(ostream&fd) fd << ")"; } -void ExpInteger::write_to_stream(ostream&fd) +void ExpInteger::write_to_stream(ostream&fd) const { fd << value_; } -void ExpReal::write_to_stream(ostream&fd) +void ExpReal::write_to_stream(ostream&fd) const { fd << value_; } -void ExpLogical::write_to_stream(ostream&) +void ExpLogical::write_to_stream(ostream&) const { ivl_assert(*this, !"Not supported"); } -void ExpName::write_to_stream(ostream&fd) +void ExpName::write_to_stream(ostream&fd) const { if (prefix_.get()) { prefix_->write_to_stream(fd); @@ -203,12 +203,12 @@ void ExpName::write_to_stream(ostream&fd) } } -void ExpRelation::write_to_stream(ostream&) +void ExpRelation::write_to_stream(ostream&) const { ivl_assert(*this, !"Not supported"); } -void ExpString::write_to_stream(ostream&fd) +void ExpString::write_to_stream(ostream&fd) const { fd << "\""; for(vector::const_iterator it = value_.begin(); @@ -218,19 +218,19 @@ void ExpString::write_to_stream(ostream&fd) fd << "\""; } -void ExpUAbs::write_to_stream(ostream&fd) +void ExpUAbs::write_to_stream(ostream&fd) const { fd << "abs "; write_to_stream_operand1(fd); } -void ExpUNot::write_to_stream(ostream&fd) +void ExpUNot::write_to_stream(ostream&fd) const { fd << "not "; write_to_stream_operand1(fd); } -void ExpCast::write_to_stream(ostream&fd) +void ExpCast::write_to_stream(ostream&fd) const { // Type casting is introduced only for a few specific cases in // SystemVerilog, so no need to use it here