Exemplo n.º 1
0
        public IMethodReference Map(IMethodSymbol methodSymbol)
        {
            Contract.Requires(methodSymbol != null);
            IMethodReference mr = null;

            if (!methodSymbolCache.TryGetValue(methodSymbol, out mr))
            {
                List <IParameterTypeInformation> ps = methodSymbol.Parameters.Length == 0 ? null : new List <IParameterTypeInformation>();
                if (methodSymbol.IsGenericMethod && methodSymbol.ConstructedFrom != methodSymbol)
                {
                    var gArgs = new List <ITypeReference>();
                    foreach (var a in methodSymbol.TypeArguments)
                    {
                        gArgs.Add(Map(a));
                    }
                    mr = new Microsoft.Cci.MutableCodeModel.GenericMethodInstanceReference()
                    {
                        CallingConvention     = methodSymbol.IsStatic ? CallingConvention.Default : CallingConvention.HasThis,
                        ContainingType        = Map(methodSymbol.ContainingType),
                        GenericArguments      = gArgs,
                        GenericMethod         = Map(methodSymbol.ConstructedFrom),
                        GenericParameterCount = (ushort)methodSymbol.TypeParameters.Length,
                        InternFactory         = this.host.InternFactory,
                        Name       = this.nameTable.GetNameFor(methodSymbol.Name),
                        Parameters = ps,
                        Type       = Map(methodSymbol.ReturnType),
                    };
                }
                else
                {
                    var m = new Microsoft.Cci.MutableCodeModel.MethodReference();
                    // IMPORTANT: Have to add it to the cache before doing anything else because it may
                    // get looked up if it is generic and a parameter's type involves the generic
                    // method parameter.
                    this.methodSymbolCache.Add(methodSymbol, m);
                    m.CallingConvention = methodSymbol.IsStatic ? CallingConvention.Default : CallingConvention.HasThis;
                    m.ContainingType    = Map(methodSymbol.ContainingType);
                    m.InternFactory     = this.host.InternFactory;
                    m.Name       = this.nameTable.GetNameFor(methodSymbol.Name);
                    m.Parameters = ps;
                    m.Type       = Map(methodSymbol.ReturnType);
                    mr           = m;
                }
                foreach (var p in methodSymbol.Parameters)
                {
                    var p_prime = new ParameterTypeInformation()
                    {
                        ContainingSignature = mr,
                        Index = (ushort)p.Ordinal,
                        Type  = Map(p.Type),
                    };
                    ps.Add(p_prime);
                }
            }
            return(mr);
        }
Exemplo n.º 2
0
 public override void RewriteChildren(Microsoft.Cci.MutableCodeModel.GenericMethodInstanceReference genericMethodInstanceReference)
 {
     base.RewriteChildren(genericMethodInstanceReference);
     if (genericMethodInstanceReference.GenericMethod.Name.Value.EndsWith("<<>>"))
     {
         genericMethodInstanceReference.Name = genericMethodInstanceReference.Name;
         var newArgs = new List <ITypeReference>();
         // add the first generic parameter of the current method.
         foreach (var gmpr in root.GenericParameters)
         {
             newArgs.Add(gmpr);
             break;
         }
         foreach (var arg in ((IGenericMethodInstanceReference)genericMethodInstanceReference).GenericArguments)
         {
             newArgs.Add(arg);
         }
         genericMethodInstanceReference.GenericArguments = newArgs;
     }
 }
