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


C# MacroStatement.GetAncestor方法代码示例

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


在下文中一共展示了MacroStatement.GetAncestor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExpandIncludeMacro

        void ExpandIncludeMacro(MacroStatement macro)
        {
            if (macro.Arguments.Count != 1)
                throw new ScriptParsingException("include requires a single literal string argument ('filename').");

            var include = macro.Arguments[0] as StringLiteralExpression;
            if (include == null)
                throw new ScriptParsingException("include argument should be a literal string ('filename').");

            var fullPath = Path.Combine(
                Path.GetDirectoryName(macro.LexicalInfo.FullPath),
                include.Value
                );

            var compiled = compiler.CompileInclude(fullPath).CompileUnit.Modules[0];

            var module = macro.GetAncestor<Module>();
            foreach (var import in compiled.Imports) {
                module.Imports.Add(import);
            }

            var type = macro.GetAncestor<TypeDefinition>();
            foreach (var member in compiled.Members) {
                type.Members.Add(member);
            }

            var parent = (Block) macro.ParentNode;
            var currentPosition = parent.Statements.IndexOf(macro);

            RemoveCurrentNode();
            foreach (var global in compiled.Globals.Statements.Reverse()) {
                parent.Insert(currentPosition, global);
            }
        }
开发者ID:JeremySkinner,项目名称:Phantom,代码行数:34,代码来源:IncludeSupportStep.cs

示例2: DoExpand

        /// <summary>
        /// Perform the actual expansion of the macro
        /// </summary>
        /// <param name="macro">The macro.</param>
        /// <returns></returns>
        protected override Statement DoExpand(MacroStatement macro)
        {
            Block body = (Block)macro.GetAncestor(NodeType.Block);
            MacroStatement macroParent = (MacroStatement)macro.GetAncestor(NodeType.MacroStatement);
           
            if (macro.Body.Statements.Count < 1 && parent.Name=="join")
            {
                Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "Join " + name + " section must contain at least a single expression statement"));
                return null;
            }

            if (macro.Arguments.Count == 0 && parent.Name!="join")
            {
                Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "Join " + name + " section must contain at least one key column"));
                return null;
            }

            if (macro.Arguments.Count > 0)
            {
                ArrayLiteralExpression ale = new ArrayLiteralExpression(macro.LexicalInfo);
                ale.Type = new ArrayTypeReference(CodeBuilder.CreateTypeReference(typeof(string)));
                foreach (Expression argument in macro.Arguments)
                {
                    ReferenceExpression expr = argument as ReferenceExpression;
                    if (expr == null)
                    {
                        Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo,"Join " + name +" section arguments must be reference expressions. Example: " + name + " name, surname"));
                        return null;
                    }
                    ale.Items.Add(new StringLiteralExpression(expr.Name));
                }
                var keyExpr = new BinaryExpression(BinaryOperatorType.Assign, new ReferenceExpression(name+"KeyColumns"), ale);
                macroParent.Arguments.Add(keyExpr);
            }

            foreach (Statement statement in macro.Body.Statements)
            {
                ExpressionStatement exprStmt = statement as ExpressionStatement;
                if(exprStmt==null)
                {
                    Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "Join " + name + " section can only contain expressions"));
                    return null;
                }
                Expression expr = exprStmt.Expression;
                parent.Arguments.Add(new MethodInvocationExpression(new ReferenceExpression(name), expr));
            }

            return null;
            
        }
开发者ID:f4i2u1,项目名称:rhino-etl,代码行数:55,代码来源:JoinSectionMacro.cs

示例3: Expand

        /// <summary>
        /// Expands the specified macro.
        /// </summary>
        /// <param name="macro">The macro.</param>
        /// <returns></returns>
        public override Statement Expand(MacroStatement macro)
        {
            Property property = new Property(propertyName);
            property.LexicalInfo = macro.LexicalInfo;
            property.Getter = new Method();
            if(macro.Arguments.Count==1)
            {
                property.Getter.Body.Add(
                    new ReturnStatement(macro.Arguments[0])
                    );
            }
            else if(
                macro.Arguments.Count == 0 &&
                macro.Body != null &&
				macro.Body.IsEmpty == false)//use the macro block
            {
				property.Getter.Body = macro.Body;
            }
            else
            {
                CompilerErrorFactory.CustomError(macro.LexicalInfo,
                                                 macro.Name + " must have a single expression argument or a block");
                return null;
            }

            ClassDefinition clazz = (ClassDefinition) macro.GetAncestor(NodeType.ClassDefinition);
            clazz.Members.Add(property);

            return null;
        }
开发者ID:JackWangCUMT,项目名称:rhino-dsl,代码行数:35,代码来源:GeneratePropertyMacro.cs

示例4: DoExpand

        /// <summary>
        /// Perform the actual expansion of the macro
        /// </summary>
        /// <param name="macro">The macro.</param>
        /// <returns></returns>
        protected override Statement DoExpand(MacroStatement macro)
        {
            Block body = (Block)macro.GetAncestor(NodeType.Block);

            if (macro.Block.Statements.Count < 1)
            {
                Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "Join"+name+" section must contain at least a single expression statement"));
                return null;
            }

            foreach (Statement statement in macro.Block.Statements)
            {
                ExpressionStatement exprStmt = statement as ExpressionStatement;
                if(exprStmt==null)
                {
                    Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "Join" + name + " section can only contain expressions"));
                    return null;
                }
                Expression expr = exprStmt.Expression;
                MethodInvocationExpression expression = new MethodInvocationExpression(new ReferenceExpression(name), expr);
                body.Add(new ExpressionStatement(expression));
            }
            return null;
        }
