void IRPrinter::visit(Expr *e) { if (auto c = e->asConst()) { visitConst(c); } else if (auto s = e->asString()) { visitString(s); } else if (auto r = e->asRegExp()) { visitRegExp(r); } else if (auto n = e->asName()) { visitName(n); } else if (auto t = e->asTemp()) { visitTemp(t); } else if (auto a = e->asArgLocal()) { visitArgLocal(a); } else if (auto c = e->asClosure()) { visitClosure(c); } else if (auto c = e->asConvert()) { visitConvert(c); } else if (auto u = e->asUnop()) { visitUnop(u); } else if (auto b = e->asBinop()) { visitBinop(b); } else if (auto c = e->asCall()) { visitCall(c); } else if (auto n = e->asNew()) { visitNew(n); } else if (auto s = e->asSubscript()) { visitSubscript(s); } else if (auto m = e->asMember()) { visitMember(m); } else { Q_UNREACHABLE(); } }
bool FunctionMergePass::visitExpr(Expr * from, Expr * to) { if (from == NULL && to == NULL) { return true; } if (from == NULL || to == NULL) { diag.debug() << "Merge failure: null expression"; return false; } if (from->exprType() != to->exprType()) { reportDifference("Difference in exprType", from, to); return false; } switch (from->exprType()) { // case Expr::Invalid: // return &Expr::ErrorVal; // // case Expr::TypeCount: // DFAIL("Invalid"); // case Expr::NoOp: return true; case Expr::ConstInt: case Expr::ConstFloat: case Expr::ConstString: return static_cast<ConstantExpr *>(from)->isEqual(static_cast<ConstantExpr *>(to)); // case Expr::TypeLiteral: // return visitTypeLiteral(static_cast<TypeLiteralExpr *>(from), static_cast<TypeLiteralExpr *>(to)); // case Expr::ConstNull: return true; case Expr::ConstObjRef: // return visitConstantObjectRef(static_cast<ConstantObjectRef *>(from), static_cast<ConstantObjectRef *>(to)); return false; case Expr::ConstEmptyArray: return TypeRelation::isEqual(from->type(), to->type()); // case Expr::ConstNArray: // return visitConstantNativeArray(static_cast<ConstantNativeArray *>(from), static_cast<ConstantNativeArray *>(to)); case Expr::LValue: return visitLValue(static_cast<LValueExpr *>(from), static_cast<LValueExpr *>(to)); // case Expr::BoundMethod: // return visitBoundMethod(static_cast<BoundMethodExpr *>(from), static_cast<BoundMethodExpr *>(to)); // case Expr::ElementRef: return visitElementRef(static_cast<BinaryExpr *>(from), static_cast<BinaryExpr *>(to)); case Expr::Assign: case Expr::PostAssign: return visitAssign(static_cast<AssignmentExpr *>(from), static_cast<AssignmentExpr *>(to)); // case Expr::MultiAssign: // return visitMultiAssign(static_cast<MultiAssignExpr *>(from), static_cast<MultiAssignExpr *>(to)); // // case Expr::Call: // case Expr::SuperCall: // //case Expr::ICall: // case Expr::Construct: // return visitCall(static_cast<CallExpr *>(from), static_cast<CallExpr *>(to)); // case Expr::FnCall: case Expr::CtorCall: case Expr::VTableCall: return visitFnCall(static_cast<FnCallExpr *>(from), static_cast<FnCallExpr *>(to)); // case Expr::IndirectCall: // return visitIndirectCall(static_cast<IndirectCallExpr *>(from), static_cast<IndirectCallExpr *>(to)); // case Expr::New: return visitNew(static_cast<NewExpr *>(from), static_cast<NewExpr *>(to)); // case Expr::ImplicitCast: // case Expr::ExplicitCast: case Expr::UpCast: // case Expr::TryCast: // case Expr::DynamicCast: case Expr::QualCast: // case Expr::UnboxCast: // case Expr::Truncate: case Expr::SignExtend: // case Expr::ZeroExtend: // case Expr::IntToFloat: // case Expr::BitCast: // case Expr::UnionMemberCast: // case Expr::CheckedUnionMemberCast: return visitCast(static_cast<CastExpr *>(from), static_cast<CastExpr *>(to)); case Expr::UnionCtorCast: return visitUnionCtorCast(static_cast<CastExpr *>(from), static_cast<CastExpr *>(to)); case Expr::BinaryOpcode: return visitBinaryOpcode(static_cast<BinaryOpcodeExpr *>(from), static_cast<BinaryOpcodeExpr *>(to)); case Expr::Compare: return visitCompare(static_cast<CompareExpr *>(from), static_cast<CompareExpr *>(to)); // case Expr::InstanceOf: // return visitInstanceOf(static_cast<InstanceOfExpr *>(from), static_cast<InstanceOfExpr *>(to)); // // case Expr::RefEq: // return visitRefEq(static_cast<BinaryExpr *>(from), static_cast<BinaryExpr *>(to)); // // case Expr::PtrDeref: // return visitPtrDeref(static_cast<UnaryExpr *>(from), static_cast<UnaryExpr *>(to)); // case Expr::Not: return visitNot(static_cast<UnaryExpr *>(from), static_cast<UnaryExpr *>(to)); case Expr::And: case Expr::Or: return visitLogicalOper(static_cast<BinaryExpr *>(from), static_cast<BinaryExpr *>(to)); case Expr::Complement: return visitComplement(static_cast<UnaryExpr *>(from), static_cast<UnaryExpr *>(to)); case Expr::InitVar: return visitInitVar(static_cast<InitVarExpr *>(from), static_cast<InitVarExpr *>(to)); // // case Expr::ClearVar: // return visitClearVar(static_cast<ClearVarExpr *>(from), static_cast<ClearVarExpr *>(to)); // case Expr::Prog2: return visitProg2(static_cast<BinaryExpr *>(from), static_cast<BinaryExpr *>(to)); case Expr::ArrayLiteral: return visitArrayLiteral( static_cast<ArrayLiteralExpr *>(from), static_cast<ArrayLiteralExpr *>(to)); // case Expr::TupleCtor: // return visitTupleCtor(static_cast<TupleCtorExpr *>(from), static_cast<TupleCtorExpr *>(to)); // // case Expr::ClosureEnv: // return visitClosureScope(static_cast<ClosureEnvExpr *>(from), static_cast<ClosureEnvExpr *>(to)); // // case Expr::IRValue: // return in; // // case Expr::SharedValue: // return visitSharedValue(static_cast<SharedValueExpr *>(from), static_cast<SharedValueExpr *>(to)); // // case Expr::PatternVar: // DFAIL("PatternVar"); case Expr::Seq: return visitSeq(static_cast<SeqExpr *>(from), static_cast<SeqExpr *>(to)); case Expr::If: return visitIf(static_cast<IfExpr *>(from), static_cast<IfExpr *>(to)); case Expr::For: return visitFor(static_cast<ForExpr *>(from), static_cast<ForExpr *>(to)); case Expr::ForEach: return visitForEach(static_cast<ForEachExpr *>(from), static_cast<ForEachExpr *>(to)); case Expr::Throw: return visitThrow(static_cast<ThrowExpr *>(from), static_cast<ThrowExpr *>(to)); case Expr::Return: return visitReturn(static_cast<ReturnExpr *>(from), static_cast<ReturnExpr *>(to)); case Expr::LocalProcedure: return visitLocalProcedure( static_cast<LocalProcedureExpr *>(from), static_cast<LocalProcedureExpr *>(to)); case Expr::LocalReturn: return visitLocalReturn(static_cast<ReturnExpr *>(from), static_cast<ReturnExpr *>(to)); case Expr::Break: case Expr::Continue: return true; default: break; } diag.error(from) << "Expr type not handled: " << exprTypeName(from->exprType()); DFAIL("Fall through"); }