aboutsummaryrefslogtreecommitdiffstats
path: root/Types.h
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-10-16 23:57:27 +0800
committerChristian <c@ethdev.com>2014-10-23 22:27:51 +0800
commita09e4c559d5631a0661b34d0f260612eac0c6e81 (patch)
tree7cb32617b4bfab8496ffd1dbe8478290b1ff49ed /Types.h
parentfd046d7c9088498fbb0bded6a8ca69554155f483 (diff)
downloaddexon-solidity-a09e4c559d5631a0661b34d0f260612eac0c6e81.tar.gz
dexon-solidity-a09e4c559d5631a0661b34d0f260612eac0c6e81.tar.zst
dexon-solidity-a09e4c559d5631a0661b34d0f260612eac0c6e81.zip
Type information for AST printer.
Diffstat (limited to 'Types.h')
-rw-r--r--Types.h31
1 files changed, 24 insertions, 7 deletions
diff --git a/Types.h b/Types.h
index e0c09bdc..82b54943 100644
--- a/Types.h
+++ b/Types.h
@@ -59,6 +59,8 @@ public:
}
virtual bool acceptsBinaryOperator(Token::Value) const { return false; }
virtual bool acceptsUnaryOperator(Token::Value) const { return false; }
+
+ virtual std::string toString() const = 0;
};
class IntegerType: public Type
@@ -68,7 +70,7 @@ public:
{
UNSIGNED, SIGNED, HASH, ADDRESS
};
- virtual Category getCategory() const { return Category::INTEGER; }
+ virtual Category getCategory() const override { return Category::INTEGER; }
static std::shared_ptr<IntegerType> smallestTypeForLiteral(std::string const& _literal);
@@ -79,6 +81,8 @@ public:
virtual bool acceptsBinaryOperator(Token::Value _operator) const override;
virtual bool acceptsUnaryOperator(Token::Value _operator) const override;
+ virtual std::string toString() const override;
+
int getNumBits() const { return m_bits; }
bool isHash() const { return m_modifier == Modifier::HASH || m_modifier == Modifier::ADDRESS; }
bool isAddress() const { return m_modifier == Modifier::ADDRESS; }
@@ -106,15 +110,18 @@ public:
{
return _operator == Token::NOT || _operator == Token::DELETE;
}
+ virtual std::string toString() const override { return "bool"; }
};
class ContractType: public Type
{
public:
- virtual Category getCategory() const { return Category::CONTRACT; }
+ virtual Category getCategory() const override { return Category::CONTRACT; }
ContractType(ContractDefinition const& _contract): m_contract(_contract) {}
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const;
+ virtual std::string toString() const override { return "contract{...}"; }
+
private:
ContractDefinition const& m_contract;
};
@@ -122,7 +129,7 @@ private:
class StructType: public Type
{
public:
- virtual Category getCategory() const { return Category::STRUCT; }
+ virtual Category getCategory() const override { return Category::STRUCT; }
StructType(StructDefinition const& _struct): m_struct(_struct) {}
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const;
virtual bool acceptsUnaryOperator(Token::Value _operator) const override
@@ -130,6 +137,9 @@ public:
return _operator == Token::DELETE;
}
+
+ virtual std::string toString() const override { return "struct{...}"; }
+
private:
StructDefinition const& m_struct;
};
@@ -137,11 +147,13 @@ private:
class FunctionType: public Type
{
public:
- virtual Category getCategory() const { return Category::FUNCTION; }
+ virtual Category getCategory() const override { return Category::FUNCTION; }
FunctionType(FunctionDefinition const& _function): m_function(_function) {}
FunctionDefinition const& getFunction() const { return m_function; }
+ virtual std::string toString() const override { return "function(...)returns(...)"; }
+
private:
FunctionDefinition const& m_function;
};
@@ -149,8 +161,10 @@ private:
class MappingType: public Type
{
public:
- virtual Category getCategory() const { return Category::MAPPING; }
+ virtual Category getCategory() const override { return Category::MAPPING; }
MappingType() {}
+ virtual std::string toString() const override { return "mapping(...=>...)"; }
+
private:
//@todo
};
@@ -159,18 +173,21 @@ private:
class VoidType: public Type
{
public:
- virtual Category getCategory() const { return Category::VOID; }
+ virtual Category getCategory() const override { return Category::VOID; }
VoidType() {}
+ virtual std::string toString() const override { return "void"; }
};
class TypeType: public Type
{
public:
- virtual Category getCategory() const { return Category::TYPE; }
+ virtual Category getCategory() const override { return Category::TYPE; }
TypeType(std::shared_ptr<Type const> const& _actualType): m_actualType(_actualType) {}
std::shared_ptr<Type const> const& getActualType() const { return m_actualType; }
+ virtual std::string toString() const override { return "type(" + m_actualType->toString() + ")"; }
+
private:
std::shared_ptr<Type const> m_actualType;
};