Fixes to loop handling & equality ops.

This commit is contained in:
rogerl%netscape.com 2002-09-12 07:34:22 +00:00
Родитель 3506d96f8d
Коммит 3110f38597
3 изменённых файлов: 75 добавлений и 25 удалений

Просмотреть файл

@ -148,28 +148,71 @@ namespace MetaData {
}
break;
case StmtNode::Break:
case StmtNode::Continue:
{
GoStmtNode *g = checked_cast<GoStmtNode *>(p);
bool found = false;
if (g->name) {
// Make sure the name is on the targetList as a viable break/continue target...
for (TargetListIterator si = targetList.begin(), end = targetList.end(); (si != end); si++) {
if (g->name) {
// Make sure the name is on the targetList as a viable break target...
if ((*si)->getKind() == StmtNode::label) {
if (checked_cast<LabelStmtNode *>(*si)->name == *g->name) {
LabelStmtNode *l = checked_cast<LabelStmtNode *>(*si);
if (l->name == *g->name) {
g->tgtID = &l->labelID;
found = true;
break;
}
}
}
else {
// any non-label statement will do
if ((*si)->getKind() != StmtNode::label) {
if (((*si)->getKind() == StmtNode::While) || ((*si)->getKind() == StmtNode::DoWhile)) {
UnaryStmtNode *w = checked_cast<UnaryStmtNode *>(*si);
g->tgtID = &w->breakLabelID;
}
else
ASSERT(false); // XXX for, forin && switch
found = true;
break;
}
}
}
else // so long as the targetList isn't empty we're fine...
found = !targetList.empty();
if (!found)
reportError(Exception::syntaxError,
(p->getKind() == StmtNode::Break) ? "No such break target available"
: "No such continue target available",
p->pos);
reportError(Exception::syntaxError, "No such break target available", p->pos);
}
break;
case StmtNode::Continue:
{
GoStmtNode *g = checked_cast<GoStmtNode *>(p);
bool found = false;
for (TargetListIterator si = targetList.begin(), end = targetList.end(); (si != end); si++) {
if (g->name) {
// Make sure the name is on the targetList as a viable continue target...
if ((*si)->getKind() == StmtNode::label) {
LabelStmtNode *l = checked_cast<LabelStmtNode *>(*si);
if (l->name == *g->name) {
g->tgtID = &l->labelID;
found = true;
break;
}
}
}
else {
// any non-label statement will do
if ((*si)->getKind() != StmtNode::label) {
if (((*si)->getKind() == StmtNode::While) || ((*si)->getKind() == StmtNode::DoWhile)) {
UnaryStmtNode *w = checked_cast<UnaryStmtNode *>(*si);
g->tgtID = &w->continueLabelID;
}
else
ASSERT(false); // XXX for, forin && switch
found = true;
break;
}
}
}
if (!found)
reportError(Exception::syntaxError, "No such break target available", p->pos);
}
break;
case StmtNode::Return:
@ -513,6 +556,12 @@ namespace MetaData {
bCon->setLabel(skipOverFalseStmt);
}
break;
case StmtNode::Break:
{
GoStmtNode *g = checked_cast<GoStmtNode *>(p);
bCon->emitBranch(eBranch, *g->tgtID, p->pos);
}
break;
case StmtNode::While:
{
UnaryStmtNode *w = checked_cast<UnaryStmtNode *>(p);

Просмотреть файл

@ -64,6 +64,7 @@
}
break;
case eNotEqual:
case eEqual:
{
bool rval;
@ -76,12 +77,11 @@
if (JS2VAL_IS_BOOLEAN(b))
rval = (JS2VAL_TO_BOOLEAN(a) == JS2VAL_TO_BOOLEAN(b));
else {
js2val ap = toNumber(a);
js2val bp = toPrimitive(b);
if (JS2VAL_IS_NULL(bp) || JS2VAL_IS_UNDEFINED(bp))
rval = false;
else
rval = float64Compare(a, toNumber(bp));
rval = (toNumber(a) == toNumber(bp));
}
}
else
@ -90,7 +90,7 @@
if (JS2VAL_IS_NULL(bp) || JS2VAL_IS_UNDEFINED(bp))
rval = false;
else
rval = float64Compare(a, toNumber(bp));
rval = (toNumber(a) == toNumber(bp));
}
else
if (JS2VAL_IS_STRING(a)) {
@ -99,7 +99,7 @@
rval = false;
else
if (JS2VAL_IS_BOOLEAN(bp) || JS2VAL_IS_NUMBER(bp))
rval = float64Compare();
rval = (toNumber(a) == toNumber(bp));
else
rval = (*JS2VAL_TO_STRING(a) == *JS2VAL_TO_STRING(bp));
}
@ -114,11 +114,8 @@
else
if (JS2VAL_IS_BOOLEAN(ap))
rval = (JS2VAL_TO_BOOLEAN(ap) == JS2VAL_TO_BOOLEAN(b));
else {
ap = toNumber(ap);
js2val bp = toNumber(b);
rval = float64Compare(ap, bp);
}
else
rval = (toNumber(ap) == toNumber(b));
}
else
if (JS2VAL_IS_NUMBER(b)) {
@ -126,7 +123,7 @@
if (JS2VAL_IS_NULL(ap) || JS2VAL_IS_UNDEFINED(ap))
rval = false;
else
rval = float64Compare(toNumber(ap), JS2VAL_TO_NUMBER(b));
rval = (toNumber(ap) == toNumber(b));
}
else
if (JS2VAL_IS_STRING(b)) {
@ -135,16 +132,17 @@
rval = false;
else
if (JS2VAL_IS_BOOLEAN(ap) || JS2VAL_IS_NUMBER(ap))
rval = float64Compare(toNumber(ap), toNumber(b));
rval = (toNumber(ap) == toNumber(b));
else
rval = (*JS2VAL_TO_STRING(ap) == *JS2VAL_TO_STRING(b));
}
else
rval = (JS2VAL_TO_OBJECT(a) == JS2VAL_TO_OBJECT(b));
push(BOOL_TO_JS2VAL(rval));
if (op == eEqual)
push(BOOLEAN_TO_JS2VAL(rval));
else
push(BOOLEAN_TO_JS2VAL(!rval));
}
break;

Просмотреть файл

@ -625,6 +625,9 @@ namespace JavaScript {
GoStmtNode(size_t pos, Kind kind, const StringAtom *name): StmtNode(pos, kind), name(name) {}
void print(PrettyPrinter &f, bool noSemi) const;
#ifdef EPIMETHEUS
MetaData::LabelID *tgtID;
#endif
};
struct CatchClause: ParseNode {