Пример #1
0
        /// <summary>
        /// Appends a formatted parameters.
        /// </summary>
        protected virtual void AppendParameter(IParameterTypeInformation param, NameFormattingOptions formattingOptions, StringBuilder sb)
        {
            IParameterDefinition def = param as IParameterDefinition;

            if (def != null && (formattingOptions & NameFormattingOptions.ParameterModifiers) != 0)
            {
                if (def.IsOut)
                {
                    sb.Append("out ");
                }
                else if (def.IsParameterArray)
                {
                    sb.Append("params ");
                }
                else if (def.IsByReference)
                {
                    sb.Append("ref ");
                }
            }
            sb.Append(_typeNameFormatter.GetTypeName(param.Type, formattingOptions));
            if (def != null && (formattingOptions & NameFormattingOptions.ParameterName) != 0)
            {
                sb.Append(" ");
                sb.Append(def.Name.Value);
            }
        }
        // Append "@" to a byref param's type
        protected override void AppendParameter(IParameterTypeInformation param, NameFormattingOptions formattingOptions, StringBuilder sb)
        {
            // HACK: This is to support CCI1 syntax where generic type arguments are not shown for nested types.
            if (param.Type is INestedTypeReference)
            {
                formattingOptions = formattingOptions | NameFormattingOptions.OmitTypeArguments;
            }

            base.AppendParameter(param, (formattingOptions & ~NameFormattingOptions.OmitContainingType), sb);

            if (param.IsByReference)
            {
                sb.Append('@');
            }

            if (param.IsModified)
            {
                int count = 0;
                foreach (ICustomModifier modifier in param.CustomModifiers)
                {
                    count++;
                    //if (count>1)
                    //{ throw new NotImplementedException("Can't create a signature with more than one custom modifier"); }
                    AppendCustomModifier(formattingOptions, sb, modifier);
                }
            }
        }
Пример #3
0
 private bool PassingObligationTo(IMethodReference method, IParameterTypeInformation p)
 {
     switch (method.Name.Value)
     {
     case "Add": return(true);
     }
     return(false);
 }
 public override void Visit(IParameterTypeInformation parameterTypeInformation)
 {
     if (Process(parameterTypeInformation))
     {
         visitor.Visit(parameterTypeInformation);
     }
     base.Visit(parameterTypeInformation);
 }
Пример #5
0
                public override BoogieType GetBoogieType(IParameterTypeInformation var)
                {
                    if (var.IsByReference)
                    {
                        return(BoogieType.Addr);
                    }

                    return(GetBoogieType(var.Type));
                }
Пример #6
0
        public virtual void Visit(IParameterTypeInformation parameterTypeInformation)
        {
            if (parameterTypeInformation.IsModified)
            {
                this.Visit(parameterTypeInformation.CustomModifiers);
            }

            this.Visit(parameterTypeInformation.GetType(Context));
        }
Пример #7
0
    internal LockReplacer(SourceMethodBody sourceMethodBody) {
      Contract.Requires(sourceMethodBody != null);
      this.host = sourceMethodBody.host; Contract.Assume(sourceMethodBody.host != null);
      this.sourceLocationProvider = sourceMethodBody.sourceLocationProvider;
      this.numberOfReferencesToLocal = sourceMethodBody.numberOfReferencesToLocal; Contract.Assume(sourceMethodBody.numberOfReferencesToLocal != null);
      this.numberOfAssignmentsToLocal = sourceMethodBody.numberOfAssignmentsToLocal; Contract.Assume(sourceMethodBody.numberOfAssignmentsToLocal != null);
      this.bindingsThatMakeALastUseOfALocalVersion = sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion; Contract.Assume(sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion != null);
      var systemThreading = new Immutable.NestedUnitNamespaceReference(this.host.PlatformType.SystemObject.ContainingUnitNamespace,
        this.host.NameTable.GetNameFor("Threading"));
      var systemThreadingMonitor = new Immutable.NamespaceTypeReference(this.host, systemThreading, this.host.NameTable.GetNameFor("Monitor"), 0,
        isEnum: false, isValueType: false, typeCode: PrimitiveTypeCode.NotPrimitive);
      var parameters = new IParameterTypeInformation[2];
      this.monitorEnter = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
        this.host.NameTable.GetNameFor("Enter"), 0, parameters);
      parameters[0] = new SimpleParameterTypeInformation(monitorEnter, 0, this.host.PlatformType.SystemObject);
      parameters[1] = new SimpleParameterTypeInformation(monitorEnter, 1, this.host.PlatformType.SystemBoolean, isByReference: true);
      this.monitorExit = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
        this.host.NameTable.GetNameFor("Exit"), 0, this.host.PlatformType.SystemObject);

    }
