Esempio n. 1
0
		void EmitPopIfNeeded (EmitContext ec)
		{
			if (add_method.ReturnType == typeof (void))
				return;

			ec.ig.Emit (OpCodes.Pop);
		}
		internal override void Emit (EmitContext ec, LocalBuilder local)
		{
			var member = EmitLoadMember (ec, local);

			foreach (var binding in bindings)
				binding.Emit (ec, member);
		}
Esempio n. 3
0
		internal override void Emit (EmitContext ec, LocalBuilder local)
		{
			var member = EmitLoadMember (ec, local);

			foreach (var initializer in initializers)
				initializer.Emit (ec, member);
		}
Esempio n. 4
0
		internal override void Emit (EmitContext ec)
		{
			ec.EmitIsInst (expression, type_operand);

			ec.ig.Emit (OpCodes.Ldnull);
			ec.ig.Emit (OpCodes.Cgt_Un);
		}
Esempio n. 5
0
 private void EmitPopIfNeeded(EmitContext emitContext)
 {
     if (GetReturnType() == typeof(void) && body.Type != typeof(void))
     {
         emitContext.ig.Emit(OpCodes.Pop);
     }
 }
Esempio n. 6
0
		internal override void Emit (EmitContext ec)
		{
			var ig = ec.ig;
			var type = this.Type;

			LocalBuilder local = null;
			if (type.IsValueType) {
				local = ig.DeclareLocal (type);
				ig.Emit (OpCodes.Ldloca, local);

				if (constructor == null) {
					ig.Emit (OpCodes.Initobj, type);
					ig.Emit (OpCodes.Ldloc, local);
					return;
				}
			}

			ec.EmitCollection (arguments);

			if (type.IsValueType) {
				ig.Emit (OpCodes.Call, constructor);
				ig.Emit (OpCodes.Ldloc, local);
			} else
				ig.Emit (OpCodes.Newobj, constructor ?? GetDefaultConstructor (type));
		}
Esempio n. 7
0
		LocalBuilder EmitLoadField (EmitContext ec, FieldInfo field)
		{
			var store = ec.ig.DeclareLocal (field.FieldType);
			ec.ig.Emit (OpCodes.Ldfld, field);
			ec.ig.Emit (OpCodes.Stloc, store);
			return store;
		}
Esempio n. 8
0
 private void EmitPopIfNeeded(EmitContext emitContext)
 {
     if (_addMethod.ReturnType == typeof(void))
     {
         return;
     }
     emitContext.ig.Emit(OpCodes.Pop);
 }
Esempio n. 9
0
		internal LocalBuilder EmitLoadMember (EmitContext ec, LocalBuilder local)
		{
			ec.EmitLoadSubject (local);

			return member.OnFieldOrProperty<LocalBuilder> (
				field => EmitLoadField (ec, field),
				prop => EmitLoadProperty (ec, prop));
		}
Esempio n. 10
0
		void EmitPropertyAccess (EmitContext ec, PropertyInfo property)
		{
			var getter = property.GetGetMethod (true);
			if (!getter.IsStatic)
				ec.EmitLoadSubject (expression);

			ec.EmitCall (getter);
		}
Esempio n. 11
0
		void EmitFieldAccess (EmitContext ec, FieldInfo field)
		{
			if (!field.IsStatic) {
				ec.EmitLoadSubject (expression);
				ec.ig.Emit (OpCodes.Ldfld, field);
			} else
				ec.ig.Emit (OpCodes.Ldsfld, field);
		}
Esempio n. 12
0
 internal override void Emit(EmitContext emitContext)
 {
     _member.OnFieldOrProperty
     (
         field => EmitFieldAccess(emitContext, field),
         prop => EmitPropertyAccess(emitContext, prop)
     );
 }
Esempio n. 13
0
		void EmitTypeAs (EmitContext ec)
		{
			var type = this.Type;

			ec.EmitIsInst (operand, type);

			if (type.IsNullable ())
				ec.ig.Emit (OpCodes.Unbox_Any, type);
		}
Esempio n. 14
0
 private void EmitPropertyAccess(EmitContext emitContext, PropertyInfo property)
 {
     var getter = property.GetGetMethod(true);
     if (!getter.IsStatic)
     {
         emitContext.EmitLoadSubject(_expression);
     }
     emitContext.EmitCall(getter);
 }
