diff options
author | chriseth <c@ethdev.com> | 2015-04-15 23:40:50 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-04-15 23:40:50 +0800 |
commit | 0c69d5fdcd3286f47c81dbcbcfb8802861eab8b5 (patch) | |
tree | f78c665e6084300b939cc4cfcebb97d3bd44d9f5 /AST.h | |
parent | 158795e48f4285d713b11f78cdd04de8c6d1f667 (diff) | |
download | dexon-solidity-0c69d5fdcd3286f47c81dbcbcfb8802861eab8b5.tar.gz dexon-solidity-0c69d5fdcd3286f47c81dbcbcfb8802861eab8b5.tar.zst dexon-solidity-0c69d5fdcd3286f47c81dbcbcfb8802861eab8b5.zip |
Fixed function overloads.
Added tests, disallowed non-calling usage of non-unique function
references.
Diffstat (limited to 'AST.h')
-rw-r--r-- | AST.h | 63 |
1 files changed, 42 insertions, 21 deletions
@@ -282,8 +282,14 @@ public: FunctionDefinition const* getFallbackFunction() const; private: + /// Checks that two functions defined in this contract with the same name have different + /// arguments and that there is at most one constructor. + void checkDuplicateFunctions() const; void checkIllegalOverrides() const; void checkAbstractFunctions(); + /// Checks that different functions with external visibility end up having different + /// external argument types (i.e. different signature). + void checkExternalTypeClashes() const; std::vector<std::pair<FixedHash<4>, FunctionTypePointer>> const& getInterfaceFunctionList() const; @@ -967,7 +973,10 @@ class Expression: public ASTNode { public: Expression(SourceLocation const& _location): ASTNode(_location) {} - virtual void checkTypeRequirements() = 0; + /// Performs type checking after which m_type should be set. + /// @arg _argumentTypes if set, provides the argument types for the case that this expression + /// is used in the context of a call, used for function overload resolution. + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) = 0; std::shared_ptr<Type const> const& getType() const { return m_type; } bool isLValue() const { return m_isLValue; } @@ -1006,7 +1015,7 @@ public: } virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual void checkTypeRequirements() override; + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) override; Expression const& getLeftHandSide() const { return *m_leftHandSide; } Token::Value getAssignmentOperator() const { return m_assigmentOperator; } @@ -1034,7 +1043,7 @@ public: } virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual void checkTypeRequirements() override; + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) override; Token::Value getOperator() const { return m_operator; } bool isPrefixOperation() const { return m_isPrefix; } @@ -1061,7 +1070,7 @@ public: } virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual void checkTypeRequirements() override; + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) override; Expression const& getLeftExpression() const { return *m_left; } Expression const& getRightExpression() const { return *m_right; } @@ -1089,7 +1098,7 @@ public: Expression(_location), m_expression(_expression), m_arguments(_arguments), m_names(_names) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual void checkTypeRequirements() override; + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) override; Expression const& getExpression() const { return *m_expression; } std::vector<ASTPointer<Expression const>> getArguments() const { return {m_arguments.begin(), m_arguments.end()}; } @@ -1115,7 +1124,7 @@ public: Expression(_location), m_contractName(_contractName) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual void checkTypeRequirements() override; + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) override; /// Returns the referenced contract. Can only be called after type checking. ContractDefinition const* getContract() const { solAssert(m_contract, ""); return m_contract; } @@ -1139,11 +1148,18 @@ public: virtual void accept(ASTConstVisitor& _visitor) const override; Expression const& getExpression() const { return *m_expression; } ASTString const& getMemberName() const { return *m_memberName; } - virtual void checkTypeRequirements() override; + /// @returns the declaration referenced by this expression. Might return nullptr even if the + /// expression is valid, e.g. if the member does not correspond to an AST node. + Declaration const* referencedDeclaration() const { return m_referencedDeclaration; } + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) override; private: ASTPointer<Expression> m_expression; ASTPointer<ASTString> m_memberName; + + /// Pointer to the referenced declaration, this is sometimes needed to resolve function over + /// loads in the type-checking phase. + Declaration const* m_referencedDeclaration = nullptr; }; /** @@ -1157,7 +1173,7 @@ public: Expression(_location), m_base(_base), m_index(_index) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual void checkTypeRequirements() override; + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) override; Expression const& getBaseExpression() const { return *m_base; } Expression const* getIndexExpression() const { return m_index.get(); } @@ -1187,28 +1203,33 @@ public: PrimaryExpression(_location), m_name(_name) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual void checkTypeRequirements() override; + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) override; ASTString const& getName() const { return *m_name; } - void setReferencedDeclaration(Declaration const& _referencedDeclaration, - ContractDefinition const* _currentContract = nullptr) + void setReferencedDeclaration( + Declaration const& _referencedDeclaration, + ContractDefinition const* _currentContract = nullptr + ) { m_referencedDeclaration = &_referencedDeclaration; m_currentContract = _currentContract; } - Declaration const* getReferencedDeclaration() const { return m_referencedDeclaration; } - ContractDefinition const* getCurrentContract() const { return m_currentContract; } + Declaration const& getReferencedDeclaration() const; - void setOverloadedDeclarations(std::set<Declaration const*> const& _declarations) { m_overloadedDeclarations = _declarations; } - std::set<Declaration const*> getOverloadedDeclarations() const { return m_overloadedDeclarations; } + /// Stores a set of possible declarations referenced by this identifier. Has to be resolved + /// providing argument types using overloadResolution before the referenced declaration + /// is accessed. + void setOverloadedDeclarations(std::set<Declaration const*> const& _declarations) + { + m_overloadedDeclarations = _declarations; + } - void checkTypeRequirementsWithFunctionCall(FunctionCall const& _functionCall); - void checkTypeRequirementsFromVariableDeclaration(); + /// Tries to find exactly one of the possible referenced declarations provided the given + /// argument types in a call context. + void overloadResolution(TypePointers const& _argumentTypes); - Declaration const* overloadResolution(FunctionCall const& _functionCall); private: - ASTPointer<ASTString> m_name; /// Declaration the name refers to. @@ -1235,7 +1256,7 @@ public: } virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual void checkTypeRequirements() override; + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) override; Token::Value getTypeToken() const { return m_typeToken; } @@ -1269,7 +1290,7 @@ public: PrimaryExpression(_location), m_token(_token), m_value(_value), m_subDenomination(_sub) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual void checkTypeRequirements() override; + virtual void checkTypeRequirements(TypePointers const* _argumentTypes) override; Token::Value getToken() const { return m_token; } /// @returns the non-parsed value of the literal |