mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'ethereum/develop' into sol_contractCompiler
Conflicts: libsolidity/AST.cpp libsolidity/AST.h libsolidity/Compiler.cpp libsolidity/Compiler.h libsolidity/NameAndTypeResolver.h libsolidity/Types.cpp solc/main.cpp test/solidityCompiler.cpp
This commit is contained in:
commit
25c0e08bdf
150
AST.h
150
AST.h
@ -41,9 +41,11 @@ namespace solidity
|
|||||||
class ASTVisitor;
|
class ASTVisitor;
|
||||||
|
|
||||||
|
|
||||||
/// The root (abstract) class of the AST inheritance tree.
|
/**
|
||||||
/// It is possible to traverse all direct and indirect children of an AST node by calling
|
* The root (abstract) class of the AST inheritance tree.
|
||||||
/// accept, providing an ASTVisitor.
|
* It is possible to traverse all direct and indirect children of an AST node by calling
|
||||||
|
* accept, providing an ASTVisitor.
|
||||||
|
*/
|
||||||
class ASTNode: private boost::noncopyable
|
class ASTNode: private boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -77,7 +79,9 @@ private:
|
|||||||
Location m_location;
|
Location m_location;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Abstract AST class for a declaration (contract, function, struct, variable).
|
/**
|
||||||
|
* Abstract AST class for a declaration (contract, function, struct, variable).
|
||||||
|
*/
|
||||||
class Declaration: public ASTNode
|
class Declaration: public ASTNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -85,15 +89,17 @@ public:
|
|||||||
ASTNode(_location), m_name(_name) {}
|
ASTNode(_location), m_name(_name) {}
|
||||||
|
|
||||||
/// Returns the declared name.
|
/// Returns the declared name.
|
||||||
const ASTString& getName() const { return *m_name; }
|
ASTString const& getName() const { return *m_name; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ASTPointer<ASTString> m_name;
|
ASTPointer<ASTString> m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Definition of a contract. This is the only AST nodes where child nodes are not visited in
|
/**
|
||||||
/// document order. It first visits all struct declarations, then all variable declarations and
|
* Definition of a contract. This is the only AST nodes where child nodes are not visited in
|
||||||
/// finally all function declarations.
|
* document order. It first visits all struct declarations, then all variable declarations and
|
||||||
|
* finally all function declarations.
|
||||||
|
*/
|
||||||
class ContractDefinition: public Declaration
|
class ContractDefinition: public Declaration
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -133,9 +139,11 @@ private:
|
|||||||
std::vector<ASTPointer<VariableDeclaration>> m_members;
|
std::vector<ASTPointer<VariableDeclaration>> m_members;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Parameter list, used as function parameter list and return list.
|
/**
|
||||||
/// None of the parameters is allowed to contain mappings (not even recursively
|
* Parameter list, used as function parameter list and return list.
|
||||||
/// inside structs), but (@todo) this is not yet enforced.
|
* None of the parameters is allowed to contain mappings (not even recursively
|
||||||
|
* inside structs), but (@todo) this is not yet enforced.
|
||||||
|
*/
|
||||||
class ParameterList: public ASTNode
|
class ParameterList: public ASTNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -183,8 +191,10 @@ private:
|
|||||||
std::vector<VariableDeclaration const*> m_localVariables;
|
std::vector<VariableDeclaration const*> m_localVariables;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Declaration of a variable. This can be used in various places, e.g. in function parameter
|
/**
|
||||||
/// lists, struct definitions and even function bodys.
|
* Declaration of a variable. This can be used in various places, e.g. in function parameter
|
||||||
|
* lists, struct definitions and even function bodys.
|
||||||
|
*/
|
||||||
class VariableDeclaration: public Declaration
|
class VariableDeclaration: public Declaration
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -196,8 +206,8 @@ public:
|
|||||||
bool isTypeGivenExplicitly() const { return bool(m_typeName); }
|
bool isTypeGivenExplicitly() const { return bool(m_typeName); }
|
||||||
TypeName* getTypeName() const { return m_typeName.get(); }
|
TypeName* getTypeName() const { return m_typeName.get(); }
|
||||||
|
|
||||||
//! Returns the declared or inferred type. Can be an empty pointer if no type was explicitly
|
/// Returns the declared or inferred type. Can be an empty pointer if no type was explicitly
|
||||||
//! declared and there is no assignment to the variable that fixes the type.
|
/// declared and there is no assignment to the variable that fixes the type.
|
||||||
std::shared_ptr<Type const> const& getType() const { return m_type; }
|
std::shared_ptr<Type const> const& getType() const { return m_type; }
|
||||||
void setType(std::shared_ptr<Type const> const& _type) { m_type = _type; }
|
void setType(std::shared_ptr<Type const> const& _type) { m_type = _type; }
|
||||||
|
|
||||||
@ -210,7 +220,9 @@ private:
|
|||||||
/// Types
|
/// Types
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
/// Abstract base class of a type name, can be any built-in or user-defined type.
|
/**
|
||||||
|
* Abstract base class of a type name, can be any built-in or user-defined type.
|
||||||
|
*/
|
||||||
class TypeName: public ASTNode
|
class TypeName: public ASTNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -222,8 +234,10 @@ public:
|
|||||||
virtual std::shared_ptr<Type> toType() = 0;
|
virtual std::shared_ptr<Type> toType() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Any pre-defined type name represented by a single keyword, i.e. it excludes mappings,
|
/**
|
||||||
/// contracts, functions, etc.
|
* Any pre-defined type name represented by a single keyword, i.e. it excludes mappings,
|
||||||
|
* contracts, functions, etc.
|
||||||
|
*/
|
||||||
class ElementaryTypeName: public TypeName
|
class ElementaryTypeName: public TypeName
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -238,8 +252,10 @@ private:
|
|||||||
Token::Value m_type;
|
Token::Value m_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Name referring to a user-defined type (i.e. a struct).
|
/**
|
||||||
/// @todo some changes are necessary if this is also used to refer to contract types later
|
* Name referring to a user-defined type (i.e. a struct).
|
||||||
|
* @todo some changes are necessary if this is also used to refer to contract types later
|
||||||
|
*/
|
||||||
class UserDefinedTypeName: public TypeName
|
class UserDefinedTypeName: public TypeName
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -248,7 +264,7 @@ public:
|
|||||||
virtual void accept(ASTVisitor& _visitor) override;
|
virtual void accept(ASTVisitor& _visitor) override;
|
||||||
virtual std::shared_ptr<Type> toType() override { return Type::fromUserDefinedTypeName(*this); }
|
virtual std::shared_ptr<Type> toType() override { return Type::fromUserDefinedTypeName(*this); }
|
||||||
|
|
||||||
const ASTString& getName() const { return *m_name; }
|
ASTString const& getName() const { return *m_name; }
|
||||||
void setReferencedStruct(StructDefinition& _referencedStruct) { m_referencedStruct = &_referencedStruct; }
|
void setReferencedStruct(StructDefinition& _referencedStruct) { m_referencedStruct = &_referencedStruct; }
|
||||||
StructDefinition const* getReferencedStruct() const { return m_referencedStruct; }
|
StructDefinition const* getReferencedStruct() const { return m_referencedStruct; }
|
||||||
|
|
||||||
@ -258,7 +274,9 @@ private:
|
|||||||
StructDefinition* m_referencedStruct;
|
StructDefinition* m_referencedStruct;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A mapping type. Its source form is "mapping('keyType' => 'valueType')"
|
/**
|
||||||
|
* A mapping type. Its source form is "mapping('keyType' => 'valueType')"
|
||||||
|
*/
|
||||||
class Mapping: public TypeName
|
class Mapping: public TypeName
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -279,20 +297,24 @@ private:
|
|||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
|
||||||
/// Abstract base class for statements.
|
/**
|
||||||
|
* Abstract base class for statements.
|
||||||
|
*/
|
||||||
class Statement: public ASTNode
|
class Statement: public ASTNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Statement(Location const& _location): ASTNode(_location) {}
|
explicit Statement(Location const& _location): ASTNode(_location) {}
|
||||||
virtual void accept(ASTVisitor& _visitor) override;
|
virtual void accept(ASTVisitor& _visitor) override;
|
||||||
|
|
||||||
//! Check all type requirements, throws exception if some requirement is not met.
|
/// Check all type requirements, throws exception if some requirement is not met.
|
||||||
//! This includes checking that operators are applicable to their arguments but also that
|
/// This includes checking that operators are applicable to their arguments but also that
|
||||||
//! the number of function call arguments matches the number of formal parameters and so forth.
|
/// the number of function call arguments matches the number of formal parameters and so forth.
|
||||||
virtual void checkTypeRequirements() = 0;
|
virtual void checkTypeRequirements() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Brace-enclosed block containing zero or more statements.
|
/**
|
||||||
|
* Brace-enclosed block containing zero or more statements.
|
||||||
|
*/
|
||||||
class Block: public Statement
|
class Block: public Statement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -306,8 +328,10 @@ private:
|
|||||||
std::vector<ASTPointer<Statement>> m_statements;
|
std::vector<ASTPointer<Statement>> m_statements;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// If-statement with an optional "else" part. Note that "else if" is modeled by having a new
|
/**
|
||||||
/// if-statement as the false (else) body.
|
* If-statement with an optional "else" part. Note that "else if" is modeled by having a new
|
||||||
|
* if-statement as the false (else) body.
|
||||||
|
*/
|
||||||
class IfStatement: public Statement
|
class IfStatement: public Statement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -324,11 +348,13 @@ public:
|
|||||||
private:
|
private:
|
||||||
ASTPointer<Expression> m_condition;
|
ASTPointer<Expression> m_condition;
|
||||||
ASTPointer<Statement> m_trueBody;
|
ASTPointer<Statement> m_trueBody;
|
||||||
ASTPointer<Statement> m_falseBody; //< "else" part, optional
|
ASTPointer<Statement> m_falseBody; ///< "else" part, optional
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Statement in which a break statement is legal.
|
/**
|
||||||
/// @todo actually check this requirement.
|
* Statement in which a break statement is legal.
|
||||||
|
* @todo actually check this requirement.
|
||||||
|
*/
|
||||||
class BreakableStatement: public Statement
|
class BreakableStatement: public Statement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -381,15 +407,17 @@ public:
|
|||||||
Expression* getExpression() const { return m_expression.get(); }
|
Expression* getExpression() const { return m_expression.get(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ASTPointer<Expression> m_expression; //< value to return, optional
|
ASTPointer<Expression> m_expression; ///< value to return, optional
|
||||||
|
|
||||||
/// Pointer to the parameter list of the function, filled by the @ref NameAndTypeResolver.
|
/// Pointer to the parameter list of the function, filled by the @ref NameAndTypeResolver.
|
||||||
ParameterList* m_returnParameters;
|
ParameterList* m_returnParameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Definition of a variable as a statement inside a function. It requires a type name (which can
|
/**
|
||||||
/// also be "var") but the actual assignment can be missing.
|
* Definition of a variable as a statement inside a function. It requires a type name (which can
|
||||||
/// Examples: var a = 2; uint256 a;
|
* also be "var") but the actual assignment can be missing.
|
||||||
|
* Examples: var a = 2; uint256 a;
|
||||||
|
*/
|
||||||
class VariableDefinition: public Statement
|
class VariableDefinition: public Statement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -477,8 +505,10 @@ private:
|
|||||||
ASTPointer<Expression> m_rightHandSide;
|
ASTPointer<Expression> m_rightHandSide;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Operation involving a unary operator, pre- or postfix.
|
/**
|
||||||
/// Examples: ++i, delete x or !true
|
* Operation involving a unary operator, pre- or postfix.
|
||||||
|
* Examples: ++i, delete x or !true
|
||||||
|
*/
|
||||||
class UnaryOperation: public Expression
|
class UnaryOperation: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -498,8 +528,10 @@ private:
|
|||||||
bool m_isPrefix;
|
bool m_isPrefix;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Operation involving a binary operator.
|
/**
|
||||||
/// Examples: 1 + 2, true && false or 1 <= 4
|
* Operation involving a binary operator.
|
||||||
|
* Examples: 1 + 2, true && false or 1 <= 4
|
||||||
|
*/
|
||||||
class BinaryOperation: public Expression
|
class BinaryOperation: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -521,7 +553,9 @@ private:
|
|||||||
std::shared_ptr<Type const> m_commonType;
|
std::shared_ptr<Type const> m_commonType;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Can be ordinary function call, type cast or struct construction.
|
/**
|
||||||
|
* Can be ordinary function call, type cast or struct construction.
|
||||||
|
*/
|
||||||
class FunctionCall: public Expression
|
class FunctionCall: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -543,7 +577,9 @@ private:
|
|||||||
std::vector<ASTPointer<Expression>> m_arguments;
|
std::vector<ASTPointer<Expression>> m_arguments;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Access to a member of an object. Example: x.name
|
/**
|
||||||
|
* Access to a member of an object. Example: x.name
|
||||||
|
*/
|
||||||
class MemberAccess: public Expression
|
class MemberAccess: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -551,7 +587,7 @@ public:
|
|||||||
ASTPointer<ASTString> const& _memberName):
|
ASTPointer<ASTString> const& _memberName):
|
||||||
Expression(_location), m_expression(_expression), m_memberName(_memberName) {}
|
Expression(_location), m_expression(_expression), m_memberName(_memberName) {}
|
||||||
virtual void accept(ASTVisitor& _visitor) override;
|
virtual void accept(ASTVisitor& _visitor) override;
|
||||||
const ASTString& getMemberName() const { return *m_memberName; }
|
ASTString const& getMemberName() const { return *m_memberName; }
|
||||||
virtual void checkTypeRequirements() override;
|
virtual void checkTypeRequirements() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -559,7 +595,9 @@ private:
|
|||||||
ASTPointer<ASTString> m_memberName;
|
ASTPointer<ASTString> m_memberName;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Index access to an array. Example: a[2]
|
/**
|
||||||
|
* Index access to an array. Example: a[2]
|
||||||
|
*/
|
||||||
class IndexAccess: public Expression
|
class IndexAccess: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -574,15 +612,19 @@ private:
|
|||||||
ASTPointer<Expression> m_index;
|
ASTPointer<Expression> m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Primary expression, i.e. an expression that do not be divided any further like a literal or
|
/**
|
||||||
/// a variable reference.
|
* Primary expression, i.e. an expression that cannot be divided any further. Examples are literals
|
||||||
|
* or variable references.
|
||||||
|
*/
|
||||||
class PrimaryExpression: public Expression
|
class PrimaryExpression: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PrimaryExpression(Location const& _location): Expression(_location) {}
|
PrimaryExpression(Location const& _location): Expression(_location) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An identifier, i.e. a reference to a declaration by name like a variable or function.
|
/**
|
||||||
|
* An identifier, i.e. a reference to a declaration by name like a variable or function.
|
||||||
|
*/
|
||||||
class Identifier: public PrimaryExpression
|
class Identifier: public PrimaryExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -599,13 +641,15 @@ public:
|
|||||||
private:
|
private:
|
||||||
ASTPointer<ASTString> m_name;
|
ASTPointer<ASTString> m_name;
|
||||||
|
|
||||||
//! Declaration the name refers to.
|
/// Declaration the name refers to.
|
||||||
Declaration* m_referencedDeclaration;
|
Declaration* m_referencedDeclaration;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An elementary type name expression is used in expressions like "a = uint32(2)" to change the
|
/**
|
||||||
/// type of an expression explicitly. Here, "uint32" is the elementary type name expression and
|
* An elementary type name expression is used in expressions like "a = uint32(2)" to change the
|
||||||
/// "uint32(2)" is a @ref FunctionCall.
|
* type of an expression explicitly. Here, "uint32" is the elementary type name expression and
|
||||||
|
* "uint32(2)" is a @ref FunctionCall.
|
||||||
|
*/
|
||||||
class ElementaryTypeNameExpression: public PrimaryExpression
|
class ElementaryTypeNameExpression: public PrimaryExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -620,7 +664,9 @@ private:
|
|||||||
Token::Value m_typeToken;
|
Token::Value m_typeToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A literal string or number. @see Type::literalToBigEndian is used to actually parse its value.
|
/**
|
||||||
|
* A literal string or number. @see Type::literalToBigEndian is used to actually parse its value.
|
||||||
|
*/
|
||||||
class Literal: public PrimaryExpression
|
class Literal: public PrimaryExpression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -30,13 +30,15 @@ namespace dev
|
|||||||
namespace solidity
|
namespace solidity
|
||||||
{
|
{
|
||||||
|
|
||||||
/// Pretty-printer for the abstract syntax tree (the "pretty" is arguable) for debugging purposes.
|
/**
|
||||||
|
* Pretty-printer for the abstract syntax tree (the "pretty" is arguable) for debugging purposes.
|
||||||
|
*/
|
||||||
class ASTPrinter: public ASTVisitor
|
class ASTPrinter: public ASTVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Create a printer for the given abstract syntax tree. If the source is specified,
|
/// Create a printer for the given abstract syntax tree. If the source is specified,
|
||||||
/// the corresponding parts of the source are printed with each node.
|
/// the corresponding parts of the source are printed with each node.
|
||||||
ASTPrinter(ASTPointer<ASTNode> const& _ast, const std::string& _source = std::string());
|
ASTPrinter(ASTPointer<ASTNode> const& _ast, std::string const& _source = std::string());
|
||||||
/// Output the string representation of the AST to _stream.
|
/// Output the string representation of the AST to _stream.
|
||||||
void print(std::ostream& _stream);
|
void print(std::ostream& _stream);
|
||||||
|
|
||||||
|
14
ASTVisitor.h
14
ASTVisitor.h
@ -30,12 +30,14 @@ namespace dev
|
|||||||
namespace solidity
|
namespace solidity
|
||||||
{
|
{
|
||||||
|
|
||||||
/// Visitor interface for the abstract syntax tree. This class is tightly bound to the
|
/**
|
||||||
/// implementation of @ref ASTNode::accept and its overrides. After a call to
|
* Visitor interface for the abstract syntax tree. This class is tightly bound to the
|
||||||
/// @ref ASTNode::accept, the function visit for the appropriate parameter is called and then
|
* implementation of @ref ASTNode::accept and its overrides. After a call to
|
||||||
/// (if it returns true) this continues recursively for all child nodes in document order
|
* @ref ASTNode::accept, the function visit for the appropriate parameter is called and then
|
||||||
/// (there is an exception for contracts). After all child nodes have been visited, endVisit is
|
* (if it returns true) this continues recursively for all child nodes in document order
|
||||||
/// called for the node.
|
* (there is an exception for contracts). After all child nodes have been visited, endVisit is
|
||||||
|
* called for the node.
|
||||||
|
*/
|
||||||
class ASTVisitor
|
class ASTVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -29,8 +29,10 @@ namespace dev
|
|||||||
namespace solidity
|
namespace solidity
|
||||||
{
|
{
|
||||||
|
|
||||||
/// Representation of an interval of source positions.
|
/**
|
||||||
/// The interval includes start and excludes end.
|
* Representation of an interval of source positions.
|
||||||
|
* The interval includes start and excludes end.
|
||||||
|
*/
|
||||||
struct Location
|
struct Location
|
||||||
{
|
{
|
||||||
Location(int _start, int _end): start(_start), end(_end) { }
|
Location(int _start, int _end): start(_start), end(_end) { }
|
||||||
|
@ -243,7 +243,7 @@ bool Compiler::visit(WhileStatement& _whileStatement)
|
|||||||
|
|
||||||
m_context << loopStart;
|
m_context << loopStart;
|
||||||
ExpressionCompiler::compileExpression(m_context, _whileStatement.getCondition());
|
ExpressionCompiler::compileExpression(m_context, _whileStatement.getCondition());
|
||||||
m_context << eth::Instruction::NOT;
|
m_context << eth::Instruction::ISZERO;
|
||||||
m_context.appendConditionalJumpTo(loopEnd);
|
m_context.appendConditionalJumpTo(loopEnd);
|
||||||
|
|
||||||
_whileStatement.getBody().accept(*this);
|
_whileStatement.getBody().accept(*this);
|
||||||
|
@ -71,10 +71,10 @@ void ExpressionCompiler::endVisit(UnaryOperation& _unaryOperation)
|
|||||||
switch (_unaryOperation.getOperator())
|
switch (_unaryOperation.getOperator())
|
||||||
{
|
{
|
||||||
case Token::NOT: // !
|
case Token::NOT: // !
|
||||||
m_context << eth::Instruction::NOT;
|
m_context << eth::Instruction::ISZERO;
|
||||||
break;
|
break;
|
||||||
case Token::BIT_NOT: // ~
|
case Token::BIT_NOT: // ~
|
||||||
m_context << eth::Instruction::BNOT;
|
m_context << eth::Instruction::NOT;
|
||||||
break;
|
break;
|
||||||
case Token::DELETE: // delete
|
case Token::DELETE: // delete
|
||||||
{
|
{
|
||||||
@ -262,7 +262,7 @@ void ExpressionCompiler::appendAndOrOperatorCode(BinaryOperation& _binaryOperati
|
|||||||
_binaryOperation.getLeftExpression().accept(*this);
|
_binaryOperation.getLeftExpression().accept(*this);
|
||||||
m_context << eth::Instruction::DUP1;
|
m_context << eth::Instruction::DUP1;
|
||||||
if (op == Token::AND)
|
if (op == Token::AND)
|
||||||
m_context << eth::Instruction::NOT;
|
m_context << eth::Instruction::ISZERO;
|
||||||
eth::AssemblyItem endLabel = m_context.appendConditionalJump();
|
eth::AssemblyItem endLabel = m_context.appendConditionalJump();
|
||||||
_binaryOperation.getRightExpression().accept(*this);
|
_binaryOperation.getRightExpression().accept(*this);
|
||||||
m_context << endLabel;
|
m_context << endLabel;
|
||||||
@ -274,7 +274,7 @@ void ExpressionCompiler::appendCompareOperatorCode(Token::Value _operator, Type
|
|||||||
{
|
{
|
||||||
m_context << eth::Instruction::EQ;
|
m_context << eth::Instruction::EQ;
|
||||||
if (_operator == Token::NE)
|
if (_operator == Token::NE)
|
||||||
m_context << eth::Instruction::NOT;
|
m_context << eth::Instruction::ISZERO;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -288,11 +288,11 @@ void ExpressionCompiler::appendCompareOperatorCode(Token::Value _operator, Type
|
|||||||
{
|
{
|
||||||
case Token::GTE:
|
case Token::GTE:
|
||||||
m_context << (isSigned ? eth::Instruction::SGT : eth::Instruction::GT)
|
m_context << (isSigned ? eth::Instruction::SGT : eth::Instruction::GT)
|
||||||
<< eth::Instruction::NOT;
|
<< eth::Instruction::ISZERO;
|
||||||
break;
|
break;
|
||||||
case Token::LTE:
|
case Token::LTE:
|
||||||
m_context << (isSigned ? eth::Instruction::SLT : eth::Instruction::LT)
|
m_context << (isSigned ? eth::Instruction::SLT : eth::Instruction::LT)
|
||||||
<< eth::Instruction::NOT;
|
<< eth::Instruction::ISZERO;
|
||||||
break;
|
break;
|
||||||
case Token::GT:
|
case Token::GT:
|
||||||
m_context << (isSigned ? eth::Instruction::SLT : eth::Instruction::LT);
|
m_context << (isSigned ? eth::Instruction::SLT : eth::Instruction::LT);
|
||||||
|
@ -33,8 +33,11 @@ namespace dev
|
|||||||
namespace solidity
|
namespace solidity
|
||||||
{
|
{
|
||||||
|
|
||||||
//! Resolves name references, resolves all types and checks that all operations are valid for the
|
/**
|
||||||
//! inferred types. An exception is throw on the first error.
|
* Resolves name references, types and checks types of all expressions.
|
||||||
|
* Specifically, it checks that all operations are valid for the inferred types.
|
||||||
|
* An exception is throw on the first error.
|
||||||
|
*/
|
||||||
class NameAndTypeResolver: private boost::noncopyable
|
class NameAndTypeResolver: private boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -54,15 +57,17 @@ public:
|
|||||||
private:
|
private:
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
//! Maps nodes declaring a scope to scopes, i.e. ContractDefinition, FunctionDeclaration and
|
/// Maps nodes declaring a scope to scopes, i.e. ContractDefinition, FunctionDeclaration and
|
||||||
//! StructDefinition (@todo not yet implemented), where nullptr denotes the global scope.
|
/// StructDefinition (@todo not yet implemented), where nullptr denotes the global scope.
|
||||||
std::map<ASTNode const*, Scope> m_scopes;
|
std::map<ASTNode const*, Scope> m_scopes;
|
||||||
|
|
||||||
Scope* m_currentScope;
|
Scope* m_currentScope;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Traverses the given AST upon construction and fills _scopes with all declarations inside the
|
/**
|
||||||
//! AST.
|
* Traverses the given AST upon construction and fills _scopes with all declarations inside the
|
||||||
|
* AST.
|
||||||
|
*/
|
||||||
class DeclarationRegistrationHelper: private ASTVisitor
|
class DeclarationRegistrationHelper: private ASTVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -87,8 +92,10 @@ private:
|
|||||||
FunctionDefinition* m_currentFunction;
|
FunctionDefinition* m_currentFunction;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Resolves references to declarations (of variables and types) and also establishes the link
|
/**
|
||||||
//! between a return statement and the return parameter list.
|
* Resolves references to declarations (of variables and types) and also establishes the link
|
||||||
|
* between a return statement and the return parameter list.
|
||||||
|
*/
|
||||||
class ReferencesResolver: private ASTVisitor
|
class ReferencesResolver: private ASTVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -125,7 +125,7 @@ public:
|
|||||||
/// Returns the current token
|
/// Returns the current token
|
||||||
Token::Value getCurrentToken() { return m_current_token.token; }
|
Token::Value getCurrentToken() { return m_current_token.token; }
|
||||||
Location getCurrentLocation() const { return m_current_token.location; }
|
Location getCurrentLocation() const { return m_current_token.location; }
|
||||||
const std::string& getCurrentLiteral() const { return m_current_token.literal; }
|
std::string const& getCurrentLiteral() const { return m_current_token.literal; }
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
///@{
|
///@{
|
||||||
@ -134,7 +134,7 @@ public:
|
|||||||
/// Returns the next token without advancing input.
|
/// Returns the next token without advancing input.
|
||||||
Token::Value peekNextToken() const { return m_next_token.token; }
|
Token::Value peekNextToken() const { return m_next_token.token; }
|
||||||
Location peekLocation() const { return m_next_token.location; }
|
Location peekLocation() const { return m_next_token.location; }
|
||||||
const std::string& peekLiteral() const { return m_next_token.literal; }
|
std::string const& peekLiteral() const { return m_next_token.literal; }
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
///@{
|
///@{
|
||||||
|
6
Scope.h
6
Scope.h
@ -32,8 +32,10 @@ namespace dev
|
|||||||
namespace solidity
|
namespace solidity
|
||||||
{
|
{
|
||||||
|
|
||||||
/// Container that stores mappings betwee names and declarations. It also contains a link to the
|
/**
|
||||||
/// enclosing scope.
|
* Container that stores mappings betwee names and declarations. It also contains a link to the
|
||||||
|
* enclosing scope.
|
||||||
|
*/
|
||||||
class Scope
|
class Scope
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
16
Types.cpp
16
Types.cpp
@ -143,7 +143,7 @@ bool IntegerType::acceptsUnaryOperator(Token::Value _operator) const
|
|||||||
_operator == Token::INC || _operator == Token::DEC;
|
_operator == Token::INC || _operator == Token::DEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IntegerType::operator==(const Type& _other) const
|
bool IntegerType::operator==(Type const& _other) const
|
||||||
{
|
{
|
||||||
if (_other.getCategory() != getCategory())
|
if (_other.getCategory() != getCategory())
|
||||||
return false;
|
return false;
|
||||||
@ -159,7 +159,7 @@ std::string IntegerType::toString() const
|
|||||||
return prefix + dev::toString(m_bits);
|
return prefix + dev::toString(m_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
u256 IntegerType::literalValue(const Literal& _literal) const
|
u256 IntegerType::literalValue(Literal const& _literal) const
|
||||||
{
|
{
|
||||||
bigint value(_literal.getValue());
|
bigint value(_literal.getValue());
|
||||||
//@todo check that the number is not too large
|
//@todo check that the number is not too large
|
||||||
@ -180,7 +180,7 @@ bool BoolType::isExplicitlyConvertibleTo(Type const& _convertTo) const
|
|||||||
return isImplicitlyConvertibleTo(_convertTo);
|
return isImplicitlyConvertibleTo(_convertTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
u256 BoolType::literalValue(const Literal& _literal) const
|
u256 BoolType::literalValue(Literal const& _literal) const
|
||||||
{
|
{
|
||||||
if (_literal.getToken() == Token::TRUE_LITERAL)
|
if (_literal.getToken() == Token::TRUE_LITERAL)
|
||||||
return u256(1);
|
return u256(1);
|
||||||
@ -190,7 +190,7 @@ u256 BoolType::literalValue(const Literal& _literal) const
|
|||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContractType::operator==(const Type& _other) const
|
bool ContractType::operator==(Type const& _other) const
|
||||||
{
|
{
|
||||||
if (_other.getCategory() != getCategory())
|
if (_other.getCategory() != getCategory())
|
||||||
return false;
|
return false;
|
||||||
@ -198,7 +198,7 @@ bool ContractType::operator==(const Type& _other) const
|
|||||||
return other.m_contract == m_contract;
|
return other.m_contract == m_contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StructType::operator==(const Type& _other) const
|
bool StructType::operator==(Type const& _other) const
|
||||||
{
|
{
|
||||||
if (_other.getCategory() != getCategory())
|
if (_other.getCategory() != getCategory())
|
||||||
return false;
|
return false;
|
||||||
@ -206,7 +206,7 @@ bool StructType::operator==(const Type& _other) const
|
|||||||
return other.m_struct == m_struct;
|
return other.m_struct == m_struct;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FunctionType::operator==(const Type& _other) const
|
bool FunctionType::operator==(Type const& _other) const
|
||||||
{
|
{
|
||||||
if (_other.getCategory() != getCategory())
|
if (_other.getCategory() != getCategory())
|
||||||
return false;
|
return false;
|
||||||
@ -214,7 +214,7 @@ bool FunctionType::operator==(const Type& _other) const
|
|||||||
return other.m_function == m_function;
|
return other.m_function == m_function;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MappingType::operator==(const Type& _other) const
|
bool MappingType::operator==(Type const& _other) const
|
||||||
{
|
{
|
||||||
if (_other.getCategory() != getCategory())
|
if (_other.getCategory() != getCategory())
|
||||||
return false;
|
return false;
|
||||||
@ -222,7 +222,7 @@ bool MappingType::operator==(const Type& _other) const
|
|||||||
return *other.m_keyType == *m_keyType && *other.m_valueType == *m_valueType;
|
return *other.m_keyType == *m_keyType && *other.m_valueType == *m_valueType;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TypeType::operator==(const Type& _other) const
|
bool TypeType::operator==(Type const& _other) const
|
||||||
{
|
{
|
||||||
if (_other.getCategory() != getCategory())
|
if (_other.getCategory() != getCategory())
|
||||||
return false;
|
return false;
|
||||||
|
40
Types.h
40
Types.h
@ -36,7 +36,9 @@ namespace solidity
|
|||||||
|
|
||||||
// @todo realMxN, string<N>, mapping
|
// @todo realMxN, string<N>, mapping
|
||||||
|
|
||||||
/// Abstract base class that forms the root of the type hierarchy.
|
/**
|
||||||
|
* Abstract base class that forms the root of the type hierarchy.
|
||||||
|
*/
|
||||||
class Type: private boost::noncopyable
|
class Type: private boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -76,7 +78,9 @@ public:
|
|||||||
virtual u256 literalValue(Literal const&) const { assert(false); }
|
virtual u256 literalValue(Literal const&) const { assert(false); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Any kind of integer type including hash and address.
|
/**
|
||||||
|
* Any kind of integer type including hash and address.
|
||||||
|
*/
|
||||||
class IntegerType: public Type
|
class IntegerType: public Type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -112,7 +116,9 @@ private:
|
|||||||
Modifier m_modifier;
|
Modifier m_modifier;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The boolean type.
|
/**
|
||||||
|
* The boolean type.
|
||||||
|
*/
|
||||||
class BoolType: public Type
|
class BoolType: public Type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -133,7 +139,9 @@ public:
|
|||||||
virtual u256 literalValue(Literal const& _literal) const override;
|
virtual u256 literalValue(Literal const& _literal) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The type of a contract instance, there is one distinct type for each contract definition.
|
/**
|
||||||
|
* The type of a contract instance, there is one distinct type for each contract definition.
|
||||||
|
*/
|
||||||
class ContractType: public Type
|
class ContractType: public Type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -148,7 +156,9 @@ private:
|
|||||||
ContractDefinition const& m_contract;
|
ContractDefinition const& m_contract;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The type of a struct instance, there is one distinct type per struct definition.
|
/**
|
||||||
|
* The type of a struct instance, there is one distinct type per struct definition.
|
||||||
|
*/
|
||||||
class StructType: public Type
|
class StructType: public Type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -167,7 +177,9 @@ private:
|
|||||||
StructDefinition const& m_struct;
|
StructDefinition const& m_struct;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The type of a function, there is one distinct type per function definition.
|
/**
|
||||||
|
* The type of a function, there is one distinct type per function definition.
|
||||||
|
*/
|
||||||
class FunctionType: public Type
|
class FunctionType: public Type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -184,7 +196,9 @@ private:
|
|||||||
FunctionDefinition const& m_function;
|
FunctionDefinition const& m_function;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The type of a mapping, there is one distinct type per key/value type pair.
|
/**
|
||||||
|
* The type of a mapping, there is one distinct type per key/value type pair.
|
||||||
|
*/
|
||||||
class MappingType: public Type
|
class MappingType: public Type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -199,8 +213,10 @@ private:
|
|||||||
std::shared_ptr<Type const> m_valueType;
|
std::shared_ptr<Type const> m_valueType;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The void type, can only be implicitly used as the type that is returned by functions without
|
/**
|
||||||
/// return parameters.
|
* The void type, can only be implicitly used as the type that is returned by functions without
|
||||||
|
* return parameters.
|
||||||
|
*/
|
||||||
class VoidType: public Type
|
class VoidType: public Type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -210,8 +226,10 @@ public:
|
|||||||
virtual std::string toString() const override { return "void"; }
|
virtual std::string toString() const override { return "void"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The type of a type reference. The type of "uint32" when used in "a = uint32(2)" is an example
|
/**
|
||||||
/// of a TypeType.
|
* The type of a type reference. The type of "uint32" when used in "a = uint32(2)" is an example
|
||||||
|
* of a TypeType.
|
||||||
|
*/
|
||||||
class TypeType: public Type
|
class TypeType: public Type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user