public override OclExpression Visit(IfExp node) { OclExpression condition = node.Condition.Accept(this); OclExpression thenExpression = node.ThenExpression.Accept(this); OclExpression elseExpression = node.ElseExpression.Accept(this); return(new IfExp(node.Type /* bool? */, condition, thenExpression, elseExpression)); }
public void Visit(IfExp node) { Expressions.Add(node.Condition); Expressions.Add(node.ThenExpression); Expressions.Add(node.ElseExpression); node.Condition.Accept(this); node.ThenExpression.Accept(this); node.ElseExpression.Accept(this); }
public void Visit(IfExp node) { sb.Append("if "); node.Condition.Accept(this); sb.Append(" then"); node.ThenExpression.Accept(this); sb.Append(" else "); node.ElseExpression.Accept(this); sb.Append(" endIf "); }
public virtual void Visit(IfExp node) { node.Condition.Accept(this); node.ThenExpression.Accept(this); node.ElseExpression.Accept(this); TranslationOption option = new TranslationOption(); option.FormatString = "if ({0}) then {1} else {2}"; SubexpressionTranslations.AddTranslationOption(node, option, node.Condition, node.ThenExpression, node.ElseExpression); }
public void Visit(IfExp node) { sb.Append("If("); node.Condition.Accept(this); sb.Append(")"); node.ThenExpression.Accept(this); sb.Append("Else"); node.ElseExpression.Accept(this); sb.Append("EndIf"); }
private Exp CalculateIf(IfExp exp, Dictionary <string, DefineExp> context) { Exp predicate = exp.Children[0]; Exp then = exp.Children[1]; Exp @else = exp.Children[2]; return(CalculateExp(predicate, context) > 0 ? then : @else); }
//----------------------------------------------------------------------------- // Bad types for the ?: operator //----------------------------------------------------------------------------- public static SymbolErrorException BadTypeIfExp( IfExp e ) { Type t = e.TrueExp.CLRType; Type f = e.FalseExp.CLRType; return(new SymbolErrorException( Code.cBadTypeIfExp, e.Location, "Type of '?:' operator can't be determined because there's no implicit conversion between '" + t + "' and '" + f + "'." )); }
public void IfExp(IfExp e) { Label FalseLabel, EndLabel; FalseLabel = il.DefineLabel(); EndLabel = il.DefineLabel(); e.EvalExp.Visit(this); il.Emit(OpCodes.Brfalse, FalseLabel); e.ThenExp.Visit(this); il.Emit(OpCodes.Br, EndLabel); il.MarkLabel(FalseLabel); e.ElseExp.Visit(this); il.MarkLabel(EndLabel); }
private void removeAllLinks() { appliedProperty = null; initializedVariable = null; loopExp = null; navigationCallExp = null; parentOperation = null; ifExp = null; thenClause = null; elseClause = null; letExp = null; collectionRange = null; collectionItem = null; }
public void testIfExp() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Boolean"), null); VariableExp condition = factory1.createVariableExp(variable); IntegerLiteralExp thenExp = factory1.createIntegerLiteralExp(100, getClassifier("Integer")); RealLiteralExp elseExp = factory1.createRealLiteralExp("247.49", getClassifier("Real")); IfExp exp = factory1.createIfExp(condition, thenExp, elseExp); Assert.AreEqual("if abc then 100 else 247.49 endif", exp.ToString()); Assert.AreEqual("Real", exp.getType().getName()); }
public override bool Visit(IfExp node) { bool condition = node.Condition.Accept(this); bool thenpart = false; bool elsepart = false; if (node.ThenExpression != null) { thenpart = node.ThenExpression.Accept(this); } if (node.ElseExpression != null) { elsepart = node.ElseExpression.Accept(this); } return(condition && thenpart && elsepart); }
public void IfExp(IfExp e) { e.EvalExp.Visit(this); CheckBool(e.EvalExp); e.ThenExp.Visit(this); e.ElseExp.Visit(this); if (e.ThenExp.ExpType != e.ElseExp.ExpType) { Console.WriteLine("Error 103: Then expression and Else Expression do not evaluate to same type"); success = false; } else { e.ExpType = e.ThenExp.ExpType; } }
public void testIfOK() { List <object> constraints = doTestContextOK("context Film inv: if 20 > 10 then self.name = self.name else self.name.concat(\"Alex\") = self.name endif", getCurrentMethodName()); foreach (CSTInvariantCS constraint in constraints) { CSTExpressionInOclCS expression = constraint.getExpressionNodeCS(); OclExpression oclExpression = ((ExpressionInOclImpl)expression.getAst()).getBodyExpression(); Assert.IsTrue(oclExpression is IfExp); IfExp exp = (IfExp)oclExpression; Assert.AreEqual("Boolean", exp.getType().getName()); Assert.IsTrue(((OperationCallExp)exp.getThenExpression()).getSource() is AttributeCallExp); Assert.IsTrue(((OperationCallExp)exp.getElseExpression()).getSource() is OperationCallExp); } }
public override string GenerateCode() { MIPS.ifCount++; string actualif = MIPS.ifCount.ToString(); string tempReg = MIPS.GetReg(); string result = "\t#if \n"; string ifCode = IfExp.GenerateCode(); string ifReg = MIPS.LastReg(); result += ifCode; result += MIPS.Emit(MIPS.Opcodes.bne, ifReg, "1", "else" + actualif); string thenCode = ThenExp.GenerateCode(); result += thenCode; result += MIPS.Emit(MIPS.Opcodes.move, tempReg, MIPS.LastReg()); result += MIPS.Emit(MIPS.Opcodes.b, "endif" + actualif); result += "\telse" + actualif + ":\n"; string elseCode = ElseExp.GenerateCode(); result += elseCode; result += MIPS.Emit(MIPS.Opcodes.move, tempReg, MIPS.LastReg()); result += "\tendif" + actualif + ":\n"; string resultReg = MIPS.GetReg(); result += MIPS.Emit(MIPS.Opcodes.move, resultReg, tempReg); return(result); }
public void visitIfExpElseBegin(IfExp exp) { formula += ","; }
/** * @param thenClause The thenClause to set. */ public void setThenClause(IfExp thenClause) { removeAllLinks(); this.thenClause = thenClause; }
/** * @param ifExp The ifExp to set. */ public void setIfExp(IfExp ifExp) { removeAllLinks(); this.ifExp = ifExp; }
/** * @param elseClause The elseClause to set. */ public void setElseClause(IfExp elseClause) { removeAllLinks(); this.elseClause = elseClause; }
public void visitIfExpThenBegin(IfExp exp) { formula += ","; }
public void visitIfExp(IfExp exp) { formula += ")"; }
public abstract TType Visit(IfExp node);
internal static expr Convert(Compiler.Ast.Expression expr, expr_context ctx) { expr ast; if (expr is ConstantExpression) ast = Convert((ConstantExpression)expr); else if (expr is NameExpression) ast = new Name((NameExpression)expr, ctx); else if (expr is UnaryExpression) ast = new UnaryOp((UnaryExpression)expr); else if (expr is BinaryExpression) ast = Convert((BinaryExpression)expr); else if (expr is AndExpression) ast = new BoolOp((AndExpression)expr); else if (expr is OrExpression) ast = new BoolOp((OrExpression)expr); else if (expr is CallExpression) ast = new Call((CallExpression)expr); else if (expr is ParenthesisExpression) return Convert(((ParenthesisExpression)expr).Expression); else if (expr is LambdaExpression) ast = new Lambda((LambdaExpression)expr); else if (expr is ListExpression) ast = new List((ListExpression)expr, ctx); else if (expr is TupleExpression) ast = new Tuple((TupleExpression)expr, ctx); else if (expr is DictionaryExpression) ast = new Dict((DictionaryExpression)expr); else if (expr is ListComprehension) ast = new ListComp((ListComprehension)expr); else if (expr is GeneratorExpression) ast = new GeneratorExp((GeneratorExpression)expr); else if (expr is MemberExpression) ast = new Attribute((MemberExpression)expr, ctx); else if (expr is YieldExpression) ast = new Yield((YieldExpression)expr); else if (expr is ConditionalExpression) ast = new IfExp((ConditionalExpression)expr); else if (expr is IndexExpression) ast = new Subscript((IndexExpression)expr, ctx); else if (expr is SliceExpression) ast = new Slice((SliceExpression)expr); else if (expr is BackQuoteExpression) ast = new Repr((BackQuoteExpression)expr); else throw new ArgumentTypeException("Unexpected expression type: " + expr.GetType()); ast.GetSourceLocation(expr); return ast; }
public void visitIfExpBegin(IfExp exp) { formula += "IF("; }