mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
liblangutil: SourceLocation to default initialize data members (w/o the use of ctor)
See: http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c45-dont-define-a-default-constructor-that-only-initializes-data-members-use-in-class-member-initializers-instead
This commit is contained in:
parent
678a95f6e3
commit
d10bae245e
@ -100,10 +100,10 @@ void ParserBase::decreaseRecursionDepth()
|
||||
|
||||
void ParserBase::parserError(string const& _description)
|
||||
{
|
||||
m_errorReporter.parserError(SourceLocation(position(), endPosition(), source()), _description);
|
||||
m_errorReporter.parserError(SourceLocation{position(), endPosition(), source()}, _description);
|
||||
}
|
||||
|
||||
void ParserBase::fatalParserError(string const& _description)
|
||||
{
|
||||
m_errorReporter.fatalParserError(SourceLocation(position(), endPosition(), source()), _description);
|
||||
m_errorReporter.fatalParserError(SourceLocation{position(), endPosition(), source()}, _description);
|
||||
}
|
||||
|
@ -38,10 +38,6 @@ namespace langutil
|
||||
*/
|
||||
struct SourceLocation
|
||||
{
|
||||
SourceLocation(): start(-1), end(-1), source{nullptr} { }
|
||||
SourceLocation(int _start, int _end, std::shared_ptr<CharStream> _source):
|
||||
start(_start), end(_end), source{std::move(_source)} { }
|
||||
|
||||
bool operator==(SourceLocation const& _other) const
|
||||
{
|
||||
return source.get() == _other.source.get() && start == _other.start && end == _other.end;
|
||||
@ -53,8 +49,8 @@ struct SourceLocation
|
||||
|
||||
bool isEmpty() const { return start == -1 && end == -1; }
|
||||
|
||||
int start;
|
||||
int end;
|
||||
int start = -1;
|
||||
int end = -1;
|
||||
std::shared_ptr<CharStream> source;
|
||||
};
|
||||
|
||||
|
@ -46,7 +46,7 @@ class Parser::ASTNodeFactory
|
||||
{
|
||||
public:
|
||||
explicit ASTNodeFactory(Parser const& _parser):
|
||||
m_parser(_parser), m_location(_parser.position(), -1, _parser.source()) {}
|
||||
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()) {}
|
||||
|
||||
|
@ -56,11 +56,11 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
|
||||
{
|
||||
Assembly _assembly;
|
||||
auto root_asm = make_shared<CharStream>("", "root.asm");
|
||||
_assembly.setSourceLocation(SourceLocation(1, 3, root_asm));
|
||||
_assembly.setSourceLocation({1, 3, root_asm});
|
||||
|
||||
Assembly _subAsm;
|
||||
auto sub_asm = make_shared<CharStream>("", "sub.asm");
|
||||
_subAsm.setSourceLocation(SourceLocation(6, 8, sub_asm));
|
||||
_subAsm.setSourceLocation({6, 8, sub_asm});
|
||||
_subAsm.append(Instruction::INVALID);
|
||||
shared_ptr<Assembly> _subAsmPtr = make_shared<Assembly>(_subAsm);
|
||||
|
||||
|
@ -53,7 +53,7 @@ namespace
|
||||
// add dummy locations to each item so that we can check that they are not deleted
|
||||
AssemblyItems input = _input;
|
||||
for (AssemblyItem& item: input)
|
||||
item.setLocation(SourceLocation(1, 3, nullptr));
|
||||
item.setLocation({1, 3, nullptr});
|
||||
return input;
|
||||
}
|
||||
|
||||
|
@ -37,12 +37,12 @@ BOOST_AUTO_TEST_CASE(test_fail)
|
||||
auto const sourceA = std::make_shared<CharStream>("", "sourceA");
|
||||
auto const sourceB = std::make_shared<CharStream>("", "sourceB");
|
||||
|
||||
BOOST_CHECK(SourceLocation() == SourceLocation());
|
||||
BOOST_CHECK(SourceLocation(0, 3, sourceA) != SourceLocation(0, 3, sourceB));
|
||||
BOOST_CHECK(SourceLocation(0, 3, source) == SourceLocation(0, 3, source));
|
||||
BOOST_CHECK(SourceLocation(3, 7, source).contains(SourceLocation(4, 6, source)));
|
||||
BOOST_CHECK(!SourceLocation(3, 7, sourceA).contains(SourceLocation(4, 6, sourceB)));
|
||||
BOOST_CHECK(SourceLocation(3, 7, sourceA) < SourceLocation(4, 6, sourceB));
|
||||
BOOST_CHECK(SourceLocation{} == SourceLocation{});
|
||||
BOOST_CHECK((SourceLocation{0, 3, sourceA} != SourceLocation{0, 3, sourceB}));
|
||||
BOOST_CHECK((SourceLocation{0, 3, source} == SourceLocation{0, 3, source}));
|
||||
BOOST_CHECK((SourceLocation{3, 7, source}.contains(SourceLocation{4, 6, source})));
|
||||
BOOST_CHECK((!SourceLocation{3, 7, sourceA}.contains(SourceLocation{4, 6, sourceB})));
|
||||
BOOST_CHECK((SourceLocation{3, 7, sourceA} < SourceLocation{4, 6, sourceB}));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -165,19 +165,19 @@ BOOST_AUTO_TEST_CASE(location_test)
|
||||
auto codegenCharStream = make_shared<CharStream>("", "--CODEGEN--");
|
||||
|
||||
vector<SourceLocation> locations =
|
||||
vector<SourceLocation>(4, SourceLocation(2, 82, sourceCode)) +
|
||||
vector<SourceLocation>(1, SourceLocation(8, 17, codegenCharStream)) +
|
||||
vector<SourceLocation>(3, SourceLocation(5, 7, codegenCharStream)) +
|
||||
vector<SourceLocation>(1, SourceLocation(30, 31, codegenCharStream)) +
|
||||
vector<SourceLocation>(1, SourceLocation(27, 28, codegenCharStream)) +
|
||||
vector<SourceLocation>(1, SourceLocation(20, 32, codegenCharStream)) +
|
||||
vector<SourceLocation>(1, SourceLocation(5, 7, codegenCharStream)) +
|
||||
vector<SourceLocation>(hasShifts ? 19 : 20, SourceLocation(2, 82, sourceCode)) +
|
||||
vector<SourceLocation>(24, SourceLocation(20, 79, sourceCode)) +
|
||||
vector<SourceLocation>(1, SourceLocation(49, 58, sourceCode)) +
|
||||
vector<SourceLocation>(1, SourceLocation(72, 74, sourceCode)) +
|
||||
vector<SourceLocation>(2, SourceLocation(65, 74, sourceCode)) +
|
||||
vector<SourceLocation>(2, SourceLocation(20, 79, sourceCode));
|
||||
vector<SourceLocation>(4, SourceLocation{2, 82, sourceCode}) +
|
||||
vector<SourceLocation>(1, SourceLocation{8, 17, codegenCharStream}) +
|
||||
vector<SourceLocation>(3, SourceLocation{5, 7, codegenCharStream}) +
|
||||
vector<SourceLocation>(1, SourceLocation{30, 31, codegenCharStream}) +
|
||||
vector<SourceLocation>(1, SourceLocation{27, 28, codegenCharStream}) +
|
||||
vector<SourceLocation>(1, SourceLocation{20, 32, codegenCharStream}) +
|
||||
vector<SourceLocation>(1, SourceLocation{5, 7, codegenCharStream}) +
|
||||
vector<SourceLocation>(hasShifts ? 19 : 20, SourceLocation{2, 82, sourceCode}) +
|
||||
vector<SourceLocation>(24, SourceLocation{20, 79, sourceCode}) +
|
||||
vector<SourceLocation>(1, SourceLocation{49, 58, sourceCode}) +
|
||||
vector<SourceLocation>(1, SourceLocation{72, 74, sourceCode}) +
|
||||
vector<SourceLocation>(2, SourceLocation{65, 74, sourceCode}) +
|
||||
vector<SourceLocation>(2, SourceLocation{20, 79, sourceCode});
|
||||
checkAssemblyLocations(items, locations);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user