TableGen: Fix type deduction for !foreach

Summary:
In the case of !foreach(id, input-list, transform) where the type of
input-list is list<A> and the type of transform is B, we now correctly
deduce list<B> as the type of the !foreach.

Change-Id: Ia19dd65eecc5991dd648280ba6a15f6a20fd61de

Reviewers: arsenm, craig.topper, tra, MartinO

Subscribers: wdng, llvm-commits

Differential Revision: https://reviews.llvm.org/D43555

llvm-svn: 325797
This commit is contained in:
Nicolai Haehnle 2018-02-22 15:26:35 +00:00
parent e4a2cf5761
commit 6d64915c87
2 changed files with 20 additions and 0 deletions

View File

@ -1075,6 +1075,14 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
Type = MHSt->getType();
if (isa<ListRecTy>(Type)) {
TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
if (!RHSt) {
TokError("could not get type of !foreach list elements");
return nullptr;
}
Type = RHSt->getType()->getListTy();
}
break;
}
case tgtok::XSubst: {

View File

@ -7,12 +7,18 @@
// CHECK: "NAME"
// CHECK: Defs
// CHECK: def DX {
// CHECK: list<string> x = ["0", "1", "2"];
// CHECK: }
// CHECK: Jr
// CHECK: Sr
// Variables for foreach
class decls {
string name;
int num;
}
def Decls : decls;
@ -37,3 +43,9 @@ def Seniors : B<People.values>;
def Juniors : C<People.values>;
def Smiths : D<["NAME", "Jane Smith"]>;
def Unprocessed : D<People.values>;
class X<list<int> a> {
list<string> x = !foreach(Decls.num, a, !cast<string>(Decls.num));
}
def DX : X<[0, 1, 2]>;