示例#1
0
        private VisitResult VisitBlock(ASTBlock node)
        {
            foreach (var child in node.Children)
            {
                switch (child)
                {
                case ASTReturn _:
                    return(new VisitResult
                    {
                        ControlType = ControlType.Return,
                        Value = Visit(child).Value
                    });

                case ASTBreak _:
                    return(new VisitResult
                    {
                        ControlType = ControlType.Break
                    });

                case ASTContinue _:
                    return(new VisitResult
                    {
                        ControlType = ControlType.Continue
                    });
                }

                var result = Visit(child);
                if (result != null && result.ControlType != ControlType.None)
                {
                    return(result);
                }
            }

            return(null);
        }
示例#2
0
        public void Visit(ASTBlock block, Function function)
        {
            List <ASTStatementBase> statements = block.Statements;

            for (int i = 0; i < statements.Count; i++)
            {
                statements[i].Accept(this, function);
            }
        }
示例#3
0
文件: ThirdPass.cs 项目: goric/cflat
        /// <summary>
        /// Open a new scope for the block and visit the body. Pop the scope when we're done.
        /// </summary>
        /// <param name="n"></param>
        public override void VisitBlock(ASTBlock n)
        {
            //a hack to get around scoping declared variables properly in for loops
            if (!_skipNextBlockScope)
            {
                _scopeMgr.PushScope("block");
                _currentMethod.AddBlock(n.IsBranch);
            }
            else
            {
                _skipNextBlockScope = false;
            }

            CheckSubTree(n.Body);

            _currentMethod.LeaveBlock();
            _scopeMgr.PopScope();
        }
