Ejemplo n.º 1
0
        private void WriteMethodName(IMethodDefinition method)
        {
            if (method.IsConstructor || method.IsStaticConstructor)
            {
                INamedEntity named = method.ContainingTypeDefinition.UnWrap() as INamedEntity;
                if (named != null)
                {
                    WriteIdentifier(named.Name.Value);
                    return;
                }
            }

            if (method.IsExplicitInterfaceMethod())
            {
                IMethodImplementation methodImplementation = method.GetMethodImplementation();
                object nullableAttributeArgument           = methodImplementation.GetExplicitInterfaceMethodNullableAttributeArgument(_metadataReaderCache);
                if (nullableAttributeArgument != null)
                {
                    WriteTypeName(methodImplementation.ImplementedMethod.ContainingType, noSpace: true, nullableAttributeArgument: nullableAttributeArgument);
                    WriteSymbol(".");
                    WriteIdentifier(methodImplementation.ImplementedMethod.Name);
                    return;
                }
            }

            WriteIdentifier(GetNormalizedMethodName(method.Name));
        }
Ejemplo n.º 2
0
 public override void Visit(IMethodImplementation methodImplementation)
 {
     if (Process(methodImplementation))
     {
         visitor.Visit(methodImplementation);
     }
     base.Visit(methodImplementation);
 }
Ejemplo n.º 3
0
        public static object GetExplicitInterfaceMethodNullableAttributeArgument(this IMethodImplementation methodImplementation, SRMetadataPEReaderCache metadataReaderCache)
        {
            if (methodImplementation != null)
            {
                uint   typeToken = ((IMetadataObjectWithToken)methodImplementation.ContainingType).TokenValue;
                string location  = methodImplementation.ContainingType.Locations.FirstOrDefault()?.Document?.Location;
                if (location != null)
                {
                    return(methodImplementation.ImplementedMethod.ContainingType.GetInterfaceImplementationAttributeConstructorArgument(typeToken, location, metadataReaderCache, NullableConstructorArgumentParser));
                }
            }

            return(null);
        }
        private void WritePropertyName(IPropertyDefinition property, IMethodDefinition accessor, bool isSetterAccessor, bool isIndexer)
        {
            if (property.IsExplicitInterfaceProperty())
            {
                IMethodImplementation methodImplementation = accessor.GetMethodImplementation();
                object nullableAttributeArgument           = methodImplementation.GetExplicitInterfaceMethodNullableAttributeArgument(_metadataReaderCache);
                if (nullableAttributeArgument != null)
                {
                    WriteTypeName(methodImplementation.ImplementedMethod.ContainingType, noSpace: true, nullableAttributeArgument: nullableAttributeArgument);
                    WriteSymbol(".");
                    if (isIndexer)
                    {
                        WriteIdentifier("this", false);
                        WriteIndexerParameters(accessor, isSetterAccessor);
                    }
                    else
                    {
                        string name = methodImplementation.ImplementedMethod.Name.Value;
                        WriteIdentifier(name.Substring(name.IndexOf("_") + 1));
                    }

                    return;
                }
            }

            if (isIndexer)
            {
                int index = property.Name.Value.LastIndexOf(".");
                if (index >= 0)
                {
                    WriteIdentifier(property.Name.Value.Substring(0, index + 1) + "this", false); // +1 to include the '.'
                }
                else
                {
                    WriteIdentifier("this", false);
                }

                WriteIndexerParameters(accessor, isSetterAccessor);
            }
            else
            {
                WriteIdentifier(property.Name);
            }
        }
Ejemplo n.º 5
0
        public override List <IMethodImplementation> Rewrite(List <IMethodImplementation> methodImplementations)
        {
            TrimType currentType = CurrentTrimElement as TrimType;

            List <IMethodImplementation> newList = new List <IMethodImplementation>();

            if (methodImplementations == null)
            {
                return(newList);
            }
            foreach (IMethodImplementation methodImpl in methodImplementations)
            {
                IMethodReference implementingMethod        = methodImpl.ImplementingMethod;
                IMethodReference implementedMethod         = methodImpl.ImplementedMethod;
                TrimMember       implementingMemberElement = currentType.GetMemberElementFromMember(implementingMethod);
                TrimMember       implementedMemberElement  = null;

                if (implementingMemberElement != null)
                {
                    ITypeReference implementedType        = Util.CanonicalizeTypeReference(implementedMethod.ContainingType);
                    TrimType       implementedTypeElement = (TrimType)_currentTrimAssembly.GetTypeElement(Util.GetTypeName(implementedType));
                    if (implementedTypeElement != null)
                    {
                        implementedMemberElement = implementedTypeElement.GetMemberElementFromMember(Util.CanonicalizeMethodReference(implementedMethod));
                    }
                }
                else
                {
                }

                if (implementingMemberElement != null && (implementedMemberElement != null ||
                                                          !_includeSet.Assemblies.ContainsKey(Util.GetDefiningAssembly(implementedMethod.ContainingType).Name.Value)))
                {
                    IMethodImplementation newMethodImpl = Rewrite(methodImpl);
                    newList.Add(newMethodImpl);
                }
                //else
                //{ Console.WriteLine("Removing {0}'s impl of {1}", implementingMethod.ToString(), implementedMethod.ToString()); }
            }

            return(newList);
        }
