[Nice-commit] Nice/src/bossa/syntax alternative.nice,1.2,1.3 dispatch.java.bootstrap,1.44,1.45
Brought to you by:
bonniot
From: Arjan B. <ar...@us...> - 2004-12-21 01:31:25
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20983/F:/nice/src/bossa/syntax Modified Files: alternative.nice dispatch.java.bootstrap Log Message: Converted ImportedAlternative. Index: alternative.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/alternative.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** alternative.nice 20 Dec 2004 23:54:14 -0000 1.2 --- alternative.nice 21 Dec 2004 01:31:14 -0000 1.3 *************** *** 69,70 **** --- 69,167 ---- method: method); } + + /** + An alternative imported from a compiled package. + + */ + public class ImportedAlternative extends Alternative + { + private gnu.expr.Expression code; + private Location loc; + + methodExp() = code; + + location() = loc; + } + + /** + * When read from a bytecode file. + */ + public void readImportedAlternative(gnu.bytecode.ClassType c, gnu.bytecode.Method method, Location location) + { + ?gnu.bytecode.MiscAttr attr = cast(gnu.bytecode.Attribute.get(method, "definition")); + if (attr == null) + // this must be a toplevel function, a constructor, ... + return; + + String fullName = new String(attr.data); + + registerJavaMethod(fullName); + + attr = cast(gnu.bytecode.Attribute.get(method, "patterns")); + if (attr == null) + throw Internal.error("Method " + method.getName() + + " in class " + c.getName() + " has no patterns"); + String rep = new String(attr.data); + + int[]/*ref*/ at = [0]; + + ArrayList<Pattern> patterns = new ArrayList(5); + + try { + ?Pattern p; + + while ((p = bossa.syntax.dispatch.readPattern(rep, at)) != null) + { + if (p.getTC() == nice.tools.typing.PrimitiveType.arrayTC) + /* Special treatment for arrays: + they are compiled into Object, + but we want a SpecialArray in the method bytecode type. + */ + { + int argnum = patterns.size(); + if (notNull(method.arg_types)[argnum] == gnu.bytecode.Type.pointer_type) + notNull(method.arg_types)[argnum] = nice.tools.code.SpecialArray.unknownTypeArray(); + } + + patterns.add(p); + } + + let alt = new ImportedAlternative(method.getName(), patterns.toArray(), + code: new gnu.expr.QuoteExp(new gnu.expr.PrimProcedure(method)), + loc: location); + + alt.add(nice.tools.util.System.split + (fullName, MethodDeclaration.methodListSeparator)); + } + catch(Pattern.Unknown ex) { + // This can happen if the class exists only in a later version + // of the JDK. We just ignore this alternative. + } + } + + /** + If this full name refers to a java method, make sure it participates + to the link tests and dispatch code generation. + */ + private void registerJavaMethod(String fullName) + { + if (! fullName.startsWith("JAVA:")) + return; + + int end = fullName.lastIndexOf(':'); + let methodName = new LocatedString(fullName.substring("JAVA:".length(), end), + bossa.util.Location.nowhere()); + + for (VarSymbol sym : bossa.syntax.Node.getGlobalScope().lookup(methodName)) + { + if (sym.getMethodDeclaration() == null) + continue; + + MethodDeclaration md = notNull(sym.getMethodDeclaration()); + if (md.getFullName().equals(fullName)) + { + md.registerForDispatch(); + return; + } + } + } \ No newline at end of file Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** dispatch.java.bootstrap 20 Dec 2004 23:54:14 -0000 1.44 --- dispatch.java.bootstrap 21 Dec 2004 01:31:14 -0000 1.45 *************** *** 13,16 **** --- 13,18 ---- public class dispatch { + public static void readImportedAlternative(gnu.bytecode.ClassType c, gnu.bytecode.Method method, bossa.util.Location location) {} + public static bossa.link.Alternative createJavaAlternative(bossa.syntax.MethodDeclaration method) { return null; } |