summaryrefslogtreecommitdiff
path: root/src/msil/ch/epfl/lamp/compiler/msil/Type.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/msil/ch/epfl/lamp/compiler/msil/Type.java')
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/Type.java101
1 files changed, 88 insertions, 13 deletions
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/Type.java b/src/msil/ch/epfl/lamp/compiler/msil/Type.java
index f7d44980c4..78704062b7 100644
--- a/src/msil/ch/epfl/lamp/compiler/msil/Type.java
+++ b/src/msil/ch/epfl/lamp/compiler/msil/Type.java
@@ -21,6 +21,31 @@ import java.util.Arrays;
*/
public abstract class Type extends MemberInfo {
+ private java.util.List /* GenericParamAndConstraints */ tVars = new java.util.LinkedList();
+ private GenericParamAndConstraints[] sortedTVars = null;
+
+ public void addTVar(GenericParamAndConstraints tvarAndConstraints) {
+ sortedTVars = null;
+ tVars.add(tvarAndConstraints);
+ }
+
+ public GenericParamAndConstraints[] getSortedTVars() {
+ if(sortedTVars == null) {
+ sortedTVars = new GenericParamAndConstraints[tVars.size()];
+ for (int i = 0; i < sortedTVars.length; i ++){
+ Iterator iter = tVars.iterator();
+ while(iter.hasNext()) {
+ GenericParamAndConstraints tvC = (GenericParamAndConstraints)iter.next();
+ if(tvC.Number == i) {
+ sortedTVars[i] = tvC;
+ }
+ }
+ }
+ }
+ return sortedTVars;
+ }
+
+
//##########################################################################
// public static members
@@ -90,7 +115,7 @@ public abstract class Type extends MemberInfo {
// the underlying type of an enumeration. null if the type is not enum.
protected Type underlyingType;
- private int auxAttr;
+ protected int auxAttr;
//##########################################################################
// Map with all the types known so far and operations on it
@@ -102,6 +127,8 @@ public abstract class Type extends MemberInfo {
}
protected static Type addType(Type t) {
+ assert(!(t instanceof TMVarUsage));
+ assert(!(t instanceof ConstructedType));
Type oldType = (Type) types.put(t.FullName, t);
// if (oldType != null)
// throw new RuntimeException("The type: [" + t.Assembly + "]" + t
@@ -259,10 +286,22 @@ public abstract class Type extends MemberInfo {
return BaseType() == ENUM();
}
+ /** IsGeneric, true for a PEType or TypeBuilder (i.e., a type definition)
+ * containing one or more type params. Not to be called on a reference
+ * to a constructed type. */
+ public final boolean IsGeneric() {
+ return tVars.size() > 0;
+ }
+
public final boolean HasElementType() {
return IsArray() || IsPointer() || IsByRef();
}
+ public boolean IsTMVarUsage() {
+ // overridden in TMVarUsage
+ return false;
+ }
+
//public final boolean IsCOMObject;
//public final boolean IsContextful;
//public final boolean IsMarshalByRef;
@@ -281,19 +320,43 @@ public abstract class Type extends MemberInfo {
//##########################################################################
- static final class PrimitiveType extends Type {
- public PrimitiveType(Module module,
- int attributes,
- String fullName,
- Type baseType,
- Type[] interfaces,
- Type declType,
- int auxAttr,
- Type elemType)
- {
- super(module, attributes, fullName,
- baseType, interfaces, declType, auxAttr, elemType);
+ public static final class TMVarUsage extends Type {
+
+ public final int Number;
+ public final boolean isTVar;
+
+ /** Non-defining reference to either a TVar or an MVar */
+ public TMVarUsage(int Number, boolean isTVar) {
+ super(null, 0, ((isTVar ? "!" : "!!") + Number), null, null, null, AuxAttr.None, null);
+ this.Number = Number;
+ this.isTVar = isTVar;
}
+
+ public String toString() {
+ return (isTVar ? "!" : "!!") + Number;
+ }
+
+ public final boolean IsTMVarUsage() {
+ return true;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ TMVarUsage that = (TMVarUsage) o;
+
+ if (Number != that.Number) return false;
+ if (isTVar != that.isTVar) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = Number;
+ result = 31 * result + (isTVar ? 1 : 0);
+ return result;
+ }
}
protected static final class AuxAttr {
@@ -336,6 +399,18 @@ public abstract class Type extends MemberInfo {
return addType(type);
}
+ /***/
+ public static Type mkByRef(Type elemType) {
+ String name = elemType.FullName + "&";
+ Type type = getType(name);
+ if (type != null) return type;
+ type = new PrimitiveType(elemType.Module,
+ TypeAttributes.NotPublic,
+ name, null, EmptyTypes, null,
+ AuxAttr.ByRef, elemType);
+ return addType(type);
+ }
+
//##########################################################################
// public methods