Ejemplo n.º 6
0
Archivo: Tuples.cs Proyecto: s0/ql
 internal static Tuple cil_method_stack_size(IMethodImplementation method, int stackSize) =>
 new Tuple("cil_method_stack_size", method, stackSize);
Ejemplo n.º 7
0
Archivo: Tuples.cs Proyecto: s0/ql
 internal static Tuple cil_method_implementation(IMethodImplementation impl, IMethod method, IAssembly assembly) =>
 new Tuple("cil_method_implementation", impl, method, assembly);
Ejemplo n.º 8
0
Archivo: Tuples.cs Proyecto: s0/ql
 internal static Tuple cil_local_variable(ILocal l, IMethodImplementation m, int i, Type t) =>
 new Tuple("cil_local_variable", l, m, i, t);
Ejemplo n.º 9
0
 //Constructs the form with an instance of IMethodImplementation
 public Form1(IMethodImplementation addImplementation)
 {
     InitializeComponent();
     AddImplementation = addImplementation;
 }
 public override void TraverseChildren(IMethodImplementation methodImplementation) {
   base.TraverseChildren(methodImplementation);
 }
Ejemplo n.º 11
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Performs some computation with the given method implementation.
 /// </summary>
 /// <param name="methodImplementation"></param>
 public virtual void Visit(IMethodImplementation methodImplementation)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(methodImplementation);
       this.Visit(methodImplementation.ImplementedMethod);
       this.Visit(methodImplementation.ImplementingMethod);
       //^ 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();
 }
Ejemplo n.º 12
0
 public void Visit(IMethodImplementation methodImplementation)
 {
     Contract.Assume(false);
 }
Ejemplo n.º 13
0
        public override void TraverseChildren(IMethodImplementation methodImplementation)
{ MethodEnter(methodImplementation);
            base.TraverseChildren(methodImplementation);
     MethodExit();   }
Ejemplo n.º 14
0
 public virtual void onMetadataElement(IMethodImplementation methodImplementation)
 {
 }
Ejemplo n.º 15
0
 public virtual void Visit(IMethodImplementation methodImplementation)
 {
     this.Visit(methodImplementation.ImplementedMethod);
     this.Visit(methodImplementation.ImplementingMethod);
 }
 /// <summary>
 /// Performs some computation with the given method implementation.
 /// </summary>
 public virtual void Visit(IMethodImplementation methodImplementation)
 {
 }
