|
@@ -844,27 +844,32 @@ implementation
|
|
|
function tcasenode.simplify(forinline:boolean):tnode;
|
|
|
var
|
|
|
tmp: pcaselabel;
|
|
|
+ walkup: boolean;
|
|
|
begin
|
|
|
result:=nil;
|
|
|
if left.nodetype=ordconstn then
|
|
|
begin
|
|
|
tmp:=labels;
|
|
|
- { walk the case labels as long as the upper bound is smaller than
|
|
|
- the constant }
|
|
|
- while assigned(tmp) and (tmp^._high<tordconstnode(left).value) do
|
|
|
- tmp:=tmp^.greater;
|
|
|
- { check whether the constant is inside the range }
|
|
|
- if assigned(tmp) and
|
|
|
- (tmp^._low<=tordconstnode(left).value) and
|
|
|
- (tmp^._high>=tordconstnode(left).value) then
|
|
|
+ { check all case labels until we find one that fits }
|
|
|
+ walkup:=assigned(tmp^.greater);
|
|
|
+ while assigned(tmp) do
|
|
|
begin
|
|
|
- if tmp^.blockid>=blocks.count then
|
|
|
- internalerror(2014022101);
|
|
|
- result:=pcaseblock(blocks[tmp^.blockid])^.statement;
|
|
|
- if not assigned(result) then
|
|
|
- internalerror(2014022102);
|
|
|
- result:=result.getcopy;
|
|
|
- exit;
|
|
|
+ if (tmp^._low<=tordconstnode(left).value) and
|
|
|
+ (tmp^._high>=tordconstnode(left).value) then
|
|
|
+ begin
|
|
|
+ if tmp^.blockid>=blocks.count then
|
|
|
+ internalerror(2014022101);
|
|
|
+ result:=pcaseblock(blocks[tmp^.blockid])^.statement;
|
|
|
+ if not assigned(result) then
|
|
|
+ internalerror(2014022102);
|
|
|
+ result:=result.getcopy;
|
|
|
+ exit;
|
|
|
+ end;
|
|
|
+
|
|
|
+ if walkup then
|
|
|
+ tmp:=tmp^.greater
|
|
|
+ else
|
|
|
+ tmp:=tmp^.less;
|
|
|
end;
|
|
|
{ no label did match; use the else block if available }
|
|
|
if assigned(elseblock) then
|