Tweaked some identifier checks

This commit is contained in:
2022-10-08 17:35:41 +01:00
parent 0b4a6097be
commit 2b0e71b6fb

View File

@@ -221,16 +221,11 @@ static int nativeInitNode(Interpreter* interpreter, LiteralArray* arguments) {
Literal node = popLiteralArray(arguments); Literal node = popLiteralArray(arguments);
Literal nodeIdn = node; //annoying Literal nodeIdn = node;
if (IS_IDENTIFIER(node) && parseIdentifierToValue(interpreter, &node)) {
if (!parseIdentifierToValue(interpreter, &node)) { freeLiteral(nodeIdn);
interpreter->errorOutput("Failed to parse node identifier to value\n");
freeLiteral(node);
return -1;
} }
freeLiteral(nodeIdn);
//check argument types //check argument types
if (!IS_OPAQUE(node)) { if (!IS_OPAQUE(node)) {
interpreter->errorOutput("Incorrect argument type passed to initNode\n"); interpreter->errorOutput("Incorrect argument type passed to initNode\n");
@@ -256,16 +251,11 @@ static int nativeFreeNode(Interpreter* interpreter, LiteralArray* arguments) {
Literal node = popLiteralArray(arguments); Literal node = popLiteralArray(arguments);
Literal nodeIdn = node; //annoying Literal nodeIdn = node;
if (IS_IDENTIFIER(node) && parseIdentifierToValue(interpreter, &node)) {
if (!parseIdentifierToValue(interpreter, &node)) { freeLiteral(nodeIdn);
interpreter->errorOutput("Failed to parse node identifier to value\n");
freeLiteral(node);
return -1;
} }
freeLiteral(nodeIdn);
//check argument types //check argument types
if (!IS_OPAQUE(node)) { if (!IS_OPAQUE(node)) {
interpreter->errorOutput("Incorrect argument type passed to freeNode\n"); interpreter->errorOutput("Incorrect argument type passed to freeNode\n");
@@ -277,8 +267,7 @@ static int nativeFreeNode(Interpreter* interpreter, LiteralArray* arguments) {
//free the node //free the node
callEngineNode(engineNode, &engine.interpreter, "onFree"); callEngineNode(engineNode, &engine.interpreter, "onFree");
freeEngineNode(engineNode);
freeEngineNode(engineNode); //tombstones this node
//cleanup //cleanup
freeLiteral(node); freeLiteral(node);
@@ -295,15 +284,10 @@ static int nativeFreeChildNode(Interpreter* interpreter, LiteralArray* arguments
Literal node = popLiteralArray(arguments); Literal node = popLiteralArray(arguments);
Literal nodeIdn = node; //annoying Literal nodeIdn = node; //annoying
if (IS_IDENTIFIER(node) && parseIdentifierToValue(interpreter, &node)) {
if (!parseIdentifierToValue(interpreter, &node)) { freeLiteral(nodeIdn);
interpreter->errorOutput("Failed to parse parent node identifier to value\n");
freeLiteral(node);
return -1;
} }
freeLiteral(nodeIdn);
//check argument types //check argument types
if (!IS_OPAQUE(node) || !IS_INTEGER(index)) { if (!IS_OPAQUE(node) || !IS_INTEGER(index)) {
interpreter->errorOutput("Incorrect argument type passed to freeChildNode\n"); interpreter->errorOutput("Incorrect argument type passed to freeChildNode\n");
@@ -349,26 +333,16 @@ static int nativePushNode(Interpreter* interpreter, LiteralArray* arguments) {
Literal child = popLiteralArray(arguments); Literal child = popLiteralArray(arguments);
Literal parent = popLiteralArray(arguments); Literal parent = popLiteralArray(arguments);
Literal parentIdn = parent; //annoying Literal parentIdn = parent;
if (IS_IDENTIFIER(parent) && parseIdentifierToValue(interpreter, &parent)) {
freeLiteral(parentIdn);
}
Literal childIdn = child; Literal childIdn = child;
if (IS_IDENTIFIER(child) && parseIdentifierToValue(interpreter, &child)) {
if (!parseIdentifierToValue(interpreter, &parent)) { freeLiteral(childIdn);
interpreter->errorOutput("Failed to parse parent identifier to value\n");
freeLiteral(parent);
freeLiteral(child);
return -1;
} }
if (!parseIdentifierToValue(interpreter, &child)) {
interpreter->errorOutput("Failed to parse child identifier to value\n");
freeLiteral(parent);
freeLiteral(child);
return -1;
}
freeLiteral(parentIdn);
freeLiteral(childIdn);
if (!IS_OPAQUE(parent) || !IS_OPAQUE(child)) { if (!IS_OPAQUE(parent) || !IS_OPAQUE(child)) {
interpreter->errorOutput("Incorrect argument type passed to pushNode\n"); interpreter->errorOutput("Incorrect argument type passed to pushNode\n");
freeLiteral(parent); freeLiteral(parent);
@@ -399,17 +373,11 @@ static int nativeGetNode(Interpreter* interpreter, LiteralArray* arguments) {
Literal index = popLiteralArray(arguments); Literal index = popLiteralArray(arguments);
Literal parent = popLiteralArray(arguments); Literal parent = popLiteralArray(arguments);
Literal parentIdn = parent; //annoying Literal parentIdn = parent;
if (IS_IDENTIFIER(parent) && parseIdentifierToValue(interpreter, &parent)) {
if (!parseIdentifierToValue(interpreter, &parent)) { freeLiteral(parentIdn);
interpreter->errorOutput("Failed to parse parent identifier to value\n");
freeLiteral(parent);
freeLiteral(index);
return -1;
} }
freeLiteral(parentIdn);
if (!IS_OPAQUE(parent) || !IS_INTEGER(index)) { if (!IS_OPAQUE(parent) || !IS_INTEGER(index)) {
interpreter->errorOutput("Incorrect argument type passed to getNode\n"); interpreter->errorOutput("Incorrect argument type passed to getNode\n");
freeLiteral(parent); freeLiteral(parent);