Пример #8
0
        internal LockReplacer(SourceMethodBody sourceMethodBody)
        {
            Contract.Requires(sourceMethodBody != null);
            this.host = sourceMethodBody.host; Contract.Assume(sourceMethodBody.host != null);
            this.sourceLocationProvider     = sourceMethodBody.sourceLocationProvider;
            this.numberOfReferencesToLocal  = sourceMethodBody.numberOfReferencesToLocal; Contract.Assume(sourceMethodBody.numberOfReferencesToLocal != null);
            this.numberOfAssignmentsToLocal = sourceMethodBody.numberOfAssignmentsToLocal; Contract.Assume(sourceMethodBody.numberOfAssignmentsToLocal != null);
            this.bindingsThatMakeALastUseOfALocalVersion = sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion; Contract.Assume(sourceMethodBody.bindingsThatMakeALastUseOfALocalVersion != null);
            var systemThreading = new Immutable.NestedUnitNamespaceReference(this.host.PlatformType.SystemObject.ContainingUnitNamespace,
                                                                             this.host.NameTable.GetNameFor("Threading"));
            var systemThreadingMonitor = new Immutable.NamespaceTypeReference(this.host, systemThreading, this.host.NameTable.GetNameFor("Monitor"), 0,
                                                                              isEnum: false, isValueType: false, typeCode: PrimitiveTypeCode.NotPrimitive);
            var parameters = new IParameterTypeInformation[2];

            this.monitorEnter = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
                                                    this.host.NameTable.GetNameFor("Enter"), 0, parameters);
            parameters[0]    = new SimpleParameterTypeInformation(monitorEnter, 0, this.host.PlatformType.SystemObject);
            parameters[1]    = new SimpleParameterTypeInformation(monitorEnter, 1, this.host.PlatformType.SystemBoolean, isByReference: true);
            this.monitorExit = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
                                                   this.host.NameTable.GetNameFor("Exit"), 0, this.host.PlatformType.SystemObject);
        }
 public override void TraverseChildren(IParameterTypeInformation parameterTypeInformation) {
   base.TraverseChildren(parameterTypeInformation);
 }
Пример #10
0
 public void Visit(IParameterTypeInformation parameterTypeInformation)
 {
     Contract.Assume(false);
 }
