mirror of https://github.com/YosysHQ/yosys.git
functional backends: identifiers in c++/smtlib may not start with digits
This commit is contained in:
parent
459e6b913a
commit
b428bf4600
|
@ -48,8 +48,8 @@ template<typename Id> struct CxxScope : public Functional::Scope<Id> {
|
|||
for(const char **p = reserved_keywords; *p != nullptr; p++)
|
||||
this->reserve(*p);
|
||||
}
|
||||
bool is_character_legal(char c) override {
|
||||
return isascii(c) && (isalnum(c) || c == '_' || c == '$');
|
||||
bool is_character_legal(char c, int index) override {
|
||||
return isascii(c) && (isalpha(c) || (isdigit(c) && index > 0) || c == '_' || c == '$');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ struct SmtScope : public Functional::Scope<int> {
|
|||
for(const char **p = reserved_keywords; *p != nullptr; p++)
|
||||
reserve(*p);
|
||||
}
|
||||
bool is_character_legal(char c) override {
|
||||
return isascii(c) && (isalnum(c) || strchr("~!@$%^&*_-+=<>.?/", c));
|
||||
bool is_character_legal(char c, int index) override {
|
||||
return isascii(c) && (isalpha(c) || (isdigit(c) && index > 0) || strchr("~!@$%^&*_-+=<>.?/", c));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -576,7 +576,7 @@ namespace Functional {
|
|||
template<class Id> class Scope {
|
||||
protected:
|
||||
char substitution_character = '_';
|
||||
virtual bool is_character_legal(char) = 0;
|
||||
virtual bool is_character_legal(char, int) = 0;
|
||||
private:
|
||||
pool<std::string> _used_names;
|
||||
dict<Id, std::string> _by_id;
|
||||
|
@ -587,7 +587,7 @@ namespace Functional {
|
|||
std::string unique_name(IdString suggestion) {
|
||||
std::string str = RTLIL::unescape_id(suggestion);
|
||||
for(size_t i = 0; i < str.size(); i++)
|
||||
if(!is_character_legal(str[i]))
|
||||
if(!is_character_legal(str[i], i))
|
||||
str[i] = substitution_character;
|
||||
if(_used_names.count(str) == 0) {
|
||||
_used_names.insert(str);
|
||||
|
|
Loading…
Reference in New Issue