LLVM API Documentation
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 public: 00026 SMLoc() : Ptr(nullptr) {} 00027 00028 bool isValid() const { return Ptr != nullptr; } 00029 00030 bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; } 00031 bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; } 00032 00033 const char *getPointer() const { return Ptr; } 00034 00035 static SMLoc getFromPointer(const char *Ptr) { 00036 SMLoc L; 00037 L.Ptr = Ptr; 00038 return L; 00039 } 00040 }; 00041 00042 /// Represents a range in source code. 00043 /// 00044 /// SMRange is implemented using a half-open range, as is the convention in C++. 00045 /// In the string "abc", the range (1,3] represents the substring "bc", and the 00046 /// range (2,2] represents an empty range between the characters "b" and "c". 00047 class SMRange { 00048 public: 00049 SMLoc Start, End; 00050 00051 SMRange() {} 00052 SMRange(SMLoc St, SMLoc En) : Start(St), End(En) { 00053 assert(Start.isValid() == End.isValid() && 00054 "Start and end should either both be valid or both be invalid!"); 00055 } 00056 00057 bool isValid() const { return Start.isValid(); } 00058 }; 00059 00060 } // end namespace llvm 00061 00062 #endif 00063