Пример #11
0
 /// <summary>
 /// Traverses the parameter type information.
 /// </summary>
 public void Traverse(IParameterTypeInformation parameterTypeInformation)
 {
     Contract.Requires(parameterTypeInformation != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(parameterTypeInformation);
       if (this.stopTraversal) return;
       this.TraverseChildren(parameterTypeInformation);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(parameterTypeInformation);
 }
Пример #12
0
 public void Visit(IParameterTypeInformation parameterTypeInformation)
 {
     throw new NotImplementedException();
 }
Пример #13
0
    uint GetParameterTypeListInternId(IEnumerator<IParameterTypeInformation> parameterTypeInformations, uint pCount) {
      Contract.Requires(parameterTypeInformations != null);

      if (pCount == 0)
        return 0;

      IParameterTypeInformation[] paras = new IParameterTypeInformation[pCount];
      
      uint i = 0;

      while (parameterTypeInformations.MoveNext())
      {
        Contract.Assume(parameterTypeInformations.Current != null);

        paras[i ++] = parameterTypeInformations.Current;
      }

      //Assert(i == pCount);

      uint tailInternedId = 0;
    
      while (i > 0)
      {
        i --;

        uint currentParameterInternedId = this.GetParameterTypeInternId(paras[i]);

        uint value = this.ParameterTypeListHashtable.Find(currentParameterInternedId, tailInternedId);

        if (value == 0)
        {
          value = this.CurrentParameterTypeListInternValue++;
          this.ParameterTypeListHashtable.Add(currentParameterInternedId, tailInternedId, value);
        }

        tailInternedId = value;
      }

      return tailInternedId;
    }
Пример #14
0
        public override void TraverseChildren(IParameterTypeInformation parameterTypeInformation)
{ MethodEnter(parameterTypeInformation);
            base.TraverseChildren(parameterTypeInformation);
     MethodExit();   }
 /// <summary>
 /// Performs some computation with the given parameter type information.
 /// </summary>
 public virtual void Visit(IParameterTypeInformation parameterTypeInformation)
 {
 }
 /// <summary>
 /// Rewrites the given parameter type information.
 /// </summary>
 public virtual IParameterTypeInformation Rewrite(IParameterTypeInformation parameterTypeInformation)
 {
     return parameterTypeInformation;
 }
Пример #17
0
        /// <summary>
        /// Generates IL for the specified lock statement.
        /// </summary>
        /// <param name="lockStatement">The lock statement.</param>
        public override void TraverseChildren(ILockStatement lockStatement)
        {
            if (this.host.SystemCoreAssemblySymbolicIdentity.Version.Major < 4) {
            this.GenerateDownLevelLockStatement(lockStatement);
            return;
              }
              var systemThreading = new NestedUnitNamespaceReference(this.host.PlatformType.SystemObject.ContainingUnitNamespace,
            this.host.NameTable.GetNameFor("Threading"));
              var systemThreadingMonitor = new NamespaceTypeReference(this.host, systemThreading, this.host.NameTable.GetNameFor("Monitor"), 0,
            isEnum: false, isValueType: false, typeCode: PrimitiveTypeCode.NotPrimitive);
              var parameters = new IParameterTypeInformation[2];
              var monitorEnter = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
            this.host.NameTable.GetNameFor("Enter"), 0, parameters);
              parameters[0] = new SimpleParameterTypeInformation(monitorEnter, 0, this.host.PlatformType.SystemObject);
              parameters[1] = new SimpleParameterTypeInformation(monitorEnter, 1, this.host.PlatformType.SystemBoolean, isByReference: true);
              var monitorExit = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
            this.host.NameTable.GetNameFor("Exit"), 0, this.host.PlatformType.SystemObject);

              this.EmitSequencePoint(lockStatement.Locations);
              var guardObject = new TemporaryVariable(lockStatement.Guard.Type, this.method);
              var lockTaken = new TemporaryVariable(this.host.PlatformType.SystemBoolean, this.method);
              //try
              var savedCurrentTryCatch = this.currentTryCatch;
              this.currentTryCatch = lockStatement;
              var savedCurrentTryCatchFinallyEnd = this.currentTryCatchFinallyEnd;
              this.currentTryCatchFinallyEnd = new ILGeneratorLabel();
              this.generator.BeginTryBody();
              this.Traverse(lockStatement.Guard);
              this.generator.Emit(OperationCode.Dup); this.StackSize++;
              this.VisitAssignmentTo(guardObject);
              this.LoadAddressOf(lockTaken, null);
              this.generator.Emit(OperationCode.Call, monitorEnter);
              this.StackSize-=2;
              this.Traverse(lockStatement.Body);
              if (!this.lastStatementWasUnconditionalTransfer)
            this.generator.Emit(OperationCode.Leave, this.currentTryCatchFinallyEnd);
              //finally
              this.generator.BeginFinallyBlock();
              //if (status)
              var endIf = new ILGeneratorLabel();
              this.LoadLocal(lockTaken);
              this.generator.Emit(OperationCode.Brfalse_S, endIf);
              this.StackSize--;
              this.LoadLocal(guardObject);
              this.generator.Emit(OperationCode.Call, monitorExit);
              this.StackSize--;
              this.generator.MarkLabel(endIf);
              //monitor exit
              this.generator.Emit(OperationCode.Endfinally);
              this.generator.EndTryBody();
              this.generator.MarkLabel(this.currentTryCatchFinallyEnd);
              this.currentTryCatchFinallyEnd = savedCurrentTryCatchFinallyEnd;
              this.currentTryCatch = savedCurrentTryCatch;
              this.lastStatementWasUnconditionalTransfer = false;
        }
Пример #18
0
 public override void Visit(IParameterTypeInformation parameterTypeInformation)
 {
     allElements.Add(new InvokInfo(Traverser, "IParameterTypeInformation", parameterTypeInformation));
 }