示例#4
0
		/// <summary>   Supports the Pluggable Directives
		/// #foo( arg+ )
		/// </summary>
		public SimpleNode Directive()
		{
			ASTDirective directiveNode = new ASTDirective(this, ParserTreeConstants.DIRECTIVE);

			bool isNodeScopeOpen = true;
			nodeTree.OpenNodeScope(directiveNode);
			Token token;
			Directive directive;
			bool doItNow = false;

			try
			{
				/*
				* note that if we were escaped, that is now handled by 
				* EscapedDirective()
				*/
				token = ConsumeToken(ParserConstants.WORD);
				String directiveName = token.Image.Substring(1);

				directive = directives.Create(directiveName, directiveStack);

				Debug.Assert(directiveNode != null);

				directiveNode.Directive = directive;

				/*
				*  Velocimacro support : if the directive is macro directive
				*   then set the flag so after the block parsing, we add the VM
				*   right then. (So available if used w/in the current template )
				*/

				if (directiveName.Equals("macro"))
				{
					doItNow = true;
				}

				/*
				* set the directive name from here.  No reason for the thing to know 
				* about parser tokens
				*/

				directiveNode.DirectiveName = directiveName;

				DirectiveType directiveType;
				if (directive == null)
				{
					// if null, then not a real directive, but maybe a Velocimacro

					//d  =  (Directive) runtimeServices.getVelocimacro( directiveName, currentTemplateName );

					// TODO: adding a null check since RuntimeServices is not finished
					// since the parser can be created without RuntimeServices - this may actually be needed here and in the orgiginal source as well.
					if (runtimeServices != null)
					{
						if (!runtimeServices.IsVelocimacro(directiveName, currentTemplateName))
						{
							token_source.StateStackPop();
							token_source.inDirective = false;
							if (true)
								return directiveNode;
						}
					}

					/*
					 *  Currently, all VMs are LINE directives
					 */
					directiveType = DirectiveType.LINE;
				}
				else
				{
					directiveType = directive.Type;
				}

				/*
				*  now, switch us out of PRE_DIRECTIVE
				*/

				token_source.SwitchTo(ParserConstants.DIRECTIVE);

				ConsumeWhiteSpaces();

				if (directive != null && !directive.AcceptParams)
				{
					int curToken = GetCurrentTokenKind();

					if (curToken == ParserConstants.NEWLINE)
					{
						ConsumeToken(ParserConstants.NEWLINE);
					}
					else
					{
						throw new ParseException(
							"Foreach directives must be the only items on the line (comments or contents are not allowed)");
					}
				}

				if (directive == null || directive.AcceptParams)
				{
					ConsumeToken(ParserConstants.LPAREN);

					while(true)
					{
						switch(GetCurrentTokenKind())
						{
							case ParserConstants.LBRACKET:
							case ParserConstants.WHITESPACE:
							case ParserConstants.STRING_LITERAL:
							case ParserConstants.TRUE:
							case ParserConstants.FALSE:
							case ParserConstants.NUMBER_LITERAL:
							case ParserConstants.WORD:
							case ParserConstants.IDENTIFIER:
							case ParserConstants.LCURLY:
								;
								break;

							default:
								jj_la1[7] = jj_gen;
								//UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1012"'
								goto label_3_brk;
						}
						DirectiveArg();
					}
					//UPGRADE_NOTE: Label 'label_3_brk' was added. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1011"'
					label_3_brk:
					;

					ConsumeToken(ParserConstants.RPAREN);
				}

				if (directiveType == DirectiveType.LINE)
				{
					return directiveNode;
				}

				directiveStack.Push(directive);

				ASTBlock jjtn001 = new ASTBlock(this, ParserTreeConstants.BLOCK);
				bool jjtc001 = true;
				nodeTree.OpenNodeScope(jjtn001);

				try
				{
					while(true)
					{
						Statement();
						int kind = GetCurrentTokenKind();
						switch(kind)
						{
							case ParserConstants.LPAREN:
							case ParserConstants.RPAREN:
							case ParserConstants.ESCAPE_DIRECTIVE:
							case ParserConstants.SET_DIRECTIVE:
							case ParserConstants.DOUBLE_ESCAPE:
							case ParserConstants.ESCAPE:
							case ParserConstants.TEXT:
							case ParserConstants.SINGLE_LINE_COMMENT:
							case ParserConstants.FORMAL_COMMENT:
							case ParserConstants.MULTI_LINE_COMMENT:
							case ParserConstants.STRING_LITERAL:
							case ParserConstants.IF_DIRECTIVE:
							case ParserConstants.STOP_DIRECTIVE:
							case ParserConstants.NUMBER_LITERAL:
							case ParserConstants.WORD:
							case ParserConstants.IDENTIFIER:
							case ParserConstants.DOT:
							case ParserConstants.LCURLY:
							case ParserConstants.RCURLY:
								break;

							default:
								jj_la1[8] = jj_gen;
								//UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1012"'
								goto label_4_brk;
						}
					}
					//UPGRADE_NOTE: Label 'label_4_brk' was added. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1011"'
					label_4_brk:
					;
				}
				catch(Exception jjte001)
				{
					nodeTree.ClearNodeScope(jjtn001);
					jjtc001 = false;
					if (jjte001 is SystemException)
					{
						throw;
					}
					if (jjte001 is ParseException)
					{
						throw;
					}
					throw (ApplicationException) jjte001;
				}
				finally
				{
					if (jjtc001)
					{
						nodeTree.CloseNodeScope(jjtn001, true);
					}

					directiveStack.Pop();
				}
				ConsumeToken(ParserConstants.END);
				nodeTree.CloseNodeScope(directiveNode, true);
				isNodeScopeOpen = false;
				/*
				 *  VM : if we are processing a #macro directive, we need to 
				 *     process the block.  In truth, I can just register the name
				 *     and do the work later when init-ing.  That would work
				 *     as long as things were always defined before use.  This way
				 *     we don't have to worry about forward references and such...
				 */

				if (doItNow)
				{
					Macro.processAndRegister(runtimeServices, directiveNode, currentTemplateName);
				}

				return directiveNode;
			}
			catch(Exception jjte000)
			{
				if (isNodeScopeOpen)
				{
					nodeTree.ClearNodeScope(directiveNode);
					isNodeScopeOpen = false;
				}
				else
				{
					nodeTree.PopNode();
				}
				if (jjte000 is SystemException)
				{
					throw;
				}
				if (jjte000 is ParseException)
				{
					throw;
				}
				throw (ApplicationException) jjte000;
			}
			finally
			{
				if (isNodeScopeOpen)
				{
					nodeTree.CloseNodeScope(directiveNode, true);
				}
			}
		}
