Add Diagnostic::Report method for reporting diagnostics without a location.

llvm-svn: 86760
This commit is contained in:
Daniel Dunbar 2009-11-10 23:55:23 +00:00
parent 3835610902
commit 93097b3906
5 changed files with 21 additions and 26 deletions

View File

@ -386,6 +386,7 @@ public:
/// @c Pos represents the source location associated with the diagnostic,
/// which can be an invalid location if no position information is available.
inline DiagnosticBuilder Report(FullSourceLoc Pos, unsigned DiagID);
inline DiagnosticBuilder Report(unsigned DiagID);
/// \brief Clear out the current diagnostic.
void Clear() { CurDiagID = ~0U; }
@ -671,6 +672,9 @@ inline DiagnosticBuilder Diagnostic::Report(FullSourceLoc Loc, unsigned DiagID){
CurDiagID = DiagID;
return DiagnosticBuilder(this);
}
inline DiagnosticBuilder Diagnostic::Report(unsigned DiagID) {
return Report(FullSourceLoc(), DiagID);
}
//===----------------------------------------------------------------------===//
// DiagnosticInfo

View File

@ -48,7 +48,7 @@ class Driver {
public:
// Diag - Forwarding function for diagnostics.
DiagnosticBuilder Diag(unsigned DiagID) const {
return Diags.Report(FullSourceLoc(), DiagID);
return Diags.Report(DiagID);
}
// FIXME: Privatize once interface is stable.

View File

@ -100,8 +100,7 @@ bool clang::ProcessWarningOptions(Diagnostic &Diags,
}
if (Diags.setDiagnosticGroupMapping(OptStart, Mapping))
Diags.Report(FullSourceLoc(), diag::warn_unknown_warning_option)
<< ("-W" + Opt);
Diags.Report(diag::warn_unknown_warning_option) << ("-W" + Opt);
}
return false;

View File

@ -411,8 +411,7 @@ static void InvalidPTH(Diagnostic *Diags, Diagnostic::Level level,
const char* Msg = 0) {
if (!Diags) return;
if (!Msg) Msg = "Invalid or corrupted PTH file";
unsigned DiagID = Diags->getCustomDiagID(level, Msg);
Diags->Report(FullSourceLoc(), DiagID);
Diags->Report(Diags->getCustomDiagID(level, Msg));
}
PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
@ -423,9 +422,9 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
if (!File) {
if (Diags) {
unsigned DiagID = Diags->getCustomDiagID(level,
"PTH file %0 could not be read");
Diags->Report(FullSourceLoc(), DiagID) << file;
unsigned DiagID =Diags->getCustomDiagID(level,
"PTH file %0 could not be read");
Diags->Report(DiagID) << file;
}
return 0;

View File

@ -862,16 +862,14 @@ static bool InitializeSourceManager(Preprocessor &PP,
const FileEntry *File = FileMgr.getFile(InFile);
if (File) SourceMgr.createMainFileID(File, SourceLocation());
if (SourceMgr.getMainFileID().isInvalid()) {
PP.getDiagnostics().Report(FullSourceLoc(), diag::err_fe_error_reading)
<< InFile.c_str();
PP.getDiagnostics().Report(diag::err_fe_error_reading) << InFile.c_str();
return true;
}
} else {
llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getSTDIN();
SourceMgr.createMainFileIDForMemBuffer(SB);
if (SourceMgr.getMainFileID().isInvalid()) {
PP.getDiagnostics().Report(FullSourceLoc(),
diag::err_fe_error_reading_stdin);
PP.getDiagnostics().Report(diag::err_fe_error_reading_stdin);
return true;
}
}
@ -1576,8 +1574,7 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
Context));
if (!Consumer.get()) {
PP.getDiagnostics().Report(FullSourceLoc(),
diag::err_fe_invalid_ast_action);
PP.getDiagnostics().Report(diag::err_fe_invalid_ast_action);
return;
}
@ -1804,8 +1801,7 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
// Set up the creation routine for code-completion.
CreateCodeCompleter = BuildPrintingCodeCompleter;
} else {
PP.getDiagnostics().Report(FullSourceLoc(),
diag::err_fe_invalid_code_complete_file)
PP.getDiagnostics().Report(diag::err_fe_invalid_code_complete_file)
<< CodeCompletionAt.FileName;
}
}
@ -1904,7 +1900,7 @@ static void ProcessASTInputFile(const CompilerInvocation &CompOpts,
std::string Error;
llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, &Error));
if (!AST) {
Diags.Report(FullSourceLoc(), diag::err_fe_invalid_ast_file) << Error;
Diags.Report(diag::err_fe_invalid_ast_file) << Error;
return;
}
@ -1917,7 +1913,7 @@ static void ProcessASTInputFile(const CompilerInvocation &CompOpts,
OutPath, Context));
if (!Consumer.get()) {
Diags.Report(FullSourceLoc(), diag::err_fe_invalid_ast_action);
Diags.Report(diag::err_fe_invalid_ast_action);
return;
}
@ -1960,7 +1956,7 @@ InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
static void LLVMErrorHandler(void *UserData, const std::string &Message) {
Diagnostic &Diags = *static_cast<Diagnostic*>(UserData);
Diags.Report(FullSourceLoc(), diag::err_fe_error_backend) << Message;
Diags.Report(diag::err_fe_error_backend) << Message;
// We cannot recover from llvm errors.
exit(1);
@ -2131,16 +2127,14 @@ int main(int argc, char **argv) {
Target(TargetInfo::CreateTargetInfo(Triple.getTriple()));
if (Target == 0) {
Diags.Report(FullSourceLoc(), diag::err_fe_unknown_triple)
<< Triple.getTriple().c_str();
Diags.Report(diag::err_fe_unknown_triple) << Triple.getTriple().c_str();
return 1;
}
// Set the target ABI if specified.
if (!TargetABI.empty()) {
if (!Target->setABI(TargetABI)) {
Diags.Report(FullSourceLoc(), diag::err_fe_unknown_target_abi)
<< TargetABI;
Diags.Report(diag::err_fe_unknown_target_abi) << TargetABI;
return 1;
}
}
@ -2195,15 +2189,14 @@ int main(int argc, char **argv) {
// Handle generating dependencies, if requested.
if (!DependencyFile.empty()) {
if (DependencyTargets.empty()) {
Diags.Report(FullSourceLoc(), diag::err_fe_dependency_file_requires_MT);
Diags.Report(diag::err_fe_dependency_file_requires_MT);
continue;
}
std::string ErrStr;
llvm::raw_ostream *DependencyOS =
new llvm::raw_fd_ostream(DependencyFile.c_str(), ErrStr);
if (!ErrStr.empty()) {
Diags.Report(FullSourceLoc(), diag::err_fe_error_opening)
<< DependencyFile << ErrStr;
Diags.Report(diag::err_fe_error_opening) << DependencyFile << ErrStr;
continue;
}