The base descriptor for a class
Inheritance: Type
Beispiel #1
0
 /*-------------------- Constructors ---------------------------------*/
 internal MethodRef(Class paren, string name, Type retType, Type[] pars)
     : base(name,retType,paren)
 {
     sig.parTypes = pars;
     if (pars != null) sig.numPars = (uint)pars.Length;
 }
Beispiel #2
0
 internal void SetClassParam(Class paren, int ix)
 {
     typeIndex = VAR;
     parent = paren;
     index = (ushort)ix;
 }
Beispiel #3
0
 internal InterfaceImpl(ClassDef theClass, TableRow theInterface)
 {
     this.theClass = theClass;
     this.theInterface = (Class)theInterface;
     tabIx = MDTable.InterfaceImpl;
 }
Beispiel #4
0
 /*-------------------- Constructors ---------------------------------*/
 internal Field(string pfName, Type pfType, Class paren)
     : base(pfName, paren)
 {
     type = pfType;
 }
Beispiel #5
0
 /// <summary>
 /// Add a type constraint to this generic parameter
 /// </summary>
 /// <param name="cType">class constraining the parameter type</param>
 public void AddConstraint(Class cType)
 {
     constraints.Add(cType);
 }
Beispiel #6
0
 public ClassTypeConst(Class classDesc)
 {
     desc = classDesc;
     type = ElementType.ClassType;
 }
Beispiel #7
0
 public void SetModifingType(Class mod)
 {
     cmodType = mod;
 }
Beispiel #8
0
 /*-------------------- Constructors ---------------------------------*/
 /// <summary>
 /// Create a new catch clause
 /// </summary>
 /// <param name="except">the exception to be caught</param>
 /// <param name="handlerStart">start of the handler code</param>
 /// <param name="handlerEnd">end of the handler code</param>
 public Catch(Class except, CILLabel handlerStart, CILLabel handlerEnd)
     : base(handlerStart,handlerEnd)
 {
     exceptType = except;
 }
Beispiel #9
0
 private Type GetBlobType()
 {
     //Class currClass, Method currMeth) {
     byte typeIx = blob.ReadByte();
     if (Diag.DiagOn) Console.WriteLine("Getting blob type " + (ElementType)typeIx);
     if (typeIx < PrimitiveType.primitives.Length)
         return PrimitiveType.primitives[typeIx];
     switch (typeIx) {
         case ((int)ElementType.Ptr) :
             return new UnmanagedPointer(GetBlobType()); //currClass,currMeth));
         case ((int)ElementType.ByRef) :
             return new ManagedPointer(GetBlobType()); //currClass,currMeth));
         case ((int)ElementType.ValueType) :
             //Console.WriteLine("Reading value type");
             uint vcIx = blob.ReadCompressedNum();
             Class vClass = (Class)GetCodedElement(CIx.TypeDefOrRef,vcIx);
             vClass.MakeValueClass();
             return vClass;
         case ((int)ElementType.Class)   :
             return (Class)GetCodedElement(CIx.TypeDefOrRef,blob.ReadCompressedNum());
         case ((int)ElementType.Array) :
             Type elemType = GetBlobType(); //currClass,currMeth);
             int rank = (int)blob.ReadCompressedNum();
             int numSizes = (int)blob.ReadCompressedNum();
             int[] sizes = null;
             if (numSizes > 0){
                 sizes = new int[numSizes];
                 for (int i=0; i < numSizes; i++)
                     sizes[i] = (int)blob.ReadCompressedNum();
             }
             int numBounds = (int)blob.ReadCompressedNum();
             int[] loBounds = null, hiBounds = null;
             if ((numBounds > 0) && (numSizes > 0)){
                 loBounds = new int[numBounds];
                 hiBounds = new int[numBounds];
                 for (int i=0; i < numBounds; i++) {
                     loBounds[i] = (int)blob.ReadCompressedNum();
                     hiBounds[i] = loBounds[i] + sizes[i] - 1;
                 }
             }
             if (numSizes == 0) return new BoundArray(elemType,rank);
             if (numBounds == 0) return new BoundArray(elemType,rank,sizes);
             return new BoundArray(elemType,rank,loBounds,hiBounds);
         case ((int)ElementType.TypedByRef) :
             return PrimitiveType.TypedRef;
         case ((int)ElementType.I) :
             return PrimitiveType.IntPtr;
         case ((int)ElementType.U) :
             return PrimitiveType.UIntPtr;
         case ((int)ElementType.FnPtr) :
             MethSig mSig = ReadMethSig(null,false);
             return new MethPtrType(mSig);
         case ((int)ElementType.Object) :
             return PrimitiveType.Object;
         case ((int)ElementType.SZArray) :
             return new ZeroBasedArray(GetBlobType()); //currClass,currMeth));
         case ((int)ElementType.CmodReqd) :
         case ((int)ElementType.CmodOpt) :
             Class modType = (Class)GetCodedElement(CIx.TypeDefOrRef,blob.ReadCompressedNum());
             return new CustomModifiedType(GetBlobType(),(CustomModifier)typeIx,modType);
         case ((int)ElementType.Sentinel) :
             return sentinel;
         case ((int)ElementType.Pinned) :
             return pinned;
         case ((int)ElementType.GenericInst) :
             Class instType = (Class)GetBlobType();
             Class scopeSave = currentClassScope;
             if (genInstNestLevel > 0) {
                 currentClassScope = instType;
             }
             genInstNestLevel++;
             ClassSpec newClassSpec = new ClassSpec(instType,GetListOfType());
             genInstNestLevel--;
             if (genInstNestLevel > 0) {
                 currentClassScope = scopeSave;
             }
             return newClassSpec;
         case ((int)ElementType.Var) :
             if (currentClassScope == null) {
                 //Console.WriteLine("GenericParam with currClass == null");
                 return GenericParam.AnonClassPar(blob.ReadCompressedNum());
                 //throw new Exception("No current class set");
             }
             return currentClassScope.GetGenPar(blob.ReadCompressedNum());
         case ((int)ElementType.MVar) :
             if (currentMethodScope == null) {
                 //Console.WriteLine("GenericParam with currMeth == null");
                 return GenericParam.AnonMethPar(blob.ReadCompressedNum());
                 //throw new Exception("No current method set");
             }
             return currentMethodScope.GetGenericParam((int)blob.ReadCompressedNum());
         default: break;
     }
     return null;
 }
