Author: Jonas Devlieghere Date: 2019-10-25T10:18:38-07:00 New Revision: 5934cd11ea3e15dd9f13a9ee960012b5b64463ec
URL: https://github.com/llvm/llvm-project/commit/5934cd11ea3e15dd9f13a9ee960012b5b64463ec DIFF: https://github.com/llvm/llvm-project/commit/5934cd11ea3e15dd9f13a9ee960012b5b64463ec.diff LOG: [TableGen] Add asserts to make sure default values match property type This adds a few asserts to the property TableGen backend to prevent mismatches between property types and their default values. This would've prevented a copy-paste mistake we discovered downstream. Added: Modified: lldb/include/lldb/Core/PropertiesBase.td lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Core/PropertiesBase.td b/lldb/include/lldb/Core/PropertiesBase.td index be97d44ae8e4..6e95ceb779ba 100644 --- a/lldb/include/lldb/Core/PropertiesBase.td +++ b/lldb/include/lldb/Core/PropertiesBase.td @@ -18,11 +18,13 @@ class Global { class DefaultTrue { int DefaultUnsignedValue = 1; bit HasDefaultUnsignedValue = 1; + bit HasDefaultBooleanValue = 1; } class DefaultFalse { int DefaultUnsignedValue = 0; bit HasDefaultUnsignedValue = 1; + bit HasDefaultBooleanValue = 1; } // Gives the property a default string value. diff --git a/lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp b/lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp index f49c05c9a585..51c15a715f38 100644 --- a/lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp +++ b/lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp @@ -46,6 +46,7 @@ static void emitProperty(Record *Property, raw_ostream &OS) { bool hasDefaultUnsignedValue = Property->getValue("HasDefaultUnsignedValue"); bool hasDefaultEnumValue = Property->getValue("HasDefaultEnumValue"); bool hasDefaultStringValue = Property->getValue("HasDefaultStringValue"); + bool hasDefaultBooleanValue = Property->getValue("HasDefaultBooleanValue"); // Guarantee that every property has a default value. assert((hasDefaultUnsignedValue || hasDefaultEnumValue || @@ -57,6 +58,21 @@ static void emitProperty(Record *Property, raw_ostream &OS) { assert(!(hasDefaultUnsignedValue && hasDefaultEnumValue) && "Property cannot have both a unsigned and enum default value."); + // Guarantee that every boolean property has a boolean default value. + assert(!(Property->getValueAsString("Type") == "Boolean" && + !hasDefaultBooleanValue) && + "Boolean property must have a boolean default value."); + + // Guarantee that every string property has a string default value. + assert(!(Property->getValueAsString("Type") == "String" && + !hasDefaultStringValue) && + "String property must have a string default value."); + + // Guarantee that every enum property has an enum default value. + assert( + !(Property->getValueAsString("Type") == "Enum" && !hasDefaultEnumValue) && + "Enum property must have a enum default value."); + // Emit the default uint value. if (hasDefaultUnsignedValue) { OS << std::to_string(Property->getValueAsInt("DefaultUnsignedValue")); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits