aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-02-24 01:27:27 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-02-27 02:09:39 +0800
commit751705978e346b372e9aa1242c78e32892fae985 (patch)
treed783c4e2924e3c042abe7abddc01771ad51f59de /libsolidity/ast
parent272262ea9908f2c8a12e0a8e367393f2a49ba3ca (diff)
downloaddexon-solidity-751705978e346b372e9aa1242c78e32892fae985.tar.gz
dexon-solidity-751705978e346b372e9aa1242c78e32892fae985.tar.zst
dexon-solidity-751705978e346b372e9aa1242c78e32892fae985.zip
Add helpers escapeIdentifier to Types
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/Types.cpp20
-rw-r--r--libsolidity/ast/Types.h8
2 files changed, 27 insertions, 1 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index e4b7e4fd..bf5745a6 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -170,6 +170,26 @@ string parenthesizeUserIdentifier(string const& _internal)
}
+string Type::escapeIdentifier(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;
+}
+
+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)
{
solAssert(Token::isElementaryTypeName(_type.token()),
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 2e7d05ba..ef898f37 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -163,10 +163,16 @@ public:
/// @returns a valid solidity identifier such that two types should compare equal if and
/// only if they have the same identifier.
/// The identifier should start with "t_".
+ virtual std::string identifier() const = 0;
+
/// More complex identifier strings use "parentheses", where $_ is interpreted as as
/// "opening parenthesis", _$ as "closing parenthesis", _$_ as "comma" and any $ that
/// appears as part of a user-supplied identifier is escaped as _$$$_.
- virtual std::string identifier() const = 0;
+ /// @returns an escaped identifier (will not contain any parenthesis or commas)
+ 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 isExplicitlyConvertibleTo(Type const& _convertTo) const
{