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);
            }
示例#4
0
 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")
     });
 }
示例#5
0
文件: Rewriter.cs 项目: xornand/cci
    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;
    }
示例#6
0
 public override void Visit(IRootUnitNamespace ns)
 {
     MarkCommon(ns);
 }
 public virtual void onMetadataElement(IRootUnitNamespace rootUnitNamespace) { }
示例#8
0
 /// <summary>
 /// Traverses the specified root unit namespace.
 /// </summary>
 public virtual void TraverseChildren(IRootUnitNamespace rootUnitNamespace)
 {
     Contract.Requires(rootUnitNamespace != null);
       this.TraverseChildren((IUnitNamespace)rootUnitNamespace);
 }
示例#9
0
 /// <summary>
 /// Performs some computation with the given root unit namespace.
 /// </summary>
 public virtual void Visit(IRootUnitNamespace 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;
 }
示例#13
0
 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);
 }
示例#15
0
 public void Visit(IRootUnitNamespace rootUnitNamespace)
 {
     throw new NotImplementedException();
 }
示例#16
0
 public override void Visit(IRootUnitNamespace rootUnitNamespace) {
   rootUnitNamespace.Unit.Dispatch(this);
 }
示例#17
0
 /// <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);
 {
 }
示例#18
0
 /// <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);
 }
示例#19
0
        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);
        }
示例#20
0
 public void Visit(IRootUnitNamespace rootUnitNamespace)
 {
     this.traverser.Traverse(rootUnitNamespace);
 }
示例#21
0
 public virtual void onMetadataElement(IRootUnitNamespace rootUnitNamespace)
 {
 }
示例#22
0
 /// <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();   }
示例#24
0
 public override void TraverseChildren(IRootUnitNamespace rootUnitNamespace)
 {
     MethodEnter(rootUnitNamespace);
     base.TraverseChildren(rootUnitNamespace);
     MethodExit();
 }
示例#25
0
 /// <summary>
 /// Traverses the specified root unit namespace.
 /// </summary>
 public virtual void TraverseChildren(IRootUnitNamespace rootUnitNamespace)
 {
     this.TraverseChildren((IUnitNamespace)rootUnitNamespace);
 }