Skip to content

Commit 5934cd1

Browse files
committed
[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.
1 parent de79836 commit 5934cd1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lldb/include/lldb/Core/PropertiesBase.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ class Global {
1818
class DefaultTrue {
1919
int DefaultUnsignedValue = 1;
2020
bit HasDefaultUnsignedValue = 1;
21+
bit HasDefaultBooleanValue = 1;
2122
}
2223

2324
class DefaultFalse {
2425
int DefaultUnsignedValue = 0;
2526
bit HasDefaultUnsignedValue = 1;
27+
bit HasDefaultBooleanValue = 1;
2628
}
2729

2830
// Gives the property a default string value.

lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static void emitProperty(Record *Property, raw_ostream &OS) {
4646
bool hasDefaultUnsignedValue = Property->getValue("HasDefaultUnsignedValue");
4747
bool hasDefaultEnumValue = Property->getValue("HasDefaultEnumValue");
4848
bool hasDefaultStringValue = Property->getValue("HasDefaultStringValue");
49+
bool hasDefaultBooleanValue = Property->getValue("HasDefaultBooleanValue");
4950

5051
// Guarantee that every property has a default value.
5152
assert((hasDefaultUnsignedValue || hasDefaultEnumValue ||
@@ -57,6 +58,21 @@ static void emitProperty(Record *Property, raw_ostream &OS) {
5758
assert(!(hasDefaultUnsignedValue && hasDefaultEnumValue) &&
5859
"Property cannot have both a unsigned and enum default value.");
5960

61+
// Guarantee that every boolean property has a boolean default value.
62+
assert(!(Property->getValueAsString("Type") == "Boolean" &&
63+
!hasDefaultBooleanValue) &&
64+
"Boolean property must have a boolean default value.");
65+
66+
// Guarantee that every string property has a string default value.
67+
assert(!(Property->getValueAsString("Type") == "String" &&
68+
!hasDefaultStringValue) &&
69+
"String property must have a string default value.");
70+
71+
// Guarantee that every enum property has an enum default value.
72+
assert(
73+
!(Property->getValueAsString("Type") == "Enum" && !hasDefaultEnumValue) &&
74+
"Enum property must have a enum default value.");
75+
6076
// Emit the default uint value.
6177
if (hasDefaultUnsignedValue) {
6278
OS << std::to_string(Property->getValueAsInt("DefaultUnsignedValue"));

0 commit comments

Comments
 (0)