Implemented the nullish concatenation and assignment operators.

Implemented the missing logical operation plus assignment.


git-svn-id: http://yate.null.ro/svn/yate/trunk@6504 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2021-07-08 14:53:44 +00:00
parent 885ed0b8ae
commit 11bcd6a7f8
2 changed files with 26 additions and 0 deletions

View File

@ -44,6 +44,10 @@ static const TokenDict s_operators_c[] =
ASSIGN("&", And),
ASSIGN("|", Or),
ASSIGN("^", Xor),
ASSIGN("&&",LAnd),
ASSIGN("||",LOr),
ASSIGN("^^",LXor),
ASSIGN("??",Nullish),
MAKEOP("<<",Shl),
MAKEOP(">>",Shr),
MAKEOP("==",Eq),
@ -55,6 +59,7 @@ static const TokenDict s_operators_c[] =
MAKEOP("&&",LAnd),
MAKEOP("||",LOr),
MAKEOP("^^",LXor),
MAKEOP("??",Nullish),
MAKEOP("+", Add),
MAKEOP("-", Sub),
MAKEOP("*", Mul),
@ -1266,6 +1271,25 @@ bool ExpEvaluator::runOperation(ObjList& stack, const ExpOperation& oper, GenObj
TelEngine::destruct(op);
}
break;
case OpcNullish:
{
ExpOperation* op2 = popValue(stack,context);
ExpOperation* op1 = popValue(stack,context);
if (!op1 || !op2) {
TelEngine::destruct(op1);
TelEngine::destruct(op2);
return gotError("ExpEvaluator stack underflow",oper.lineNumber());
}
if (JsParser::isMissing(*op1)) {
TelEngine::destruct(op1);
pushOne(stack,op2);
}
else {
TelEngine::destruct(op2);
pushOne(stack,op1);
}
}
break;
case OpcFunc:
return runFunction(stack,oper,context) ||
gotError("Function '" + oper.name() + "' call failed",oper.lineNumber());

View File

@ -311,6 +311,8 @@ public:
OpcLabel, // ( --- )
// Push with deep copy
OpcCopy, // ( --- CopiedA)
// Nullish coalescing
OpcNullish, // (A B --- A??B)
// Field assignment - can be ORed with other binary operators
OpcAssign = 0x0100, // (A B --- B,(&A=B))
// Private extension area for derived classes