1 //===- SourceMgr.h - Manager for Source Buffers & Diagnostics ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SourceMgr class. This class is used as a simple
11 // substrate for diagnostics, #include handling, and other low level things for
14 //===----------------------------------------------------------------------===//
31 TGLoc(const TGLoc &RHS) : Ptr(RHS.Ptr) {}
33 bool operator==(const TGLoc &RHS) const { return RHS.Ptr == Ptr; }
34 bool operator!=(const TGLoc &RHS) const { return RHS.Ptr != Ptr; }
36 const char *getPointer() const { return Ptr; }
38 static TGLoc getFromPointer(const char *Ptr) {
45 /// TGSourceMgr - This owns the files read by tblgen, handles include stacks,
46 /// and handles printing of diagnostics.
49 /// Buffer - The memory buffer for the file.
52 /// IncludeLoc - This is the location of the parent include, or null if at
57 /// Buffers - This is all of the buffers that we are reading from.
58 std::vector<SrcBuffer> Buffers;
60 TGSourceMgr(const TGSourceMgr&); // DO NOT IMPLEMENT
61 void operator=(const TGSourceMgr&); // DO NOT IMPLEMENT
66 const SrcBuffer &getBufferInfo(unsigned i) const {
67 assert(i < Buffers.size() && "Invalid Buffer ID!");
71 const MemoryBuffer *getMemoryBuffer(unsigned i) const {
72 assert(i < Buffers.size() && "Invalid Buffer ID!");
73 return Buffers[i].Buffer;
76 TGLoc getParentIncludeLoc(unsigned i) const {
77 assert(i < Buffers.size() && "Invalid Buffer ID!");
78 return Buffers[i].IncludeLoc;
81 unsigned AddNewSourceBuffer(MemoryBuffer *F, TGLoc IncludeLoc) {
84 NB.IncludeLoc = IncludeLoc;
85 Buffers.push_back(NB);
86 return Buffers.size()-1;
89 /// FindBufferContainingLoc - Return the ID of the buffer containing the
90 /// specified location, returning -1 if not found.
91 int FindBufferContainingLoc(TGLoc Loc) const;
93 /// FindLineNumber - Find the line number for the specified location in the
94 /// specified file. This is not a fast method.
95 unsigned FindLineNumber(TGLoc Loc, int BufferID = -1) const;
98 /// PrintError - Emit an error message about the specified location with the
100 void PrintError(TGLoc ErrorLoc, const std::string &Msg) const;
103 void PrintIncludeStack(TGLoc IncludeLoc) const;
106 } // end llvm namespace