当前位置: 首页>>代码示例>>C#>>正文


C# Ast.Block类代码示例

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


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

示例1: evaluate

        public static Expression evaluate(BlockExpression formula)
        {
            var body = new Block(formula.LexicalInfo);
            for (int i = 0; i < formula.Body.Statements.Count; ++i)
            {
                var statement = formula.Body.Statements[i];

                if (statement is ExpressionStatement &&
                    i == formula.Body.Statements.Count - 1)
                {
                    var last = (ExpressionStatement)statement;
                    body.Statements.Add(new ReturnStatement(last.Expression));
                }
                else
                    body.Statements.Add(formula.Body.Statements[i]);
            }

            var result = new BlockExpression(body);
            result.Parameters.Add(new ParameterDeclaration("this",
                CompilerContext.Current.CodeBuilder
                    .CreateTypeReference(EvaluationContext.CurrentContext.GetType())));
            result.ReturnType = CompilerContext.Current.CodeBuilder
                .CreateTypeReference(typeof(bool));

            return new MethodInvocationExpression(
                new ReferenceExpression("SetEvaluationFunction"), result);
        }
开发者ID:JackWangCUMT,项目名称:RulesEngine,代码行数:27,代码来源:DslModel.cs

示例2: MapStatementModifier

        public static Statement MapStatementModifier(StatementModifier modifier, out Block block)
        {
            switch (modifier.Type)
            {
                case StatementModifierType.If:
                {
                    IfStatement stmt = new IfStatement(modifier.LexicalInfo);
                    stmt.Condition = modifier.Condition;
                    stmt.TrueBlock = new Block();
                    block = stmt.TrueBlock;
                    return stmt;
                }

                case StatementModifierType.Unless:
                {
                    UnlessStatement stmt = new UnlessStatement(modifier.LexicalInfo);
                    stmt.Condition = modifier.Condition;
                    block = stmt.Block;
                    return stmt;
                }

                case StatementModifierType.While:
                {
                    WhileStatement stmt = new WhileStatement(modifier.LexicalInfo);
                    stmt.Condition = modifier.Condition;
                    block = stmt.Block;
                    return stmt;
                }
            }
            throw CompilerErrorFactory.NotImplemented(modifier, string.Format("modifier {0} supported", modifier.Type));
        }
开发者ID:boo,项目名称:boo-lang,代码行数:31,代码来源:NormalizeStatementModifiers.cs

示例3: DetectUnreachableCode

		//this method returns -1 if it doesn't detect unreachable code
		//else it returns the index of the first unreachable in block.Statements 
		private int DetectUnreachableCode(Block block, Statement limit)
		{
			var unreachable = false;
			var idx = 0;
			foreach (var stmt in block.Statements)
			{
				//HACK: __switch__ builtin function is hard to detect/handle
				//		within this context, let's ignore whatever is after __switch__
				if (IsSwitchBuiltin(stmt))
					return -1;//ignore followings

				if (unreachable && stmt is LabelStatement)
					return -1;

				if (stmt == limit)
					unreachable = true;
				else if (unreachable)
				{
					if (!stmt.IsSynthetic)
						Warnings.Add(CompilerWarningFactory.UnreachableCodeDetected(stmt));
					return idx;
				}

				idx++;
			}
			return -1;
		}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:29,代码来源:RemoveDeadCode.cs

示例4: DetectUnreachableCode

		//this method returns -1 if it doesn't detect unreachable code
		//else it returns the index of the first unreachable in block.Statements 
		private int DetectUnreachableCode(Block block, Statement limit)
		{
			bool unreachable = false;
			int idx = 0;
			foreach (Statement stmt in block.Statements)
			{
				//HACK: __switch__ builtin function is hard to detect/handle
				//		within this context, let's ignore whatever is after __switch__
				ExpressionStatement est = stmt as ExpressionStatement;
				if (null != est)
				{
					MethodInvocationExpression mie = est.Expression as MethodInvocationExpression;
					if (null != mie && TypeSystem.BuiltinFunction.Switch == mie.Target.Entity)
						return -1;//ignore followings
				}

				if (unreachable && stmt is LabelStatement)
					return -1;

				if (stmt == limit)
				{
					unreachable = true;
				}
				else if (unreachable)
				{
					Warnings.Add(
						CompilerWarningFactory.UnreachableCodeDetected(stmt) );
					return idx;
				}
				idx++;
			}
			return -1;
		}
开发者ID:HaKDMoDz,项目名称:GNet,代码行数:35,代码来源:RemoveDeadCode.cs

