This is the first step in enhancing TableGen's error message capabilities. I added the source location to the RecordVal class, so that now source locations are associated with both the Record and RecordVal classes. This allows more precise error messages in backends. I added two PrintFatalError methods that accept a Record or a RecordVal.
As a test of this, I improved the error messages in the SearchableTableEmitter backend. Every message now includes at least the record definition location and quite often the field definition location. I also made its messages more consistent.
I think function can be very well written with early-return pattern i.e. check for the condition, if fails, return false. This way you can avoid nested "if" blocks.