From f70ffa4f4b336215ce15ce4c4cc6c5b935cc5d7a Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 22 Jul 2020 11:53:35 +0200 Subject: [PATCH] WIP: error type --- libsolidity/ast/AST.h | 41 ++++++++++++++++++++++++++++++++ libsolidity/ast/ASTAnnotations.h | 5 ++++ libsolidity/ast/ASTForward.h | 1 + libsolidity/ast/Types.h | 11 ++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 34fefeb0a..a93161f47 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -594,6 +594,47 @@ private: ASTPointer m_typeName; }; +template +class CompositeType: public Declaration +{ +public: + CompositeType( + int64_t _id, + SourceLocation const& _location, + ASTPointer const& _name, + std::vector> _members + ): + Declaration(_id, _location, _name), m_members(std::move(_members)) {} + + void accept(ASTVisitor& _visitor) override; + void accept(ASTConstVisitor& _visitor) const override; + + std::vector> const& members() const { return m_members; } + + TypePointer type() const override + { + return TypeProvider::typeType(TypeProvider::errorType(*this, DataLocation::Storage)); + } + + bool isVisibleInDerivedContracts() const override { return true; } + bool isVisibleViaContractTypeAccess() const override { return true; } + + AnnotationT& annotation() const override; + +private: + std::vector> m_members; +}; +using ErrorDefinition = CompositeType; +TypePointer ErrorDefinition::type() const +{ +} + +ErrorDeclarationAnnotation& ErrorDefinition::annotation() const +{ + return initAnnotation(); +} + + class StructDefinition: public Declaration { public: diff --git a/libsolidity/ast/ASTAnnotations.h b/libsolidity/ast/ASTAnnotations.h index 507559ca6..1e65c00b0 100644 --- a/libsolidity/ast/ASTAnnotations.h +++ b/libsolidity/ast/ASTAnnotations.h @@ -138,6 +138,11 @@ struct StructDeclarationAnnotation: TypeDeclarationAnnotation std::optional recursive; }; +struct ErrorDeclarationAnnotation: TypeDeclarationAnnotation +{ + // currently no annotations +}; + struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, StructurallyDocumentedAnnotation { /// List of functions and modifiers without a body. Can also contain functions from base classes. diff --git a/libsolidity/ast/ASTForward.h b/libsolidity/ast/ASTForward.h index 38da35218..28c5915c9 100644 --- a/libsolidity/ast/ASTForward.h +++ b/libsolidity/ast/ASTForward.h @@ -47,6 +47,7 @@ class ContractDefinition; class InheritanceSpecifier; class UsingForDirective; class StructDefinition; +class ErrorDefinition; class EnumDefinition; class EnumValue; class ParameterList; diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 155fa7f14..498ca5ae2 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -171,11 +171,12 @@ public: enum class Category { Address, Integer, RationalNumber, StringLiteral, Bool, FixedPoint, Array, ArraySlice, - FixedBytes, Contract, Struct, Function, Enum, Tuple, + FixedBytes, Contract, Struct, Error, Function, Enum, Tuple, Mapping, TypeType, Modifier, Magic, Module, InaccessibleDynamic }; + /// @returns a pointer to _a or _b if the other is implicitly convertible to it or nullptr otherwise static TypePointer commonType(Type const* _a, Type const* _b); @@ -1002,6 +1003,14 @@ private: mutable std::optional m_interfaceType_library; }; +class ErrorType: public StructType +{ +public: + explicit ErrorType(ErrorDefinition const& _def): + StructType{_def, DataLocation::Memory} + {} +}; + /** * The type of an enum instance, there is one distinct type per enum definition. */