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

C# Ast.Block类代码示例

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

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



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


示例16: Expand

		public override Statement Expand(MacroStatement macro)
		{
			if (macro.Arguments.Count == 0)
				throw new MonoRailException("Section must be called with a name");

			MacroStatement component = GetParentComponent(macro);

			componentContextName = ComponentNaming.GetComponentContextName(component);
			componentVariableName = ComponentNaming.GetComponentNameFor(component);


			string sectionName = macro.Arguments[0].ToString();
			Block block = new Block();
			//if (!Component.SupportsSection(section.Name))
			//   throw new ViewComponentException( String.Format("The section '{0}' is not supported by the ViewComponent '{1}'", section.Name, ComponentName));
			MethodInvocationExpression supportsSection = new MethodInvocationExpression(
				AstUtil.CreateReferenceExpression(componentVariableName + ".SupportsSection"),
				new StringLiteralExpression(sectionName));
			//create the new exception
			RaiseStatement raiseSectionNotSupportted = new RaiseStatement(
				new MethodInvocationExpression(
					AstUtil.CreateReferenceExpression(typeof(ViewComponentException).FullName),
					new StringLiteralExpression(
						String.Format("The section '{0}' is not supported by the ViewComponent '{1}'", sectionName,
						              component.Arguments[0].ToString())
						)
					));

			Block trueBlock = new Block();
			trueBlock.Add(raiseSectionNotSupportted);
			IfStatement ifSectionNotSupported =
				new IfStatement(new UnaryExpression(UnaryOperatorType.LogicalNot, supportsSection),
				                trueBlock, null);
			block.Add(ifSectionNotSupported);
			//componentContext.RegisterSection(sectionName);
			MethodInvocationExpression mie = new MethodInvocationExpression(
				new MemberReferenceExpression(new ReferenceExpression(componentContextName), "RegisterSection"),
				new StringLiteralExpression(sectionName),
				CodeBuilderHelper.CreateCallableFromMacroBody(CodeBuilder, macro));
			block.Add(mie);

			IDictionary sections = (IDictionary) component["sections"];
			if (sections == null)
			{
				component["sections"] = sections = new Hashtable();
			}
			sections.Add(sectionName, block);
			return null;
		}
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:49,代码来源:SectionMacro.cs


示例17: Reify

 public Statement Reify(Statement node)
 {
     var result = node;
     if (node is MacroStatement)
     {
         // macro statements are replaced
         // so we need to wrap it in a Block
         // otherwise we would lose the result
         var parentNode = node.ParentNode;
         result = new Block(node);
         parentNode.Replace(node, result);
     }
     ApplyAttributesAndExpandMacros();
     return result;
 }
开发者ID:Bombadil77,项目名称:boo,代码行数:15,代码来源:MacroAndAttributeExpansion.cs


示例18: ExpandImpl

        protected override Statement ExpandImpl(MacroStatement macro){
            if (macro.Arguments.Count == 0)
            {
                Context.Errors.Add(new CompilerError(macro.LexicalInfo,
                                                     "call macro requires at least one reference or string attribute for action name"));
            }
            var basis = new ReferenceExpression("Html");
            var method = new MemberReferenceExpression(basis, "RenderAction");
            var call = new MethodInvocationExpression(method);
            int i = 0;
            var result = new Block();
            foreach (Expression argument in macro.Arguments){
                i++;
                Expression exp = argument;
                if (!(exp is HashLiteralExpression)){
//action and contrller parameters
                    if (!(exp is NullLiteralExpression)){
                        exp = new StringLiteralExpression(argument.ToCodeString());
                    }
                    call.Arguments.Add(exp);
                }
                else{
                    string name = "__rd";
                    result.Add(
                        new DeclarationStatement(
                            new Declaration(name, null),
                            new MethodInvocationExpression(AstUtil.CreateReferenceExpression("RouteValueDictionary"))
                            )
                        );
                    var dict = argument as HashLiteralExpression;
                    foreach (ExpressionPair item in dict.Items){
                        result.Add(
                            new MethodInvocationExpression(
                                AstUtil.CreateReferenceExpression(name + ".Add"),
                                item.First,
                                item.Second
                                )
                            );
                    }
                    if (i == 2){
                        call.Arguments.Add(new NullLiteralExpression());
                    }
                    call.Arguments.Add(AstUtil.CreateReferenceExpression(name));
                }
            }
            result.Add(call);
            return result;
        }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:48,代码来源:CallMacro.cs


示例19: OnMacroStatement

 public override void OnMacroStatement(MacroStatement node)
 {
     if (node.Name == "includeast")
     {
         var expander = new IncludeastMacro();
         var statements = expander.ExpandGenerator(node);
         var block = new Block();
         foreach (var statement in statements){
             block.Statements.Add((Statement)statement);
         }
         node.ReplaceBy(block);
     }
     else{
         base.OnMacroStatement(node);
     }
 }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:16,代码来源:IncludeAstMacroExpandStep.cs


示例20: GetExpressionsFromBlock

		private static Expression[] GetExpressionsFromBlock(Block block)
		{
			List<Expression> expressions = new List<Expression>(block.Statements.Count);
			foreach (Statement statement in block.Statements)
			{
				if (statement is ExpressionStatement)
					expressions.Add((statement as ExpressionStatement).Expression);
				else if (statement is MacroStatement)
				{
					MacroStatement macroStatement = statement as MacroStatement;
					if (macroStatement.Arguments.Count == 0 &&
						macroStatement.Body.IsEmpty)
					{
						// Assume it is a reference expression
						ReferenceExpression refExp = new ReferenceExpression(macroStatement.LexicalInfo);
						refExp.Name = macroStatement.Name;
						expressions.Add(refExp);
					}
					else
					{
						// Assume it is a MethodInvocation
						MethodInvocationExpression mie = new MethodInvocationExpression(macroStatement.LexicalInfo);
						mie.Target = new ReferenceExpression(macroStatement.LexicalInfo, macroStatement.Name);
						mie.Arguments = macroStatement.Arguments;

						if (macroStatement.Body.IsEmpty == false)
						{
							// If the macro statement has a block,                      
							// transform it into a block expression and pass that as the last argument                     
							// to the method invocation.
							BlockExpression be = new BlockExpression(macroStatement.LexicalInfo);
							be.Body = macroStatement.Body.CloneNode();

							mie.Arguments.Add(be);
						}

						expressions.Add(mie);
					}
				}
				else
				{
					throw new InvalidOperationException(string.Format("Can not transform block with {0} into argument.",
																	  statement.GetType()));
				}
			}
			return expressions.ToArray();
		}
开发者ID:yonglehou,项目名称:NGinnBPM,代码行数:47,代码来源:BlockToArgumentsTransformer.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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