Beispiel #10
0
 /// <summary>
 /// Delete a class from this module
 /// </summary>
 /// <param name="aClass">The name of the class to be deleted</param>
 public void RemoveClass(Class aClass)
 {
     classes.Remove(aClass);
 }
Beispiel #11
0
 internal virtual void AddToClassList(Class aClass)
 {
     classes.Add(aClass);
 }
Beispiel #12
0
 internal void ReplaceClass(Class aClass)
 {
     bool found = false;
     for (int i=0; (i < classes.Count) && !found; i++) {
         if (((Class)classes[i]).Name() == aClass.Name()) {
             found = true;
         }
     }
     if (!found)
         classes.Add(aClass);
 }
Beispiel #13
0
 /// <summary>
 /// Add a class to this PE File
 /// </summary>
 /// <param name="attrSet">attributes of this class</param>
 /// <param name="nsName">name space name</param>
 /// <param name="name">class name</param>
 /// <param name="superType">super type of this class (extends)</param>
 /// <returns>a descriptor for this new class</returns>
 public ClassDef AddClass(TypeAttr attrSet, string nsName, string name, Class superType)
 {
     ClassDef aClass = AddClass(attrSet,nsName,name);
     aClass.SuperType = superType;
     return aClass;
 }
Beispiel #14
0
 internal MethSig InstantiateGenTypes(Class classType, Type[] genTypes)
 {
     MethSig newSig = new MethSig(name);
     newSig.callConv = callConv;
     newSig.numPars = numPars;
     newSig.numOptPars = numOptPars;
     newSig.numGenPars = numGenPars;
     newSig.parTypes = ReplaceGenPars(parTypes,classType,genTypes);
     newSig.optParTypes = ReplaceGenPars(optParTypes,classType,genTypes);
     newSig.retType = SubstituteType(retType,classType,genTypes);
     return newSig;
 }
Beispiel #15
0
 internal override void Resolve(PEReader buff)
 {
     buff.currentClassScope = this;
     superType = (Class)buff.GetCodedElement(CIx.TypeDefOrRef,extendsIx);
     if ((superType != null) && superType.isValueType())
         typeIndex = (byte)ElementType.ValueType;
     for (int i=0; fieldIx < fieldEndIx; i++, fieldIx++) {
         FieldDef field = (FieldDef)buff.GetElement(MDTable.Field,fieldIx);
         field.SetParent(this);
         fields.Add(field);
     }
     for (int i=0; methodIx < methodEndIx; i++, methodIx++) {
         MethodDef meth = (MethodDef)buff.GetElement(MDTable.Method,methodIx);
         if (Diag.DiagOn) Console.WriteLine("Adding method " + meth.Name() + " to class " + name);
         meth.SetParent(this);
         methods.Add(meth);
     }
     buff.currentClassScope = null;
 }
Beispiel #16
0
 /// <summary>
 /// Mark this position as the end of the last started block and
 /// make it a catch block.  This catch block is associated with the
 /// specified try block.
 /// </summary>
 /// <param name="exceptType">the exception type to be caught</param>
 /// <param name="tryBlock">the try block associated with this catch block</param>
 public void EndCatchBlock(Class exceptType, TryBlock tryBlock)
 {
     Catch catchBlock = new Catch(exceptType,(CILLabel)blockStack.Pop(), NewCodedLabel());
     tryBlock.AddHandler(catchBlock);
 }
