示例#1
0
    public LocalVariableNameReader(MethodInfo m)
    {
        ISymbolReader symReader = SymUtil.GetSymbolReaderForFile(m.DeclaringType.Assembly.Location, null);
        ISymbolMethod met       = symReader.GetMethod(new SymbolToken(m.MetadataToken));

        VisitLocals(met.RootScope);
    }
示例#2
0
        /// <summary>
        /// Load the PDB given the parameters at the ctor and spew it out to the XmlWriter specified
        /// at the ctor.
        /// </summary>
        public void ReadPdbAndWriteToXml()
        {
            // Actually load the files
            ISymbolReader reader = SymUtil.GetSymbolReaderForFile(m_fileName, null);

            m_assembly = System.Reflection.Assembly.ReflectionOnlyLoadFrom(m_fileName);

            // Begin writing XML.
            m_writer.WriteStartDocument();
            m_writer.WriteComment("This is an XML file representing the PDB for '" + m_fileName + "'");
            m_writer.WriteStartElement("symbols");


            // Record what input file these symbols are for.
            m_writer.WriteAttributeString("file", m_fileName);

            WriteDocList(reader);
            WriteEntryPoint(reader);
            WriteAllMethods(reader);

            m_writer.WriteEndElement(); // "Symbols";
        }
示例#3
0
        //------------------------------------------------------------
        // ReflectionUtil.GetConstructedFieldInfo
        //
        /// <summary></summary>
        /// <param name="compiler"></param>
        /// <param name="fieldSym"></param>
        /// <param name="aggTypeSym"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal static FieldInfo GetConstructedFieldInfo(
            COMPILER compiler,
            MEMBVARSYM fieldSym,
            AGGTYPESYM aggTypeSym)
        {
            DebugUtil.Assert(compiler != null && compiler.Emitter != null);
            EMITTER emitter = compiler.Emitter;

            DebugUtil.Assert(emitter != null && fieldSym != null && aggTypeSym != null);

            SymUtil.EmitParentSym(emitter, aggTypeSym);
            SymUtil.GetSystemTypeFromSym(aggTypeSym, null, null);
            emitter.EmitMembVarDef(fieldSym);

            Type      parentType   = aggTypeSym.Type;
            FieldInfo fieldDefInfo = fieldSym.FieldInfo;
            Exception ex           = null;

            if (!parentType.IsGenericType)
            {
                return(fieldDefInfo);
            }

            FieldInfo cstrFieldInfo = null;

            try
            {
                cstrFieldInfo = parentType.GetField(fieldDefInfo.Name);
            }
            catch (NotSupportedException)
            {
                cstrFieldInfo = ReflectionUtil.GetFieldInfo(
                    parentType,
                    fieldDefInfo,
                    out ex);
            }
            return(cstrFieldInfo);
        }
