aboutsummaryrefslogtreecommitdiffstats
path: root/test/let1.awk
blob: 413b6e1e355dbca3a741ee5d4418d953eef6611f (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
function f0()
{
  @let (l0)
    return l0
}

BEGIN {
  l0 = "abc"
  r0 = f0(42);
  print r0 == 0 && r0 == ""
}

function f1(l1)
{
  @let (l1 = 42)
    ;
  return l1;
}

BEGIN {
  print "f1", f1(3)
}

function f2(l2)
{
  @let (x = l2 + 1, x = x + 1, x = x + 1)
    @let (x = x + 1, x = x + 1)
       return l2 "-" x
}

BEGIN {
  print "f2", f2(3)
}

BEGIN {
  @let (l3 = 3, x = l3 + 1, x = x + 1, x = x + 1)
    @let (x = x + 1, x = x + 1)
       print "b3", l3 "-" x
}

# test re-use of scalar var as array

BEGIN {
   @let (i = 3) { }
   @let (a) { a[0] = 42 }
   @let (i = 3) { }
}

# Yacc rules are duplicated for first versus rest, so we need additional coverage.

BEGIN {
   @let (x, i = 3) { }
   @let (x, a) { a[0] = 42 }
   @let (x, i = 3) { }
}

# test clearing uninitialized variables

function f4()
{
  @let (i) for (i = 0; i < 2; i++) {
    @let (a, b, c) {
      if (a != 0 || a != "")
        exit 1
      if (b != 0 || b != "")
        exit 1
      if (c != 0 || c != "")
        exit 1
      a = b = c = 1
    }
  }
}

BEGIN { f4() }

BEGIN {
  @let (i) for (i = 0; i < 2; i++) {
    @let (a, b, c) {
      if (a != 0 || a != "")
        exit 1
      if (b != 0 || b != "")
        exit 1
      if (c != 0 || c != "")
        exit 1
      a = b = c = 1
    }
  }
}

BEGIN {
  @let (i = 0) while (i++ < 2) {
    @let (a, b, c) {
      if (a != 0 || a != "")
        exit 1
      if (b != 0 || b != "")
        exit 1
      if (c != 0 || c != "")
        exit 1
      a = b = c = 1
    }
  }
}

BEGIN {
  @let (i = 0) do {
    @let (a, b, c) {
      if (a != 0 || a != "")
        exit 1
      if (b != 0 || b != "")
        exit 1
      if (c != 0 || c != "")
        exit 1
      a = b = c = 1
    }
  } while (++i < 2)
}

BEGIN {
  @let (a, i) {
    a[0] = 42
    for (i in a) {
      @let (a, b, c) {
        if (a != 0 || a != "")
          exit 1
        if (b != 0 || b != "")
          exit 1
        if (c != 0 || c != "")
          exit 1
        a = b = c = 1
      }
    }
  }
}

BEGIN {
  @let (a = 1, b = 1, c = 1) { }
  @let (a, b, c) {
    if (a != 0 || a != "")
      exit 1
    if (b != 0 || b != "")
      exit 1
    if (c != 0 || c != "")
      exit 1
  }
}

function f5()
{
  @let (x = 1) { print "f5", x }
  @let (x = 1, y = 2) { print "f5", x, y }
  @let (x = 1, y = 2, z = 3) { print "f5", x, y, z }
}

BEGIN {
  f5()
  @let (x = 1) { print "b6", x }
  @let (x = 1, y = 2) { print "b6", x, y }
  @let (x = 1, y = 2, z = 3) { print "b6", x, y, z }
}