vhdlpp: Support for unary sign operator.

This commit is contained in:
Maciej Suminski 2016-06-14 18:31:53 +02:00
parent 9e95ae5859
commit 798adc9863
6 changed files with 48 additions and 9 deletions

View File

@ -818,6 +818,15 @@ ExpUNot::~ExpUNot()
{ {
} }
ExpUMinus::ExpUMinus(Expression*op1)
: ExpUnary(op1)
{
}
ExpUMinus::~ExpUMinus()
{
}
ExpCast::ExpCast(Expression*base, const VType*type) : ExpCast::ExpCast(Expression*base, const VType*type) :
base_(base), type_(type) base_(base), type_(type)
{ {

View File

@ -948,6 +948,19 @@ class ExpUNot : public ExpUnary {
void dump(ostream&out, int indent = 0) const; void dump(ostream&out, int indent = 0) const;
}; };
class ExpUMinus : public ExpUnary {
public:
explicit ExpUMinus(Expression*op1);
~ExpUMinus();
Expression*clone() const { return new ExpUMinus(peek_operand()->clone()); }
void write_to_stream(std::ostream&fd) const;
int emit(ostream&out, Entity*ent, ScopeBase*scope) const;
void dump(ostream&out, int indent = 0) const;
};
/* /*
* Class that wraps other expressions to cast them to other types. * Class that wraps other expressions to cast them to other types.
*/ */

View File

@ -142,6 +142,12 @@ void ExpUNot::dump(ostream&out, int indent) const
dump_operand1(out, indent+4); dump_operand1(out, indent+4);
} }
void ExpUMinus::dump(ostream&out, int indent) const
{
out << setw(indent) << "" << "unary_minus() at " << get_fileline() << endl;
dump_operand1(out, indent+4);
}
void ExpTime::dump(ostream&out, int indent) const void ExpTime::dump(ostream&out, int indent) const
{ {
out << setw(indent) << "" << "Time "; out << setw(indent) << "" << "Time ";

View File

@ -1048,6 +1048,15 @@ int ExpUNot::emit(ostream&out, Entity*ent, ScopeBase*scope) const
return errors; return errors;
} }
int ExpUMinus::emit(ostream&out, Entity*ent, ScopeBase*scope) const
{
int errors = 0;
out << "-(";
errors += emit_operand1(out, ent, scope);
out << ")";
return errors;
}
int ExpCast::emit(ostream&out, Entity*ent, ScopeBase*scope) const int ExpCast::emit(ostream&out, Entity*ent, ScopeBase*scope) const
{ {
int errors = 0; int errors = 0;

View File

@ -327,6 +327,13 @@ void ExpUNot::write_to_stream(ostream&fd) const
write_to_stream_operand1(fd); write_to_stream_operand1(fd);
} }
void ExpUMinus::write_to_stream(ostream&fd) const
{
fd << "-(";
write_to_stream_operand1(fd);
fd << ")";
}
void ExpCast::write_to_stream(ostream&fd) const void ExpCast::write_to_stream(ostream&fd) const
{ {
// Type casting is introduced only for a few specific cases in // Type casting is introduced only for a few specific cases in

View File

@ -2484,11 +2484,6 @@ shift_expression
} }
; ;
sign
: '+'
| '-'
;
signal_declaration_assign_opt signal_declaration_assign_opt
: VASSIGN expression { $$ = $2; } : VASSIGN expression { $$ = $2; }
| { $$ = 0; } | { $$ = 0; }
@ -2514,10 +2509,10 @@ signal_declaration_assign_opt
* list fixes up the associations. * list fixes up the associations.
*/ */
simple_expression simple_expression
: sign simple_expression_2 : '-' simple_expression_2
{ sorrymsg(@1, "Unary expression +- not supported.\n"); { $$ = new ExpUMinus($2); }
$$ = $2; | '+' simple_expression_2
} { $$ = $2; }
| simple_expression_2 | simple_expression_2
{ $$ = $1; } { $$ = $1; }
; ;