summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authormihaylov <mihaylov@epfl.ch>2004-12-13 15:00:53 +0000
committermihaylov <mihaylov@epfl.ch>2004-12-13 15:00:53 +0000
commit99847828c7cfe7da54722c0f8dcc52edc641419e (patch)
tree8d8c6f9c57320cfbaebe701093566597818034b6 /sources
parent8332a1e9d802472fe763cce3a3bf6967e74a0249 (diff)
downloadscala-99847828c7cfe7da54722c0f8dcc52edc641419e.tar.gz
scala-99847828c7cfe7da54722c0f8dcc52edc641419e.tar.bz2
scala-99847828c7cfe7da54722c0f8dcc52edc641419e.zip
[MSIL] Prevent the loading of synthetic Scala c...
[MSIL] Prevent the loading of synthetic Scala classes by marking them with a special attribute.
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/runtime/MetaAttribute.cs2
-rw-r--r--sources/scala/runtime/SymtabAttribute.cs12
-rw-r--r--sources/scalac/backend/msil/GenMSIL.java44
-rw-r--r--sources/scalac/backend/msil/TypeCreator.java7
-rw-r--r--sources/scalac/symtab/classfile/CLRPackageParser.java4
-rw-r--r--sources/scalac/symtab/classfile/CLRTypes.java13
6 files changed, 60 insertions, 22 deletions
diff --git a/sources/scala/runtime/MetaAttribute.cs b/sources/scala/runtime/MetaAttribute.cs
index d9727d0f06..72a44dd8ff 100644
--- a/sources/scala/runtime/MetaAttribute.cs
+++ b/sources/scala/runtime/MetaAttribute.cs
@@ -13,6 +13,8 @@ namespace scala.runtime
AllowMultiple = false, Inherited = false)]
public class MetaAttribute : Attribute
{
+ // keeps a textual representation of the pico-style attributes
+ // used in some classes of the runtime library
public readonly string meta;
public MetaAttribute(string meta)
{
diff --git a/sources/scala/runtime/SymtabAttribute.cs b/sources/scala/runtime/SymtabAttribute.cs
index a4cefa1327..23fc8faabd 100644
--- a/sources/scala/runtime/SymtabAttribute.cs
+++ b/sources/scala/runtime/SymtabAttribute.cs
@@ -9,10 +9,22 @@ namespace scala.runtime
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class SymtabAttribute : Attribute
{
+ // stores scalac symbol table
public readonly byte[] symtab;
+
+ // indicates if the type should be considered by the compiler;
+ // used for synthetic classes introduced by the Scala compiler
+ public readonly bool shouldLoadClass;
+
public SymtabAttribute(byte[] symtab)
{
this.symtab = symtab;
+ this.shouldLoadClass = true;
+ }
+
+ public SymtabAttribute() {
+ this.symtab = new byte[0];
+ this.shouldLoadClass = false;
}
}
}
diff --git a/sources/scalac/backend/msil/GenMSIL.java b/sources/scalac/backend/msil/GenMSIL.java
index 0d6250e4c5..36c1b6432a 100644
--- a/sources/scalac/backend/msil/GenMSIL.java
+++ b/sources/scalac/backend/msil/GenMSIL.java
@@ -21,6 +21,7 @@ import scalac.ast.Tree;
import scalac.ast.TreeList;
import scalac.atree.AConstant;
import Tree.*;
+import scalac.symtab.AttrInfo;
import scalac.symtab.Symbol;
import scalac.symtab.TypeTags;
import scalac.symtab.Modifiers;
@@ -38,6 +39,7 @@ import ch.epfl.lamp.compiler.msil.emit.*;
import Item.*;
+import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
@@ -170,38 +172,47 @@ public final class GenMSIL {
/** The method that is currently being compiled. */
private MethodBase currentMethod;
+
+ private static final byte[] NO_SYMTAB = new byte[] {1, 0, 0, 0};
/*
* Emit the symbol table for the class given class as an MSIL attribute.
*/
private void emitSymtab(Symbol clazz) {
+ ConstructorInfo symtabConstr = tc.SYMTAB_DEFAULT_CONSTR;
+ byte[] symtab = null;
Pickle pickle = (Pickle)global.symdata.get(clazz);
- if (pickle != null) {
- byte[] symtab = new byte[pickle.size() + 8];
+ if (pickle == null) {
+ symtab = NO_SYMTAB;
+ } else {
+ symtabConstr = tc.SYMTAB_CONSTR;
+ symtab = new byte[pickle.size() + 8];
symtab[0] = 1;
for (int size = pickle.size(), i = 2; i < 6; i++) {
symtab[i] = (byte)(size & 0xff);
size >>= 8;
}
System.arraycopy(pickle.bytes, 0, symtab, 6, pickle.size());
- TypeBuilder type = (TypeBuilder) tc.getType(clazz);
- if (clazz.isModuleClass()) {
- TypeBuilder t = tc.getStaticType(clazz);
- if (t != null) {
- type = t;
- if (global.args.debuginfo.value)
- type.setPosition(Position.line(clazz.pos), getSourceFilename());
- }
- }
- type.SetCustomAttribute(tc.SCALA_SYMTAB_ATTR_CONSTR, symtab);
- }
+ }
+ TypeBuilder type = (TypeBuilder) tc.getType(clazz);
+ if (clazz.isModuleClass()) {
+ TypeBuilder t = tc.getStaticType(clazz);
+ if (t != null) {
+ type.SetCustomAttribute(tc.SYMTAB_DEFAULT_CONSTR, NO_SYMTAB);
+ type = t;
+ if (global.args.debuginfo.value)
+ type.setPosition(Position.line(clazz.pos), getSourceFilename());
+ }
+ }
+ type.SetCustomAttribute(symtabConstr, symtab);
}
/*
* Generate the code for a class definition
*/
private void genClass(Symbol clazz, Tree[] body) {
- //Object o = global.mapSymbolAttr.get(clazz);
- //System.out.println("[" + o + "]" + Debug.show(clazz));
+// AttrInfo attrs = global.getAttributes(clazz);
+// if (attrs != null)
+// System.out.println("" + attrs + Debug.show(clazz));
Symbol outerClass = currentClass;
currentClass = clazz;
if (clazz.isModuleClass()) {
@@ -268,6 +279,9 @@ public final class GenMSIL {
* Generate code for constructors and methods.
*/
private void genDef(Symbol sym, ValDef[] parameters, Tree rhs, MSILType toType) {
+// AttrInfo attrs = global.getAttributes(sym);
+// if (attrs != null)
+// System.out.println("" + attrs + Debug.show(sym));
MethodBase method = tc.getMethod(sym);
params.clear();
diff --git a/sources/scalac/backend/msil/TypeCreator.java b/sources/scalac/backend/msil/TypeCreator.java
index 1b8fae8277..af106a1fa1 100644
--- a/sources/scalac/backend/msil/TypeCreator.java
+++ b/sources/scalac/backend/msil/TypeCreator.java
@@ -115,7 +115,8 @@ final class TypeCreator {
public Symbol SYM_COMPARE_TO_IGNORE_CASE;
public MethodInfo COMPARE_TO_IGNORE_CASE;
- public ConstructorInfo SCALA_SYMTAB_ATTR_CONSTR;
+ public ConstructorInfo SYMTAB_CONSTR;
+ public ConstructorInfo SYMTAB_DEFAULT_CONSTR;
private scalac.symtab.Type MAIN_METHOD_TYPE;
@@ -194,7 +195,6 @@ final class TypeCreator {
final Symbol JOBJECT = defs.OBJECT_CLASS; //defs.getClass("java.lang.Object");
final Symbol JSTRING = defs.STRING_CLASS;
-
// initialize type mappings
map(defs.ANY_CLASS, OBJECT);
map(defs.ANYREF_CLASS, OBJECT);
@@ -289,7 +289,8 @@ final class TypeCreator {
STRING.GetMethod("Compare", new Type[]{STRING, STRING, BOOLEAN});
initialized = true;
- SCALA_SYMTAB_ATTR_CONSTR = ti.SCALA_SYMTAB_ATTR.GetConstructors()[0];
+ SYMTAB_CONSTR = ti.SYMTAB_CONSTR;
+ SYMTAB_DEFAULT_CONSTR = ti.SYMTAB_DEFAULT_CONSTR;
scalac.symtab.Type argument = defs.array_TYPE(defs.STRING_TYPE());
scalac.symtab.Type result = defs.void_TYPE();
diff --git a/sources/scalac/symtab/classfile/CLRPackageParser.java b/sources/scalac/symtab/classfile/CLRPackageParser.java
index 6375bb17a4..d97ab203a9 100644
--- a/sources/scalac/symtab/classfile/CLRPackageParser.java
+++ b/sources/scalac/symtab/classfile/CLRPackageParser.java
@@ -115,7 +115,9 @@ public final class CLRPackageParser extends PackageParser {
(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();
+ 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() + "]",
diff --git a/sources/scalac/symtab/classfile/CLRTypes.java b/sources/scalac/symtab/classfile/CLRTypes.java
index 945261ab47..c510323492 100644
--- a/sources/scalac/symtab/classfile/CLRTypes.java
+++ b/sources/scalac/symtab/classfile/CLRTypes.java
@@ -70,10 +70,12 @@ public final class CLRTypes {
public final Type STRING;
public final Type STRING_ARRAY;
- public final Type SCALA_SYMTAB_ATTR;
-
public final Type PICO_META_ATTR;
+ public final Type SCALA_SYMTAB_ATTR;
+ public final ConstructorInfo SYMTAB_CONSTR;
+ public final ConstructorInfo SYMTAB_DEFAULT_CONSTR;
+
private final SymbolNameWriter snw = new SymbolNameWriter();
private Type[] types;
@@ -110,10 +112,15 @@ public final class CLRTypes {
STRING = getType("System.String");
STRING_ARRAY = getType("System.String[]");
- SCALA_SYMTAB_ATTR = Type.GetType("scala.runtime.SymtabAttribute");
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);
assert PICO_META_ATTR != null;
+ assert SCALA_SYMTAB_ATTR != null;
Type[] types = Type.EmptyTypes;
Iterator as = assemblies.iterator();