Descriptor for a class/interface declared in another module of THIS assembly, or in another assembly.
Наследование: ClassDesc
Пример #1
0
 internal static MethodRef MethodBodyCtor(ClassRef klass)
 {
     MethodRef ctor = klass.GetMethod(".ctor");
     if (ctor != null)
         return ctor;
     else
     {
         ctor = klass.AddMethod(".ctor", PrimitiveType.Void, new Type[0]);
         ctor.AddCallConv(CallConv.Instance);
         return ctor;
     }
 }
Пример #2
0
 /// <summary>
 /// Add a class to this Scope.  If this class already exists, throw
 /// an exception
 /// </summary>
 /// <param name="newClass">The class to be added</param>
 public void AddClass(ClassRef newClass)
 {
     ClassRef aClass = (ClassRef)GetClass(newClass.NameSpace(),newClass.Name(),true);
     if (aClass != null)
         throw new DescriptorException("Class " + newClass.NameString());
     if (Diag.DiagOn) Console.WriteLine("Adding class " + newClass.Name() + " to ResolutionScope " + name);
     classes.Add(newClass);
     // Change Refs to Defs here
     newClass.SetScope(this);
 }
Пример #3
0
 /*-------------------- Constructors ---------------------------------*/
 internal ReferenceScope(string name)
     : base(name)
 {
     defaultClass = new ClassRef(this,"","");
     defaultClass.MakeSpecial();
 }
Пример #4
0
        //////////////////////////////////////////////////////////////////////////
        // Util
        //////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Find the Type instance for this fully qualified type name.
        /// </summary>
        internal PERWAPI.Type findType(string qname)
        {
            // Always convert voids to native
            if (qname == "Fan.Sys.Void")
            {
                qname = "System.Void";
            }

            PERWAPI.Type type = (PERWAPI.Type)types[qname];
            if (type == null)
            {
                string aname = FanUtil.getPodName(qname);
                if (aname == null)
                {
                    aname = "mscorlib";
                }
                if (qname.StartsWith("Fanx."))
                {
                    aname = "sys";                       // hack for support classes
                }
                if (qname.EndsWith("Peer"))
                {
                    aname += "Native_";                  // TODO
                }
                // first check if this is a type in this pod that
                // hasn't been defined yet
                if (aname == assemblyName)
                {
                    // stub out type - fill get filled in later (we hope)
                    string[] sn   = FanUtil.splitQName(qname);
                    ClassDef stub = null;
                    if (qname.IndexOf("/") != -1)
                    {
                        // Nested class
                        PERWAPI.ClassDef cdef = (PERWAPI.ClassDef)findType(sn[0]);
                        stub = cdef.AddNestedClass(PERWAPI.TypeAttr.NestedPublic, sn[1]);
                    }
                    else
                    {
                        // Normal class
                        stub = peFile.AddClass(PERWAPI.TypeAttr.Public, sn[0], sn[1]);
                    }
                    types[qname] = stub;
                    return(stub);
                }

                AssemblyRef aref = (AssemblyRef)assemblies[aname];
                if (aref == null)
                {
                    aref = peFile.MakeExternAssembly(aname);
                    assemblies[aname] = aref;
                }

                string[] s = FanUtil.splitQName(qname);
                if (qname.IndexOf("/") != -1)
                {
                    // Nested class
                    PERWAPI.ClassRef cref = (PERWAPI.ClassRef)findType(s[0]);
                    type = cref.AddNestedClass(s[1]);
                }

                /*
                 * else if (qname.IndexOf("<") != -1)
                 * {
                 * // Generic type
                 * //if (type == null) type = aref.AddClass(s[0], s[1]);
                 * PERWAPI.ClassRef cref = (PERWAPI.ClassRef)findType(s[0]);
                 * cref.SetGenericParams(new GenericParam[] { cref.GetGenericParam(0) });
                 * type = cref;
                 * }
                 */
                else
                {
                    // Normal class, get/add type
                    type = aref.GetClass(s[0], s[1]);
                    if (type == null)
                    {
                        type = aref.AddClass(s[0], s[1]);
                    }
                }
                types[qname] = type;
            }
            return(type);
        }
Пример #5
0
 internal static ClassRef ReadDef(PEReader buff, ReferenceScope resScope, uint index)
 {
     uint junk = buff.ReadUInt32();
     string cName = buff.GetString();
     string nsName = buff.GetString();
     ClassRef newClass = (ClassRef)resScope.GetExistingClass(nsName,cName);
     if (newClass == null) {
         newClass = new ClassRef(resScope,nsName,cName);
         resScope.AddToClassList(newClass);
     }
     newClass.readAsDef = true;
     newClass.Row = index;
     junk = buff.GetCodedIndex(CIx.TypeDefOrRef);
     newClass.fieldIx = buff.GetIndex(MDTable.Field);
     newClass.methodIx = buff.GetIndex(MDTable.Method);
     return newClass;
 }
