void WriteTypeHeader(TypeDefinition type)
        {
            m_writer.Write(".class ");

            if ((type.Attributes & TypeAttributes.ClassSemanticMask) == TypeAttributes.Interface)
            {
                m_writer.Write("interface ");
            }

            int attributes = (int)type.Attributes;

            m_writer.WriteFlags(attributes, (int)TypeAttributes.VisibilityMask,
                                m_typeVisibilityVals, m_typeVisibilityMap);
            m_writer.WriteFlags(attributes, (int)TypeAttributes.LayoutMask,
                                m_typeLayoutVals, m_typeLayoutMap);
            m_writer.WriteFlags(attributes, (int)TypeAttributes.StringFormatMask,
                                m_typeFormatVals, m_typeFormatMap);
            m_writer.WriteFlags(attributes, m_typeVals, m_typeMap);

            m_writer.WriteLine(Formater.Escape(type.Name));

            if (type.BaseType != null)
            {
                m_writer.Indent();
                m_writer.Write("extends ");
                m_writer.WriteLine(Formater.Format(type.BaseType));
                m_writer.Unindent();
            }
        }
Exemple #2
0
        public override void VisitVariableDefinitionCollection(VariableDefinitionCollection variables)
        {
            if (variables.Count == 0)
            {
                return;
            }

            //FIXME: check for 'init' from method header
            m_writer.WriteLine(".locals init (");
            m_writer.Indent();
            for (int i = 0; i < variables.Count; i++)
            {
                VisitVariableDefinition(variables [i]);
                m_writer.WriteLine(i < variables.Count - 1 ? "," : string.Empty);
            }
            m_writer.Unindent();
            m_writer.WriteLine(")");
        }
Exemple #3
0
        //FIXME: Move to ReflectionDisassembler ?
        public void DisassembleMethod(MethodDefinition method, CilWriter writer)
        {
            m_writer = writer;
            //    .method public hidebysig  specialname
            //               instance default class [mscorlib]System.IO.TextWriter get_BaseWriter ()  cil managed
            //

            // write method header
            m_writer.Write(".method ");

            //emit flags
            WriteMethodVisibility(method.Attributes);
            WriteMethodAttributes(method.Attributes);

            m_writer.WriteLine();
            m_writer.Indent();

            if (method.HasThis)
            {
                m_writer.Write("instance ");
            }

            //call convention
            WriteMethodCallingConvention(method.CallingConvention);

            //return type
            //method.ReturnType.ReturnType.Accept (m_reflectDis);
            //FIXME: another visitor for printing names (refs to methoddef/typedef/typeref etc
            m_writer.Write(Formater.Signature(method.ReturnType.ReturnType, false, true));
            m_writer.Write(method.Name);

            //( params )
            m_writer.Write(" (");
            method.Parameters.Accept(m_reflectDis);
            m_writer.Write(") ");
            //cil managed
            WriteMethodCodeType(method.ImplAttributes);
            WriteMethodManagedType(method.ImplAttributes);

            m_writer.Unindent();

            m_writer.OpenBlock();
            m_reflectDis.VisitCustomAttributeCollection(method.CustomAttributes);
            m_reflectDis.VisitSecurityDeclarationCollection(method.SecurityDeclarations);

            if (method.HasBody)
            {
                VisitMethodBody(method.Body);
            }

            m_writer.CloseBlock();
        }
		//FIXME: Move to ReflectionDisassembler ?
		public void DisassembleMethod (MethodDefinition method, CilWriter writer)
		{
			m_writer = writer;
			//    .method public hidebysig  specialname
			//               instance default class [mscorlib]System.IO.TextWriter get_BaseWriter ()  cil managed
			//

			// write method header
			m_writer.Write (".method ");

			//emit flags
			WriteMethodVisibility (method.Attributes);
			WriteMethodAttributes (method.Attributes);

			if(method.IsPInvokeImpl) {
				//Console.Error.WriteLine(method.PInvokeInfo);
				String module = method.PInvokeInfo.Module.Name;
				String symbol = method.PInvokeInfo.EntryPoint;
				m_writer.BaseWriter.Write("(");
				m_writer.BaseWriter.Write(String.Format("\"{0}\" as \"{1}\"", module, symbol));
				m_writer.BaseWriter.Write(")");
			}

			m_writer.WriteLine ();
			m_writer.Indent ();

			if (method.HasThis)
				m_writer.Write ("instance ");

			//call convention
			WriteMethodCallingConvention (method.CallingConvention);

			//return type
			//method.ReturnType.ReturnType.Accept (m_reflectDis);
			//FIXME: another visitor for printing names (refs to methoddef/typedef/typeref etc
			m_writer.Write (Formater.Signature (method.ReturnType.ReturnType, false, !NoAlias));
			m_writer.Write (method.Name);

			//( params )
			m_writer.BaseWriter.Write (" (");
			method.Parameters.Accept (m_reflectDis);
			m_writer.BaseWriter.Write (") ");
			//cil managed
			WriteMethodCodeType (method.ImplAttributes);
			WriteMethodManagedType (method.ImplAttributes);

			m_writer.Unindent ();

			m_writer.OpenBlock ();
			m_reflectDis.VisitCustomAttributeCollection (method.CustomAttributes);
			m_reflectDis.VisitSecurityDeclarationCollection (method.SecurityDeclarations);

			if (method.HasBody)
				VisitMethodBody (method.Body);

			m_writer.CloseBlock ();
		}