[Nice-commit] Nice/src/bossa/syntax typecheck.nice,1.52,1.53 tools.nice,1.18,1.19
Brought to you by:
bonniot
|
From: <bo...@us...> - 2003-03-12 03:27:12
|
Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1:/tmp/cvs-serv18990/src/bossa/syntax
Modified Files:
typecheck.nice tools.nice
Log Message:
Handle nullness tests on the right side of && and || expressions.
Index: typecheck.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -d -r1.52 -r1.53
*** typecheck.nice 11 Mar 2003 20:14:26 -0000 1.52
--- typecheck.nice 12 Mar 2003 03:26:36 -0000 1.53
***************
*** 53,57 ****
variable.setVarType(now: unsureType,
otherBranch: variable.type,
! brothers: unsureType);
return;
}
--- 53,57 ----
variable.setVarType(now: unsureType,
otherBranch: variable.type,
! out: unsureType);
return;
}
***************
*** 96,103 ****
}
typecheck(e@CallExp)
{
typecheck(e.function);
! e.arguments.typecheckArgs();
// forces computation of the type if not done.
--- 96,170 ----
}
+ void typecheckAndArgs(Arguments args)
+ {
+ if (args.size() != 2)
+ {
+ typecheckArgs(args);
+ return;
+ }
+
+ enterIf();
+ try {
+ typecheck(args.getExp(0));
+
+ ?List<MonoSymbol> l = variablesNotNullIfTestSucceeds(args.getExp(0));
+ if (l != null)
+ l.foreach(MonoSymbol variable => {
+ mlsub.typing.Monotype type = notNull(variable.type);
+ mlsub.typing.Monotype sureType = makeSure(type);
+ setVarType(variable, now: sureType, out: type);
+ });
+
+ typecheck(args.getExp(1));
+ args.getExp(1).computeType();
+ }
+ finally {
+ // There is no else part, but this call is necessary to pop off
+ // conditional type information (from assignments) from the stack.
+ enterElse();
+ exitIf();
+ }
+ }
+
+ void typecheckOrArgs(Arguments args)
+ {
+ if (args.size() != 2)
+ {
+ typecheckArgs(args);
+ return;
+ }
+
+ enterIf();
+ try {
+ typecheck(args.getExp(0));
+
+ ?List<MonoSymbol> l = variablesNotNullIfTestFails(args.getExp(0));
+ if (l != null)
+ l.foreach(MonoSymbol variable => {
+ mlsub.typing.Monotype type = notNull(variable.type);
+ mlsub.typing.Monotype sureType = makeSure(type);
+ setVarType(variable, now: sureType, out: type);
+ });
+
+ typecheck(args.getExp(1));
+ args.getExp(1).computeType();
+ }
+ finally {
+ // There is no else part, but this call is necessary to pop off
+ // conditional type information (from assignments) from the stack.
+ enterElse();
+ exitIf();
+ }
+ }
+
typecheck(e@CallExp)
{
typecheck(e.function);
! if (e.isCallTo("&&"))
! e.arguments.typecheckAndArgs();
! else if (e.isCallTo("||"))
! e.arguments.typecheckOrArgs();
! else
! e.arguments.typecheckArgs();
// forces computation of the type if not done.
***************
*** 215,218 ****
--- 282,292 ----
}
+ ?List<MonoSymbol> variablesNotNullIfTestFails(Expression test)
+ {
+ (?List<MonoSymbol> notNullIfTrue, ?List<MonoSymbol> notNullIfFalse) =
+ nullnessInfo(test);
+ return notNullIfFalse;
+ }
+
/**
Collects knowledge about more precise type in branches of conditionals.
***************
*** 255,259 ****
}
! void pushBrotherType(MonoSymbol variable, mlsub.typing.Monotype baseType)
{
levels.push(2 * ifLevel + 1);
--- 329,333 ----
}
! void pushOuterType(MonoSymbol variable, mlsub.typing.Monotype baseType)
{
levels.push(2 * ifLevel + 1);
***************
*** 289,293 ****
mlsub.typing.Monotype type = notNull(variable.type);
mlsub.typing.Monotype sureType = makeSure(type);
! setVarType(variable, now: sureType, brothers: type);
});
--- 363,367 ----
mlsub.typing.Monotype type = notNull(variable.type);
mlsub.typing.Monotype sureType = makeSure(type);
! setVarType(variable, now: sureType, otherBranch: type);
});
***************
*** 304,308 ****
mlsub.typing.Monotype type = notNull(variable.type);
mlsub.typing.Monotype sureType = makeSure(type);
! setVarType(variable, now: sureType, brothers: type);
});
--- 378,382 ----
mlsub.typing.Monotype type = notNull(variable.type);
mlsub.typing.Monotype sureType = makeSure(type);
! setVarType(variable, now: sureType, out: type);
});
***************
*** 330,343 ****
@param now type to be used in the next branch.
@param otherBranch type to be used in the other branches
! @param brothers type to be used in the block containing the conditional
! @param later type to be used when returning to the parent block
*/
private void setVarType(MonoSymbol variable,
mlsub.typing.Monotype now,
?mlsub.typing.Monotype otherBranch = null,
! mlsub.typing.Monotype brothers)
{
variable.type = now;
! pushBrotherType(variable, brothers);
if (otherBranch != null)
pushBranchType(variable, otherBranch);
--- 404,417 ----
@param now type to be used in the next branch.
@param otherBranch type to be used in the other branches
! @param out type to be used after returning to the outer block
*/
private void setVarType(MonoSymbol variable,
mlsub.typing.Monotype now,
?mlsub.typing.Monotype otherBranch = null,
! ?mlsub.typing.Monotype out = null)
{
variable.type = now;
! if (out != null)
! pushOuterType(variable, out);
if (otherBranch != null)
pushBranchType(variable, otherBranch);
***************
*** 499,503 ****
setVarType(variable,
now: makeSure(variable.type),
! brothers: variable.type));
}
--- 573,577 ----
setVarType(variable,
now: makeSure(variable.type),
! out: variable.type));
}
Index: tools.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** tools.nice 20 Feb 2003 14:58:39 -0000 1.18
--- tools.nice 12 Mar 2003 03:26:37 -0000 1.19
***************
*** 24,27 ****
--- 24,28 ----
identString(e@IdentExp) = e.ident;
identString(e@SymbolExp) = e.getName();
+ identString(e@OverloadedSymbolExp) = e.ident;
boolean isCallTo(CallExp e, String name)
|