Пример #19
0
    uint GetParameterTypeInternId(IParameterTypeInformation parameterTypeInformation) {
      Contract.Requires(parameterTypeInformation != null);

      uint typeReferenceInternId = this.GetTypeReferenceInternId(parameterTypeInformation.Type);
      uint customModifiersInternId = 0;
      if (parameterTypeInformation.IsModified)
        customModifiersInternId = this.GetCustomModifierListInternId(parameterTypeInformation.CustomModifiers.GetEnumerator());
      foreach (ParameterTypeStore parameterTypeStore in this.ParameterTypeHashtable.GetValuesFor(typeReferenceInternId)) {
        if (
          parameterTypeStore.IsByReference == parameterTypeInformation.IsByReference
          && parameterTypeStore.CustomModifiersInternId == customModifiersInternId
        ) {
          return parameterTypeStore.InternedId;
        }
      }
      ParameterTypeStore parameterTypeStore1 = new ParameterTypeStore(parameterTypeInformation.IsByReference, customModifiersInternId, this.CurrentParameterTypeInternValue++);
      this.ParameterTypeHashtable.Add(typeReferenceInternId, parameterTypeStore1);
      return parameterTypeStore1.InternedId;
    }
Пример #20
0
        public bool TryGetParameterReference(CSharpParameter semanticParameter, ushort index, out IParameterTypeInformation cciParameter)
        {
            cciParameter = null;

            #region Check input
            if (semanticParameter == null)
            {
                return(false);
            }
            #endregion
            #region Set up our working cci parameter
            Microsoft.Cci.MutableCodeModel.ParameterTypeInformation workingParameter = null;
            cciParameter = workingParameter = new Microsoft.Cci.MutableCodeModel.ParameterTypeInformation();
            #endregion
            #region Get our parameter type
            ITypeReference paramType;
            if (!TryGetTypeReference(semanticParameter.Type, out paramType))
            {
                goto ReturnFalse;
            }
            workingParameter.Type = paramType;
            #endregion
            #region Get our index
            workingParameter.Index = index;
            #endregion
            #region Get our reference status
            workingParameter.IsByReference = semanticParameter.IsOut || semanticParameter.IsRef;
            #endregion
            #region ReturnTrue:
            //ReturnTrue:
            return(cciParameter != Dummy.ParameterTypeInformation);

            #endregion
            #region ReturnFalse:
ReturnFalse:
            if (semanticParameter.Name != null)
            {
                ContractsPackageAccessor.Current.Logger.WriteToLog("Failed to build parameter reference for: " + semanticParameter.Name.Text);
            }
            return(false);

            #endregion
        }
Пример #21
0
 private MethodInfo GetGenericMethodFrom(IMethodReference methodReference, MemberInfo[] members) {
   MethodInfo result = null;
   var parameterCount = methodReference.ParameterCount;
   var parameters = new IParameterTypeInformation[parameterCount];
   int i = 0; foreach (var par in methodReference.Parameters) parameters[i++] = par;
   var referencedMethodIsStatic = methodReference.IsStatic;
   foreach (var member in members) {
     var method = member as MethodInfo;
     if (method == null || !method.IsGenericMethodDefinition) continue;
     if (methodReference.GenericParameterCount != method.GetGenericArguments().Length) continue;
     if (!this.CallingConventionsMatch(method, methodReference)) continue;
     var mrtype = method.ReturnType;
     if (methodReference.ReturnValueIsByRef) mrtype = mrtype.GetElementType();
     if (!this.TypesMatch(methodReference.Type, mrtype, method)) continue;
     if (methodReference.ReturnValueIsModified) {
       if (!this.ModifiersMatch(method.ReturnParameter.GetOptionalCustomModifiers(), method.ReturnParameter.GetRequiredCustomModifiers(), methodReference.ReturnValueCustomModifiers)) continue;
     }
     var memberParameterInfos = method.GetParameters();
     if (parameterCount != memberParameterInfos.Length) continue;
     bool matched = true;
     for (i = 0; i < parameterCount; i++) {
       var mparInfo = memberParameterInfos[i];
       var mparType = mparInfo.ParameterType;
       var ipar = parameters[i];
       if (ipar.IsByReference) mparType = mparType.GetElementType();
       if (!this.TypesMatch(ipar.Type, mparType, method)) { matched = false; break; }
       if (ipar.IsModified) {
         if (!this.ModifiersMatch(mparInfo.GetOptionalCustomModifiers(), mparInfo.GetRequiredCustomModifiers(), ipar.CustomModifiers)) continue;
       }
     }
     if (!matched) continue;
     result = method;
     break;
   }
   if (result != null)
     this.methodMap.Add(methodReference.InternedKey, result);
   return result;
 }
