summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab/classfile
diff options
context:
space:
mode:
Diffstat (limited to 'sources/scalac/symtab/classfile')
-rw-r--r--sources/scalac/symtab/classfile/AttributeParser.java216
-rw-r--r--sources/scalac/symtab/classfile/CLRClassParser.java538
-rw-r--r--sources/scalac/symtab/classfile/CLRPackageParser.java151
-rw-r--r--sources/scalac/symtab/classfile/CLRTypes.java330
-rw-r--r--sources/scalac/symtab/classfile/ClassParser.java49
-rw-r--r--sources/scalac/symtab/classfile/ClassfileConstants.java79
-rw-r--r--sources/scalac/symtab/classfile/ClassfileParser.java323
-rw-r--r--sources/scalac/symtab/classfile/ConstantPool.java217
-rw-r--r--sources/scalac/symtab/classfile/JavaTypeCreator.java162
-rw-r--r--sources/scalac/symtab/classfile/JavaTypeFactory.java35
-rw-r--r--sources/scalac/symtab/classfile/MetaParser.java287
-rw-r--r--sources/scalac/symtab/classfile/PackageParser.java232
-rw-r--r--sources/scalac/symtab/classfile/Pickle.java616
-rw-r--r--sources/scalac/symtab/classfile/Signatures.java175
-rw-r--r--sources/scalac/symtab/classfile/SymblParser.java47
-rw-r--r--sources/scalac/symtab/classfile/UnPickle.java643
16 files changed, 0 insertions, 4100 deletions
diff --git a/sources/scalac/symtab/classfile/AttributeParser.java b/sources/scalac/symtab/classfile/AttributeParser.java
deleted file mode 100644
index 7f04a3d147..0000000000
--- a/sources/scalac/symtab/classfile/AttributeParser.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-** **
-** $Id$
-\* */
-
-package scalac.symtab.classfile;
-
-import scala.tools.util.Position;
-import scala.tools.util.AbstractFileReader;
-import scalac.*;
-import scalac.atree.AConstant;
-import scalac.symtab.*;
-import scalac.util.*;
-import java.util.*;
-
-public class AttributeParser implements ClassfileConstants {
-
- /** the classfile input buffer
- */
- protected AbstractFileReader in;
-
- /** the constant pool
- */
- protected ConstantPool pool;
-
- protected ClassfileParser parser;
-
- /** constructor
- */
- public AttributeParser(AbstractFileReader in,
- ConstantPool pool,
- ClassfileParser parser)
- {
- this.in = in;
- this.pool = pool;
- this.parser = parser;
- }
-
- /** convert an attribute name into an attribute id
- */
- public int nameToId(Name name) {
- if (name == SOURCEFILE_N)
- return SOURCEFILE_ATTR;
- if (name == SYNTHETIC_N)
- return SYNTHETIC_ATTR;
- if (name == DEPRECATED_N)
- return DEPRECATED_ATTR;
- if (name == CODE_N)
- return CODE_ATTR;
- if (name == EXCEPTIONS_N)
- return EXCEPTIONS_ATTR;
- if (name == CONSTANT_VALUE_N)
- return CONSTANT_VALUE_ATTR;
- if (name == LINE_NUM_TABLE_N)
- return LINE_NUM_TABLE_ATTR;
- if (name == LOCAL_VAR_TABLE_N)
- return LOCAL_VAR_TABLE_ATTR;
- if (name == INNERCLASSES_N)
- return INNERCLASSES_ATTR;
- if (name == META_N)
- return META_ATTR;
- if (name == SCALA_N)
- return SCALA_ATTR;
- if (name == JACO_N)
- return JACO_ATTR;
- if (name == BRIDGE_N)
- return BRIDGE_ATTR;
- if (name == SIG_N)
- return SIG_ATTR;
- return BAD_ATTR;
- }
-
- /** skip all attributes.
- */
- public void skipAttributes() {
- char nattr = in.nextChar();
- for (int i = 0; i < nattr; i++) {
- in.skip(2);
- in.skip(in.nextInt());
- }
- }
-
- /** read all attributes associated with symbol 'sym' which are
- * contained in 'attrs'.
- */
- public Symbol readAttributes(Symbol def, Type type, int attrs) {
- char nattr = in.nextChar();
- for (int i = 0; i < nattr; i++) {
- Name attrName = pool.getName(in.nextChar());
- int attr = nameToId(attrName);
- int attrLen = in.nextInt();
- if ((attrs & attr) == 0) {
- //System.out.println("# skipping " + attrName + " of " + def);
- in.skip(attrLen);
- } else {
- //System.out.println("# reading " + attrName + " of " + def);
- readAttribute(def, type, attr, attrLen);
- }
- }
- return def;
- }
-
- /** read a single attribute 'attr' for symbol 'sym' with type 'type'.
- */
- public void readAttribute(Symbol sym, Type type, int attr, int attrLen) {
- switch (attr) {
- // class attributes
- case SCALA_ATTR:
- try {
- UnPickle.parse(parser.global, in.nextBytes(attrLen), sym);
- return;
- } catch (UnPickle.BadSignature exception) {
- throw new RuntimeException(exception);
- }
- case INNERCLASSES_ATTR:
- int n = in.nextChar();
- //System.out.println(sym + " has " + n + " innerclass entries");
- for (int i = 0; i < n; i++) {
- int inner = in.nextChar();
- if (inner == 0) { in.skip(6); continue; }
- int outer = in.nextChar();
- if (outer == 0) { in.skip(4); continue; }
- int name = in.nextChar();
- if (name == 0) { in.skip(2); continue; }
- int flags = in.nextChar();
- if ((flags & JAVA_ACC_STATIC) == 0) continue;
- if ((flags & (JAVA_ACC_PUBLIC | JAVA_ACC_PROTECTED)) == 0)
- continue;
- if (pool.getClass(outer) != sym) continue;
- Symbol alias = sym.linkedModule().moduleClass()
- .newTypeAlias(Position.NOPOS, 0,
- pool.getName(name).toTypeName(),
- parser.make.classType(pool.getClass(inner)));
- parser.statics.enterNoHide(alias);
- }
- //in.skip(attrLen);
- return;
- // method attributes
- case CODE_ATTR:
- in.skip(attrLen);
- return;
- case EXCEPTIONS_ATTR:
- //int nexceptions = in.nextChar();
- //Type[] thrown = new Type[nexceptions];
- //for (int j = 0; j < nexceptions; j++)
- // thrown[j] = make.classType(reader.readClassName(in.nextChar()));
- //((MethodType)def.type).thrown = thrown;
- in.skip(attrLen);
- return;
- case LINE_NUM_TABLE_ATTR:
- in.skip(attrLen);
- return;
- case LOCAL_VAR_TABLE_ATTR:
- in.skip(attrLen);
- return;
- // general attributes
- case SYNTHETIC_ATTR:
- sym.flags |= Modifiers.SYNTHETIC;
- return;
- case BRIDGE_ATTR:
- sym.flags |= Modifiers.BRIDGE;
- return;
- case DEPRECATED_ATTR:
- sym.flags |= Modifiers.DEPRECATED;
- return;
- case CONSTANT_VALUE_ATTR:
- AConstant constant = pool.getConstantValue(in.nextChar());
- switch (constant) {
- case INT(int value):
- Definitions definitions = parser.global.definitions;
- Symbol base = sym.getType().symbol();
- if (base == definitions.INT_CLASS) break;
- if (base == definitions.CHAR_CLASS)
- constant = AConstant.CHAR((char)value);
- else if (base == definitions.SHORT_CLASS)
- constant = AConstant.SHORT((short)value);
- else if (base == definitions.BYTE_CLASS)
- constant = AConstant.BYTE((byte)value);
- else
- constant = AConstant.BOOLEAN(value != 0);
- }
- sym.setInfo(parser.make.constantType(constant));
- return;
- case META_ATTR:
- //System.out.println("parsing meta data for " + sym);
- String meta = pool.getString(in.nextChar()).trim();
- MetaParser mp = new MetaParser
- (meta, tvars, sym, type, parser.c, parser.ctype, parser.make);
- sym.setInfo(mp.parse());
- return;
- case JACO_ATTR:
- // this attribute is present in all PiCo generated classfiles
- int mods = in.nextChar();
- mods |= (in.nextChar() << 16);
- boolean algebraicClass = (mods & 0x00100000) != 0;
- boolean caseClass = (mods & 0x00200000) != 0;
- if (caseClass)
- sym.flags |= Modifiers.CASE | Modifiers.JAVA;
- in.skip(attrLen - 4);
- return;
- case SOURCEFILE_ATTR:
- String name = pool.getString(in.nextChar());
- parser.c.getOrigin().setSourceFileAttribute(name);
- parser.m.moduleClass().getOrigin().setSourceFileAttribute(name);
- return;
- default:
- in.skip(attrLen);
- return;
- }
- }
-
- Scope tvars = new Scope();
-}
diff --git a/sources/scalac/symtab/classfile/CLRClassParser.java b/sources/scalac/symtab/classfile/CLRClassParser.java
deleted file mode 100644
index 498237edbe..0000000000
--- a/sources/scalac/symtab/classfile/CLRClassParser.java
+++ /dev/null
@@ -1,538 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2003, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.symtab.classfile;
-
-import scalac.Global;
-import scalac.atree.AConstant;
-import scalac.symtab.Symbol;
-import scalac.symtab.SymbolLoader;
-import scalac.symtab.SymbolOrigin;
-import scalac.symtab.Scope;
-import scalac.symtab.Modifiers;
-import scalac.symtab.Type.*;
-import scalac.util.Name;
-import scalac.util.Names;
-import scalac.util.Debug;
-
-import scala.tools.util.Position;
-import ch.epfl.lamp.compiler.msil.*;
-
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Arrays;
-import java.util.Iterator;
-
-public class CLRClassParser extends SymbolLoader {
-
- //##########################################################################
-
- private static Name[] ENUM_CMP_NAMES = new Name[]
- { Names.EQ, Names.NE, Names.LT, Names.LE, Names.GT, Names.GE };
-
- private static Name[] ENUM_BIT_LOG_NAMES = new Name[]
- { Names.OR, Names.AND, Names.XOR };
-
- private static JavaTypeFactory make;
-
- private static final CLRTypes clrTypes = CLRTypes.instance();
-
- private final Type type;
-
- public CLRClassParser(Global global, Type type) {
- super(global);
- this.type = type;
- }
-
- private Symbol clazz;
- private Scope members;
- private Symbol staticsClass;
- private Scope statics;
- scalac.symtab.Type clazzType;
-
- private final Scope tvars = new Scope();
-
- protected String doComplete(Symbol root) {
- clazz = root;
- clazz.owner().initialize(); //???
-
- if (make == null)
- make = new JavaTypeCreator(global.definitions);
-
- clazz.flags = translateAttributes(type);
- Type[] ifaces = type.getInterfaces();
- scalac.symtab.Type[] baseTypes = new scalac.symtab.Type[ifaces.length+1];
- baseTypes[0] = type.BaseType() != null ? getCLRType(type.BaseType())
- : (type.IsInterface() ? make.objectType() : make.anyType());
- for (int i = 0; i < ifaces.length; i++)
- baseTypes[i + 1] = getCLRType(ifaces[i]);
- members = new Scope();
- statics = new Scope();
- scalac.symtab.Type clazzInfo =
- scalac.symtab.Type.compoundType(baseTypes, members, clazz);
- clazz.setInfo(clazzInfo);
- Symbol staticsModule = clazz.linkedModule();
- staticsClass = staticsModule.moduleClass();
- assert staticsClass.isModuleClass(): Debug.show(staticsClass);
- scalac.symtab.Type staticsInfo = scalac.symtab.Type.compoundType
- (scalac.symtab.Type.EMPTY_ARRAY, statics, staticsClass);
- staticsClass.setInfo(staticsInfo);
- staticsModule.setInfo(make.classType(staticsClass));
- clazzType = make.classType(clazz);
-
- // import nested types
- Type[] nestedTypes = type.getNestedTypes();
- for (int i = 0; i < nestedTypes.length; i++) {
- Type ntype = nestedTypes[i];
- if (ntype.IsNestedPrivate() || ntype.IsNestedAssembly()
- || ntype.IsNestedFamANDAssem())
- continue;
- Name classname = Name.fromString(ntype.Name).toTypeName();
- CLRClassParser loader = new CLRClassParser(global, ntype);
- SymbolOrigin origin = SymbolOrigin.CLRAssembly(ntype.Assembly());
- Symbol nclazz = staticsClass.newLoadedClass
- (JAVA, classname, loader, statics, origin);
- clrTypes.map(nclazz, ntype);
- }
-
- FieldInfo[] fields = type.getFields();
- for (int i = 0; i < fields.length; i++) {
- if (fields[i].IsPrivate() || fields[i].IsAssembly()
- || fields[i].IsFamilyAndAssembly())
- continue;
- int mods = translateAttributes(fields[i]);
- Name name = Name.fromString(fields[i].Name);
- scalac.symtab.Type fieldType = getCLRType(fields[i].FieldType);
- if (fields[i].IsLiteral() && !fields[i].FieldType.IsEnum())
- fieldType = make.constantType(
- getConstant(fieldType.symbol(), fields[i].getValue()));
- Symbol owner = fields[i].IsStatic() ? staticsClass : clazz;
- Symbol field = owner.newField(Position.NOPOS, mods, name);
- parseMeta(field, fields[i], fieldType);
- (fields[i].IsStatic() ? statics : members).enterOrOverload(field);
- clrTypes.map(field, fields[i]);
- }
-
- Set methodsSet = new HashSet(Arrays.asList(type.getMethods()));
-
- PropertyInfo[] props = type.getProperties();
- for (int i = 0; i < props.length; i++) {
- scalac.symtab.Type proptype = getCLSType(props[i].PropertyType);
- if (proptype == null)
- continue;
-
- MethodInfo getter = props[i].GetGetMethod(true);
- MethodInfo setter = props[i].GetSetMethod(true);
- if (getter == null || getter.IsPrivate() ||
- getter.IsAssembly() || getter.IsFamilyAndAssembly())
- continue;
- assert props[i].PropertyType == getter.ReturnType;
- Name n;
- scalac.symtab.Type mtype;
-
- ParameterInfo[] gparams = getter.GetParameters();
- if (gparams.length == 0) {
- n = Name.fromString(props[i].Name);
- mtype =
- scalac.symtab.Type.PolyType(Symbol.EMPTY_ARRAY, proptype);
- } else {
- n = Names.apply;
- mtype = methodType(getter, getter.ReturnType);
- }
- int mods = translateAttributes(getter);
- createMethod(n, mods, mtype, getter, getter.IsStatic());
- assert methodsSet.contains(getter) : "" + getter;
- methodsSet.remove(getter);
-
- if (setter == null || setter.IsPrivate() ||
- setter.IsAssembly() || setter.IsFamilyAndAssembly())
- continue;
- ParameterInfo[] sparams = setter.GetParameters();
- assert getter.IsStatic() == setter.IsStatic();
- assert setter.ReturnType == clrTypes.VOID;
- assert sparams.length == gparams.length + 1 : "" + getter + "; " + setter;
-
- if (gparams.length == 0)
- n = Name.fromString(n.toString() + Names._EQ);
- else n = Names.update;
-
- mods = translateAttributes(setter);
- mtype = methodType(setter, global.definitions.UNIT_TYPE());
- createMethod(n, mods, mtype, setter, setter.IsStatic());
- assert methodsSet.contains(setter) : "" + setter;
- methodsSet.remove(setter);
- }
-
- for (Iterator i = methodsSet.iterator(); i.hasNext(); ) {
- MethodInfo method = (MethodInfo)i.next();
- if ((clrTypes.getSymbol(method) != null) || method.IsPrivate()
- || method.IsAssembly() || method.IsFamilyAndAssembly())
- continue;
- createMethod(method);
- }
-
- // Create symbols related to delegate types
- if(clrTypes.isDelegateType(type)) {
- createDelegateView();
- createDelegateChainers();
- }
-
- // for enumerations introduce comparison and bitwise logical operations;
- // the backend should recognize and replace them with comparison or
- // bitwise logical operations on the primitive underlying type
- if (type.IsEnum()) {
- scalac.symtab.Type[] argTypes = new scalac.symtab.Type[] {clazzType};
- int mods = Modifiers.JAVA | Modifiers.FINAL;
- for (int i = 0; i < ENUM_CMP_NAMES.length; i++) {
- scalac.symtab.Type enumCmpType =
- make.methodType(argTypes,
- global.definitions.boolean_TYPE(),
- scalac.symtab.Type.EMPTY_ARRAY);
- createMethod(ENUM_CMP_NAMES[i], mods, enumCmpType, null, false);
- }
- for (int i = 0; i < ENUM_BIT_LOG_NAMES.length; i++) {
- scalac.symtab.Type enumBitLogType = make.methodType
- (argTypes, clazzType, scalac.symtab.Type.EMPTY_ARRAY);
- createMethod
- (ENUM_BIT_LOG_NAMES[i], mods, enumBitLogType, null, false);
- }
- }
-
- ConstructorInfo[] constrs = type.getConstructors();
- for (int i = 0; i < constrs.length; i++) {
- if (constrs[i].IsStatic() || constrs[i].IsPrivate()
- || constrs[i].IsAssembly() || constrs[i].IsFamilyAndAssembly())
- continue;
- createConstructor(constrs[i]);
- }
-
- Symbol constr = clazz.primaryConstructor();
- if (!constr.isInitialized()) {
- constr.setInfo(scalac.symtab.Type.MethodType
- (Symbol.EMPTY_ARRAY, clazzType));
- if ((clazz.flags & Modifiers.INTERFACE) == 0)
- constr.flags |= Modifiers.PRIVATE;
- }
-
- parseMeta(clazz, type, clazzInfo);
-
- return type + " from assembly " + type.Assembly();
- }
-
- private scalac.symtab.Type parseMeta(Symbol sym,
- ICustomAttributeProvider member,
- scalac.symtab.Type defaultType)
- {
- if (member !=null && member.IsDefined(clrTypes.PICO_META_ATTR, false)) {
- Object[] attrs =
- member.GetCustomAttributes(clrTypes.PICO_META_ATTR, false);
- assert attrs.length == 1 : "attrs.length = " + attrs.length;
- String meta =
- (String)((Attribute)attrs[0]).getConstructorArguments()[0];
- defaultType = new MetaParser
- (meta, tvars, sym, defaultType, clazz, clazzType, make).parse();
- }
- sym.setInfo(defaultType);
- return defaultType;
- }
-
- private void createConstructor(ConstructorInfo constr) {
- scalac.symtab.Type mtype = methodType(constr, clazzType);
- if (mtype == null)
- return;
- Symbol constrSym = clazz.primaryConstructor();
- int mods = translateAttributes(constr);
- if (constrSym.isInitialized()) {
- constrSym = clazz.newConstructor(Position.NOPOS, mods);
- clazz.addConstructor(constrSym);
- } else {
- constrSym.flags = mods;
- }
- setParamOwners(mtype, constrSym);
- parseMeta(constrSym, constr, mtype);
- clrTypes.map(constrSym, constr);
- }
-
- private void createMethod(MethodInfo method) {
- scalac.symtab.Type mtype =
- methodType(method, method.ReturnType);
- if (mtype == null)
- return;
- int mods = translateAttributes(method);
- createMethod(getName(method), mods, mtype, method, method.IsStatic());
- }
-
- // Create static view methods within the delegate and the function type
- // with the following signatures:
- // def MyDelegate.view(MyDelegate): FunctionX[InvokeArgs..., InvokeRet];
- // def FunctionX.view(FunctionX[InvokeArgs..., InvokeRet]): MyDelegate;
- private void createDelegateView() {
- // Extract the parameter and return types of the Invoke method
- MethodInfo invoke = (MethodInfo)type.GetMember("Invoke")[0];
- scalac.symtab.Type invokeRetType = getCLRType(invoke.ReturnType);
- scalac.symtab.Type invokeParamTypes[] =
- new scalac.symtab.Type[invoke.GetParameters().length];
- for(int j = 0; j < invoke.GetParameters().length; j++)
- invokeParamTypes[j] =
- getCLRType(invoke.GetParameters()[j].ParameterType);
- scalac.symtab.Type funType =
- global.definitions.FUNCTION_TYPE(invokeParamTypes, invokeRetType);
-
- // FORWARD MAPPING (Delegate => Function)
- scalac.symtab.Type viewParamTypes[] = { getCLRType(type) };
- scalac.symtab.Type viewRetType = funType;
- scalac.symtab.Type viewMethodType = make.methodType(
- viewParamTypes,
- viewRetType,
- scalac.symtab.Type.EMPTY_ARRAY);
-
- createMethod(Names.view, Modifiers.JAVA, viewMethodType, null, true);
-
- // REVERSE MAPPING (Function => Delegate)
- viewParamTypes = new scalac.symtab.Type[]{ funType };
- viewRetType = getCLRType(type);
- viewMethodType = make.methodType(
- viewParamTypes,
- viewRetType,
- scalac.symtab.Type.EMPTY_ARRAY);
-
- createMethod(Names.view, Modifiers.JAVA, viewMethodType, null, true);
- }
-
- private void createDelegateChainers() {
- int mods = Modifiers.JAVA | Modifiers.FINAL;
- Type[] args = new Type[]{type};
-
- createMethod(Names.PLUSEQ, mods, args, clrTypes.VOID,
- clrTypes.DELEGATE_COMBINE, false);
- createMethod(Names.MINUSEQ, mods, args, clrTypes.VOID,
- clrTypes.DELEGATE_REMOVE, false);
- createMethod
- (Names.PLUS, mods, args, type, clrTypes.DELEGATE_COMBINE, false);
- createMethod
- (Names.MINUS, mods, args, type, clrTypes.DELEGATE_REMOVE, false);
- }
-
- private Symbol createMethod(Name name, int mods, Type[] args,
- Type retType, MethodInfo method, boolean statik)
- {
- return createMethod(name, mods, args, getCLSType(retType), method, statik);
- }
- private Symbol createMethod(Name name, int mods, Type[] args,
- scalac.symtab.Type retType,
- MethodInfo method,
- boolean statik)
- {
- scalac.symtab.Type mtype = methodType(args, retType);
- assert mtype != null : name;
- return createMethod(name, mods, mtype, method, statik);
- }
- private Symbol createMethod(Name name, int mods, scalac.symtab.Type mtype,
- MethodInfo method, boolean statik)
- {
- Symbol methodSym = (statik ? staticsClass: clazz)
- .newMethod(Position.NOPOS, mods, name);
- setParamOwners(mtype, methodSym);
- parseMeta(methodSym, method, mtype); // sets the type to mtype if no meta
- (statik ? statics : members).enterOrOverload(methodSym);
- if (method != null)
- clrTypes.map(methodSym, method);
- return methodSym;
- }
-
- private Name getName(MethodInfo method) {
- final String name = method.Name;
- if (method.IsStatic()) return Name.fromString(name);
- final ParameterInfo[] params = method.GetParameters();
- if (name.equals("GetHashCode") && params.length == 0)
- return Names.hashCode;
- if (name.equals("ToString") && params.length == 0)
- return Names.toString;
- if (name.equals("Finalize") && params.length == 0)
- return Names.finalize;
- if (name.equals("Equals") && params.length == 1
- && params[0].ParameterType == clrTypes.OBJECT)
- return Names.equals;
- // TODO: check if the type implements ICloneable?
- if (name.equals("Clone") && params.length == 0)
- return Names.clone;
- // Pretend that delegates have a 'apply' method instead of the 'Invoke'
- // method. This is harmless because the latter one can't be called
- // directly anyway.
- if (name.equals("Invoke")
- && clrTypes.isDelegateType(method.DeclaringType))
- return Names.apply;
- return Name.fromString(name);
- }
-
- //##########################################################################
-
- private Type[] getParamTypes(MethodBase method) {
- ParameterInfo[] params = method.GetParameters();
- Type[] paramTypes = new Type[params.length];
- for (int i = 0; i < params.length; i++)
- paramTypes[i] = params[i].ParameterType;
- return paramTypes;
- }
-
- private scalac.symtab.Type methodType(MethodBase method, Type rettype) {
- scalac.symtab.Type rtype = getCLSType(rettype);
- return rtype == null ? null : methodType(method, rtype);
- }
-
- /** Return a method type for the given method. */
- private scalac.symtab.Type methodType(MethodBase method,
- scalac.symtab.Type rettype)
- {
- return methodType(getParamTypes(method), rettype);
- }
-
- /** Return a method type for the provided argument types and return type. */
- private scalac.symtab.Type methodType(Type[] argtypes,
- scalac.symtab.Type rettype)
- {
- scalac.symtab.Type[] ptypes = new scalac.symtab.Type[argtypes.length];
- for (int i = 0; i < argtypes.length; i++) {
- ptypes[i] = getCLSType(argtypes[i]);
- if (ptypes[i] == null)
- return null;
- }
- return make.methodType(ptypes, rettype, scalac.symtab.Type.EMPTY_ARRAY);
- }
-
- private void setParamOwners(scalac.symtab.Type type, Symbol owner) {
- switch (type) {
- case PolyType(Symbol[] params, scalac.symtab.Type restype):
- for (int i = 0; i < params.length; i++) params[i].setOwner(owner);
- setParamOwners(restype, owner);
- return;
- case MethodType(Symbol[] params, scalac.symtab.Type restype):
- for (int i = 0; i < params.length; i++) params[i].setOwner(owner);
- setParamOwners(restype, owner);
- return;
- }
- }
-
- //##########################################################################
-
- private scalac.symtab.Type getClassType(Type type) {
- assert type != null;
- scalac.symtab.Type res =
- make.classType(type.FullName.replace('+', '.'));
- if (res.isError())
- global.error("unknown class reference " + type.FullName);
- return res;
- }
-
- private scalac.symtab.Type getCLSType(Type type) {
- if (/*type == clrTypes.BYTE ||*/ type == clrTypes.USHORT
- || type == clrTypes.UINT || type == clrTypes.ULONG
- || type.IsNotPublic() || type.IsNestedPrivate()
- || type.IsNestedAssembly() || type.IsNestedFamANDAssem()
- || type.IsPointer()
- || (type.IsArray() && getCLSType(type.GetElementType()) == null))
- return null;
- //Symbol s = clrTypes.getSymbol(type);
- //scalac.symtab.Type t = s != null ? make.classType(s) : getCLRType(type);
- return getCLRType(type);
- }
-
- private scalac.symtab.Type getCLRType(Type type) {
- if (type == clrTypes.OBJECT)
- return make.objectType();
- if (type == clrTypes.STRING)
- return make.stringType();
- if (type == clrTypes.VOID)
- return make.voidType();
- if (type == clrTypes.BOOLEAN)
- return make.booleanType();
- if (type == clrTypes.CHAR)
- return make.charType();
- if (type == clrTypes.BYTE || type == clrTypes.UBYTE)
- return make.byteType();
- if (type == clrTypes.SHORT || type == clrTypes.USHORT)
- return make.shortType();
- if (type == clrTypes.INT || type == clrTypes.UINT)
- return make.intType();
- if (type == clrTypes.LONG || type == clrTypes.ULONG)
- return make.longType();
- if (type == clrTypes.FLOAT)
- return make.floatType();
- if (type == clrTypes.DOUBLE)
- return make.doubleType();
- if (type.IsArray())
- return make.arrayType(getCLRType(type.GetElementType()));
- Symbol s = clrTypes.getSymbol(type);
- return s != null ? make.classType(s) : getClassType(type);
- }
-
- public AConstant getConstant(Symbol base, Object value) {
- if (base == global.definitions.BOOLEAN_CLASS)
- return AConstant.BOOLEAN(((Number)value).intValue() != 0);
- if (base == global.definitions.BYTE_CLASS)
- return AConstant.BYTE(((Number)value).byteValue());
- if (base == global.definitions.SHORT_CLASS)
- return AConstant.SHORT(((Number)value).shortValue());
- if (base == global.definitions.CHAR_CLASS)
- return AConstant.CHAR(((Character)value).charValue());
- if (base == global.definitions.INT_CLASS)
- return AConstant.INT(((Number)value).intValue());
- if (base == global.definitions.LONG_CLASS)
- return AConstant.LONG(((Number)value).longValue());
- if (base == global.definitions.FLOAT_CLASS)
- return AConstant.FLOAT(((Number)value).floatValue());
- if (base == global.definitions.DOUBLE_CLASS)
- return AConstant.DOUBLE(((Number)value).doubleValue());
- if (base == global.definitions.STRING_CLASS)
- return AConstant.STRING((String)value);
- throw Debug.abort("illegal value", Debug.show(value, base));
- }
-
- private static int translateAttributes(Type type) {
- int mods = Modifiers.JAVA;
- if (type.IsNotPublic() || type.IsNestedPrivate()
- || type.IsNestedAssembly() || type.IsNestedFamANDAssem())
- mods |= Modifiers.PRIVATE;
- else if (type.IsNestedFamily() || type.IsNestedFamORAssem())
- mods |= Modifiers.PROTECTED;
- if (type.IsAbstract())
- mods |= Modifiers.ABSTRACT;
- if (type.IsSealed())
- mods |= Modifiers.FINAL;
- if (type.IsInterface())
- mods |= Modifiers.INTERFACE | Modifiers.TRAIT | Modifiers.ABSTRACT;
-
- return mods;
- }
-
- private static int translateAttributes(FieldInfo field) {
- int mods = Modifiers.JAVA;
- if (field.IsPrivate() || field.IsAssembly() || field.IsFamilyAndAssembly())
- mods |= Modifiers.PRIVATE;
- else if (field.IsFamily() || field.IsFamilyOrAssembly())
- mods |= Modifiers.PROTECTED;
- if (field.IsInitOnly())
- mods |= Modifiers.FINAL;
- else
- mods |= Modifiers.MUTABLE;
-
- return mods;
- }
-
- private static int translateAttributes(MethodBase method) {
- int mods = Modifiers.JAVA;
- if (method.IsPrivate() || method.IsAssembly() || method.IsFamilyAndAssembly())
- mods |= Modifiers.PRIVATE;
- else if (method.IsFamily() || method.IsFamilyOrAssembly())
- mods |= Modifiers.PROTECTED;
- if (method.IsAbstract())
- mods |= Modifiers.DEFERRED;
-
- return mods;
- }
-}
diff --git a/sources/scalac/symtab/classfile/CLRPackageParser.java b/sources/scalac/symtab/classfile/CLRPackageParser.java
deleted file mode 100644
index c7e5296e17..0000000000
--- a/sources/scalac/symtab/classfile/CLRPackageParser.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.symtab.classfile;
-
-import java.util.Iterator;
-import java.util.HashMap;
-import java.util.HashSet;
-
-import scala.tools.util.AbstractFile;
-import scala.tools.util.ByteArrayFile;
-import scala.tools.util.VirtualDirectory;
-
-import scalac.Global;
-import scalac.util.Debug;
-import scalac.util.Name;
-import scalac.symtab.Scope;
-import scalac.symtab.Symbol;
-import scalac.symtab.SymbolLoader;
-import scalac.symtab.SymbolOrigin;
-
-import ch.epfl.lamp.compiler.msil.Type;
-import ch.epfl.lamp.compiler.msil.Attribute;
-
-/**
- * Package/namespace member loader for the CLR.
- */
-public final class CLRPackageParser extends PackageParser {
-
- //########################################################################
- // Private Constants
-
- /** An empty directory */
- private static final AbstractFile EMPTY = new VirtualDirectory("<empty>");
-
- //########################################################################
- // Protected Fields
-
- /** A table to collect types */
- protected final HashMap types = new HashMap();
-
- //########################################################################
- // Public Constructors
-
- public CLRPackageParser(Global global, AbstractFile directory) {
- super(global, directory);
- }
-
- //########################################################################
- // Protected Methods
-
- protected PackageParser newPackageParser(AbstractFile directory) {
- return new CLRPackageParser(global, directory);
- }
-
- protected void collectAllMembers(Symbol clasz) {
- super.collectAllMembers(clasz);
- HashSet namespaces = new HashSet();
- CLRTypes.instance().collectMembers(clasz, types, namespaces);
- for (Iterator i = namespaces.iterator(); i.hasNext(); ) {
- String namespace = (String)i.next();
- if (!packages.containsKey(namespace))
- packages.put(namespace, EMPTY);
- }
- }
-
- protected void removeHiddenMembers(Symbol clasz) {
- // Ignore all ".symbl" and ".class" files.
- symbols.clear();
- classes.clear();
- super.removeHiddenMembers(clasz);
- // Classes/Objects in the root package are hidden.
- if (clasz.isRoot()) { types.clear(); }
- // Source versions hide compiled versions except if separate
- // compilation is enabled and the compiled version is more
- // recent. In that case the compiled version hides the source
- // version.
- boolean separate = global.separate;
- for (Iterator i = sources.entrySet().iterator(); i.hasNext(); ) {
- if (types.isEmpty()) break;
- HashMap.Entry entry = (HashMap.Entry)i.next();
- String name = (String)entry.getKey();
- AbstractFile sfile = (AbstractFile)entry.getValue();
- Type type = (Type)types.get(name);
- boolean hidden = false;
- if (type != null)
- if (separate /* !!! && type.Assembly().getFile().lastModified() > sfile.lastModified() */)
- hidden = true;
- else
- types.remove(name);
- if (hidden) i.remove();
- }
- // Packages are hidden by classes/objects with the same name.
- packages.keySet().removeAll(types.keySet());
- }
-
- protected Scope createMemberSymbols(Symbol clasz) {
- CLRTypes clrTypes = CLRTypes.instance();
- String namespace = clrTypes.getNameSpaceOf(clasz);
- Scope members = super.createMemberSymbols(clasz);
-
- // import the CLR types contained in the package (namespace)
- for (Iterator i = types.values().iterator(); i.hasNext(); ) {
- Type type = (Type)i.next();
-
- assert namespace.equals(type.Namespace)
- : Debug.show(clasz, namespace) + " << " + type.FullName;
- AbstractFile symfile = null;
- if (type.IsDefined(clrTypes.SCALA_SYMTAB_ATTR, false)) {
- Object[] attrs = type.GetCustomAttributes
- (clrTypes.SCALA_SYMTAB_ATTR, false);
- assert attrs.length == 1 : attrs.length;
- Attribute a = (Attribute)attrs[0];
- assert a.GetType() == clrTypes.SCALA_SYMTAB_ATTR : a.toString();
- if (a.getConstructor() == clrTypes.SYMTAB_DEFAULT_CONSTR)
- continue;
- byte[] symtab = (byte[])a.getConstructorArguments()[0];
- symfile = new ByteArrayFile
- (type.FullName, "[" + type.Assembly().GetName() + "]",
- symtab);
- }
- SymbolLoader loader = symfile != null
- ? new SymblParser(Global.instance, symfile)
- : new CLRClassParser(Global.instance, type);
-
- Name classname = Name.fromString(type.Name).toTypeName();
- SymbolOrigin origin = SymbolOrigin.CLRAssembly(type.Assembly());
- Symbol clazz = clasz.newLoadedClass
- (JAVA, classname, loader, members, origin);
- clrTypes.map(clazz, type);
- //Type moduleType = getType(type.FullName + "$");
- //map(clazz, moduleType != null ? moduleType : type);
- }
-
- return members;
- }
-
- protected String doComplete(Symbol root) {
- String base = super.doComplete(root);
- base = directory == EMPTY ? "" : base + " and ";
- String namespace = CLRTypes.instance().getNameSpaceOf(root);
- return base + "namespace '" + namespace + "'";
- }
-
- //########################################################################
-} // CLRPackageParser
diff --git a/sources/scalac/symtab/classfile/CLRTypes.java b/sources/scalac/symtab/classfile/CLRTypes.java
deleted file mode 100644
index f7a5af508c..0000000000
--- a/sources/scalac/symtab/classfile/CLRTypes.java
+++ /dev/null
@@ -1,330 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.symtab.classfile;
-
-import java.util.List;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.LinkedHashSet;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.Comparator;
-
-import java.io.File;
-
-import scalac.Global;
-import scalac.CompilerCommand;
-import scalac.util.Debug;
-import scalac.util.Name;
-import scalac.symtab.Symbol;
-import scalac.symtab.SymbolNameWriter;
-
-import ch.epfl.lamp.compiler.msil.*;
-
-/**
- * Collects all types from all reference assemblies.
- */
-public final class CLRTypes {
-
- //##########################################################################
-
- private static CLRTypes instance;
-
- /** Return the unique instance of the CLRTypes class */
- public static CLRTypes instance() {
- assert instance != null;
- return instance;
- }
-
- /** Initialize the CLRTypes */
- public static void init(CompilerCommand args) {
- instance = new CLRTypes(args);
- }
-
- //##########################################################################
-
- public final Type BYTE;
- public final Type UBYTE;
- public final Type CHAR;
- public final Type SHORT;
- public final Type USHORT;
- public final Type INT;
- public final Type UINT;
- public final Type LONG;
- public final Type ULONG;
- public final Type FLOAT;
- public final Type DOUBLE;
- public final Type BOOLEAN;
- public final Type VOID;
- public final Type ENUM;
- public final Type DELEGATE;
-
- public final Type OBJECT;
- public final Type STRING;
- public final Type STRING_ARRAY;
-
- public final MethodInfo MEMBERWISE_CLONE;
-
- public final Type PICO_META_ATTR;
-
- public final Type SCALA_SYMTAB_ATTR;
- public final ConstructorInfo SYMTAB_CONSTR;
- public final ConstructorInfo SYMTAB_DEFAULT_CONSTR;
-
- public final MethodInfo DELEGATE_COMBINE;
- public final MethodInfo DELEGATE_REMOVE;
-
- private final SymbolNameWriter snw = new SymbolNameWriter();
-
- private Type[] types;
-
- private final CompilerCommand args;
-
- private CLRTypes(CompilerCommand args) {
- this.args = args;
- scala.tools.util.ClassPath.addFilesInPath(
- assemrefs, args.assemrefs.value);
- Assembly mscorlib = findAssembly("mscorlib.dll", true);
- Type.initMSCORLIB(mscorlib);
- findAllAssemblies();
-
- if (getType("scala.Int") == null) {
- findAssembly("scala.dll", true);
- }
-
- BYTE = getType("System.SByte");
- UBYTE = getType("System.Byte");
- CHAR = getType("System.Char");
- SHORT = getType("System.Int16");
- USHORT = getType("System.UInt16");
- INT = getType("System.Int32");
- UINT = getType("System.UInt32");
- LONG = getType("System.Int64");
- ULONG = getType("System.UInt64");
- FLOAT = getType("System.Single");
- DOUBLE = getType("System.Double");
- BOOLEAN = getType("System.Boolean");
- VOID = getType("System.Void");
- ENUM = getType("System.Enum");
- DELEGATE = getType("System.MulticastDelegate");
-
- OBJECT = getType("System.Object");
- STRING = getType("System.String");
- STRING_ARRAY = getType("System.String[]");
-
- MEMBERWISE_CLONE = OBJECT.GetMethod("MemberwiseClone", Type.EmptyTypes);
-
- PICO_META_ATTR = Type.GetType("scala.runtime.MetaAttribute");
- SCALA_SYMTAB_ATTR = Type.GetType("scala.runtime.SymtabAttribute");
- final Type[] bytearray = new Type[]{ Type.GetType("System.Byte[]") };
- SYMTAB_CONSTR = SCALA_SYMTAB_ATTR.GetConstructor(bytearray);
- SYMTAB_DEFAULT_CONSTR =
- SCALA_SYMTAB_ATTR.GetConstructor(Type.EmptyTypes);
-
- Type delegate = Type.GetType("System.Delegate");
- Type[] dargs = new Type[]{delegate, delegate};
- DELEGATE_COMBINE = delegate.GetMethod("Combine", dargs);
- DELEGATE_REMOVE = delegate.GetMethod("Remove", dargs);
-
- assert PICO_META_ATTR != null;
- assert SCALA_SYMTAB_ATTR != null;
- assert DELEGATE_COMBINE != null;
- assert DELEGATE_REMOVE != null;
-
- Type[] types = Type.EmptyTypes;
- Iterator as = assemblies.iterator();
- while (as.hasNext()) {
- Type[] atypes = ((Assembly)as.next()).GetTypes();
- int j = 0;
- for (int i = 0; i < atypes.length; i++)
- // skip nested types
- if (atypes[i].DeclaringType == null)
- atypes[j++] = atypes[i];
- Type[] btypes = new Type[types.length + j];
- System.arraycopy(types, 0, btypes, 0, types.length);
- System.arraycopy(atypes, 0, btypes, types.length, j);
- types = btypes;
- }
-
- Comparator typeNameComparator =
- new Comparator() {
- public int compare(Object o1, Object o2) {
- Type t1 = (Type)o1;
- Type t2 = (Type)o2;
- return t1.FullName.compareTo(t2.FullName);
- }
- };
-
- Arrays.sort(types, typeNameComparator);
- this.types = types;
- }
-
- //##########################################################################
- // type mapping and lookup
-
- private final Map syms2members = new HashMap();
- private final Map members2syms = new HashMap();
-
- public void map(Symbol sym, MemberInfo m) {
- syms2members.put(sym, m);
- members2syms.put(m, sym);
- }
-
- public MemberInfo getMember(Symbol sym) {
- return (MemberInfo)syms2members.get(sym);
- }
-
- public Symbol getSymbol(MemberInfo m) {
- return (Symbol)members2syms.get(m);
- }
-
- public Type getType(String name) {
- Type t = Type.GetType(name);
- //assert t != null : name;
- return t;
- }
-
- public Type mkArrayType(Type elemType) {
- return getType(elemType.FullName + "[]");
- }
-
- // Returns true if the given type is a delegate type.
- public boolean isDelegateType(Type t) {
- return t.BaseType() == DELEGATE;
- }
-
- //##########################################################################
- // assembly loading methods
-
- // a list of all loaded assemblies
- private final List assemblies = new LinkedList();
-
- // a set of all directories and assembly files
- private final Set/*<File>*/ assemrefs = new LinkedHashSet();
-
- /** Load the assembly with the given name
- */
- private Assembly findAssembly(String name, boolean required) {
- // see if the assembly is referenced directly
- for (Iterator assems = assemrefs.iterator(); assems.hasNext();) {
- File file = (File)assems.next();
- if (!file.getName().equals(name))
- continue;
- Assembly assem = Assembly.LoadFrom(file.getPath());
- if (assem != null) {
- assems.remove();
- assemblies.add(assem);
- return assem;
- }
- }
- // look in directories specified with the '-r' option
- for (Iterator assems = assemrefs.iterator(); assems.hasNext();) {
- File d = (File)assems.next();
- if (!d.isDirectory())
- continue;
- File file = new File(d, name);
- if (file.exists()) {
- Assembly assem = Assembly.LoadFrom(file.getPath());
- if (assem != null) {
- assemblies.add(assem);
- return assem;
- }
- }
- }
- // try in the current directory
- File file = new File(".", name);
- if (file.exists()) {
- Assembly assem = Assembly.LoadFrom(file.getPath());
- if (assem != null) {
- assemblies.add(assem);
- return assem;
- }
- }
-
- if (required)
- abort(name);
-
- return null;
- }
-
- /** Load the rest of the assemblies specified with the '-r' option
- */
- private void findAllAssemblies() {
- for (Iterator assems = assemrefs.iterator(); assems.hasNext();) {
- File f = (File)assems.next();
- if (f.isFile()) {
- Assembly assem = Assembly.LoadFrom(f.getPath());
- if (assem != null) {
- assemblies.add(assem);
- assems.remove();
- }
- }
- }
- }
-
- private void abort(String name) {
- //the Global instance is not yet constructed; use the Reporter from args
- args.reporter().error(null, "cannot find assembly " + name +
- "; use the -r option to specify its location");
- throw Debug.abort();
- }
-
- //##########################################################################
- // collect the members contained in a given namespace
-
- /** Find the position of the first type whose name starts with
- * the given prefix; return the length of the types array if no match
- * is found so the result can be used to terminate loop conditions
- */
- private int findFirst(String prefix) {
- int m = 0, n = types.length - 1;
- while (m < n) {
- int l = (m + n) / 2;
- int res = types[l].FullName.compareTo(prefix);
- if (res < 0) m = l + 1;
- else n = l;
- }
- return types[m].FullName.startsWith(prefix) ? m : types.length;
- }
-
- /** Collects the members contained in the given Scala package (namespace)
- */
- void collectMembers(Symbol pakage, Map/*<String,Type>*/ typesMap,
- Set/*<String>*/ namespacesSet)
- {
- String namespace = pakage.isRoot() ? "" : snw.toString(pakage) + ".";
- int nl = namespace.length();
- for (int i = findFirst(namespace);
- i < types.length && types[i].FullName.startsWith(namespace);
- i++)
- {
- Type type = types[i];
- if (type.FullName.equals("java.lang.Object")
- || type.FullName.equals("java.lang.String")) {
- continue;
- }
- int k = type.FullName.indexOf(".", nl);
- if (k < 0) {
- typesMap.put(type.Name, type);
- } else {
- namespacesSet.add(type.Namespace.substring(nl, k));
- }
- }
- }
-
- /** Returns the namespace of the given package */
- String getNameSpaceOf(Symbol pakage) {
- assert pakage.hasPackageFlag() || pakage.isRoot(): Debug.show(pakage);
- return pakage.isRoot() ? "" : snw.toString(pakage);
- }
-
- //##########################################################################
-} // CLRTypes
diff --git a/sources/scalac/symtab/classfile/ClassParser.java b/sources/scalac/symtab/classfile/ClassParser.java
deleted file mode 100644
index 5284d9cfed..0000000000
--- a/sources/scalac/symtab/classfile/ClassParser.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.symtab.classfile;
-
-import java.io.IOException;
-
-import scala.tools.util.AbstractFile;
-
-import scalac.Global;
-import scalac.symtab.Symbol;
-import scalac.symtab.SymbolLoader;
-import scalac.util.Debug;
-
-/** This class implements a SymbolLoader that reads a class file. */
-public class ClassParser extends SymbolLoader {
-
- //########################################################################
- // Private Fields
-
- /** The class file to read */
- private final AbstractFile file;
-
- //########################################################################
- // Public Constructors
-
- /** Initializes this instance with the specified class file. */
- public ClassParser(Global global, AbstractFile file) {
- super(global);
- this.file = file;
- }
-
- //########################################################################
- // Protected Methods
-
- /** Completes the specified symbol by reading the class file. */
- protected String doComplete(Symbol root) throws IOException {
- assert root.isClassType(): Debug.show(root);
- ClassfileParser.parse(global, file, root);
- return "class file '" + file + "'";
- }
-
- //########################################################################
-}
diff --git a/sources/scalac/symtab/classfile/ClassfileConstants.java b/sources/scalac/symtab/classfile/ClassfileConstants.java
deleted file mode 100644
index 02c07eea4b..0000000000
--- a/sources/scalac/symtab/classfile/ClassfileConstants.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-** **
-** $Id$
-\* */
-
-package scalac.symtab.classfile;
-
-import scalac.util.Name;
-
-public interface ClassfileConstants {
-
- int JAVA_MAGIC = 0xCAFEBABE;
- int JAVA_MAJOR_VERSION = 45;
- int JAVA_MINOR_VERSION = 3;
-
- int JAVA_ACC_PUBLIC = 0x0001;
- int JAVA_ACC_PRIVATE = 0x0002;
- int JAVA_ACC_PROTECTED = 0x0004;
- int JAVA_ACC_STATIC = 0x0008;
- int JAVA_ACC_FINAL = 0x0010;
- int JAVA_ACC_SUPER = 0x0020;
- int JAVA_ACC_SYNCHRONIZED = 0x0020;
- int JAVA_ACC_VOLATILE = 0x0040;
- int JAVA_ACC_BRIDGE = 0x0040;
- int JAVA_ACC_TRANSIENT = 0x0080;
- int JAVA_ACC_NATIVE = 0x0100;
- int JAVA_ACC_INTERFACE = 0x0200;
- int JAVA_ACC_ABSTRACT = 0x0400;
- int JAVA_ACC_STRICT = 0x0800;
- int JAVA_ACC_SYNTHETIC = 0x1000;
-
- int CONSTANT_UTF8 = 1;
- int CONSTANT_UNICODE = 2;
- int CONSTANT_INTEGER = 3;
- int CONSTANT_FLOAT = 4;
- int CONSTANT_LONG = 5;
- int CONSTANT_DOUBLE = 6;
- int CONSTANT_CLASS = 7;
- int CONSTANT_STRING = 8;
- int CONSTANT_FIELDREF = 9;
- int CONSTANT_METHODREF = 10;
- int CONSTANT_INTFMETHODREF = 11;
- int CONSTANT_NAMEANDTYPE = 12;
-
- int BAD_ATTR = 0x00000;
- int SOURCEFILE_ATTR = 0x00001;
- int SYNTHETIC_ATTR = 0x00002;
- int DEPRECATED_ATTR = 0x00004;
- int CODE_ATTR = 0x00008;
- int EXCEPTIONS_ATTR = 0x00010;
- int CONSTANT_VALUE_ATTR = 0x00020;
- int LINE_NUM_TABLE_ATTR = 0x00040;
- int LOCAL_VAR_TABLE_ATTR = 0x00080;
- int INNERCLASSES_ATTR = 0x08000;
- int META_ATTR = 0x10000;
- int SCALA_ATTR = 0x20000;
- int JACO_ATTR = 0x40000;
- int BRIDGE_ATTR = 0x80000;
- int SIG_ATTR = 0x100000;
-
- Name SOURCEFILE_N = Name.fromString("SourceFile");
- Name SYNTHETIC_N = Name.fromString("Synthetic");
- Name BRIDGE_N = Name.fromString("Bridge");
- Name DEPRECATED_N = Name.fromString("Deprecated");
- Name CODE_N = Name.fromString("Code");
- Name EXCEPTIONS_N = Name.fromString("Exceptions");
- Name CONSTANT_VALUE_N = Name.fromString("ConstantValue");
- Name LINE_NUM_TABLE_N = Name.fromString("LineNumberTable");
- Name LOCAL_VAR_TABLE_N = Name.fromString("LocalVariableTable");
- Name INNERCLASSES_N = Name.fromString("InnerClasses");
- Name META_N = Name.fromString("JacoMeta");
- Name SCALA_N = Name.fromString("ScalaSignature");
- Name JACO_N = Name.fromString("JacoInterface");
- Name SIG_N = Name.fromString("Signature");
- Name CONSTR_N = Name.fromString("<init>");
-}
diff --git a/sources/scalac/symtab/classfile/ClassfileParser.java b/sources/scalac/symtab/classfile/ClassfileParser.java
deleted file mode 100644
index 235e350903..0000000000
--- a/sources/scalac/symtab/classfile/ClassfileParser.java
+++ /dev/null
@@ -1,323 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-** **
-** $Id$
-\* */
-
-package scalac.symtab.classfile;
-
-import scala.tools.util.AbstractFile;
-import scala.tools.util.AbstractFileReader;
-import scala.tools.util.Position;
-import scalac.*;
-import scalac.util.*;
-import scalac.symtab.*;
-import scalac.symtab.Scope.SymbolIterator;
-import java.io.*;
-import java.util.*;
-
-//todo: don't keep statics module in scope.
-
-public class ClassfileParser implements ClassfileConstants {
-
- static final int CLASS_ATTR = SOURCEFILE_ATTR
- | INNERCLASSES_ATTR
- | SYNTHETIC_ATTR
- | DEPRECATED_ATTR
- | META_ATTR
- | SCALA_ATTR
- | JACO_ATTR
- | SIG_ATTR;
- static final int METH_ATTR = CODE_ATTR
- | EXCEPTIONS_ATTR
- | SYNTHETIC_ATTR
- | DEPRECATED_ATTR
- | META_ATTR
- | SIG_ATTR
- | BRIDGE_ATTR;
- static final int FIELD_ATTR = CONSTANT_VALUE_ATTR
- | SYNTHETIC_ATTR
- | DEPRECATED_ATTR
- | META_ATTR
- | SIG_ATTR;
-
- protected final Global global;
- protected final AbstractFileReader in;
- protected final Symbol c;
- protected final Symbol m;
- protected final Type ctype;
- protected final JavaTypeFactory make;
- protected final ConstantPool pool;
- protected final AttributeParser attrib;
- protected final Scope locals;
- protected final Scope statics;
-
-
- private ClassfileParser(Global global, AbstractFileReader in, Symbol c, JavaTypeFactory make, ConstantPool pool) {
- this.global = global;
- this.in = in;
- this.c = c;
- this.m = c.linkedModule();
- this.ctype = make.classType(c);
- this.make = make;
- this.pool = pool;
- this.attrib = new AttributeParser(in, pool, this);
- this.locals = new Scope();
- this.statics = new Scope();
- }
-
-
- /** parse the classfile and throw IO exception if there is an
- * error in the classfile structure
- */
- public static void parse(Global global, AbstractFile file, Symbol c) throws IOException {
- AbstractFileReader in = new AbstractFileReader(file);
- try {
- int magic = in.nextInt();
- if (magic != JAVA_MAGIC)
- throw new IOException("class file '" + in.file + "' "
- + "has wrong magic number 0x" + Integer.toHexString(magic)
- + ", should be 0x" + Integer.toHexString(JAVA_MAGIC));
- int minorVersion = in.nextChar();
- int majorVersion = in.nextChar();
- if ((majorVersion < JAVA_MAJOR_VERSION) ||
- ((majorVersion == JAVA_MAJOR_VERSION) &&
- (minorVersion < JAVA_MINOR_VERSION)))
- throw new IOException("class file '" + in.file + "' "
- + "has unknown version "
- + majorVersion + "." + minorVersion
- + ", should be less than "
- + JAVA_MAJOR_VERSION + "." + JAVA_MINOR_VERSION);
- JavaTypeFactory make = new JavaTypeCreator(global.definitions);
- Signatures sigs = new Signatures(global, make, in);
- ConstantPool pool = new ConstantPool(in, sigs);
- int flags = in.nextChar();
- Symbol clasz = pool.getClass(in.nextChar());
- if (c != clasz)
- throw new IOException("class file '" + in.file + "' "
- + "contains wrong class " + clasz.staticType());
- new ClassfileParser(global, in, c, make, pool).parse(flags);
- } catch (RuntimeException e) {
- if (global.debug) e.printStackTrace();
- throw new IOException("class file '" + in.file + "' is broken");
- }
- }
-
- protected void parse(int flags) {
- {
- // todo: correct flag transition
- c.flags = transFlags(flags);
- if ((c.flags & Modifiers.DEFERRED) != 0)
- c.flags = c.flags & ~Modifiers.DEFERRED | Modifiers.ABSTRACT;
- Type supertpe = readClassType(in.nextChar());
- Type[] basetpes = new Type[in.nextChar() + 1];
- // set info of class
- Type classInfo = Type.compoundType(basetpes, locals, c);
- c.setInfo(classInfo);
- // set info of statics class
- Symbol staticsClass = m.moduleClass();
- assert staticsClass.isModuleClass(): Debug.show(staticsClass);
- Type staticsInfo = Type.compoundType(Type.EMPTY_ARRAY, statics, staticsClass);
- staticsClass.setInfo(staticsInfo);
- m.setInfo(make.classType(staticsClass));
- basetpes[0] = supertpe;
- for (int i = 1; i < basetpes.length; i++)
- basetpes[i] = readClassType(in.nextChar());
- int fieldCount = in.nextChar();
- for (int i = 0; i < fieldCount; i++)
- parseField();
- int methodCount = in.nextChar();
- for (int i = 0; i < methodCount; i++)
- parseMethod();
-
- Symbol constr = c.primaryConstructor();
- if (!constr.isInitialized()) {
- constr.setInfo(
- Type.MethodType(Symbol.EMPTY_ARRAY, ctype));
- if ((c.flags & Modifiers.INTERFACE) == 0)
- constr.flags |= Modifiers.PRIVATE;
- }
- attrib.readAttributes(c, classInfo, CLASS_ATTR);
- //System.out.println("dynamic class: " + c);
- //System.out.println("statics class: " + staticsClass);
- //System.out.println("module: " + m);
- //System.out.println("modules class: " + m.type().symbol());
-
- int savedFlags = c.flags;
- c.flags |= Modifiers.INITIALIZED;
- // hack to make memberType in addInheritedOverloaded work
- if (global.currentPhase.id <= global.PHASE.REFCHECK.id() &&
- !c.name.toString().endsWith("$class"))
- addInheritedOverloaded();
-
- //if (global.debug) {
- // Symbol[] elems = c.members().elements();
- // global.log(c + " defines: ");
- // for (int i = 0; i < elems.length; i++) {
- // global.log(elems[i] + ":" + elems[i].type());
- // }
- //}
-
- c.flags = savedFlags;
-
- // Add static members of superclass
- // todo: remove
- Symbol superclass = supertpe.symbol();
- if (m.isJava() && superclass.isJava()) {
- Symbol mclass = m.moduleClass();
- SymbolIterator i = superclass.linkedModule().moduleClass()
- .members().iterator();
- outer:
- while (i.hasNext()) {
- Symbol member = i.next();
- Symbol current = statics.lookup(member.name);
- if (!current.isNone()) {
- if (!member.isTerm()) continue outer;
- Type info = member.info();
- Symbol[] currents = current.alternativeSymbols();
- inner:
- for (int j = 0; j < currents.length; j++) {
- if (currents[j].owner() != mclass)
- continue inner;
- if (currents[j].info().isSubType(info))
- continue outer;
- }
- }
- statics.enterOrOverload(member);
- }
- }
- }
- }
-
- private void addInheritedOverloaded() {
- Symbol[] elems = c.members().elements();
- for (int i = 0; i < elems.length; i++) {
- addInheritedOverloaded(elems[i]);
- }
- }
-
- private void addInheritedOverloaded(Symbol sym) {
- if (sym.isMethod() && !sym.isConstructor()) {
- sym.addInheritedOverloaded(sym.type());
- }
- }
-
- /** convert Java modifiers into Scala flags
- */
- public int transFlags(int flags) {
- int res = 0;
- if ((flags & JAVA_ACC_PRIVATE) != 0)
- res |= Modifiers.PRIVATE;
- else if ((flags & JAVA_ACC_PROTECTED) != 0)
- res |= Modifiers.PROTECTED;
- else if ((flags & JAVA_ACC_PUBLIC) == 0)
- res |= Modifiers.PRIVATE;
- if ((flags & JAVA_ACC_ABSTRACT) != 0)
- res |= Modifiers.DEFERRED;
- if ((flags & JAVA_ACC_FINAL) != 0)
- res |= Modifiers.FINAL;
- if ((flags & JAVA_ACC_INTERFACE) != 0)
- res |= Modifiers.INTERFACE | Modifiers.TRAIT | Modifiers.ABSTRACT;
- if ((flags & JAVA_ACC_SYNTHETIC) != 0)
- res |= Modifiers.SYNTHETIC;
- return res | Modifiers.JAVA;
- }
-
- /** read a class name and return the corresponding class type
- */
- protected Type readClassType(int i) {
- return i == 0 ? make.anyType() : make.classType(pool.getClass(i));
- }
-
- /** read a field
- */
- protected void parseField() {
- int jflags = in.nextChar();
- int sflags = transFlags(jflags);
- if ((jflags & JAVA_ACC_FINAL) == 0) sflags |= Modifiers.MUTABLE;
- if ((sflags & Modifiers.PRIVATE) != 0) {
- in.skip(4);
- attrib.skipAttributes();
- } else {
- Name name = pool.getName(in.nextChar());
- Symbol owner = getOwner(jflags);
- Symbol symbol = owner.newTerm(Position.NOPOS, sflags, name);
- Type type = pool.getFieldType(in.nextChar());
- symbol.setInfo(type);
- attrib.readAttributes(symbol, type, FIELD_ATTR);
- getScope(jflags).enterOrOverload(symbol);
- }
- }
-
- /** read a method
- */
- protected void parseMethod() {
- int jflags = in.nextChar();
- int sflags = transFlags(jflags);
- if ((jflags & JAVA_ACC_BRIDGE) != 0) sflags |= Modifiers.PRIVATE;
- if ((sflags & Modifiers.PRIVATE) != 0) {
- in.skip(4);
- attrib.skipAttributes();
- } else {
- Name name = pool.getName(in.nextChar());
- Type type = pool.getMethodType(in.nextChar());
- Symbol owner = getOwner(jflags);
- Symbol symbol;
- boolean newConstructor = false;
- if (name == CONSTR_N) {
- switch (type) {
- case MethodType(Symbol[] vparams, _):
- type = Type.MethodType(vparams, ctype);
- break;
- default:
- throw Debug.abort("illegal case", type);
- }
- symbol = owner.primaryConstructor();
- if (symbol.isInitialized()) {
- symbol = owner.newConstructor(Position.NOPOS, sflags);
- newConstructor = true;
- } else {
- symbol.flags = sflags;
- }
- } else {
- symbol = owner.newTerm(Position.NOPOS, sflags, name);
- }
- setParamOwners(type, symbol);
- symbol.setInfo(type);
- attrib.readAttributes(symbol, type, METH_ATTR);
- if (name != CONSTR_N) {
- if ((symbol.flags & Modifiers.BRIDGE) == 0)
- getScope(jflags).enterOrOverload(symbol);
- } else if (newConstructor)
- owner.addConstructor(symbol);
- }
- }
-
- /** return the owner of a member with given java flags
- */
- private Symbol getOwner(int jflags) {
- return (jflags & JAVA_ACC_STATIC) != 0 ? m.moduleClass() : c;
- }
-
- /** return the scope of a member with given java flags
- */
- private Scope getScope(int jflags) {
- return (jflags & JAVA_ACC_STATIC) != 0 ? statics : locals;
- }
-
- private void setParamOwners(Type type, Symbol owner) {
- switch (type) {
- case PolyType(Symbol[] params, Type result):
- for (int i = 0; i < params.length; i++)
- params[i].setOwner(owner);
- setParamOwners(result, owner);
- break;
- case MethodType(Symbol[] params, Type result):
- for (int i = 0; i < params.length; i++) params[i].setOwner(owner);
- setParamOwners(result, owner);
- break;
- }
- }
-}
diff --git a/sources/scalac/symtab/classfile/ConstantPool.java b/sources/scalac/symtab/classfile/ConstantPool.java
deleted file mode 100644
index 0a042ae3f0..0000000000
--- a/sources/scalac/symtab/classfile/ConstantPool.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.symtab.classfile;
-
-import scalac.atree.AConstant;
-import scalac.symtab.Symbol;
-import scalac.symtab.Type;
-import scala.tools.util.AbstractFileReader;
-import scalac.util.Debug;
-import scalac.util.Name;
-import scalac.util.SourceRepresentation;
-
-/** This class implements the parsing of class file constant pools. */
-public class ConstantPool implements ClassfileConstants {
-
- //########################################################################
- // Private Fields
-
- /** The input file */
- private final AbstractFileReader in;
-
- /** The signature parser */
- private final Signatures parser;
-
- /** The start addresses of all constants */
- private final int[] starts;
-
- /** The values of the constants (or null if not yet read) */
- private final Object[] values;
-
- //########################################################################
- // Public Constructors
-
- /** Initializes this instance by reading constant pool in file. */
- public ConstantPool(AbstractFileReader in, Signatures parser) {
- this.in = in;
- this.parser = parser;
- this.starts = new int[in.nextChar()];
- this.values = new Object[starts.length];
- for (int index = 1; index < starts.length; ) {
- starts[index++] = in.bp;
- switch (in.nextByte()) {
- case CONSTANT_UTF8:
- case CONSTANT_UNICODE:
- in.skip(in.nextChar());
- continue;
- case CONSTANT_CLASS:
- case CONSTANT_STRING:
- in.skip(2);
- continue;
- case CONSTANT_FIELDREF:
- case CONSTANT_METHODREF:
- case CONSTANT_INTFMETHODREF:
- case CONSTANT_NAMEANDTYPE:
- case CONSTANT_INTEGER:
- case CONSTANT_FLOAT:
- in.skip(4);
- continue;
- case CONSTANT_LONG:
- case CONSTANT_DOUBLE:
- in.skip(8);
- index++;
- continue;
- default:
- throw errorBadTag(in.bp - 1);
- }
- }
- }
-
- //########################################################################
- // Public Methods
-
- /** Returns the string at given index. */
- public String getString(int index) {
- if (index <= 0 || starts.length <= index) throw errorBadIndex(index);
- if (values[index] instanceof String) return (String)values[index];
- if (values[index] instanceof Name) return values[index].toString();
- String value = readString(starts[index]);
- values[index] = value;
- return value;
- }
-
- /** Returns the name at given index. */
- public Name getName(int index) {
- if (index <= 0 || starts.length <= index) throw errorBadIndex(index);
- if (values[index] instanceof Name) return (Name)values[index];
- Name value = readName(starts[index]);
- values[index] = value;
- return value;
- }
-
- /** Returns the class at given index. */
- public Symbol getClass(int index) {
- if (index <= 0 || starts.length <= index) throw errorBadIndex(index);
- if (values[index] instanceof Symbol) return (Symbol)values[index];
- Symbol value = readClass(starts[index]);
- values[index] = value;
- return value;
- }
-
- /** Returns the field type at given index. */
- public Type getFieldType(int index) {
- if (index <= 0 || starts.length <= index) throw errorBadIndex(index);
- if (values[index] instanceof Type) return (Type)values[index];
- Type value = readFieldType(starts[index]);
- values[index] = value;
- return value;
- }
-
- /** Returns the method type at given index. */
- public Type getMethodType(int index) {
- if (index <= 0 || starts.length <= index) throw errorBadIndex(index);
- if (values[index] instanceof Type) return clone((Type)values[index]);
- Type value = readMethodType(starts[index]);
- values[index] = value;
- return value;
- }
-
- /** Returns the constant value at given index. */
- public AConstant getConstantValue(int index) {
- if (index <= 0 || starts.length <= index) throw errorBadIndex(index);
- if (values[index] != null) return (AConstant)values[index];
- AConstant value = readConstantValue(starts[index]);
- values[index] = value;
- return value;
- }
-
- //########################################################################
- // Private Fields
-
- /** Reads the string at given address. */
- private String readString(int address) {
- if (in.byteAt(address) != CONSTANT_UTF8) throw errorBadTag(address);
- return parser.at(address).getSignature();
- }
-
- /** Reads the name at given address. */
- private Name readName(int address) {
- return Name.fromString(readString(address));
- }
-
- /** Reads the class at given address. */
- private Symbol readClass(int address) {
- if (in.byteAt(address) != CONSTANT_CLASS) throw errorBadTag(address);
- int index = in.getChar(address + 1);
- if (index <= 0 || starts.length <= index) throw errorBadIndex(index);
- address = starts[index];
- if (in.byteAt(address) != CONSTANT_UTF8) throw errorBadTag(address);
- return parser.at(address).readClassName();
- }
-
- /** Reads the field type at given address. */
- private Type readFieldType(int address) {
- if (in.byteAt(address) != CONSTANT_UTF8) throw errorBadTag(address);
- return parser.at(address).readValueType();
- }
-
- /** Reads the method type at given address. */
- private Type readMethodType(int address) {
- if (in.byteAt(address) != CONSTANT_UTF8) throw errorBadTag(address);
- return parser.at(address).readMethodType();
- }
-
- /** Reads the constant value at given address. */
- private AConstant readConstantValue(int address) {
- switch (in.byteAt(address)) {
- case CONSTANT_STRING:
- return AConstant.STRING(getString(in.getChar(address + 1)));
- case CONSTANT_INTEGER:
- return AConstant.INT(in.getInt(address + 1));
- case CONSTANT_FLOAT:
- return AConstant.FLOAT(in.getFloat(address + 1));
- case CONSTANT_LONG:
- return AConstant.LONG(in.getLong(address + 1));
- case CONSTANT_DOUBLE:
- return AConstant.DOUBLE(in.getDouble(address + 1));
- default:
- throw errorBadTag(address);
- }
- }
-
- /** Returns the type with all its parameters symbols cloned. */
- private Type clone(Type type) {
- switch (type) {
- case MethodType(Symbol[] params, Type result):
- Symbol[] clones = new Symbol[params.length];
- for (int i = 0; i < clones.length; i++)
- clones[i] = params[i].cloneSymbol(Symbol.NONE);
- return Type.MethodType(clones, result);
- case ErrorType:
- return type;
- default:
- throw Debug.abort("illegal case", type);
- }
- }
-
- /** Throws an exception signaling a bad constant index. */
- private RuntimeException errorBadIndex(int index) {
- String error = "bad constant pool index: " + index;
- throw new RuntimeException(error);
- }
-
- /** Throws an exception signaling a bad tag at given address. */
- private RuntimeException errorBadTag(int address) {
- int tag = in.byteAt(address);
- String error = "bad constant pool tag " + tag + " at byte " + address;
- throw new RuntimeException(error);
- }
-
- //########################################################################
-}
diff --git a/sources/scalac/symtab/classfile/JavaTypeCreator.java b/sources/scalac/symtab/classfile/JavaTypeCreator.java
deleted file mode 100644
index d01f1923e2..0000000000
--- a/sources/scalac/symtab/classfile/JavaTypeCreator.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-** **
-** $Id$
-\* */
-
-package scalac.symtab.classfile;
-
-import scala.tools.util.Position;
-import scalac.atree.AConstant;
-import scalac.util.Debug;
-import scalac.util.Name;
-import scalac.symtab.*;
-import Type.*;
-
-
-public class JavaTypeCreator implements JavaTypeFactory {
-
- protected final Definitions definitions;
-
- protected final Type ANY_TYPE;
- protected final Type DOUBLE_TYPE;
- protected final Type FLOAT_TYPE;
- protected final Type LONG_TYPE;
- protected final Type INT_TYPE;
- protected final Type CHAR_TYPE;
- protected final Type SHORT_TYPE;
- protected final Type BYTE_TYPE;
- protected final Type BOOLEAN_TYPE;
- protected final Type UNIT_TYPE;
- protected final Type OBJECT_TYPE;
- protected final Type STRING_TYPE;
- protected final Type ARRAY_TYPE;
-
- public JavaTypeCreator(Definitions definitions) {
- this.definitions = definitions;
- this.ANY_TYPE = classType(definitions.ANY_CLASS);
- this.DOUBLE_TYPE = classType(definitions.DOUBLE_CLASS);
- this.FLOAT_TYPE = classType(definitions.FLOAT_CLASS);
- this.LONG_TYPE = classType(definitions.LONG_CLASS);
- this.INT_TYPE = classType(definitions.INT_CLASS);
- this.CHAR_TYPE = classType(definitions.CHAR_CLASS);
- this.SHORT_TYPE = classType(definitions.SHORT_CLASS);
- this.BYTE_TYPE = classType(definitions.BYTE_CLASS);
- this.BOOLEAN_TYPE = classType(definitions.BOOLEAN_CLASS);
- this.UNIT_TYPE = classType(definitions.UNIT_CLASS);
- this.OBJECT_TYPE = classType(definitions.OBJECT_CLASS);
- this.STRING_TYPE = classType(definitions.STRING_CLASS);
- this.ARRAY_TYPE = classType(definitions.ARRAY_CLASS);
- }
-
- public Type anyType() {
- return ANY_TYPE;
- }
-
- public Type byteType() {
- return BYTE_TYPE;
- }
-
- public Type shortType() {
- return SHORT_TYPE;
- }
-
- public Type charType() {
- return CHAR_TYPE;
- }
-
- public Type intType() {
- return INT_TYPE;
- }
-
- public Type longType() {
- return LONG_TYPE;
- }
-
- public Type floatType() {
- return FLOAT_TYPE;
- }
-
- public Type doubleType() {
- return DOUBLE_TYPE;
- }
-
- public Type booleanType() {
- return BOOLEAN_TYPE;
- }
-
- public Type voidType() {
- return UNIT_TYPE;
- }
-
- public Type objectType() {
- return OBJECT_TYPE;
- }
-
- public Type stringType() {
- return STRING_TYPE;
- }
-
- public Type classType(String classname) {
- if (classname.equals("java.lang.Object"))
- return objectType();
- if (classname.equals("java.lang.String"))
- return stringType();
- return classType(definitions.getClass(classname));
- }
-
- public Type classType(Symbol clasz) {
- return clasz.staticType();
- }
-
- public Type arrayType(Type elemtpe) {
- return Type.appliedType(ARRAY_TYPE, new Type[]{elemtpe});
- }
-
- public Type methodType(Type[] argtpes, Type restpe, Type[] thrown) {
- Symbol[] args = new Symbol[argtpes.length];
- for (int i = 0; i < args.length; i++) {
- args[i] = Symbol.NONE.newTerm( // !!! should be newVParam
- Position.NOPOS, Modifiers.PARAM, Name.fromString("x" + i));
- args[i].setInfo(objToAny(argtpes[i]));
- }
- return new MethodType(args, restpe);
- }
- private Type objToAny(Type tp) {
- return tp.isSameAs(OBJECT_TYPE) ? ANY_TYPE : tp;
- }
-
- public Type packageType(Name packagename) {
- return null;
- }
-
- /** return the constant type for the given constant.
- */
- public Type constantType(AConstant value) {
- return Type.constantType(value);
- }
-
- /** return the type of a given constant.
- */
- public Type typeOfValue(Object value) {
- if (value instanceof Character)
- return charType();
- else if (value instanceof Integer)
- return intType();
- else if (value instanceof Long)
- return longType();
- else if (value instanceof Float)
- return floatType();
- else if (value instanceof Double)
- return doubleType();
- else if (value instanceof String)
- return stringType();
- else if (value instanceof Boolean)
- return booleanType();
- else
- throw Debug.abort("unknown constant type", value.getClass());
- }
-
-}
diff --git a/sources/scalac/symtab/classfile/JavaTypeFactory.java b/sources/scalac/symtab/classfile/JavaTypeFactory.java
deleted file mode 100644
index af89fce22b..0000000000
--- a/sources/scalac/symtab/classfile/JavaTypeFactory.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-** **
-** $Id$
-\* */
-
-package scalac.symtab.classfile;
-
-import scalac.atree.AConstant;
-import scalac.symtab.Symbol;
-import scalac.symtab.Type;
-import scalac.util.Name;
-
-public interface JavaTypeFactory {
- Type anyType();
- Type byteType();
- Type shortType();
- Type charType();
- Type intType();
- Type longType();
- Type floatType();
- Type doubleType();
- Type booleanType();
- Type voidType();
- Type objectType();
- Type stringType();
- Type classType(String classname);
- Type classType(Symbol clasz);
- Type arrayType(Type elemtpe);
- Type methodType(Type[] argtpes, Type restpe, Type[] thrown);
- Type packageType(Name packagename);
- Type constantType(AConstant value);
-}
diff --git a/sources/scalac/symtab/classfile/MetaParser.java b/sources/scalac/symtab/classfile/MetaParser.java
deleted file mode 100644
index afc5f525e1..0000000000
--- a/sources/scalac/symtab/classfile/MetaParser.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, 2003, 2004, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-** **
-** $Id$
-\* */
-
-package scalac.symtab.classfile;
-
-import scala.tools.util.Position;
-import scalac.util.Name;
-import scalac.symtab.Modifiers;
-import scalac.symtab.Symbol;
-import scalac.symtab.Scope;
-import scalac.symtab.Type;
-import scalac.ApplicationError;
-import scalac.util.Debug;
-
-import java.util.Vector;
-import java.util.StringTokenizer;
-import java.util.NoSuchElementException;
-
-/** a parser class for parsing meta type information in classfiles
- * generated by pico.
- */
-class MetaParser {
- private final Symbol owner;
- private final StringTokenizer scanner;
- private final Type defaultType;
- private String token;
- private final Scope tvars;
- private Scope locals;
- private final Symbol clazz;
- private final Type ctype;
- private final JavaTypeFactory make;
-
- MetaParser(String meta, Scope tvars, Symbol owner, Type defaultType,
- Symbol clazz, Type ctype, JavaTypeFactory make) {
- this.scanner = new StringTokenizer(meta, "()[], \t<;", true);
- this.defaultType = defaultType;
- this.owner = owner;
- this.tvars = tvars;
- this.clazz = clazz;
- this.ctype = ctype;
- this.make = make;
- }
-
- private static Name getTypeName(String name) {
- return Name.fromString(name).toTypeName();
- }
-
- private Symbol getTVar(String name) {
- return getTVar(name, clazz.primaryConstructor());
- }
-
- private Symbol getTVar(String name, Symbol owner) {
- if (name.startsWith("?")) {
- Symbol s = (locals != null ? locals : tvars)
- .lookup(getTypeName(name));
- if (s != Symbol.NONE)
- return s;
- else if (locals != null) {
- s = tvars.lookup(getTypeName(name));
- if (s != Symbol.NONE)
- return s;
- }
- s = owner.newTParam
- (Position.NOPOS, 0, getTypeName(token), make.anyType());
- tvars.enter(s);
- return s;
- } else
- return Symbol.NONE;
- }
-
- private String nextToken() {
- do {
- token = scanner.nextToken().trim();
- } while (token.length() == 0);
- return token;
- }
-
- protected Type parse() {
- if (scanner.hasMoreTokens()) {
- nextToken();
- if (!scanner.hasMoreTokens())
- return defaultType;
- if ("class".equals(token))
- return parseMetaClass();
- if ("method".equals(token))
- return parseMetaMethod();
- if ("field".equals(token))
- return parseMetaField();
- if ("constr".equals(token))
- return parseConstrField();
- }
- return defaultType;
- }
-
- protected Type parseMetaClass() {
- nextToken();
- //System.out.println("parse meta class " + token);//DEBUG
- if ("[".equals(token)) {
- try {
- Vector syms = new Vector();
- do {
- nextToken();
- int vflag = 0;
- if (token.equals("+")) {
- nextToken();
- vflag = Modifiers.COVARIANT;
- } else if (token.equals("-")) {
- nextToken();
- vflag = Modifiers.CONTRAVARIANT;
- }
- assert token.startsWith("?");
- Symbol s = getTVar(token);
- if (s == Symbol.NONE)
- return defaultType;
- s.flags |= vflag;
- nextToken();
- //System.out.println("new var " + s + ", " + token);//DEBUG
- if (token.equals("<")) {
- nextToken();
- s.setInfo(parseType());
- }
- syms.add(s);
- } while (token.equals(","));
- assert "]".equals(token);
- nextToken();
- Symbol[] smbls = (Symbol[])syms.toArray(new Symbol[syms.size()]);
- //System.out.println("*** " + syms);//DEBUG
- Type clazztype = Type.appliedType(ctype, Symbol.type(smbls));
- Symbol constr = clazz.primaryConstructor();
- switch (constr.rawInfo()) {
- case MethodType(Symbol[] vparams, _):
- constr.setInfo(Type.PolyType
- (smbls, Type.MethodType(vparams, clazztype)));
- break;
- default:
- throw new ApplicationError(constr.rawInfo());
- }
- } catch (NoSuchElementException e) {
- }
- }
- Type res = defaultType;
- if ("extends".equals(token)) {
- Vector basetpes = new Vector();
- do {
- nextToken();
- basetpes.add(parseType());
- } while (token.equals("with"));
- switch (defaultType) {
- case CompoundType(_, Scope scope):
- Type[] ts = (Type[])basetpes.toArray(new Type[basetpes.size()]);
- res = Type.compoundType(ts, scope, defaultType.symbol());
- }
- }
- assert ";".equals(token);
- return res;
- }
-
- protected Type parseType() {
- String name = token;
- Symbol s = getTVar(name);
- nextToken();
- if (s != Symbol.NONE)
- return s.type();
- Type clazztype = make.classType(name).unalias();
- if (token.equals("[")) {
- Vector types = new Vector();
- do {
- nextToken();
- types.add(parseType());
- } while (token.equals(","));
- assert "]".equals(token);
- nextToken();
- Type[] args = new Type[types.size()];
- types.toArray(args);
- return Type.appliedType(clazztype, args);
- } else {
- return clazztype;
- }
- }
-
- protected Type parseMetaMethod() {
- locals = new Scope();
- try {
- nextToken();
- Symbol[] smbls = null;
- //System.out.println("parse meta method " + token);
- if ("[".equals(token)) {
- Vector syms = new Vector();
- do {
- nextToken();
- if ("]".equals(token))
- break;
- assert token.startsWith("?");
- Symbol s = owner.newTParam
- (Position.NOPOS, 0, getTypeName(token), make.anyType());
- locals.enter(s);
- nextToken();
- if (token.equals("<")) {
- nextToken();
- s.setInfo(parseType());
- }
- syms.add(s);
- } while (token.equals(","));
- assert "]".equals(token);
- nextToken();
- smbls = (Symbol[])syms.toArray(new Symbol[syms.size()]);
- }
- if ("(".equals(token)) {
- int i = 0;
- Vector params = new Vector();
- do {
- nextToken();
- if (")".equals(token))
- break;
- int flags = 0;
- if ("def".equals(token)) {
- nextToken();
- flags |= Modifiers.DEF;
- }
- Symbol vp = owner.newVParam
- (Position.NOPOS, flags, Name.fromString("x" + (i++)));
- params.add(vp.setInfo(parseType()));
- //System.out.println(" + " + token);
- } while (token.equals(","));
- assert ")".equals(token);
- nextToken();
- //System.out.println("+++ method " + token);
- Type restpe = parseType();
- assert ";".equals(token);
- Type mtype = Type.MethodType
- ((Symbol[])params.toArray(new Symbol[params.size()]),
- restpe);
- return smbls == null ? mtype : Type.PolyType(smbls, mtype);
- } else {
- Type res = parseType();
- assert ";".equals(token);
- return Type.PolyType
- (smbls == null ? Symbol.EMPTY_ARRAY : smbls, res);
- }
- } catch (NoSuchElementException e) {
- e.printStackTrace();
- return defaultType;
- } finally {
- locals = null;
- }
- }
-
- protected Type parseMetaField() {
- nextToken();
- return parseType();
- }
-
- protected Type parseConstrField() {
- try {
- nextToken();
- //System.out.println("+++ constr " + token);
- if ("(".equals(token)) {
- int i = 0;
- Vector params = new Vector();
- do {
- nextToken();
- if (")".equals(token))
- break;
- Symbol vp = owner.newVParam
- (Position.NOPOS, 0, Name.fromString("x" + (i++)));
- params.add(vp.setInfo(parseType()));
- //System.out.println(" + " + token);
- } while (token.equals(","));
- assert ")".equals(token);
- nextToken();
- assert ";".equals(token);
- return Type.MethodType((Symbol[])params.toArray(new Symbol[params.size()]),
- ctype);
- } else {
- assert ";".equals(token);
- return Type.PolyType(Symbol.EMPTY_ARRAY, ctype);
- }
- } catch (NoSuchElementException e) {
- return defaultType;
- }
- }
-}
diff --git a/sources/scalac/symtab/classfile/PackageParser.java b/sources/scalac/symtab/classfile/PackageParser.java
deleted file mode 100644
index fdbc796916..0000000000
--- a/sources/scalac/symtab/classfile/PackageParser.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.symtab.classfile;
-
-import java.util.Iterator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map.Entry;
-
-import scala.tools.util.AbstractFile;
-
-import scalac.Global;
-import scalac.symtab.Scope;
-import scalac.symtab.SourceCompleter;
-import scalac.symtab.Symbol;
-import scalac.symtab.SymbolLoader;
-import scalac.symtab.SymbolOrigin;
-import scalac.symtab.Type;
-import scalac.util.Name;
-import scalac.util.Debug;
-
-/**
- * This class implements a package member loader. It can be used to
- * complete package class symbols.
- */
-public class PackageParser extends SymbolLoader {
-
- //########################################################################
- // Protected Fields
-
- /** The directory to read */
- protected final AbstractFile directory;
-
- /** A table to collect .scala files */
- protected final HashMap/*<String,AbstractFile>*/ sources = new HashMap();
- /** A table to collect .symbl files */
- protected final HashMap/*<String,AbstractFile>*/ symbols = new HashMap();
- /** A table to collect .class files */
- protected final HashMap/*<String,AbstractFile>*/ classes = new HashMap();
- /** A table to collect subdirectories */
- protected final HashMap/*<String,AbstractFile>*/ packages = new HashMap();
-
- //########################################################################
- // Public Constructors
-
- /** Initializes this instance. */
- public PackageParser(Global global, AbstractFile directory) {
- super(global);
- this.directory = directory;
- assert directory != null;
- }
-
- //########################################################################
- // Protected Methods
-
- /** Is the given name a valid input file base name? */
- protected boolean isValidName(String name) {
- return name.length() > 0
- &&!name.endsWith("$class")
- && name.indexOf("$$anon") == -1;
- }
-
- /** Returns a new package parser for the given directory. */
- protected PackageParser newPackageParser(AbstractFile directory) {
- return new PackageParser(global, directory);
- }
-
- /**
- * Collects all members of the package. This method is invoked by
- * method "doComplete". It should not be invoked otherwise.
- */
- protected void collectAllMembers(Symbol clasz) {
- for (Iterator i = directory.list(); i.hasNext(); ) {
- AbstractFile file = (AbstractFile)i.next();
- String filename = file.getName();
- if (file.isDirectory()) {
- if (filename.equals("META-INF")) continue;
- packages.put(filename, file);
- continue;
- }
- if (filename.endsWith(".class")) {
- String name = filename.substring(0, filename.length() - 6);
- if (!isValidName(name)) continue;
- if (!classes.containsKey(name)) classes.put(name, file);
- continue;
- }
- if (filename.endsWith(".symbl")) {
- String name = filename.substring(0, filename.length() - 6);
- if (!isValidName(name)) continue;
- if (!symbols.containsKey(name)) symbols.put(name, file);
- continue;
- }
- if (filename.endsWith(".scala")) {
- String name = filename.substring(0, filename.length() - 6);
- if (!isValidName(name)) continue;
- if (!sources.containsKey(name)) sources.put(name, file);
- continue;
- }
- }
- }
-
- /**
- * Removes from the members collected by "collectAllMembers" all
- * those that are hidden. This method is invoked by method
- * "doComplete". It should not be invoked otherwise.
- */
- protected void removeHiddenMembers(Symbol clasz) {
- // Classes/Objects in the root package are hidden.
- if (clasz.isRoot()) sources.clear();
- if (clasz.isRoot()) symbols.clear();
- if (clasz.isRoot()) classes.clear();
- // For all files "<N>.class" find the longest M such that
- // there is a file "<M>.symbl" and M equals N or "<M>$" is a
- // prefix of N. If the file "<N>.class" is less recent than
- // the file "<M>.symbl" ignore the ".class" file. Otherwise,
- // if M equals N, ignore the ".symbl" file.
- for (Iterator i = classes.entrySet().iterator(); i.hasNext(); ) {
- if (symbols.isEmpty()) break;
- Entry entry = (Entry)i.next();
- String cname = (String)entry.getKey();
- AbstractFile cfile = (AbstractFile)entry.getValue();
- for (String zname = cname; true; ) {
- AbstractFile zfile = (AbstractFile)symbols.get(zname);
- if (zfile != null) {
- if (cfile.lastModified() <= zfile.lastModified()) {
- i.remove();
- } else if (zname == cname) {
- symbols.remove(zname);
- }
- break;
- }
- int index = zname.lastIndexOf('$');
- if (index < 0) break;
- zname = zname.substring(0, index);
- }
- }
- // Source versions hide compiled versions except if separate
- // compilation is enabled and the compiled version is more
- // recent. In that case the compiled version hides the source
- // version.
- boolean separate = global.separate;
- for (Iterator i = sources.entrySet().iterator(); i.hasNext(); ) {
- if (symbols.isEmpty() && classes.isEmpty()) break;
- HashMap.Entry entry = (HashMap.Entry)i.next();
- String name = (String)entry.getKey();
- AbstractFile sfile = (AbstractFile)entry.getValue();
- AbstractFile zfile = (AbstractFile)symbols.get(name);
- AbstractFile cfile = (AbstractFile)classes.get(name);
- boolean hidden = false;
- if (zfile != null)
- if (separate && zfile.lastModified() > sfile.lastModified())
- hidden = true;
- else
- symbols.remove(name);
- if (cfile != null)
- if (separate && cfile.lastModified() > sfile.lastModified())
- hidden = true;
- else
- classes.remove(name);
- if (hidden) i.remove();
- }
- // Packages are hidden by classes/objects with the same name.
- packages.keySet().removeAll(sources.keySet());
- packages.keySet().removeAll(symbols.keySet());
- packages.keySet().removeAll(classes.keySet());
- }
-
- /**
- * Creates symbols for all members left by method
- * "removeHiddenMembers". This method is invoked by method
- * "doComplete". It should not be invoked otherwise.
- */
- protected Scope createMemberSymbols(Symbol clasz) {
- Scope members = new Scope();
- for (Iterator i = sources.entrySet().iterator(); i.hasNext(); ) {
- HashMap.Entry entry = (HashMap.Entry)i.next();
- String name = (String)entry.getKey();
- AbstractFile sfile = (AbstractFile)entry.getValue();
- Name classname = Name.fromString(name).toTypeName();
- SymbolLoader loader = new SourceCompleter(global, sfile);
- SymbolOrigin origin = SymbolOrigin.ScalaFile(sfile);
- clasz.newLoadedClass(0, classname, loader, members, origin);
- }
- for (Iterator i = symbols.entrySet().iterator(); i.hasNext(); ) {
- HashMap.Entry entry = (HashMap.Entry)i.next();
- String name = (String)entry.getKey();
- AbstractFile zfile = (AbstractFile)entry.getValue();
- Name classname = Name.fromString(name).toTypeName();
- SymbolLoader loader = new SymblParser(global, zfile);
- SymbolOrigin origin = SymbolOrigin.SymblFile(zfile);
- clasz.newLoadedClass(0, classname, loader, members, origin);
- }
- for (Iterator i = classes.entrySet().iterator(); i.hasNext(); ) {
- HashMap.Entry entry = (HashMap.Entry)i.next();
- String name = (String)entry.getKey();
- AbstractFile cfile = (AbstractFile)entry.getValue();
- Name classname = Name.fromString(name).toTypeName();
- SymbolLoader loader = new ClassParser(global, cfile);
- SymbolOrigin origin = SymbolOrigin.ClassFile(cfile, null);
- clasz.newLoadedClass(JAVA, classname, loader, members, origin);
- }
- for (Iterator i = packages.entrySet().iterator(); i.hasNext(); ) {
- HashMap.Entry entry = (HashMap.Entry)i.next();
- String name = (String)entry.getKey();
- AbstractFile dfile = (AbstractFile)entry.getValue();
- Name packagename = Name.fromString(name);
- SymbolLoader loader = newPackageParser(dfile);
- SymbolOrigin origin = SymbolOrigin.Directory(dfile);
- clasz.newLoadedPackage(packagename, loader, members, origin);
- }
- return members;
- }
-
- /** Completes the package symbol by loading all its members. */
- protected String doComplete(Symbol root) {
- assert root.isRoot() || root.isPackage(): Debug.show(root);
- Symbol clasz = root.isRoot() ? root : root.moduleClass();
- collectAllMembers(clasz);
- removeHiddenMembers(clasz);
- Scope members = createMemberSymbols(clasz);
- clasz.setInfo(Type.compoundType(Type.EMPTY_ARRAY, members, clasz));
- return "directory path '" + directory + "'";
- }
-
- //########################################################################
-}
diff --git a/sources/scalac/symtab/classfile/Pickle.java b/sources/scalac/symtab/classfile/Pickle.java
deleted file mode 100644
index 22699b33a3..0000000000
--- a/sources/scalac/symtab/classfile/Pickle.java
+++ /dev/null
@@ -1,616 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.symtab.classfile;
-
-import scala.tools.util.Position;
-import java.util.HashMap;
-import java.io.*;
-import scalac.Global;
-import scalac.ApplicationError;
-import scalac.atree.AConstant;
-import scalac.util.*;
-import scalac.symtab.*;
-import Symbol.*;
-import Type.*;
-
-public class Pickle implements Kinds, Modifiers, EntryTags {
-
- final static boolean debug = false;
-
-/***************************************************
- * Symbol table attribute format: see EntryTags.java
- */
- public byte[] bytes;
- private int bp;
-
- private Name rootname;
- private Symbol rootowner;
- private HashMap index;
- private Object[] entries;
- private int ep;
-
- /** Write symbol table info for root.
- * root must be either a module or a class.
- */
- public Pickle() {
- index = new HashMap();
- entries = new Object[256];
- ep = 0;
- }
-
- /** Pickle all symbols descending from `root'.
- */
- public void add(Symbol root) {
- if (!root.isExternal()) {
- if (Global.instance.debug) System.out.println("pickling " + root);
- if (index.get(root) == null) {
- this.rootname = root.name.toTermName();
- this.rootowner = root.owner();
- putSymbol(root);
- }
- }
- }
-
- /** Finalize pickler with given fullname.
- */
- public void pickle() {
- bytes = new byte[4096];
- bp = 0;
- writeAttr();
- this.index = null;
- this.entries = null;
- }
-
- /** The number of elements defined in `bytes'.
- */
- public int size() {
- return bp;
- }
-
- public void writeTo(File file) throws IOException {
- OutputStream stream = new FileOutputStream(file);
- stream.write(bytes, 0, size());
- stream.close();
- }
-
-/* **************************************************
- * Phase 1: Build entry table
- ************************************************* */
-
- /** Is root in symbol.owner*?
- */
- private boolean isLocal(Symbol sym) {
- return
- sym.name.toTermName() == rootname && sym.owner() == rootowner
- ||
- sym.isConstructor() && isLocal(sym.constructorClass())
- ||
- (sym.kind != NONE && isLocal(sym.owner()));
- }
-
- /** Store entry `e' in index at next available position unless it it
- * already there. Return true iff entry is new.
- */
- private boolean putEntry(Object e) {
- Integer n = (Integer) index.get(e);
- if (n == null) {
- //System.out.println("entry " + e);//DEBUG
- if (ep == entries.length) {
- Object[] entries1 = new Object[ep * 2];
- System.arraycopy(entries, 0, entries1, 0, ep);
- entries = entries1;
- }
- entries[ep] = e;
- index.put(e, new Integer(ep));
- ep++;
- return true;
- } else {
- return false;
- }
- }
-
- /** Store symbol in index. If symbol is local, also store
- * everything it refers to.
- */
- private void putSymbol(Symbol sym) {
- if (putEntry(sym)) {
- if (debug) System.out.println("put " + sym);
- if (isLocal(sym)) {
- putEntry(sym.name);
- putSymbol(sym.isConstructor() ? sym.constructorClass() : sym.owner());
- switch (sym.kind) {
- case TYPE:
- if (sym.isViewBounded()) putType(sym.vuBound());
- else putType(sym.info());
- putType(sym.loBound());
- break;
- case ALIAS:
- putType(sym.info());
- putSymbol(sym.allConstructors());
- break;
- case CLASS:
- putType(sym.info());
- if (sym.isModuleClass()) putSymbol(sym.sourceModule());
- putType(sym.typeOfThis());
- putSymbol(sym.allConstructors());
- Symbol[] elems = sym.members().elements();
- for (int i = 0; i < elems.length; i++)
- putSymbol(elems[i]);
-
- break;
- case VAL:
- putType(sym.removeInheritedOverloaded(sym.info()));
- if (sym.isConstructor() &&
- sym == sym.constructorClass().allConstructors())
- putSymbol(sym.constructorClass());
- else if (sym.isModule())
- putSymbol(sym.moduleClass());
- break;
- default:
- throw new ApplicationError();
- }
- } else if (sym.kind != NONE) {
- putEntry(sym.isModuleClass() || sym.isRoot() ? sym.name.toTermName() : sym.name);
- if (!sym.owner().isRoot())
- putSymbol(sym.owner());
- }
- }
- }
-
- private void putSymbols(Symbol[] syms) {
- for (int i = 0; i < syms.length; i++)
- putSymbol(syms[i]);
- }
-
- /** Store type and everythig it refers to in index.
- */
- private void putType(Type tp) {
- if (putEntry(tp)) {
- switch (tp) {
- case NoType:
- break;
- case NoPrefix:
- putSymbol(Symbol.NONE);
- // !!! code above is usefull for compatibility
- // !!! nothing would be better line
- break;
- case ThisType(Symbol sym):
- putSymbol(sym);
- break;
- case SingleType(Type pre, Symbol sym):
- putType(pre);
- putSymbol(sym);
- break;
- case ConstantType(Type base, AConstant value):
- putType(base);
- putConstant(value);
- break;
- case TypeRef(Type pre, Symbol sym, Type[] args):
- putType(pre);
- putSymbol(sym);
- putTypes(args);
- break;
- case CompoundType(Type[] parents, Scope members):
- Symbol clazz = tp.symbol();
- if (clazz.isCompoundSym()) putSymbol(clazz.owner());
- putSymbol(clazz);
- putTypes(parents);
- break;
- case MethodType(Symbol[] vparams, Type result):
- putType(result);
- for (int i = 0; i < vparams.length; i++) {
- Type ptype = vparams[i].type();
- putType(ptype);
- int pflags = vparams[i].flags;
- if ((pflags & (REPEATED | DEF)) != 0)
- putEntry(new FlagsAndType(encodeFlags(pflags), ptype));
- }
- break;
- case PolyType(Symbol[] tparams, Type result):
- putType(result);
- putSymbols(tparams);
- break;
- case OverloadedType(Symbol[] alts, Type[] alttypes):
- for (int i = 0; i < alts.length; i++) alts[i].flags |= ALTERNATIVE;
- putSymbols(alts);
- putTypes(alttypes);
- break;
- default:
- throw new ApplicationError();
- }
- }
- }
-
- private void putTypes(Type[] tps) {
- for (int i = 0; i < tps.length; i++)
- putType(tps[i]);
- }
-
- private void putConstant(AConstant constant) {
- if (putEntry(constant)) {
- switch (constant) {
- case STRING(String value):
- putEntry(Name.fromString(value));
- return;
- }
- }
- }
-
-/* **************************************************
- * Phase 2: Write byte array
- ************************************************* */
-
- private void resizeTo(int size) {
- byte[] bytes1 = new byte[size];
- System.arraycopy(bytes, 0, bytes1, 0, bp);
- bytes = bytes1;
- }
-
- /** Write a byte of data
- */
- private void writeByte(int b) {
- if (bp == bytes.length) resizeTo(bytes.length * 2);
- bytes[bp++] = (byte)b;
- if (debug) System.out.print(b + " ");
- }
-
- /** Write a natural number in big endian format, base 128.
- * All but the last digits have bit 0x80 set.
- */
- private void writeNat(int x) {
- int y = x >>> 7;
- if (y != 0) writeNatPrefix(y);
- writeByte(x & 0x7f);
- }
-
- private void writeNatPrefix(int x) {
- int y = x >>> 7;
- if (y != 0) writeNatPrefix(y);
- writeByte((x & 0x7f) | 0x80);
- }
-
- /** Write a natural number at `pos'
- * If number is more than one byte, shift rest of array to make space.
- */
- private void patchNat(int pos, int x) {
- bytes[pos] = (byte) (x & 0x7f);
- int y = x >>> 7;
- if (y != 0) patchNatPrefix(pos, y);
- }
-
- private void patchNatPrefix(int pos, int x) {
- writeByte(0);
- System.arraycopy(bytes, pos, bytes, pos+1, bp - (pos+1));
- bytes[pos] = (byte) ((x & 0x7f) | 0x80);
- int y = x >>> 7;
- if (y != 0) patchNatPrefix(pos, y);
- }
-
- /** Write a long number in signed big endian format, base 256.
- */
- private void writeLong(long x) {
- long y = x >> 8;
- long z = x & 0xff;
- if (-y != z >> 7) writeLong(y);
- writeByte((int) z);
- }
-
- /** Write a reference to object, i.e., the object's number in the index.
- */
- private void writeRef(Object ref) {
- Integer i = (Integer) index.get(ref);
- assert i != null : ref + " " + ref.getClass();
- writeNat(i.intValue());
- }
-
- private void writeRefs(Object[] es) {
- for (int i = 0; i < es.length; i++) writeRef(es[i]);
- }
-
- /** Write a name entry. Names are stored in Utf8 format.
- */
- private void writeName(Name name) {
- writeByte(name.isTermName() ? TERMname : TYPEname);
- writeByte(0); // space for length
- byte[] ascii = name.toAsciiUnsafe();
- while (bp + ascii.length > bytes.length) resizeTo(bytes.length * 2);
- System.arraycopy(ascii, 0, bytes, bp, ascii.length);
- if (debug) System.out.print(name);
- bp = bp + ascii.length;
- }
-
- /** Write a symbol entry.
- */
- private void writeSymbol(Symbol sym) {
- if (debug) System.out.println("write " + sym);
- if (isLocal(sym)) {
- switch (sym.kind) {
- case TYPE:
- writeByte(TYPEsym);
- break;
- case ALIAS:
- writeByte(ALIASsym);
- break;
- case CLASS:
- writeByte(CLASSsym);
- break;
- case VAL:
- writeByte(VALsym);
- break;
- default:
- throw new ApplicationError();
- }
- writeByte(0); // space for length
- writeRef(sym.name);
- writeRef(sym.isConstructor() ? sym.constructorClass() : sym.owner());
- writeNat(sym.flags);
- switch (sym.kind) {
- case TYPE:
- if (sym.isViewBounded()) writeRef(sym.vuBound());
- else writeRef(sym.info());
- writeRef(sym.loBound());
- break;
- case ALIAS:
- writeRef(sym.info());
- writeRef(sym.allConstructors());
- break;
- case CLASS:
- writeRef(sym.info());
- if (sym.isModuleClass()) writeRef(sym.sourceModule());
- writeRef(sym.typeOfThis());
- writeRef(sym.allConstructors());
- break;
- case VAL:
- writeRef(sym.removeInheritedOverloaded(sym.info()));
- if (sym.isConstructor() &&
- sym == sym.constructorClass().allConstructors())
- writeRef(sym.constructorClass());
- else if (sym.isModule())
- writeRef(sym.moduleClass());
- break;
- default:
- throw new ApplicationError();
- }
- } else if (sym.kind == NONE) {
- writeByte(NONEsym);
- writeByte(0); // space for length
- } else {
- if (sym.isModuleClass() || sym.isRoot()) {
- writeByte(EXTMODCLASSref);
- writeByte(0); // space for length
- writeRef(sym.name.toTermName());
- } else {
- writeByte(EXTref);
- writeByte(0); // space for length
- assert !sym.isConstructor() : sym;
- writeRef(sym.name);
- }
- if (!sym.owner().isRoot())
- writeRef(sym.owner());
- }
- sym.flags &= ~ALTERNATIVE;
- }
-
- /** Write a type entry.
- */
- private void writeType(Type tp) {
- switch (tp) {
- case NoType:
- writeByte(NOtpe);
- writeByte(0); // space for length
- break;
- case NoPrefix:
- writeByte(THIStpe);
- writeByte(0); // space for length
- writeRef(Symbol.NONE);
- // !!! code above is usefull for compatibility
- // !!! following code would be better line:
- // !!! writeByte(NOpre);
- // !!! writeByte(0); // space for length
- break;
- case ThisType(Symbol sym):
- writeByte(THIStpe);
- writeByte(0); // space for length
- writeRef(sym);
- break;
-
- case SingleType(Type pre, Symbol sym):
- writeByte(SINGLEtpe);
- writeByte(0); // space for length
- writeRef(pre);
- writeRef(sym);
- break;
-
- case ConstantType(Type base, AConstant value):
- writeByte(CONSTANTtpe);
- writeByte(0); // space for length
- writeRef(base);
- writeRef(value);
- break;
-
- case TypeRef(Type pre, Symbol sym, Type[] args):
- writeByte(TYPEREFtpe);
- writeByte(0); // space for length
- writeRef(pre);
- writeRef(sym);
- writeRefs(args);
- break;
-
- case CompoundType(Type[] parents, Scope members):
- writeByte(COMPOUNDtpe);
- writeByte(0); // space for length
- Symbol clazz = tp.symbol();
- writeByte(clazz.isCompoundSym() ? 1 : 0);
- if (clazz.isCompoundSym()) writeRef(clazz.owner());
- writeRef(clazz);
- writeRefs(parents);
- break;
-
- case MethodType(Symbol[] vparams, Type result):
- writeByte(METHODtpe);
- writeByte(0); // space for length
- writeRef(result);
- for (int i = 0; i < vparams.length; i++) {
- Type ptype = vparams[i].type();
- int pflags = vparams[i].flags;
- if ((pflags & (REPEATED | DEF)) != 0)
- writeRef(new FlagsAndType(encodeFlags(pflags), ptype));
- else
- writeRef(ptype);
- }
- break;
-
- case PolyType(Symbol[] tparams, Type result):
- writeByte(POLYtpe);
- writeByte(0); // space for length
- writeRef(result);
- writeRefs(tparams);
- break;
-
- case OverloadedType(Symbol[] alts, Type[] alttypes):
- writeByte(OVERLOADEDtpe);
- writeByte(0); // space for length
- writeRefs(alts);
- writeRefs(alttypes);
- break;
-
- default:
- throw new ApplicationError();
- }
- }
-
- private void writeFlagsAndType(FlagsAndType ft) {
- writeByte(FLAGGEDtpe);
- writeByte(0); // space for length
- writeNat(ft.flags);
- writeRef(ft.type);
- }
-
- /** Write a constant entry.
- */
- private void writeConstant(AConstant constant) {
- switch (constant) {
- case UNIT:
- writeByte(LITERALunit);
- writeByte(0); // space for length
- return;
- case BOOLEAN(boolean value):
- writeByte(LITERALboolean);
- writeByte(0); // space for length
- writeByte(value ? 1 : 0);
- return;
- case BYTE(byte value):
- writeByte(LITERALbyte);
- writeByte(0); // space for length
- writeLong(value);
- return;
- case SHORT(short value):
- writeByte(LITERALshort);
- writeByte(0); // space for length
- writeLong(value);
- return;
- case CHAR(char value):
- writeByte(LITERALchar);
- writeByte(0); // space for length
- writeLong(value);
- return;
- case INT(int value):
- writeByte(LITERALint);
- writeByte(0); // space for length
- writeLong(value);
- return;
- case LONG(long value):
- writeByte(LITERALlong);
- writeByte(0); // space for length
- writeLong(value);
- return;
- case FLOAT(float value):
- writeByte(LITERALfloat);
- writeByte(0); // space for length
- writeLong(Float.floatToIntBits(value));
- return;
- case DOUBLE(double value):
- writeByte(LITERALdouble);
- writeByte(0); // space for length
- writeLong(Double.doubleToLongBits(value));
- return;
- case STRING(String value):
- writeByte(LITERALstring);
- writeByte(0); // space for length
- writeRef(Name.fromString(value));
- return;
- case NULL:
- writeByte(LITERALnull);
- writeByte(0); // space for length
- return;
- case ZERO:
- writeByte(LITERALzero);
- writeByte(0); // space for length
- return;
- default:
- throw Debug.abort("unknown case", constant);
- }
- }
-
- private void writeEntry(Object e) {
- int startpos = bp;
- if (e instanceof Symbol)
- writeSymbol((Symbol) e);
- else if (e instanceof Type)
- writeType((Type) e);
- else if (e instanceof Name)
- writeName((Name) e);
- else if (e instanceof FlagsAndType)
- writeFlagsAndType((FlagsAndType) e);
- else if (e instanceof AConstant)
- writeConstant((AConstant)e);
- else
- throw new ApplicationError(e);
- patchNat(startpos + 1, bp - (startpos + 2));
- }
-
- private void writeAttr() {
- writeNat(ep);
- for (int i = 0; i < ep; i++) {
- if (debug) System.out.print(i + "," + bp + ": ");
- writeEntry(entries[i]);
- if (debug) System.out.print("(" + entries[i] + ")");
- if (debug) System.out.println();
- }
- }
-
- private static int encodeFlags(int flags) {
- int n = 0;
- if ((flags & REPEATED) != 0) n |= REPEATEDflag;
- if ((flags & DEF) != 0) n |= DEFflag;
- return n;
- }
-
- static class FlagsAndType {
- int flags;
- Type type;
- FlagsAndType(int flags, Type type) {
- this.flags = flags;
- this.type = type;
- }
- public boolean equals(Object other) {
- if (other instanceof FlagsAndType) {
- FlagsAndType that = (FlagsAndType) other;
- return this.type.equals(that.type) &&
- this.flags == that.flags;
- } else {
- return false;
- }
- }
- public int hashCode() {
- return 37 + ((flags * 41) ^ type.hashCode());
- }
- }
-}
-
diff --git a/sources/scalac/symtab/classfile/Signatures.java b/sources/scalac/symtab/classfile/Signatures.java
deleted file mode 100644
index 102bce1a64..0000000000
--- a/sources/scalac/symtab/classfile/Signatures.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.symtab.classfile;
-
-import scala.tools.util.Position;
-import scala.tools.util.AbstractFileReader;
-import scalac.Global;
-import scalac.symtab.Symbol;
-import scalac.symtab.Type;
-import scalac.util.Name;
-import scalac.util.Names;
-import scalac.util.SourceRepresentation;
-import scalac.util.Debug;
-
-/** This class implements the parsing of class file signatures. */
-public class Signatures {
-
- //########################################################################
- // Private Fields
-
- /** The global environment */
- private final Global global;
-
- /** The Java type factory */
- private final JavaTypeFactory make;
-
- /** The input file */
- private final AbstractFileReader in;
-
- /** The address of the first byte of the current signature */
- private int first;
-
- /** The address of the last byte of the current signature */
- private int last;
-
- /** The current address (first <= current <= last) */
- private int current;
-
- //########################################################################
- // Public Constructors
-
- /** Initializes this instance. */
- public Signatures(Global global, JavaTypeFactory make,
- AbstractFileReader in)
- {
- this.global = global;
- this.make = make;
- this.in = in;
- }
-
- //########################################################################
- // Public Methods
-
- /**
- * Sets the address of the next signature to read. The address
- * must point to the first byte of a CONSTANT_Utf8_info.
- */
- public Signatures at(int address) {
- first = address + 3;
- last = first + in.getChar(address + 1) - 1;
- current = first;
- return this;
- }
-
- /** Returns the current signature. */
- public String getSignature() {
- return SourceRepresentation.ascii2string(in.buf, first, last-first+1);
- }
-
- /** Reads the class signature at current address. */
- public Symbol readClassName() {
- Symbol owner = global.definitions.ROOT_CLASS;
- int start = current;
- for (; current <= last; current++) {
- int b = in.byteAt(current);
- if (b == ';') break;
- if (b != '/') continue;
- Name name = Name.fromAscii(in.buf, start, current - start);
- Symbol module = owner.members().lookup(name);
- if (!module.isModule()) {
- Symbol symbol = owner.newModule(Position.NOPOS, 0, name);
- symbol.moduleClass().setInfo(Type.ErrorType);
- error("could not find module " + symbol.staticType());
- if (module.isNone()) owner.members().enterNoHide(symbol);
- module = symbol;
- }
- owner = module.moduleClass();
- start = current + 1;
- }
-
- Symbol clasz = null;
- Name name = Name.fromAscii(in.buf, start, current-start);
- if (owner == global.definitions.JAVALANG.moduleClass()) {
- if (name == Names.String)
- clasz = global.definitions.STRING_CLASS;
- else if (name == Names.Object)
- clasz = global.definitions.OBJECT_CLASS;
- }
- if (clasz == null) {
- name = name.toTypeName();
- clasz = owner.members().lookup(name);
- }
-
- if (!clasz.isClass()) {
- Symbol symbol = owner.newErrorClass(name);
- error("could not find class " + symbol.staticType());
- if (clasz.isNone()) owner.members().enterNoHide(symbol);
- clasz = symbol;
- }
- current++;
- return clasz;
- }
-
- /** Reads the value type signature at current address. */
- public Type readValueType() {
- switch (in.byteAt(current++)) {
- case 'V': return make.voidType();
- case 'Z': return make.booleanType();
- case 'B': return make.byteType();
- case 'S': return make.shortType();
- case 'C': return make.charType();
- case 'I': return make.intType();
- case 'J': return make.longType();
- case 'F': return make.floatType();
- case 'D': return make.doubleType();
- case 'L': return make.classType(readClassName());
- case '[': return make.arrayType(readValueType());
- default : return errorBadTypeTag(current - 1);
- }
- }
-
- /** Reads the method type signature at current address. */
- public Type readMethodType() {
- if (in.byteAt(current++) != '(') return errorBadTypeTag(current - 1);
- Type[] parameters = readParamterTypes(0);
- Type result = readValueType();
- return make.methodType(parameters, result, Type.EMPTY_ARRAY);
- }
-
- //########################################################################
- // Private Methods
-
- /** Reads the parameter types at current address. */
- private Type[] readParamterTypes(int i) {
- if (in.byteAt(current) == ')') {
- current++;
- return new Type[i];
- } else {
- Type type = readValueType();
- Type[] types = readParamterTypes(i + 1);
- types[i] = type;
- return types;
- }
- }
-
- /** Signals a bad tag at given address. Return ErrorType. */
- private Type errorBadTypeTag(int address) {
- char tag = (char)in.byteAt(address);
- error("bad tag '" + tag + "' in signature '" + getSignature() + "'");
- return Type.ErrorType;
- }
-
- /** Signals the given error. */
- private void error(String error) {
- global.error("class file '" + in.file + "': " + error);
- }
-
- //########################################################################
-}
diff --git a/sources/scalac/symtab/classfile/SymblParser.java b/sources/scalac/symtab/classfile/SymblParser.java
deleted file mode 100644
index 5c948d9176..0000000000
--- a/sources/scalac/symtab/classfile/SymblParser.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.symtab.classfile;
-
-import java.io.IOException;
-
-import scala.tools.util.AbstractFile;
-
-import scalac.Global;
-import scalac.symtab.Symbol;
-import scalac.symtab.SymbolLoader;
-
-/** This class implements a SymbolLoader that reads a symbol file. */
-public class SymblParser extends SymbolLoader {
-
- //########################################################################
- // Private Fields
-
- /** The symbol file to read */
- private final AbstractFile file;
-
- //########################################################################
- // Public Constructors
-
- /** Initializes this instance with the specified symbol file. */
- public SymblParser(Global global, AbstractFile file) {
- super(global);
- this.file = file;
- }
-
- //########################################################################
- // Protected Methods
-
- /** Completes the specified symbol by reading the symbol file. */
- public String doComplete(Symbol root) throws IOException {
- UnPickle.parse(global, file, root);
- return "symbol file '" + file + "'";
- }
-
- //########################################################################
-}
diff --git a/sources/scalac/symtab/classfile/UnPickle.java b/sources/scalac/symtab/classfile/UnPickle.java
deleted file mode 100644
index f3a715b480..0000000000
--- a/sources/scalac/symtab/classfile/UnPickle.java
+++ /dev/null
@@ -1,643 +0,0 @@
-/* ____ ____ ____ ____ ______ *\
-** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
-** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
-** /_____/\____/\___/\____/____/ **
-\* */
-
-// $Id$
-
-package scalac.symtab.classfile;
-
-import java.util.HashMap;
-import java.io.IOException;
-import java.io.PrintStream;
-import scala.tools.util.AbstractFile;
-import scala.tools.util.Position;
-import scalac.*;
-import scalac.atree.AConstant;
-import scalac.util.*;
-import scalac.symtab.*;
-import Symbol.*;
-import Type.*;
-
-public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags {
-
-/***************************************************
- * Symbol table attribute format: see EntryTags.java
- */
- static final boolean debug = true;
-
- public static void parse(Global global, AbstractFile file, Symbol root)
- throws IOException
- {
- try {
- parse(global, file.read(), root);
- } catch (BadSignature exception) {
- throw new IOException("symbol file '" + file.getPath() + "' "
- + "could not be loaded; " + exception.getMessage());
- }
- }
-
- /**
- * The root symbol must be either a module or a non-module
- * class. The unpickler initializes it. If it has a linked module
- * or class, it will also be initialized.
- */
- public static void parse(Global global, byte[] data, Symbol root)
- throws BadSignature
- {
- new UnPickle(global, data, root);
- }
-
- Symbol classroot;
- Symbol moduleroot;
- byte[] bytes;
- int bp;
- int[] index;
- Object[] entries;
- int paramFlags;
- final Global global;
-
- private UnPickle(Global global, byte[] data, Symbol root) {
- this.global = global;
- this.classroot = root.isModule() ? root.linkedClass() : root;
- this.moduleroot = root.isClassType() ? root.linkedModule() : root;
- assert classroot == null || classroot.isClassType(): Debug.show(root);
- assert moduleroot == null || moduleroot.isModule(): Debug.show(root);
- if (root != moduleroot && moduleroot != null) {
- moduleroot.moduleClass().setInfo(Type.NoType);
- }
- if (global.debug) global.log(
- "unpickle " + root + " " + classroot + " " + moduleroot
- + (moduleroot != null ? " " + moduleroot.moduleClass() : ""));
- this.bytes = data;
- this.bp = 0;
- index = new int[readNat()];
- for (int i = 0; i < index.length; i++) {
- index[i] = bp;
- bp++;
- bp = readNat() + bp;
- }
- entries = new Object[index.length];
-
- if (global.debug) print(System.out);
-
- for (int i = 0; i < index.length; i++) {
- if (isSymbolEntry(i)) getSymbol(i);
- }
- if (global.debug) global.log("unpickled " + root + ":" + root.rawInfo());//debug
- if (!classroot.isInitialized() && !moduleroot.isInitialized())
- throw new BadSignature(this, "it does not define " + root);
- // the isModule test is needed because moduleroot may become
- // the case class factory method of classroot
- if (moduleroot != null && moduleroot.isModule() && moduleroot.moduleClass().type() == Type.NoType) {
- moduleroot.setInfo(Type.NoType);
- }
- }
-
- int readByte() {
- return bytes[bp++];
- }
-
- int readNat() {
- int b;
- int x = 0;
- do {
- b = readByte();
- x = (x << 7) + (b & 0x7f);
- } while ((b & 0x80) != 0);
- return x;
- }
-
- long readLong(int n) {
- long x = 0;
- for (int i = 0; i < n; i++) {
- x = (x << 8) + (readByte() & 0xff);
- }
- int leading = 64 - (n * 8);
- return x << leading >> leading;
- }
-
- boolean isTypeEntry(int i) {
- int tag = bytes[index[i]];
- return (firstTypeTag <= tag && tag <= lastTypeTag) || tag == NOpre;
- }
-
- boolean isSymbolEntry(int i) {
- int tag = bytes[index[i]];
- return (firstSymTag <= tag && tag <= lastSymTag);
- }
-
- Name getName(int n) {
- if (entries[n] == null) {
- int savedBp = bp;
- bp = index[n];
- int tag = bytes[bp++];
- int len = readNat();
- Name name = Name.fromAscii(bytes, bp, len);
- switch (tag) {
- case TERMname : entries[n] = name; break;
- case TYPEname : entries[n] = name.toTypeName(); break;
- default: throw new BadSignature(this);
- }
- bp = savedBp;
- }
- return (Name) entries[n];
- }
-
- Name readNameRef() {
- return getName(readNat());
- }
-
- String decode(Name name) {
- if (name.isTypeName()) return "type " + NameTransformer.decode(name);
- else return "value " + NameTransformer.decode(name);
- }
-
- /*
- void enterSymbol(Symbol sym) {
- Symbol owner = sym.owner();
- if (owner.kind == CLASS &&
- !sym.isConstructor() && !sym.isModuleClass()) {
- Scope scope = owner.info().members();
- scope.enterOrOverload(sym);
- }
- }
- */
-
- void enterSymbol(Symbol sym) {
- /*
- if (global.debug) {
- global.log("entering " + sym + ":" + sym.type() + " in " + sym.owner());//debug
- if (sym.kind == CLASS)
- global.log("primconstr = " + sym.primaryConstructor());
- }
- */
- if ((sym.flags & ALTERNATIVE) != 0) {
- sym.flags &= ~ALTERNATIVE;
- } else {
- Symbol owner = sym.owner();
- if (owner.kind == CLASS &&
- !sym.isConstructor() && !sym.isModuleClass()) {
- Scope scope = owner.info().members();
- Symbol other = scope.lookup(sym.name);
- if (other == Symbol.NONE) {
- scope.enter(sym);
- } else {
- assert sym == other
- : "double enter: " + other + ":" + other.rawFirstInfo() + "," + sym + ":" + sym.rawFirstInfo();
- }
- }
- }
- }
-
- Symbol getSymbol(int n) {
- if (entries[n] == null) {
- int savedBp = bp;
- bp = index[n];
- int tag = bytes[bp++];
- int end = readNat() + bp;
- Symbol sym;
- Symbol owner;
- switch (tag) {
- case NONEsym:
- entries[n] = sym = Symbol.NONE;
- break;
- case EXTref:
- case EXTMODCLASSref:
- Name name = readNameRef();
- if (bp == end) {
- owner = global.definitions.ROOT_CLASS;
- } else {
- assert bp < end;
- owner = readSymbolRef();
- }
- if (name == Names.ROOT && owner == Symbol.NONE) {
- sym = global.definitions.ROOT_CLASS;
- if (tag == EXTref) sym = sym;
- // !!! line above is usefull for the transition
- // !!! after some time, replace it by the following line:
- // !!! assert tag != EXTref;
- } else {
- sym = owner.info().lookup(name);
- if (tag == EXTMODCLASSref) {
- /*
- if (sym.kind == VAL)
- switch (sym.type()) {
- case OverloadedType(Symbol[] alts, _):
- for (int i = 0; i < alts.length; i++)
- if (alts[i].isModule()) sym = alts[i];
- }
- */
- assert sym.isModule();
- sym = sym.moduleClass();
- }
- }
- entries[n] = sym;
- if (sym.kind == NONE) {
- if (global.debug)
- global.log(owner.info().members().toString());
- throw new BadSignature(this,
- "reference " + decode(name) + " of " + owner +
- " refers to nonexisting symbol.");
- }
- break;
- default:
- assert isSymbolEntry(n) : n;
- Name name = readNameRef();
- if (global.debug)
- global.log("reading " + name + " at " + n);
- owner = readSymbolRef();
- if (entries[n] == null) {
- int flags = readNat();
- int inforef = readNat();
- switch (tag) {
- case TYPEsym:
- entries[n] = sym = owner.newAbstractType(
- Position.NOPOS, flags, name);
- if ((flags & VIEWBOUND) != 0) {
- sym.setInfo(global.definitions.ANY_TYPE());
- sym.setVuBound(getType(inforef, sym));
- } else {
- sym.setInfo(getType(inforef, sym));
- }
- sym.setLoBound(readTypeRef(sym));
- break;
-
- case ALIASsym:
- entries[n] = sym = owner.newTypeAlias(
- Position.NOPOS, flags, name);
- sym.setInfo(getType(inforef, sym));
- Symbol constr = readSymbolRef();
- break;
-
- case CLASSsym:
- if ((flags & MODUL) != 0) {
- Symbol modulesym = readSymbolRef();
- entries[n] = sym = modulesym.moduleClass();
- sym.flags = flags;
- } else if (classroot != null && name == classroot.name && owner == classroot.owner()) {
- if (global.debug)
- global.log("overwriting " + classroot);
- entries[n] = sym = classroot;
- sym.flags = flags;
- } else {
- entries[n] = sym = owner.newClass(
- Position.NOPOS, flags, name);
- }
- sym.setInfo(getType(inforef, sym));
- sym.setTypeOfThis(readTypeRef(sym));
- Symbol constr = readSymbolRef();
- assert constr == sym.allConstructors();
- break;
-
- case VALsym:
- if (moduleroot != null && name == moduleroot.name && owner == moduleroot.owner()) {
- if (global.debug)
- global.log("overwriting " + moduleroot);
- entries[n] = sym = moduleroot;
- sym.flags = flags;
- } else if ((flags & MODUL) != 0) {
- entries[n] = sym = owner.newModule(
- Position.NOPOS, flags, name);
- } else if (name == Names.CONSTRUCTOR) {
- Symbol tsym = bp < end ? readSymbolRef() : null;
- if (tsym == null) {
- entries[n] = sym = owner.newConstructor(
- Position.NOPOS, flags);
- } else {
- entries[n] = sym = tsym.allConstructors();
- sym.flags = flags;
- }
- } else {
- entries[n] = sym = owner.newTerm(
- Position.NOPOS, flags, name);
- }
- if (sym.isModule()) {
- Symbol clasz = readSymbolRef();
- assert clasz == sym.moduleClass(): Debug.show(sym);
- }
- Type owntype = getType(inforef, sym);
- sym.setInfo(owntype);
- break;
-
- default:
- throw new BadSignature(this);
- }
-
- enterSymbol(sym);
- }
- }
- bp = savedBp;
- }
- return (Symbol) entries[n];
- }
-
- Symbol readSymbolRef() {
- return getSymbol(readNat());
- }
-
- Symbol[] readSymbolRefs(int end) {
- return readSymbolRefs(0, end);
- }
-
- Symbol[] readSymbolRefs(int nread, int end) {
- if (bp == end) {
- return new Symbol[nread];
- } else {
- assert bp < end;
- int bp0 = bp;
- int ref = readNat();
- if (isSymbolEntry(ref)) {
- Symbol s = getSymbol(ref);
- Symbol[] ss = readSymbolRefs(nread+1, end);
- ss[nread] = s;
- return ss;
- } else {
- bp = bp0;
- return new Symbol[nread];
- }
- }
- }
-
- Type getType(int n, Symbol owner) {
- Type tpe = (Type)entries[n];
- if (tpe == null) {
- int savedBp = bp;
- bp = index[n];
- int tag = bytes[bp++];
- int end = readNat() + bp;
- switch (tag) {
- case NOtpe:
- tpe = Type.NoType;
- break;
- case NOpre:
- tpe = Type.NoPrefix;
- break;
- case THIStpe:
- Symbol sym = readSymbolRef();
- tpe = (sym.kind == NONE) ? Type.NoPrefix : Type.ThisType(sym);
- // !!! code above is usefull for the transition
- // !!! after some time, replace it by the following line:
- // !!! tpe = Type.ThisType(readSymbolRef());
- break;
- case SINGLEtpe:
- Type prefix = readTypeRef(owner);
- Symbol symbol = readSymbolRef();
- tpe = symbol.isRoot() ? symbol.thisType() : Type.singleType(prefix, symbol);
- // !!! code above is usefull for the transition
- // !!! after some time, replace it by the following line:
- // !!! tpe = Type.singleType(readTypeRef(), readSymbolRef());
- break;
- case CONSTANTtpe:
- Type base = readTypeRef(owner);
- AConstant value = readConstantRef();
- tpe = new Type.ConstantType(base, value);
- break;
- case TYPEREFtpe:
- tpe = Type.newTypeRefUnsafe( // !!!
- readTypeRef(owner), readSymbolRef(), readTypeRefs(end, owner));
- break;
- case COMPOUNDtpe:
- boolean isCompoundSym = readByte() != 0;
- Symbol ctOwner = isCompoundSym
- ? readSymbolRef()
- : null;
- int ctClassRef = readNat();
- Symbol ctClass = isCompoundSym
- ? (Symbol)entries[ctClassRef]
- : getSymbol(ctClassRef);
- Type[] parents = readTypeRefs(end, owner);
- if (ctClass == null) {
- tpe = Type.compoundTypeWithOwner(ctOwner, parents, new Scope());
- entries[ctClassRef] = tpe.symbol();
- } else {
- tpe = Type.compoundType(parents, new Scope(), ctClass);
- }
- break;
- case METHODtpe:
- Type restype = readTypeRef(owner);
- int bp1 = bp;
- Type[] argtypes = readTypeRefs(end, owner);
- int[] flags = new int[argtypes.length];
- bp = bp1;
- readFlags(flags);
- Symbol[] params = new Symbol[argtypes.length];
- for (int i = 0; i < argtypes.length; i++) {
- Name name = Name.fromString("$" + i);
- params[i] = owner.newVParam(
- Position.NOPOS, flags[i], name, argtypes[i]);
- }
- tpe = Type.MethodType(params, restype);
- break;
- case POLYtpe:
- Type restype = readTypeRef(owner);
- tpe = Type.PolyType(readSymbolRefs(end), restype);
- break;
- case OVERLOADEDtpe:
- int bp0 = bp;
- Symbol[] alts = readSymbolRefs(end);
- int bp1 = bp;
- Type[] alttypes = readTypeRefs(end, alts);
- assert alts.length == alttypes.length
- : alts.length + "!=" + alttypes.length +
- " at " + bp0 + "/" + bp1 + "/" + bp;
- tpe = Type.OverloadedType(alts, alttypes);
- break;
- case FLAGGEDtpe:
- readNat(); // skip flags
- tpe = readTypeRef(owner);
- break;
- default:
- throw new BadSignature(this);
- }
- if (tag != METHODtpe) entries[n] = tpe;
- bp = savedBp;
- }
- return tpe;
- }
-
- Type readTypeRef(Symbol owner) {
- return getType(readNat(), owner);
- }
-
- Type[] readTypeRefs(int end, Symbol owner) {
- return readTypeRefs(0, end, owner, null);
- }
-
- Type[] readTypeRefs(int end, Symbol[] owners) {
- return readTypeRefs(0, end, null, owners);
- }
-
- Type[] readTypeRefs(int nread, int end, Symbol owner, Symbol[] owners) {
- assert (owner != null) ^ (owners != null);
- if (bp == end) {
- return new Type[nread];
- } else {
- assert bp < end : bp + ">" + end;
- int bp0 = bp;
- int ref = readNat();
- if (isTypeEntry(ref)) {
- Type t = getType(ref, owner != null ? owner : owners[nread]);
- Type[] ts = readTypeRefs(nread + 1, end, owner, owners);
- ts[nread] = t;
- return ts;
- } else {
- bp = bp0;
- return new Type[nread];
- }
- }
- }
-
- void readFlags(int[] flags) {
- for (int i = 0; i < flags.length; i++)
- flags[i] = getFlags(readNat());
- }
-
- int getFlags(int n) {
- int savedBp = bp;
- bp = index[n];
- int tag = bytes[bp++];
- int end = readNat() + bp;
- int flags = (tag == FLAGGEDtpe) ? decodeFlags(readNat()) : 0;
- bp = savedBp;
- return flags;
- }
-
- private static int decodeFlags(int n) {
- int flags = 0;
- if ((n & REPEATEDflag) != 0) flags |= REPEATED;
- if ((n & DEFflag) != 0) flags |= DEF;
- return flags;
- }
-
- AConstant readConstant() {
- int tag = bytes[bp++];
- int len = readNat();
- switch (tag) {
- case LITERALunit:
- return AConstant.UNIT;
- case LITERALboolean:
- return AConstant.BOOLEAN(readByte() == 0 ? false : true);
- case LITERALbyte:
- return AConstant.BYTE((byte)readLong(len));
- case LITERALshort:
- return AConstant.SHORT((short)readLong(len));
- case LITERALchar:
- return AConstant.CHAR((char)readLong(len));
- case LITERALint:
- return AConstant.INT((int)readLong(len));
- case LITERALlong:
- return AConstant.LONG(readLong(len));
- case LITERALfloat:
- return AConstant.FLOAT(Float.intBitsToFloat((int)readLong(len)));
- case LITERALdouble:
- return AConstant.DOUBLE(Double.longBitsToDouble(readLong(len)));
- case LITERALstring:
- return AConstant.STRING(readNameRef().toString());
- case LITERALnull:
- return AConstant.NULL;
- case LITERALzero:
- return AConstant.ZERO;
- default:
- throw Debug.abort("illegal tag: " + tag);
- }
- }
-
- AConstant readConstantRef() {
- int n = readNat();
- int savedBp = bp;
- bp = index[n];
- AConstant constant = readConstant();
- bp = savedBp;
- return constant;
- }
-
- public static class BadSignature extends java.lang.Error {
- public BadSignature(UnPickle outer, String msg) {
- super(msg);
- }
- public BadSignature(UnPickle outer) {
- this(outer, "malformed signature at " + outer.bp);
- }
- }
-
-// --- print symbl files -------------------------------------------------
-
- private static String tag2string(int tag) {
- switch (tag) {
- case TERMname: return "TERMname";
- case TYPEname: return "TYPEname";
- case NONEsym: return "NONEsym";
- case TYPEsym: return "TYPEsym";
- case ALIASsym: return "ALIASsym";
- case CLASSsym: return "CLASSsym";
- case VALsym: return "VALsym";
- case EXTref: return "EXTref";
- case EXTMODCLASSref: return "EXTMODCLASSref";
- case NOtpe: return "NOtpe";
- case THIStpe: return "THIStpe";
- case SINGLEtpe: return "SINGLEtpe";
- case TYPEREFtpe: return "TYPEREFtpe";
- case CONSTANTtpe: return "CONSTANTtpe";
- case COMPOUNDtpe: return "COMPOUNDtpe";
- case METHODtpe: return "METHODtpe";
- case POLYtpe: return "POLYtpe";
- case OVERLOADEDtpe: return "OVERLOADEDtpe";
- case UNBOXEDtpe: return "UNBOXEDtpe";
- case UNBOXEDARRAYtpe: return "UNBOXEDARRAYtpe";
- case FLAGGEDtpe: return "FLAGGEDtpe";
- case ERRORtpe: return "ERRORtpe";
- case LITERALunit: return "LITERALunit";
- case LITERALboolean: return "LITERALboolean";
- case LITERALbyte: return "LITERALbyte";
- case LITERALshort: return "LITERALshort";
- case LITERALchar: return "LITERALchar";
- case LITERALint: return "LITERALint";
- case LITERALlong: return "LITERALlong";
- case LITERALfloat: return "LITERALfloat";
- case LITERALdouble: return "LITERALdouble";
- case LITERALstring: return "LITERALstring";
- case LITERALnull: return "LITERALnull";
- case LITERALzero: return "LITERALzero";
- default: return "***BAD TAG***(" + tag + ")";
- }
- }
-
- private void print(PrintStream out) {
- out.println("symbl attribute for " + classroot + ":");
- for (int i = 0; i < index.length; i++) {
- out.print(i + "," + index[i] + ": ");
- bp = index[i];
- int tag = readByte();
- out.print(tag2string(tag));
- int len = readNat();
- int end = len + bp;
- out.print(" " + len);
- switch (tag) {
- case TERMname:
- case TYPEname:
- String name = SourceRepresentation.ascii2string(bytes, bp, len);
- out.print(" " + SourceRepresentation.escape(name));
- bp = end;
- break;
- case NONEsym:
- break;
- case TYPEsym:
- case ALIASsym:
- case CLASSsym:
- case VALsym:
- out.print(" " + readNat()); //name
- out.print(" " + readNat()); //owner
- out.print(" " + Integer.toHexString(readNat())); //flags
- out.print(" " + readNat()); //type
- break;
- case FLAGGEDtpe:
- out.print(" " + Integer.toHexString(readNat())); //flags
- }
- while (bp < end) out.print(" " + readNat());
- out.println();
- }
- }
-}
-