Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27004/F:/nice/src/bossa/syntax
Modified Files:
analyse.nice SuperExp.java
Log Message:
Type(constructors) can be passed to an SuperExp to resolve ambigiuties.
Index: analyse.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v
retrieving revision 1.98
retrieving revision 1.99
diff -C2 -d -r1.98 -r1.99
*** analyse.nice 2 Feb 2004 23:21:44 -0000 1.98
--- analyse.nice 5 Feb 2004 22:59:52 -0000 1.99
***************
*** 635,638 ****
--- 635,644 ----
}
+
+ analyse(e@SuperExp, info)
+ {
+ e.resolveTC(info.outerTypeScope);
+ return e;
+ }
/****************************************************************
* Statements
Index: SuperExp.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/SuperExp.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** SuperExp.java 12 Dec 2003 18:51:31 -0000 1.15
--- SuperExp.java 5 Feb 2004 22:59:53 -0000 1.16
***************
*** 37,40 ****
--- 37,46 ----
public class SuperExp extends Expression
{
+
+ public SuperExp(List types)
+ {
+ this.types = types;
+ }
+
void setCurrentMethod(MethodBodyDefinition m)
{
***************
*** 42,45 ****
--- 48,54 ----
MethodDeclaration decl = currentMethod.getDeclaration();
+ if (tc != null && tc.size() != decl.getArity())
+ User.error(this, "Number of types doesn't match the number of arguments");
+
superAlternative = getSuper(decl);
}
***************
*** 49,52 ****
--- 58,73 ----
Method superMethod = null;
+ private Pattern[] minimumPatterns()
+ {
+ if (tc == null)
+ return null;
+
+ Pattern[] res = new Pattern[tc.size()];
+ for (int i = 0; i < tc.size(); i++)
+ res[i] = new Pattern((TypeConstructor)tc.get(i), false);
+
+ return res;
+ }
+
private Alternative getSuper(MethodDeclaration decl)
{
***************
*** 55,58 ****
--- 76,80 ----
java.util.Iterator alternatives = Alternative.sortedAlternatives(decl).iterator();
+ Pattern[] mPatterns = minimumPatterns();
// Look for the first alternative more general than the current one.
***************
*** 61,64 ****
--- 83,101 ----
Alternative a = (Alternative) alternatives.next();
if (a == current) continue;
+
+ if (mPatterns != null)
+ {
+ boolean match = true;
+ Pattern[] aPatterns = a.getPatterns();
+ for (int i = 0; i < mPatterns.length; i++)
+ if (! aPatterns[i].leq(mPatterns[i]))
+ {
+ match = false;
+ break;
+ }
+
+ if (!match)
+ continue;
+ }
if (Alternative.leq(current, a))
***************
*** 110,113 ****
--- 147,160 ----
}
+ public void resolveTC(TypeScope scope)
+ {
+ if (types != null)
+ {
+ tc = new ArrayList();
+ for (Iterator it = types.iterator(); it.hasNext();)
+ tc.add(((TypeIdent)it.next()).resolveToTC(scope));
+ }
+ }
+
/****************************************************************
* Typing
***************
*** 218,222 ****
public String toString()
{
! return "super";
}
}
--- 265,272 ----
public String toString()
{
! return "super" + (types != null ? "" : Util.map("(", ", ", ")", types));
}
+
+ List/*TypeIdent*/ types;
+ List/*TypeConstructor*/ tc = null;
}
|