make use of C++ = default constructor declarations as well as more non-static member initialization syntax.

This commit is contained in:
Christian Parpart 2018-12-12 14:51:22 +01:00
parent d10bae245e
commit 62fe57479e
No known key found for this signature in database
GPG Key ID: 19BC8DD20312C929
27 changed files with 51 additions and 65 deletions

View File

@ -34,8 +34,6 @@ DEV_SIMPLE_EXCEPTION(IndentedWriterError);
class IndentedWriter
{
public:
explicit IndentedWriter(): m_lines(std::vector<Line>{{std::string(), 0}}) {}
// Returns the formatted output.
std::string format() const;
@ -61,7 +59,7 @@ private:
unsigned indentation;
};
std::vector<Line> m_lines;
std::vector<Line> m_lines{{std::string(), 0}};
};
}

View File

@ -45,8 +45,6 @@ using AssemblyPointer = std::shared_ptr<Assembly>;
class Assembly
{
public:
Assembly() {}
AssemblyItem newTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(Tag, m_usedTags++); }
AssemblyItem newPushTag() { assertThrow(m_usedTags < 0xffffffff, AssemblyException, ""); return AssemblyItem(PushTag, m_usedTags++); }
/// Returns a tag identified by the given name. Creates it if it does not yet exist.

View File

