Transformation of Applicative Specifications into Imperative ...

Transformation of Applicative Specifications into Imperative ... Transformation of Applicative Specifications into Imperative ...

26.09.2013 Views

APPENDIX C. FORMAL SPECIFICATIONS OF TRANSFORMATIONS else CheckPreCondGen( value_expr(hd cbl), func, trans, types) ∧ CheckPreCondGenCaseBranch( tl cbl, func, trans, types) end, /∗Checks for transformability of a value expression. ∗/ /∗ Arguments: ======= ve: the value expression et: the expected type of the value expression Results: ===== Bool: true if the list is transformable, false otherwise ∗/ CheckValueExpr : ValueExpr × ExpType × TYPINGS × FUNC × TRANS × ENV × TYPES → Bool × ENV × TYPES CheckValueExpr( ve, et, typings, func, trans, env, types) ≡ case ve of Make_ValueLiteral(vl) → (true, updateENV(env, et, trans), types), Make_ValueOrVariableName(vn) → if ∼ isinBinding(IdBinding(id(vn)), dom types) then (true, updateENV(env, et, trans), types) else if checkTRANS( types(IdBinding(id(vn))), dom trans) then /∗The value expression is of the type of interest. ∗/ (isinBinding(IdBinding(id(vn)), rng env), updateENV(env, et, trans), types) else /∗The value expression is not of the type of interest. ∗/ (true, updateENV(env, et, trans), types) 162

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER end end, Make_BasicExpr(be) → (true, env, types), ProductExpr(vel) → CheckValueExprList( vel, expTypeToExpTypeList( removeBrackets(et), len vel), typings, func, trans, env, types), Make_SetExpr(setExpr) → if containsTRANSName( getSetType(et), typings, dom trans) then (false, env, types) else CheckSetExpr( setExpr, getSetType(et), typings, func, trans, env, types) end, Make_ListExpr(listExpr) → if containsTRANSName( getListType(et), typings, dom trans) then (false, env, types) else CheckListExpr( listExpr, getListType(et), typings, func, trans, env, types) end, Make_MapExpr(mapExpr) → if containsTRANSName( tedom(getMapType(et)), typings, dom trans) ∨ containsTRANSName( terange(getMapType(et)), typings, dom trans) then (false, env, types) else CheckMapExpr( mapExpr, getMapType(et), typings, func, trans, env, types) end, ApplicationExpr(ave, vl) → CheckApplicationExpr( ave, vl, et, typings, func, trans, env, types), 163

APPENDIX C. FORMAL SPECIFICATIONS OF TRANSFORMATIONS<br />

else<br />

CheckPreCondGen(<br />

value_expr(hd cbl), func, trans, types) ∧<br />

CheckPreCondGenCaseBranch(<br />

tl cbl, func, trans, types)<br />

end,<br />

/∗Checks for transformability <strong>of</strong> a value expression.<br />

∗/<br />

/∗<br />

Arguments:<br />

=======<br />

ve: the value expression<br />

et: the expected type <strong>of</strong> the value expression<br />

Results:<br />

=====<br />

Bool: true if the list is transformable, false<br />

otherwise<br />

∗/<br />

CheckValueExpr :<br />

ValueExpr × ExpType × TYPINGS × FUNC × TRANS ×<br />

ENV × TYPES →<br />

Bool × ENV × TYPES<br />

CheckValueExpr(<br />

ve, et, typings, func, trans, env, types) ≡<br />

case ve <strong>of</strong><br />

Make_ValueLiteral(vl) →<br />

(true, updateENV(env, et, trans), types),<br />

Make_ValueOrVariableName(vn) →<br />

if ∼ isinBinding(IdBinding(id(vn)), dom types)<br />

then (true, updateENV(env, et, trans), types)<br />

else<br />

if<br />

checkTRANS(<br />

types(IdBinding(id(vn))), dom trans)<br />

then<br />

/∗The value expression is <strong>of</strong> the type <strong>of</strong> interest.<br />

∗/<br />

(isinBinding(IdBinding(id(vn)), rng env),<br />

updateENV(env, et, trans), types)<br />

else<br />

/∗The value expression is not <strong>of</strong> the type <strong>of</strong> interest.<br />

∗/<br />

(true, updateENV(env, et, trans), types)<br />

162

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!