From 57838db0a1cfcfbb8d1df59562dccd22208cd703 Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Wed, 19 Sep 2012 02:14:59 +0000 Subject: [PATCH] De-nest if's and fix mix-up Two deeply nested if's obscured that the sense of the conditions was mixed up. Amazingly, TableGen's output is exactly the same even with the sense of the tests fixed; it seems that all of TableGen's conversions are symmetric so that the inverted sense was nonetheless correct "by accident". As such, I couldn't come up with a test case. If there does in fact exist a non-symmetric conversion in TableGen's type system, then a test case should be prepared. Despite the symmetry, both if's are left in place for robustness in the face of future changes. Review by Jakob. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164195 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Record.cpp | 78 +++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index b2a7b628e4c..9955617aa89 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -344,57 +344,53 @@ bool RecordRecTy::baseClassOf(const RecordRecTy *RHS) const { return false; } - /// resolveTypes - Find a common type that T1 and T2 convert to. /// Return 0 if no such type exists. /// RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) { - if (!T1->typeIsConvertibleTo(T2)) { - if (!T2->typeIsConvertibleTo(T1)) { - // If one is a Record type, check superclasses - RecordRecTy *RecTy1 = dynamic_cast(T1); - if (RecTy1) { - // See if T2 inherits from a type T1 also inherits from - const std::vector &T1SuperClasses = - RecTy1->getRecord()->getSuperClasses(); - for(std::vector::const_iterator i = T1SuperClasses.begin(), - iend = T1SuperClasses.end(); - i != iend; - ++i) { - RecordRecTy *SuperRecTy1 = RecordRecTy::get(*i); - RecTy *NewType1 = resolveTypes(SuperRecTy1, T2); - if (NewType1 != 0) { - if (NewType1 != SuperRecTy1) { - delete SuperRecTy1; - } - return NewType1; - } + if (T1->typeIsConvertibleTo(T2)) + return T2; + if (T2->typeIsConvertibleTo(T1)) + return T1; + + // If one is a Record type, check superclasses + if (RecordRecTy *RecTy1 = dynamic_cast(T1)) { + // See if T2 inherits from a type T1 also inherits from + const std::vector &T1SuperClasses = + RecTy1->getRecord()->getSuperClasses(); + for(std::vector::const_iterator i = T1SuperClasses.begin(), + iend = T1SuperClasses.end(); + i != iend; + ++i) { + RecordRecTy *SuperRecTy1 = RecordRecTy::get(*i); + RecTy *NewType1 = resolveTypes(SuperRecTy1, T2); + if (NewType1 != 0) { + if (NewType1 != SuperRecTy1) { + delete SuperRecTy1; } + return NewType1; } - RecordRecTy *RecTy2 = dynamic_cast(T2); - if (RecTy2) { - // See if T1 inherits from a type T2 also inherits from - const std::vector &T2SuperClasses = - RecTy2->getRecord()->getSuperClasses(); - for (std::vector::const_iterator i = T2SuperClasses.begin(), - iend = T2SuperClasses.end(); - i != iend; - ++i) { - RecordRecTy *SuperRecTy2 = RecordRecTy::get(*i); - RecTy *NewType2 = resolveTypes(T1, SuperRecTy2); - if (NewType2 != 0) { - if (NewType2 != SuperRecTy2) { - delete SuperRecTy2; - } - return NewType2; - } + } + } + if (RecordRecTy *RecTy2 = dynamic_cast(T2)) { + // See if T1 inherits from a type T2 also inherits from + const std::vector &T2SuperClasses = + RecTy2->getRecord()->getSuperClasses(); + for (std::vector::const_iterator i = T2SuperClasses.begin(), + iend = T2SuperClasses.end(); + i != iend; + ++i) { + RecordRecTy *SuperRecTy2 = RecordRecTy::get(*i); + RecTy *NewType2 = resolveTypes(T1, SuperRecTy2); + if (NewType2 != 0) { + if (NewType2 != SuperRecTy2) { + delete SuperRecTy2; } + return NewType2; } - return 0; } - return T2; } - return T1; + return 0; } -- 2.34.1