Esempio n. 15
0
 internal LocalBuilder EmitLoadMember(EmitContext emitContext, LocalBuilder local)
 {
     emitContext.EmitLoadSubject(local);
     return _member.OnFieldOrProperty
     (
         field => EmitLoadField(emitContext, field),
         prop => EmitLoadProperty(emitContext, prop)
     );
 }
Esempio n. 16
0
		internal override void Emit (EmitContext ec)
		{
			if (Type.IsNullable ()) {
				EmitNullableConstant (ec, Type, value);
				return;
			}

			EmitConstant (ec, Type, value);
		}
Esempio n. 17
0
		void EmitPropertyAssignment (EmitContext ec, PropertyInfo property, LocalBuilder local)
		{
			var setter = property.GetSetMethod (true);
			if (setter == null)
				throw new InvalidOperationException ();

			ec.EmitLoadSubject (local);
			expression.Emit (ec);
			ec.EmitCall (setter);
		}
Esempio n. 18
0
		void EmitNullableConstant (EmitContext ec, Type type, object value)
		{
			if (value == null) {
				var local = ec.ig.DeclareLocal (type);
				ec.EmitNullableInitialize (local);
			} else {
				EmitConstant (ec, type.GetFirstGenericArgument (), value);
				ec.EmitNullableNew (type);
			}
		}
Esempio n. 19
0
		LocalBuilder EmitLoadProperty (EmitContext ec, PropertyInfo property)
		{
			var getter = property.GetGetMethod (true);
			if (getter == null)
				throw new NotSupportedException ();

			var store = ec.ig.DeclareLocal (property.PropertyType);
			ec.EmitCall (getter);
			ec.ig.Emit (OpCodes.Stloc, store);
			return store;
		}
Esempio n. 20
0
 private void EmitNewArrayBounds(EmitContext emitContext, Type type)
 {
     int rank = _expressions.Count;
     emitContext.EmitCollection(_expressions);
     if (rank == 1)
     {
         emitContext.ig.Emit(OpCodes.Newarr, type);
         return;
     }
     emitContext.ig.Emit(OpCodes.Newobj, GetArrayConstructor(type, rank));
 }
 internal override void Emit(EmitContext emitContext)
 {
     var ig = emitContext.ig;
     if (_expression.Type == typeof(void))
     {
         ig.Emit(OpCodes.Ldc_I4_0);
         return;
     }
     emitContext.EmitIsInst(_expression, _typeOperand);
     ig.Emit(OpCodes.Ldnull);
     ig.Emit(OpCodes.Cgt_Un);
 }
Esempio n. 22
0
 private void EmitHoistedLocal(EmitContext emitContext, int level, int position)
 {
     emitContext.EmitScope();
     for (int i = 0; i < level; i++)
     {
         emitContext.EmitParentScope();
     }
     emitContext.EmitLoadLocals();
     emitContext.ig.Emit(OpCodes.Ldc_I4, position);
     emitContext.ig.Emit(OpCodes.Ldelem, typeof(object));
     emitContext.EmitLoadStrongBoxValue(Type);
 }
Esempio n. 23
0
 private void EmitFieldAccess(EmitContext emitContext, FieldInfo field)
 {
     if (field.IsStatic)
     {
         emitContext.ig.Emit(OpCodes.Ldsfld, field);
     }
     else
     {
         emitContext.EmitLoadSubject(_expression);
         emitContext.ig.Emit(OpCodes.Ldfld, field);
     }
 }
Esempio n. 24
0
		internal override void Emit (EmitContext ec)
		{
			if (expression.Type == typeof (void)) {
				ec.ig.Emit (OpCodes.Ldc_I4_0);
				return;
			}

			ec.EmitIsInst (expression, type_operand);

			ec.ig.Emit (OpCodes.Ldnull);
			ec.ig.Emit (OpCodes.Cgt_Un);
		}
 internal override void Emit(EmitContext emitContext)
 {
     var ig = emitContext.ig;
     var false_target = ig.DefineLabel();
     var end_target = ig.DefineLabel();
     _test.Emit(emitContext);
     ig.Emit(OpCodes.Brfalse, false_target);
     _ifTrue.Emit(emitContext);
     ig.Emit(OpCodes.Br, end_target);
     ig.MarkLabel(false_target);
     _ifFalse.Emit(emitContext);
     ig.MarkLabel(end_target);
 }
