Skip to content

Commit

Permalink
Remove @each (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccir committed Mar 7, 2023
1 parent 946c89b commit 89e9cbc
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 328 deletions.
70 changes: 0 additions & 70 deletions src/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,73 +922,6 @@ generate()
}
}

function handleNSEachStatement(node)
{
if (language === LanguageTypechecker) {
let object = "";

if (node.left.type == Syntax.VariableDeclaration) {
object = node.left.kind + " " + node.left.declarations[0].id.name;
} else {
object = node.left.name;
}

modifier.from(node).to(node.right).replace("for (" + object + " = N$_atEachGetMember(");
modifier.from(node.right).to(node.body).replace(") ; N$_atEachTest() ; ) ");

} else {
let i = makeTemporaryVariable(false);
let length = makeTemporaryVariable(false);

let object, array;
let initLeft = "var ";
let initRight = "";
let expr = false;

// The left side is "var foo", "let foo", etc
if (node.left.type == Syntax.VariableDeclaration) {
object = node.left.declarations[0].id.name;
initLeft = node.left.kind + " " + object + ", ";

// The left side is just an identifier
} else if (node.left.type == Syntax.Identifier) {
if (currentClass && currentClass.isIvar(node.left.name, true)) {
Utils.throwError(NSError.RestrictedUsage, `Cannot use ivar "${node.left.name}" on left-hand side of @each`, node);
}

object = node.left.name;
}

// The right side is a simple identifier
if (node.right.type == Syntax.Identifier && currentClass && !currentClass.isIvar(node.right.name, true)) {
array = node.right.name;

// The right side is an expression, we need an additional variable
} else {
array = makeTemporaryVariable(false);
initLeft += array + " = (";
initRight = initRight + "), ";
expr = true;
}

initRight += i + " = 0, " + length + " = (" + array + " ? " + array + ".length : 0)";

let test = i + " < " + length;
let increment = i + "++";

if (expr) {
modifier.from(node).to(node.right).replace("for (" + initLeft);
modifier.from(node.right).to(node.body).replace(initRight + "; " + test + "; " + increment + ") ");
} else {
modifier.from(node).to(node.body).replace("for (" + initLeft + initRight + "; " + test + "; " + increment + ") ");
}

if (node.body.body.length) {
modifier.from(node.body).to(node.body.body[0]).insert("{" + object + " = " + array + "[" + i + "];");
}
}
}

function handleNSGlobalDeclaration(node)
{
let declaration = node.declaration;
Expand Down Expand Up @@ -1177,9 +1110,6 @@ generate()
} else if (type === Syntax.NSTypeAnnotation) {
handleNSTypeAnnotation(node, parent);

} else if (type === Syntax.NSEachStatement) {
handleNSEachStatement(node);

} else if (type === Syntax.NSGlobalDeclaration) {
handleNSGlobalDeclaration(node);

Expand Down
32 changes: 0 additions & 32 deletions test/issues/TestIssue41.ns

This file was deleted.

60 changes: 0 additions & 60 deletions test/issues/TestIssue59.ns

This file was deleted.

13 changes: 0 additions & 13 deletions test/issues/TestIssue89.ns

This file was deleted.

153 changes: 0 additions & 153 deletions test/single/Each.ns

This file was deleted.

0 comments on commit 89e9cbc

Please sign in to comment.