aboutsummaryrefslogtreecommitdiffstats
path: root/Types.h
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2014-12-13 00:14:43 +0800
committerchriseth <c@ethdev.com>2014-12-13 00:14:43 +0800
commit3860814fa0a50ea496926069c4144209fdccdc3a (patch)
tree24f211bcc3365b44abd87ced76ec44fd21280f94 /Types.h
parent6fcdfdc353cb4100f8a1a3c139e0fa9dc9302397 (diff)
parenta7352280790f1b88048b4879c46748d2082b1325 (diff)
downloaddexon-solidity-3860814fa0a50ea496926069c4144209fdccdc3a.tar
dexon-solidity-3860814fa0a50ea496926069c4144209fdccdc3a.tar.gz
dexon-solidity-3860814fa0a50ea496926069c4144209fdccdc3a.tar.bz2
dexon-solidity-3860814fa0a50ea496926069c4144209fdccdc3a.tar.lz
dexon-solidity-3860814fa0a50ea496926069c4144209fdccdc3a.tar.xz
dexon-solidity-3860814fa0a50ea496926069c4144209fdccdc3a.tar.zst
dexon-solidity-3860814fa0a50ea496926069c4144209fdccdc3a.zip
Merge pull request #584 from chriseth/sol_strings
String types.
Diffstat (limited to 'Types.h')
-rw-r--r--Types.h31
1 files changed, 30 insertions, 1 deletions
diff --git a/Types.h b/Types.h
index dd89f311..8e93bd31 100644
--- a/Types.h
+++ b/Types.h
@@ -36,7 +36,7 @@ namespace dev
namespace solidity
{
-// @todo realMxN, string<N>
+// @todo realMxN, dynamic strings, text, arrays
class Type; // forward
using TypePointer = std::shared_ptr<Type const>;
@@ -179,6 +179,35 @@ private:
};
/**
+ * String type with fixed length, up to 32 bytes.
+ */
+class StaticStringType: public Type
+{
+public:
+ virtual Category getCategory() const override { return Category::STRING; }
+
+ /// @returns the smallest string type for the given literal or an empty pointer
+ /// if no type fits.
+ static std::shared_ptr<StaticStringType> smallestTypeForLiteral(std::string const& _literal);
+
+ StaticStringType(int _bytes);
+
+ virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;
+ virtual bool operator==(Type const& _other) const override;
+
+ virtual unsigned getCalldataEncodedSize() const override { return m_bytes; }
+ virtual bool isValueType() const override { return true; }
+
+ virtual std::string toString() const override { return "string" + dev::toString(m_bytes); }
+ virtual u256 literalValue(Literal const& _literal) const override;
+
+ int getNumBytes() const { return m_bytes; }
+
+private:
+ int m_bytes;
+};
+
+/**
* The boolean type.
*/
class BoolType: public Type