开发者ID:nkmajeti,项目名称:rhino-tools,代码行数:29,代码来源:JoinSectionMacro.cs

示例5: Expand

		public override Statement Expand(MacroStatement macro)
		{
			componentContextName = ComponentNaming.GetComponentContextName(macro);
			componentFactoryName = ComponentNaming.GetComponentFactoryName(macro);
			componentVariableName = ComponentNaming.GetComponentNameFor(macro);

			if (macro.Arguments.Count == 0) throw new MonoRailException("Component must be called with a name");

			Block block = new Block();

			Method method;

			method = (Method) macro.GetAncestor(NodeType.Method);

			StringLiteralExpression componentName = new StringLiteralExpression(macro.Arguments[0].ToString());

			MethodInvocationExpression dictionary = CreateParametersDictionary(macro);

			Expression macroBody = CodeBuilderHelper.CreateCallableFromMacroBody(CodeBuilder, macro);

			MethodInvocationExpression initContext = new MethodInvocationExpression();
			initContext.Target = AstUtil.CreateReferenceExpression("Castle.MonoRail.Views.Brail.BrailViewComponentContext");
			initContext.Arguments.Extend(
				new Expression[]
					{
						new SelfLiteralExpression(),
						macroBody, componentName,
						AstUtil.CreateReferenceExpression("OutputStream"),
						dictionary
					});

			// compilerContext = BrailViewComponentContext(macroBodyClosure, "componentName", OutputStream, dictionary)
			block.Add(new BinaryExpression(BinaryOperatorType.Assign,
			                               new ReferenceExpression(componentContextName), initContext));

			// AddViewComponentProperties( compilerContext.ComponentParams )
			MethodInvocationExpression addProperties =
				new MethodInvocationExpression(AstUtil.CreateReferenceExpression("AddViewComponentProperties"));
			addProperties.Arguments.Add(AstUtil.CreateReferenceExpression(componentContextName + ".ComponentParameters"));
			block.Add(addProperties);

			InternalLocal viewComponentFactoryLocal = CodeBuilder.DeclareLocal(method, componentFactoryName,
			                                                                   TypeSystemServices.Map(
			                                                                   	typeof(IViewComponentFactory)));

			// viewComponentFactory = context.GetService(IViewComponentFactory)
			MethodInvocationExpression callService = new MethodInvocationExpression(
				AstUtil.CreateReferenceExpression("context.GetService"));
			callService.Arguments.Add(CodeBuilder.CreateTypeofExpression(typeof(IViewComponentFactory)));

			block.Add(new BinaryExpression(BinaryOperatorType.Assign,
			                               CodeBuilder.CreateLocalReference(componentFactoryName, viewComponentFactoryLocal),
			                               callService));

			// component = viewComponentFactory.Create( componentName)
			MethodInvocationExpression createComponent = new MethodInvocationExpression(
				new MemberReferenceExpression(CodeBuilder.CreateLocalReference(componentFactoryName, viewComponentFactoryLocal),
				                              "Create"));
			createComponent.Arguments.Add(componentName);
			block.Add(new BinaryExpression(BinaryOperatorType.Assign,
			                               new ReferenceExpression(componentVariableName),
			                               createComponent));
			AddSections(block, macro);

			// component.Init(context, componentContext)
			MethodInvocationExpression initComponent = new MethodInvocationExpression(
				AstUtil.CreateReferenceExpression(componentVariableName + ".Init"));
			initComponent.Arguments.Extend(
				new Expression[]
					{
						new ReferenceExpression("context"),
						new ReferenceExpression(componentContextName)
					});

			block.Add(initComponent);

			// component.Render()
			block.Add(new MethodInvocationExpression(
			          	AstUtil.CreateReferenceExpression(componentVariableName + ".Render")));

			// if component.ViewToRender is not null:
			//	OutputSubView("/"+component.ViewToRender, context.CompnentParameters)
			Block renderView = new Block();
			MethodInvocationExpression outputSubView = new MethodInvocationExpression(
				AstUtil.CreateReferenceExpression("OutputSubView"));
			outputSubView.Arguments.Add(new BinaryExpression(BinaryOperatorType.Addition,
			                                                 new StringLiteralExpression("/"),
			                                                 AstUtil.CreateReferenceExpression(componentContextName +
			                                                                                   ".ViewToRender")));

			outputSubView.Arguments.Add(AstUtil.CreateReferenceExpression(componentContextName + ".ComponentParameters"));
			renderView.Add(outputSubView);

			block.Add(new IfStatement(AstUtil.CreateReferenceExpression(componentContextName + ".ViewToRender"),
			                          renderView, new Block()));

			// RemoveViewComponentProperties( compilerContext.ComponentParams )
			MethodInvocationExpression removeProperties =
				new MethodInvocationExpression(AstUtil.CreateReferenceExpression("RemoveViewComponentProperties"));
			removeProperties.Arguments.Add(AstUtil.CreateReferenceExpression(componentContextName + ".ComponentParameters"));
//.........这里部分代码省略.........
开发者ID:candland,项目名称:Castle.MonoRail,代码行数:101,代码来源:ComponentMacro.cs


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