[Nice-commit] Nice/src/bossa/syntax contract.nice,NONE,1.1 customConstructor.nice,1.7,1.8 userOperat
Brought to you by:
bonniot
From: Arjan B. <ar...@us...> - 2005-01-01 14:38:13
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13867/F:/nice/src/bossa/syntax Modified Files: customConstructor.nice userOperator.nice Added Files: contract.nice Removed Files: Contract.java Log Message: Converted Contract. --- Contract.java DELETED --- Index: customConstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/customConstructor.nice,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** customConstructor.nice 1 Jan 2005 13:10:55 -0000 1.7 --- customConstructor.nice 1 Jan 2005 14:38:03 -0000 1.8 *************** *** 144,148 **** { return new CustomConstructor(new LocatedString("<init>", className.location()), ! cst, getCCReturnType(className, cst), params, contract: Contract.noContract, className: className, body: body); --- 144,148 ---- { return new CustomConstructor(new LocatedString("<init>", className.location()), ! cst, getCCReturnType(className, cst), params, contract: noContract, className: className, body: body); Index: userOperator.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/userOperator.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** userOperator.nice 1 Jan 2005 13:10:55 -0000 1.1 --- userOperator.nice 1 Jan 2005 14:38:03 -0000 1.2 *************** *** 114,118 **** from bytecode. */ ! if (contract != Contract.noContract) this.typecheck(); } --- 114,118 ---- from bytecode. */ ! if (contract != noContract) this.typecheck(); } --- NEW FILE: contract.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; import bossa.util.*; /** The contract of a method. */ public class Contract { private List<Expression> pre = new LinkedList(); private List<Expression> post = new LinkedList(); private StringBuffer requireRepr = new StringBuffer("requires "); private StringBuffer ensureRepr = new StringBuffer("ensures "); private ?MonoSymbol result = null; public void addElement(Expression condition, ?Expression name, boolean precond) { let sym = createIdentExp(new LocatedString("alwaysAssert", condition.location())); Expression call; String repr; if (name == null) { call = createCallExp(sym, condition); repr = condition.toString() + ","; } else { call = createCallExp(sym, condition, name); repr = condition.toString() + ":" + name.toString() + ","; } if (precond) { pre.add(call); requireRepr.append(repr); } else { post.add(call); ensureRepr.append(repr); } } void resolve(VarScope scope, TypeScope typeScope, mlsub.typing.Monotype resultType, Location location) { pre = pre.map(Expression e => analyse(e, scope, typeScope)); if (post.isEmpty()) return; if (! nice.tools.typing.Types.isVoid(resultType)) result = new ResultMonoSymbol(new LocatedString("result", location), resultType); try { if (result != null) scope.addSymbol(result); post = post.map(Expression e => analyse(e, scope, typeScope)); } finally { if (result != null) scope.removeSymbol(result); } } void typecheck() { for (pe : pre) typecheck(pe); for (pe : post) typecheck(pe); } public gnu.expr.Expression compile(gnu.expr.Expression body) { return new gnu.expr.CheckContract(Expression.compile(pre.toArray()), Expression.compile(post.toArray()), body); } toString() { StringBuffer res = new StringBuffer(); if (! pre.isEmpty()) res.append(requireRepr.toString()); if (! post.isEmpty()) res.append(ensureRepr.toString()); return res.toString(); } } let Contract noContract = new NoContract(); class NoContract extends Contract { resolve(scope, typeScope, resultType, location) {} typecheck() {} compile(body) = body; toString() = ""; } class ResultMonoSymbol extends MonoSymbol { isAssignable() = false; compile() = gnu.expr.CheckContract.result; } |