summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab/classfile
diff options
context:
space:
mode:
authorMatthias Zenger <mzenger@gmail.com>2003-09-24 22:21:00 +0000
committerMatthias Zenger <mzenger@gmail.com>2003-09-24 22:21:00 +0000
commit423ecdde9b683f8b32624e5e08930c7f461dca4e (patch)
tree023d3e4d85ed27a5def1dfe7946da6c77e5b75e9 /sources/scalac/symtab/classfile
parent191c921e2e289b9e2daf7cb4e5b5a45d5dff8de5 (diff)
downloadscala-423ecdde9b683f8b32624e5e08930c7f461dca4e.tar.gz
scala-423ecdde9b683f8b32624e5e08930c7f461dca4e.tar.bz2
scala-423ecdde9b683f8b32624e5e08930c7f461dca4e.zip
Support for pattern matching on Jaco case class...
Support for pattern matching on Jaco case classes in Scala.
Diffstat (limited to 'sources/scalac/symtab/classfile')
-rw-r--r--sources/scalac/symtab/classfile/AttributeParser.java94
-rw-r--r--sources/scalac/symtab/classfile/ClassfileConstants.java2
-rw-r--r--sources/scalac/symtab/classfile/ClassfileParser.java97
3 files changed, 99 insertions, 94 deletions
diff --git a/sources/scalac/symtab/classfile/AttributeParser.java b/sources/scalac/symtab/classfile/AttributeParser.java
index 7c52cd347e..d7bda1c82d 100644
--- a/sources/scalac/symtab/classfile/AttributeParser.java
+++ b/sources/scalac/symtab/classfile/AttributeParser.java
@@ -57,6 +57,8 @@ public class AttributeParser implements ClassfileConstants {
return META_ATTR;
if (name == SCALA_N)
return SCALA_ATTR;
+ if (name == JACO_N)
+ return JACO_ATTR;
return BAD_ATTR;
}
@@ -82,8 +84,7 @@ public class AttributeParser implements ClassfileConstants {
// class attributes
case SCALA_ATTR:
new UnPickle(sym, in.nextBytes(attrLen), Name.fromString(in.path));
- return;
-
+ return;
case INNERCLASSES_ATTR:
/* int n = in.nextChar();
for (int i = 0; i < n; i++) {
@@ -99,12 +100,10 @@ public class AttributeParser implements ClassfileConstants {
} */
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];
@@ -113,39 +112,42 @@ public class AttributeParser implements ClassfileConstants {
//((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 DEPRECATED_ATTR:
sym.flags |= Modifiers.DEPRECATED;
return;
-
case CONSTANT_VALUE_ATTR:
// Type ctype = (Type)reader.readPool(in.nextChar());
// def.type = types.coerce(ctype, def.type);
in.skip(attrLen);
return;
-
case META_ATTR:
//System.out.println("parsing meta data for " + sym);
String meta = pool.readPool(in.nextChar()).toString().trim();
sym.setFirstInfo(
- new MetaParser(meta, tvars, sym, type).parse());
+ new MetaParser(meta, tvars, sym, type).parse());
return;
-
- default:
- in.skip(attrLen);
+ 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;
+ default:
+ in.skip(attrLen);
return;
}
}
@@ -175,22 +177,22 @@ public class AttributeParser implements ClassfileConstants {
private Symbol getTVar(String name, Symbol owner) {
if (name.startsWith("?")) {
- Symbol s = ((locals != null) ? locals : tvars)
- .lookup(Name.fromString(name).toTypeName());
- if (s != Symbol.NONE)
- return s;
- else if (locals != null) {
- s = tvars.lookup(Name.fromString(name).toTypeName());
- if (s != Symbol.NONE)
- return s;
- }
+ Symbol s = ((locals != null) ? locals : tvars)
+ .lookup(Name.fromString(name).toTypeName());
+ if (s != Symbol.NONE)
+ return s;
+ else if (locals != null) {
+ s = tvars.lookup(Name.fromString(name).toTypeName());
+ if (s != Symbol.NONE)
+ return s;
+ }
s = new AbsTypeSymbol(
- Position.NOPOS,
- Name.fromString(token).toTypeName(),
- owner,
- Modifiers.PARAM);
- s.setFirstInfo(parser.defs.ANY_TYPE);
- tvars.enter(s);
+ Position.NOPOS,
+ Name.fromString(token).toTypeName(),
+ owner,
+ Modifiers.PARAM);
+ s.setFirstInfo(parser.defs.ANY_TYPE);
+ tvars.enter(s);
return s;
} else
return Symbol.NONE;
@@ -254,17 +256,17 @@ public class AttributeParser implements ClassfileConstants {
Symbol[] smbls = (Symbol[])syms.toArray(new Symbol[syms.size()]);
//System.out.println("*** " + syms);//DEBUG
Type clazztype = Type.appliedType(
- parser.ctype, Symbol.type(smbls));
- Symbol constr = parser.c.primaryConstructor();
- switch (constr.rawInfo()) {
- case MethodType(Symbol[] vparams, _):
- constr.setFirstInfo(
- Type.PolyType(
- smbls, Type.MethodType(vparams, clazztype)));
- break;
- default:
- throw new ApplicationError(constr.rawInfo());
- }
+ parser.ctype, Symbol.type(smbls));
+ Symbol constr = parser.c.primaryConstructor();
+ switch (constr.rawInfo()) {
+ case MethodType(Symbol[] vparams, _):
+ constr.setFirstInfo(
+ Type.PolyType(
+ smbls, Type.MethodType(vparams, clazztype)));
+ break;
+ default:
+ throw new ApplicationError(constr.rawInfo());
+ }
} catch (NoSuchElementException e) {
}
}
@@ -324,12 +326,12 @@ public class AttributeParser implements ClassfileConstants {
break;
assert token.startsWith("?");
Symbol s = new AbsTypeSymbol(
- Position.NOPOS,
- Name.fromString(token).toTypeName(),
- owner,
- Modifiers.PARAM);
- s.setFirstInfo(parser.defs.ANY_TYPE);
- locals.enter(s);
+ Position.NOPOS,
+ Name.fromString(token).toTypeName(),
+ owner,
+ Modifiers.PARAM);
+ s.setFirstInfo(parser.defs.ANY_TYPE);
+ locals.enter(s);
nextToken();
if (token.equals("<")) {
nextToken();
diff --git a/sources/scalac/symtab/classfile/ClassfileConstants.java b/sources/scalac/symtab/classfile/ClassfileConstants.java
index 16b9f5af44..e35150ae30 100644
--- a/sources/scalac/symtab/classfile/ClassfileConstants.java
+++ b/sources/scalac/symtab/classfile/ClassfileConstants.java
@@ -41,6 +41,7 @@ public interface ClassfileConstants {
int INNERCLASSES_ATTR = 0x08000;
int META_ATTR = 0x10000;
int SCALA_ATTR = 0x20000;
+ int JACO_ATTR = 0x40000;
Name SOURCEFILE_N = Name.fromString("SourceFile");
Name SYNTHETIC_N = Name.fromString("Synthetic");
@@ -53,5 +54,6 @@ public interface ClassfileConstants {
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 CONSTR_N = Name.fromString("<init>");
}
diff --git a/sources/scalac/symtab/classfile/ClassfileParser.java b/sources/scalac/symtab/classfile/ClassfileParser.java
index 04d876fce8..28f31c3647 100644
--- a/sources/scalac/symtab/classfile/ClassfileParser.java
+++ b/sources/scalac/symtab/classfile/ClassfileParser.java
@@ -24,7 +24,8 @@ public class ClassfileParser implements ClassfileConstants {
| SYNTHETIC_ATTR
| DEPRECATED_ATTR
| META_ATTR
- | SCALA_ATTR;
+ | SCALA_ATTR
+ | JACO_ATTR;
static final int METH_ATTR = CODE_ATTR
| EXCEPTIONS_ATTR
| SYNTHETIC_ATTR
@@ -52,7 +53,7 @@ public class ClassfileParser implements ClassfileConstants {
this.global = global;
this.in = in;
this.c = c;
- this.ctype = c.typeConstructor();
+ this.ctype = c.typeConstructor();
this.make = new JavaTypeCreator(global);
this.sigs = new Signatures(global, make);
this.pool = new ConstantPool(in, sigs);
@@ -84,8 +85,8 @@ public class ClassfileParser implements ClassfileConstants {
"' contains wrong class " + name);
// todo: correct flag transition
c.flags = transFlags(flags);
- if ((c.flags & Modifiers.DEFERRED) != 0)
- c.flags = c.flags & ~Modifiers.DEFERRED | Modifiers.ABSTRACTCLASS;
+ if ((c.flags & Modifiers.DEFERRED) != 0)
+ c.flags = c.flags & ~Modifiers.DEFERRED | Modifiers.ABSTRACTCLASS;
Type supertpe = readClassType(in.nextChar());
Type[] basetpes = new Type[in.nextChar() + 1];
this.locals = new Scope();
@@ -94,13 +95,13 @@ public class ClassfileParser implements ClassfileConstants {
Type classType = Type.compoundType(basetpes, locals, c);
c.setFirstInfo(classType);
// set type of statics
- Symbol staticsClass = c.module().moduleClass();
- if (staticsClass.isModuleClass()) {
- Type staticsInfo = Type.compoundType(Type.EMPTY_ARRAY, statics, staticsClass);
- staticsClass.setFirstInfo(staticsInfo);
- c.module().setInfo(Type.TypeRef(staticsClass.owner().thisType(),
- staticsClass, Type.EMPTY_ARRAY));
- }
+ Symbol staticsClass = c.module().moduleClass();
+ if (staticsClass.isModuleClass()) {
+ Type staticsInfo = Type.compoundType(Type.EMPTY_ARRAY, statics, staticsClass);
+ staticsClass.setFirstInfo(staticsInfo);
+ c.module().setInfo(Type.TypeRef(staticsClass.owner().thisType(),
+ staticsClass, Type.EMPTY_ARRAY));
+ }
basetpes[0] = supertpe;
for (int i = 1; i < basetpes.length; i++)
basetpes[i] = readClassType(in.nextChar());
@@ -111,18 +112,18 @@ public class ClassfileParser implements ClassfileConstants {
for (int i = 0; i < methodCount; i++)
parseMethod();
- Symbol constr = c.primaryConstructor();
- if (!constr.isInitialized()) {
- constr.setFirstInfo(
- Type.MethodType(Symbol.EMPTY_ARRAY, ctype));
- if ((c.flags & Modifiers.INTERFACE) == 0)
- constr.flags |= Modifiers.PRIVATE;
- }
+ Symbol constr = c.primaryConstructor();
+ if (!constr.isInitialized()) {
+ constr.setFirstInfo(
+ Type.MethodType(Symbol.EMPTY_ARRAY, ctype));
+ if ((c.flags & Modifiers.INTERFACE) == 0)
+ constr.flags |= Modifiers.PRIVATE;
+ }
attrib.readAttributes(c, classType, CLASS_ATTR);
- //System.out.println("dynamic class: " + c);
- //System.out.println("statics class: " + staticsClass);
- //System.out.println("module: " + c.module());
- //System.out.println("modules class: " + c.module().type().symbol());
+ //System.out.println("dynamic class: " + c);
+ //System.out.println("statics class: " + staticsClass);
+ //System.out.println("module: " + c.module());
+ //System.out.println("modules class: " + c.module().type().symbol());
} catch (RuntimeException e) {
if (global.debug) e.printStackTrace();
String s = e.getMessage() == null ? "" : " (" +e.getMessage()+ ")";
@@ -178,16 +179,16 @@ public class ClassfileParser implements ClassfileConstants {
int flags = in.nextChar();
Name name = (Name)pool.readPool(in.nextChar());
Type type = readType(in.nextChar());
- int mods = transFlags(flags);
- if ((flags & 0x0010) == 0)
- mods |= Modifiers.MUTABLE;
- Symbol owner = c;
- if ((flags & 0x0008) != 0)
- owner = c.module().moduleClass();
+ int mods = transFlags(flags);
+ if ((flags & 0x0010) == 0)
+ mods |= Modifiers.MUTABLE;
+ Symbol owner = c;
+ if ((flags & 0x0008) != 0)
+ owner = c.module().moduleClass();
Symbol s = new TermSymbol(Position.NOPOS, name, owner, mods);
s.setFirstInfo(type);
attrib.readAttributes(s, type, FIELD_ATTR);
- ((flags & 0x0008) != 0 ? statics : locals).enterOrOverload(s);
+ ((flags & 0x0008) != 0 ? statics : locals).enterOrOverload(s);
}
/** read a method
@@ -206,27 +207,27 @@ public class ClassfileParser implements ClassfileConstants {
return;
}
switch (type) {
- case MethodType(Symbol[] vparams, _):
- type = Type.MethodType(vparams, ctype);
- break;
- default:
- throw new ApplicationError();
- }
- s.setFirstInfo(type);
+ case MethodType(Symbol[] vparams, _):
+ type = Type.MethodType(vparams, ctype);
+ break;
+ default:
+ throw new ApplicationError();
+ }
+ s.setFirstInfo(type);
attrib.readAttributes(s, type, METH_ATTR);
- Symbol constr = c.primaryConstructor();
- if (constr.isInitialized()) constr = c.addConstructor();
- s.copyTo(constr);
- //System.out.println(c + " " + c.allConstructors() + ":" + c.allConstructors().info());//debug
+ Symbol constr = c.primaryConstructor();
+ if (constr.isInitialized()) constr = c.addConstructor();
+ s.copyTo(constr);
+ //System.out.println(c + " " + c.allConstructors() + ":" + c.allConstructors().info());//debug
//System.out.println("-- enter " + s);
} else {
- Symbol s = new TermSymbol(
- Position.NOPOS, name,
- ((flags & 0x0008) != 0) ? c.module().moduleClass() : c,
- transFlags(flags));
- s.setFirstInfo(type);
- attrib.readAttributes(s, type, METH_ATTR);
- ((flags & 0x0008) != 0 ? statics : locals).enterOrOverload(s);
- }
+ Symbol s = new TermSymbol(
+ Position.NOPOS, name,
+ ((flags & 0x0008) != 0) ? c.module().moduleClass() : c,
+ transFlags(flags));
+ s.setFirstInfo(type);
+ attrib.readAttributes(s, type, METH_ATTR);
+ ((flags & 0x0008) != 0 ? statics : locals).enterOrOverload(s);
+ }
}
}