public static procedure_definition BuildToStringFuncForAutoClass(List <ident> names) { var pal = new procedure_attributes_list(proc_attribute.attr_override); var fp = new formal_parameters(); var ff = new function_header("ToString", "string", fp, pal); var cleft = new char_const('('); var cright = new char_const(')'); var ccomma = new char_const(','); bin_expr ex = new bin_expr(cleft, cright, Operators.Plus); for (var i = 0; i < names.Count; i++) { var dn = new dot_node(names[i], new ident("ToString")); var asnode = new typecast_node(names[i], new named_type_reference("object"), op_typecast.as_op); var eqnode = new bin_expr(asnode, new nil_const(), Operators.Equal); var expr = new question_colon_expression(eqnode, new string_const("nil"), dn); ex.left = new bin_expr(ex.left, expr, Operators.Plus); if (i < names.Count - 1) { ex.left = new bin_expr(ex.left, ccomma, Operators.Plus); } } var ass = new assign("Result", ex); return(BuildShortProcFuncDefinitionNoSC(ff, ass)); }
public override void visit(double_question_node dqn) { var st = dqn.Parent; while (!(st is statement)) { st = st.Parent; } var tname = "#temp" + UniqueNumStr(); var tt = new var_statement(new ident(tname), dqn.left); tt.var_def.Parent = tt; var l = new List <statement>(); l.Add(tt); l.Add(st as statement); expression right = dqn.right; var eq = new bin_expr(new ident(tname), new nil_const(), Operators.NotEqual, dqn.left.source_context); var qce = new question_colon_expression(eq, new ident(tname), right, dqn.source_context); ReplaceUsingParent(dqn, qce); visit(qce); ReplaceStatementUsingParent(st as statement, l); visit(tt); }
/*public question_colon_expression ConvertToQCE1(dot_question_node dqn) * { * addressed_value left = dqn.left; * addressed_value right = dqn.right; * * var eq = new bin_expr(left, new nil_const(), Operators.Equal, left.source_context); * * var nr = Into(left, right); * * var q = new question_colon_expression(eq, new nil_const(), nr, dqn.source_context); * nr.Parent = q; * return q; * }*/ public question_colon_expression ConvertToQCE1(dot_question_node dqn, string name) { addressed_value right = dqn.right; var eq = new bin_expr(new ident(name), new nil_const(), Operators.Equal, dqn.left.source_context); var nr = Into(new ident(name), right); var q = new question_colon_expression(eq, new nil_const(), nr, dqn.source_context); nr.Parent = q; return(q); }
public question_colon_expression ConvertToQCE(dot_question_node dqn) { addressed_value left = dqn.left; addressed_value right = dqn.right; var eq = new bin_expr(left, new nil_const(), Operators.Equal, left.source_context); addressed_value dn = null; var dnleft = right; // Левая часть dn addressed_value rdqn = null; addressed_value ldqn = null; // Если right - это dot_question_node, то протащить внутрь него left. В силу ассоциирования слева направо достаточно на первый уровень. if (right.GetType() == typeof(dot_question_node)) { var dqn_int = right as dot_question_node; ldqn = dqn_int.left; dnleft = ldqn; rdqn = dqn_int.right; // необходимо left протащить внутрь в ldqn } // Пока right - это dot_node, то необходимо протаскивать left чтобы присоединить его к первому не dot_node while (dnleft.GetType() == typeof(dot_node)) { dn = dnleft; dnleft = (dnleft as dot_node).left; } // В итоге в dnleft - самый внутренний left, который уже не является dot_node dnleft = new dot_node(left, dnleft, left.source_context); // Прикрепили right к самому внутреннему левому узлу в нотации a.b.c.d if (dn != null) { (dn as dot_node).left = dnleft; } else if (rdqn == null) { right = dnleft; } else { right = new dot_question_node(dnleft, (right as dot_question_node).right, dnleft.source_context); } var q = new question_colon_expression(eq, new nil_const(), right, dqn.source_context); right.Parent = q; return(q); }
public override void visit(dot_question_node dqn) { var st = dqn.Parent; while ((st != null) && !(st is statement)) { st = st.Parent; } if (st == null) { throw new SyntaxVisitorError("?._CANNOT_BE_IN_THIS_CONTEXT", dqn.source_context); } var tname = "#dqn_temp" + UniqueNumStr(); dot_question_node rif = null; var qce = ConvertToQCE1(dqn, tname); if (qce.ret_if_false is dot_question_node dn) { rif = dn; var expr = new question_colon_expression(qce.condition, qce.ret_if_true, rif.left); rif.left.ExprToQCE = expr; } var sug = sugared_addressed_value.NewP(dqn, qce, dqn.source_context); ReplaceUsingParent(dqn, sug); //Replace(dqn, sug); // Этот не подходит! var dl = (dqn.left.ExprToQCE == null ? dqn.left : dqn.left.ExprToQCE) as addressed_value; dqn.Parent = null; var tt = new var_statement(new ident(tname), dl, dqn.source_context); tt.var_def.Parent = tt; var l = new List <statement>(); l.Add(tt); l.Add(st as statement); ReplaceStatementUsingParent(st as statement, l); visit(qce); visit(tt); }
public override void visit(question_colon_expression node) { }
public virtual void visit(question_colon_expression _question_colon_expression) { DefaultVisit(_question_colon_expression); }
public override void visit(question_colon_expression _question_colon_expression) { DefaultVisit(_question_colon_expression); pre_do_visit(_question_colon_expression); visit(question_colon_expression.condition); visit(question_colon_expression.ret_if_true); visit(question_colon_expression.ret_if_false); post_do_visit(_question_colon_expression); }
public virtual void post_do_visit(question_colon_expression _question_colon_expression) { }
public virtual void visit(question_colon_expression _question_colon_expression) { }
public override void visit(question_colon_expression _question_colon_expression) { _question_colon_expression.condition.visit(this); _question_colon_expression.ret_if_true.visit(this); _question_colon_expression.ret_if_false.visit(this); }
private void VisitQuestionColonExpression(question_colon_expression en) { VisitExpression(en.internal_condition); VisitExpression(en.internal_ret_if_true); VisitExpression(en.internal_ret_if_false); }
public override void visit(question_colon_expression node) { prepare_node(node.condition, "condition"); prepare_node(node.ret_if_true, "ret_if_true"); prepare_node(node.ret_if_false, "ret_if_false"); }
public override void visit(question_colon_expression _question_colon_expression) { executer.visit(_question_colon_expression); if (_question_colon_expression.condition != null) this.visit((dynamic)_question_colon_expression.condition); if (_question_colon_expression.ret_if_true != null) this.visit((dynamic)_question_colon_expression.ret_if_true); if (_question_colon_expression.ret_if_false != null) this.visit((dynamic)_question_colon_expression.ret_if_false); if (_question_colon_expression.attributes != null) this.visit((dynamic)_question_colon_expression.attributes); }