2008-03-27 06:49:32 +03:00
|
|
|
//===--- PathDiagnostic.cpp - Path-Specific Diagnostic Handling -*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the PathDiagnostic-related interfaces.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Analysis/PathDiagnostic.h"
|
2008-11-19 09:51:40 +03:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2008-03-27 09:16:40 +03:00
|
|
|
#include <sstream>
|
2008-03-27 06:49:32 +03:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
PathDiagnostic::~PathDiagnostic() {
|
|
|
|
for (iterator I = begin(), E = end(); I != E; ++I) delete &*I;
|
|
|
|
}
|
|
|
|
|
This reworks some of the Diagnostic interfaces a bit to change how diagnostics
are formed. In particular, a diagnostic with all its strings and ranges is now
packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a
ton of random stuff. This has the benefit of simplifying the interface, making
it more extensible, and allowing us to do more checking for things like access
past the end of the various arrays passed in.
In addition to introducing DiagnosticInfo, this also substantially changes how
Diagnostic::Report works. Instead of being passed in all of the info required
to issue a diagnostic, Report now takes only the required info (a location and
ID) and returns a fresh DiagnosticInfo *by value*. The caller is then free to
stuff strings and ranges into the DiagnosticInfo with the << operator. When
the dtor runs on the DiagnosticInfo object (which should happen at the end of
the statement), the diagnostic is actually emitted with all of the accumulated
information. This is a somewhat tricky dance, but it means that the
accumulated DiagnosticInfo is allowed to keep pointers to other expression
temporaries without those pointers getting invalidated.
This is just the minimal change to get this stuff working, but this will allow
us to eliminate the zillions of variant "Diag" methods scattered throughout
(e.g.) sema. For example, instead of calling:
Diag(BuiltinLoc, diag::err_overload_no_match, typeNames,
SourceRange(BuiltinLoc, RParenLoc));
We will soon be able to just do:
Diag(BuiltinLoc, diag::err_overload_no_match)
<< typeNames << SourceRange(BuiltinLoc, RParenLoc));
This scales better to support arbitrary types being passed in (not just
strings) in a type-safe way. Go operator overloading?!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59502 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 10:04:44 +03:00
|
|
|
void PathDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
|
|
|
|
const DiagnosticInfo &Info) {
|
2008-03-27 06:49:32 +03:00
|
|
|
|
|
|
|
// Create a PathDiagnostic with a single piece.
|
|
|
|
|
2008-04-22 20:15:03 +04:00
|
|
|
PathDiagnostic* D = new PathDiagnostic();
|
2008-03-27 06:49:32 +03:00
|
|
|
|
2008-11-18 07:44:58 +03:00
|
|
|
const char *LevelStr;
|
2008-03-27 09:16:40 +03:00
|
|
|
switch (DiagLevel) {
|
2009-02-07 06:46:08 +03:00
|
|
|
default:
|
2009-02-06 06:57:44 +03:00
|
|
|
case Diagnostic::Ignored: assert(0 && "Invalid diagnostic type");
|
2008-11-18 07:44:58 +03:00
|
|
|
case Diagnostic::Note: LevelStr = "note: "; break;
|
|
|
|
case Diagnostic::Warning: LevelStr = "warning: "; break;
|
|
|
|
case Diagnostic::Error: LevelStr = "error: "; break;
|
2009-02-06 06:57:44 +03:00
|
|
|
case Diagnostic::Fatal: LevelStr = "fatal error: "; break;
|
2008-03-27 09:16:40 +03:00
|
|
|
}
|
|
|
|
|
2008-11-19 09:51:40 +03:00
|
|
|
llvm::SmallString<100> StrC;
|
|
|
|
StrC += LevelStr;
|
|
|
|
Info.FormatDiagnostic(StrC);
|
2008-03-27 06:49:32 +03:00
|
|
|
|
This reworks some of the Diagnostic interfaces a bit to change how diagnostics
are formed. In particular, a diagnostic with all its strings and ranges is now
packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a
ton of random stuff. This has the benefit of simplifying the interface, making
it more extensible, and allowing us to do more checking for things like access
past the end of the various arrays passed in.
In addition to introducing DiagnosticInfo, this also substantially changes how
Diagnostic::Report works. Instead of being passed in all of the info required
to issue a diagnostic, Report now takes only the required info (a location and
ID) and returns a fresh DiagnosticInfo *by value*. The caller is then free to
stuff strings and ranges into the DiagnosticInfo with the << operator. When
the dtor runs on the DiagnosticInfo object (which should happen at the end of
the statement), the diagnostic is actually emitted with all of the accumulated
information. This is a somewhat tricky dance, but it means that the
accumulated DiagnosticInfo is allowed to keep pointers to other expression
temporaries without those pointers getting invalidated.
This is just the minimal change to get this stuff working, but this will allow
us to eliminate the zillions of variant "Diag" methods scattered throughout
(e.g.) sema. For example, instead of calling:
Diag(BuiltinLoc, diag::err_overload_no_match, typeNames,
SourceRange(BuiltinLoc, RParenLoc));
We will soon be able to just do:
Diag(BuiltinLoc, diag::err_overload_no_match)
<< typeNames << SourceRange(BuiltinLoc, RParenLoc));
This scales better to support arbitrary types being passed in (not just
strings) in a type-safe way. Go operator overloading?!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59502 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 10:04:44 +03:00
|
|
|
PathDiagnosticPiece *P =
|
2008-11-19 09:51:40 +03:00
|
|
|
new PathDiagnosticPiece(Info.getLocation(),
|
|
|
|
std::string(StrC.begin(), StrC.end()));
|
2008-03-27 06:49:32 +03:00
|
|
|
|
This reworks some of the Diagnostic interfaces a bit to change how diagnostics
are formed. In particular, a diagnostic with all its strings and ranges is now
packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a
ton of random stuff. This has the benefit of simplifying the interface, making
it more extensible, and allowing us to do more checking for things like access
past the end of the various arrays passed in.
In addition to introducing DiagnosticInfo, this also substantially changes how
Diagnostic::Report works. Instead of being passed in all of the info required
to issue a diagnostic, Report now takes only the required info (a location and
ID) and returns a fresh DiagnosticInfo *by value*. The caller is then free to
stuff strings and ranges into the DiagnosticInfo with the << operator. When
the dtor runs on the DiagnosticInfo object (which should happen at the end of
the statement), the diagnostic is actually emitted with all of the accumulated
information. This is a somewhat tricky dance, but it means that the
accumulated DiagnosticInfo is allowed to keep pointers to other expression
temporaries without those pointers getting invalidated.
This is just the minimal change to get this stuff working, but this will allow
us to eliminate the zillions of variant "Diag" methods scattered throughout
(e.g.) sema. For example, instead of calling:
Diag(BuiltinLoc, diag::err_overload_no_match, typeNames,
SourceRange(BuiltinLoc, RParenLoc));
We will soon be able to just do:
Diag(BuiltinLoc, diag::err_overload_no_match)
<< typeNames << SourceRange(BuiltinLoc, RParenLoc));
This scales better to support arbitrary types being passed in (not just
strings) in a type-safe way. Go operator overloading?!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59502 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-18 10:04:44 +03:00
|
|
|
for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i)
|
|
|
|
P->addRange(Info.getRange(i));
|
2008-04-22 20:15:03 +04:00
|
|
|
D->push_front(P);
|
2008-03-27 06:49:32 +03:00
|
|
|
|
2008-03-27 09:16:40 +03:00
|
|
|
HandlePathDiagnostic(D);
|
2008-03-27 06:49:32 +03:00
|
|
|
}
|