Home | History | Annotate | Download | only in Support
      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 
     15 #ifndef SUPPORT_SMLOC_H
     16 #define SUPPORT_SMLOC_H
     17 
     18 #include <cassert>
     19 
     20 namespace llvm {
     21 
     22 /// SMLoc - Represents a location in source code.
     23 class SMLoc {
     24   const char *Ptr;
     25 public:
     26   SMLoc() : Ptr(0) {}
     27   SMLoc(const SMLoc &RHS) : Ptr(RHS.Ptr) {}
     28 
     29   bool isValid() const { return Ptr != 0; }
     30 
     31   bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
     32   bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
     33 
     34   const char *getPointer() const { return Ptr; }
     35 
     36   static SMLoc getFromPointer(const char *Ptr) {
     37     SMLoc L;
     38     L.Ptr = Ptr;
     39     return L;
     40   }
     41 };
     42 
     43 /// SMRange - Represents a range in source code.  Note that unlike standard STL
     44 /// ranges, the locations specified are considered to be *inclusive*.  For
     45 /// example, [X,X] *does* include X, it isn't an empty range.
     46 class SMRange {
     47 public:
     48   SMLoc Start, End;
     49 
     50   SMRange() {}
     51   SMRange(SMLoc Start, SMLoc End) : Start(Start), End(End) {
     52     assert(Start.isValid() == End.isValid() &&
     53            "Start and end should either both be valid or both be invalid!");
     54   }
     55 
     56   bool isValid() const { return Start.isValid(); }
     57 };
     58 
     59 } // end namespace llvm
     60 
     61 #endif
     62 
     63