From fae8ca001ef33041b5ba5debc5a71ecc3eb5645b Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 28 Oct 2014 09:25:01 +0100 Subject: [PATCH 1/8] Stylistic corrections. --- AST.h | 22 +++++++++++----------- Compiler.cpp | 10 +++------- NameAndTypeResolver.h | 16 ++++++++-------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/AST.h b/AST.h index db6637aea..5c975ee4b 100644 --- a/AST.h +++ b/AST.h @@ -191,8 +191,8 @@ public: bool isTypeGivenExplicitly() const { return bool(m_typeName); } TypeName* getTypeName() const { return m_typeName.get(); } - //! 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. + /// 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. std::shared_ptr const& getType() const { return m_type; } void setType(std::shared_ptr const& _type) { m_type = _type; } @@ -281,14 +281,14 @@ public: explicit Statement(Location const& _location): ASTNode(_location) {} virtual void accept(ASTVisitor& _visitor) override; - //! 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 - //! the number of function call arguments matches the number of formal parameters and so forth. + /// 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 + /// the number of function call arguments matches the number of formal parameters and so forth. virtual void checkTypeRequirements() = 0; protected: - //! Helper function, check that the inferred type for @a _expression is @a _expectedType or at - //! least implicitly convertible to @a _expectedType. If not, throw exception. + /// Helper function, check that the inferred type for @a _expression is @a _expectedType or at + /// least implicitly convertible to @a _expectedType. If not, throw exception. void expectType(Expression& _expression, Type const& _expectedType); }; @@ -407,7 +407,7 @@ public: std::shared_ptr const& getType() const { return m_type; } protected: - //! Inferred type of the expression, only filled after a call to checkTypeRequirements(). + /// Inferred type of the expression, only filled after a call to checkTypeRequirements(). std::shared_ptr m_type; }; @@ -532,8 +532,8 @@ private: ASTPointer 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 { public: @@ -557,7 +557,7 @@ public: private: ASTPointer m_name; - //! Declaration the name refers to. + /// Declaration the name refers to. Declaration* m_referencedDeclaration; }; diff --git a/Compiler.cpp b/Compiler.cpp index acb0a5cc7..ef5680138 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -25,11 +25,9 @@ #include #include - namespace dev { namespace solidity { - void CompilerContext::setLabelPosition(uint32_t _label, uint32_t _position) { assert(m_labelPositions.find(_label) == m_labelPositions.end()); @@ -63,12 +61,10 @@ bytes ExpressionCompiler::getAssembledBytecode() const } for (AssemblyItem const& item: m_assemblyItems) - { if (item.getType() == AssemblyItem::Type::LABELREF) assembled.push_back(m_context.getLabelPosition(item.getLabel())); else assembled.push_back(item.getData()); - } return assembled; } @@ -203,17 +199,17 @@ void ExpressionCompiler::endVisit(FunctionCall& _functionCall) } } -void ExpressionCompiler::endVisit(MemberAccess& _memberAccess) +void ExpressionCompiler::endVisit(MemberAccess&) { } -void ExpressionCompiler::endVisit(IndexAccess& _indexAccess) +void ExpressionCompiler::endVisit(IndexAccess&) { } -void ExpressionCompiler::endVisit(Identifier& _identifier) +void ExpressionCompiler::endVisit(Identifier&) { } diff --git a/NameAndTypeResolver.h b/NameAndTypeResolver.h index 7abcbb0c5..055835c4f 100644 --- a/NameAndTypeResolver.h +++ b/NameAndTypeResolver.h @@ -33,8 +33,8 @@ namespace dev 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, resolves all types and checks that all operations are valid for the +/// inferred types. An exception is throw on the first error. class NameAndTypeResolver: private boost::noncopyable { public: @@ -46,15 +46,15 @@ public: private: void reset(); - //! Maps nodes declaring a scope to scopes, i.e. ContractDefinition, FunctionDeclaration and - //! StructDefinition (@todo not yet implemented), where nullptr denotes the global scope. + /// Maps nodes declaring a scope to scopes, i.e. ContractDefinition, FunctionDeclaration and + /// StructDefinition (@todo not yet implemented), where nullptr denotes the global scope. std::map m_scopes; 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 { public: @@ -78,8 +78,8 @@ private: Scope* m_currentScope; }; -//! 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 { public: From 933fbd7d60006092cd8846cc164188f7ad41460f Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 28 Oct 2014 16:51:26 +0100 Subject: [PATCH 2/8] Asterisk-syntax for doxygen class documentation. --- AST.h | 140 ++++++++++++++++++++++++++++-------------- ASTPrinter.h | 4 +- Compiler.h | 24 +++++--- NameAndTypeResolver.h | 19 ++++-- Scope.h | 6 +- Types.h | 40 ++++++++---- 6 files changed, 159 insertions(+), 74 deletions(-) diff --git a/AST.h b/AST.h index 5c975ee4b..e66572800 100644 --- a/AST.h +++ b/AST.h @@ -41,9 +41,11 @@ namespace solidity 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 -/// accept, providing an 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 + * accept, providing an ASTVisitor. + */ class ASTNode: private boost::noncopyable { public: @@ -77,7 +79,9 @@ private: 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 { public: @@ -91,9 +95,11 @@ private: ASTPointer 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 -/// finally all function declarations. +/** + * 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 + * finally all function declarations. + */ class ContractDefinition: public Declaration { public: @@ -133,9 +139,11 @@ private: std::vector> m_members; }; -/// Parameter list, used as function parameter list and return list. -/// None of the parameters is allowed to contain mappings (not even recursively -/// inside structs), but (@todo) this is not yet enforced. +/** + * Parameter list, used as function parameter list and return list. + * 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 { public: @@ -178,8 +186,10 @@ private: ASTPointer m_body; }; -/// 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 { public: @@ -205,7 +215,9 @@ private: /// 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 { public: @@ -217,8 +229,10 @@ public: virtual std::shared_ptr 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 { public: @@ -233,8 +247,10 @@ private: 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 { public: @@ -253,7 +269,9 @@ private: 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 { public: @@ -274,7 +292,9 @@ private: /// @{ -/// Abstract base class for statements. +/** + * Abstract base class for statements. + */ class Statement: public ASTNode { public: @@ -292,7 +312,9 @@ protected: void expectType(Expression& _expression, Type const& _expectedType); }; -/// Brace-enclosed block containing zero or more statements. +/** + * Brace-enclosed block containing zero or more statements. + */ class Block: public Statement { public: @@ -306,8 +328,10 @@ private: std::vector> 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 { public: @@ -324,8 +348,10 @@ private: ASTPointer 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 { public: @@ -380,9 +406,11 @@ private: 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. -/// Examples: var a = 2; uint256 a; +/** + * 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. + * Examples: var a = 2; uint256 a; + */ class VariableDefinition: public Statement { public: @@ -397,8 +425,10 @@ private: ASTPointer m_value; ///< the assigned value, can be missing }; -/// An expression, i.e. something that has a value (which can also be of type "void" in case -/// of function calls). +/** + * An expression, i.e. something that has a value (which can also be of type "void" in case + * of function calls). + */ class Expression: public Statement { public: @@ -416,8 +446,10 @@ protected: /// Expressions /// @{ -/// Assignment, can also be a compound assignment. -/// Examples: (a = 7 + 8) or (a *= 2) +/** + * Assignment, can also be a compound assignment. + * Examples: (a = 7 + 8) or (a *= 2) + */ class Assignment: public Expression { public: @@ -438,8 +470,10 @@ private: ASTPointer 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 { public: @@ -459,8 +493,10 @@ private: 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 { public: @@ -482,7 +518,9 @@ private: std::shared_ptr 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 { public: @@ -501,7 +539,9 @@ private: std::vector> 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 { public: @@ -517,7 +557,9 @@ private: ASTPointer m_memberName; }; -/// Index access to an array. Example: a[2] +/** + * Index access to an array. Example: a[2] + */ class IndexAccess: public Expression { public: @@ -532,15 +574,19 @@ private: ASTPointer m_index; }; -/// Primary expression, i.e. an expression that cannot be divided any further. Examples are literals -/// or variable references. +/** + * Primary expression, i.e. an expression that cannot be divided any further. Examples are literals + * or variable references. + */ class PrimaryExpression: public Expression { public: 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 { public: @@ -561,9 +607,11 @@ private: 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 -/// "uint32(2)" is a @ref FunctionCall. +/** + * 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 + * "uint32(2)" is a @ref FunctionCall. + */ class ElementaryTypeNameExpression: public PrimaryExpression { public: @@ -578,7 +626,9 @@ private: 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 { public: diff --git a/ASTPrinter.h b/ASTPrinter.h index 74e0837ff..97256c056 100644 --- a/ASTPrinter.h +++ b/ASTPrinter.h @@ -30,7 +30,9 @@ namespace dev 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 { public: diff --git a/Compiler.h b/Compiler.h index ac5e10ec9..1401e12e3 100644 --- a/Compiler.h +++ b/Compiler.h @@ -28,9 +28,11 @@ namespace dev { namespace solidity { -/// A single item of compiled code that can be assembled to a single byte value in the final -/// bytecode. Its main purpose is to inject jump labels and label references into the opcode stream, -/// which can be resolved in the final step. +/** + * A single item of compiled code that can be assembled to a single byte value in the final + * bytecode. Its main purpose is to inject jump labels and label references into the opcode stream, + * which can be resolved in the final step. + */ class AssemblyItem { public: @@ -64,9 +66,11 @@ private: using AssemblyItems = std::vector; -/// Context to be shared by all units that compile the same contract. Its current usage only -/// concerns dispensing unique jump label IDs and storing their actual positions in the bytecode -/// stream. +/** + * Context to be shared by all units that compile the same contract. Its current usage only + * concerns dispensing unique jump label IDs and storing their actual positions in the bytecode + * stream. + */ class CompilerContext { public: @@ -81,9 +85,11 @@ private: std::map m_labelPositions; }; -/// Compiler for expressions, i.e. converts an AST tree whose root is an Expression into a stream -/// of EVM instructions. It needs a compiler context that is the same for the whole compilation -/// unit. +/** + * Compiler for expressions, i.e. converts an AST tree whose root is an Expression into a stream + * of EVM instructions. It needs a compiler context that is the same for the whole compilation + * unit. + */ class ExpressionCompiler: public ASTVisitor { public: diff --git a/NameAndTypeResolver.h b/NameAndTypeResolver.h index 055835c4f..bb7fcb98f 100644 --- a/NameAndTypeResolver.h +++ b/NameAndTypeResolver.h @@ -33,8 +33,11 @@ namespace dev 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 { public: @@ -53,8 +56,10 @@ private: 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 { public: @@ -78,8 +83,10 @@ private: Scope* m_currentScope; }; -/// 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 { public: diff --git a/Scope.h b/Scope.h index 83b01f423..637c2d5ce 100644 --- a/Scope.h +++ b/Scope.h @@ -32,8 +32,10 @@ namespace dev 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 { public: diff --git a/Types.h b/Types.h index 4d56b5abb..c9f6da574 100644 --- a/Types.h +++ b/Types.h @@ -36,7 +36,9 @@ namespace solidity // @todo realMxN, string, 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 { public: @@ -72,7 +74,9 @@ public: virtual bytes literalToBigEndian(Literal const&) const { return NullBytes; } }; -/// Any kind of integer type including hash and address. +/** + * Any kind of integer type including hash and address. + */ class IntegerType: public Type { public: @@ -106,7 +110,9 @@ private: Modifier m_modifier; }; -/// The boolean type. +/** + * The boolean type. + */ class BoolType: public Type { public: @@ -125,7 +131,9 @@ public: virtual bytes literalToBigEndian(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 { public: @@ -140,7 +148,9 @@ private: 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 { public: @@ -159,7 +169,9 @@ private: 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 { public: @@ -176,7 +188,9 @@ private: 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 { public: @@ -191,8 +205,10 @@ private: std::shared_ptr 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 { public: @@ -202,8 +218,10 @@ public: 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 { public: From 7bb3311be6ba971d05482114df323f1d015e96a9 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 28 Oct 2014 16:57:20 +0100 Subject: [PATCH 3/8] Forgot some asterisks. --- ASTVisitor.h | 14 ++++++++------ BaseTypes.h | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ASTVisitor.h b/ASTVisitor.h index a667ad392..e4818ee27 100644 --- a/ASTVisitor.h +++ b/ASTVisitor.h @@ -30,12 +30,14 @@ namespace dev 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 -/// @ref ASTNode::accept, the function visit for the appropriate parameter is called and then -/// (if it returns true) this continues recursively for all child nodes in document order -/// (there is an exception for contracts). After all child nodes have been visited, endVisit is -/// called for the node. +/** + * 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 + * @ref ASTNode::accept, the function visit for the appropriate parameter is called and then + * (if it returns true) this continues recursively for all child nodes in document order + * (there is an exception for contracts). After all child nodes have been visited, endVisit is + * called for the node. + */ class ASTVisitor { public: diff --git a/BaseTypes.h b/BaseTypes.h index cfc14c7e9..d1ffd7bbc 100644 --- a/BaseTypes.h +++ b/BaseTypes.h @@ -29,8 +29,10 @@ namespace dev 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 { Location(int _start, int _end): start(_start), end(_end) { } From f91ddc27889fd0565179bcac44ff8b7d0413cf20 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 28 Oct 2014 17:09:06 +0100 Subject: [PATCH 4/8] Adjustments for the NEG->BNOT change. --- Compiler.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Compiler.cpp b/Compiler.cpp index ef5680138..43cbc462e 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -107,13 +107,7 @@ void ExpressionCompiler::endVisit(UnaryOperation& _unaryOperation) append(eth::Instruction::NOT); break; case Token::BIT_NOT: // ~ - // ~a modeled as "a xor (0 - 1)" for now - append(eth::Instruction::PUSH1); - append(1); - append(eth::Instruction::PUSH1); - append(0); - append(eth::Instruction::SUB); - append(eth::Instruction::XOR); + append(eth::Instruction::BNOT); break; case Token::DELETE: // delete // a -> a xor a (= 0). @@ -145,7 +139,10 @@ void ExpressionCompiler::endVisit(UnaryOperation& _unaryOperation) // unary add, so basically no-op break; case Token::SUB: // - - append(eth::Instruction::NEG); + // unary -x translates into "0-x" + append(eth::Instruction::PUSH1); + append(0); + append(eth::Instruction::SUB); break; default: assert(false); // invalid operation From 62822ffd92cfef4b76cea44783c67278950a7e79 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 29 Oct 2014 19:28:30 +0100 Subject: [PATCH 5/8] Fixed placements of const. --- Compiler.cpp | 2 +- Types.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Compiler.cpp b/Compiler.cpp index 43cbc462e..be1d38b9c 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -230,7 +230,7 @@ void ExpressionCompiler::endVisit(Literal& _literal) } } -void ExpressionCompiler::cleanHigherOrderBitsIfNeeded(const Type& _typeOnStack, const Type& _targetType) +void ExpressionCompiler::cleanHigherOrderBitsIfNeeded(Type const& _typeOnStack, Type const& _targetType) { // If the type of one of the operands is extended, we need to remove all // higher-order bits that we might have ignored in previous operations. diff --git a/Types.cpp b/Types.cpp index 05b12df09..e6711b3cb 100644 --- a/Types.cpp +++ b/Types.cpp @@ -143,7 +143,7 @@ bool IntegerType::acceptsUnaryOperator(Token::Value _operator) const _operator == Token::INC || _operator == Token::DEC; } -bool IntegerType::operator==(const Type& _other) const +bool IntegerType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) return false; @@ -159,7 +159,7 @@ std::string IntegerType::toString() const return prefix + dev::toString(m_bits); } -bytes IntegerType::literalToBigEndian(const Literal& _literal) const +bytes IntegerType::literalToBigEndian(Literal const& _literal) const { bigint value(_literal.getValue()); if (!isSigned() && value < 0) @@ -182,7 +182,7 @@ bool BoolType::isExplicitlyConvertibleTo(Type const& _convertTo) const return isImplicitlyConvertibleTo(_convertTo); } -bytes BoolType::literalToBigEndian(const Literal& _literal) const +bytes BoolType::literalToBigEndian(Literal const& _literal) const { if (_literal.getToken() == Token::TRUE_LITERAL) return bytes(1, 1); @@ -192,7 +192,7 @@ bytes BoolType::literalToBigEndian(const Literal& _literal) const return NullBytes; } -bool ContractType::operator==(const Type& _other) const +bool ContractType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) return false; @@ -200,7 +200,7 @@ bool ContractType::operator==(const Type& _other) const return other.m_contract == m_contract; } -bool StructType::operator==(const Type& _other) const +bool StructType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) return false; @@ -208,7 +208,7 @@ bool StructType::operator==(const Type& _other) const return other.m_struct == m_struct; } -bool FunctionType::operator==(const Type& _other) const +bool FunctionType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) return false; @@ -216,7 +216,7 @@ bool FunctionType::operator==(const Type& _other) const return other.m_function == m_function; } -bool MappingType::operator==(const Type& _other) const +bool MappingType::operator==(Type const& _other) const { if (_other.getCategory() != getCategory()) return false; @@ -224,7 +224,7 @@ bool MappingType::operator==(const Type& _other) const 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()) return false; From 5d287e7ea2e1847bb5fc4c67c520248c7060c4c6 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 29 Oct 2014 19:41:07 +0100 Subject: [PATCH 6/8] Further const placement changes. --- AST.cpp | 2 +- AST.h | 6 +++--- ASTPrinter.h | 2 +- Scanner.h | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/AST.cpp b/AST.cpp index 0b635339d..5bba8dce7 100644 --- a/AST.cpp +++ b/AST.cpp @@ -255,7 +255,7 @@ TypeError ASTNode::createTypeError(string const& _description) return TypeError() << errinfo_sourceLocation(getLocation()) << errinfo_comment(_description); } -void Statement::expectType(Expression& _expression, const Type& _expectedType) +void Statement::expectType(Expression& _expression, Type const& _expectedType) { _expression.checkTypeRequirements(); if (!_expression.getType()->isImplicitlyConvertibleTo(_expectedType)) diff --git a/AST.h b/AST.h index e66572800..e72826602 100644 --- a/AST.h +++ b/AST.h @@ -89,7 +89,7 @@ public: ASTNode(_location), m_name(_name) {} /// Returns the declared name. - const ASTString& getName() const { return *m_name; } + ASTString const& getName() const { return *m_name; } private: ASTPointer m_name; @@ -259,7 +259,7 @@ public: virtual void accept(ASTVisitor& _visitor) override; virtual std::shared_ptr 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; } StructDefinition const* getReferencedStruct() const { return m_referencedStruct; } @@ -549,7 +549,7 @@ public: ASTPointer const& _memberName): Expression(_location), m_expression(_expression), m_memberName(_memberName) {} virtual void accept(ASTVisitor& _visitor) override; - const ASTString& getMemberName() const { return *m_memberName; } + ASTString const& getMemberName() const { return *m_memberName; } virtual void checkTypeRequirements() override; private: diff --git a/ASTPrinter.h b/ASTPrinter.h index 97256c056..d788ba76c 100644 --- a/ASTPrinter.h +++ b/ASTPrinter.h @@ -38,7 +38,7 @@ class ASTPrinter: public ASTVisitor public: /// 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. - ASTPrinter(ASTPointer const& _ast, const std::string& _source = std::string()); + ASTPrinter(ASTPointer const& _ast, std::string const& _source = std::string()); /// Output the string representation of the AST to _stream. void print(std::ostream& _stream); diff --git a/Scanner.h b/Scanner.h index fbaba9ed6..c08d3219e 100644 --- a/Scanner.h +++ b/Scanner.h @@ -124,7 +124,7 @@ public: /// Returns the current token Token::Value getCurrentToken() { return m_current_token.token; } 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; } ///@} ///@{ @@ -133,7 +133,7 @@ public: /// Returns the next token without advancing input. Token::Value peekNextToken() const { return m_next_token.token; } 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; } ///@} ///@{ From 9f53f1889310e92e1aa9011e1c43eda9c038fce5 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 31 Oct 2014 13:29:32 +0100 Subject: [PATCH 7/8] Corrected doxygen post comments. --- AST.h | 4 ++-- Compiler.h | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/AST.h b/AST.h index e72826602..4dc44e29b 100644 --- a/AST.h +++ b/AST.h @@ -345,7 +345,7 @@ public: private: ASTPointer m_condition; ASTPointer m_trueBody; - ASTPointer m_falseBody; //< "else" part, optional + ASTPointer m_falseBody; ///< "else" part, optional }; /** @@ -400,7 +400,7 @@ public: void setFunctionReturnParameters(ParameterList& _parameters) { m_returnParameters = &_parameters; } private: - ASTPointer m_expression; //< value to return, optional + ASTPointer m_expression; ///< value to return, optional /// Pointer to the parameter list of the function, filled by the @ref NameAndTypeResolver. ParameterList* m_returnParameters; diff --git a/Compiler.h b/Compiler.h index 1401e12e3..5817f12f1 100644 --- a/Compiler.h +++ b/Compiler.h @@ -38,10 +38,10 @@ class AssemblyItem public: enum class Type { - CODE, //< m_data is opcode, m_label is empty. - DATA, //< m_data is actual data, m_label is empty - LABEL, //< m_data is JUMPDEST opcode, m_label is id of label - LABELREF //< m_data is empty, m_label is id of label + CODE, ///< m_data is opcode, m_label is empty. + DATA, ///< m_data is actual data, m_label is empty + LABEL, ///< m_data is JUMPDEST opcode, m_label is id of label + LABELREF ///< m_data is empty, m_label is id of label }; explicit AssemblyItem(eth::Instruction _instruction) : m_type(Type::CODE), m_data(byte(_instruction)) {} @@ -59,8 +59,8 @@ private: AssemblyItem(Type _type, byte _data, uint32_t _label): m_type(_type), m_data(_data), m_label(_label) {} Type m_type; - byte m_data; //< data to be written to the bytecode stream (or filled by a label if this is a LABELREF) - uint32_t m_label; //< the id of a label either referenced or defined by this item + byte m_data; ///< data to be written to the bytecode stream (or filled by a label if this is a LABELREF) + uint32_t m_label; ///< the id of a label either referenced or defined by this item }; using AssemblyItems = std::vector; From c45495afb96fcd9bf8b3ad965144a3436fc101a5 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 31 Oct 2014 14:35:13 +0100 Subject: [PATCH 8/8] Big fixes. --- Compiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Compiler.cpp b/Compiler.cpp index be1d38b9c..f19dd3f7f 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -104,10 +104,10 @@ void ExpressionCompiler::endVisit(UnaryOperation& _unaryOperation) switch (_unaryOperation.getOperator()) { case Token::NOT: // ! - append(eth::Instruction::NOT); + append(eth::Instruction::ISZERO); break; case Token::BIT_NOT: // ~ - append(eth::Instruction::BNOT); + append(eth::Instruction::NOT); break; case Token::DELETE: // delete // a -> a xor a (= 0).