From: Roberto Raggi Date: Mon, 11 Jun 2012 12:21:02 +0000 (+0200) Subject: Remove dead code. X-Git-Tag: submit/tizen/20131211.000705~670^2~659^2~1080 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b9aa2286443fd315d0d2c1eb0bfb17bd2eba358a;p=platform%2Fupstream%2Fqtdeclarative.git Remove dead code. --- diff --git a/qv4codegen.cpp b/qv4codegen.cpp index eb7037e36..962b87c0d 100644 --- a/qv4codegen.cpp +++ b/qv4codegen.cpp @@ -369,43 +369,45 @@ IR::Expr *Codegen::binop(IR::AluOp op, IR::Expr *left, IR::Expr *right) { if (IR::Const *c1 = left->asConst()) { if (IR::Const *c2 = right->asConst()) { - const IR::Type ty = IR::Binop::typeForOp(op, left, right); - - switch (op) { - case IR::OpAdd: return _block->CONST(ty, c1->value + c2->value); - case IR::OpAnd: return _block->CONST(ty, c1->value ? c2->value : 0); - case IR::OpBitAnd: return _block->CONST(ty, int(c1->value) & int(c2->value)); - case IR::OpBitOr: return _block->CONST(ty, int(c1->value) | int(c2->value)); - case IR::OpBitXor: return _block->CONST(ty, int(c1->value) ^ int(c2->value)); - case IR::OpDiv: return _block->CONST(ty, c1->value / c2->value); - case IR::OpEqual: return _block->CONST(ty, c1->value == c2->value); - case IR::OpGe: return _block->CONST(ty, c1->value >= c2->value); - case IR::OpGt: return _block->CONST(ty, c1->value > c2->value); - case IR::OpLe: return _block->CONST(ty, c1->value <= c2->value); - case IR::OpLShift: return _block->CONST(ty, int(c1->value) << int(c2->value)); - case IR::OpLt: return _block->CONST(ty, c1->value < c2->value); - case IR::OpMod: return _block->CONST(ty, ::fmod(c1->value, c2->value)); - case IR::OpMul: return _block->CONST(ty, c1->value * c2->value); - case IR::OpNotEqual: return _block->CONST(ty, c1->value != c2->value); - case IR::OpOr: return _block->CONST(ty, c1->value ? c1->value : c2->value); - case IR::OpRShift: return _block->CONST(ty, int(c1->value) >> int(c2->value)); - case IR::OpStrictEqual: return _block->CONST(ty, c1->value == c2->value); - case IR::OpStrictNotEqual: return _block->CONST(ty, c1->value != c2->value); - case IR::OpSub: return _block->CONST(ty, c1->value - c2->value); - case IR::OpURShift: return _block->CONST(ty, unsigned(c1->value) >> int(c2->value)); - - case IR::OpInstanceof: - case IR::OpIn: - assert(!"unreachabe"); - break; - - case IR::OpIfTrue: // unary ops - case IR::OpNot: - case IR::OpUMinus: - case IR::OpUPlus: - case IR::OpCompl: - case IR::OpInvalid: - break; + if (c1->type == IR::NumberType && c2->type == IR::NumberType) { + const IR::Type ty = IR::NumberType; + + switch (op) { + case IR::OpAdd: return _block->CONST(ty, c1->value + c2->value); + case IR::OpAnd: return _block->CONST(ty, c1->value ? c2->value : 0); + case IR::OpBitAnd: return _block->CONST(ty, int(c1->value) & int(c2->value)); + case IR::OpBitOr: return _block->CONST(ty, int(c1->value) | int(c2->value)); + case IR::OpBitXor: return _block->CONST(ty, int(c1->value) ^ int(c2->value)); + case IR::OpDiv: return _block->CONST(ty, c1->value / c2->value); + case IR::OpEqual: return _block->CONST(ty, c1->value == c2->value); + case IR::OpGe: return _block->CONST(ty, c1->value >= c2->value); + case IR::OpGt: return _block->CONST(ty, c1->value > c2->value); + case IR::OpLe: return _block->CONST(ty, c1->value <= c2->value); + case IR::OpLShift: return _block->CONST(ty, int(c1->value) << int(c2->value)); + case IR::OpLt: return _block->CONST(ty, c1->value < c2->value); + case IR::OpMod: return _block->CONST(ty, ::fmod(c1->value, c2->value)); + case IR::OpMul: return _block->CONST(ty, c1->value * c2->value); + case IR::OpNotEqual: return _block->CONST(ty, c1->value != c2->value); + case IR::OpOr: return _block->CONST(ty, c1->value ? c1->value : c2->value); + case IR::OpRShift: return _block->CONST(ty, int(c1->value) >> int(c2->value)); + case IR::OpStrictEqual: return _block->CONST(ty, c1->value == c2->value); + case IR::OpStrictNotEqual: return _block->CONST(ty, c1->value != c2->value); + case IR::OpSub: return _block->CONST(ty, c1->value - c2->value); + case IR::OpURShift: return _block->CONST(ty, unsigned(c1->value) >> int(c2->value)); + + case IR::OpInstanceof: + case IR::OpIn: + assert(!"unreachabe"); + break; + + case IR::OpIfTrue: // unary ops + case IR::OpNot: + case IR::OpUMinus: + case IR::OpUPlus: + case IR::OpCompl: + case IR::OpInvalid: + break; + } } } } else if (op == IR::OpAdd) { @@ -1436,7 +1438,7 @@ IR::Function *Codegen::defineFunction(const QString &name, AST::Node *ast, unsigned returnAddress = entryBlock->newTemp(); entryBlock->MOVE(entryBlock->TEMP(returnAddress), entryBlock->CONST(IR::UndefinedType, 0)); - exitBlock->RET(exitBlock->TEMP(returnAddress), IR::InvalidType); + exitBlock->RET(exitBlock->TEMP(returnAddress)); IR::ExprList *throwArgs = function->New(); throwArgs->expr = throwBlock->TEMP(returnAddress); throwBlock->EXP(throwBlock->CALL(throwBlock->NAME(IR::Name::builtin_throw, /*line*/0, /*column*/0), throwArgs)); diff --git a/qv4ir.cpp b/qv4ir.cpp index c915c9ad9..79d5f113e 100644 --- a/qv4ir.cpp +++ b/qv4ir.cpp @@ -55,61 +55,14 @@ namespace IR { const char *typeName(Type t) { switch (t) { - case InvalidType: return "invalid"; case UndefinedType: return "undefined"; case NullType: return "null"; - case VoidType: return "void"; - case StringType: return "string"; - case UrlType: return "QUrl"; - case ColorType: return "QColor"; - case SGAnchorLineType: return "SGAnchorLine"; - case AttachType: return "AttachType"; - case ObjectType: return "object"; - case VariantType: return "variant"; - case VarType: return "var"; case BoolType: return "bool"; - case IntType: return "int"; - case FloatType: return "float"; case NumberType: return "number"; default: return "invalid"; } } -inline bool isNumberType(IR::Type ty) -{ - return ty >= IR::FirstNumberType; -} - -inline bool isStringType(IR::Type ty) -{ - return ty == IR::StringType || ty == IR::UrlType || ty == IR::ColorType; -} - -IR::Type maxType(IR::Type left, IR::Type right) -{ - if (isStringType(left) && isStringType(right)) { - // String promotions (url to string) are more specific than - // identity conversions (AKA left == right). That's because - // we want to ensure we convert urls to strings in binary - // expressions. - return IR::StringType; - } else if (left == right) - return left; - else if (isNumberType(left) && isNumberType(right)) { - IR::Type ty = qMax(left, right); - return ty == FloatType ? NumberType : ty; // promote floats - } else if ((isNumberType(left) && isStringType(right)) || - (isNumberType(right) && isStringType(left))) - return IR::StringType; - else - return IR::InvalidType; -} - -bool isRealType(IR::Type type) -{ - return type == IR::NumberType || type == IR::FloatType; -} - const char *opname(AluOp op) { switch (op) { @@ -194,9 +147,6 @@ void Const::dump(QTextStream &out) case QQmlJS::IR::NullType: out << "null"; break; - case QQmlJS::IR::VoidType: - out << "void"; - break; case QQmlJS::IR::BoolType: out << (value ? "true" : "false"); break; @@ -232,18 +182,16 @@ QString String::escape(const QString &s) return r; } -void Name::init(Type type, const QString *id, quint32 line, quint32 column) +void Name::init(const QString *id, quint32 line, quint32 column) { - this->type = type; this->id = id; this->builtin = builtin_invalid; this->line = line; this->column = column; } -void Name::init(Type type, Builtin builtin, quint32 line, quint32 column) +void Name::init(Builtin builtin, quint32 line, quint32 column) { - this->type = type; this->id = 0; this->builtin = builtin; this->line = line; @@ -281,24 +229,6 @@ void Unop::dump(QTextStream &out) expr->dump(out); } -Type Unop::typeForOp(AluOp op, Expr *expr) -{ - switch (op) { - case OpIfTrue: return BoolType; - case OpNot: return BoolType; - - case OpUMinus: - case OpUPlus: - case OpCompl: - return maxType(expr->type, NumberType); - - default: - break; - } - - return InvalidType; -} - void Binop::dump(QTextStream &out) { left->dump(out); @@ -306,65 +236,6 @@ void Binop::dump(QTextStream &out) right->dump(out); } -Type Binop::typeForOp(AluOp op, Expr *left, Expr *right) -{ - if (! (left && right)) - return InvalidType; - - switch (op) { - case OpInvalid: - return InvalidType; - - // unary operators - case OpIfTrue: - case OpNot: - case OpUMinus: - case OpUPlus: - case OpCompl: - return InvalidType; - - // bit fields - case OpBitAnd: - case OpBitOr: - case OpBitXor: - return IntType; - - case OpAdd: - if (left->type == StringType) - return StringType; - return NumberType; - - case OpSub: - case OpMul: - case OpDiv: - case OpMod: - return NumberType; - - case OpLShift: - case OpRShift: - case OpURShift: - return IntType; - - case OpAnd: - case OpOr: - return BoolType; - - case OpGt: - case OpLt: - case OpGe: - case OpLe: - case OpEqual: - case OpNotEqual: - case OpStrictEqual: - case OpStrictNotEqual: - case OpInstanceof: - case OpIn: - return BoolType; - } // switch - - return InvalidType; -} - void Call::dump(QTextStream &out) { base->dump(out); @@ -377,11 +248,6 @@ void Call::dump(QTextStream &out) out << ')'; } -Type Call::typeForFunction(Expr *) -{ - return InvalidType; -} - void New::dump(QTextStream &out) { out << "new "; @@ -395,11 +261,6 @@ void New::dump(QTextStream &out) out << ')'; } -Type New::typeForFunction(Expr *) -{ - return InvalidType; -} - void Subscript::dump(QTextStream &out) { base->dump(out); @@ -522,11 +383,11 @@ unsigned BasicBlock::newTemp() Temp *BasicBlock::TEMP(int index) { Temp *e = function->New(); - e->init(IR::InvalidType, index); + e->init(index); return e; } -Expr *BasicBlock::CONST(Type type, double value) +Expr *BasicBlock::CONST(Type type, double value) { Const *e = function->New(); e->init(type, value); @@ -543,21 +404,21 @@ Expr *BasicBlock::STRING(const QString *value) Name *BasicBlock::NAME(const QString &id, quint32 line, quint32 column) { Name *e = function->New(); - e->init(InvalidType, function->newString(id), line, column); + e->init(function->newString(id), line, column); return e; } Name *BasicBlock::NAME(Name::Builtin builtin, quint32 line, quint32 column) { Name *e = function->New(); - e->init(InvalidType, builtin, line, column); + e->init(builtin, line, column); return e; } Closure *BasicBlock::CLOSURE(Function *function) { Closure *clos = function->New(); - clos->init(IR::InvalidType, function); + clos->init(function); return clos; } @@ -694,13 +555,13 @@ Stmt *BasicBlock::CJUMP(Expr *cond, BasicBlock *iftrue, BasicBlock *iffalse) return s; } -Stmt *BasicBlock::RET(Temp *expr, Type type) +Stmt *BasicBlock::RET(Temp *expr) { if (isTerminated()) return 0; Ret *s = function->New(); - s->init(expr, type); + s->init(expr); statements.append(s); return s; } diff --git a/qv4ir_p.h b/qv4ir_p.h index c5e2af9e1..ef9d80131 100644 --- a/qv4ir_p.h +++ b/qv4ir_p.h @@ -146,28 +146,11 @@ AluOp binaryOperator(int op); const char *opname(IR::AluOp op); enum Type { - InvalidType, UndefinedType, NullType, - VoidType, - StringType, - UrlType, - ColorType, - SGAnchorLineType, - AttachType, - ObjectType, - VariantType, - VarType, - - FirstNumberType, - BoolType = FirstNumberType, - IntType, - FloatType, + BoolType, NumberType }; -Type maxType(IR::Type left, IR::Type right); -bool isRealType(IR::Type type); -const char *typeName(IR::Type t); struct ExprVisitor { virtual ~ExprVisitor() {} @@ -196,9 +179,6 @@ struct StmtVisitor { }; struct Expr { - Type type; - - Expr(): type(InvalidType) {} virtual ~Expr() {} virtual void accept(ExprVisitor *) = 0; virtual Const *asConst() { return 0; } @@ -227,6 +207,7 @@ struct ExprList { }; struct Const: Expr { + Type type; double value; void init(Type type, double value) @@ -246,7 +227,6 @@ struct String: Expr { void init(const QString *value) { - this->type = StringType; this->value = value; } @@ -271,8 +251,8 @@ struct Name: Expr { quint32 line; quint32 column; - void init(Type type, const QString *id, quint32 line, quint32 column); - void init(Type type, Builtin builtin, quint32 line, quint32 column); + void init(const QString *id, quint32 line, quint32 column); + void init(Builtin builtin, quint32 line, quint32 column); virtual void accept(ExprVisitor *v) { v->visitName(this); } virtual Name *asName() { return this; } @@ -283,9 +263,8 @@ struct Name: Expr { struct Temp: Expr { int index; - void init(Type type, int index) + void init(int index) { - this->type = type; this->index = index; } @@ -298,9 +277,8 @@ struct Temp: Expr { struct Closure: Expr { Function *value; - void init(Type type, Function *value) + void init(Function *value) { - this->type = type; this->value = value; } @@ -316,7 +294,6 @@ struct Unop: Expr { void init(AluOp op, Temp *expr) { - this->type = this->typeForOp(op, expr); this->op = op; this->expr = expr; } @@ -325,9 +302,6 @@ struct Unop: Expr { virtual Unop *asUnop() { return this; } virtual void dump(QTextStream &out); - -private: - static Type typeForOp(AluOp op, Expr *expr); }; struct Binop: Expr { @@ -337,7 +311,6 @@ struct Binop: Expr { void init(AluOp op, Temp *left, Temp *right) { - this->type = typeForOp(op, left, right); this->op = op; this->left = left; this->right = right; @@ -347,8 +320,6 @@ struct Binop: Expr { virtual Binop *asBinop() { return this; } virtual void dump(QTextStream &out); - - static Type typeForOp(AluOp op, Expr *left, Expr *right); }; struct Call: Expr { @@ -357,7 +328,6 @@ struct Call: Expr { void init(Expr *base, ExprList *args) { - this->type = typeForFunction(base); this->base = base; this->args = args; } @@ -372,9 +342,6 @@ struct Call: Expr { virtual Call *asCall() { return this; } virtual void dump(QTextStream &out); - -private: - static Type typeForFunction(Expr *base); }; struct New: Expr { @@ -383,7 +350,6 @@ struct New: Expr { void init(Expr *base, ExprList *args) { - this->type = typeForFunction(base); this->base = base; this->args = args; } @@ -398,9 +364,6 @@ struct New: Expr { virtual New *asNew() { return this; } virtual void dump(QTextStream &out); - -private: - static Type typeForFunction(Expr *base); }; struct Subscript: Expr { @@ -409,7 +372,6 @@ struct Subscript: Expr { void init(Temp *base, Temp *index) { - this->type = typeForFunction(base); this->base = base; this->index = index; } @@ -418,9 +380,6 @@ struct Subscript: Expr { virtual Subscript *asSubscript() { return this; } virtual void dump(QTextStream &out); - -private: - static Type typeForFunction(Expr *) { return IR::InvalidType; } }; struct Member: Expr { @@ -429,7 +388,6 @@ struct Member: Expr { void init(Temp *base, const QString *name) { - this->type = typeForFunction(base); this->base = base; this->name = name; } @@ -438,9 +396,6 @@ struct Member: Expr { virtual Member *asMember() { return this; } virtual void dump(QTextStream &out); - -private: - static Type typeForFunction(Expr *) { return IR::InvalidType; } }; struct Stmt { @@ -571,12 +526,10 @@ struct CJump: Stmt { struct Ret: Stmt { Temp *expr; - Type type; - void init(Temp *expr, Type type) + void init(Temp *expr) { this->expr = expr; - this->type = type; } virtual Stmt *asTerminator() { return this; } @@ -700,7 +653,7 @@ struct BasicBlock { Stmt *JUMP(BasicBlock *target); Stmt *CJUMP(Expr *cond, BasicBlock *iftrue, BasicBlock *iffalse); - Stmt *RET(Temp *expr, Type type); + Stmt *RET(Temp *expr); void dump(QTextStream &out, Stmt::Mode mode = Stmt::HIR); };