% $Id: BoundVarIds.oz,v 1.5 2009/01/10 19:19:41 leavens Exp $ % AUTHOR: Gary T. Leavens \insert 'FreeVarIds.oz' % this includes the set operations. declare fun {BoundVarIds Stmt} %% ENSURES: Result is the set of variable identifiers %% that occur bound in Stmt case Stmt of skipStmt then {EmptySet} [] seqStmt(StmtList) then {UnionList {Map StmtList BoundVarIds}} [] localStmt(V Body) then {Union {BoundVarIds Body} {Intersect {AsSet [V]} {FreeVarIds Body}}} [] assignStmt(_ Exp) then {BoundVarIdsExp Exp} [] ifStmt(TestExp S1 S2) then {Union {BoundVarIdsExp TestExp} {Union {BoundVarIds S1} {BoundVarIds S2}}} [] caseStmt(Exp Pattern S1 S2) then {Union {BoundVarIdsExp Exp} {Union {Union {BoundVarIds S1} {BoundVarIds S2}} {Intersect {DeclaredIdsPattern Pattern} {FreeVarIds S1}}}} [] applyStmt(ProcExp ArgExpList) then {Union {BoundVarIdsExp ProcExp} {UnionList {Map ArgExpList BoundVarIdsExp}}} [] namedFunStmt(_ Formals Body) then {Union {BoundVarIdsExp Body} {Intersect {UnionList {Map Formals DeclaredIdsPattern}} {FreeVarIdsExp Body}}} [] inStmt(Pattern Exp Body) then {Union {BoundVarIdsExp Exp} {Union {BoundVarIds Body} {Intersect {DeclaredIdsPattern Pattern} {FreeVarIds Body}}}} end end fun {BoundVarIdsExp Exp} %% ENSURES: Result is the set of variable identifiers %% that occur bound in Exp case Exp of varIdExp(_) then {EmptySet} [] atomExp(_) then {EmptySet} [] boolExp(_) then {EmptySet} [] numExp(_) then {EmptySet} [] recordExp(LabelExp FieldList) then {Union {BoundVarIdsExp LabelExp} {UnionList {Map FieldList BoundVarIdsField}}} [] procExp(Formals Body) then {Union {BoundVarIds Body} {Intersect {UnionList {Map Formals DeclaredIdsPattern}} {FreeVarIds Body}}} [] ifExp(TestExp E1 E2) then {Union {BoundVarIdsExp TestExp} {Union {BoundVarIdsExp E1} {BoundVarIdsExp E2}}} [] caseExp(Exp Pattern E1 E2) then {Union {BoundVarIdsExp Exp} {Union {Union {BoundVarIdsExp E1} {BoundVarIdsExp E2}} {Intersect {DeclaredIdsPattern Pattern} {FreeVarIdsExp E1}}}} [] applyExp(FunExp ArgExpList) then {Union {BoundVarIdsExp FunExp} {UnionList {Map ArgExpList BoundVarIdsExp}}} end end fun {BoundVarIdsField Field} %% ENSURES: Result is the set of variable identifiers %% that occur bound in Field case Field of colonFld(_ Exp) then {BoundVarIdsExp Exp} [] posFld(Exp) then {BoundVarIdsExp Exp} end end