Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1:/tmp/cvs-serv16940/src/bossa/syntax
Modified Files:
NewExp.java JavaClasses.java
Log Message:
Support 'new Object()'.
Index: NewExp.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NewExp.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** NewExp.java 23 Jun 2003 17:49:01 -0000 1.36
--- NewExp.java 16 Dec 2003 12:34:33 -0000 1.37
***************
*** 15,18 ****
--- 15,20 ----
import bossa.util.*;
import java.util.*;
+ import mlsub.typing.TypeSymbol;
+ import mlsub.typing.TypeConstructor;
/**
***************
*** 30,41 ****
}
! private void resolveTC(TypeMap typeScope)
{
! if (tc != null)
! return;
!
! tc = ti.resolveToTC(typeScope);
! ti = null;
! if(!TypeConstructors.instantiable(tc))
{
String message;
--- 32,52 ----
}
! void resolve(TypeMap typeScope)
{
! TypeSymbol sym = ti.resolveToTypeSymbol(typeScope);
!
! if (sym == mlsub.typing.TopMonotype.instance)
! setObject();
! else if (sym instanceof TypeConstructor)
! setTC((TypeConstructor) sym);
! else
! throw User.error(ti, ti + " is not a class" + sym.getClass());
! }
!
! private void setTC(TypeConstructor tc)
! {
! this.tc = tc;
!
! if (! TypeConstructors.instantiable(tc))
{
String message;
***************
*** 48,60 ****
throw User.error(this, message);
}
- }
-
- void resolve(TypeMap typeScope)
- {
- if (tc != null)
- return;
- resolveTC(typeScope);
-
// Make sure that the constructors have been created.
ClassDefinition definition = ClassDefinition.get(tc);
--- 59,63 ----
***************
*** 79,83 ****
--- 82,93 ----
(constructors, new LocatedString("new " + tc, location()));
}
+
+ private void setObject()
+ {
+ JavaMethod method = JavaClasses.getObjectConstructor();
+ function = new SymbolExp(method.getSymbol(), ti.location());
+ }
+
/****************************************************************
* Printing
***************
*** 86,94 ****
public String toString()
{
! String cl = (ti == null ? tc.toString() : ti.toString());
return "new " + cl + arguments;
}
private TypeIdent ti;
! mlsub.typing.TypeConstructor tc;
}
--- 96,106 ----
public String toString()
{
! String cl = ti.toString();
return "new " + cl + arguments;
}
private TypeIdent ti;
!
! /** Can be null if the class instantiated is Object. */
! TypeConstructor tc = null;
}
Index: JavaClasses.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/JavaClasses.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -d -r1.42 -r1.43
*** JavaClasses.java 12 Dec 2003 14:53:30 -0000 1.42
--- JavaClasses.java 16 Dec 2003 12:34:33 -0000 1.43
***************
*** 306,310 ****
return possibilities;
! }
/**search recursively in superclasses and interfaces for static java fields*/
--- 306,321 ----
return possibilities;
! }
!
! private static JavaMethod objectConstructor;
!
! static JavaMethod getObjectConstructor()
! {
! if (objectConstructor == null)
! objectConstructor = JavaMethod.make
! (Type.pointer_type.getDeclaredMethod("<init>", 0), true);
!
! return objectConstructor;
! }
/**search recursively in superclasses and interfaces for static java fields*/
|