File: foldl.td

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (71 lines) | stat: -rw-r--r-- 1,475 bytes parent folder | download | duplicates (26)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// RUN: llvm-tblgen %s | FileCheck %s
// XFAIL: vg_leak

// CHECK: --- Defs ---

// CHECK: def A1 {
// CHECK:   int ret = 0;
// CHECK: }

// CHECK: def A2 {
// CHECK:   int ret = 5;
// CHECK: }

// CHECK: def A3 {
// CHECK:   int ret = 10;
// CHECK: }

// CHECK: def B1 {
// CHECK:   list<string> ret = [];
// CHECK: }

// CHECK: def B2 {
// CHECK:   list<string> ret = [];
// CHECK: }

// CHECK: def B3 {
// CHECK:   list<string> ret = ["a"];
// CHECK: }

// CHECK: def B4 {
// CHECK:   list<string> ret = ["a", "b", "c", "d"];
// CHECK: }

// CHECK: def E0 {
// CHECK:   list<int> ret = [45, 45, 45, 45];
// CHECK: }

class Sum<list<int> lst> {
  int ret = !foldl(0, lst, a, b, !add(a, b));
}

class Flatten<list<list<string>> lst> {
  list<string> ret = !foldl([]<string>, lst, a, b, !listconcat(a, b));
}

def A1 : Sum<[]>;
def A2 : Sum<[5]>;
def A3 : Sum<[1, 2, 3, 4]>;

def B1 : Flatten<[]>;
def B2 : Flatten<[[]]>;
def B3 : Flatten<[["a"]]>;
def B4 : Flatten<[["a", "b"], [], ["c"], ["d"]]>;

// The variables a and b are declared both in the "inner" foldl and in the
// other foreach. The test checks that they don't "leak".
class C<list<int> lst> {
  int ret = !foldl(0, lst, a, b, !add(a, b));
}

class D<list<int> lst1, list<int> lst2> {
  list<int> x = !foreach(a, lst1, C<lst2>.ret);
  list<int> y = !foreach(b, lst1, C<lst2>.ret);
  list<int> z = !listconcat(x, y);
}

class E<list<int> lst2> {
  list<int> ret = D<[0, 1], lst2>.z;
}

def E0 : E<[10, 15, 20]>;