Пример #22
0
        private MethodInfo GetGenericMethodFrom(IMethodReference methodReference, MemberInfo[] members)
        {
            MethodInfo result         = null;
            var        parameterCount = methodReference.ParameterCount;
            var        parameters     = new IParameterTypeInformation[parameterCount];
            int        i = 0; foreach (var par in methodReference.Parameters)
            {
                parameters[i++] = par;
            }
            var referencedMethodIsStatic = methodReference.IsStatic;

            foreach (var member in members)
            {
                var method = member as MethodInfo;
                if (method == null || !method.IsGenericMethodDefinition)
                {
                    continue;
                }
                if (methodReference.GenericParameterCount != method.GetGenericArguments().Length)
                {
                    continue;
                }
                if (!this.CallingConventionsMatch(method, methodReference))
                {
                    continue;
                }
                var mrtype = method.ReturnType;
                if (methodReference.ReturnValueIsByRef)
                {
                    mrtype = mrtype.GetElementType();
                }
                if (!this.TypesMatch(methodReference.Type, mrtype, method))
                {
                    continue;
                }
                if (methodReference.ReturnValueIsModified)
                {
                    if (!this.ModifiersMatch(method.ReturnParameter.GetOptionalCustomModifiers(), method.ReturnParameter.GetRequiredCustomModifiers(), methodReference.ReturnValueCustomModifiers))
                    {
                        continue;
                    }
                }
                var memberParameterInfos = method.GetParameters();
                if (parameterCount != memberParameterInfos.Length)
                {
                    continue;
                }
                bool matched = true;
                for (i = 0; i < parameterCount; i++)
                {
                    var mparInfo = memberParameterInfos[i];
                    var mparType = mparInfo.ParameterType;
                    var ipar     = parameters[i];
                    if (ipar.IsByReference)
                    {
                        mparType = mparType.GetElementType();
                    }
                    if (!this.TypesMatch(ipar.Type, mparType, method))
                    {
                        matched = false; break;
                    }
                    if (ipar.IsModified)
                    {
                        if (!this.ModifiersMatch(mparInfo.GetOptionalCustomModifiers(), mparInfo.GetRequiredCustomModifiers(), ipar.CustomModifiers))
                        {
                            continue;
                        }
                    }
                }
                if (!matched)
                {
                    continue;
                }
                result = method;
                break;
            }
            if (result != null)
            {
                this.methodMap.Add(methodReference.InternedKey, result);
            }
            return(result);
        }
 public override void Visit(IParameterTypeInformation parameterTypeInformation)
 {
     if(Process(parameterTypeInformation)){visitor.Visit(parameterTypeInformation);}
     base.Visit(parameterTypeInformation);
 }
Пример #24
0
 public virtual void Visit(IParameterTypeInformation parameterTypeInformation)
 {
     this.Visit(parameterTypeInformation.CustomModifiers);
     this.Visit(parameterTypeInformation.GetType(Context));
 }
    public bool TryGetParameterReference(IParameterSymbol semanticParameter, ushort index, out IParameterTypeInformation cciParameter) {

      cciParameter = null;

      #region Check input
      if (semanticParameter == null) {
        return false;
      }
      #endregion
      #region Set up our working cci parameter
      Microsoft.Cci.MutableCodeModel.ParameterTypeInformation workingParameter = null;
      cciParameter = workingParameter = new Microsoft.Cci.MutableCodeModel.ParameterTypeInformation();
      #endregion
      #region Get our parameter type
      ITypeReference paramType;
      if (!TryGetTypeReference(semanticParameter.Type, out paramType))
        goto ReturnFalse;
      workingParameter.Type = paramType;
      #endregion
      #region Get our index
      workingParameter.Index = index;
      #endregion
      #region Get our reference status
      workingParameter.IsByReference = semanticParameter.RefKind == RefKind.Out || semanticParameter.RefKind == RefKind.Ref;
      #endregion
      #region ReturnTrue:
    //ReturnTrue:
      return cciParameter != Dummy.ParameterTypeInformation;
      #endregion
      #region ReturnFalse:
    ReturnFalse:
      if (semanticParameter.Name != null)
      {
        ContractsPackageAccessor.Current.Logger.WriteToLog("Failed to build parameter reference for: " + semanticParameter.Name);
      }
      return false;
      #endregion
    }
