[Nice-commit] Nice/src/bossa/syntax typecheck.nice,1.54,1.55 analyse.nice,1.56,1.57 UserOperator.jav
Brought to you by:
bonniot
Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1:/tmp/cvs-serv18669/src/bossa/syntax
Modified Files:
typecheck.nice analyse.nice UserOperator.java ReturnStmt.java
PrimitiveType.java MonoSymbol.java
Log Message:
Allow functions returning a value to be used as arguments where
functions returning void are expected.
Index: typecheck.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** typecheck.nice 12 Mar 2003 12:07:38 -0000 1.54
--- typecheck.nice 13 Mar 2003 23:19:41 -0000 1.55
***************
*** 626,631 ****
r.value = notNull(r.value).noOverloading();
else
! r.value = notNull(r.value).resolveOverloading
! (new mlsub.typing.Polytype(expectedType));
try { typecheck(r.value); }
--- 626,636 ----
r.value = notNull(r.value).noOverloading();
else
! {
! if (! r.fake && nice.tools.code.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); }
Index: analyse.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v
retrieving revision 1.56
retrieving revision 1.57
diff -C2 -d -r1.56 -r1.57
*** analyse.nice 18 Feb 2003 23:39:43 -0000 1.56
--- analyse.nice 13 Mar 2003 23:19:41 -0000 1.57
***************
*** 175,178 ****
--- 175,181 ----
{
symbol.type = notNull(notNull(symbol.syntacticType).resolve(this.typeMap));
+ if (nice.tools.code.Types.isVoid(symbol.type))
+ throw error(symbol, "A variable cannot have a void type");
+
this.vars[symbol.name.toString()] = symbol;
}
Index: UserOperator.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/UserOperator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** UserOperator.java 27 Nov 2002 17:56:08 -0000 1.2
--- UserOperator.java 13 Mar 2003 23:19:42 -0000 1.3
***************
*** 53,57 ****
{
mlsub.typing.Monotype[] paramTypes = getArgTypes();
! for (int i = 0; i < symbols.length; i++)
if (symbols[i].name != null)
{
--- 53,60 ----
{
mlsub.typing.Monotype[] paramTypes = getArgTypes();
! for (int i = 0; i < symbols.length; i++) {
! if (Types.isVoid(paramTypes[i]))
! throw bossa.util.User.error(symbols[i].syntacticType,
! "A parameter cannot have a void type");
if (symbols[i].name != null)
{
***************
*** 59,62 ****
--- 62,66 ----
scope.addSymbol(symbols[i]);
}
+ }
}
Index: ReturnStmt.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ReturnStmt.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** ReturnStmt.java 20 Jan 2003 19:20:59 -0000 1.27
--- ReturnStmt.java 13 Mar 2003 23:19:42 -0000 1.28
***************
*** 31,37 ****
--- 31,47 ----
public ReturnStmt(Expression value)
{
+ this(value, false);
+ }
+
+ /**
+ @param fake This return was not explicitely written, but is the result
+ of syntactic sugar.
+ */
+ public ReturnStmt(Expression value, boolean fake)
+ {
this.value = value;
if (value != null)
this.setLocation(value.location());
+ this.fake = fake;
}
***************
*** 66,68 ****
--- 76,79 ----
Expression value;
+ boolean fake;
}
Index: PrimitiveType.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/PrimitiveType.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** PrimitiveType.java 18 Feb 2003 14:21:20 -0000 1.4
--- PrimitiveType.java 13 Mar 2003 23:19:42 -0000 1.5
***************
*** 117,120 ****
--- 117,122 ----
if(name.equals("nice.lang.void"))
{
+ voidTC = tc;
+ mlsub.typing.lowlevel.Engine.setTop(tc);
voidType = Monotype.sure(new MonotypeConstructor(tc, null));
voidPolytype = new mlsub.typing.Polytype
***************
*** 162,166 ****
}
! public static TypeConstructor byteTC, charTC, intTC, longTC, boolTC, shortTC, doubleTC, floatTC, arrayTC;
//these two only for dispatch testing booleans
public static TypeConstructor trueBoolTC, falseBoolTC;
--- 164,168 ----
}
! public static TypeConstructor byteTC, charTC, intTC, longTC, boolTC, shortTC, doubleTC, floatTC, arrayTC, voidTC;
//these two only for dispatch testing booleans
public static TypeConstructor trueBoolTC, falseBoolTC;
Index: MonoSymbol.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MonoSymbol.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** MonoSymbol.java 25 Sep 2002 16:40:26 -0000 1.19
--- MonoSymbol.java 13 Mar 2003 23:19:42 -0000 1.20
***************
*** 91,94 ****
--- 91,97 ----
type = syntacticType.resolve(typeScope);
syntacticType = null;
+
+ if (Types.isVoid(type))
+ throw User.error(name, "A variable cannot have a void type");
}
|