aboutsummaryrefslogtreecommitdiff
path: root/src/interp/compiler.boot
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2010-06-13 01:33:35 +0000
committerdos-reis <gdr@axiomatics.org>2010-06-13 01:33:35 +0000
commite6c324c2e70288ca0df86efd0957ef2c5b66f39c (patch)
tree79159bf2bf6cd0649069f0582527b9e0a8c9a0ba /src/interp/compiler.boot
parent413741a1a80fe41ef99e40a9d2ddeb72c7591478 (diff)
downloadopen-axiom-e6c324c2e70288ca0df86efd0957ef2c5b66f39c.tar.gz
* interp/compiler.boot (complainIfShadowing): New.
(compStepIterator): Use it to warn about loop variable shadowing declaration in enclosing scope. (compIterator): Likewise.
Diffstat (limited to 'src/interp/compiler.boot')
-rw-r--r--src/interp/compiler.boot11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/interp/compiler.boot b/src/interp/compiler.boot
index 87d07c89..ceae230f 100644
--- a/src/interp/compiler.boot
+++ b/src/interp/compiler.boot
@@ -2362,12 +2362,19 @@ compIntegerValue(x,e) ==
comp(x,$PositiveInteger,e) or
comp(x,$NonNegativeInteger,e) or
compOrCroak(x,$Integer,e)
-
+
+++ Issue a diagnostic if `x' names a loop variable with a matching
+++ declaration or definition in the enclosing scope.
+complainIfShadowing(x,e) ==
+ if getmode(x,e) ~= nil then
+ stackWarning('"loop variable %1b shadows variable from enclosing scope",[x])
+
++ Attempt to compile a `for' iterator of the form
++ for index in start..final by inc
++ where the bound `final' may be missing.
compStepIterator(index,start,final,inc,e) ==
checkVariableName index
+ complainIfShadowing(index,e)
$formalArgList := [index,:$formalArgList]
[start,startMode,e] := compIntegerValue(start,e) or return
stackMessage('"start value of index: %1b must be an integer",[start])
@@ -2389,6 +2396,7 @@ compIterator(it,e) ==
-- ??? Allow for declared iterator variable.
it is ["IN",x,y] =>
checkVariableName x
+ complainIfShadowing(x,e)
--these two lines must be in this order, to get "for f in list f"
--to give an error message if f is undefined
[y',m,e]:= comp(y,$EmptyMode,e) or return nil
@@ -2403,6 +2411,7 @@ compIterator(it,e) ==
[["IN",x,y''],e]
it is ["ON",x,y] =>
checkVariableName x
+ complainIfShadowing(x,e)
$formalArgList:= [x,:$formalArgList]
[y',m,e]:= comp(y,$EmptyMode,e) or return nil
[mOver,mUnder]:=