Esempio n. 26
0
 private void EmitNewArrayInit(EmitContext emitContext, Type type)
 {
     var size = _expressions.Count;
     emitContext.ig.Emit(OpCodes.Ldc_I4, size);
     emitContext.ig.Emit(OpCodes.Newarr, type);
     for (int i = 0; i < size; i++)
     {
         emitContext.ig.Emit(OpCodes.Dup);
         emitContext.ig.Emit(OpCodes.Ldc_I4, i);
         _expressions[i].Emit(emitContext);
         emitContext.ig.Emit(OpCodes.Stelem, type);
     }
 }
Esempio n. 27
0
		void EmitNullableConstant (EmitContext ec, Type type, object value)
		{
			if (value == null) {
				var ig = ec.ig;
				var local = ig.DeclareLocal (type);
				ig.Emit (OpCodes.Ldloca, local);
				ig.Emit (OpCodes.Initobj, type);
				ig.Emit (OpCodes.Ldloc, local);
			} else {
				EmitConstant (ec, type.GetFirstGenericArgument (), value);
				ec.EmitNullableNew (type);
			}
		}
Esempio n. 28
0
		void EmitNewArrayInit (EmitContext ec, Type type)
		{
			var size = expressions.Count;

			ec.ig.Emit (OpCodes.Ldc_I4, size);
			ec.ig.Emit (OpCodes.Newarr, type);

			for (int i = 0; i < size; i++) {
				ec.ig.Emit (OpCodes.Dup);
				ec.ig.Emit (OpCodes.Ldc_I4, i);
				expressions [i].Emit (ec);
				ec.ig.Emit (OpCodes.Stelem, type);
			}
		}
Esempio n. 29
0
        public override void Emit(EmitContext ec)
        {
            Label is_null_label = ec.DefineLabel ();
            Label end_label = ec.DefineLabel ();

            unwrap.EmitCheck (ec);
            ec.Emit (OpCodes.Brfalse, is_null_label);

            expr.Emit (ec);

            ec.Emit (OpCodes.Br, end_label);
            ec.MarkLabel (is_null_label);

            null_value.Emit (ec);
            ec.MarkLabel (end_label);
        }
Esempio n. 30
0
		internal override void Emit (EmitContext ec)
		{
			int position = -1;
			if (ec.IsLocalParameter (this, ref position)) {
				EmitLocalParameter (ec, position);
				return;
			}

			int level = 0;
			if (ec.IsHoistedLocal (this, ref level, ref position)) {
				EmitHoistedLocal (ec, level, position);
				return;
			}

			throw new InvalidOperationException ("Parameter out of scope");
		}
Esempio n. 31
0
        internal static void GetConsolidatedTypeArguments(this ITypeReference typeReference, ArrayBuilder <ITypeReference> consolidatedTypeArguments, EmitContext context)
        {
            INestedTypeReference nestedTypeReference = typeReference.AsNestedTypeReference;

            nestedTypeReference?.GetContainingType(context).GetConsolidatedTypeArguments(consolidatedTypeArguments, context);

            IGenericTypeInstanceReference genTypeInstance = typeReference.AsGenericTypeInstanceReference;

            if (genTypeInstance != null)
            {
                consolidatedTypeArguments.AddRange(genTypeInstance.GetGenericArguments(context));
            }
        }
Esempio n. 32
0
 /// <summary>
 /// A reference to the constructor that will be used to instantiate this custom attribute during execution (if the attribute is inspected via Reflection).
 /// </summary>
 public Cci.IMethodReference Constructor(EmitContext context)
 => _sourceAttribute.Constructor(context);
Esempio n. 33
0
 public MatchDefsToMetadata(EmitContext sourceContext, PEAssemblySymbol otherAssembly) :
     base(sourceContext)
 {
     _otherAssembly = otherAssembly;
 }
Esempio n. 34
0
 Cci.ITypeReference Cci.ITypeDefinition.GetBaseClass(EmitContext context)
 {
     return(GetBaseClass((TPEModuleBuilder)context.Module, (TSyntaxNode)context.SyntaxNodeOpt, context.Diagnostics));
 }
