1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
llvm-mirror/include/llvm/Support/SMLoc.h

65 lines
1.8 KiB
C
Raw Normal View History

//===- SMLoc.h - Source location for use with diagnostics -------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file declares the SMLoc class. This class encapsulates a location in
// source code for use in diagnostics.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_SUPPORT_SMLOC_H
#define LLVM_SUPPORT_SMLOC_H
#include "llvm/ADT/None.h"
#include <cassert>
namespace llvm {
/// Represents a location in source code.
2011-08-29 23:15:20 +02:00
class SMLoc {
const char *Ptr = nullptr;
2015-08-10 06:21:43 +02:00
public:
SMLoc() = default;
2011-08-29 23:15:20 +02:00
bool isValid() const { return Ptr != nullptr; }
2011-08-29 23:15:20 +02:00
bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
2011-08-29 23:15:20 +02:00
const char *getPointer() const { return Ptr; }
2011-08-29 23:15:20 +02:00
static SMLoc getFromPointer(const char *Ptr) {
SMLoc L;
L.Ptr = Ptr;
return L;
}
};
/// Represents a range in source code.
///
/// SMRange is implemented using a half-open range, as is the convention in C++.
2018-05-07 07:21:20 +02:00
/// In the string "abc", the range [1,3) represents the substring "bc", and the
/// range [2,2) represents an empty range between the characters "b" and "c".
class SMRange {
public:
SMLoc Start, End;
SMRange() = default;
SMRange(NoneType) {}
SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
assert(Start.isValid() == End.isValid() &&
2018-05-07 07:21:20 +02:00
"Start and End should either both be valid or both be invalid!");
}
2015-08-10 06:22:09 +02:00
bool isValid() const { return Start.isValid(); }
};
2015-08-10 06:22:09 +02:00
} // end namespace llvm
#endif // LLVM_SUPPORT_SMLOC_H