2009-03-14 06:21:17 +08:00
|
|
|
//=- ClangDiagnosticsEmitter.cpp - Generate Clang diagnostics tables -*- C++ -*-
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These tablegen backends emit Clang diagnostics tables.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ClangDiagnosticsEmitter.h"
|
|
|
|
#include "Record.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2009-03-19 05:36:46 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2009-03-14 06:21:17 +08:00
|
|
|
#include "llvm/Support/Streams.h"
|
2009-03-19 05:16:16 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2009-04-16 04:13:18 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/VectorExtras.h"
|
2009-03-19 05:16:16 +08:00
|
|
|
#include <set>
|
|
|
|
#include <map>
|
2009-03-14 06:21:17 +08:00
|
|
|
using namespace llvm;
|
2009-03-19 05:16:16 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Warning Tables (.inc file) generation.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-03-14 06:21:17 +08:00
|
|
|
void ClangDiagsDefsEmitter::run(std::ostream &OS) {
|
2009-03-14 06:53:41 +08:00
|
|
|
// Write the #if guard
|
|
|
|
if (!Component.empty()) {
|
2009-04-16 04:16:12 +08:00
|
|
|
std::string ComponentName = UppercaseString(Component);
|
|
|
|
OS << "#ifdef " << ComponentName << "START\n";
|
|
|
|
OS << "__" << ComponentName << "START = DIAG_START_" << ComponentName
|
|
|
|
<< ",\n";
|
|
|
|
OS << "#undef " << ComponentName << "START\n";
|
|
|
|
OS << "#endif\n";
|
2009-03-14 06:53:41 +08:00
|
|
|
}
|
2009-04-16 04:55:08 +08:00
|
|
|
|
|
|
|
const std::vector<Record*> &Diags =
|
|
|
|
Records.getAllDerivedDefinitions("Diagnostic");
|
2009-03-14 06:53:41 +08:00
|
|
|
|
2009-04-16 04:55:08 +08:00
|
|
|
for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
|
|
|
|
const Record &R = *Diags[i];
|
2009-04-15 14:26:49 +08:00
|
|
|
// Filter by component.
|
|
|
|
if (!Component.empty() && Component != R.getValueAsString("Component"))
|
|
|
|
continue;
|
2009-03-14 06:53:41 +08:00
|
|
|
|
2009-04-16 04:55:08 +08:00
|
|
|
OS << "DIAG(" << R.getName() << ", ";
|
|
|
|
OS << R.getValueAsDef("Class")->getName();
|
|
|
|
OS << ", diag::" << R.getValueAsDef("DefaultMapping")->getName();
|
|
|
|
OS << ", \"";
|
|
|
|
std::string S = R.getValueAsString("Text");
|
|
|
|
EscapeString(S);
|
|
|
|
OS << S << "\")\n";
|
2009-03-14 06:21:17 +08:00
|
|
|
}
|
2009-03-14 06:53:41 +08:00
|
|
|
}
|
2009-03-19 05:16:16 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-04-16 04:55:08 +08:00
|
|
|
// Warning Group Tables generation
|
2009-03-19 05:16:16 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-04-16 04:55:08 +08:00
|
|
|
void ClangDiagGroupsEmitter::run(std::ostream &OS) {
|
|
|
|
// Invert the 1-[0/1] mapping of diags to group into a one to many mapping of
|
|
|
|
// groups to diags in the group.
|
|
|
|
std::map<std::string, std::vector<const Record*> > DiagsInGroup;
|
2009-03-19 05:16:16 +08:00
|
|
|
|
2009-04-16 04:55:08 +08:00
|
|
|
const std::vector<Record*> &Diags =
|
|
|
|
Records.getAllDerivedDefinitions("Diagnostic");
|
2009-03-19 05:16:16 +08:00
|
|
|
|
2009-04-16 04:55:08 +08:00
|
|
|
for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
|
|
|
|
const Record *R = Diags[i];
|
|
|
|
DefInit *DI = dynamic_cast<DefInit*>(R->getValueInit("Group"));
|
|
|
|
if (DI == 0) continue;
|
|
|
|
DiagsInGroup[DI->getDef()->getValueAsString("GroupName")].push_back(R);
|
2009-03-19 05:16:16 +08:00
|
|
|
}
|
|
|
|
|
2009-04-16 04:55:08 +08:00
|
|
|
// Walk through the groups emitting an array for each diagnostic of the diags
|
|
|
|
// that are mapped to.
|
|
|
|
OS << "\n#ifdef GET_DIAG_ARRAYS\n";
|
|
|
|
unsigned IDNo = 0;
|
|
|
|
unsigned MaxLen = 0;
|
|
|
|
for (std::map<std::string, std::vector<const Record*> >::iterator
|
|
|
|
I = DiagsInGroup.begin(), E = DiagsInGroup.end(); I != E; ++I) {
|
|
|
|
MaxLen = std::max(MaxLen, (unsigned)I->first.size());
|
2009-03-19 05:16:16 +08:00
|
|
|
|
2009-04-16 04:55:08 +08:00
|
|
|
OS << "static const short DiagArray" << IDNo++
|
|
|
|
<< "[] = { ";
|
|
|
|
std::vector<const Record*> &V = I->second;
|
|
|
|
for (unsigned i = 0, e = V.size(); i != e; ++i)
|
|
|
|
OS << "diag::" << V[i]->getName() << ", ";
|
|
|
|
OS << "-1 };\n";
|
2009-03-19 05:16:16 +08:00
|
|
|
}
|
2009-04-16 04:55:08 +08:00
|
|
|
OS << "#endif // GET_DIAG_ARRAYS\n\n";
|
|
|
|
|
|
|
|
// Emit the table now.
|
|
|
|
OS << "\n#ifdef GET_DIAG_TABLE\n";
|
|
|
|
IDNo = 0;
|
|
|
|
for (std::map<std::string, std::vector<const Record*> >::iterator
|
|
|
|
I = DiagsInGroup.begin(), E = DiagsInGroup.end(); I != E; ++I) {
|
|
|
|
std::string S = I->first;
|
|
|
|
EscapeString(S);
|
|
|
|
OS << " { \"" << S << "\","
|
|
|
|
<< std::string(MaxLen-I->first.size()+1, ' ')
|
|
|
|
<< "DiagArray" << IDNo++ << " },\n";
|
2009-03-19 05:28:47 +08:00
|
|
|
}
|
2009-04-16 04:55:08 +08:00
|
|
|
OS << "#endif // GET_DIAG_TABLE\n\n";
|
2009-03-19 05:16:16 +08:00
|
|
|
}
|