Пример #26
0
 protected IParameterTypeInformation[] GetModuleParameterTypeInformations(ISignature signature, int paramCount) {
   var parameterTypes = new IParameterTypeInformation[paramCount];
   for (var index = 0; index < paramCount; index++) {
     bool dummyPinned;
     var customModifiers = this.GetCustomModifiers(out dummyPinned);
     byte currByte = this.SignatureMemoryReader.PeekByte(0);
     if (currByte == ElementType.Sentinel) {
       this.SignatureMemoryReader.SkipBytes(1);
       if (index < paramCount) Array.Resize(ref parameterTypes, index);
       break;
     }
     bool isByReference = false;
     ITypeReference/*?*/ typeReference;
     if (currByte == ElementType.TypedReference) {
       this.SignatureMemoryReader.SkipBytes(1);
       typeReference = this.PEFileToObjectModel.PlatformType.SystemTypedReference;
     } else {
       if (currByte == ElementType.ByReference) {
         this.SignatureMemoryReader.SkipBytes(1);
         isByReference = true;
       }
       typeReference = this.GetTypeReference();
     }
     var parameterType = new ParameterInfo(this.PEFileToObjectModel, index, customModifiers, typeReference, signature, isByReference);
     parameterTypes[index] = parameterType;
   }
   return parameterTypes;
 }
Пример #27
0
        private MethodBase /*?*/ GetMethodFrom(Type containingType, IMethodReference methodReference, MemberInfo[] members)
        {
            //Generic methods need special treatment because their signatures refer to their generic parameters
            //and we can't map those to types unless we can first map the generic method.
            if (methodReference.IsGeneric)
            {
                return(this.GetGenericMethodFrom(methodReference, members));
            }
            MethodBase result           = null;
            var        methodReturnType = this.GetType(methodReference.Type);

            if (methodReturnType == null)
            {
                return(null);
            }
            if (methodReference.ReturnValueIsByRef)
            {
                methodReturnType = methodReturnType.MakeByRefType();
            }
            var parameterCount = methodReference.ParameterCount;
            var parameters     = new IParameterTypeInformation[parameterCount];
            var parameterTypes = parameterCount == 0 ? null : new Type[parameterCount];
            int parameterIndex = 0;

            foreach (var parameter in methodReference.Parameters)
            {
                parameters[parameterIndex] = parameter;
                var ptype = this.GetType(parameter.Type);
                if (ptype == null)
                {
                    return(null);
                }
                if (parameter.IsByReference)
                {
                    ptype = ptype.MakeByRefType();
                }
                parameterTypes[parameterIndex++] = ptype;
            }
            foreach (var member in members)
            {
                var methodBase = member as MethodBase;
                if (methodBase == null || methodBase.IsGenericMethodDefinition)
                {
                    continue;
                }
                if (!this.CallingConventionsMatch(methodBase, methodReference))
                {
                    continue;
                }
                if (methodBase.IsConstructor)
                {
                    if (methodReference.Type.TypeCode != PrimitiveTypeCode.Void)
                    {
                        continue;
                    }
                }
                else
                {
                    var method = (MethodInfo)methodBase;

                    if (!AreEquivalient(containingType, method.ReturnType, methodReturnType))
                    {
                        continue;
                    }
                    if (methodReference.ReturnValueIsModified)
                    {
                        if (!this.ModifiersMatch(method.ReturnParameter.GetOptionalCustomModifiers(), method.ReturnParameter.GetRequiredCustomModifiers(), methodReference.ReturnValueCustomModifiers))
                        {
                            continue;
                        }
                    }
                }
                var memberParameterInfos = methodBase.GetParameters();
                if (parameterCount != memberParameterInfos.Length)
                {
                    continue;
                }
                bool matched = true;
                for (int i = 0; i < parameterCount; i++)
                {
                    var mparInfo = memberParameterInfos[i];
                    var ipar     = parameters[i];
                    var part     = parameterTypes[i];
                    if (!AreEquivalient(containingType, mparInfo.ParameterType, part))
                    {
                        matched = false; break;
                    }
                    if (ipar.IsModified)
                    {
                        if (!this.ModifiersMatch(mparInfo.GetOptionalCustomModifiers(), mparInfo.GetRequiredCustomModifiers(), ipar.CustomModifiers))
                        {
                            continue;
                        }
                    }
                }
                if (!matched)
                {
                    continue;
                }
                result = methodBase;
                break;
            }
            if (result != null)
            {
                this.methodMap.Add(methodReference.InternedKey, result);
            }
            return(result);
        }
