forked from OSchip/llvm-project
unique_ptrify Directives in VerifyDiagnosticConsumer
llvm-svn: 216740
This commit is contained in:
parent
33bba9f440
commit
93106514a9
|
@ -145,9 +145,12 @@ public:
|
||||||
///
|
///
|
||||||
class Directive {
|
class Directive {
|
||||||
public:
|
public:
|
||||||
static Directive *create(bool RegexKind, SourceLocation DirectiveLoc,
|
static std::unique_ptr<Directive> create(bool RegexKind,
|
||||||
SourceLocation DiagnosticLoc, bool MatchAnyLine,
|
SourceLocation DirectiveLoc,
|
||||||
StringRef Text, unsigned Min, unsigned Max);
|
SourceLocation DiagnosticLoc,
|
||||||
|
bool MatchAnyLine, StringRef Text,
|
||||||
|
unsigned Min, unsigned Max);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Constant representing n or more matches.
|
/// Constant representing n or more matches.
|
||||||
static const unsigned MaxCount = UINT_MAX;
|
static const unsigned MaxCount = UINT_MAX;
|
||||||
|
@ -181,7 +184,7 @@ public:
|
||||||
void operator=(const Directive &) LLVM_DELETED_FUNCTION;
|
void operator=(const Directive &) LLVM_DELETED_FUNCTION;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<Directive*> DirectiveList;
|
typedef std::vector<std::unique_ptr<Directive>> DirectiveList;
|
||||||
|
|
||||||
/// ExpectedData - owns directive objects and deletes on destructor.
|
/// ExpectedData - owns directive objects and deletes on destructor.
|
||||||
///
|
///
|
||||||
|
@ -192,13 +195,11 @@ public:
|
||||||
DirectiveList Notes;
|
DirectiveList Notes;
|
||||||
|
|
||||||
void Reset() {
|
void Reset() {
|
||||||
llvm::DeleteContainerPointers(Errors);
|
Errors.clear();
|
||||||
llvm::DeleteContainerPointers(Warnings);
|
Warnings.clear();
|
||||||
llvm::DeleteContainerPointers(Remarks);
|
Remarks.clear();
|
||||||
llvm::DeleteContainerPointers(Notes);
|
Notes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
~ExpectedData() { Reset(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DirectiveStatus {
|
enum DirectiveStatus {
|
||||||
|
|
|
@ -502,13 +502,12 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct new directive.
|
// Construct new directive.
|
||||||
std::unique_ptr<Directive> D(
|
std::unique_ptr<Directive> D = Directive::create(
|
||||||
Directive::create(RegexKind, Pos, ExpectedLoc, MatchAnyLine, Text,
|
RegexKind, Pos, ExpectedLoc, MatchAnyLine, Text, Min, Max);
|
||||||
Min, Max));
|
|
||||||
|
|
||||||
std::string Error;
|
std::string Error;
|
||||||
if (D->isValid(Error)) {
|
if (D->isValid(Error)) {
|
||||||
DL->push_back(D.release());
|
DL->push_back(std::move(D));
|
||||||
FoundDirective = true;
|
FoundDirective = true;
|
||||||
} else {
|
} else {
|
||||||
Diags.Report(Pos.getLocWithOffset(ContentBegin-PH.Begin),
|
Diags.Report(Pos.getLocWithOffset(ContentBegin-PH.Begin),
|
||||||
|
@ -644,15 +643,16 @@ static unsigned PrintUnexpected(DiagnosticsEngine &Diags, SourceManager *SourceM
|
||||||
|
|
||||||
/// \brief Takes a list of diagnostics that were expected to have been generated
|
/// \brief Takes a list of diagnostics that were expected to have been generated
|
||||||
/// but were not and produces a diagnostic to the user from this.
|
/// but were not and produces a diagnostic to the user from this.
|
||||||
static unsigned PrintExpected(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
|
static unsigned PrintExpected(DiagnosticsEngine &Diags,
|
||||||
DirectiveList &DL, const char *Kind) {
|
SourceManager &SourceMgr,
|
||||||
|
std::vector<Directive *> &DL, const char *Kind) {
|
||||||
if (DL.empty())
|
if (DL.empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
SmallString<256> Fmt;
|
SmallString<256> Fmt;
|
||||||
llvm::raw_svector_ostream OS(Fmt);
|
llvm::raw_svector_ostream OS(Fmt);
|
||||||
for (DirectiveList::iterator I = DL.begin(), E = DL.end(); I != E; ++I) {
|
for (auto *DirPtr : DL) {
|
||||||
Directive &D = **I;
|
Directive &D = *DirPtr;
|
||||||
OS << "\n File " << SourceMgr.getFilename(D.DiagnosticLoc);
|
OS << "\n File " << SourceMgr.getFilename(D.DiagnosticLoc);
|
||||||
if (D.MatchAnyLine)
|
if (D.MatchAnyLine)
|
||||||
OS << " Line *";
|
OS << " Line *";
|
||||||
|
@ -694,11 +694,11 @@ static unsigned CheckLists(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
|
||||||
DirectiveList &Left,
|
DirectiveList &Left,
|
||||||
const_diag_iterator d2_begin,
|
const_diag_iterator d2_begin,
|
||||||
const_diag_iterator d2_end) {
|
const_diag_iterator d2_end) {
|
||||||
DirectiveList LeftOnly;
|
std::vector<Directive *> LeftOnly;
|
||||||
DiagList Right(d2_begin, d2_end);
|
DiagList Right(d2_begin, d2_end);
|
||||||
|
|
||||||
for (DirectiveList::iterator I = Left.begin(), E = Left.end(); I != E; ++I) {
|
for (auto &Owner : Left) {
|
||||||
Directive& D = **I;
|
Directive &D = *Owner;
|
||||||
unsigned LineNo1 = SourceMgr.getPresumedLineNumber(D.DiagnosticLoc);
|
unsigned LineNo1 = SourceMgr.getPresumedLineNumber(D.DiagnosticLoc);
|
||||||
|
|
||||||
for (unsigned i = 0; i < D.Max; ++i) {
|
for (unsigned i = 0; i < D.Max; ++i) {
|
||||||
|
@ -720,7 +720,7 @@ static unsigned CheckLists(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
|
||||||
if (II == IE) {
|
if (II == IE) {
|
||||||
// Not found.
|
// Not found.
|
||||||
if (i >= D.Min) break;
|
if (i >= D.Min) break;
|
||||||
LeftOnly.push_back(*I);
|
LeftOnly.push_back(&D);
|
||||||
} else {
|
} else {
|
||||||
// Found. The same cannot be found twice.
|
// Found. The same cannot be found twice.
|
||||||
Right.erase(II);
|
Right.erase(II);
|
||||||
|
@ -872,12 +872,14 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
|
||||||
ED.Reset();
|
ED.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Directive *Directive::create(bool RegexKind, SourceLocation DirectiveLoc,
|
std::unique_ptr<Directive> Directive::create(bool RegexKind,
|
||||||
SourceLocation DiagnosticLoc, bool MatchAnyLine,
|
SourceLocation DirectiveLoc,
|
||||||
StringRef Text, unsigned Min, unsigned Max) {
|
SourceLocation DiagnosticLoc,
|
||||||
|
bool MatchAnyLine, StringRef Text,
|
||||||
|
unsigned Min, unsigned Max) {
|
||||||
if (!RegexKind)
|
if (!RegexKind)
|
||||||
return new StandardDirective(DirectiveLoc, DiagnosticLoc, MatchAnyLine,
|
return llvm::make_unique<StandardDirective>(DirectiveLoc, DiagnosticLoc,
|
||||||
Text, Min, Max);
|
MatchAnyLine, Text, Min, Max);
|
||||||
|
|
||||||
// Parse the directive into a regular expression.
|
// Parse the directive into a regular expression.
|
||||||
std::string RegexStr;
|
std::string RegexStr;
|
||||||
|
@ -902,6 +904,6 @@ Directive *Directive::create(bool RegexKind, SourceLocation DirectiveLoc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RegexDirective(DirectiveLoc, DiagnosticLoc, MatchAnyLine, Text,
|
return llvm::make_unique<RegexDirective>(
|
||||||
Min, Max, RegexStr);
|
DirectiveLoc, DiagnosticLoc, MatchAnyLine, Text, Min, Max, RegexStr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue