Modified MCAsmLexer to return error information upward
authorSean Callanan <scallanan@apple.com>
Wed, 20 Jan 2010 22:18:24 +0000 (22:18 +0000)
committerSean Callanan <scallanan@apple.com>
Wed, 20 Jan 2010 22:18:24 +0000 (22:18 +0000)
rather than printing it locally, reducing its dependence
on SourceMgr.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94041 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAsmLexer.h
tools/llvm-mc/AsmLexer.cpp
tools/llvm-mc/AsmParser.cpp

index e9a6e3fda4ae4e386b242803c1ae49899b5d30a2..bec6ede4ae2bae1d078625d73a394be3c7b27b48 100644 (file)
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/System/DataTypes.h"
+#include "llvm/Support/SMLoc.h"
 
 namespace llvm {
 class MCAsmLexer;
 class MCInst;
-class SMLoc;
 class Target;
 
 /// AsmToken - Target independent representation for an assembler token.
@@ -103,6 +103,10 @@ public:
 class MCAsmLexer {
   /// The current token, stored in the base class for faster access.
   AsmToken CurTok;
+  
+  /// The location and description of the current error
+  SMLoc ErrLoc;
+  std::string Err;
 
   MCAsmLexer(const MCAsmLexer &);   // DO NOT IMPLEMENT
   void operator=(const MCAsmLexer &);  // DO NOT IMPLEMENT
@@ -110,7 +114,12 @@ protected: // Can only create subclasses.
   MCAsmLexer();
 
   virtual AsmToken LexToken() = 0;
-
+  
+  void SetError(const SMLoc &errLoc, const std::string &err) {
+    ErrLoc = errLoc;
+    Err = err;
+  }
+  
 public:
   virtual ~MCAsmLexer();
 
@@ -126,6 +135,16 @@ public:
   const AsmToken &getTok() {
     return CurTok;
   }
+  
+  /// getErrLoc - Get the current error location
+  const SMLoc &getErrLoc() {
+    return ErrLoc;
+  }
+           
+  /// getErr - Get the current error string
+  const std::string &getErr() {
+    return Err;
+  }
 
   /// getKind - Get the kind of current token.
   AsmToken::TokenKind getKind() const { return CurTok.getKind(); }
index ba0d247d46cd4772dacf31a359aee6f537f39afb..758fac4cd2b769713f63820cf220a5885fdc4af8 100644 (file)
@@ -44,7 +44,8 @@ void AsmLexer::PrintMessage(SMLoc Loc, const std::string &Msg,
 /// ReturnError - Set the error to the specified string at the specified
 /// location.  This is defined to always return AsmToken::Error.
 AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) {
-  PrintMessage(SMLoc::getFromPointer(Loc), Msg, "error");
+  SetError(SMLoc::getFromPointer(Loc), Msg);
+  
   return AsmToken(AsmToken::Error, StringRef(Loc, 0));
 }
 
index ab37eb838300ce9018f5e0dc8fab346f5f88806a..eb77e8d395bd7f77874611425d50bc855488d45f 100644 (file)
@@ -101,7 +101,12 @@ bool AsmParser::TokError(const char *Msg) {
 }
 
 const AsmToken &AsmParser::Lex() {
-  return Lexer.Lex();
+  const AsmToken &tok = Lexer.Lex();
+  
+  if (tok.is(AsmToken::Error))
+    Lexer.PrintMessage(Lexer.getErrLoc(), Lexer.getErr(), "error");
+  
+  return tok;
 }
 
 bool AsmParser::Run() {