Exemplo n.º 3
0
 public IMethodReference Map(R.IMethodSymbol methodSymbol) {
   Contract.Requires(methodSymbol != null);
   IMethodReference mr = null;
   if (!methodSymbolCache.TryGetValue(methodSymbol, out mr)) {
     List<IParameterTypeInformation> ps = methodSymbol.Parameters.Count == 0 ? null : new List<IParameterTypeInformation>();
     if (methodSymbol.IsGenericMethod && methodSymbol.ConstructedFrom != methodSymbol) {
       var gArgs = new List<ITypeReference>();
       foreach (var a in methodSymbol.TypeArguments){
         gArgs.Add(Map(a));
       }
       mr = new Microsoft.Cci.MutableCodeModel.GenericMethodInstanceReference() {
         CallingConvention = methodSymbol.IsStatic ? CallingConvention.Default : CallingConvention.HasThis,
         ContainingType = Map(methodSymbol.ContainingType),
         GenericArguments = gArgs,
         GenericMethod = Map(methodSymbol.ConstructedFrom),
         GenericParameterCount = (ushort) methodSymbol.TypeParameters.Count,
         InternFactory = this.host.InternFactory,
         Name = this.nameTable.GetNameFor(methodSymbol.Name),
         Parameters = ps,
         Type = Map(methodSymbol.ReturnType),
       };
     } else {
       var m = new Microsoft.Cci.MutableCodeModel.MethodReference();
       // IMPORTANT: Have to add it to the cache before doing anything else because it may
       // get looked up if it is generic and a parameter's type involves the generic
       // method parameter.
       this.methodSymbolCache.Add(methodSymbol, m);
       m.CallingConvention = methodSymbol.IsStatic ? CallingConvention.Default : CallingConvention.HasThis;
       m.ContainingType = Map(methodSymbol.ContainingType);
       m.InternFactory = this.host.InternFactory;
       m.Name = this.nameTable.GetNameFor(methodSymbol.Name);
       m.Parameters = ps;
       m.Type = Map(methodSymbol.ReturnType);
       mr = m;
     }
     foreach (var p in methodSymbol.Parameters) {
       var p_prime = new ParameterTypeInformation() {
         ContainingSignature = mr,
         Index = (ushort)p.Ordinal,
         Type = Map(p.Type),
       };
       ps.Add(p_prime);
     }
   }
   return mr;
 }
Exemplo n.º 4
0
      /// <summary>
      /// Converts the return value into a call to Contract.Result
      /// </summary>
      public override IExpression Rewrite(IReturnValue returnValue) {

        var mref = this.contractProvider.ContractMethods.Result;
        var methodToCall = new Microsoft.Cci.MutableCodeModel.GenericMethodInstanceReference() {
          CallingConvention = CallingConvention.Generic,
          ContainingType = mref.ContainingType,
          GenericArguments = new List<ITypeReference> { returnValue.Type },
          GenericMethod = mref,
          InternFactory = this.host.InternFactory,
          Name = mref.Name,
          Type = returnValue.Type,
        };
        var methodCall = new MethodCall() {
          IsStaticCall = true,
          MethodToCall = methodToCall,
          Type = returnValue.Type,
          Locations = new List<ILocation>(returnValue.Locations),
        };
        return methodCall;
      }
Exemplo n.º 5
0
      /// <summary>
      /// Converts the old value into a call to Contract.OldValue
      /// </summary>
      public override IExpression Rewrite(IOldValue oldValue) {

        var mref = this.contractProvider.ContractMethods.Old;
        var methodToCall = new Microsoft.Cci.MutableCodeModel.GenericMethodInstanceReference() {
          CallingConvention = CallingConvention.Generic,
          ContainingType = mref.ContainingType,
          GenericArguments = new List<ITypeReference> { oldValue.Type },
          GenericMethod = mref,
          InternFactory = this.host.InternFactory,
          Name = mref.Name,
          Parameters = new List<IParameterTypeInformation>{
            new ParameterTypeInformation { Type = oldValue.Type, }
          },
          Type = oldValue.Type,
        };
        var methodCall = new MethodCall() {
          Arguments = new List<IExpression> { oldValue.Expression, },
          IsStaticCall = true,
          MethodToCall = methodToCall,
          Type = oldValue.Type,
          Locations = new List<ILocation>(oldValue.Locations),
        };
        return methodCall;
      }