Пример #28
0
        private void GenerateDownLevelLockStatement(ILockStatement lockStatement)
        {
            var systemThreading = new NestedUnitNamespaceReference(this.host.PlatformType.SystemObject.ContainingUnitNamespace,
            this.host.NameTable.GetNameFor("Threading"));
              var systemThreadingMonitor = new NamespaceTypeReference(this.host, systemThreading, this.host.NameTable.GetNameFor("Monitor"), 0,
            isEnum: false, isValueType: false, typeCode: PrimitiveTypeCode.NotPrimitive);
              var parameters = new IParameterTypeInformation[2];
              var monitorEnter = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
            this.host.NameTable.GetNameFor("Enter"), 0, this.host.PlatformType.SystemObject);
              var monitorExit = new MethodReference(this.host, systemThreadingMonitor, CallingConvention.Default, this.host.PlatformType.SystemVoid,
            this.host.NameTable.GetNameFor("Exit"), 0, this.host.PlatformType.SystemObject);

              this.EmitSequencePoint(lockStatement.Locations);
              var guardObject = new TemporaryVariable(lockStatement.Guard.Type, this.method);
              this.Traverse(lockStatement.Guard);
              this.generator.Emit(OperationCode.Dup); this.StackSize++;
              this.VisitAssignmentTo(guardObject);
              this.generator.Emit(OperationCode.Call, monitorEnter);
              this.StackSize--;
              //try
              var savedCurrentTryCatch = this.currentTryCatch;
              this.currentTryCatch = lockStatement;
              var savedCurrentTryCatchFinallyEnd = this.currentTryCatchFinallyEnd;
              this.currentTryCatchFinallyEnd = new ILGeneratorLabel();
              this.generator.BeginTryBody();
              this.Traverse(lockStatement.Body);
              if (!this.lastStatementWasUnconditionalTransfer)
            this.generator.Emit(OperationCode.Leave, this.currentTryCatchFinallyEnd);
              //finally
              this.generator.BeginFinallyBlock();
              //if (status)
              this.LoadLocal(guardObject);
              this.generator.Emit(OperationCode.Call, monitorExit);
              this.StackSize--;
              //monitor exit
              this.generator.Emit(OperationCode.Endfinally);
              this.generator.EndTryBody();
              this.generator.MarkLabel(this.currentTryCatchFinallyEnd);
              this.currentTryCatchFinallyEnd = savedCurrentTryCatchFinallyEnd;
              this.currentTryCatch = savedCurrentTryCatch;
              this.lastStatementWasUnconditionalTransfer = false;
        }
Пример #29
0
 public override void Visit(IParameterTypeInformation parameterTypeInformation) {
   parameterTypeInformation.Type.ResolvedType.Dispatch(this);
   if (parameterTypeInformation.IsModified) this.Visit(parameterTypeInformation.CustomModifiers);
   if (parameterTypeInformation.IsByReference) {
     int h = this.hash;
     h = (h << 5 + h) ^ 2;
     this.hash = h;
   }
 }
Пример #30
0
 internal CallByRefAssignment(Instruction original, IParameterTypeInformation p)
 {
     this.original  = original;
     this.Parameter = p;
 }
Пример #31
0
        // Append "@" to a byref param's type
        protected override void AppendParameter(IParameterTypeInformation param, NameFormattingOptions formattingOptions, StringBuilder sb)
        {
            // HACK: This is to support CCI1 syntax where generic type arguments are not shown for nested types.
            if (param.Type is INestedTypeReference) formattingOptions = formattingOptions | NameFormattingOptions.OmitTypeArguments;

            base.AppendParameter(param, (formattingOptions & ~NameFormattingOptions.OmitContainingType), sb);

            if (param.IsByReference) sb.Append('@');

            if (param.IsModified)
            {
                int count = 0;
                foreach (ICustomModifier modifier in param.CustomModifiers)
                {
                    count++;
                    //if (count>1)
                    //{ throw new NotImplementedException("Can't create a signature with more than one custom modifier"); }
                    AppendCustomModifier(formattingOptions, sb, modifier);
                }
            }
        }
Пример #32
0
 public static bool IsBoogieRefType(IParameterTypeInformation var)
 {
     return(IsBoogieRefType(Helpers.GetBoogieType(var)));
 }
Пример #33
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Performs some computation with the given parameter type information.
 /// </summary>
 /// <param name="parameterTypeInformation"></param>
 public virtual void Visit(IParameterTypeInformation parameterTypeInformation)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(parameterTypeInformation);
       if (parameterTypeInformation.IsModified)
     this.Visit(parameterTypeInformation.CustomModifiers);
       this.Visit(parameterTypeInformation.Type);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count.
       this.path.Pop();
 }