Beispiel #17
0
 /*-------------------- Constructors ---------------------------------*/
 internal ClassSpec(Class clType, Type[] gPars)
 {
     this.typeIndex = GENERICINST;
     genClass = clType;
     genericParams = new ArrayList(gPars);
     tabIx = MDTable.TypeSpec;
     typeIndex = GENERICINST;
     ArrayList classMethods = clType.GetMethodList();
     ArrayList classFields = clType.GetFieldList();
     for (int i=0; i < classMethods.Count; i++) {
         MethSig mSig = ((Method)classMethods[i]).GetSig(); //.InstantiateGenTypes(this,gPars);
         if (mSig != null) {
             MethodRef newMeth = new MethodRef(mSig);
             newMeth.SetParent(this);
             newMeth.GenericParams = ((Method)classMethods[i]).GenericParams;
             methods.Add(newMeth);
         }
     }
     for (int i=0; i < classFields.Count; i++) {
         Type fType = ((Field)classFields[i]).GetFieldType();
         //if ((fType is GenericParam) && (((GenericParam)fType).GetParent() == genClass)) {
         //  fType = gPars[((GenericParam)fType).Index];
         //}
         fields.Add(new FieldRef(this,((Field)classFields[i]).Name(),fType));
     }
 }
Beispiel #18
0
 internal void AddToClassList(Class nClass)
 {
     nestedClasses.Add(nClass);
 }
Beispiel #19
0
 /*-------------------- Constructors ---------------------------------*/
 /// <summary>
 /// Create a new custom modifier for a type
 /// </summary>
 /// <param name="type">the type to be modified</param>
 /// <param name="cmod">the modifier</param>
 /// <param name="cmodType">the type reference to be associated with the type</param>
 public CustomModifiedType(Type type, CustomModifier cmod, Class cmodType)
     : base((byte)cmod)
 {
     this.type = type;
     this.cmodType = cmodType;
 }
Beispiel #20
0
 //uint[] interfaceIndexes;
 //private string[] eventNames, propertyNames, nestedNames;
 //internal string[][] names = new string[numListIx][];
 /*-------------------- Constructors ---------------------------------*/
 internal ClassDef(PEFile scope, TypeAttr attrSet, string nsName, string name)
     : base(nsName,name)
 {
     this.scope = scope;
     superType = MSCorLib.mscorlib.ObjectClass;
     flags = (uint)attrSet;
     tabIx = MDTable.TypeDef;
 }
Beispiel #21
0
 internal override void AddToClassList(Class aClass)
 {
     ((ClassDef)aClass).SetScope((PEFile)this);
     classes.Add(aClass);
 }
Beispiel #22
0
 /// <summary>
 /// Add an interface that is implemented by this class
 /// </summary>
 /// <param name="iFace">the interface that is implemented</param>
 public void AddImplementedInterface(Class iFace)
 {
     interfaces.Add(new InterfaceImpl(this,iFace));
     //metaData.AddToTable(MDTable.InterfaceImpl,new InterfaceImpl(this,iFace));
 }
Beispiel #23
0
 /*-------------------- Constructors ---------------------------------*/
 internal FieldRef(Class paren, string name, Type fType)
     : base(name, fType, paren)
 {
     parent = paren;
 }
Beispiel #24
0
 /// <summary>
 /// Add a nested class to this class
 /// </summary>
 /// <param name="attrSet">attributes for this nested class</param>
 /// <param name="name">nested class name</param>
 /// <param name="sType">super type of this nested class</param>
 /// <returns>a descriptor for this new nested class</returns>
 public NestedClassDef AddNestedClass(TypeAttr attrSet, string name, Class sType)
 {
     NestedClassDef nClass = AddNestedClass(attrSet,name);
     nClass.superType = sType;
     return (nClass);
 }
Beispiel #25
0
 /// <summary>
 /// Remove a constraint from this generic parameter
 /// </summary>
 /// <param name="cType">class type of constraint</param>
 public void RemoveConstraint(Class cType)
 {
     for (int i=0; i < constraints.Count; i++) {
         if (constraints[i] == cType) {
             constraints.RemoveAt(i);
             return;
         }
     }
 }
Beispiel #26
0
 /// <summary>
 /// Get the interfaces implemented by this class
 /// </summary>
 /// <returns>List of implemented interfaces</returns>
 public Class[] GetInterfaces()
 {
     Class[] iFaces = new Class[interfaces.Count];
     for (int i=0; i < iFaces.Length; i++) {
         iFaces[i] = ((InterfaceImpl)interfaces[i]).TheInterface();
     }
     return iFaces;
 }
Beispiel #27
0
 /*-------------------- Constructors ---------------------------------*/
 public GenericParamConstraint(GenericParam parent, Class constraint)
 {
     this.parent = parent;
     this.constraint = constraint;
     tabIx = MDTable.GenericParamConstraint;
 }
Beispiel #28
0
 public override void MakeSpecial()
 {
     special = true;
     superType = null;
     flags = (uint)TypeAttr.Private;
 }
Beispiel #29
0
 internal override void Resolve(PEReader buff)
 {
     theClass = (ClassDef)buff.GetElement(MDTable.TypeDef,classIx);
     theInterface = (Class)buff.GetCodedElement(CIx.TypeDefOrRef,interfacesIndex);
     theClass.AddImplementedInterface(this);
 }
Beispiel #30
0
 /*-------------------- Constructors ---------------------------------*/
 internal Method(string methName, Type rType, Class paren)
     : base(methName,paren)
 {
     sig = new MethSig(methName);
     sig.retType = rType;
 }