diff options
| author | John McCall <rjmccall@apple.com> | 2019-10-25 16:23:17 -0700 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2019-10-25 16:39:21 -0700 |
| commit | 27e2c8faec6926fafdbd4d9b5b2f827f002e1c8e (patch) | |
| tree | 2d64c0e32eeeb4fd2cf9c58be3f6b39baae88468 /llvm/lib/TableGen | |
| parent | dd501045cdea1c80b6788f0266d2a79f8b412eea (diff) | |
| download | bcm5719-llvm-27e2c8faec6926fafdbd4d9b5b2f827f002e1c8e.tar.gz bcm5719-llvm-27e2c8faec6926fafdbd4d9b5b2f827f002e1c8e.zip | |
Add Record::getValueAsOptionalDef().
Using `?` as an optional marker is very useful in Clang's AST-node
emitters because otherwise we need a separate class just to encode
the presence or absence of a base node reference.
Diffstat (limited to 'llvm/lib/TableGen')
| -rw-r--r-- | llvm/lib/TableGen/Record.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index 835ef8c7141..2ab7b98ca03 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -2277,6 +2277,21 @@ Record *Record::getValueAsDef(StringRef FieldName) const { FieldName + "' does not have a def initializer!"); } +Record *Record::getValueAsOptionalDef(StringRef FieldName) const { + const RecordVal *R = getValue(FieldName); + if (!R || !R->getValue()) + PrintFatalError(getLoc(), "Record `" + getName() + + "' does not have a field named `" + FieldName + "'!\n"); + + if (DefInit *DI = dyn_cast<DefInit>(R->getValue())) + return DI->getDef(); + if (isa<UnsetInit>(R->getValue())) + return nullptr; + PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + + FieldName + "' does not have either a def initializer or '?'!"); +} + + bool Record::getValueAsBit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (!R || !R->getValue()) |