Пример #34
0
 public abstract BoogieType GetBoogieType(IParameterTypeInformation var);
Пример #35
0
 /// <summary>
 /// Traverses the children of the parameter type information.
 /// </summary>
 public virtual void TraverseChildren(IParameterTypeInformation parameterTypeInformation)
 {
     Contract.Requires(parameterTypeInformation != null);
       if (parameterTypeInformation.IsModified) {
     this.Traverse(parameterTypeInformation.CustomModifiers);
     if (this.stopTraversal) return;
       }
       this.Traverse(parameterTypeInformation.Type);
 }
Пример #36
0
 public override BoogieType GetBoogieType(IParameterTypeInformation var)
 {
     return(GetBoogieType(var.Type));
 }
Пример #37
0
 /// <summary>
 /// Performs some computation with the given parameter type information.
 /// </summary>
 public void Visit(IParameterTypeInformation parameterTypeInformation)
 {
 }
Пример #38
0
 // if needed we will check if the variable has been referenced
 public static BoogieType GetBoogieType(IParameterTypeInformation var)
 {
     return(BoogieType.GetBoogieTypeTranslator().GetBoogieType(var));
 }
Пример #39
0
 public virtual void onMetadataElement(IParameterTypeInformation parameterTypeInformation) { }
Пример #40
0
 public virtual void onMetadataElement(IParameterTypeInformation parameterTypeInformation)
 {
 }
Пример #41
0
 public override void TraverseChildren(IParameterTypeInformation parameterTypeInformation)
 {
     MethodEnter(parameterTypeInformation);
     base.TraverseChildren(parameterTypeInformation);
     MethodExit();
 }
Пример #42
0
 private MethodBase/*?*/ GetMethodFrom(IMethodReference methodReference, MemberInfo[] members) {
   //Generic methods need special treatment because their signatures refer to their generic parameters
   //and we can't map those to types unless we can first map the generic method. 
   if (methodReference.IsGeneric) return this.GetGenericMethodFrom(methodReference, members);
   MethodBase result = null;
   var methodReturnType = this.GetType(methodReference.Type);
   if (methodReturnType == null) return null;
   if (methodReference.ReturnValueIsByRef) methodReturnType = methodReturnType.MakeByRefType();
   var parameterCount = methodReference.ParameterCount;
   var parameters = new IParameterTypeInformation[parameterCount];
   var parameterTypes = parameterCount == 0 ? null : new Type[parameterCount];
   int parameterIndex = 0;
   foreach (var parameter in methodReference.Parameters) {
     parameters[parameterIndex] = parameter;
     var ptype = this.GetType(parameter.Type);
     if (ptype == null) return null;
     if (parameter.IsByReference) ptype = ptype.MakeByRefType();
     parameterTypes[parameterIndex++] = ptype;
   }
   foreach (var member in members) {
     var methodBase = member as MethodBase;
     if (methodBase == null || methodBase.IsGenericMethodDefinition) continue;
     if (!this.CallingConventionsMatch(methodBase, methodReference)) continue;
     if (methodBase.IsConstructor) {
       if (methodReference.Type.TypeCode != PrimitiveTypeCode.Void) continue;
     } else {
       var method = (MethodInfo)methodBase;
       if (methodReturnType != method.ReturnType) continue;
       if (methodReference.ReturnValueIsModified) {
         if (!this.ModifiersMatch(method.ReturnParameter.GetOptionalCustomModifiers(), method.ReturnParameter.GetRequiredCustomModifiers(), methodReference.ReturnValueCustomModifiers)) continue;
       }
     }
     var memberParameterInfos = methodBase.GetParameters();
     if (parameterCount != memberParameterInfos.Length) continue;
     bool matched = true;
     for (int i = 0; i < parameterCount; i++) {
       var mparInfo = memberParameterInfos[i];
       var ipar = parameters[i];
       var part = parameterTypes[i];
       if (mparInfo.ParameterType != part) { matched = false; break; }
       if (ipar.IsModified) {
         if (!this.ModifiersMatch(mparInfo.GetOptionalCustomModifiers(), mparInfo.GetRequiredCustomModifiers(), ipar.CustomModifiers)) continue;
       }
     }
     if (!matched) continue;
     result = methodBase;
     break;
   }
   if (result != null)
     this.methodMap.Add(methodReference.InternedKey, result);
   return result;
 }