Ejemplo n.º 1
0
    public void AddGenericParameter(MethodDefinition method)
    {
        var oneMoreGP = new List <IGenericMethodParameter>();
        var gp1       = new GenericMethodParameter();

        gp1.Name           = this.host.NameTable.GetNameFor("_SX_");
        gp1.DefiningMethod = method;
        gp1.Index          = 0;
        gp1.InternFactory  = this.host.InternFactory;
        oneMoreGP.Add(gp1);
        if (method.GenericParameterCount > 0)
        {
            foreach (GenericMethodParameter gp in method.GenericParameters)
            {
                gp.Index++;
                oneMoreGP.Add(gp);
            }
        }
        method.GenericParameters = oneMoreGP;
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates either a generic method parameter or a generic type parameter
        /// and adds it to the type symbol cache.
        /// </summary>
        /// <param name="typeSymbol"></param>
        /// <returns></returns>
        private GenericParameter CreateTypeDefinition(ITypeParameterSymbol typeSymbol)
        {
            Contract.Requires(typeSymbol != null);
            Contract.Ensures(Contract.Result <GenericParameter>() != null);

            GenericParameter cciType;

            var containingSymbol = typeSymbol.ContainingSymbol;

            if (containingSymbol is IMethodSymbol)
            {
                cciType = new GenericMethodParameter()
                {
                    DefiningMethod = (IMethodDefinition)this.Map((IMethodSymbol)containingSymbol),
                    Name           = this.host.NameTable.GetNameFor(typeSymbol.Name),
                };
            }
            else
            {
                // assume it is a class parameter?
                cciType = new GenericTypeParameter()
                {
                    DefiningType = (ITypeDefinition)this.Map((ITypeSymbol)containingSymbol),
                    Name         = this.host.NameTable.GetNameFor(typeSymbol.Name),
                };
            }

            var constraints = new List <ITypeReference>();

            foreach (var c in typeSymbol.ConstraintTypes)
            {
                var c2 = this.Map(c);
                constraints.Add(c2);
            }
            cciType.Constraints = constraints;

            this.typeSymbolCache.Add(typeSymbol, cciType);
            return(cciType);
        }
 /// <summary>
 /// Copies the generic parameters from this.method to the given delegate method and fixes up 
 /// the delegate method signature to refer to its own type parameters, rather than those of this.method.
 /// </summary>
 private void MakeDelegateMethodGeneric(MethodDefinition delegateMethod) {
   delegateMethod.CallingConvention |= CallingConvention.Generic;
   var savedGenericMethodParameterMap = this.genericMethodParameterMap;
   this.genericMethodParameterMap = new Dictionary<ushort, IGenericParameterReference>();
   delegateMethod.GenericParameters = new List<IGenericMethodParameter>(this.method.GenericParameterCount);
   foreach (var genericParameter in this.method.GenericParameters) {
     var delPar = new GenericMethodParameter();
     delPar.Copy(genericParameter, this.host.InternFactory);
     delPar.DefiningMethod = delegateMethod;
     delegateMethod.GenericParameters.Add(delPar);
     this.genericMethodParameterMap.Add(genericParameter.Index, delPar);
   }
   new GenericParameterRewriter(this.host, this.genericMethodParameterMap).RewriteChildren(delegateMethod);
   this.genericMethodParameterMap = savedGenericMethodParameterMap;
 }
Ejemplo n.º 4
0
    private IMethodReference CreateThreeArgVersionOfMethod(string originalMethodName, string keyName, ushort genericParameters, bool backwardCompat) {
      MethodBody body = new MethodBody() {
        Operations = new List<IOperation>{ new Operation() { OperationCode = OperationCode.Ret, } },
      };

      MethodDefinition threeArgVersion = new MethodDefinition() {
        Body = body,
        CallingConvention = CallingConvention.Default, // Isn't it the default for the calling convention to be the default?
        ContainingTypeDefinition = this.classHoldingThreeArgVersions,
        GenericParameters = new List<IGenericMethodParameter>(genericParameters),
        Name = backwardCompat ? this.host.NameTable.GetNameFor("Requires") : this.host.NameTable.GetNameFor(originalMethodName),
        Type = this.systemVoidType,
        Visibility = TypeMemberVisibility.Public,
        IsStatic = true,
        InternFactory = this.host.InternFactory, // NB: without this, the method has an interned key of zero, which gets confused with other dummy interned keys!!
      };
      if (genericParameters != 0) {
        threeArgVersion.CallingConvention = CallingConvention.Generic;
        var typeArg = new GenericMethodParameter() {
          Name = this.host.NameTable.GetNameFor("TException"),
          DefiningMethod = threeArgVersion,
          InternFactory = this.host.InternFactory,
        };
        // TODO: add SystemException base type?
        threeArgVersion.GenericParameters.Add(typeArg);
      }
      List<IParameterDefinition> paramList = new List<IParameterDefinition>();
      paramList.Add(
        new ParameterDefinition() {
          ContainingSignature = threeArgVersion,
          Name = this.host.NameTable.GetNameFor("condition"),
          Type = this.systemBooleanType,
          Index = 0,
        });
      paramList.Add(
        new ParameterDefinition() {
          ContainingSignature = threeArgVersion,
          Name = this.host.NameTable.GetNameFor("userSuppliedString"),
          Type = this.systemStringType,
          Index = 1,
        });
      paramList.Add(
        new ParameterDefinition() {
          ContainingSignature = threeArgVersion,
          Name = this.host.NameTable.GetNameFor("sourceText"),
          Type = this.systemStringType,
          Index = 2,
        });
      threeArgVersion.Parameters = paramList;
      body.MethodDefinition = threeArgVersion;
      this.threeArgumentVersionofContractMethod.Add(keyName, threeArgVersion);
      if (this.classHoldingThreeArgVersions.Methods == null) this.classHoldingThreeArgVersions.Methods = new List<IMethodDefinition>(1);
      this.classHoldingThreeArgVersions.Methods.Add(threeArgVersion);

      return threeArgVersion;
    }
Ejemplo n.º 5
0
        private IMethodReference CreateThreeArgVersionOfMethod(string originalMethodName, string keyName, ushort genericParameters, bool backwardCompat)
        {
            MethodBody body = new MethodBody()
            {
                Operations = new List <IOperation> {
                    new Operation()
                    {
                        OperationCode = OperationCode.Ret,
                    }
                },
            };

            MethodDefinition threeArgVersion = new MethodDefinition()
            {
                Body = body,
                CallingConvention        = CallingConvention.Default, // Isn't it the default for the calling convention to be the default?
                ContainingTypeDefinition = this.classHoldingThreeArgVersions,
                GenericParameters        = new List <IGenericMethodParameter>(genericParameters),
                Name          = backwardCompat ? this.host.NameTable.GetNameFor("Requires") : this.host.NameTable.GetNameFor(originalMethodName),
                Type          = this.systemVoidType,
                Visibility    = TypeMemberVisibility.Public,
                IsStatic      = true,
                InternFactory = this.host.InternFactory, // NB: without this, the method has an interned key of zero, which gets confused with other dummy interned keys!!
            };

            if (genericParameters != 0)
            {
                threeArgVersion.CallingConvention = CallingConvention.Generic;
                var typeArg = new GenericMethodParameter()
                {
                    Name           = this.host.NameTable.GetNameFor("TException"),
                    DefiningMethod = threeArgVersion,
                    InternFactory  = this.host.InternFactory,
                };
                // TODO: add SystemException base type?
                threeArgVersion.GenericParameters.Add(typeArg);
            }
            List <IParameterDefinition> paramList = new List <IParameterDefinition>();

            paramList.Add(
                new ParameterDefinition()
            {
                ContainingSignature = threeArgVersion,
                Name  = this.host.NameTable.GetNameFor("condition"),
                Type  = this.systemBooleanType,
                Index = 0,
            });
            paramList.Add(
                new ParameterDefinition()
            {
                ContainingSignature = threeArgVersion,
                Name  = this.host.NameTable.GetNameFor("userSuppliedString"),
                Type  = this.systemStringType,
                Index = 1,
            });
            paramList.Add(
                new ParameterDefinition()
            {
                ContainingSignature = threeArgVersion,
                Name  = this.host.NameTable.GetNameFor("sourceText"),
                Type  = this.systemStringType,
                Index = 2,
            });
            threeArgVersion.Parameters = paramList;
            body.MethodDefinition      = threeArgVersion;
            this.threeArgumentVersionofContractMethod.Add(keyName, threeArgVersion);
            if (this.classHoldingThreeArgVersions.Methods == null)
            {
                this.classHoldingThreeArgVersions.Methods = new List <IMethodDefinition>(1);
            }
            this.classHoldingThreeArgVersions.Methods.Add(threeArgVersion);

            return(threeArgVersion);
        }
Ejemplo n.º 6
0
    /// <summary>
    /// Creates either a generic method parameter or a generic type parameter
    /// and adds it to the type symbol cache.
    /// </summary>
    /// <param name="typeSymbol"></param>
    /// <returns></returns>
    private GenericParameter CreateTypeDefinition(R.ITypeParameterSymbol typeSymbol) {
      Contract.Requires(typeSymbol != null);
      Contract.Ensures(Contract.Result<GenericParameter>() != null);

      GenericParameter cciType;

      var containingSymbol = typeSymbol.ContainingSymbol;
      if (containingSymbol is R.IMethodSymbol) {
        cciType = new GenericMethodParameter() {
          DefiningMethod = (IMethodDefinition)this.Map((R.IMethodSymbol)containingSymbol),
          Name  = this.host.NameTable.GetNameFor(typeSymbol.Name),
        };
      } else {
        // assume it is a class parameter?
        cciType = new GenericTypeParameter() {
          DefiningType = (ITypeDefinition)this.Map((R.ITypeSymbol)containingSymbol),
          Name = this.host.NameTable.GetNameFor(typeSymbol.Name),
        };
      }

      var constraints = new List<ITypeReference>();
      foreach (var c in typeSymbol.ConstraintTypes) {
        var c2 = this.Map(c);
        constraints.Add(c2);

      }
      cciType.Constraints = constraints;

      this.typeSymbolCache.Add(typeSymbol, cciType);
      return cciType;
    }