@ -304,7 +304,7 @@ KnownState::StoreOperation KnownState::storeInStorage(
AssemblyItem item(Instruction::SSTORE, _location);
Id id = m_expressionClasses->find(item, {_slot, _value}, true, m_sequenceNumber);
StoreOperation operation(StoreOperation::Storage, _slot, m_sequenceNumber, id);
StoreOperation operation{StoreOperation::Storage, _slot, m_sequenceNumber, id};
m_storageContent[_slot] = _value;
// increment a second time so that we get unique sequence numbers for writes
m_sequenceNumber++;
@ -336,7 +336,7 @@ KnownState::StoreOperation KnownState::storeInMemory(Id _slot, Id _value, Source
AssemblyItem item(Instruction::MSTORE, _location);
Id id = m_expressionClasses->find(item, {_slot, _value}, true, m_sequenceNumber);
StoreOperation operation(StoreOperation(StoreOperation::Memory, _slot, m_sequenceNumber, id));
StoreOperation operation{StoreOperation::Memory, _slot, m_sequenceNumber, id};
m_memoryContent[_slot] = _value;
// increment a second time so that we get unique sequence numbers for writes
m_sequenceNumber++;

View File

@ -74,18 +74,13 @@ public:
struct StoreOperation
{
enum Target { Invalid, Memory, Storage };
StoreOperation(): target(Invalid), sequenceNumber(-1) {}
StoreOperation(
Target _target,
Id _slot,
unsigned _sequenceNumber,
Id _expression
): target(_target), slot(_slot), sequenceNumber(_sequenceNumber), expression(_expression) {}
bool isValid() const { return target != Invalid; }
Target target;
Id slot;
unsigned sequenceNumber;
Id expression;
Target target{Invalid};
Id slot{std::numeric_limits<Id>::max()};
unsigned sequenceNumber{std::numeric_limits<unsigned>::max()};
Id expression{std::numeric_limits<Id>::max()};
};
explicit KnownState(

View File

@ -67,9 +67,9 @@ namespace langutil
class CharStream
{
public:
CharStream(): m_position(0) {}
CharStream() = default;
explicit CharStream(std::string const& _source, std::string const& name):
m_source(_source), m_name(name), m_position(0) {}
m_source(_source), m_name(name) {}
int position() const { return m_position; }
bool isPastEndOfInput(size_t _charsForward = 0) const { return (m_position + _charsForward) >= m_source.size(); }
@ -94,7 +94,7 @@ public:
private:
std::string m_source;
std::string m_name;
size_t m_position;
size_t m_position{0};
};
}

View File

@ -39,7 +39,7 @@ class EVMVersion:
boost::equality_comparable<EVMVersion>
{
public:
EVMVersion() {}
EVMVersion() = default;
static EVMVersion homestead() { return {Version::Homestead}; }
static EVMVersion tangerineWhistle() { return {Version::TangerineWhistle}; }

View File

@ -31,28 +31,29 @@ namespace langutil
struct LineColumn
{
int line;
int column;
int line = {-1};
int column = {-1};
LineColumn() = default;
LineColumn(std::tuple<int, int> const& _t): line{std::get<0>(_t)}, column{std::get<1>(_t)} {}
LineColumn(int _line, int _column): line{_line}, column{_column} {}
LineColumn(): line{-1}, column{-1} {}
};
struct SourceReference
{
std::string message; ///< A message that relates to this source reference (such as a warning or an error message).
std::string sourceName; ///< Underlying source name (for example the filename).
LineColumn position; ///< Actual (error) position this source reference is surrounding.
bool multiline; ///< Indicates whether the actual SourceReference is truncated to one line.
std::string text; ///< Extracted source code text (potentially truncated if multiline or too long).
int startColumn; ///< Highlighting range-start of text field.
int endColumn; ///< Highlighting range-end of text field.
std::string message; ///< A message that relates to this source reference (such as a warning or an error message).
std::string sourceName; ///< Underlying source name (for example the filename).
LineColumn position; ///< Actual (error) position this source reference is surrounding.
bool multiline = {false}; ///< Indicates whether the actual SourceReference is truncated to one line.
std::string text; ///< Extracted source code text (potentially truncated if multiline or too long).
int startColumn = {-1}; ///< Highlighting range-start of text field.
int endColumn = {-1}; ///< Highlighting range-end of text field.
/// Constructs a SourceReference containing a message only.
static SourceReference MessageOnly(std::string _msg)
{
return SourceReference{std::move(_msg), "", LineColumn{-1, -1}, false, "", -1, -1};
SourceReference sref;
sref.message = std::move(_msg);
return sref;
}
};

View File

@ -41,7 +41,7 @@ class CodeFragment
public:
using ReadCallback = std::function<std::string(std::string const&)>;
CodeFragment() {}
CodeFragment() = default;
CodeFragment(sp::utree const& _t, CompilerState& _s, ReadCallback const& _readFile, bool _allowASM = false);
static CodeFragment compile(std::string const& _src, CompilerState& _s, ReadCallback const& _readFile);

View File

@ -103,7 +103,8 @@ struct CFGNode
/** Describes the control flow of a function. */
struct FunctionFlow
{
virtual ~FunctionFlow() {}
virtual ~FunctionFlow() = default;
/// Entry node. Control flow of the function starts here.
/// This node is empty and does not have any entries.
CFGNode* entry = nullptr;

View File

@ -46,7 +46,7 @@ using TypePointer = std::shared_ptr<Type const>;
struct ASTAnnotation
{
virtual ~ASTAnnotation() {}
virtual ~ASTAnnotation() = default;
};
struct DocTag
@ -57,7 +57,7 @@ struct DocTag
struct DocumentedAnnotation
{
virtual ~DocumentedAnnotation() {}
virtual ~DocumentedAnnotation() = default;
/// Mapping docstring tag name -> content.
std::multimap<std::string, DocTag> docTags;
};

View File

@ -601,7 +601,6 @@ private:
class BoolType: public Type
{
public:
BoolType() {}
Category category() const override { return Category::Bool; }
std::string richIdentifier() const override { return "t_bool"; }
TypeResult unaryOperatorResult(Token _operator) const override;

View File

@ -49,7 +49,7 @@ protected:
m_context(_compilerContext), m_dataType(_dataType) {}
public:
virtual ~LValue() {}
virtual ~LValue() = default;
/// @returns the number of stack slots occupied by the lvalue reference
virtual unsigned sizeOnStack() const { return 1; }
/// Copies the value of the current lvalue to the top of the stack and, if @a _remove is true,

View File

@ -48,7 +48,7 @@ public:
explicit ASTNodeFactory(Parser const& _parser):
m_parser(_parser), m_location{_parser.position(), -1, _parser.source()} {}
ASTNodeFactory(Parser const& _parser, ASTPointer<ASTNode> const& _childNode):
m_parser(_parser), m_location(_childNode->location()) {}
m_parser(_parser), m_location{_childNode->location()} {}
void markEndPosition() { m_location.end = m_parser.endPosition(); }
void setLocation(SourceLocation const& _location) { m_location = _location; }

View File

@ -47,7 +47,10 @@ private:
struct VarDeclParserOptions
{
// This is actually not needed, but due to a defect in the C++ standard, we have to.
// https://stackoverflow.com/questions/17430377
VarDeclParserOptions() {}
bool allowVar = false;
bool isStateVariable = false;
bool allowIndexed = false;
@ -85,7 +88,7 @@ private:
ASTPointer<EnumDefinition> parseEnumDefinition();
ASTPointer<EnumValue> parseEnumValue();
ASTPointer<VariableDeclaration> parseVariableDeclaration(
VarDeclParserOptions const& _options = VarDeclParserOptions(),
VarDeclParserOptions const& _options = {},
ASTPointer<TypeName> const& _lookAheadArrayType = ASTPointer<TypeName>()
);
ASTPointer<ModifierDefinition> parseModifierDefinition();
@ -99,7 +102,7 @@ private:
ASTPointer<FunctionTypeName> parseFunctionType();
ASTPointer<Mapping> parseMapping();
ASTPointer<ParameterList> parseParameterList(
VarDeclParserOptions const& _options,
VarDeclParserOptions const& _options = {},
bool _allowEmpty = true
);
ASTPointer<Block> parseBlock(ASTPointer<ASTString> const& _docString = {});

View File

@ -54,7 +54,7 @@ struct Dialect: boost::noncopyable
virtual BuiltinFunction const* builtin(YulString /*_name*/) const { return nullptr; }
Dialect(AsmFlavour _flavour): flavour(_flavour) {}
virtual ~Dialect() {}
virtual ~Dialect() = default;
static std::shared_ptr<Dialect> yul()
{

View File

@ -37,7 +37,7 @@ struct AsmAnalysisInfo;
*/
struct ObjectNode
{
virtual ~ObjectNode() {}
virtual ~ObjectNode() = default;
virtual std::string toString(bool _yul) const = 0;
YulString name;

View File

@ -42,10 +42,9 @@ public:
size_t id;
std::uint64_t hash;
};
YulStringRepository():
m_strings{std::make_shared<std::string>()},
m_hashToID{std::make_pair(emptyHash(), 0)}
{}
YulStringRepository() = default;
static YulStringRepository& instance()
{
static YulStringRepository inst;
@ -80,9 +79,10 @@ public:
return hash;
}
static constexpr std::uint64_t emptyHash() { return 14695981039346656037u; }
private:
std::vector<std::shared_ptr<std::string>> m_strings;
std::unordered_multimap<std::uint64_t, size_t> m_hashToID;
std::vector<std::shared_ptr<std::string>> m_strings = {std::make_shared<std::string>()};
std::unordered_multimap<std::uint64_t, size_t> m_hashToID = {{emptyHash(), 0}};
};
/// Wrapper around handles into the YulString repository.

View File

@ -55,7 +55,7 @@ public:
using LabelID = size_t;
using SubID = size_t;
virtual ~AbstractAssembly() {}
virtual ~AbstractAssembly() = default;
/// Set a new source location valid starting from the next instruction.
virtual void setSourceLocation(langutil::SourceLocation const& _location) = 0;

View File

@ -38,7 +38,7 @@ class EVMAssembly: public AbstractAssembly
{
public:
explicit EVMAssembly(bool _evm15 = false): m_evm15(_evm15) { }
virtual ~EVMAssembly() {}
virtual ~EVMAssembly() = default;
/// Set a new source location valid starting from the next instruction.
void setSourceLocation(langutil::SourceLocation const& _location) override;

View File

@ -38,7 +38,7 @@ using namespace dev::solidity;
EVMDialect::EVMDialect(AsmFlavour _flavour, bool _objectAccess):
Dialect(_flavour), m_objectAccess(_objectAccess)
Dialect{_flavour}, m_objectAccess(_objectAccess)
{
// The EVM instructions will be moved to builtins at some point.
if (!m_objectAccess)

View File

@ -115,7 +115,7 @@ public:
static void run(Block& _ast);
private:
RedundantAssignEliminator() {}
RedundantAssignEliminator() = default;
class State
{

View File

@ -41,8 +41,6 @@ enum class DocumentationType: uint8_t;
class CommandLineInterface
{
public:
CommandLineInterface() {}
/// Parse command line arguments and return false if we should not continue
bool parseArguments(int _argc, char** _argv);
/// Parse the files and create source code objects

View File

@ -36,7 +36,7 @@ class TestCase
public:
using TestCaseCreator = std::unique_ptr<TestCase>(*)(std::string const&);
virtual ~TestCase() {}
virtual ~TestCase() = default;
/// Runs the test case.
/// Outputs error messages to @arg _stream. Each line of output is prefixed with @arg _linePrefix.

View File

@ -44,7 +44,6 @@ namespace test
class GasMeterTestFramework: public SolidityExecutionFramework
{
public:
GasMeterTestFramework() { }
void compile(string const& _sourceCode)
{
m_compiler.reset(false);

View File

@ -38,8 +38,6 @@ namespace test
class JSONInterfaceChecker
{
public:
JSONInterfaceChecker(): m_compilerStack() {}
void checkInterface(std::string const& _code, std::string const& _contractName, std::string const& _expectedInterfaceString)
{
m_compilerStack.reset(false);

View File

@ -39,8 +39,6 @@ namespace test
class DocumentationChecker
{
public:
DocumentationChecker(): m_compilerStack() {}
void checkNatspec(
std::string const& _code,
std::string const& _contractName,

View File

@ -45,8 +45,6 @@ namespace test
class OptimizerTestFramework: public SolidityExecutionFramework
{
public:
OptimizerTestFramework() { }
bytes const& compileAndRunWithOptimizer(
std::string const& _sourceCode,
u256 const& _value = 0,