tblgen: Use LLVM-style RTTI in clang-tblgen

llvm-svn: 165649
This commit is contained in:
Sean Silva 2012-10-10 20:25:43 +00:00
parent c0a9e39d0a
commit 1c4aaa8d1c
4 changed files with 24 additions and 25 deletions

View File

@ -33,7 +33,7 @@ getValueAsListOfStrings(Record &R, StringRef FieldName) {
i != e;
++i) {
assert(*i && "Got a null element in a ListInit");
if (StringInit *S = dynamic_cast<StringInit *>(*i))
if (StringInit *S = dyn_cast<StringInit>(*i))
Strings.push_back(S->getValue());
else
assert(false && "Got a non-string, non-code element in a ListInit");

View File

@ -75,7 +75,7 @@ getCategoryFromDiagGroup(const Record *Group,
static std::string getDiagnosticCategory(const Record *R,
DiagGroupParentMap &DiagGroupParents) {
// If the diagnostic is in a group, and that group has a category, use it.
if (DefInit *Group = dynamic_cast<DefInit*>(R->getValueInit("Group"))) {
if (DefInit *Group = dyn_cast<DefInit>(R->getValueInit("Group"))) {
// Check the diagnostic's diag group for a category.
std::string CatName = getCategoryFromDiagGroup(Group->getDef(),
DiagGroupParents);
@ -136,7 +136,7 @@ static void groupDiagnostics(const std::vector<Record*> &Diags,
std::map<std::string, GroupInfo> &DiagsInGroup) {
for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
const Record *R = Diags[i];
DefInit *DI = dynamic_cast<DefInit*>(R->getValueInit("Group"));
DefInit *DI = dyn_cast<DefInit>(R->getValueInit("Group"));
if (DI == 0) continue;
assert(R->getValueAsDef("Class")->getName() != "CLASS_NOTE" &&
"Note can't be in a DiagGroup");
@ -280,7 +280,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
Record *R = Diags[i];
if (isExtension(R) && isOffByDefault(R)) {
DiagsSet.insert(R);
if (DefInit *Group = dynamic_cast<DefInit*>(R->getValueInit("Group"))) {
if (DefInit *Group = dyn_cast<DefInit>(R->getValueInit("Group"))) {
const Record *GroupRec = Group->getDef();
if (!isSubGroupOfGroup(GroupRec, "pedantic")) {
markGroup(GroupRec);
@ -299,7 +299,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
// Check if the group is implicitly in -Wpedantic. If so,
// the diagnostic should not be directly included in the -Wpedantic
// diagnostic group.
if (DefInit *Group = dynamic_cast<DefInit*>(R->getValueInit("Group")))
if (DefInit *Group = dyn_cast<DefInit>(R->getValueInit("Group")))
if (groupInPedantic(Group->getDef()))
continue;
@ -391,7 +391,7 @@ void EmitClangDiagsDefs(RecordKeeper &Records, raw_ostream &OS,
// Check if this is an error that is accidentally in a warning
// group.
if (isError(R)) {
if (DefInit *Group = dynamic_cast<DefInit*>(R.getValueInit("Group"))) {
if (DefInit *Group = dyn_cast<DefInit>(R.getValueInit("Group"))) {
const Record *GroupRec = Group->getDef();
const std::string &GroupName = GroupRec->getValueAsString("GroupName");
throw "Error " + R.getName() + " cannot be in a warning group [" +
@ -413,7 +413,7 @@ void EmitClangDiagsDefs(RecordKeeper &Records, raw_ostream &OS,
// Warning associated with the diagnostic. This is stored as an index into
// the alphabetically sorted warning table.
if (DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group"))) {
if (DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group"))) {
std::map<std::string, GroupInfo>::iterator I =
DiagsInGroup.find(DI->getDef()->getValueAsString("GroupName"));
assert(I != DiagsInGroup.end());

View File

@ -28,7 +28,7 @@ static bool isHidden(const Record &R) {
if (R.getValueAsBit("Hidden"))
return true;
// Not declared as hidden, check the parent package if it is hidden.
if (DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("ParentPackage")))
if (DefInit *DI = dyn_cast<DefInit>(R.getValueInit("ParentPackage")))
return isHidden(*DI->getDef());
return false;
@ -42,7 +42,7 @@ static std::string getPackageFullName(const Record *R);
static std::string getParentPackageFullName(const Record *R) {
std::string name;
if (DefInit *DI = dynamic_cast<DefInit*>(R->getValueInit("ParentPackage")))
if (DefInit *DI = dyn_cast<DefInit>(R->getValueInit("ParentPackage")))
name = getPackageFullName(DI->getDef());
return name;
}
@ -63,8 +63,7 @@ static std::string getCheckerFullName(const Record *R) {
}
static std::string getStringValue(const Record &R, StringRef field) {
if (StringInit *
SI = dynamic_cast<StringInit*>(R.getValueInit(field)))
if (StringInit *SI = dyn_cast<StringInit>(R.getValueInit(field)))
return SI->getValue();
return std::string();
}
@ -131,7 +130,7 @@ void EmitClangSACheckers(RecordKeeper &Records, raw_ostream &OS) {
Record *R = checkers[i];
Record *package = 0;
if (DefInit *
DI = dynamic_cast<DefInit*>(R->getValueInit("ParentPackage")))
DI = dyn_cast<DefInit>(R->getValueInit("ParentPackage")))
package = DI->getDef();
if (!isCheckerNamed(R) && !package)
throw "Checker '" + R->getName() + "' is neither named, nor in a package!";
@ -151,20 +150,20 @@ void EmitClangSACheckers(RecordKeeper &Records, raw_ostream &OS) {
// Insert the checker and its parent packages into the subgroups set of
// the corresponding parent package.
while (DefInit *DI
= dynamic_cast<DefInit*>(currR->getValueInit("ParentPackage"))) {
= dyn_cast<DefInit>(currR->getValueInit("ParentPackage"))) {
Record *parentPackage = DI->getDef();
recordGroupMap[parentPackage]->SubGroups.insert(currR);
currR = parentPackage;
}
// Insert the checker into the set of its group.
if (DefInit *DI = dynamic_cast<DefInit*>(R->getValueInit("Group")))
if (DefInit *DI = dyn_cast<DefInit>(R->getValueInit("Group")))
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")))
if (DefInit *DI = dyn_cast<DefInit>(packages[i]->getValueInit("Group")))
addPackageToCheckerGroup(packages[i], DI->getDef(), recordGroupMap);
typedef std::map<std::string, const Record *> SortedRecords;
@ -205,7 +204,7 @@ void EmitClangSACheckers(RecordKeeper &Records, raw_ostream &OS) {
OS << "PACKAGE(" << "\"";
OS.write_escaped(getPackageFullName(&R)) << "\", ";
// Group index
if (DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group")))
if (DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group")))
OS << groupToSortIndex[DI->getDef()] << ", ";
else
OS << "-1, ";
@ -233,7 +232,7 @@ void EmitClangSACheckers(RecordKeeper &Records, raw_ostream &OS) {
OS << "\"";
OS.write_escaped(getStringValue(R, "HelpText")) << "\", ";
// Group index
if (DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group")))
if (DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group")))
OS << groupToSortIndex[DI->getDef()] << ", ";
else
OS << "-1, ";

View File

@ -56,7 +56,7 @@ static int CompareOptionRecords(const void *Av, const void *Bv) {
static const std::string getOptionName(const Record &R) {
// Use the record name unless EnumName is defined.
if (dynamic_cast<UnsetInit*>(R.getValueInit("EnumName")))
if (isa<UnsetInit>(R.getValueInit("EnumName")))
return R.getName();
return R.getValueAsString("EnumName");
@ -109,7 +109,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS, bool GenDefs) {
// The containing option group (if any).
OS << ", ";
if (const DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group")))
if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group")))
OS << getOptionName(*DI->getDef());
else
OS << "INVALID";
@ -118,7 +118,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS, bool GenDefs) {
OS << ", INVALID, 0, 0";
// The option help text.
if (!dynamic_cast<UnsetInit*>(R.getValueInit("HelpText"))) {
if (!isa<UnsetInit>(R.getValueInit("HelpText"))) {
OS << ",\n";
OS << " ";
write_cstring(OS, R.getValueAsString("HelpText"));
@ -149,14 +149,14 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS, bool GenDefs) {
// The containing option group (if any).
OS << ", ";
if (const DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group")))
if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Group")))
OS << getOptionName(*DI->getDef());
else
OS << "INVALID";
// The option alias (if any).
OS << ", ";
if (const DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Alias")))
if (const DefInit *DI = dyn_cast<DefInit>(R.getValueInit("Alias")))
OS << getOptionName(*DI->getDef());
else
OS << "INVALID";
@ -170,7 +170,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS, bool GenDefs) {
for (unsigned i = 0, e = LI->size(); i != e; ++i) {
if (i)
OS << " | ";
OS << dynamic_cast<DefInit*>(LI->getElement(i))->getDef()->getName();
OS << cast<DefInit>(LI->getElement(i))->getDef()->getName();
}
}
@ -178,7 +178,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS, bool GenDefs) {
OS << ", " << R.getValueAsInt("NumArgs");
// The option help text.
if (!dynamic_cast<UnsetInit*>(R.getValueInit("HelpText"))) {
if (!isa<UnsetInit>(R.getValueInit("HelpText"))) {
OS << ",\n";
OS << " ";
write_cstring(OS, R.getValueAsString("HelpText"));
@ -187,7 +187,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS, bool GenDefs) {
// The option meta-variable name.
OS << ", ";
if (!dynamic_cast<UnsetInit*>(R.getValueInit("MetaVarName")))
if (!isa<UnsetInit>(R.getValueInit("MetaVarName")))
write_cstring(OS, R.getValueAsString("MetaVarName"));
else
OS << "0";