Ejemplo n.º 17
0
 public virtual void Visit(IMethodImplementation methodImplementation)
 {
     this.Visit(methodImplementation.ImplementedMethod);
     this.Visit(methodImplementation.ImplementingMethod);
 }
 /// <summary>
 /// Rewrites the given method implementation.
 /// </summary>
 public virtual IMethodImplementation Rewrite(IMethodImplementation methodImplementation)
 {
     return methodImplementation;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Traverses the method implementation.
 /// </summary>
 public void Traverse(IMethodImplementation methodImplementation)
 {
     Contract.Requires(methodImplementation != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(methodImplementation);
       this.Traverse(methodImplementation.ImplementedMethod);
       if (this.stopTraversal) return;
       this.Traverse(methodImplementation.ImplementingMethod);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(methodImplementation);
 }
Ejemplo n.º 20
0
 public void Visit(IMethodImplementation methodImplementation)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Traverses the children of the method implementation.
 /// </summary>
 public virtual void TraverseChildren(IMethodImplementation methodImplementation)
 {
     Contract.Requires(methodImplementation != null);
       this.Traverse(methodImplementation.ImplementedMethod);
       if (this.stopTraversal) return;
       this.Traverse(methodImplementation.ImplementingMethod);
 }
Ejemplo n.º 22
0
 public override void TraverseChildren(IMethodImplementation methodImplementation)
 {
     MethodEnter(methodImplementation);
     base.TraverseChildren(methodImplementation);
     MethodExit();
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Performs some computation with the given method implementation.
 /// </summary>
 public virtual void Visit(IMethodImplementation methodImplementation)
 {
 }
 public override void Visit(IMethodImplementation methodImplementation)
 {
     if(Process(methodImplementation)){visitor.Visit(methodImplementation);}
     base.Visit(methodImplementation);
 }
Ejemplo n.º 25
0
            /// <summary>
            /// Performs some computation with the given method implementation.
            /// </summary>
            public void Visit(IMethodImplementation methodImplementation)
            {
                if (methodImplementation.ContainingType is Dummy)
                  this.ReportError(MetadataError.IncompleteNode, methodImplementation, "ContainingType");
                if (methodImplementation.ImplementedMethod is Dummy)
                  this.ReportError(MetadataError.IncompleteNode, methodImplementation, "ImplementedMethod");
                if (methodImplementation.ImplementingMethod is Dummy)
                  this.ReportError(MetadataError.IncompleteNode, methodImplementation, "ImplementingMethod");
                var resolvedImplementedMethod = methodImplementation.ImplementedMethod.ResolvedMethod;
                if (resolvedImplementedMethod != Dummy.Method) {
                  if (!resolvedImplementedMethod.IsVirtual || resolvedImplementedMethod.IsSealed || resolvedImplementedMethod.ContainingTypeDefinition.IsSealed)
                this.ReportError(MetadataError.MethodCannotBeAnOverride, resolvedImplementedMethod, methodImplementation);
                  if (resolvedImplementedMethod.IsAccessCheckedOnOverride) {
                switch (resolvedImplementedMethod.Visibility) {
                  case TypeMemberVisibility.Public:
                  case TypeMemberVisibility.Family:
                  case TypeMemberVisibility.FamilyOrAssembly:
                break;
                  case TypeMemberVisibility.Assembly:
                  case TypeMemberVisibility.FamilyAndAssembly:
                var implementedUnit = TypeHelper.GetDefiningUnit(resolvedImplementedMethod.ContainingTypeDefinition);
                if (implementedUnit is Dummy) break; //Complaining might be a false positive. Wait until runtime.
                if (implementedUnit.UnitIdentity.Equals(this.validator.currentModule.ModuleIdentity)) break;
                var implementingAssembly = this.validator.currentModule as IAssembly;
                var implementedAssembly = implementedUnit as IAssembly;
                if (implementingAssembly != null && implementedAssembly != null &&
                  UnitHelper.AssemblyOneAllowsAssemblyTwoToAccessItsInternals(implementedAssembly, implementingAssembly))
                  break;
                goto default;
                  default:
                this.ReportError(MetadataError.MayNotOverrideInaccessibleMethod, resolvedImplementedMethod, methodImplementation);
                break;
                }
                  }
                }
                //check that implemented method is inherited from a base class or interface
                //check for local or inherited implementer
                var resolvedImplementingMethod = methodImplementation.ImplementingMethod.ResolvedMethod;
                if (resolvedImplementedMethod != Dummy.Method) {
                  if (!(resolvedImplementedMethod.IsVirtual || resolvedImplementedMethod.IsAbstract || resolvedImplementedMethod.IsExternal))
                this.ReportError(MetadataError.MethodCannotBeAnOverride, resolvedImplementedMethod, methodImplementation);
                }

                if (methodImplementation.ImplementingMethod.IsGeneric) {
                  if (!MemberHelper.GenericMethodSignaturesAreEqual(methodImplementation.ImplementedMethod, methodImplementation.ImplementingMethod))
                this.ReportError(MetadataError.ExplicitOverrideDoesNotMatchSignatureOfOverriddenMethod, methodImplementation);
                } else {
                  if (!MemberHelper.SignaturesAreEqual(methodImplementation.ImplementedMethod, methodImplementation.ImplementingMethod))
                this.ReportError(MetadataError.ExplicitOverrideDoesNotMatchSignatureOfOverriddenMethod, methodImplementation);
                }
            }
Ejemplo n.º 26
0
Archivo: Tuples.cs Proyecto: s0/ql
 internal static Tuple cil_instruction(IInstruction instruction, int opcode, int index, IMethodImplementation parent) =>
 new Tuple("cil_instruction", instruction, opcode, index, parent);
Ejemplo n.º 27
0
 public virtual void onMetadataElement(IMethodImplementation methodImplementation) { }
Ejemplo n.º 28
0
 public override void Visit(IMethodImplementation methodImplementation)
 {
     allElements.Add(new InvokInfo(Traverser, "IMethodImplementation", methodImplementation));
 }
Ejemplo n.º 29
0
Archivo: Tuples.cs Proyecto: s0/ql
 internal static Tuple cil_handler(IExceptionRegion region, IMethodImplementation method, int index, int kind,
                                   IInstruction region_start,
                                   IInstruction region_end,
                                   IInstruction handler_start) =>
 new Tuple("cil_handler", region, method, index, kind, region_start, region_end, handler_start);
Ejemplo n.º 30
0
 /// <summary>
 /// Traverses the children of the method implementation.
 /// </summary>
 public virtual void TraverseChildren(IMethodImplementation methodImplementation)
 {
     this.Traverse(methodImplementation.ImplementedMethod);
       if (this.stopTraversal) return;
       this.Traverse(methodImplementation.ImplementingMethod);
 }