Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7 KiB

  1. //===- SMLoc.h - Source location for use with diagnostics -------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file declares the SMLoc class. This class encapsulates a location in
  11. // source code for use in diagnostics.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_SUPPORT_SMLOC_H
  15. #define LLVM_SUPPORT_SMLOC_H
  16. #include <cassert>
  17. namespace llvm {
  18. /// Represents a location in source code.
  19. class SMLoc {
  20. const char *Ptr;
  21. public:
  22. SMLoc() : Ptr(0) {}
  23. bool isValid() const { return Ptr != 0; }
  24. bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
  25. bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
  26. const char *getPointer() const { return Ptr; }
  27. static SMLoc getFromPointer(const char *Ptr) {
  28. SMLoc L;
  29. L.Ptr = Ptr;
  30. return L;
  31. }
  32. };
  33. /// Represents a range in source code.
  34. ///
  35. /// SMRange is implemented using a half-open range, as is the convention in C++.
  36. /// In the string "abc", the range (1,3] represents the substring "bc", and the
  37. /// range (2,2] represents an empty range between the characters "b" and "c".
  38. class SMRange {
  39. public:
  40. SMLoc Start, End;
  41. SMRange() {}
  42. SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
  43. assert(Start.isValid() == End.isValid() &&
  44. "Start and end should either both be valid or both be invalid!");
  45. }
  46. bool isValid() const { return Start.isValid(); }
  47. };
  48. } // end namespace llvm
  49. #endif