LLVM  mainline
SMLoc.h
Go to the documentation of this file.
00001 //===- SMLoc.h - Source location for use with diagnostics -------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the SMLoc class.  This class encapsulates a location in
00011 // source code for use in diagnostics.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_SUPPORT_SMLOC_H
00016 #define LLVM_SUPPORT_SMLOC_H
00017 
00018 #include <cassert>
00019 
00020 namespace llvm {
00021 
00022 /// Represents a location in source code.
00023 class SMLoc {
00024   const char *Ptr;
00025 
00026 public:
00027   SMLoc() : Ptr(nullptr) {}
00028 
00029   bool isValid() const { return Ptr != nullptr; }
00030 
00031   bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
00032   bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
00033 
00034   const char *getPointer() const { return Ptr; }
00035 
00036   static SMLoc getFromPointer(const char *Ptr) {
00037     SMLoc L;
00038     L.Ptr = Ptr;
00039     return L;
00040   }
00041 };
00042 
00043 /// Represents a range in source code.
00044 ///
00045 /// SMRange is implemented using a half-open range, as is the convention in C++.
00046 /// In the string "abc", the range (1,3] represents the substring "bc", and the
00047 /// range (2,2] represents an empty range between the characters "b" and "c".
00048 class SMRange {
00049 public:
00050   SMLoc Start, End;
00051 
00052   SMRange() {}
00053   SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
00054     assert(Start.isValid() == End.isValid() &&
00055            "Start and end should either both be valid or both be invalid!");
00056   }
00057 
00058   bool isValid() const { return Start.isValid(); }
00059 };
00060 
00061 } // end namespace llvm
00062 
00063 #endif