Use new escaping helpers for type identifiers

This commit is contained in:
Alex Beregszaszi 2018-02-24 01:13:34 +01:00
parent 2e7067fbe4
commit b471983e3c
2 changed files with 9 additions and 20 deletions

View File

@ -131,28 +131,28 @@ namespace
string parenthesizeIdentifier(string const& _internal) string parenthesizeIdentifier(string const& _internal)
{ {
return "$_" + _internal + "_$"; return "(" + _internal + ")";
} }
template <class Range> template <class Range>
string identifierList(Range const&& _list) string identifierList(Range const&& _list)
{ {
return parenthesizeIdentifier(boost::algorithm::join(_list, "_$_")); return parenthesizeIdentifier(boost::algorithm::join(_list, ","));
} }
string identifier(TypePointer const& _type) string richIdentifier(TypePointer const& _type)
{ {
return _type ? _type->identifier() : ""; return _type ? _type->richIdentifier() : "";
} }
string identifierList(vector<TypePointer> const& _list) string identifierList(vector<TypePointer> const& _list)
{ {
return identifierList(_list | boost::adaptors::transformed(identifier)); return identifierList(_list | boost::adaptors::transformed(richIdentifier));
} }
string identifierList(TypePointer const& _type) string identifierList(TypePointer const& _type)
{ {
return parenthesizeIdentifier(identifier(_type)); return parenthesizeIdentifier(richIdentifier(_type));
} }
string identifierList(TypePointer const& _type1, TypePointer const& _type2) string identifierList(TypePointer const& _type1, TypePointer const& _type2)
@ -165,7 +165,7 @@ string identifierList(TypePointer const& _type1, TypePointer const& _type2)
string parenthesizeUserIdentifier(string const& _internal) string parenthesizeUserIdentifier(string const& _internal)
{ {
return parenthesizeIdentifier(boost::algorithm::replace_all_copy(_internal, "$", "$$$")); return parenthesizeIdentifier(_internal);
} }
} }
@ -173,23 +173,14 @@ string parenthesizeUserIdentifier(string const& _internal)
string Type::escapeIdentifier(string const& _identifier) string Type::escapeIdentifier(string const& _identifier)
{ {
string ret = _identifier; string ret = _identifier;
boost::algorithm::replace_all(ret, "$", "_$$$_"); // FIXME: should be _$$$_
boost::algorithm::replace_all(ret, "$", "$$$");
boost::algorithm::replace_all(ret, ",", "_$_"); boost::algorithm::replace_all(ret, ",", "_$_");
boost::algorithm::replace_all(ret, "(", "$_"); boost::algorithm::replace_all(ret, "(", "$_");
boost::algorithm::replace_all(ret, ")", "_$"); boost::algorithm::replace_all(ret, ")", "_$");
return ret; return ret;
} }
string Type::unescapeIdentifier(string const& _identifier)
{
string ret = _identifier;
boost::algorithm::replace_all(ret, "_$_", ",");
boost::algorithm::replace_all(ret, "_$$$_", "$");
boost::algorithm::replace_all(ret, "$_", "(");
boost::algorithm::replace_all(ret, "_$", ")");
return ret;
}
TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type) TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type)
{ {
solAssert(Token::isElementaryTypeName(_type.token()), solAssert(Token::isElementaryTypeName(_type.token()),

View File

@ -176,8 +176,6 @@ public:
/// appears as part of a user-supplied identifier is escaped as _$$$_. /// appears as part of a user-supplied identifier is escaped as _$$$_.
/// @returns an escaped identifier (will not contain any parenthesis or commas) /// @returns an escaped identifier (will not contain any parenthesis or commas)
static std::string escapeIdentifier(std::string const& _identifier); static std::string escapeIdentifier(std::string const& _identifier);
/// @returns an unescaped identifier
static std::string unescapeIdentifier(std::string const& _identifier);
virtual bool isImplicitlyConvertibleTo(Type const& _other) const { return *this == _other; } virtual bool isImplicitlyConvertibleTo(Type const& _other) const { return *this == _other; }
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const