Esempio n. 35
0
        public override IEnumerable <Cci.INamespaceTypeDefinition> GetTopLevelTypeDefinitions(EmitContext context)
        {
            Cci.TypeReferenceIndexer typeReferenceIndexer = null;
            HashSet <string>         names;

            // First time through, we need to collect emitted names of all top level types.
            if (_namesOfTopLevelTypes == null)
            {
                names = new HashSet <string>();
            }
            else
            {
                names = null;
            }

            // First time through, we need to push things through TypeReferenceIndexer
            // to make sure we collect all to be embedded NoPia types and members.
            if (EmbeddedTypesManagerOpt != null && !EmbeddedTypesManagerOpt.IsFrozen)
            {
                typeReferenceIndexer = new Cci.TypeReferenceIndexer(context);
                Debug.Assert(names != null);

                // Run this reference indexer on the assembly- and module-level attributes first.
                // We'll run it on all other types below.
                // The purpose is to trigger Translate on all types.
                Dispatch(typeReferenceIndexer);
            }

            AddTopLevelType(names, RootModuleType);
            VisitTopLevelType(typeReferenceIndexer, RootModuleType);
            yield return(RootModuleType);

            foreach (var typeDef in GetAnonymousTypeDefinitions(context))
            {
                AddTopLevelType(names, typeDef);
                VisitTopLevelType(typeReferenceIndexer, typeDef);
                yield return(typeDef);
            }

            foreach (var typeDef in GetTopLevelTypeDefinitionsCore(context))
            {
                AddTopLevelType(names, typeDef);
                VisitTopLevelType(typeReferenceIndexer, typeDef);
                yield return(typeDef);
            }

            var privateImpl = PrivateImplClass;

            if (privateImpl != null)
            {
                AddTopLevelType(names, privateImpl);
                VisitTopLevelType(typeReferenceIndexer, privateImpl);
                yield return(privateImpl);
            }

            if (EmbeddedTypesManagerOpt != null)
            {
                foreach (var embedded in EmbeddedTypesManagerOpt.GetTypes(context.Diagnostics, names))
                {
                    AddTopLevelType(names, embedded);
                    yield return(embedded);
                }
            }

            if (names != null)
            {
                Debug.Assert(_namesOfTopLevelTypes == null);
                _namesOfTopLevelTypes = names;
            }
        }
Esempio n. 36
0
 Cci.INamespaceTypeDefinition Cci.ITypeReference.AsNamespaceTypeDefinition(EmitContext context)
 {
     return(this);
 }
Esempio n. 37
0
 IEnumerable <Cci.TypeReferenceWithAttributes> Cci.ITypeDefinition.Interfaces(EmitContext context)
 {
     return(GetInterfaces(context));
 }
Esempio n. 38
0
 Cci.ITypeDefinition Cci.ITypeReference.GetResolvedType(EmitContext context)
 {
     return(null);
 }
Esempio n. 39
0
 Cci.IUnitReference Cci.INamespaceTypeReference.GetUnit(EmitContext context)
 {
     return(TypeManager.ModuleBeingBuilt);
 }
Esempio n. 40
0
 Cci.IMethodDefinition Cci.IMethodReference.GetResolvedMethod(EmitContext context)
 {
     return(ResolvedMethodImpl(context));
 }
Esempio n. 41
0
        internal static ITypeReference GetUninstantiatedGenericType(this ITypeReference typeReference, EmitContext context)
        {
            IGenericTypeInstanceReference genericTypeInstanceReference = typeReference.AsGenericTypeInstanceReference;

            if (genericTypeInstanceReference != null)
            {
                return(genericTypeInstanceReference.GetGenericType(context));
            }

            ISpecializedNestedTypeReference specializedNestedType = typeReference.AsSpecializedNestedTypeReference;

            if (specializedNestedType != null)
            {
                return(specializedNestedType.GetUnspecializedVersion(context));
            }

            return(typeReference);
        }
Esempio n. 42
0
        IEnumerable <Cci.ITypeReference> Cci.IGenericMethodInstanceReference.GetGenericArguments(EmitContext context)
        {
            PEModuleBuilder moduleBeingBuilt = (PEModuleBuilder)context.Module;

            Debug.Assert(((Cci.IMethodReference) this).AsGenericMethodInstanceReference != null);

            foreach (var arg in this.TypeArguments)
            {
                yield return(moduleBeingBuilt.Translate(arg,
                                                        syntaxNodeOpt: context.SyntaxNodeOpt,
                                                        diagnostics: context.Diagnostics));
            }

            yield break;
        }