示例5: BooInferredReturnType

		public BooInferredReturnType(Block block, IClass context, bool useLastStatementIfNoReturnStatement)
		{
			if (block == null) throw new ArgumentNullException("block");
			this.useLastStatementIfNoReturnStatement = useLastStatementIfNoReturnStatement;
			this.block = block;
			this.context = context;
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:7,代码来源:InferredReturnType.cs

示例6: ExpandImpl

        protected override Statement ExpandImpl(MacroStatement macro){
            var result = new Block();
            foreach (Statement st in macro.Body.Statements){
                var decl = st as DeclarationStatement;
                var refer = st as ExpressionStatement;
                if(null==decl){
                    var ex = refer.Expression;
                    if (ex is MethodInvocationExpression){
                        decl =
                            new DeclarationStatement(
                                new Declaration(((MethodInvocationExpression) refer.Expression).Target.ToCodeString(),
                                                null), null);
                    }
                    if(ex is BinaryExpression){
                        var b = ex as BinaryExpression;
                        decl = new DeclarationStatement(
                            new Declaration(b.Left.ToCodeString(),null),b.Right
                            );
                    }
                }

                var bin = new BinaryExpression(BinaryOperatorType.Assign,
                                               new TryCastExpression(new ReferenceExpression(decl.Declaration.Name),
                                                                     decl.Declaration.Type),
                                               decl.Initializer);
                var def = new MacroStatement("definebrailproperty");
                def.Arguments.Add(bin);
                result.Add(def);
            }
            return result;
        }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:31,代码来源:DefinesMacro.cs

示例7: ConvertBlock

		B.Block ConvertBlock(BlockStatement block)
		{
			B.Block b = new B.Block(GetLexicalInfo(block));
			b.EndSourceLocation = GetLocation(block.EndLocation);
			ConvertStatements(block.Children, b);
			return b;
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:7,代码来源:ConvertVisitorStatements.cs

示例8: IfStatement

 public IfStatement(LexicalInfo token, Expression condition, Block trueBlock, Block falseBlock)
     : base(token)
 {
     this.Condition = condition;
     this.TrueBlock = trueBlock;
     this.FalseBlock = falseBlock;
 }
开发者ID:w4x,项目名称:boolangstudio,代码行数:7,代码来源:IfStatement.cs

示例9: OnBlock

		override public void OnBlock(Block block)
		{
			var currentChecked = _checked;
			_checked = AstAnnotations.IsChecked(block, Parameters.Checked);

			Visit(block.Statements);

			_checked = currentChecked;
		}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:9,代码来源:CheckLiteralValues.cs

示例10: ForCoverage

        public void ForCoverage()
        {
            var block = new Block();
            var statement = new ReturnStatement(new StringLiteralExpression("literal"));
            block.Statements.Add(statement);

            var visitor = new ReturnValueVisitor();
            bool found = visitor.Found;
            visitor.OnReturnStatement(statement);
        }
开发者ID:JonKruger,项目名称:MvcContrib,代码行数:10,代码来源:ReturnValueVisitorTester.cs

示例11: IsNewBlock

        public static bool IsNewBlock(MethodInvocationExpression method, out Block block)
        {
            block = null;

            if (method.Arguments.Count > 0 &&
                method.Arguments[method.Arguments.Count - 1] is BlockExpression)
            {
                block = ((BlockExpression)method.Arguments[method.Arguments.Count - 1]).Body;
            }

            return block != null;
        }
开发者ID:oz-systems,项目名称:rhino-commons,代码行数:12,代码来源:MacroHelper.cs

示例12: Expand

		public Statement Expand(IEnumerable<Node> generator)
		{
			Block resultingBlock = new Block();
			foreach (Node node in generator)
			{
				//'yield' (ie. implicit 'yield null') means 'yield `macro`.Body'
				Node generatedNode = node ?? _node.Body;
				if (null == generatedNode)
					continue;

				TypeMember member = generatedNode as TypeMember;
				if (null != member)
				{
					ExpandTypeMember(member, resultingBlock);
					continue;
				}

				Block block = generatedNode as Block;
				if (null != block)
				{
					resultingBlock.Add(block);
					continue;
				}

				Statement statement = generatedNode as Statement;
				if (null != statement)
				{
					resultingBlock.Add(statement);
					continue;
				}

				Expression expression = generatedNode as Expression;
				if (null != expression)
				{
					resultingBlock.Add(expression);
					continue;
				}

				Import import = generatedNode as Import;
				if (null != import)
				{
					ExpandImport(import);
					continue;
				}

				throw new CompilerError(_node, "Unsupported expansion: " + generatedNode.ToCodeString());
			}

			return resultingBlock.IsEmpty
					? null
					: resultingBlock.Simplify();
		}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:52,代码来源:NodeGeneratorExpander.cs

示例13: when

 public static Statement when(Expression expression)
 {
     var body = new Block(expression.LexicalInfo);
     body.Add(new ReturnStatement(expression));
     var result = new BlockExpression(body);
     result.Parameters.Add(
         new ParameterDeclaration("order",
                                  CurrentContext.CodeBuilder.CreateTypeReference(typeof(Order))));
     result.Parameters.Add(
         new ParameterDeclaration("customer",
                                  CurrentContext.CodeBuilder.CreateTypeReference(typeof(Customer))));
     return new ReturnStatement(result);
 }
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:13,代码来源:GlobalMethods.cs

示例14: WriteOutCells

        public static Block WriteOutCells(IEnumerable<CellDefinition> cells, bool header){
            string tagname = header ? "th" : "td";
            var onitem = new Block();
            foreach (CellDefinition cell in cells){
                var opentag = new ExpressionInterpolationExpression();
                ExpressionInterpolationExpression attrs = getAttributes(cell.Attributes);
                opentag.append("<" + tagname).append(attrs).append(">");
                onitem.add(opentag.writeOut());
                onitem.add(cell.Value.brailOutResolve());

                onitem.Add(("</" + tagname + ">").toLiteral().writeOut());
            }
            return onitem;
        }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:14,代码来源:BrailBuildingHelper.cs

示例15: ExpandImpl

 protected override Statement ExpandImpl(MacroStatement macro){
     var result = new Block();
     Expression outvar = macro.Arguments.Count == 0 ? new ReferenceExpression("_out") : macro.Arguments[0];
     var tryer = new TryStatement();
     var protectblock = new Block();
     protectblock.add(new MethodInvocationExpression(new ReferenceExpression("_catchoutput")));
     protectblock.add(macro.Body);
     tryer.ProtectedBlock = protectblock;
     tryer.EnsureBlock =
         new Block().add(outvar.assign(new MethodInvocationExpression(new ReferenceExpression("_endcatchoutput"))));
     result.Add(outvar.assign(""));
     result.Add(tryer);
     return result;
 }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:14,代码来源:CatchMacro.cs


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