Пример #6
0
 internal static void Read(PEReader buff, TableRow[] typeRefs, bool resolve)
 {
     for (uint i=0; i < typeRefs.Length; i++) {
         uint resScopeIx = buff.GetCodedIndex(CIx.ResolutionScope);
         string name = buff.GetString();
         string nameSpace = buff.GetString();
         if (buff.CodedTable(CIx.ResolutionScope,resScopeIx) == MDTable.TypeRef)
             typeRefs[i] = new NestedClassRef(resScopeIx,nameSpace,name);
         else
             typeRefs[i] = new ClassRef(resScopeIx,nameSpace,name);
         typeRefs[i].Row = i+1;
     }
     if (resolve) {
         for (int i=0; i < typeRefs.Length; i++) {
             ((ClassRef)typeRefs[i]).ResolveParent(buff,false);
         }
     }
 }
Пример #7
0
        /// <summary>
        /// Make a ClassRef for this ClassDef
        /// </summary>
        /// <returns>ClassRef equivalent to this ClassDef</returns>
        public virtual ClassRef MakeRefOf()
        {
            if (refOf == null) {
                Assembly assem = scope.GetThisAssembly();
                ReferenceScope scopeRef;
                if (assem != null)
                    scopeRef = assem.MakeRefOf();
                else
                    scopeRef = scope.MakeRefOf();

                refOf = scopeRef.GetClass(name);
                if (refOf == null) {
                    refOf = new ClassRef(scopeRef,nameSpace,name);
                    scopeRef.AddToClassList(refOf);
                }
                refOf.defOf = this;
            }
            return refOf;
        }
Пример #8
0
 internal void SetDefaultClass(ClassRef dClass)
 {
     defaultClass = dClass;
 }
Пример #9
0
 /*------------------------- public set and get methods --------------------------*/
 /// <summary>
 /// Add a class which is declared public in this external module of
 /// THIS assembly.  This class will be exported from this assembly.
 /// The ilasm syntax for this is .extern class
 /// </summary>
 /// <param name="attrSet">attributes of the class to be exported</param>
 /// <param name="nsName">name space name</param>
 /// <param name="name">external class name</param>
 /// <param name="declFile">the file where the class is declared</param>
 /// <param name="isValueClass">is this class a value type?</param>
 /// <returns>a descriptor for this external class</returns>
 public ClassRef AddExternClass(TypeAttr attrSet, string nsName,
     string name, bool isValueClass, PEFile pefile)
 {
     ClassRef cRef = new ClassRef(this,nsName,name);
     if (isValueClass) cRef.MakeValueClass();
     ExternClass eClass = new ExternClass(attrSet,nsName,name,modFile);
     exportedClasses.Add(eClass);
     cRef.SetExternClass(eClass);
     classes.Add(cRef);
     return cRef;
 }
Пример #10
0
 internal static void GetMethodRefs(PEReader buff, uint num, ClassRef parent)
 {
     for (int i=0; i < num; i++) {
         uint rva = buff.ReadUInt32();
         ushort implFlags = buff.ReadUInt16();
         ushort methFlags = buff.ReadUInt16();
         string name = buff.GetString();
         uint sigIx = buff.GetBlobIx();
         uint parIx = buff.GetIndex(MDTable.Param);
         if (IsPublicOrProtected(methFlags)) {
             MethodRef mRef = new MethodRef(parIx,name,sigIx);  // changed
             mRef.SetParent(parent);
             //Console.WriteLine(parent.NameString());
             MethSig mSig = buff.ReadMethSig(mRef,name,sigIx);
             //mSig.name = name;
             mRef.SetSig(mSig); // changed
             parent.AddToMethodList(mRef);
             //if (parent.GetMethod(mSig) == null) {
             //  MethodRef mRef = new MethodRef(mSig);
             //  parent.AddToMethodList(mRef);
             //}
         }
     }
 }
Пример #11
0
 internal EVAL(Scope current, Frame frame, YYLTYPE location): base(current, location)
 {
     this.frame = frame;
     if (frame.current_block != null)
         block_type = CodeGenContext.FindClass(frame.current_block.GetType());
 }
Пример #12
0
        internal static FieldRef AddField(ClassRef classRef, string name, PERWAPI.Type type)
        {
            FieldRef field = classRef.GetField(name);

            if (field == null)
                field = classRef.AddField(name, type);

            return field;
        }