Esempio n. 43
0
 Cci.IMethodBody Cci.IMethodDefinition.GetBody(EmitContext context)
 {
     CheckDefinitionInvariant();
     return(((PEModuleBuilder)context.Module).GetMethodBody(this));
 }
Esempio n. 44
0
 public override IEnumerable <Cci.IFileReference> GetFiles(EmitContext context) => SpecializedCollections.EmptyEnumerable <Cci.IFileReference>();
Esempio n. 45
0
 public override CType GetEvaluatedCType(EmitContext ec)
 {
     return(Left.GetEvaluatedCType(ec));
 }
Esempio n. 46
0
 public virtual System.Reflection.MethodImplAttributes GetImplementationAttributes(EmitContext context)
 {
     CheckDefinitionInvariant();
     return(this.ImplementationAttributes);
 }
Esempio n. 47
0
 Cci.IDefinition Cci.IReference.AsDefinition(EmitContext context)
 {
     return(null);
 }
 public MetadataVisitor(EmitContext context)
 {
     this.Context = context;
 }
Esempio n. 49
0
 protected abstract IEnumerable <Cci.TypeReferenceWithAttributes> GetInterfaces(EmitContext context);
Esempio n. 50
0
 Cci.ITypeReference Cci.ICustomModifier.GetModifier(EmitContext context)
 {
     return(((PEModuleBuilder)context.Module).Translate(this.Modifier, (CSharpSyntaxNode)context.SyntaxNodeOpt, context.Diagnostics));
 }
Esempio n. 51
0
 IEnumerable <Cci.INestedTypeDefinition> Cci.ITypeDefinition.GetNestedTypes(EmitContext context)
 {
     return(SpecializedCollections.EmptyEnumerable <Cci.INestedTypeDefinition>());
 }
 Cci.IMethodReference Cci.IGenericMethodInstanceReference.GetGenericMethod(EmitContext context)
 {
     return(_genericMethod);
 }
Esempio n. 53
0
 IEnumerable <Cci.MethodImplementation> Cci.ITypeDefinition.GetExplicitImplementationOverrides(EmitContext context)
 {
     return(SpecializedCollections.EmptyEnumerable <Cci.MethodImplementation>());
 }
        IEnumerable <Cci.ITypeReference> Cci.IGenericMethodInstanceReference.GetGenericArguments(EmitContext context)
        {
            PEModuleBuilder moduleBeingBuilt = (PEModuleBuilder)context.Module;

            foreach (var arg in UnderlyingMethod.TypeArgumentsWithAnnotations)
            {
                Debug.Assert(arg.CustomModifiers.IsEmpty);
                yield return(moduleBeingBuilt.Translate(arg.Type, syntaxNodeOpt: (CSharpSyntaxNode)context.SyntaxNodeOpt, diagnostics: context.Diagnostics));
            }
        }
Esempio n. 55
0
 public DeletedMethodBody(DeletedMethodDefinition methodDef, EmitContext context)
 {
     _methodDef = methodDef;
     _ilBytes   = GetIL(context);
 }
Esempio n. 56
0
 internal override IEnumerable <Cci.INamespaceTypeDefinition> GetTopLevelTypesCore(EmitContext context)
 {
     return(_changes.GetTopLevelTypes(context));
 }
Esempio n. 57
0
        public sealed override Cci.ITypeReference GetPlatformType(Cci.PlatformType platformType, EmitContext context)
        {
            Debug.Assert((object)this == context.Module);

            switch (platformType)
            {
            case Cci.PlatformType.SystemType:
                return(GetSystemType((TSyntaxNode)context.SyntaxNodeOpt, context.Diagnostics));

            default:
                return(GetSpecialType((SpecialType)platformType, (TSyntaxNode)context.SyntaxNodeOpt, context.Diagnostics));
            }
        }
Esempio n. 58
0
 Cci.ITypeDefinition Cci.ITypeReference.AsTypeDefinition(EmitContext context)
 {
     return(null);
 }
Esempio n. 59
0
 public MatchDefs(EmitContext sourceContext)
 {
     _sourceContext = sourceContext;
     _matches       = new ConcurrentDictionary <Cci.IDefinition, Cci.IDefinition>(ReferenceEqualityComparer.Instance);
 }
Esempio n. 60
0
 Cci.IDefinition Cci.IReference.AsDefinition(EmitContext context)
 {
     return(ResolvedMethodImpl(context));
 }