• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Compiler.Statement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Compiler.Statement的典型用法代码示例。如果您正苦于以下问题:C# Statement类的具体用法?C# Statement怎么用?C# Statement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Statement类属于System.Compiler命名空间,在下文中一共展示了Statement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: VisitStatement

 protected override IDataFlowState VisitStatement(CfgBlock block, Statement statement, IDataFlowState dfstate) {
   // For debug purpose
   try{
     Analyzer.WriteLine(new SampleInstructionVisitor().Visit(statement,null)+"   :::   " +statement.SourceContext.SourceText);
   }catch(Exception){
     Analyzer.WriteLine("Print error: "+statement);
   }
   IDataFlowState result=null;
   try{
     result =(IDataFlowState)(iVisitor.Visit(statement,dfstate));
   }catch(ModifiesException e){
     typeSystem.HandleError(statement,System.Compiler.Error.Warning,":"+e.Message);
   }catch(Exception e){
     typeSystem.HandleError(statement,System.Compiler.Error.Warning,":CFG1:"+e.Message);
   }
   Analyzer.WriteLine(dfstate);
   return dfstate;
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:18,代码来源:ModifyAnalysis.cs


示例2: GenerateForLoop

        internal static Statement GenerateForLoop(Variable loopVariable, Expression lowerBound, Expression upperBound, Statement body)
        {
            Block bodyAsBlock = body as Block ?? new Block(new StatementList(body));
            Block init = new Block(new StatementList(2));
            Block increment = new Block(new StatementList(1));
            Block test = new Block(new StatementList(new Branch(
              new BinaryExpression(loopVariable, upperBound, NodeType.Lt), bodyAsBlock))); //, false, true, false)));

            init.Statements.Add(new AssignmentStatement(loopVariable, lowerBound));
            init.Statements.Add(new Branch(null, test));

            increment.Statements.Add(new AssignmentStatement(loopVariable, new BinaryExpression(loopVariable, Literal.Int32One, NodeType.Add)));

            Block forLoop = new Block(new StatementList(4));
            forLoop.Statements.Add(init);
            forLoop.Statements.Add(bodyAsBlock);
            forLoop.Statements.Add(increment);
            forLoop.Statements.Add(test);
            return forLoop;
        }
开发者ID:nbulp,项目名称:CodeContracts,代码行数:20,代码来源:RewriteUtils.cs


示例3: VisitLoadNull

    protected override object VisitLoadNull(Variable dest, Literal source, Statement stat, object arg) {
      ExposureState estate=(ExposureState)arg;

      return arg;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:5,代码来源:ExposureAnalysis.cs


示例4: IsNonTrivial

        private static bool IsNonTrivial(Statement s)
        {
            if (s == null) return false;

            Block b = s as Block;
            
            if (b != null) return (IsNonTrivial(b));
            
            if (s.NodeType == NodeType.Nop) return false;
            
            return true;
        }
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:12,代码来源:HelperMethods.cs


示例5: IsClosureCreation

        public static bool IsClosureCreation(Method containingMethod, Statement s, out Local closureLocal)
        {
            var closureType = IsClosureCreation(containingMethod, s);
            if (closureType != null)
            {
                // it's a closure alright
                var assign = s as AssignmentStatement;
                if (assign != null)
                {
                    closureLocal = assign.Target as Local;
                }
                else
                {
                    closureLocal = null;
                }

                return true;
            }
            
            closureLocal = null;
            return false;
        }
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:22,代码来源:HelperMethods.cs


示例6: Visit

            /// <summary>
            /// Perform subsitution if necessary (create fresh nodes)
            /// </summary>
            internal Statement Visit(Statement statement)
            {
                Contract.Requires(this.IsValid);
                Contract.Requires(this.Depth >= 0);
                Contract.Ensures(this.Depth >= -1);

                if (statement == null) return null;

                switch (statement.NodeType)
                {
                    case NodeType.Nop:
                    case NodeType.Rethrow:
                    case NodeType.EndFilter:
                    case NodeType.EndFinally:
                        break;

                    case NodeType.Pop:
                        // a pop statement rather than expression
                        this.Depth--;
                        if (this.Depth < 0)
                        {
                            // we popped the original closure from the stack.
                            return null;
                        }

                        return statement;

                    case NodeType.AssignmentStatement:
                        var astmt = (AssignmentStatement) statement.Clone();
                        astmt.Target = Visit(astmt.Target);
                        astmt.Source = Visit(astmt.Source);
                        return astmt;

                    case NodeType.ExpressionStatement:
                        var estmt = (ExpressionStatement) statement.Clone();
                        if (estmt.Expression.NodeType == NodeType.Dup)
                        {
                            if (this.Depth == 0)
                            {
                                // duping the closure. Do nothing:
                                return null;
                            }

                            // otherwise, leave dup
                        }
                        else if (estmt.Expression.NodeType == NodeType.Pop)
                        {
                            var unary = estmt.Expression as UnaryExpression;
                            if (unary != null && unary.Operand != null)
                            {
                                // we are popping the thing we just push, so the depth does not change.
                                unary = (UnaryExpression) unary.Clone();
                                unary.Operand = Visit(unary.Operand);
                                estmt.Expression = unary;
                                return estmt;
                            }

                            // a pop statement rather than expression
                            this.Depth--;
                            if (this.Depth < 0)
                            {
                                // we popped the original closure from the stack.
                                return null;
                            }
                        }
                        else
                        {
                            estmt.Expression = Visit(estmt.Expression);
                            if (!IsVoidType(estmt.Expression.Type))
                            {
                                this.Depth++;
                            }
                        }

                        return estmt;

                    case NodeType.Block:
                        var block = (Block) statement.Clone();
                        block.Statements = Visit(block.Statements);
                        return block;

                    case NodeType.SwitchInstruction:
                        var sw = (SwitchInstruction) statement.Clone();
                        sw.Expression = Visit(sw.Expression);
                        return sw;

                    case NodeType.Throw:
                        var th = (Throw) statement.Clone();
                        th.Expression = Visit(th.Expression);
                        return th;

                    case NodeType.Return:
                        var ret = (Return) statement.Clone();
                        ret.Expression = Visit(ret.Expression);
                        return ret;

                    default:
//.........这里部分代码省略.........
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:101,代码来源:HelperMethods.cs


示例7: IsPopStatement

		/// <summary>
		/// Checks whether a given CciHelper statement encodes an MSIL Pop instruction.
		/// The correctness of this method depends heavily on what Herman does in the CciHelper reader ...
		/// </summary>
		/// <param name="stat">Statement to check.</param>
		/// <returns><c>true</c> iff <c>stat</c> encodes an MSIL Pop instruction.</returns>
		public static bool IsPopStatement(Statement stat) 
		{
			if(stat.NodeType == NodeType.Pop)
				return true;
			ExpressionStatement expr_stat = stat as ExpressionStatement;
			if(expr_stat == null) return false;

			Expression expr = expr_stat.Expression;

			if (expr.NodeType != NodeType.Pop) return false;

			UnaryExpression unexpr = expr as UnaryExpression;
			if ((unexpr != null ) && (unexpr.Operand != null) && (unexpr.Operand.NodeType != NodeType.Pop)) return false;

			return true;
		}
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:22,代码来源:CciUtils.cs


示例8: WrapTryCatch

    private static Statement WrapTryCatch(Method method, Statement statement)
    {
      Block afterCatches = new Block(new StatementList());
      Block tryBlock = new Block(new StatementList());
      Block blockAfterTryBody = new Block(null);
      tryBlock.Statements.Add(statement);
      tryBlock.Statements.Add(new Branch(null, afterCatches, false, true, true));
      tryBlock.Statements.Add(blockAfterTryBody);
      Block catchBlock = new Block(new StatementList());
      // emit code that pops the exception and fools fxcop
      Block branchTargetToFoolFxCop = new Block(null);
      var branch = new Branch(new Expression(NodeType.Pop), branchTargetToFoolFxCop);
      SourceContext hiddenContext = new SourceContext(HiddenDocument.Document);
      branch.SourceContext = hiddenContext;
      catchBlock.Statements.Add(branch);
      var rethrowStatement = new Throw();
      rethrowStatement.SourceContext = hiddenContext;
      rethrowStatement.NodeType = NodeType.Rethrow;
      catchBlock.Statements.Add(rethrowStatement);
      catchBlock.Statements.Add(branchTargetToFoolFxCop);
      var leave = new Branch(null, afterCatches, false, true, true);
      leave.SourceContext = hiddenContext;
      catchBlock.Statements.Add(leave);
      Block tryCatch = new Block(new StatementList());
      tryCatch.Statements.Add(tryBlock);
      tryCatch.Statements.Add(catchBlock);
      tryCatch.Statements.Add(afterCatches);

      if (method.ExceptionHandlers == null) method.ExceptionHandlers = new ExceptionHandlerList();

      ExceptionHandler exHandler = new ExceptionHandler();
      exHandler.TryStartBlock = tryBlock;
      exHandler.BlockAfterTryEnd = blockAfterTryBody;
      exHandler.HandlerStartBlock = catchBlock;
      exHandler.BlockAfterHandlerEnd = afterCatches;
      exHandler.FilterType = SystemTypes.Exception;
      exHandler.HandlerType = NodeType.Catch;
      method.ExceptionHandlers.Add(exHandler);

      return tryCatch;
    }
开发者ID:nbulp,项目名称:CodeContracts,代码行数:41,代码来源:Rewriter.cs


示例9: VisitReturn

    protected override object VisitReturn(Variable var, Statement stat, object arg) {
      ExposureState estate=(ExposureState)arg;

      // TODO: see if returned value is supposed to be exposed or not and then what do we know about it?
      return arg;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:6,代码来源:ExposureAnalysis.cs


示例10: VisitStoreField

    protected override object VisitStoreField(Variable dest, Field field, Variable source, Statement stat, object arg) {
      ExposureState estate=(ExposureState)arg;

      // static Fields
      if(field.IsStatic){
      }

      // BUGBUG!!
      // It seems that it would be better to start off ctors with the method's "this" object
      // in the Exposed state, but I'm not sure how to do that.
      This t = null;
      ThisBinding tb = dest as ThisBinding;
      if (tb != null){
        t = tb.BoundThis;
      }else{
        t = dest as This;
      }
      if (t != null &&
        this.ExposureChecker.currentMethod.NodeType == NodeType.InstanceInitializer
        && this.ExposureChecker.currentMethod.ThisParameter == t){
        ; // skip
      }else{
        ExposureState.Lattice.AVal valueOfdest = estate.GetAVal(dest);
        if (valueOfdest.lowerBound == null || valueOfdest.upperBound == null){
          HandleError(stat, stat, Error.WritingPackedObject, dest.Name.Name);
          return arg;
        }
        if (valueOfdest.lowerBound.IsAssignableTo(field.DeclaringType)){
          HandleError(stat, stat, Error.WritingPackedObject, dest.Name.Name);
          return arg;
        }
      }

      return arg;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:35,代码来源:ExposureAnalysis.cs


示例11: VisitLoadField

    protected override object VisitLoadField(Variable dest, Variable source, Field field, Statement stat, object arg) {
      ExposureState estate=(ExposureState)arg;

      // Check the receiver here only if one needs to be unpacked for read access
      //CheckReceiver(stat,source,estate);

      return arg;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:8,代码来源:ExposureAnalysis.cs


示例12: VisitConstrainedCall

    protected override object VisitConstrainedCall(Variable dest, Variable receiver, Method callee, ExpressionList arguments, TypeNode constraint, Statement stat, object arg) {
      Reference rtype = receiver.Type as Reference;
      if (rtype != null && rtype.ElementType != null && !rtype.ElementType.IsValueType) {
        // instance could be a reference type that could be null.

        // BUGBUG: when we track address of, we need to check here that target is indeed non-null
      }
      return VisitCall(dest, receiver, callee, arguments, true, stat, arg);
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:9,代码来源:ExposureAnalysis.cs


示例13: VisitCall

    protected override object VisitCall(Variable dest, Variable receiver, Method callee, ExpressionList arguments, bool virtcall, Statement stat, object arg) {
      ExposureState estate=(ExposureState)arg;

      if (callee.CciKind == Cci.CciMemberKind.FrameGuardGetter){
        // associate dest with receiver, because unpack is going to happen with dest as receiver
        estate.AssignFrameFor(dest,receiver,callee.DeclaringType); // receiver could be a subtype of the type that the frame guard is for
      }else if (callee == UnpackMethod){
        if(estate.IsFrameExposable(receiver)) {
          // BUGBUG: Using CopyVariable encodes the assumption that StartWritingTransitively returns itself!!! It may not!
          estate.CopyVariable(receiver,dest);
          estate.AssignFrameForExposed(dest);
        }else{
          TypeNode t = estate.LowerBoundOfObjectPointedToByFrame(receiver);
          if (t == null){ // BUGBUG: is this the same as it being Top?
            HandleError(stat, stat, Error.DontKnowIfCanExposeObject);
          }else{
            HandleError(stat, stat, Error.ExposingExposedObject);
          }
          return null;
        }
      }else if (callee == PackMethod){
        estate.AssignFrameForNotExposed(receiver);
      }else if (callee == IsExposableMethod){
        estate.AssignFunctionLink(ExposureState.EqIsExposableId,dest,receiver);
      }else if (callee == IsExposedMethod){
        estate.AssignEqIsExposed(dest,receiver);
      }else if (callee == AssertMethod){
        Variable v = arguments[0] as Variable;
        if (v != null && estate.IsFalse(v))
          return null;
      }

      // Push possible exceptions to handlers.
      for(int i=0;i<callee.Contract.Ensures.Count;i++){
        EnsuresExceptional e=callee.Contract.Ensures[i] as EnsuresExceptional;
        if(e!=null){
          ExposureState newnn=new ExposureState(estate);
          newnn.currentException=e.Type;
          ExposureChecker.PushExceptionState(ExposureChecker.currBlock,newnn);
        }
      }

      return arg;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:44,代码来源:ExposureAnalysis.cs


示例14: VisitCastClass

    /// <summary>
    /// Note: casts don't require a non-null argument. null value casts always succeed.
    /// </summary>
    protected override object VisitCastClass(Variable dest, TypeNode type, Variable source, Statement stat, object arg) {
      ExposureState estate=(ExposureState)arg;

      // acts like a copy retaining null status
      estate.CopyVariable(source, dest);
      return arg;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:10,代码来源:ExposureAnalysis.cs


示例15: VisitLoadConstant

    protected override object VisitLoadConstant(Variable dest, Literal source, Statement stat, object arg) 
    {
      ExposureState estate=(ExposureState)arg;

      if (source == Literal.False){
        estate.SetToFalse(dest);
      }

      return arg;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:10,代码来源:ExposureAnalysis.cs


示例16: ExtractCallFromStatement

 /// <summary>
 /// Helper method for CCI decoding
 /// </summary>
 internal static Method ExtractCallFromStatement(Statement s)
 {
   MethodCall dummy;
   return ExtractCallFromStatement(s, out dummy);
 }
开发者ID:nbulp,项目名称:CodeContracts,代码行数:8,代码来源:Rewriter.cs


示例17: VisitNop

 protected override object VisitNop(Statement stat, object arg) {
   return arg;
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:3,代码来源:ExposureAnalysis.cs


示例18: VisitReturn

 public override void VisitReturn(Return Return)
 {
     this.ReturnStatement = Return;
     base.VisitReturn(Return);
 }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:5,代码来源:LookForBadStuff.cs


示例19: VisitBranch

    protected override object VisitBranch(Variable cond, Block target, Statement stat, object arg) {
      ExposureState estate=(ExposureState)arg;

      if(cond==null)
        return arg;

      ExposureState trueState, falseState;

      estate.RefineBranchInformation(cond, out trueState, out falseState);

      if ( trueState != null ) {
        ExposureChecker.PushState(ExposureChecker.currBlock, ExposureChecker.currBlock.TrueContinuation, trueState);
      }
      if ( falseState != null ) {
        ExposureChecker.PushState(ExposureChecker.currBlock, ExposureChecker.currBlock.FalseContinuation, falseState);
      }
      return null;
    }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:18,代码来源:ExposureAnalysis.cs


示例20: IsMethodCall

        /// <summary>
        /// Analyzes a statement to see if it is a call to a method.
        /// </summary>
        /// <param name="s">Any statement.</param>
        /// <returns>The method m if the statement is an expression statement that is a method call to m or null</returns>
        internal static Method IsMethodCall(Statement s)
        {
            if (s == null) return null;

            ExpressionStatement es = s as ExpressionStatement;
            
            if (es == null) return null;
            
            // If the expression statement represents a method call, then it can
            // have two different values as its expression:
            // 0. if the method's return type is void, then the expression is just the
            //    method call.
            // 1. if the method's return type is not void, then the value of the method
            //    isn't needed and it is wrapped inside of a unary expression,
            //    Pop(method call(...)) in order to throw away the return value
            //
            // We want the method call only if its return type is void, so just look
            // for pattern 0.
            //
            MethodCall mc = es.Expression as MethodCall;
            if (mc == null) return null;

            MemberBinding mb = mc.Callee as MemberBinding;
            if (mb == null) return null;
            
            return mb.BoundMember as Method;
        }
开发者ID:Yatajga,项目名称:CodeContracts,代码行数:32,代码来源:HelperMethods.cs



注:本文中的System.Compiler.Statement类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Compiler.TypeNode类代码示例发布时间:2022-05-26
下一篇:
C# Compiler.SourceContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap