Normalize SourceMgr messages.
[oota-llvm.git] / include / llvm / Support / SourceMgr.h
index 953cf897b9946d52d135952d7076db0869ad7604..23044a8bd032b822c82d99b39954add0f6e6cb42 100644 (file)
@@ -30,6 +30,8 @@ public:
   SMLoc() : Ptr(0) {}
   SMLoc(const SMLoc &RHS) : Ptr(RHS.Ptr) {}
   
+  bool isValid() const { return Ptr != 0; }
+
   bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
   bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
 
@@ -57,12 +59,20 @@ class SourceMgr {
   /// Buffers - This is all of the buffers that we are reading from.
   std::vector<SrcBuffer> Buffers;
   
+  // IncludeDirectories - This is the list of directories we should search for
+  // include files in.
+  std::vector<std::string> IncludeDirectories;
+  
   SourceMgr(const SourceMgr&);    // DO NOT IMPLEMENT
   void operator=(const SourceMgr&); // DO NOT IMPLEMENT
 public:
   SourceMgr() {}
   ~SourceMgr();
   
+  void setIncludeDirs(const std::vector<std::string> &Dirs) {
+    IncludeDirectories = Dirs;
+  }
+  
   const SrcBuffer &getBufferInfo(unsigned i) const {
     assert(i < Buffers.size() && "Invalid Buffer ID!");
     return Buffers[i];
@@ -86,6 +96,11 @@ public:
     return Buffers.size()-1;
   }
   
+  /// AddIncludeFile - Search for a file with the specified name in the current
+  /// directory or in one of the IncludeDirs.  If no file is found, this returns
+  /// ~0, otherwise it returns the buffer ID of the stacked file.
+  unsigned AddIncludeFile(const std::string &Filename, SMLoc IncludeLoc);
+  
   /// FindBufferContainingLoc - Return the ID of the buffer containing the
   /// specified location, returning -1 if not found.
   int FindBufferContainingLoc(SMLoc Loc) const;
@@ -94,10 +109,12 @@ public:
   /// specified file.  This is not a fast method.
   unsigned FindLineNumber(SMLoc Loc, int BufferID = -1) const;
   
-  
-  /// PrintError - Emit an error message about the specified location with the
+  /// PrintMessage - Emit a message about the specified location with the
   /// specified string.
-  void PrintError(SMLoc ErrorLoc, const std::string &Msg) const;
+  ///
+  /// @param Type - If non-null, the kind of message (e.g., "error") which is
+  /// prefixed to the message.
+  void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
   
 private:
   void PrintIncludeStack(SMLoc IncludeLoc) const;