vhdlpp: Escape quotation marks in emitted strings.
This commit is contained in:
parent
6f5addb1b7
commit
925827d2c2
|
|
@ -415,12 +415,8 @@ void ExpRelation::dump(ostream&out, int indent) const
|
||||||
|
|
||||||
void ExpString::dump(ostream&out, int indent) const
|
void ExpString::dump(ostream&out, int indent) const
|
||||||
{
|
{
|
||||||
out << setw(indent) << "" << "String \"";
|
out << setw(indent) << "" << "String \"" << value_;
|
||||||
for(vector<char>::const_iterator it = value_.begin();
|
out << "\"" << " at " << get_fileline() << endl;
|
||||||
it != value_.end(); ++it)
|
|
||||||
out << *it;
|
|
||||||
out << "\""
|
|
||||||
<< " at " << get_fileline() << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpUAbs::dump(ostream&out, int indent) const
|
void ExpUAbs::dump(ostream&out, int indent) const
|
||||||
|
|
|
||||||
|
|
@ -632,10 +632,8 @@ ExpShift::ExpShift(ExpShift::shift_t op, Expression*op1, Expression*op2)
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpString::ExpString(const char* value)
|
ExpString::ExpString(const char* value)
|
||||||
: value_(strlen(value))
|
: value_(value)
|
||||||
{
|
{
|
||||||
for(size_t idx = 0; idx < value_.size(); idx += 1)
|
|
||||||
value_[idx] = value[idx];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpString::~ExpString()
|
ExpString::~ExpString()
|
||||||
|
|
|
||||||
|
|
@ -796,13 +796,17 @@ class ExpString : public Expression {
|
||||||
int emit(ostream&out, Entity*ent, ScopeBase*scope);
|
int emit(ostream&out, Entity*ent, ScopeBase*scope);
|
||||||
bool is_primary(void) const;
|
bool is_primary(void) const;
|
||||||
void dump(ostream&out, int indent = 0) const;
|
void dump(ostream&out, int indent = 0) const;
|
||||||
const std::vector<char>& get_value() const { return value_; }
|
const std::string& get_value() const { return value_; }
|
||||||
|
|
||||||
|
// Converts quotation marks (") to its escaped
|
||||||
|
// counterpart in SystemVerilog (\")
|
||||||
|
static std::string escape_quot(const std::string& str);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int emit_as_array_(ostream&out, Entity*ent, ScopeBase*scope, const VTypeArray*arr);
|
int emit_as_array_(ostream&out, Entity*ent, ScopeBase*scope, const VTypeArray*arr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<char> value_;
|
std::string value_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExpUAbs : public ExpUnary {
|
class ExpUAbs : public ExpUnary {
|
||||||
|
|
|
||||||
|
|
@ -916,11 +916,8 @@ int ExpString::emit(ostream& out, Entity*ent, ScopeBase*scope)
|
||||||
return emit_as_array_(out, ent, scope, arr);
|
return emit_as_array_(out, ent, scope, arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "\"";
|
out << "\"" << escape_quot(value_) << "\"";
|
||||||
for(vector<char>::const_iterator it = value_.begin()
|
|
||||||
; it != value_.end(); ++it)
|
|
||||||
out << *it;
|
|
||||||
out << "\"";
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -959,6 +956,19 @@ int ExpString::emit_as_array_(ostream& out, Entity*, ScopeBase*, const VTypeArra
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ExpString::escape_quot(const std::string& str)
|
||||||
|
{
|
||||||
|
size_t idx = 0;
|
||||||
|
string result(str);
|
||||||
|
|
||||||
|
while((idx = result.find('"', idx)) != string::npos) {
|
||||||
|
result.replace(idx, 1, "\\\"");
|
||||||
|
idx += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int ExpUAbs::emit(ostream&out, Entity*ent, ScopeBase*scope)
|
int ExpUAbs::emit(ostream&out, Entity*ent, ScopeBase*scope)
|
||||||
{
|
{
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
|
|
|
||||||
|
|
@ -272,10 +272,15 @@ void ExpShift::write_to_stream(ostream&out) const
|
||||||
void ExpString::write_to_stream(ostream&fd) const
|
void ExpString::write_to_stream(ostream&fd) const
|
||||||
{
|
{
|
||||||
fd << "\"";
|
fd << "\"";
|
||||||
for(vector<char>::const_iterator it = value_.begin();
|
|
||||||
it != value_.end(); ++it) {
|
// Restore double quotation marks
|
||||||
fd << *it;
|
for(string::const_iterator it = value_.begin(); it != value_.end(); ++it) {
|
||||||
|
if(*it == '"')
|
||||||
|
fd << "\"\"";
|
||||||
|
else
|
||||||
|
fd << *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd << "\"";
|
fd << "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -484,7 +484,7 @@ int ReportStmt::emit(ostream&out, Entity*, ScopeBase*)
|
||||||
case UNSPECIFIED: ivl_assert(*this, false); break;
|
case UNSPECIFIED: ivl_assert(*this, false); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out << msg_;
|
out << ExpString::escape_quot(msg_);
|
||||||
out << " (" << get_fileline() << ")\");";
|
out << " (" << get_fileline() << ")\");";
|
||||||
|
|
||||||
if(severity_ == FAILURE)
|
if(severity_ == FAILURE)
|
||||||
|
|
@ -497,7 +497,7 @@ int ReportStmt::emit(ostream&out, Entity*, ScopeBase*)
|
||||||
|
|
||||||
void ReportStmt::write_to_stream(std::ostream&fd)
|
void ReportStmt::write_to_stream(std::ostream&fd)
|
||||||
{
|
{
|
||||||
fd << "report \"" << msg_ << "\"" << std::endl;
|
fd << "report \"" << ExpString::escape_quot(msg_) << "\"" << std::endl;
|
||||||
|
|
||||||
fd << "severity ";
|
fd << "severity ";
|
||||||
switch(severity_)
|
switch(severity_)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue