return UnknownRange;
}
-types::Function::ReturnValue sci_existsOrIsdef(types::typed_list &in, int _iRetCount, types::typed_list &out, const char* fname)
+static types::Function::ReturnValue isdef(types::typed_list& in, int _iRetCount, types::typed_list& out, const char* fname)
{
- types::String* pStrIn = NULL;
+ types::String* pStrIn = NULL;
if (in.size() != 1 && in.size() != 2)
{
psScope = in[1]->getAs<types::String>()->get(0);
}
- pStrIn = in[0]->getAs<types::String>();
- if (strcmp(fname, "exists") == 0)
- {
- types::Double* pDblOut = new types::Double(pStrIn->getDims(), pStrIn->getDimsArray());
- switch (getScopeFromOption(psScope))
- {
- case All:
- for (int i = 0; i < pStrIn->getSize(); i++)
- {
- symbol::Context::getInstance()->get(symbol::Symbol(pStrIn->get(i))) ? pDblOut->set(i, 1) : pDblOut->set(i, 0);
- }
- break;
- case Local:
- for (int i = 0; i < pStrIn->getSize(); i++)
- {
- symbol::Context::getInstance()->getCurrentLevel(symbol::Symbol(pStrIn->get(i))) ? pDblOut->set(i, 1) : pDblOut->set(i, 0);
- }
- break;
- case NoLocal:
- for (int i = 0; i < pStrIn->getSize(); i++)
- {
- symbol::Context::getInstance()->getAllButCurrentLevel(symbol::Symbol(pStrIn->get(i))) ? pDblOut->set(i, 1) : pDblOut->set(i, 0);
- }
- break;
- default :
- Scierror(36, _("%s: Wrong input argument %d.\n"), fname, 2);
- return types::Function::Error;
- }
+ pStrIn = in[0]->getAs<types::String>();
- out.push_back(pDblOut);
- }
- else
- {
- types::Bool* pBOut = new types::Bool(pStrIn->getDims(), pStrIn->getDimsArray());
- switch (getScopeFromOption(psScope))
- {
- case All:
- for (int i = 0; i < pStrIn->getSize(); i++)
- {
- symbol::Context::getInstance()->get(symbol::Symbol(pStrIn->get(i))) ? pBOut->set(i, 1) : pBOut->set(i, 0);
- }
- break;
- case Local:
- for (int i = 0; i < pStrIn->getSize(); i++)
- {
- symbol::Context::getInstance()->getCurrentLevel(symbol::Symbol(pStrIn->get(i))) ? pBOut->set(i, 1) : pBOut->set(i, 0);
- }
- break;
- case NoLocal:
- for (int i = 0; i < pStrIn->getSize(); i++)
- {
- symbol::Context::getInstance()->getAllButCurrentLevel(symbol::Symbol(pStrIn->get(i))) ? pBOut->set(i, 1) : pBOut->set(i, 0);
- }
- break;
- default :
- Scierror(36, _("%s: Wrong input argument %d.\n"), fname, 2);
- return types::Function::Error;
- }
+ types::InternalType *pIT;
+ types::Bool* pBOut = new types::Bool(pStrIn->getDims(), pStrIn->getDimsArray());
- out.push_back(pBOut);
+ switch (getScopeFromOption(psScope))
+ {
+ case All:
+ for (int i = 0; i < pStrIn->getSize(); i++)
+ {
+ pIT = symbol::Context::getInstance()->get(symbol::Symbol(pStrIn->get(i)));
+ pBOut->set(i, pIT != NULL && pIT->getType() != types::InternalType::ScilabVoid);
+ }
+ break;
+ case Local:
+ for (int i = 0; i < pStrIn->getSize(); i++)
+ {
+ pIT = symbol::Context::getInstance()->getCurrentLevel(symbol::Symbol(pStrIn->get(i)));
+ pBOut->set(i, pIT != NULL && pIT->getType() != types::InternalType::ScilabVoid);
+ }
+ break;
+ case NoLocal:
+ for (int i = 0; i < pStrIn->getSize(); i++)
+ {
+ pIT = symbol::Context::getInstance()->getAllButCurrentLevel(symbol::Symbol(pStrIn->get(i)));
+ pBOut->set(i, pIT != NULL && pIT->getType() != types::InternalType::ScilabVoid);
+ }
+ break;
+ default:
+ Scierror(36, _("%s: Wrong input argument %d.\n"), fname, 2);
+ return types::Function::Error;
}
+ out.push_back(pBOut);
+
return types::Function::OK;
}
-types::Function::ReturnValue sci_exists(types::typed_list &in, int _iRetCount, types::typed_list &out)
+types::Function::ReturnValue sci_isdef(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
- return sci_existsOrIsdef(in, _iRetCount, out, "exists");
+ return isdef(in, _iRetCount, out, "isdef");
}
-types::Function::ReturnValue sci_isdef(types::typed_list &in, int _iRetCount, types::typed_list &out)
+types::Function::ReturnValue sci_exists(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
- return sci_existsOrIsdef(in, _iRetCount, out, "isdef");
+ types::Function::ReturnValue retVal = isdef(in, _iRetCount, out, "exists");
+
+ if (retVal == types::Function::OK)
+ {
+ types::Bool* pBOut = out[0]->getAs<types::Bool>();
+ types::Double* pDblOut = new types::Double(pBOut->getDims(), pBOut->getDimsArray());
+ for (int i = 0; i < pBOut->getSize(); i++)
+ {
+ pDblOut->set(i, (double)pBOut->get(i));
+ }
+
+ pBOut->killMe();
+ out.pop_back();
+ out.push_back(pDblOut);
+ }
+
+ return retVal;
}
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2018 - Stéphane MOTTELET
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+//
+//
+// <-- Non-regression test for bug 15310 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=15310
+//
+// <-- Short Description -->
+// unlike isdef(varargin(k),"l"), isdef(argin,"l") now always returns %t even for unpassed arguments (REGRESSION)
+
+function out=f(_x,_y)
+ out=isdef(['_x','_y'],'local')
+endfunction
+
+function out=g(_x,_y)
+ out=exists(['_x','_y'],'local')
+endfunction
+
+assert_checkequal(f(,), [%f,%f])
+assert_checkequal(f(,2), [%f,%t])
+assert_checkequal(f(1,), [%t,%f])
+
+assert_checkequal(g(,), [0,0])
+assert_checkequal(g(,2), [0,1])
+assert_checkequal(g(1,), [1,0])