private ASTType CheckTypes(BinaryExp n) { ASTType t1 = n.e1.accept(this); ASTType t2 = n.e2.accept(this); if (t1.GetType() == t2.GetType()) return t1; Swift.error(new IncompatibleTypesException(n.Context)); return null; }
private Exp ParseTerm() { var left = ParseFactor(); while (t.Kind == Kind.Mul || t.Kind == Kind.Div) { var op = t; Next(); var right = ParseFactor(); left = new BinaryExp(op, left, right); } return(left); }
// Get the name for operloaded binary-op // return null for an illegal op static internal string GetOpOverloadedName(BinaryExp.BinaryOp op) { switch(op) { case BinaryExp.BinaryOp.cAdd: return "op_Addition"; case BinaryExp.BinaryOp.cMul: return "op_Multiply"; case BinaryExp.BinaryOp.cDiv: return "op_Division"; case BinaryExp.BinaryOp.cSub: return "op_Subtraction"; case BinaryExp.BinaryOp.cEqu: return "op_Equality"; case BinaryExp.BinaryOp.cNeq: return "op_Inequality"; default: return null; } }
// For overloaded operators // No modifiers needed since op overloading must be public & static. // Have a special constructor so that we can set the IsOp flag and // get a safe string name. public MethodDecl( BinaryExp.BinaryOp op, TypeSig tRetType, ParamVarDecl[] arParams, BlockStatement stmtBody ) { m_fIsOpOverload = true; string strName = GetOpOverloadedName(op); m_idName = new Identifier(strName, tRetType.Location); m_tRetType = tRetType; m_arParams = (arParams != null) ? arParams : new ParamVarDecl[0]; m_stmtBody = stmtBody; //m_mods = new Modifiers(Modifiers.EFlags.Public | Modifiers.EFlags.Static); m_mods = new Modifiers(); m_mods.SetPublic(); m_mods.SetStatic(); Debug.Assert(m_idName != null); Debug.Assert(m_stmtBody != null); Debug.Assert(m_arParams != null); }
protected void OnBinExp( BinaryExp exp, string separator ) { bool first = true; foreach( Expression e in exp.children ) { if(!first) writer.Write(separator); first=false; Visit(e); } }