public virtual void VisitStatement(IStatementNode node) { if (node is CreateTableNode) { VisitCreateTable((CreateTableNode)node); } if (node is CreateViewNode) { VisitCreateView((CreateViewNode)node); } if (node is CreateTriggerNode) { VisitCreateTrigger((CreateTriggerNode)node); } else if (node is SelectStatementNode) { VisitSelect((SelectStatementNode)node); } else if (node is UpdateStatementNode) { VisitUpdate((UpdateStatementNode)node); } else if (node is InsertStatementNode) { VisitInsert((InsertStatementNode)node); } }
private IStatementNode ParseIfNode() { IStatementNode stmt = null; var fstmt = this.ParseSimpleStatementNode(); if (this.TryParseToken(TokenType.Delimiter, ";")) { stmt = fstmt; fstmt = this.ParseSimpleStatementNode(); } var expr = ((ExpressionStatementNode)fstmt).ExpressionNode; var thenCmd = this.ParseStatementBlock(); IStatementNode elseCmd = null; if (this.TryParseName("else")) { elseCmd = this.ParseStatementBlock(); } return(new IfNode(stmt, expr, thenCmd, elseCmd)); }
public void VisitStatement(IStatementNode node) { if (StatementVisitor != null) { node.AcceptStatementVisitor(StatementVisitor); } }
public FuncNode(string name, IList <NameNode> parameters, IStatementNode body, TypeInfo returnType) { this.name = name; this.parameters = parameters; this.body = body; this.returnType = returnType; }
public IfNode(IStatementNode statement, IExpressionNode expression, IStatementNode thenNode, IStatementNode elseNode) { this.statement = statement; this.expression = expression; this.thenCommand = thenNode; this.elseCommand = elseNode; }
public ForNode(IStatementNode initstmt, IExpressionNode expression, IStatementNode poststmt, IStatementNode body) { this.initstmt = initstmt; this.expression = expression; this.poststmt = poststmt; this.body = body; }
public ForNode(VarSetNode varSetNode, ScopedDefineNode defineNode, IExpressionNode expression, IStatementNode statement, BlockNode block, Range range) : base(range) { VarSetNode = varSetNode; DefineNode = defineNode; Expression = expression; Statement = statement; Block = block; }
private IStatementNode ParseSimpleStatementNode(bool canHaveLabel = false) { var token = this.NextToken(); while (token != null && token.Type == TokenType.NewLine) { token = this.NextToken(); } if (token == null) { return(null); } if (token.Type == TokenType.Name) { IStatementNode stmt = this.TryParseNameStatement(token.Value); if (stmt != null) { return(stmt); } } this.PushToken(token); if (token.Type == TokenType.Delimiter && token.Value == "{") { return(this.ParseStatementBlock()); } IExpressionNode node = this.ParseExpressionNode(); if (node == null) { return(null); } AssignmentNode anode = this.TryParseAssignmentNode(node); if (anode != null) { return(anode); } if (this.TryParseToken(TokenType.Operator, "<-")) { var cmdnode = new SendNode(node, this.ParseExpressionNode()); return(cmdnode); } var cmd = new ExpressionStatementNode(node); return(cmd); }
public override Node VisitBlock(DeltinScriptParser.BlockContext context) { IStatementNode[] statements = new IStatementNode[context.statement().Length]; for (int i = 0; i < statements.Length; i++) { statements[i] = (IStatementNode)VisitStatement(context.statement()[i]); } var node = new BlockNode(statements, Range.GetRange(context)); CheckRange(node); return(node); }
protected override void Visit(IStatementNode node) { var trace = (StatementTrace)node; if (isFirstStatementInGroup) { Pad(sb, indent); } sb.Append(node.Text).Append("(").Append(trace.Outcome).Append(")"); foreach (var tracing in trace.Tracings) { sb.AppendLine(); Pad(sb, indent); sb.Append("!").Append(tracing); } sb.AppendLine(); isFirstStatementInGroup = false; }
public override Node VisitFor(DeltinScriptParser.ForContext context) { Node node; BlockNode block = (BlockNode)VisitBlock(context.block()); if (context.IN() != null) { IExpressionNode array = (IExpressionNode)Visit(context.expr()); string variable = context.PART().GetText(); node = new ForEachNode(variable, array, block, Range.GetRange(context)); } else { VarSetNode varSet = null; if (context.varset() != null) { varSet = (VarSetNode)VisitVarset(context.varset()); } ScopedDefineNode defineNode = null; if (context.define() != null) { defineNode = (ScopedDefineNode)VisitDefine(context.define()); } IExpressionNode expression = null; if (context.expr() != null) { expression = (IExpressionNode)VisitExpr(context.expr()); } IStatementNode statement = null; if (context.statement() != null) { statement = (IStatementNode)VisitStatement(context.statement()); } node = new ForNode(varSet, defineNode, expression, statement, block, Range.GetRange(context)); } CheckRange(node); return(node); }
private IStatementNode ParseForNode() { if (this.TryPeekToken(TokenType.Delimiter, "{")) { return(new ForNode(null, null, null, this.ParseStatementBlock())); } IExpressionNode expr = null; if (this.TryParseToken(TokenType.Delimiter, ";")) { expr = this.ParseExpressionNode(); this.ParseToken(TokenType.Delimiter, ";"); if (this.TryPeekToken(TokenType.Delimiter, "{")) { return(new ForNode(null, expr, null, this.ParseStatementBlock())); } IStatementNode poststmt = this.ParseSimpleStatementNode(); return(new ForNode(null, expr, poststmt, this.ParseStatementBlock())); } IStatementNode initstmt = this.ParseSimpleStatementNode(); if (this.TryParseToken(TokenType.Delimiter, ";")) { expr = this.ParseExpressionNode(); this.ParseToken(TokenType.Delimiter, ";"); IStatementNode poststmt = null; if (!this.TryPeekToken(TokenType.Delimiter, "{")) { poststmt = this.ParseSimpleStatementNode(); } return(new ForNode(initstmt, expr, poststmt, this.ParseStatementBlock())); } expr = ((ExpressionStatementNode)initstmt).ExpressionNode; return(new ForNode(expr, this.ParseStatementBlock())); }
public void AppendStatement(IStatementNode newStatement) { _statements.Add(newStatement); }
public virtual void visit(IStatementNode value) { }
public IfNode(IExpressionNode expression, IStatementNode block) : this(null, expression, block) { }
public LabelNode(string label, IStatementNode statement) { this.label = label; this.statement = statement; }
public IfNode(IStatementNode statement, IExpressionNode expression, IStatementNode thenNode) : this(statement, expression, thenNode, null) { }
public ForNode(IExpressionNode expression, IStatementNode body) : this(null, expression, null, body) { }
protected override void Visit(IStatementNode node) { linker.Link((StatementNode)node, scopes.Peek(), false); }
//перевод statement-а private void ConvertStatement(IStatementNode value) { make_next_spoint = true; if (save_debug_info /*&& !(value is IForNode)*/) MarkSequencePoint(value.Location); make_next_spoint = false; value.visit(this); make_next_spoint = true; //нужно для очистки стека после вызова функции в качестве процедуры //ssyy добавил //если вызов конструктора предка, то стек не очищаем if (!( (value is IFunctionCallNode) && ((IFunctionCallNode)value).last_result_function_call || (value is ICompiledConstructorCall) && !((ICompiledConstructorCall)value).new_obj_awaited() || (value is ICommonConstructorCall) && !((ICommonConstructorCall)value).new_obj_awaited() )) //\ssyy if ((value is IFunctionCallNode) && !(value is IBasicFunctionCallNode)) { IFunctionCallNode fc = value as IFunctionCallNode; if (fc.function.return_value_type != null) { ICompiledTypeNode ct = fc.function.return_value_type as ICompiledTypeNode; if ((ct == null) || (ct != null && (ct.compiled_type != TypeFactory.VoidType))) il.Emit(OpCodes.Pop); } } }
public void VisitStatement(IStatementNode node) { _visitor.Visit(node); }
private bool BeginOnForNode(IStatementNode value) { //if (value is IForNode) return true; IStatementsListNode stats = value as IStatementsListNode; if (stats == null) return false; if (stats.statements.Length == 0) return false; //if (stats.statements[0] is IForNode) return true; return false; }
//перевод тела private void ConvertBody(IStatementNode body) { if (!(body is IStatementsListNode) && save_debug_info && body.Location != null) if (body.Location.begin_line_num == 0xFFFFFF) MarkSequencePoint(il, body.Location); body.visit(this); OptMakeExitLabel(); }
protected virtual void Visit(IStatementNode node) { }
public void VisitStatement(IStatementNode node) { node.AcceptStatementVisitor(this); }
protected virtual void VisitDefaultStatement(IStatementNode node) { }
protected override void Visit(IStatementNode node) { Pad(sb, indent); sb.Append(node.Text); sb.Append("\r\n"); }
public virtual void VisitStatement(IStatementNode node) { if (node is CreateTableNode) VisitCreateTable((CreateTableNode) node); if (node is CreateViewNode) VisitCreateView((CreateViewNode) node); if (node is CreateTriggerNode) { VisitCreateTrigger((CreateTriggerNode) node); } else if (node is SelectStatementNode) { VisitSelect((SelectStatementNode) node); } else if (node is UpdateStatementNode) { VisitUpdate((UpdateStatementNode) node); } else if (node is InsertStatementNode) { VisitInsert((InsertStatementNode) node); } }
public void visit(IStatementNode value) { // abstract ISemanticNodeConverter.SourceTextBuilder.AddNodeInToStack(""); }
public void visit(IStatementNode value) { }
public static BlockNode ToBlock(IStatementNode stmt) => new BlockNode().Return(x => x.Statements.Add(stmt)).R(stmt);
void ParseStatement(ScopeGroup scope, IStatementNode statement, Var returnVar, bool isLast) { switch (statement) { // Method case MethodNode methodNode: Element method = ParseMethod(scope, methodNode, false); if (method != null) { Actions.Add(method); } return; // Variable set case VarSetNode varSetNode: ParseVarset(scope, varSetNode); return; // For case ForEachNode forEachNode: { ContinueSkip.Setup(); // The action the for loop starts on. int forActionStartIndex = Actions.Count() - 1; ScopeGroup forGroup = scope.Child(); // Create the for's temporary variable. DefinedVar forTempVar = VarCollection.AssignDefinedVar( scopeGroup: forGroup, name: forEachNode.Variable, isGlobal: IsGlobal, range: forEachNode.Range ); // Reset the counter. Actions.Add(forTempVar.SetVariable(new V_Number(0))); // Parse the for's block. ParseBlock(forGroup, forEachNode.Block, false, returnVar); // Add the for's finishing elements Actions.Add(forTempVar.SetVariable( // Indent the index by 1. Element.Part <V_Add> ( forTempVar.GetVariable(), new V_Number(1) ) )); ContinueSkip.SetSkipCount(forActionStartIndex); // The target array in the for statement. Element forArrayElement = ParseExpression(scope, forEachNode.Array); Actions.Add(Element.Part <A_LoopIf>( // Loop if the for condition is still true. Element.Part <V_Compare> ( forTempVar.GetVariable(), EnumData.GetEnumValue(Operators.LessThan), Element.Part <V_CountOf>(forArrayElement) ) )); ContinueSkip.ResetSkip(); return; } // For case ForNode forNode: { ContinueSkip.Setup(); // The action the for loop starts on. int forActionStartIndex = Actions.Count() - 1; ScopeGroup forGroup = scope.Child(); // Set the variable if (forNode.VarSetNode != null) { ParseVarset(scope, forNode.VarSetNode); } if (forNode.DefineNode != null) { ParseDefine(scope, forNode.DefineNode); } // Parse the for's block. ParseBlock(forGroup, forNode.Block, false, returnVar); Element expression = null; if (forNode.Expression != null) { expression = ParseExpression(forGroup, forNode.Expression); } // Check the expression if (forNode.Expression != null) // If it has an expression { // Parse the statement if (forNode.Statement != null) { ParseStatement(forGroup, forNode.Statement, returnVar, false); } ContinueSkip.SetSkipCount(forActionStartIndex); Actions.Add(Element.Part <A_LoopIf>(expression)); } // If there is no expression but there is a statement, parse the statement. else if (forNode.Statement != null) { ParseStatement(forGroup, forNode.Statement, returnVar, false); ContinueSkip.SetSkipCount(forActionStartIndex); // Add the loop Actions.Add(Element.Part <A_Loop>()); } ContinueSkip.ResetSkip(); return; } // While case WhileNode whileNode: { ContinueSkip.Setup(); // The action the while loop starts on. int whileStartIndex = Actions.Count() - 2; ScopeGroup whileGroup = scope.Child(); ParseBlock(whileGroup, whileNode.Block, false, returnVar); ContinueSkip.SetSkipCount(whileStartIndex); // Add the loop-if Element expression = ParseExpression(scope, whileNode.Expression); Actions.Add(Element.Part <A_LoopIf>(expression)); ContinueSkip.ResetSkip(); return; } // If case IfNode ifNode: { A_SkipIf if_SkipIf = new A_SkipIf(); Actions.Add(if_SkipIf); var ifScope = scope.Child(); // Parse the if body. ParseBlock(ifScope, ifNode.IfData.Block, false, returnVar); // Determines if the "Skip" action after the if block will be created. // Only if there is if-else or else statements. bool addIfSkip = ifNode.ElseIfData.Length > 0 || ifNode.ElseBlock != null; // Update the initial SkipIf's skip count now that we know the number of actions the if block has. // Add one to the body length if a Skip action is going to be added. if_SkipIf.ParameterValues = new IWorkshopTree[] { Element.Part <V_Not>(ParseExpression(scope, ifNode.IfData.Expression)), new V_Number(Actions.Count - 1 - Actions.IndexOf(if_SkipIf) + (addIfSkip ? 1 : 0)) }; // Create the "Skip" action. A_Skip if_Skip = new A_Skip(); if (addIfSkip) { Actions.Add(if_Skip); } // Parse else-ifs A_Skip[] elseif_Skips = new A_Skip[ifNode.ElseIfData.Length]; // The ElseIf's skips for (int i = 0; i < ifNode.ElseIfData.Length; i++) { // Create the SkipIf action for the else if. A_SkipIf elseif_SkipIf = new A_SkipIf(); Actions.Add(elseif_SkipIf); // Parse the else-if body. var elseifScope = scope.Child(); ParseBlock(elseifScope, ifNode.ElseIfData[i].Block, false, returnVar); // Determines if the "Skip" action after the else-if block will be created. // Only if there is additional if-else or else statements. bool addIfElseSkip = i < ifNode.ElseIfData.Length - 1 || ifNode.ElseBlock != null; // Set the SkipIf's parameters. elseif_SkipIf.ParameterValues = new IWorkshopTree[] { Element.Part <V_Not>(ParseExpression(scope, ifNode.ElseIfData[i].Expression)), new V_Number(Actions.Count - 1 - Actions.IndexOf(elseif_SkipIf) + (addIfElseSkip ? 1 : 0)) }; // Create the "Skip" action for the else-if. if (addIfElseSkip) { elseif_Skips[i] = new A_Skip(); Actions.Add(elseif_Skips[i]); } } // Parse else body. if (ifNode.ElseBlock != null) { var elseScope = scope.Child(); ParseBlock(elseScope, ifNode.ElseBlock, false, returnVar); } // Replace dummy skip with real skip now that we know the length of the if, if-else, and else's bodies. // Replace if's dummy. if_Skip.ParameterValues = new IWorkshopTree[] { new V_Number(Actions.Count - 1 - Actions.IndexOf(if_Skip)) }; // Replace else-if's dummy. for (int i = 0; i < elseif_Skips.Length; i++) { if (elseif_Skips[i] != null) { elseif_Skips[i].ParameterValues = new IWorkshopTree[] { new V_Number(Actions.Count - 1 - Actions.IndexOf(elseif_Skips[i])) }; } } return; } // Return case ReturnNode returnNode: if (returnNode.Value != null) { Element result = ParseExpression(scope, returnNode.Value); if (returnVar != null) { Actions.Add(returnVar.SetVariable(result)); } } if (!isLast) { A_Skip returnSkip = new A_Skip(); Actions.Add(returnSkip); ReturnSkips.Add(returnSkip); } return; // Define case ScopedDefineNode defineNode: ParseDefine(scope, defineNode); return; } }
private bool contains_only_if(IStatementNode stmt) { return stmt is IIfNode || stmt is ISwitchNode || stmt is IStatementsListNode && (stmt as IStatementsListNode).statements.Length == 1 && ((stmt as IStatementsListNode).statements[0] is IIfNode || (stmt as IStatementsListNode).statements[0] is ISwitchNode); }
public IStatementNode AppendStatement(IStatementNode statement) { statement.Parent = this; _statements.Add(statement); return(statement); }