Пример #13
0
        internal static MethodRef AddStaticMethod(ClassRef classRef, string name, PERWAPI.Type retType, PERWAPI.Type[] args)
        {
            MethodRef method = classRef.GetMethod(name, args);

            if (method == null)
                method = classRef.AddMethod(name, retType, args);
            
            return method;
        }
Пример #14
0
        internal static MethodRef AddInstanceMethod(ClassRef classRef, string name, PERWAPI.Type retType, PERWAPI.Type[] args)
        {
            MethodRef method = classRef.GetMethod(name, args);

            if (method == null || method.GetCallConv() != CallConv.Instance)
            {
                method = classRef.AddMethod(name, retType, args);
                method.AddCallConv(CallConv.Instance);
            }
            return method;
        }
Пример #15
0
 /// <summary>
 /// Add a class to this Scope.  If the class already exists,
 /// throw an exception.
 /// </summary>
 /// <param name="nsName">name space name</param>
 /// <param name="name">class name</param>
 /// <returns>a descriptor for this class in another module</returns>
 public virtual ClassRef AddClass(string nsName, string name)
 {
     ClassRef aClass = GetClass(nsName,name);
     if (aClass != null) {
         if ((aClass is SystemClass) && (!((SystemClass)aClass).added))
             ((SystemClass)aClass).added = true;
         else
             throw new DescriptorException("Class " + aClass.NameString());
     } else {
         aClass = new ClassRef(this,nsName,name);
         classes.Add(aClass);
     }
     return aClass;
 }
Пример #16
0
 /*------------------------- internal functions --------------------------*/
 /*    internal void AddMember(Member memb) {
       if (memb is Method) {
         Method existing = GetMethod(memb.Name(),((Method)memb).GetParTypes());
         if (existing == null)
           methods.Add(memb);
       } else {
         Field existing = GetField(memb.Name());
         if (existing == null)
           fields.Add(memb);
       }
     }
     */
 internal void AddToExportedClassList(ClassRef exClass)
 {
     if (exportedClasses.Contains(exClass)) return;
     exportedClasses.Add(exClass);
 }
Пример #17
0
 internal bool isDefaultClass(ClassRef aClass)
 {
     return aClass == defaultClass;
 }
Пример #18
0
 internal MSCorLib()
     : base("mscorlib")
 {
     classes.Add(new SystemClass(this,PrimitiveType.Void));
     classes.Add(new SystemClass(this,PrimitiveType.Boolean));
     classes.Add(new SystemClass(this,PrimitiveType.Char));
     classes.Add(new SystemClass(this,PrimitiveType.Int8));
     classes.Add(new SystemClass(this,PrimitiveType.UInt8));
     classes.Add(new SystemClass(this,PrimitiveType.Int16));
     classes.Add(new SystemClass(this,PrimitiveType.UInt16));
     classes.Add(new SystemClass(this,PrimitiveType.Int32));
     classes.Add(new SystemClass(this,PrimitiveType.UInt32));
     classes.Add(new SystemClass(this,PrimitiveType.Int64));
     classes.Add(new SystemClass(this,PrimitiveType.UInt64));
     classes.Add(new SystemClass(this,PrimitiveType.Float32));
     classes.Add(new SystemClass(this,PrimitiveType.Float64));
     classes.Add(new SystemClass(this,PrimitiveType.IntPtr));
     classes.Add(new SystemClass(this,PrimitiveType.UIntPtr));
     classes.Add(new SystemClass(this,PrimitiveType.String));
     classes.Add(new SystemClass(this,PrimitiveType.TypedRef));
     ObjectClass = new SystemClass(this,PrimitiveType.Object);
     classes.Add(ObjectClass);
     valueType = new ClassRef(this,"System","ValueType");
     valueType.MakeValueClass();
     classes.Add(valueType);
 }
Пример #19
0
 internal static void GetClassRefs(PEReader buff, TableRow[] eClasses)
 {
     for (uint i=0; i < eClasses.Length; i++) {
         uint junk = buff.ReadUInt32();
         junk = buff.ReadUInt32();
         string name = buff.GetString();
         string nameSpace = buff.GetString();
         uint implIx = buff.GetCodedIndex(CIx.Implementation);
         eClasses[i] = new ClassRef(implIx,nameSpace,name);
         eClasses[i].Row = i+1;
     }
 }
Пример #20
0
 /*-------------------- Constructors ---------------------------------*/
 internal NestedClassRef(ClassRef parent, string name)
     : base(parent.GetScope(),"",name)
 {
     this.parent = parent;
 }
