diff options
author | Christian Parpart <christian@ethereum.org> | 2018-11-28 23:19:22 +0800 |
---|---|---|
committer | Christian Parpart <christian@ethereum.org> | 2018-12-01 00:07:12 +0800 |
commit | c48a5264be4221873fe02cac57f6a41a32010fea (patch) | |
tree | 441c9c554fb9521f41f4a143dc138a33afb03589 /test | |
parent | 22eff22492b2d569fe56b59763ddc1cd1cf9ccf4 (diff) | |
download | dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.gz dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.bz2 dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.lz dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.xz dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.tar.zst dexon-solidity-c48a5264be4221873fe02cac57f6a41a32010fea.zip |
liblangutil: SourceLocation: adds (shared) pointer to underlying CharStream source, eliminating sourceName
Also, adapted affecting code to those changes.
Diffstat (limited to 'test')
-rw-r--r-- | test/libevmasm/Assembler.cpp | 6 | ||||
-rw-r--r-- | test/libevmasm/Optimiser.cpp | 2 | ||||
-rw-r--r-- | test/liblangutil/SourceLocation.cpp | 14 | ||||
-rw-r--r-- | test/libsolidity/Assembly.cpp | 39 |
4 files changed, 35 insertions, 26 deletions
diff --git a/test/libevmasm/Assembler.cpp b/test/libevmasm/Assembler.cpp index 5ad01594..bece2be4 100644 --- a/test/libevmasm/Assembler.cpp +++ b/test/libevmasm/Assembler.cpp @@ -55,10 +55,12 @@ BOOST_AUTO_TEST_SUITE(Assembler) BOOST_AUTO_TEST_CASE(all_assembly_items) { Assembly _assembly; - _assembly.setSourceLocation(SourceLocation(1, 3, make_shared<string>("root.asm"))); + auto root_asm = make_shared<CharStream>("", "root.asm"); + _assembly.setSourceLocation(SourceLocation(1, 3, root_asm)); Assembly _subAsm; - _subAsm.setSourceLocation(SourceLocation(6, 8, make_shared<string>("sub.asm"))); + auto sub_asm = make_shared<CharStream>("", "sub.asm"); + _subAsm.setSourceLocation(SourceLocation(6, 8, sub_asm)); _subAsm.append(Instruction::INVALID); shared_ptr<Assembly> _subAsmPtr = make_shared<Assembly>(_subAsm); diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp index c061b783..7d102948 100644 --- a/test/libevmasm/Optimiser.cpp +++ b/test/libevmasm/Optimiser.cpp @@ -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, make_shared<string>(""))); + item.setLocation(SourceLocation(1, 3, nullptr)); return input; } diff --git a/test/liblangutil/SourceLocation.cpp b/test/liblangutil/SourceLocation.cpp index ac7a2173..ef4103da 100644 --- a/test/liblangutil/SourceLocation.cpp +++ b/test/liblangutil/SourceLocation.cpp @@ -33,12 +33,16 @@ BOOST_AUTO_TEST_SUITE(SourceLocationTest) BOOST_AUTO_TEST_CASE(test_fail) { + auto const source = std::make_shared<CharStream>("", "source"); + 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, std::make_shared<std::string>("sourceA")) != SourceLocation(0, 3, std::make_shared<std::string>("sourceB"))); - BOOST_CHECK(SourceLocation(0, 3, std::make_shared<std::string>("source")) == SourceLocation(0, 3, std::make_shared<std::string>("source"))); - BOOST_CHECK(SourceLocation(3, 7, std::make_shared<std::string>("source")).contains(SourceLocation(4, 6, std::make_shared<std::string>("source")))); - BOOST_CHECK(!SourceLocation(3, 7, std::make_shared<std::string>("sourceA")).contains(SourceLocation(4, 6, std::make_shared<std::string>("sourceB")))); - BOOST_CHECK(SourceLocation(3, 7, std::make_shared<std::string>("sourceA")) < SourceLocation(4, 6, std::make_shared<std::string>("sourceB"))); + 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() diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index 620f9661..004917d4 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -52,13 +52,13 @@ namespace test namespace { -eth::AssemblyItems compileContract(string const& _sourceCode) +eth::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode) { ErrorList errors; ErrorReporter errorReporter(errors); Parser parser(errorReporter); ASTPointer<SourceUnit> sourceUnit; - BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode, "")))); + BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(_sourceCode))); BOOST_CHECK(!!sourceUnit); map<ASTNode const*, shared_ptr<DeclarationContainer>> scopes; @@ -104,7 +104,7 @@ void printAssemblyLocations(AssemblyItems const& _items) ", " << _loc.end << ", make_shared<string>(\"" << - *_loc.sourceName << + _loc.source->name() << "\"))) +" << endl; }; @@ -151,29 +151,32 @@ BOOST_AUTO_TEST_SUITE(Assembly) BOOST_AUTO_TEST_CASE(location_test) { - char const* sourceCode = R"( + auto sourceCode = make_shared<CharStream>(R"( contract test { function f() public returns (uint256 a) { return 16; } } - )"; + )", ""); AssemblyItems items = compileContract(sourceCode); bool hasShifts = dev::test::Options::get().evmVersion().hasBitwiseShifting(); + + auto codegenCharStream = make_shared<CharStream>("", "--CODEGEN--"); + vector<SourceLocation> locations = - vector<SourceLocation>(hasShifts ? 21 : 22, SourceLocation(2, 82, make_shared<string>(""))) + - vector<SourceLocation>(2, SourceLocation(20, 79, make_shared<string>(""))) + - vector<SourceLocation>(1, SourceLocation(8, 17, make_shared<string>("--CODEGEN--"))) + - vector<SourceLocation>(3, SourceLocation(5, 7, make_shared<string>("--CODEGEN--"))) + - vector<SourceLocation>(1, SourceLocation(30, 31, make_shared<string>("--CODEGEN--"))) + - vector<SourceLocation>(1, SourceLocation(27, 28, make_shared<string>("--CODEGEN--"))) + - vector<SourceLocation>(1, SourceLocation(20, 32, make_shared<string>("--CODEGEN--"))) + - vector<SourceLocation>(1, SourceLocation(5, 7, make_shared<string>("--CODEGEN--"))) + - vector<SourceLocation>(24, SourceLocation(20, 79, make_shared<string>(""))) + - vector<SourceLocation>(1, SourceLocation(49, 58, make_shared<string>(""))) + - vector<SourceLocation>(1, SourceLocation(72, 74, make_shared<string>(""))) + - vector<SourceLocation>(2, SourceLocation(65, 74, make_shared<string>(""))) + - vector<SourceLocation>(2, SourceLocation(20, 79, make_shared<string>(""))); + vector<SourceLocation>(hasShifts ? 21 : 22, SourceLocation(2, 82, sourceCode)) + + vector<SourceLocation>(2, SourceLocation(20, 79, 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>(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); } |