示例#5
0
		public void ElseIfStatement()
		{
			/*@bgen(jjtree) ElseIfStatement */
			ASTElseIfStatement jjtn000 = new ASTElseIfStatement(this, ParserTreeConstants.ELSE_IF_STATEMENT);
			bool jjtc000 = true;
			nodeTree.OpenNodeScope(jjtn000);
			//UPGRADE_NOTE: Exception 'java.lang.Throwable' was converted to ' ' which has different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1100"'
			try
			{
				ConsumeToken(ParserConstants.ELSEIF_DIRECTIVE);
				switch(GetCurrentTokenKind())
				{
					case ParserConstants.WHITESPACE:
						ConsumeToken(ParserConstants.WHITESPACE);
						break;

					default:
						jj_la1[33] = jj_gen;
						break;
				}
				ConsumeToken(ParserConstants.LPAREN);
				Expression();
				ConsumeToken(ParserConstants.RPAREN);
				ASTBlock jjtn001 = new ASTBlock(this, ParserTreeConstants.BLOCK);
				bool jjtc001 = true;
				nodeTree.OpenNodeScope(jjtn001);
				//UPGRADE_NOTE: Exception 'java.lang.Throwable' was converted to ' ' which has different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1100"'
				try
				{
					while(true)
					{
						Statement();
						switch(GetCurrentTokenKind())
						{
							case ParserConstants.LPAREN:
							case ParserConstants.RPAREN:
							case ParserConstants.ESCAPE_DIRECTIVE:
							case ParserConstants.SET_DIRECTIVE:
							case ParserConstants.DOUBLE_ESCAPE:
							case ParserConstants.ESCAPE:
							case ParserConstants.TEXT:
							case ParserConstants.SINGLE_LINE_COMMENT:
							case ParserConstants.FORMAL_COMMENT:
							case ParserConstants.MULTI_LINE_COMMENT:
							case ParserConstants.STRING_LITERAL:
							case ParserConstants.IF_DIRECTIVE:
							case ParserConstants.STOP_DIRECTIVE:
							case ParserConstants.NUMBER_LITERAL:
							case ParserConstants.WORD:
							case ParserConstants.IDENTIFIER:
							case ParserConstants.DOT:
							case ParserConstants.LCURLY:
							case ParserConstants.RCURLY:
								;
								break;

							default:
								jj_la1[34] = jj_gen;
								//UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1012"'
								goto label_12_brk;
						}
					}
					//UPGRADE_NOTE: Label 'label_12_brk' was added. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1011"'
					label_12_brk:
					;
				}
				catch(Exception exception)
				{
					nodeTree.ClearNodeScope(jjtn001);
					jjtc001 = false;
					if (exception is SystemException)
					{
						throw;
					}
					if (exception is ParseException)
					{
						throw;
					}
					throw (ApplicationException) exception;
				}
				finally
				{
					if (jjtc001)
					{
						nodeTree.CloseNodeScope(jjtn001, true);
					}
				}
			}
			catch(Exception exception)
			{
				nodeTree.ClearNodeScope(jjtn000);
				jjtc000 = false;
				if (exception is SystemException)
				{
					throw;
				}
				if (exception is ParseException)
				{
					throw;
				}
				throw (ApplicationException) exception;
			}
			finally
			{
				if (jjtc000)
				{
					nodeTree.CloseNodeScope(jjtn000, true);
				}
			}
		}
示例#6
0
 public virtual Object Visit(ASTBlock node, Object data)
 {
     data = node.ChildrenAccept(this, data);
     return(data);
 }
示例#7
0
 /// <summary>Display an ASTBlock node
 /// </summary>
 public override Object Visit(ASTBlock node, Object data)
 {
     return(ShowNode(node, data));
 }
示例#8
0
 public override void VisitBlock(ASTBlock n)
 {
     n.Body.Visit(this);
 }
示例#9
0
 /// <summary>Display an ASTBlock node
 /// </summary>
 public override System.Object visit(ASTBlock node, System.Object data)
 {
     return(showNode(node, data));
 }
示例#10
0
 public virtual System.Object visit(ASTBlock node, System.Object data)
 {
     data = node.childrenAccept(this, data);
     return(data);
 }
示例#11
0
 public override object Visit(ASTBlock node, object data)
 {
     return(this.ShowNode(node, data));
 }