[Nice-commit] Nice/src/bossa/syntax analyse.nice,1.104,1.105 funexp.nice,1.1,1.2 return.nice,1.1,1.2
Brought to you by:
bonniot
From: Arjan B. <ar...@us...> - 2004-07-28 20:48:39
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24781/F:/nice/src/bossa/syntax Modified Files: analyse.nice funexp.nice return.nice typecheck.nice Log Message: Split up of ReturnStmt in ReturnStmt and VoidReturnStmt. Index: return.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/return.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** return.nice 28 Jul 2004 14:40:33 -0000 1.1 --- return.nice 28 Jul 2004 20:48:28 -0000 1.2 *************** *** 21,51 **** public class ReturnStmt extends Statement { ! ?Expression value; boolean fake = false; mlsub.typing.Polytype returnType() { ! if (value == null) ! return notNull(PrimitiveType.voidPolytype); ! ! return notNull(value).getType(); } generateCode() { ! if (value == null) ! return notNull(nice.tools.code.Gen.returnVoid()); ! ! return nice.tools.code.Gen.returnValue(notNull(value).generateCode()); } toString() { ! return "return" + (value!=null ? " " + notNull(value) : "") + ";"; } } ! public Statement createReturnStmt(Expression value) { return createReturnStmt(value, false); --- 21,63 ---- public class ReturnStmt extends Statement { ! Expression value; boolean fake = false; mlsub.typing.Polytype returnType() { ! return value.getType(); } generateCode() { ! return nice.tools.code.Gen.returnValue(value.generateCode()); } toString() { ! return "return " + value + ";"; ! } ! } ! ! public class VoidReturnStmt extends Statement ! { ! ! mlsub.typing.Polytype returnType() ! { ! return notNull(PrimitiveType.voidPolytype); ! } ! ! generateCode() ! { ! return notNull(nice.tools.code.Gen.returnVoid()); } + toString() + { + return "return;"; + } } ! public Statement createReturnStmt(?Expression value) { return createReturnStmt(value, false); *************** *** 56,65 **** of syntactic sugar. */ ! public Statement createReturnStmt(Expression value, boolean fake) { ! let res = new ReturnStmt(value: value, fake: fake); ! if (value != null) ! res.setLocation(value.location()); return res; } --- 68,78 ---- of syntactic sugar. */ ! public Statement createReturnStmt(?Expression value, boolean fake) { ! if (value == null) ! return new VoidReturnStmt(); + let res = new ReturnStmt(value: value, fake: fake); + res.setLocation(value.location()); return res; } Index: analyse.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v retrieving revision 1.104 retrieving revision 1.105 diff -C2 -d -r1.104 -r1.105 *** analyse.nice 28 Jul 2004 14:40:33 -0000 1.104 --- analyse.nice 28 Jul 2004 20:48:27 -0000 1.105 *************** *** 840,843 **** --- 840,848 ---- } + analyse(r@VoidReturnStmt, info) + { + info.setUnreachable(); + } + analyse(t@TryStmt, info) { Index: funexp.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/funexp.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** funexp.nice 28 Jul 2004 14:40:33 -0000 1.1 --- funexp.nice 28 Jul 2004 20:48:28 -0000 1.2 *************** *** 112,116 **** { let ReturnStmt rs = cast(body); ! bodyValue = notNull(rs.value).toString(); } else --- 112,116 ---- { let ReturnStmt rs = cast(body); ! bodyValue = rs.value.toString(); } else Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.102 retrieving revision 1.103 diff -C2 -d -r1.102 -r1.103 *** typecheck.nice 28 Jul 2004 14:40:33 -0000 1.102 --- typecheck.nice 28 Jul 2004 20:48:28 -0000 1.103 *************** *** 864,883 **** ?mlsub.typing.Monotype expectedType = function.getExpectedType(); ! if (r.value != null) { ! if (expectedType == null) ! r.value = notNull(r.value).noOverloading(); ! else ! { ! if (! r.fake && nice.tools.typing.Types.isVoid(expectedType)) ! throw bossa.util.User.error(r, "Cannot return a value here"); ! r.value = notNull(r.value).resolveOverloading (new mlsub.typing.Polytype(expectedType)); - } - - try { typecheck(r.value); } - catch (bossa.util.UserError ex) { throw ensureLocated(ex, r); } } try{ --- 864,880 ---- ?mlsub.typing.Monotype expectedType = function.getExpectedType(); ! if (expectedType == null) ! r.value = notNull(r.value).noOverloading(); ! else { ! if (! r.fake && nice.tools.typing.Types.isVoid(expectedType)) ! throw bossa.util.User.error(r, "Cannot return a value here"); ! r.value = notNull(r.value).resolveOverloading (new mlsub.typing.Polytype(expectedType)); } + + try { typecheck(r.value); } + catch (bossa.util.UserError ex) { throw ensureLocated(ex, r); } try{ *************** *** 895,898 **** --- 892,917 ---- } + typecheck(r@VoidReturnStmt) + { + ?Function function = Node.currentFunction; + if (function == null) + throw bossa.util.User.error(r, "This return is not inside a function"); + + ?mlsub.typing.Monotype expectedType = function.getExpectedType(); + + try{ + if (! (expectedType != null && nice.tools.typing.Types.isVoid(expectedType))) + function.checkReturnedType(r.returnType()); + } + catch(Function.WrongReturnType e){ + wrongReturnType(r, notNull(r.returnType()).toString(), + valueOf(e.expectedReturnType), notNull(e.typingException)); + } + catch(Function.IncompatibleReturnType e){ + throw bossa.util.User.error(r, "The returned value is incompatible with the return type: " + e.previouslyInferredType); + } + } + + typecheck(t@TryStmt) { |