[Nice-commit] Nice/src/bossa/syntax constant.nice,NONE,1.1 ConstantExp.java,1.51,1.52 EnumDefinition
Brought to you by:
bonniot
From: Arjan B. <ar...@us...> - 2004-09-02 15:46:44
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29818/F:/nice/src/bossa/syntax Modified Files: ConstantExp.java EnumDefinition.java analyse.nice dispatch.java.bootstrap pattern.nice tools.nice Added Files: constant.nice Removed Files: NullExp.java StringConstantExp.java TypeConstantExp.java VoidConstantExp.java Log Message: Converted constantExp subclasses to Nice code. Index: analyse.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v retrieving revision 1.110 retrieving revision 1.111 diff -C2 -d -r1.110 -r1.111 *** analyse.nice 13 Aug 2004 21:04:41 -0000 1.110 --- analyse.nice 2 Sep 2004 15:46:32 -0000 1.111 *************** *** 351,355 **** throw unknownIdent(notNull(pkg.locatedName())); ! return TypeConstantExp.create(pkg, nextComponent); } } --- 351,355 ---- throw unknownIdent(notNull(pkg.locatedName())); ! return createTypeConstantExp(pkg, nextComponent); } } *************** *** 539,543 **** if (e.enableClassExp) ! return notNull(TypeConstantExp.create(e.ident)); throw unknownIdent(notNull(e.ident)); --- 539,543 ---- if (e.enableClassExp) ! return createTypeConstantExp(null, notNull(e.ident)); throw unknownIdent(notNull(e.ident)); *************** *** 647,651 **** } ! return TypeConstantExp.universalPolytype(tc, sure); } --- 647,651 ---- } ! return universalPolytype(tc, sure); } Index: pattern.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/pattern.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pattern.nice 14 Aug 2004 11:14:15 -0000 1.2 --- pattern.nice 2 Sep 2004 15:46:32 -0000 1.3 *************** *** 608,613 **** if (name[0] == '\"') ! return createPattern(ConstantExp.makeString(new LocatedString( ! name.substring(1,name.length()-1), loc))); if (name[0] == '<' || name[0] == '>') --- 608,613 ---- if (name[0] == '\"') ! return createPattern(createStringConstantExp( ! name.substring(1,name.length()-1))); if (name[0] == '<' || name[0] == '>') *************** *** 626,630 **** if (name.equals("NULL")) ! return createPattern(NullExp.create(loc)); if (name.equals("true") || name.equals("false") ) --- 626,630 ---- if (name.equals("NULL")) ! return createPattern(createNullExp(loc)); if (name.equals("true") || name.equals("false") ) --- NEW FILE: constant.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ /** The 'null' expression. */ public class NullExp extends ConstantExp { isNull() = true; computeType() { // The type needs to be generated each time, since it is polymorphic. } getType() { let alpha = new mlsub.typing.MonotypeVar("any"); return new mlsub.typing.Polytype(new mlsub.typing.Constraint([alpha], null), bossa.syntax.Monotype.maybe(alpha)); } compile() = notNull(gnu.expr.QuoteExp.nullExp); toString() = "null"; } ConstantExp createNullExp(bossa.util.Location loc) { let res = new NullExp(); res.setLocation(loc); return res; } /** The void constant. */ public class VoidConstantExp extends ConstantExp { { this.className = voidName; this.value = gnu.mapping.Values.empty; } toString() = "{}"; } let LocatedString voidName = new LocatedString("void", bossa.util.Location.nowhere()); /** A String constant. */ public class StringConstantExp extends ConstantExp { final String escapedValue; toString() = "\""+escapedValue+"\""; } public ConstantExp createStringConstantExp(String value) { return createStringConstantExp(value, false); } public StringConstantExp createStringConstantExp(String value, boolean multiline) { if (multiline) value = escapeEOL(value); let res = new StringConstantExp(escapedValue: value); res.value = unescapeLiteral(value); res.className = stringClassName; return res; } let LocatedString stringClassName = new LocatedString("java.lang.String", Location.nowhere()); // cf. JLS 3.10.6 public String unescapeLiteral(String s) { let sb = new StringBuffer(); int n = s.length(); for (int i = 0; i < n; i++) { char c = s[i]; if (c == '\\') { i++; char c2 = s[i]; if (c2 == 'b') sb.append('\b'); else if (c2 =='t') sb.append('\t'); else if (c2 =='n') sb.append('\n'); else if (c2 =='f') sb.append('\f'); else if (c2 =='r') sb.append('\r'); else if (c2 =='\"') sb.append('\"'); else if (c2 =='\'') sb.append('\''); else if (c2 =='\\') sb.append('\\'); else { // octal escape int code = int(c2) - int('0'); if (i+1 < n) { int ic3 = int(s[i+1]); if (int('0') <= ic3 <= int('7')) { code = 8*code + (ic3 - int('0')); i++; if (int('0') <= int(c2) <= int('3') && i+1 < n) { // try a last number... int ic4 = int(s[i+1]); if (int('0') <= ic4 <= int('7')) { code = 8*code + (ic4 - int('0')); i++; } } } } sb.append(char(code)); } } else { sb.append(c); } } return sb.toString(); } String escapeEOL(String s) { let sb = new StringBuffer(); int n = s.length(); for (int i = 0; i < n; i++) { char c = s[i]; if (c == '\n') sb.append("\\n"); else if (c == '\r') { sb.append("\\n"); if (s[i+1] == '\n') i++; } else sb.append(c); } return sb.toString(); } /** A type used as an expression. */ public class TypeConstantExp extends ConstantExp { staticClass() { // If this is a '<name>.class' expression, do not consider it as a // qualified prefix. if (isExpression) return null; return cast(value); } void setRepresentedType(mlsub.typing.Polytype type, ?gnu.bytecode.Type bytecodeType) { this.value = bytecodeType; this.representedType = type.getMonotype(); this.type = new mlsub.typing.Polytype (type.getConstraint(), Monotype.sure(new mlsub.typing.MonotypeConstructor (PrimitiveType.classTC, [type.getMonotype()]))); } compile() { if (isLiteral) return super; gnu.bytecode.Type type = cast(value); String representation = type instanceof gnu.bytecode.ArrayType ? type.getSignature().replace('/', '.') : type.getName(); return new gnu.expr.ApplyExp(class_forName, [new gnu.expr.QuoteExp(representation)]); } TypeConstructor getTC() { return nice.tools.typing.Types.rawType(representedType).head(); } ?mlsub.typing.Monotype representedType = null; public boolean isExpression = false; public boolean isLiteral = false; } public TypeConstantExp createTypeConstantExp(LocatedString name) { return new TypeConstantExp(null, null, name, name.toString(), name.location()); } /** @return an Expression representing [root].[name] or a type or package literal if root == null */ Expression createTypeConstantExp(?PackageExp root, LocatedString name) { String fullName = name.toString(); if (root != null) fullName =notNull(root.name).append(".").append(fullName).toString(); ?mlsub.typing.TypeConstructor tc = Node.getGlobalTypeScope().globalLookup(fullName, name.location()); if(tc != null) { gnu.bytecode.Type type = nice.tools.code.Types.javaType(tc); // type might not be a class // for instance if the ident was "int" if (type instanceof gnu.bytecode.ClassType) { TypeConstantExp res = new TypeConstantExp(name); res.setRepresentedType(universalPolytype(tc, true), type); res.setLocation(root == null ? name.location() : root.location()); return res; } } if (root != null) // name has been appended to root's name return root; let res = new PackageExp(fullName); res.setLocation(name.location()); return res; } mlsub.typing.Polytype universalPolytype(mlsub.typing.TypeConstructor tc, boolean sure) { mlsub.typing.MonotypeVar[?] vars = mlsub.typing.MonotypeVar.news(tc.arity()); mlsub.typing.Monotype type = new mlsub.typing.MonotypeConstructor(tc, cast(vars)); return new mlsub.typing.Polytype (vars == null ? null : new mlsub.typing.Constraint(cast(vars), null), sure ? Monotype.sure(type) : Monotype.maybe(type)); } let gnu.bytecode.Method class_forName = gnu.bytecode.ClassType.make("java.lang.Class").getDeclaredMethod("forName", 1); --- TypeConstantExp.java DELETED --- --- NullExp.java DELETED --- --- StringConstantExp.java DELETED --- Index: EnumDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/EnumDefinition.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** EnumDefinition.java 12 Aug 2004 23:21:41 -0000 1.13 --- EnumDefinition.java 2 Sep 2004 15:46:32 -0000 1.14 *************** *** 98,102 **** super(name, type); List args = new ArrayList(2 + fields.size()); ! args.add(new Arguments.Argument(new StringConstantExp(name.toString()), new LocatedString("name",name.location))); Integer val = new Integer(ordinal); --- 98,102 ---- super(name, type); List args = new ArrayList(2 + fields.size()); ! args.add(new Arguments.Argument(bossa.syntax.dispatch.createStringConstantExp(name.toString()), new LocatedString("name",name.location))); Integer val = new Integer(ordinal); Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** tools.nice 13 Aug 2004 21:04:41 -0000 1.48 --- tools.nice 2 Sep 2004 15:46:32 -0000 1.49 *************** *** 193,196 **** --- 193,197 ---- GlobalTypeScope getGlobalTypeScope() = native GlobalTypeScope Node.getGlobalTypeScope(); ?gnu.bytecode.ClassType staticClass(Arguments) = native gnu.bytecode.ClassType Arguments.staticClass(); + ?gnu.bytecode.ClassType staticClass(Expression) = native gnu.bytecode.ClassType Expression.staticClass(); List<VarSymbol> findJavaMethods(?gnu.bytecode.ClassType, String, int) = native List JavaClasses.findJavaMethods(gnu.bytecode.ClassType,java.lang.String,int); List<VarSymbol> findJavaMethods(?gnu.bytecode.ClassType, String) = native List JavaClasses.findJavaMethods(gnu.bytecode.ClassType,java.lang.String); Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** dispatch.java.bootstrap 25 Aug 2004 20:49:39 -0000 1.21 --- dispatch.java.bootstrap 2 Sep 2004 15:46:32 -0000 1.22 *************** *** 72,75 **** --- 72,78 ---- { return null; } + public static ConstantExp createStringConstantExp(String value) + { return null; } + static Statement analyse(Statement s, VarScope v, TypeScope t, boolean r) { return null; } Index: ConstantExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ConstantExp.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** ConstantExp.java 5 Aug 2004 19:01:18 -0000 1.51 --- ConstantExp.java 2 Sep 2004 15:46:32 -0000 1.52 *************** *** 274,284 **** } - public static ConstantExp makeString(LocatedString representation) - { - StringConstantExp res = new StringConstantExp(representation.toString()); - res.setLocation(representation.location()); - return res; - } - /**************************************************************** * Booleans --- 274,277 ---- --- VoidConstantExp.java DELETED --- |