Changeset 2319 for cobra/trunk/Source/Members.cobra
- Timestamp:
- 03/15/10 05:32:06 (2 years ago)
- Files:
-
- 1 modified
-
cobra/trunk/Source/Members.cobra (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/Members.cobra
r2310 r2319 1665 1665 def _bindImp is override 1666 1666 base._bindImp 1667 # note: expressions cannot refer to locals in contracts 1667 1668 newExprs = List<of Expr>() 1668 i = 01669 1669 for expr in _exprs 1670 1670 expr.bindImp # TODO: error recovery 1671 1671 assert expr.type 1672 if not expr.hasError, _checkForLocalReferences(expr) 1672 1673 if expr.type is not .compiler.boolType 1673 1674 expr = TruthExpr(expr).bindAll to Expr # CC: axe cast when Cobra supports "as this" 1674 1675 assert expr.type 1675 1676 newExprs.add(expr) 1676 i += 11677 1677 _exprs.clear 1678 1678 _exprs.addRange(newExprs) 1679 1679 1680 def _checkForLocalReferences(expr as Expr) 1681 for expr in expr.allExprs 1682 if expr inherits IdentifierExpr 1683 if expr.definition inherits LocalVar 1684 if expr.name <> 'result' or not expr.definition.isImplicit 1685 expr.recordError('Cannot refer to local variable "[expr.name]" in a contract. Use an "assert" statement in the implementation to verify conditions on locals.') 1686 1680 1687 def checkConnectToken 1681 1688 """ … … 1722 1729 1723 1730 1724 class EnsurePart 1725 is partial 1726 inherits ContractPart 1731 class EnsurePart inherits ContractPart is partial 1727 1732 1728 1733 cue init(codeMember as AbstractMethod) … … 1747 1752 return have 1748 1753 1749 def _bindImp is override 1750 if _codeMember.resultType is .compiler.voidType 1754 def _bindImp 1755 codeMember = _codeMember 1756 if codeMember.resultType is .compiler.voidType 1751 1757 base._bindImp 1752 1758 else 1753 resultLocal = _codeMember.findLocal('result')1759 resultLocal = codeMember.findLocal('result') 1754 1760 resultBuiltIn = ResultVar(.token, _codeMember) 1755 if resultLocal 1756 _codeMember.replaceLocal(resultBuiltIn) 1757 else 1758 _codeMember.addLocal(resultBuiltIn) 1761 if resultLocal, codeMember.replaceLocal(resultBuiltIn) 1762 else, codeMember.addLocal(resultBuiltIn) 1759 1763 try 1760 1764 base._bindImp 1761 1765 finally 1762 if resultLocal 1763 _codeMember.replaceLocal(resultLocal to LocalVar) 1764 else 1765 _codeMember.removeLocal('result') 1766 if resultLocal, codeMember.replaceLocal(resultLocal to LocalVar) 1767 else, codeMember.removeLocal('result')



