public override void Visit(IRootUnitNamespace rootUnitNamespace) { if (Process(rootUnitNamespace)) { visitor.Visit(rootUnitNamespace); } base.Visit(rootUnitNamespace); }
public override void TraverseChildren(IRootUnitNamespace rootUnitNamespace) { if (!_filter.Include(rootUnitNamespace)) { return; } base.TraverseChildren(rootUnitNamespace); }
public override IRootUnitNamespace Rewrite(IRootUnitNamespace root) { var testClass = new NamespaceTypeDefinition { BaseClasses = new List <ITypeReference>(1) { Host.PlatformType.SystemObject }, ContainingUnitNamespace = root, InternFactory = Host.InternFactory, IsClass = true, IsPublic = true, Methods = new List <IMethodDefinition>(1), Name = NameTable.GetNameFor("VisualMutatorGeneratedClass"), }; ((RootUnitNamespace)root).Members.Add(testClass); ((Assembly)Module).AllTypes.Add(testClass); var mainMethod = new MethodDefinition { ContainingTypeDefinition = testClass, InternFactory = Host.InternFactory, IsCil = true, IsStatic = true, Name = NameTable.GetNameFor("FailOnZero"), Type = Host.PlatformType.SystemInt32, Visibility = TypeMemberVisibility.Public, }; mainMethod.Parameters = new List <IParameterDefinition>() { new ParameterDefinition() { Type = Host.PlatformType.SystemInt32, Name = NameTable.GetNameFor("x"), } }; testClass.Methods.Add(mainMethod); var body = new SourceMethodBody(Host) { MethodDefinition = mainMethod, LocalsAreZeroed = true }; mainMethod.Body = body; body.Block = GeneratedBlock; return(root); }
private static NamespaceTypeDefinition CreatePInvokeHelpers(IRootUnitNamespace rootUnitNamespace, IMetadataHost host) { return(new NamespaceTypeDefinition { ContainingUnitNamespace = rootUnitNamespace, IsPublic = false, IsAbstract = true, IsSealed = true, IsBeforeFieldInit = true, BaseClasses = new List <ITypeReference> { host.PlatformType.SystemObject }, Name = host.NameTable.GetNameFor("PInvokeHelpers") }); }
private NamespaceTypeDefinition CreateContractReferenceAssemblyAttribute(IRootUnitNamespace rootNs) { var internFactory = this.host.InternFactory; var nameTable = this.host.NameTable; var contractReferenceAssemblyAttributeName = nameTable.GetNameFor("ContractReferenceAssemblyAttribute"); var contractNamespaceName = nameTable.GetNameFor("System.Diagnostics.Contracts"); #region Define type CustomAttribute compilerGeneratedAttribute = new CustomAttribute() { Constructor = new Microsoft.Cci.MethodReference( this.host, this.compilerGeneratedAttributeType, CallingConvention.HasThis, this.systemVoidType, this.host.NameTable.Ctor, 0) }; var contractsNs = new NestedUnitNamespace() { ContainingUnitNamespace = rootNs, Name = contractNamespaceName, }; NamespaceTypeDefinition result = new NamespaceTypeDefinition() { Name = contractReferenceAssemblyAttributeName, Attributes = new List<ICustomAttribute>{ compilerGeneratedAttribute }, BaseClasses = new List<ITypeReference>{ this.systemAttributeType }, ContainingUnitNamespace = contractsNs, //unitNamespace, InternFactory = internFactory, IsBeforeFieldInit = true, IsClass = true, IsSealed = true, Methods = new List<IMethodDefinition>(), Layout = LayoutKind.Auto, StringFormat = StringFormatKind.Ansi, }; contractsNs.Members.Add(result); this.allTypes.Add(result); #endregion Define type #region Define the ctor List<IStatement> statements = new List<IStatement>(); SourceMethodBody body = new SourceMethodBody(this.host) { LocalsAreZeroed = true, Block = new BlockStatement() { Statements = statements }, }; MethodDefinition ctor = new MethodDefinition() { Body = body, CallingConvention = CallingConvention.HasThis, ContainingTypeDefinition = result, InternFactory = internFactory, IsRuntimeSpecial = true, IsStatic = false, IsSpecialName = true, Name = nameTable.Ctor, Type = this.systemVoidType, Visibility = TypeMemberVisibility.Public, }; body.MethodDefinition = ctor; var thisRef = new ThisReference() { Type = result, }; // base(); foreach (var baseClass in result.BaseClasses) { var baseCtor = new Microsoft.Cci.MutableCodeModel.MethodReference() { CallingConvention = CallingConvention.HasThis, ContainingType = baseClass, GenericParameterCount = 0, InternFactory = this.host.InternFactory, Name = nameTable.Ctor, Type = this.systemVoidType, }; statements.Add( new ExpressionStatement() { Expression = new MethodCall() { MethodToCall = baseCtor, IsStaticCall = false, // REVIEW: Is this needed in addition to setting the ThisArgument? ThisArgument = new ThisReference() { Type = result, }, Type = this.systemVoidType, // REVIEW: Is this the right way to do this? Arguments = new List<IExpression>(), } } ); break; } // return; statements.Add(new ReturnStatement()); result.Methods.Add(ctor); #endregion Define the ctor return result; }
public override void Visit(IRootUnitNamespace ns) { MarkCommon(ns); }
public virtual void onMetadataElement(IRootUnitNamespace rootUnitNamespace) { }
/// <summary> /// Traverses the specified root unit namespace. /// </summary> public virtual void TraverseChildren(IRootUnitNamespace rootUnitNamespace) { Contract.Requires(rootUnitNamespace != null); this.TraverseChildren((IUnitNamespace)rootUnitNamespace); }
/// <summary> /// Performs some computation with the given root unit namespace. /// </summary> public virtual void Visit(IRootUnitNamespace rootUnitNamespace) { }
public override void TraverseChildren(IRootUnitNamespace rootUnitNamespace) { if (!_filter.Include(rootUnitNamespace)) return; base.TraverseChildren(rootUnitNamespace); }
/// <summary> /// Rewrites the given root unit namespace. /// </summary> public virtual IRootUnitNamespace Rewrite(IRootUnitNamespace rootUnitNamespace) { return rootUnitNamespace; }
public override void Visit(IRootUnitNamespace rootUnitNamespace) { allElements.Add(new InvokInfo(Traverser, "IRootUnitNamespace", rootUnitNamespace)); }
public override void Visit(IRootUnitNamespace rootUnitNamespace) { if(Process(rootUnitNamespace)){visitor.Visit(rootUnitNamespace);} base.Visit(rootUnitNamespace); }
public void Visit(IRootUnitNamespace rootUnitNamespace) { throw new NotImplementedException(); }
public override void Visit(IRootUnitNamespace rootUnitNamespace) { rootUnitNamespace.Unit.Dispatch(this); }
/// <summary> /// Performs some computation with the given root unit namespace. /// </summary> /// <param name="rootUnitNamespace"></param> public virtual void Visit(IRootUnitNamespace rootUnitNamespace) //^ ensures this.path.Count == old(this.path.Count); { }
/// <summary> /// Traverses the specified root unit namespace. /// </summary> public void Traverse(IRootUnitNamespace rootUnitNamespace) { Contract.Requires(rootUnitNamespace != null); if (this.preorderVisitor != null) this.preorderVisitor.Visit(rootUnitNamespace); if (this.stopTraversal) return; this.TraverseChildren(rootUnitNamespace); if (this.stopTraversal) return; if (this.postorderVisitor != null) this.postorderVisitor.Visit(rootUnitNamespace); }
private NamespaceTypeDefinition CreateContractReferenceAssemblyAttribute(IRootUnitNamespace rootNs) { var internFactory = this.host.InternFactory; var nameTable = this.host.NameTable; var contractReferenceAssemblyAttributeName = nameTable.GetNameFor("ContractReferenceAssemblyAttribute"); var contractNamespaceName = nameTable.GetNameFor("System.Diagnostics.Contracts"); #region Define type CustomAttribute compilerGeneratedAttribute = new CustomAttribute() { Constructor = new Microsoft.Cci.MethodReference( this.host, this.compilerGeneratedAttributeType, CallingConvention.HasThis, this.systemVoidType, this.host.NameTable.Ctor, 0) }; var contractsNs = new NestedUnitNamespace() { ContainingUnitNamespace = rootNs, Name = contractNamespaceName, }; NamespaceTypeDefinition result = new NamespaceTypeDefinition() { Name = contractReferenceAssemblyAttributeName, Attributes = new List <ICustomAttribute> { compilerGeneratedAttribute }, BaseClasses = new List <ITypeReference> { this.systemAttributeType }, ContainingUnitNamespace = contractsNs, //unitNamespace, InternFactory = internFactory, IsBeforeFieldInit = true, IsClass = true, IsSealed = true, Methods = new List <IMethodDefinition>(), Layout = LayoutKind.Auto, StringFormat = StringFormatKind.Ansi, }; contractsNs.Members.Add(result); this.allTypes.Add(result); #endregion Define type #region Define the ctor List <IStatement> statements = new List <IStatement>(); SourceMethodBody body = new SourceMethodBody(this.host) { LocalsAreZeroed = true, Block = new BlockStatement() { Statements = statements }, }; MethodDefinition ctor = new MethodDefinition() { Body = body, CallingConvention = CallingConvention.HasThis, ContainingTypeDefinition = result, InternFactory = internFactory, IsRuntimeSpecial = true, IsStatic = false, IsSpecialName = true, Name = nameTable.Ctor, Type = this.systemVoidType, Visibility = TypeMemberVisibility.Public, }; body.MethodDefinition = ctor; var thisRef = new ThisReference() { Type = result, }; // base(); foreach (var baseClass in result.BaseClasses) { var baseCtor = new Microsoft.Cci.MutableCodeModel.MethodReference() { CallingConvention = CallingConvention.HasThis, ContainingType = baseClass, GenericParameterCount = 0, InternFactory = this.host.InternFactory, Name = nameTable.Ctor, Type = this.systemVoidType, }; statements.Add( new ExpressionStatement() { Expression = new MethodCall() { MethodToCall = baseCtor, IsStaticCall = false, // REVIEW: Is this needed in addition to setting the ThisArgument? ThisArgument = new ThisReference() { Type = result, }, Type = this.systemVoidType, // REVIEW: Is this the right way to do this? Arguments = new List <IExpression>(), } } ); break; } // return; statements.Add(new ReturnStatement()); result.Methods.Add(ctor); #endregion Define the ctor return(result); }
public void Visit(IRootUnitNamespace rootUnitNamespace) { this.traverser.Traverse(rootUnitNamespace); }
/// <summary> /// Performs some computation with the given root unit namespace. /// </summary> public void Visit(IRootUnitNamespace rootUnitNamespace) { this.Visit((IUnitNamespace)rootUnitNamespace); }
public override void TraverseChildren(IRootUnitNamespace rootUnitNamespace) { MethodEnter(rootUnitNamespace); base.TraverseChildren(rootUnitNamespace); MethodExit(); }
/// <summary> /// Traverses the specified root unit namespace. /// </summary> public virtual void TraverseChildren(IRootUnitNamespace rootUnitNamespace) { this.TraverseChildren((IUnitNamespace)rootUnitNamespace); }