2008-03-27 06:49:32 +03:00
|
|
|
//===--- PathDiagnostic.h - 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_PATH_DIAGNOSTIC_H
|
|
|
|
#define LLVM_CLANG_PATH_DIAGNOSTIC_H
|
|
|
|
|
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
2008-03-27 09:16:40 +03:00
|
|
|
#include <algorithm>
|
2008-03-27 06:49:32 +03:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
class PathDiagnosticPiece {
|
2008-05-07 01:33:07 +04:00
|
|
|
public:
|
|
|
|
enum DisplayHint { Above, Below };
|
|
|
|
|
|
|
|
private:
|
2008-03-27 06:49:32 +03:00
|
|
|
FullSourceLoc Pos;
|
2008-03-27 09:16:40 +03:00
|
|
|
std::string str;
|
2008-05-07 01:33:07 +04:00
|
|
|
DisplayHint Hint;
|
2008-03-27 06:49:32 +03:00
|
|
|
std::vector<SourceRange> ranges;
|
2008-05-07 01:33:07 +04:00
|
|
|
|
2008-03-27 06:49:32 +03:00
|
|
|
public:
|
|
|
|
|
2008-05-07 01:33:07 +04:00
|
|
|
PathDiagnosticPiece(FullSourceLoc pos, const std::string& s,
|
|
|
|
DisplayHint hint = Above)
|
|
|
|
: Pos(pos), str(s), Hint(hint) {}
|
2008-03-27 06:49:32 +03:00
|
|
|
|
2008-05-07 01:33:07 +04:00
|
|
|
PathDiagnosticPiece(FullSourceLoc pos, const char* s,
|
|
|
|
DisplayHint hint = Above)
|
|
|
|
: Pos(pos), str(s), Hint(hint) {}
|
2008-04-02 11:03:43 +04:00
|
|
|
|
2008-03-27 09:16:40 +03:00
|
|
|
const std::string& getString() const { return str; }
|
2008-05-07 01:33:07 +04:00
|
|
|
|
|
|
|
DisplayHint getDisplayHint() const { return Hint; }
|
|
|
|
|
2008-03-27 06:49:32 +03:00
|
|
|
void addRange(SourceRange R) {
|
|
|
|
ranges.push_back(R);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addRange(SourceLocation B, SourceLocation E) {
|
|
|
|
ranges.push_back(SourceRange(B,E));
|
|
|
|
}
|
|
|
|
|
2008-07-24 01:51:42 +04:00
|
|
|
typedef const SourceRange* range_iterator;
|
|
|
|
|
|
|
|
range_iterator ranges_begin() const {
|
2008-03-27 06:49:32 +03:00
|
|
|
return ranges.empty() ? NULL : &ranges[0];
|
|
|
|
}
|
|
|
|
|
2008-07-24 01:51:42 +04:00
|
|
|
range_iterator ranges_end() const {
|
2008-03-27 06:49:32 +03:00
|
|
|
return ranges_begin() + ranges.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const SourceManager& getSourceManager() const {
|
|
|
|
return Pos.getManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
FullSourceLoc getLocation() const { return Pos; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class PathDiagnostic {
|
|
|
|
std::list<PathDiagnosticPiece*> path;
|
|
|
|
unsigned Size;
|
2008-04-02 11:03:43 +04:00
|
|
|
std::string Desc;
|
2008-05-01 03:47:44 +04:00
|
|
|
std::vector<std::string> OtherDesc;
|
2008-05-07 01:33:07 +04:00
|
|
|
|
|
|
|
public:
|
2008-03-27 09:16:40 +03:00
|
|
|
PathDiagnostic() : Size(0) {}
|
2008-05-07 01:33:07 +04:00
|
|
|
|
2008-04-03 00:44:27 +04:00
|
|
|
PathDiagnostic(const char* desc) : Size(0), Desc(desc) {}
|
2008-05-07 01:33:07 +04:00
|
|
|
|
2008-04-03 00:44:27 +04:00
|
|
|
PathDiagnostic(const std::string& desc) : Size(0), Desc(desc) {}
|
2008-03-27 06:49:32 +03:00
|
|
|
|
|
|
|
~PathDiagnostic();
|
|
|
|
|
2008-04-02 11:03:43 +04:00
|
|
|
const std::string& getDescription() const { return Desc; }
|
|
|
|
|
2008-05-01 03:47:44 +04:00
|
|
|
typedef std::vector<std::string>::const_iterator meta_iterator;
|
|
|
|
meta_iterator meta_begin() const { return OtherDesc.begin(); }
|
|
|
|
meta_iterator meta_end() const { return OtherDesc.end(); }
|
|
|
|
void addMeta(const std::string& s) { OtherDesc.push_back(s); }
|
|
|
|
void addMeta(const char* s) { OtherDesc.push_back(s); }
|
|
|
|
|
2008-03-27 06:49:32 +03:00
|
|
|
void push_front(PathDiagnosticPiece* piece) {
|
|
|
|
path.push_front(piece);
|
|
|
|
++Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void push_back(PathDiagnosticPiece* piece) {
|
|
|
|
path.push_back(piece);
|
|
|
|
++Size;
|
|
|
|
}
|
|
|
|
|
2008-04-03 00:35:01 +04:00
|
|
|
PathDiagnosticPiece* back() {
|
|
|
|
return path.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
const PathDiagnosticPiece* back() const {
|
|
|
|
return path.back();
|
|
|
|
}
|
|
|
|
|
2008-03-27 09:16:40 +03:00
|
|
|
unsigned size() const { return Size; }
|
|
|
|
bool empty() const { return Size == 0; }
|
|
|
|
|
2008-03-27 06:49:32 +03:00
|
|
|
class iterator {
|
|
|
|
public:
|
|
|
|
typedef std::list<PathDiagnosticPiece*>::iterator ImplTy;
|
|
|
|
|
2008-03-27 09:16:40 +03:00
|
|
|
typedef PathDiagnosticPiece value_type;
|
|
|
|
typedef value_type& reference;
|
|
|
|
typedef value_type* pointer;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef std::bidirectional_iterator_tag iterator_category;
|
|
|
|
|
2008-03-27 06:49:32 +03:00
|
|
|
private:
|
|
|
|
ImplTy I;
|
|
|
|
|
|
|
|
public:
|
|
|
|
iterator(const ImplTy& i) : I(i) {}
|
|
|
|
|
|
|
|
bool operator==(const iterator& X) const { return I == X.I; }
|
|
|
|
bool operator!=(const iterator& X) const { return I != X.I; }
|
|
|
|
|
|
|
|
PathDiagnosticPiece& operator*() const { return **I; }
|
|
|
|
PathDiagnosticPiece* operator->() const { return *I; }
|
|
|
|
|
|
|
|
iterator& operator++() { ++I; return *this; }
|
|
|
|
iterator& operator--() { --I; return *this; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class const_iterator {
|
|
|
|
public:
|
|
|
|
typedef std::list<PathDiagnosticPiece*>::const_iterator ImplTy;
|
|
|
|
|
2008-03-27 09:16:40 +03:00
|
|
|
typedef const PathDiagnosticPiece value_type;
|
|
|
|
typedef value_type& reference;
|
|
|
|
typedef value_type* pointer;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef std::bidirectional_iterator_tag iterator_category;
|
|
|
|
|
2008-03-27 06:49:32 +03:00
|
|
|
private:
|
|
|
|
ImplTy I;
|
|
|
|
|
|
|
|
public:
|
|
|
|
const_iterator(const ImplTy& i) : I(i) {}
|
|
|
|
|
|
|
|
bool operator==(const const_iterator& X) const { return I == X.I; }
|
|
|
|
bool operator!=(const const_iterator& X) const { return I != X.I; }
|
|
|
|
|
2008-03-27 09:16:40 +03:00
|
|
|
reference operator*() const { return **I; }
|
|
|
|
pointer operator->() const { return *I; }
|
2008-03-27 06:49:32 +03:00
|
|
|
|
|
|
|
const_iterator& operator++() { ++I; return *this; }
|
|
|
|
const_iterator& operator--() { --I; return *this; }
|
|
|
|
};
|
2008-03-27 09:16:40 +03:00
|
|
|
|
|
|
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
|
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
|
|
|
|
|
|
|
|
|
|
// forward iterator creation methods.
|
|
|
|
|
2008-03-27 06:49:32 +03:00
|
|
|
iterator begin() { return path.begin(); }
|
|
|
|
iterator end() { return path.end(); }
|
2008-03-27 09:16:40 +03:00
|
|
|
|
2008-03-27 06:49:32 +03:00
|
|
|
const_iterator begin() const { return path.begin(); }
|
|
|
|
const_iterator end() const { return path.end(); }
|
|
|
|
|
2008-03-27 09:16:40 +03:00
|
|
|
// reverse iterator creation methods.
|
|
|
|
reverse_iterator rbegin() { return reverse_iterator(end()); }
|
|
|
|
const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
|
|
|
|
reverse_iterator rend() { return reverse_iterator(begin()); }
|
|
|
|
const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
|
2008-03-27 06:49:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class PathDiagnosticClient : public DiagnosticClient {
|
|
|
|
public:
|
|
|
|
PathDiagnosticClient() {}
|
|
|
|
virtual ~PathDiagnosticClient() {}
|
|
|
|
|
|
|
|
virtual void HandleDiagnostic(Diagnostic &Diags,
|
|
|
|
Diagnostic::Level DiagLevel,
|
|
|
|
FullSourceLoc Pos,
|
|
|
|
diag::kind ID,
|
|
|
|
const std::string *Strs,
|
|
|
|
unsigned NumStrs,
|
|
|
|
const SourceRange *Ranges,
|
|
|
|
unsigned NumRanges);
|
|
|
|
|
2008-04-22 20:15:03 +04:00
|
|
|
virtual void HandlePathDiagnostic(const PathDiagnostic* D) = 0;
|
2008-03-27 06:49:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} //end clang namespace
|
|
|
|
#endif
|