Move #line state into the Parser and out of the SourceManager.

As part of this change, allow #line directives to extend to the end of the
file, rather than requiring a reset.

Note that #line regions that start or end within function bodies will not
behave correctly when in delayed parsing modes. This was true before and
after this commit. (#line regions contained entirely within a function and
not within any other #line regions should be fine.)

Swift SVN r20571
This commit is contained in:
Jordan Rose
2014-07-25 23:01:43 +00:00
parent 071291003b
commit 29f8c25d63
8 changed files with 116 additions and 64 deletions

View File

@@ -19,6 +19,7 @@
#include "swift/Basic/LLVM.h"
#include "llvm/Support/SMLoc.h"
#include <functional>
namespace swift {
class SourceManager;
@@ -29,6 +30,7 @@ namespace swift {
class SourceLoc {
friend class SourceManager;
friend class SourceRange;
friend class CharSourceRange;
friend class DiagnosticConsumer;
llvm::SMLoc Value;
@@ -134,6 +136,14 @@ public:
return SourceLoc();
}
/// Returns true if the given source location is contained in the range.
bool contains(SourceLoc loc) const {
auto less = std::less<const char *>();
auto less_equal = std::less_equal<const char *>();
return less_equal(getStart().Value.getPointer(), loc.Value.getPointer()) &&
less(loc.Value.getPointer(), getEnd().Value.getPointer());
}
/// \brief Return the length of this valid range in bytes. Can be zero.
unsigned getByteLength() const {
assert(isValid() && "length does not make sense for an invalid range");