For ClangSACheckersEmitter, allow a package to belong to checker group, in which all its checkers will go into the group.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128474 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Argyrios Kyrtzidis 2011-03-29 18:53:00 +00:00
parent cf610d07de
commit 9993a38583

View File

@ -71,7 +71,7 @@ static std::string getStringValue(const Record &R, StringRef field) {
namespace {
struct GroupInfo {
std::vector<const Record*> Checkers;
llvm::DenseSet<const Record*> Checkers;
llvm::DenseSet<const Record *> SubGroups;
bool Hidden;
unsigned Index;
@ -80,6 +80,19 @@ struct GroupInfo {
};
}
static void addPackageToCheckerGroup(const Record *package, const Record *group,
llvm::DenseMap<const Record *, GroupInfo *> &recordGroupMap) {
llvm::DenseSet<const Record *> &checkers = recordGroupMap[package]->Checkers;
for (llvm::DenseSet<const Record *>::iterator
I = checkers.begin(), E = checkers.end(); I != E; ++I)
recordGroupMap[group]->Checkers.insert(*I);
llvm::DenseSet<const Record *> &subGroups = recordGroupMap[package]->SubGroups;
for (llvm::DenseSet<const Record *>::iterator
I = subGroups.begin(), E = subGroups.end(); I != E; ++I)
addPackageToCheckerGroup(*I, group, recordGroupMap);
}
void ClangSACheckersEmitter::run(raw_ostream &OS) {
std::vector<Record*> checkers = Records.getAllDerivedDefinitions("Checker");
llvm::DenseMap<const Record *, unsigned> checkerRecIndexMap;
@ -150,9 +163,9 @@ void ClangSACheckersEmitter::run(raw_ostream &OS) {
GroupInfo &info = groupInfoByName[fullName];
info.Hidden = R->getValueAsBit("Hidden");
recordGroupMap[R] = &info;
info.Checkers.push_back(R);
info.Checkers.insert(R);
} else {
recordGroupMap[package]->Checkers.push_back(R);
recordGroupMap[package]->Checkers.insert(R);
}
Record *currR = isCheckerNamed(R) ? R : package;
@ -166,9 +179,15 @@ void ClangSACheckersEmitter::run(raw_ostream &OS) {
}
// Insert the checker into the set of its group.
if (DefInit *DI = dynamic_cast<DefInit*>(R->getValueInit("Group")))
recordGroupMap[DI->getDef()]->Checkers.push_back(R);
recordGroupMap[DI->getDef()]->Checkers.insert(R);
}
// If a package is in group, add all its checkers and its sub-packages
// checkers into the group.
for (unsigned i = 0, e = packages.size(); i != e; ++i)
if (DefInit *DI = dynamic_cast<DefInit*>(packages[i]->getValueInit("Group")))
addPackageToCheckerGroup(packages[i], DI->getDef(), recordGroupMap);
unsigned index = 0;
for (std::map<std::string, GroupInfo>::iterator
I = groupInfoByName.begin(), E = groupInfoByName.end(); I != E; ++I)
@ -183,11 +202,12 @@ void ClangSACheckersEmitter::run(raw_ostream &OS) {
I = groupInfoByName.begin(), E = groupInfoByName.end(); I != E; ++I) {
maxLen = std::max(maxLen, (unsigned)I->first.size());
std::vector<const Record*> &V = I->second.Checkers;
if (!V.empty()) {
llvm::DenseSet<const Record *> &checkers = I->second.Checkers;
if (!checkers.empty()) {
OS << "static const short CheckerArray" << I->second.Index << "[] = { ";
for (unsigned i = 0, e = V.size(); i != e; ++i)
OS << checkerRecIndexMap[V[i]] << ", ";
for (llvm::DenseSet<const Record *>::iterator
I = checkers.begin(), E = checkers.end(); I != E; ++I)
OS << checkerRecIndexMap[*I] << ", ";
OS << "-1 };\n";
}