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)); }
public override void Visit(IMethodImplementation methodImplementation) { if (Process(methodImplementation)) { visitor.Visit(methodImplementation); } base.Visit(methodImplementation); }
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); } }
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); }
internal static Tuple cil_method_stack_size(IMethodImplementation method, int stackSize) => new Tuple("cil_method_stack_size", method, stackSize);
internal static Tuple cil_method_implementation(IMethodImplementation impl, IMethod method, IAssembly assembly) => new Tuple("cil_method_implementation", impl, method, assembly);
internal static Tuple cil_local_variable(ILocal l, IMethodImplementation m, int i, Type t) => new Tuple("cil_local_variable", l, m, i, t);
//Constructs the form with an instance of IMethodImplementation public Form1(IMethodImplementation addImplementation) { InitializeComponent(); AddImplementation = addImplementation; }
public override void TraverseChildren(IMethodImplementation methodImplementation) { base.TraverseChildren(methodImplementation); }
//^ 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(); }
public void Visit(IMethodImplementation methodImplementation) { Contract.Assume(false); }
public override void TraverseChildren(IMethodImplementation methodImplementation) { MethodEnter(methodImplementation); base.TraverseChildren(methodImplementation); MethodExit(); }
public virtual void onMetadataElement(IMethodImplementation methodImplementation) { }
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) { }
/// <summary> /// Rewrites the given method implementation. /// </summary> public virtual IMethodImplementation Rewrite(IMethodImplementation methodImplementation) { return methodImplementation; }
/// <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); }
public void Visit(IMethodImplementation methodImplementation) { throw new NotImplementedException(); }
/// <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); }
public override void Visit(IMethodImplementation methodImplementation) { if(Process(methodImplementation)){visitor.Visit(methodImplementation);} base.Visit(methodImplementation); }
/// <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); } }
internal static Tuple cil_instruction(IInstruction instruction, int opcode, int index, IMethodImplementation parent) => new Tuple("cil_instruction", instruction, opcode, index, parent);
public override void Visit(IMethodImplementation methodImplementation) { allElements.Add(new InvokInfo(Traverser, "IMethodImplementation", methodImplementation)); }
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);
/// <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); }