From ea920b48c8fe3a0cc9769174fd208f9db8abb7ee Mon Sep 17 00:00:00 2001 From: "rogerl%netscape.com" Date: Fri, 23 Jun 2000 21:20:03 +0000 Subject: [PATCH] Add return statement if the function doesn't end with one --- js/js2/icodegenerator.cpp | 24 +++++++++++++++++++----- js/js2/icodegenerator.h | 1 + js2/src/icodegenerator.cpp | 24 +++++++++++++++++++----- js2/src/icodegenerator.h | 1 + 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/js/js2/icodegenerator.cpp b/js/js2/icodegenerator.cpp index 54c24dc3143c..060fdde354e4 100644 --- a/js/js2/icodegenerator.cpp +++ b/js/js2/icodegenerator.cpp @@ -113,6 +113,17 @@ ICodeModule *ICodeGenerator::complete() ASSERT((*i)->mOffset <= iCode->size()); } #endif + + + if (iCode->size()) { + ICodeOp lastOp = (*iCode)[iCode->size() - 1]->op(); + if ((lastOp != RETURN) && (lastOp != RETURN_VOID)) + returnStmt(); + } + else + returnStmt(); + + /* XXX FIXME I wanted to do the following rather than have to have the label set hanging around as well @@ -397,10 +408,12 @@ GenericBranch *ICodeGenerator::branchFalse(Label *label, TypedRegister condition void ICodeGenerator::returnStmt(TypedRegister r) { - if (r.first == NotARegister) - iCode->push_back(new ReturnVoid()); - else - iCode->push_back(new Return(r)); + iCode->push_back(new Return(r)); +} + +void ICodeGenerator::returnStmt() +{ + iCode->push_back(new ReturnVoid()); } @@ -588,7 +601,8 @@ TypedRegister ICodeGenerator::genExpr(ExprNode *p, if (i->op->getKind() == ExprNode::dot) { BinaryExprNode *b = static_cast(i->op); - ret = methodCall(genExpr(b->op1), loadString(static_cast(b->op2)->name), args); + TypedRegister base = genExpr(b->op1); + ret = methodCall(base, loadString(static_cast(b->op2)->name), args); } else if (i->op->getKind() == ExprNode::identifier) { diff --git a/js/js2/icodegenerator.h b/js/js2/icodegenerator.h index 44e5a5a63fec..f26a2ebcc16e 100644 --- a/js/js2/icodegenerator.h +++ b/js/js2/icodegenerator.h @@ -200,6 +200,7 @@ namespace ICG { void isScript() { mWithinWith = true; } void returnStmt(TypedRegister r); + void returnStmt(); void throwStmt(TypedRegister r) { iCode->push_back(new Throw(r)); } diff --git a/js2/src/icodegenerator.cpp b/js2/src/icodegenerator.cpp index 54c24dc3143c..060fdde354e4 100644 --- a/js2/src/icodegenerator.cpp +++ b/js2/src/icodegenerator.cpp @@ -113,6 +113,17 @@ ICodeModule *ICodeGenerator::complete() ASSERT((*i)->mOffset <= iCode->size()); } #endif + + + if (iCode->size()) { + ICodeOp lastOp = (*iCode)[iCode->size() - 1]->op(); + if ((lastOp != RETURN) && (lastOp != RETURN_VOID)) + returnStmt(); + } + else + returnStmt(); + + /* XXX FIXME I wanted to do the following rather than have to have the label set hanging around as well @@ -397,10 +408,12 @@ GenericBranch *ICodeGenerator::branchFalse(Label *label, TypedRegister condition void ICodeGenerator::returnStmt(TypedRegister r) { - if (r.first == NotARegister) - iCode->push_back(new ReturnVoid()); - else - iCode->push_back(new Return(r)); + iCode->push_back(new Return(r)); +} + +void ICodeGenerator::returnStmt() +{ + iCode->push_back(new ReturnVoid()); } @@ -588,7 +601,8 @@ TypedRegister ICodeGenerator::genExpr(ExprNode *p, if (i->op->getKind() == ExprNode::dot) { BinaryExprNode *b = static_cast(i->op); - ret = methodCall(genExpr(b->op1), loadString(static_cast(b->op2)->name), args); + TypedRegister base = genExpr(b->op1); + ret = methodCall(base, loadString(static_cast(b->op2)->name), args); } else if (i->op->getKind() == ExprNode::identifier) { diff --git a/js2/src/icodegenerator.h b/js2/src/icodegenerator.h index 44e5a5a63fec..f26a2ebcc16e 100644 --- a/js2/src/icodegenerator.h +++ b/js2/src/icodegenerator.h @@ -200,6 +200,7 @@ namespace ICG { void isScript() { mWithinWith = true; } void returnStmt(TypedRegister r); + void returnStmt(); void throwStmt(TypedRegister r) { iCode->push_back(new Throw(r)); }