1 //===- TGSourceMgr.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 TGSourceMgr class.
12 //===----------------------------------------------------------------------===//
29 TGLoc(const TGLoc &RHS) : Ptr(RHS.Ptr) {}
31 bool operator==(const TGLoc &RHS) const { return RHS.Ptr == Ptr; }
32 bool operator!=(const TGLoc &RHS) const { return RHS.Ptr != Ptr; }
34 const char *getPointer() const { return Ptr; }
36 static TGLoc getFromPointer(const char *Ptr) {
43 /// TGSourceMgr - This owns the files read by tblgen, handles include stacks,
44 /// and handles printing of diagnostics.
47 /// Buffer - The memory buffer for the file.
50 /// IncludeLoc - This is the location of the parent include, or null if at
55 /// Buffers - This is all of the buffers that we are reading from.
56 std::vector<SrcBuffer> Buffers;
58 TGSourceMgr(const TGSourceMgr&); // DO NOT IMPLEMENT
59 void operator=(const TGSourceMgr&); // DO NOT IMPLEMENT
64 const SrcBuffer &getBufferInfo(unsigned i) const {
65 assert(i < Buffers.size() && "Invalid Buffer ID!");
69 const MemoryBuffer *getMemoryBuffer(unsigned i) const {
70 assert(i < Buffers.size() && "Invalid Buffer ID!");
71 return Buffers[i].Buffer;
74 TGLoc getParentIncludeLoc(unsigned i) const {
75 assert(i < Buffers.size() && "Invalid Buffer ID!");
76 return Buffers[i].IncludeLoc;
79 unsigned AddNewSourceBuffer(MemoryBuffer *F, TGLoc IncludeLoc) {
82 NB.IncludeLoc = IncludeLoc;
83 Buffers.push_back(NB);
84 return Buffers.size()-1;
87 /// FindBufferContainingLoc - Return the ID of the buffer containing the
88 /// specified location, returning -1 if not found.
89 int FindBufferContainingLoc(TGLoc Loc) const;
91 /// FindLineNumber - Find the line number for the specified location in the
92 /// specified file. This is not a fast method.
93 unsigned FindLineNumber(TGLoc Loc, int BufferID = -1) const;
96 /// PrintError - Emit an error message about the specified location with the
98 void PrintError(TGLoc ErrorLoc, const std::string &Msg) const;
101 void PrintIncludeStack(TGLoc IncludeLoc) const;
104 } // end llvm namespace