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 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
# simple structures work ------------------------------------------------------
tcc -c -u stderr -Wnounused 2>&1
$x.foo = 5;
$x.bar = 17;
$y = $x.foo+$x.bar;
EOF
$x.foo = 5
$x.bar = 17
$y = 22
# multi-level structures work too (1) -----------------------------------------
tcc -c -u stderr -Wnounused 2>&1
$x.y.z = 10;
$a.b.c.d.e = 20;
$a.a.a = $x.y.z*$a.b.c.d.e;
EOF
$x.y.z = 10
$a.b.c.d.e = 20
$a.a.a = 200
# multi-level structures work too (2) -----------------------------------------
tcc -c -u stderr -Wnounused 2>&1
$a.b.c = 10;
$a.b.x.y = 20;
$a.b.z = $a.b.x.y/$a.b.c;
EOF
$a.b.c = 10
$a.b.x.y = 20
$a.b.z = 2
# structure assignment works --------------------------------------------------
tcc -c -u stderr -Wnounused 2>&1
$x.a = 1;
$x.b = 2;
$y = $x;
EOF
$x.a = 1
$x.b = 2
$y.a = 1
$y.b = 2
# structure assignment works with compound expressions ------------------------
tcc -c -u stderr -Wnounused 2>&1
$y = { $x.a = 1; $x.b = 2; $x; };
EOF
{
$x.a = 1
$x.b = 2
}
$y.a = 1
$y.b = 2
# cannot access entries in undefined variable ---------------------------------
tcc -c 2>&1
$foo = $bar.xyzzy;
EOF
ERROR
<stdin>:1: variable bar is uninitialized near ";"
# cannot access entries in non-structure --------------------------------------
tcc -c 2>&1
$bar = 5;
$foo = $bar.xyzzy;
EOF
ERROR
<stdin>:2: expected structure, not type integer near ";"
# cannot access unknown entry -------------------------------------------------
tcc -c 2>&1
$bar.foo = 5;
$foo = $bar.xyzzy;
EOF
ERROR
<stdin>:2: no entry "xyzzy" in structure near ";"
# cannot forward-reference structure entry ------------------------------------
tcc -c 2>&1
dsmark {
class (<$foo.bar>) if 1;
}
EOF
ERROR
<stdin>:2: cannot forward-declare structure entries near ">"
# cannot assign to entry in forward-declared variable -------------------------
tcc -c 2>&1
dsmark {
class (<$foo>) if 1;
prio {
$foo.fail = class;
}
}
EOF
ERROR
<stdin>:5: cannot access structure entries in forward-declared variable near "}"
# structure entries cross scope boundaries (1) --------------------------------
tcc -c -u stderr -Wnounused 2>&1
$foo.x = 5;
prio {
$foo.y = $foo.x;
}
$bar = $foo.x+$foo.y;
EOF
$foo.x = 5
{ device eth0
{ qdisc eth0:1
$foo.y = 5
}
$bar = 10
}
# structure entries cross scope boundaries (2) --------------------------------
tcc -c -u stderr -Wnounused 2>&1
$foo.x = 5;
$foo.y = 7;
prio {
$foo.y = 10;
}
$bar = $foo.x+$foo.y;
EOF
$foo.x = 5
$foo.y = 7
{ device eth0
{ qdisc eth0:1
$foo.y = 10
}
$bar = 15
}
# unaccessed structure is unused ----------------------------------------------
tcc -c 2>&1
$foo.xy = 10;
EOF
<stdin>:1: warning: unused variable foo
# conversion to structure redefines -------------------------------------------
tcc -c -Wredefine 2>&1
$foo = 5;
$foo.foo = 0;
EOF
<stdin>:1: warning: unused variable foo
<stdin>:2: warning: variable foo redefined
<stdin>:2: warning: unused variable foo
# accessing any entry makes structure "used" ----------------------------------
tcc -c 2>&1
$foo.x = 1;
$foo.y = 2;
$bar = $foo.x;
EOF
<stdin>:3: warning: unused variable bar
# creating new entry does not make structure unused ---------------------------
tcc -c 2>&1
$foo.x = 1;
$foo.y = $foo.x;
EOF
# changing existing entry does not make structure unused ----------------------
tcc -c 2>&1
$foo.x = 1;
$foo.x = $foo.x;
EOF
# expansion of structure assignments ------------------------------------------
tcc -c -u stderr 2>&1
warn "nounused";
$x = { $x.a = "xa"; $x.foo = "xfoo"; $x; };
$y = { $y.bar = "ybar"; $y.b = "yb"; $y; };
$y.b = $x;
$z = $y;
EOF
{
$x.a = "xa"
$x.foo = "xfoo"
}
$x.a = "xa"
$x.foo = "xfoo"
{
$y.bar = "ybar"
$y.b = "yb"
}
$y.bar = "ybar"
$y.b = "yb"
$y.b.a = "xa"
$y.b.foo = "xfoo"
$z.bar = "ybar"
$z.b.a = "xa"
$z.b.foo = "xfoo"
|