示例#4
0
        //------------------------------------------------------------
        // ReflectionUtil.GetConstructedMethodInfo
        //
        /// <summary></summary>
        /// <param name="compiler"></param>
        /// <param name="methodSym"></param>
        /// <param name="aggTypeSym"></param>
        /// <param name="methTypeArguments"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal static MethodInfo GetConstructedMethodInfo(
            COMPILER compiler,
            METHSYM methodSym,
            AGGTYPESYM aggTypeSym,
            TypeArray methTypeArguments)
        {
            DebugUtil.Assert(compiler != null && compiler.Emitter != null);
            EMITTER emitter = compiler.Emitter;

            DebugUtil.Assert(emitter != null && methodSym != null && aggTypeSym != null);

            SymUtil.EmitParentSym(emitter, aggTypeSym);
            SymUtil.GetSystemTypeFromSym(aggTypeSym, null, null);
            emitter.EmitMethodDef(methodSym);

            Type       parentType    = aggTypeSym.Type;
            MethodInfo methodDefInfo = methodSym.MethodInfo;

            bool isGenericType   = parentType.IsGenericType;
            bool isGenericMethod = methodDefInfo.IsGenericMethod;

            //--------------------------------------------------------
            // (1-1) Non-generic Type, non-generic method
            //--------------------------------------------------------
            if (!isGenericType && !isGenericMethod)
            {
                return(methodDefInfo);
            }

            //--------------------------------------------------------
            // Parameter types
            //--------------------------------------------------------
            TypeArray paramTypeArray  = methodSym.ParameterTypes;
            TypeArray paramTypeArray2 = null;

            Type[] paramTypes = null;

            if (paramTypeArray != null && paramTypeArray.Count > 0)
            {
                paramTypeArray2 = compiler.MainSymbolManager.SubstTypeArray(
                    paramTypeArray,
                    aggTypeSym.AllTypeArguments,
                    methTypeArguments,
                    SubstTypeFlagsEnum.NormNone);

                paramTypes = SymUtil.GetSystemTypesFromTypeArray(
                    paramTypeArray2,
                    methodSym.ClassSym,
                    methodSym);
            }
            else
            {
                paramTypes = Type.EmptyTypes;
            }

            //--------------------------------------------------------
            // (1-2) Non-generic Type, generic method
            //--------------------------------------------------------
            if (!isGenericType)
            {
                DebugUtil.Assert(methTypeArguments != null);

                Exception ex       = null;
                Type[]    typeArgs = SymUtil.GetSystemTypesFromTypeArray(
                    methTypeArguments,
                    methodSym.ClassSym,
                    methodSym);
                return(ReflectionUtil.GetGenericMethod(
                           methodDefInfo,
                           typeArgs,
                           out ex));
            }
            //--------------------------------------------------------
            // (2) Generic Type
            //--------------------------------------------------------
            else
            {
                string     methodName   = methodDefInfo.Name;
                MethodInfo cstrMethInfo = null;
                Exception  ex           = null;

                try
                {
                    cstrMethInfo = parentType.GetMethod(methodName, paramTypes);
                }
                catch (NotSupportedException)
                {
                    cstrMethInfo = GetMethodInfo(parentType, methodDefInfo, out ex);
                }

                if (!isGenericMethod)
                {
                    return(cstrMethInfo);
                }

                DebugUtil.Assert(methTypeArguments != null);
                Type[] typeArgs = SymUtil.GetSystemTypesFromTypeArray(
                    methTypeArguments,
                    methodSym.ClassSym,
                    methodSym);

                return(ReflectionUtil.GetGenericMethod(
                           cstrMethInfo,
                           typeArgs,
                           out ex));
            }
        }
示例#5
0
        //------------------------------------------------------------
        // ReflectionUtil.GetConstructedConstructorInfo
        //
        /// <summary></summary>
        /// <param name="compiler"></param>
        /// <param name="methodSym"></param>
        /// <param name="aggTypeSym"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        internal static ConstructorInfo GetConstructedConstructorInfo(
            COMPILER compiler,
            METHSYM methodSym,
            AGGTYPESYM aggTypeSym)
        {
            DebugUtil.Assert(compiler != null && compiler.Emitter != null);
            EMITTER emitter = compiler.Emitter;

            DebugUtil.Assert(emitter != null && methodSym != null && aggTypeSym != null);

            SymUtil.EmitParentSym(emitter, aggTypeSym);
            SymUtil.GetSystemTypeFromSym(aggTypeSym, null, null);
            emitter.EmitMethodDef(methodSym);

            Type            parentType   = aggTypeSym.Type;
            ConstructorInfo cnstrDefInfo = methodSym.ConstructorInfo;

            DebugUtil.Assert(cnstrDefInfo != null);

            bool isGenericType = parentType.IsGenericType;

            //--------------------------------------------------------
            // (1) Non-generic Type
            //--------------------------------------------------------
            if (!isGenericType)
            {
                return(cnstrDefInfo);
            }

            //--------------------------------------------------------
            // (2) Generic Type
            //--------------------------------------------------------
            TypeArray paramTypeArray  = methodSym.ParameterTypes;
            TypeArray paramTypeArray2 = null;

            Type[] paramTypes = null;

            if (paramTypeArray != null && paramTypeArray.Count > 0)
            {
                paramTypeArray2 = compiler.MainSymbolManager.SubstTypeArray(
                    paramTypeArray,
                    aggTypeSym.AllTypeArguments,
                    null,
                    SubstTypeFlagsEnum.NormNone);

                paramTypes = SymUtil.GetSystemTypesFromTypeArray(
                    paramTypeArray2,
                    methodSym.ClassSym,
                    methodSym);
            }
            else
            {
                paramTypes = Type.EmptyTypes;
            }

            ConstructorInfo constructedInfo = null;
            Exception       ex = null;

            try
            {
                constructedInfo = parentType.GetConstructor(paramTypes);
            }
            catch (NotSupportedException)
            {
                constructedInfo = GetConstructorInfo(parentType, cnstrDefInfo, out ex);
            }
            return(constructedInfo);
        }