aboutsummaryrefslogtreecommitdiffstats
path: root/Types.h
diff options
context:
space:
mode:
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 8e2f4803..c96d0bb1 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