Replaced SourceLocation::isEmpty() with isValid() and hasText().

The function SourceLocation::isEmpty() had somewhat dual role.
Sometimes it indicates that the SourceLocation is invalid.
Sometimes it means that there is no corresponding source text.

Hence the proposal is to replace it with two functions, isValid() and hasText().

I also removed Scanner::sourceAt(). (Do we have a rule of thumb to remove unused code?)

Since hasText() checks that start and end are valid indices for source, I adjusted a couple of tests to avoid empty source strings.
This commit is contained in:
alex
2020-02-03 08:04:21 +01:00
committed by alex
parent b6190e06a5
commit e4b18e85e6
11 changed files with 31 additions and 29 deletions
+2 -2
View File
@@ -51,11 +51,11 @@ BOOST_AUTO_TEST_SUITE(Assembler)
BOOST_AUTO_TEST_CASE(all_assembly_items)
{
Assembly _assembly;
auto root_asm = make_shared<CharStream>("", "root.asm");
auto root_asm = make_shared<CharStream>("lorem ipsum", "root.asm");
_assembly.setSourceLocation({1, 3, root_asm});
Assembly _subAsm;
auto sub_asm = make_shared<CharStream>("", "sub.asm");
auto sub_asm = make_shared<CharStream>("lorem ipsum", "sub.asm");
_subAsm.setSourceLocation({6, 8, sub_asm});
_subAsm.append(Instruction::INVALID);
shared_ptr<Assembly> _subAsmPtr = make_shared<Assembly>(_subAsm);