Пример #21
0
 internal static void GetClassRefs(PEReader buff, TableRow[] typeRefs, ReferenceScope paren, uint[] parIxs)
 {
     int num = typeRefs.Length;
     uint[] fieldStart = new uint[num+1], methStart = new uint[num+1], extends = new uint[num+1];
     for (int i=0; i < num; i++) {
         uint flags = buff.ReadUInt32();
         string name = buff.GetString();
         string nameSpace = buff.GetString();
         extends[i] = buff.GetCodedIndex(CIx.TypeDefOrRef);
         fieldStart[i] = buff.GetIndex(MDTable.Field);
         methStart[i] = buff.GetIndex(MDTable.Method);
         //Console.WriteLine("flags = " + Hex.Int(flags));
         if (i == 0) // ASSERT first entry is always <Module>
             typeRefs[i] = paren.GetDefaultClass();
         else if (isPublic(flags)) {
             if (parIxs[i] != 0) {
                 typeRefs[i] = new NestedClassRef(paren,nameSpace,name);
             } else {
                 typeRefs[i] = paren.GetExistingClass(nameSpace,name);
                 if (typeRefs[i] == null) {
                     typeRefs[i] = new ClassRef(paren,nameSpace,name);
                     paren.AddToClassList((ClassRef)typeRefs[i]);
                 }
             }
         }
     }
     fieldStart[num] = buff.GetTableSize(MDTable.Field)+1;
     methStart[num] = buff.GetTableSize(MDTable.Method)+1;
     // Find Nested Classes
     for (int i=0; i < typeRefs.Length; i++) {
         if ((typeRefs[i] != null) && (typeRefs[i] is NestedClassRef)) {
             NestedClassRef nRef = (NestedClassRef)typeRefs[i];
             ClassRef nPar = (ClassRef)typeRefs[parIxs[i]-1];
             if (nPar == null) {  // parent is private, so ignore
                 typeRefs[i] = null;
             } else {
                 nRef.SetParent(nPar);
                 nPar.AddToClassList(nRef);
             }
         }
         if (typeRefs[i] != null) {
             if (buff.GetCodedElement(CIx.TypeDefOrRef,extends[i]) == MSCorLib.mscorlib.ValueType())
                 ((ClassRef)typeRefs[i]).MakeValueClass();
             buff.SetElementPosition(MDTable.Field,fieldStart[i]);
             FieldDef.GetFieldRefs(buff,fieldStart[i+1]-fieldStart[i],(ClassRef)typeRefs[i]);
             buff.SetElementPosition(MDTable.Method,methStart[i]);
             MethodDef.GetMethodRefs(buff,methStart[i+1]-methStart[i],(ClassRef)typeRefs[i]);
         }
     }
 }
Пример #22
0
 internal override void ResolveParent(PEReader buff, bool isExtern)
 {
     if (parent != null) return;
     CIx cIx = CIx.ResolutionScope;
     if (isExtern) cIx = CIx.Implementation;
     parent = (ClassRef)buff.GetCodedElement(cIx,resScopeIx);
     parent.ResolveParent(buff,isExtern);
     parent = (ClassRef)buff.GetCodedElement(cIx,resScopeIx);
     if (parent == null) return;
     NestedClassRef existing = parent.GetNestedClass(name);
     if (existing == null) {
         scope = parent.GetScope();
         parent.AddToClassList(this);
     } else if (isExtern)
         buff.InsertInTable(MDTable.ExportedType,Row,existing);
     else
         buff.InsertInTable(MDTable.TypeRef,Row,existing);
 }
Пример #23
0
 internal static ClassRef ReadClass(PEReader buff, ReferenceScope resScope)
 {
     uint resScopeIx = buff.GetCodedIndex(CIx.ResolutionScope);
     string name = buff.GetString();
     string nameSpace = buff.GetString();
     ClassRef newClass = (ClassRef)resScope.GetExistingClass(nameSpace,name);
     if (newClass == null)
         newClass = new ClassRef(resScope,nameSpace,name);
     return newClass;
 }
Пример #24
0
 internal void SetParent(ClassRef paren)
 {
     parent = paren;
 }
Пример #25
0
 internal static void GetFieldRefs(PEReader buff, uint num, ClassRef parent)
 {
     for (int i=0; i < num; i++) {
         uint flags = buff.ReadUInt16();
         string name = buff.GetString();
         uint sigIx = buff.GetBlobIx();
         if ((flags & (uint)FieldAttr.Public) == (uint)FieldAttr.Public) {
             if (parent.GetField(name) == null) {
                 //Console.WriteLine(parent.NameString());
                 buff.currentClassScope = parent;
                 FieldRef fRef = new FieldRef(parent,name,buff.GetFieldType(sigIx));
                 buff.currentClassScope = null;
                 parent.AddToFieldList(fRef);
             }
         }
     }
 }
Пример #26
0
 internal bool HasArg(ClassRef argType) {
     foreach (Type t in Method.GetParTypes())
         if (argType == t)
             return true;
     return false;
 }