// ATOMS ===============================================================
if with_module("atoms") then
if sciargs() <> "-noatomsautoload" & isdef("atomsQuit") then
- //atomsQuit();
+ atomsQuit();
end
end
//if ((getscilabmode() == "NWNI" | getscilabmode() == "NW") & ~fromjava() & ~fromc() & sciargs()<>"-nb")
if ((getscilabmode() == "NWNI" | getscilabmode() == "NW") & sciargs()<>"-nb")
[v, opts] = getversion()
- printf(strsubst(v, "scilab-", "Scilab ") + " (" + opts($-1) + ", " + opts($) + ")");
+ printf(strsubst(v, "scilab-", "Scilab ") + " (" + opts($-1) + ", " + opts($) + ")\n");
clear v opts;
end
<Command>lib /DEF:"$(ProjectDir)core_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)Localization_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)scilocalization.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)elementary_functions_f.lib" 1>NUL 2>NUL
-lib /DEF:"$(ProjectDir)elementary_functions_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)elementary_functions.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)linpack_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)linpack_f.lib" 1>NUL 2>NUL
cd $(IntDir) >nul
</Command>
</PreLinkEvent>
<Link>
- <AdditionalDependencies>elementary_functions_f.lib;elementary_functions.lib;linpack_f.lib;core.lib;scilocalization.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>elementary_functions_f.lib;linpack_f.lib;core.lib;scilocalization.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
<ModuleDefinitionFile>api_scilab_export.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<Command>lib /DEF:"$(ProjectDir)core_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)Localization_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)scilocalization.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)elementary_functions_f.lib" 1>NUL 2>NUL
-lib /DEF:"$(ProjectDir)elementary_functions_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)elementary_functions.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)linpack_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)linpack_f.lib" 1>NUL 2>NUL
cd $(IntDir) >nul
</Command>
</PreLinkEvent>
<Link>
- <AdditionalDependencies>elementary_functions_f.lib;elementary_functions.lib;linpack_f.lib;core.lib;scilocalization.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>elementary_functions_f.lib;linpack_f.lib;core.lib;scilocalization.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
<ModuleDefinitionFile>api_scilab_export.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<Command>lib /DEF:"$(ProjectDir)core_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)Localization_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)scilocalization.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)elementary_functions_f.lib" 1>NUL 2>NUL
-lib /DEF:"$(ProjectDir)elementary_functions_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)elementary_functions.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)linpack_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)linpack_f.lib" 1>NUL 2>NUL
cd $(IntDir) >nul
</Command>
</PreLinkEvent>
<Link>
- <AdditionalDependencies>elementary_functions_f.lib;elementary_functions.lib;linpack_f.lib;core.lib;scilocalization.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>elementary_functions_f.lib;linpack_f.lib;core.lib;scilocalization.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
<ModuleDefinitionFile>api_scilab_export.def</ModuleDefinitionFile>
<GenerateDebugInformation>false</GenerateDebugInformation>
<Command>lib /DEF:"$(ProjectDir)core_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)core.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)Localization_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)scilocalization.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)elementary_functions_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)elementary_functions_f.lib" 1>NUL 2>NUL
-lib /DEF:"$(ProjectDir)elementary_functions_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)elementary_functions.lib" 1>NUL 2>NUL
lib /DEF:"$(ProjectDir)linpack_f_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)linpack_f.lib" 1>NUL 2>NUL
cd $(IntDir) >nul
</Command>
</PreLinkEvent>
<Link>
- <AdditionalDependencies>elementary_functions_f.lib;elementary_functions.lib;linpack_f.lib;core.lib;scilocalization.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>elementary_functions_f.lib;linpack_f.lib;core.lib;scilocalization.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
<ModuleDefinitionFile>api_scilab_export.def</ModuleDefinitionFile>
<GenerateDebugInformation>false</GenerateDebugInformation>
<ItemGroup>
<None Include="core_import.def" />
<None Include="elementary_functions_f_Import.def" />
- <None Include="elementary_functions_Import.def" />
<None Include="linpack_f_Import.def" />
<None Include="locales\api_scilab.pot" />
<None Include="Localization_Import.def" />
<None Include="linpack_f_Import.def">
<Filter>Libraries Dependencies\Imports</Filter>
</None>
- <None Include="elementary_functions_Import.def">
- <Filter>Libraries Dependencies\Imports</Filter>
- </None>
</ItemGroup>
</Project>
\ No newline at end of file
freeArrayOfString
isopt_
numopt_
-SciToF77
MyHeapAlloc
MyHeapFree
+++ /dev/null
-LIBRARY elementary_functions.dll
-
-
-EXPORTS
-SciToF77
}
using namespace std;
-using namespace types;
/********************************/
/* boolean matrix functions */
if (_piBool)
{
- *_piBool = ((InternalType*)_piAddress)->getAs<types::Bool>()->get();
+ *_piBool = ((types::InternalType*)_piAddress)->getAs<types::Bool>()->get();
}
return sciErr;
}
return sciErr;
}
- GatewayStruct* pStr = (GatewayStruct*)_pvCtx;
- typed_list in = *pStr->m_pIn;
- InternalType** out = pStr->m_pOut;
+ types::GatewayStruct* pStr = (types::GatewayStruct*)_pvCtx;
+ types::typed_list in = *pStr->m_pIn;
+ types::InternalType** out = pStr->m_pOut;
- Bool *pBool = new Bool(_iRows, _iCols);
+ types::Bool *pBool = new types::Bool(_iRows, _iCols);
if (pBool == NULL)
{
addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocated variable"), "allocMatrixOfBoolean");
C2F(dcopy)(&iSize, const_cast<double*>(&_pdblData->r), &iTwo, pdblReal, &iOne);
C2F(dcopy)(&iSize, const_cast<double*>(&_pdblData->i), &iOne, pdblImg, &iOne);
- symbol::Context::getInstance()->put(symbol::Symbol(pwstName), *pDbl);
+ symbol::Context::getInstance()->put(symbol::Symbol(pwstName), pDbl);
FREE(pwstName);
return sciErr;
}
C2F(dcopy)(&iSize, const_cast<double*>(_pdblImg), &iOne, pdblImg, &iOne);
}
- symbol::Context::getInstance()->put(symbol::Symbol(pwstName), *pDbl);
+ symbol::Context::getInstance()->put(symbol::Symbol(pwstName), pDbl);
FREE(pwstName);
return sciErr;
}
return sciErr;
}
- symbol::Context::getInstance()->put(symbol::Symbol(pwstName), *pIT);
+ symbol::Context::getInstance()->put(symbol::Symbol(pwstName), pIT);
FREE(pwstName);
return sciErr;
}
#include "gatewaystruct.hxx"
#include "pointer.hxx"
#include "context.hxx"
+#include "scilabexception.hxx"
extern "C"
{
wchar_t* pwstName = to_wide_string(_pstName);
Pointer* pP = new Pointer(_pvPtr);
- symbol::Context::getInstance()->put(symbol::Symbol(pwstName), *pP);
+ symbol::Context::getInstance()->put(symbol::Symbol(pwstName), pP);
FREE(pwstName);
return sciErr;
pP->setCoef(i, pD);
}
- symbol::Context::getInstance()->put(symbol::Symbol(pwstName), *pP);
+ symbol::Context::getInstance()->put(symbol::Symbol(pwstName), pP);
FREE(pwstName);
return sciErr;
}
}
wchar_t* pwstName = to_wide_string(_pstName);
- symbol::Context::getInstance()->put(symbol::Symbol(pwstName), *pS);
+ symbol::Context::getInstance()->put(symbol::Symbol(pwstName), pS);
FREE(pwstName);
return sciErr;
{
public :
ExpHistory();
- ExpHistory(ExpHistory*, const ast::SimpleVar*);
+ ExpHistory(ExpHistory*, ast::SimpleVar*);
ExpHistory(ExpHistory*, types::typed_list*);
- ExpHistory(ExpHistory*, const ast::SimpleVar*, types::typed_list*, int, bool, types::InternalType*);
+ ExpHistory(ExpHistory*, ast::SimpleVar*, types::typed_list*, int, bool, types::InternalType*);
~ExpHistory();
// expression "a"
- void setExp(const ast::SimpleVar*);
- const ast::SimpleVar* getExp();
+ void setExp(ast::SimpleVar*);
+ ast::SimpleVar* getExp();
std::wstring getExpAsString();
// arguments x of a(x)
int* m_piArgsDimsArray;
int m_iArgsDims;
- const ast::SimpleVar* m_pExp;
+ ast::SimpleVar* m_pExp;
ExpHistory* m_pParent;
types::InternalType* m_pITCurrent;
** \{ */
public:
/** \brief Return the name of the size (read only). */
- const Exp& left_exp_get() const
+ Exp& left_exp_get() const
{
return *_left_exp;
}
}
/** \brief Return the name of the init (read only). */
- const Exp& right_exp_get() const
+ Exp& right_exp_get() const
{
return *_right_exp;
}
** \{ */
public:
/** \brief Return the implicit variable declaration (read only) */
- const VarDec& vardec_get () const
+ VarDec& vardec_get () const
{
return *_vardec;
}
_name (name),
_args (&args),
_returns (&returns),
- _body (&body)
+ _body (&body),
+ _stack(NULL)
{
}
virtual FunctionDec* clone()
{
Location* newloc = const_cast<Location*>(&location_get())->clone();
- FunctionDec* cloned = new FunctionDec(*newloc, *new symbol::Symbol(name_get().name_get()), *args_get().clone(), *returns_get().clone(), *body_get().clone());
+ FunctionDec* cloned = new FunctionDec(*newloc, name_get(), *args_get().clone(), *returns_get().clone(), *body_get().clone());
cloned->set_verbose(is_verbose());
return cloned;
}
_body = body;
}
+ symbol::Variable* stack_get()
+ {
+ if (_stack == NULL)
+ {
+ _stack = symbol::Context::getInstance()->getOrCreate(_name);
+ }
+
+ return _stack;
+ }
+
protected:
symbol::Symbol& _name;
+ symbol::Variable* _stack;
ArrayListVar* _args;
ArrayListVar* _returns;
Exp* _body;
#define AST_SIMPLEVAR_HXX
#include "var.hxx"
-#include "symbol.hxx"
+#include "context.hxx"
namespace ast
{
SimpleVar (const Location& location,
symbol::Symbol& name)
: Var (location),
- _name (name)
+ _name (name),
+ _stack(NULL)
{
}
/** \brief Destroy a Field Variable node.
{
return _name;
}
+
+ symbol::Variable* stack_get()
+ {
+ if (_stack == NULL)
+ {
+ _stack = symbol::Context::getInstance()->getOrCreate(_name);
+ }
+
+ return _stack;
+ }
/** \} */
protected:
/** \brief Variable's name */
symbol::Symbol& _name;
+ symbol::Variable* _stack;
};
} // namespace ast
#include <assert.h>
#include "dec.hxx"
-#include "symbol.hxx"
+#include "context.hxx"
namespace ast
{
symbol::Symbol& name, Exp& init)
: Dec (location),
_name (name),
- _init (&init)
+ _init (&init),
+ _stack(NULL)
{
}
virtual VarDec* clone()
{
Location* newloc = const_cast<Location*>(&location_get())->clone();
- VarDec* cloned = new VarDec(*newloc, *new symbol::Symbol(name_get().name_get()), *init_get().clone());
+ VarDec* cloned = new VarDec(*newloc, name_get(), *init_get().clone());
cloned->set_verbose(is_verbose());
return cloned;
}
return _name;
}
+ symbol::Variable* stack_get()
+ {
+ if (_stack == NULL)
+ {
+ _stack = symbol::Context::getInstance()->getOrCreate(_name);
+ }
+
+ return _stack;
+ }
+
/** \brief Return the initial expression value (read only). */
const Exp& init_get (void) const
{
protected:
/** \brief Name of the declared variable. */
symbol::Symbol& _name;
+ symbol::Variable* _stack;
/** \brief The initial value (expression) assigned to the variable. */
Exp* _init;
};
#include "overload.hxx"
#include "scilabWrite.hxx"
#include "context.hxx"
+#include "variables.hxx"
extern "C" {
#include "more.h"
_resultVect.push_back(NULL);
_result = NULL;
m_bSingleResult = true;
- m_pAns = new symbol::Symbol(L"ans");
+ m_pAns = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"ans"));
}
~RunVisitor()
types::InternalType* _result;
bool m_bSingleResult;
int _excepted_result;
- symbol::Symbol* m_pAns;
+ symbol::Variable* m_pAns;
};
template <class T>
void visitprivate(const SimpleVar &e)
{
- InternalType *pI = symbol::Context::getInstance()->get(e.name_get());
+ InternalType *pI = symbol::Context::getInstance()->get(((SimpleVar&)e).stack_get());
result_set(pI);
if (pI != NULL)
{
EXTERN_AST const std::wstring* getStructNameFromExp(const ast::Exp* _pExp);
-EXTERN_AST bool getFieldsFromExp(const ast::Exp* _pExp, std::list<ExpHistory*>& fields);
+EXTERN_AST bool getFieldsFromExp(ast::Exp* _pExp, std::list<ExpHistory*>& fields);
EXTERN_AST types::InternalType* evaluateFields(const ast::Exp* _pExp, std::list<ExpHistory*>& fields, types::InternalType* pIT);
#include "expHistory.hxx"
#include "types_tools.hxx"
#include "types.hxx"
+#include "context.hxx"
/**
** Constructor & Destructor (public)
}
-ExpHistory::ExpHistory(ExpHistory* _pEH, const ast::SimpleVar* _pExp)
+ExpHistory::ExpHistory(ExpHistory* _pEH, ast::SimpleVar* _pExp)
{
initHistory();
m_pParent = _pParent;
}
-ExpHistory::ExpHistory(ExpHistory* _pParent, const ast::SimpleVar* _pExp, types::typed_list* _pArgs, int _iLevel, bool _bCellExp, types::InternalType* _pITCurrent)
+ExpHistory::ExpHistory(ExpHistory* _pParent, ast::SimpleVar* _pExp, types::typed_list* _pArgs, int _iLevel, bool _bCellExp, types::InternalType* _pITCurrent)
{
initHistory();
** Accessor (public)
*/
-void ExpHistory::setExp(const ast::SimpleVar* _pExp)
+void ExpHistory::setExp(ast::SimpleVar* _pExp)
{
m_pExp = _pExp;
}
-const ast::SimpleVar* ExpHistory::getExp()
+ast::SimpleVar* ExpHistory::getExp()
{
return m_pExp;
}
}
else
{
- for (int i = 0; i < std::min(m_iArgsDims, m_pITCurrent->getAs<types::GenericType>()->getDims()); i++)
+ for (int i = 0; i < Min(m_iArgsDims, m_pITCurrent->getAs<types::GenericType>()->getDims()); i++)
{
- m_piArgsDimsArray[i] = std::max(m_piArgsDimsArray[i], piDimsArray[i]);
+ m_piArgsDimsArray[i] = Max(m_piArgsDimsArray[i], piDimsArray[i]);
}
}
}
bool ExpHistory::isCellExp()
{
return m_bCellExp;
-}
\ No newline at end of file
+}
try
{
/*get king of left hand*/
- const SimpleVar *pVar = dynamic_cast<const SimpleVar*>(&e.left_exp_get());
+ SimpleVar *pVar = dynamic_cast<SimpleVar*>(&e.left_exp_get());
if (pVar)
{
// x = ?
std::wostringstream os;
os << _W("Can not assign multiple value in a single variable") << std::endl;
//os << ((Location)e.right_exp_get().location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, e.right_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_exp_get().location_get());
}
pIT = result_get();
if (pReturn)
{
//ReturnExp so, put the value in the previous scope
- symbol::Context::getInstance()->putInPreviousScope(pVar->name_get(), *pIT);
+ symbol::Context::getInstance()->putInPreviousScope(pVar->stack_get(), pIT);
((AssignExp*)&e)->return_set();
}
else
{
- symbol::Context::getInstance()->put(pVar->name_get(), *pIT);
+ symbol::Context::getInstance()->put(pVar->stack_get(), pIT);
}
if (e.is_verbose() && ConfigVariable::isPromptShow())
return;
}
- const CellCallExp *pCell = dynamic_cast<const CellCallExp*>(&e.left_exp_get());
+ CellCallExp *pCell = dynamic_cast<CellCallExp*>(&e.left_exp_get());
if (pCell)
{
InternalType *pOut = NULL;
// if the right hand is NULL.
std::wostringstream os;
os << _W("Unable to extract right part expression.\n");
- throw ScilabError(os.str(), 999, e.left_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.left_exp_get().location_get());
}
std::list<ExpHistory*> fields;
{
std::wostringstream os;
os << _W("Get fields from expression failed.");
- throw ScilabError(os.str(), 999, e.right_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_exp_get().location_get());
}
pOut = evaluateFields(pCell, fields, pITR);
{
std::wostringstream os;
os << _W("Fields evaluation failed.");
- throw ScilabError(os.str(), 999, e.right_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_exp_get().location_get());
}
if (pOut != NULL)
//manage error
std::wostringstream os;
os << _W("Invalid Index.\n");
- throw ScilabError(os.str(), 999, e.right_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_exp_get().location_get());
}
return;
}
- const CallExp *pCall = dynamic_cast<const CallExp*>(&e.left_exp_get());
+ CallExp *pCall = dynamic_cast<CallExp*>(&e.left_exp_get());
if (pCall)
{
//x(?) = ?
// if the right hand is NULL.
std::wostringstream os;
os << _W("Unable to extract right part expression.\n");
- throw ScilabError(os.str(), 999, e.left_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.left_exp_get().location_get());
}
std::list<ExpHistory*> fields;
{
std::wostringstream os;
os << _W("Get fields from expression failed.");
- throw ScilabError(os.str(), 999, e.right_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_exp_get().location_get());
}
pOut = evaluateFields(pCall, fields, pITR);
{
std::wostringstream os;
os << _W("Fields evaluation failed.");
- throw ScilabError(os.str(), 999, e.right_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_exp_get().location_get());
}
if (e.is_verbose() && ConfigVariable::isPromptShow())
return;
}
- const AssignListExp *pList = dynamic_cast<const AssignListExp*>(&e.left_exp_get());
+ AssignListExp *pList = dynamic_cast<AssignListExp*>(&e.left_exp_get());
if (pList)
{
//[x,y] = ?
std::wostringstream os;
os << _W("Incompatible assignation: trying to assign ") << exec.result_getSize();
os << _W(" values in ") << iLhsCount << _W(" variables.") << std::endl;
- throw ScilabError(os.str(), 999, e.right_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_exp_get().location_get());
}
std::list<Exp *>::const_reverse_iterator it;
return;
}
- const FieldExp *pField = dynamic_cast<const FieldExp*>(&e.left_exp_get());
+ FieldExp *pField = dynamic_cast<FieldExp*>(&e.left_exp_get());
if (pField)
{
//a.b = x
{
std::wostringstream os;
os << _W("Get fields from expression failed.");
- throw ScilabError(os.str(), 999, e.right_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_exp_get().location_get());
}
if (evaluateFields(pField, fields, pIT) == NULL)
{
std::wostringstream os;
os << _W("Fields evaluation failed.");
- throw ScilabError(os.str(), 999, e.right_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_exp_get().location_get());
}
if (e.is_verbose() && ConfigVariable::isPromptShow())
std::wostringstream os;
os << _W("unknow script form");
//os << ((Location)e.right_exp_get().location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, e.right_exp_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_exp_get().location_get());
}
- catch (ScilabError error)
+ catch (ast::ScilabError error)
{
throw error;
}
{
std::wostringstream os;
os << _W("Wrong number of output arguments.\n") << std::endl;
- throw ScilabError(os.str(), 999, e.location_get());
+ throw ast::ScilabError(os.str(), 999, e.location_get());
}
//get function arguments
{
std::wostringstream os;
os << _W("left side of optional parameter must be a variable") << std::endl;
- throw ScilabError(os.str(), 999, e.location_get());
+ throw ast::ScilabError(os.str(), 999, e.location_get());
}
Exp* pR = &pAssign->right_exp_get();
std::wostringstream os;
os << _W("bad lhs, expected : ") << iRetCount << _W(" returned : ") << out.size() << std::endl;
- throw ScilabError(os.str(), 999, e.location_get());
+ throw ast::ScilabError(os.str(), 999, e.location_get());
}
}
{
ConfigVariable::setLastErrorFunction(pCall->getName());
ConfigVariable::setLastErrorLine(e.location_get().first_line);
- throw ScilabError();
+ throw ast::ScilabError();
}
}
catch (ScilabMessage sm)
{
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), sm.GetErrorLocation().first_line, pCall->getName().c_str());
- throw ScilabMessage(szError);
+ throw ast::ScilabMessage(szError);
}
else
{
const SimpleVar *Var = dynamic_cast<const SimpleVar*>(&e.name_get());
if (Var != NULL)
{
- pIT = symbol::Context::getInstance()->get(Var->name_get());
+ pIT = symbol::Context::getInstance()->get(((SimpleVar*)Var)->stack_get());
}
else
{
//try to call specific exrtaction function
ret = Overload::call(L"%" + pIT->getAs<TList>()->getShortTypeStr() + L"_e", in, 1, ResultList, this);
}
- catch (ScilabError /*&e*/)
+ catch (ast::ScilabError /*&e*/)
{
//if call failed try to call generic extraction function
ret = Overload::call(L"%l_e", in, 1, ResultList, this);
{
std::wostringstream os;
os << _W("Invalid index.\n");
- throw ScilabError(os.str(), 999, (*e.args_get().begin())->location_get());
+ throw ast::ScilabError(os.str(), 999, (*e.args_get().begin())->location_get());
}
break;
case 1 :
}
else
{
- throw ScilabError();
+ throw ast::ScilabError();
}
break;
}
//try to call specific exrtaction function
ret = Overload::call(L"%" + pIT->getAs<MList>()->getShortTypeStr() + L"_e", in, 1, ResultList, this);
}
- catch (ScilabError /*&e*/)
+ catch (ast::ScilabError /*&e*/)
{
//if call failed try to call generic extraction function
ret = Overload::call(L"%l_e", in, 1, ResultList, this);
{
std::wostringstream os;
os << _W("Invalid index.\n");
- throw ScilabError(os.str(), 999, (*e.args_get().begin())->location_get());
+ throw ast::ScilabError(os.str(), 999, (*e.args_get().begin())->location_get());
}
break;
case 1 :
}
else
{
- throw ScilabError();
+ throw ast::ScilabError();
}
break;
}
{
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("Field \"%ls\" does not exists\n"), wstField.c_str());
- throw ScilabError(szError, 999, (*e.args_get().begin())->location_get());
+ throw ast::ScilabError(szError, 999, (*e.args_get().begin())->location_get());
}
}
in.push_back(pS);
in.push_back(pH);
- Function* pCall = (Function*)symbol::Context::getInstance()->get(symbol::Symbol(L"%h_e"));
+ static symbol::Variable* h_e = NULL;
+ if (h_e == NULL)
+ {
+ h_e = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"%h_e"));
+ }
+
+ Function* pCall = (Function*)symbol::Context::getInstance()->get(h_e);
Callable::ReturnValue ret = pCall->call(in, opt, 1, out, this);
if (ret == Callable::OK)
{
std::wostringstream os;
os << _W("Invalid index.\n");
//os << ((*e.args_get().begin())->location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, (*e.args_get().begin())->location_get());
+ throw ast::ScilabError(os.str(), 999, (*e.args_get().begin())->location_get());
}
}
result_set(pOut);
std::wostringstream os;
os << _W("inconsistent row/column dimensions\n");
//os << ((*e.args_get().begin())->location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, (*e.args_get().begin())->location_get());
+ throw ast::ScilabError(os.str(), 999, (*e.args_get().begin())->location_get());
}
}
}
if (pIT->isCell() == false)
{
- throw ScilabError(_W("[error] Cell contents reference from a non-cell array object.\n"), 999, (*e.args_get().begin())->location_get());
+ throw ast::ScilabError(_W("[error] Cell contents reference from a non-cell array object.\n"), 999, (*e.args_get().begin())->location_get());
}
//Create list of indexes
types::typed_list *pArgs = GetArgumentList(e.args_get());
std::wostringstream os;
os << _W("inconsistent row/column dimensions\n");
//os << ((*e.args_get().begin())->location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, (*e.args_get().begin())->location_get());
+ throw ast::ScilabError(os.str(), 999, (*e.args_get().begin())->location_get());
}
if (pList->getSize() == 1)
{
std::wostringstream os;
os << _W("unable to concatenate\n");
- throw ScilabError(os.str(), 999, (*col)->location_get());
+ throw ast::ScilabError(os.str(), 999, (*col)->location_get());
}
GenericType* pGT = pIT->getAs<GenericType>();
{
std::wostringstream os;
os << _W("inconsistent row/column dimensions\n");
- throw ScilabError(os.str(), 999, (*row)->location_get());
+ throw ast::ScilabError(os.str(), 999, (*row)->location_get());
}
// if we concatenate [Double Sparse], transform the Double to Sparse and perform [Sparse Sparse]
{
std::wostringstream os;
os << _W("inconsistent row/column dimensions\n");
- throw ScilabError(os.str(), 999, (*e.lines_get().begin())->location_get());
+ throw ast::ScilabError(os.str(), 999, (*e.lines_get().begin())->location_get());
}
// if we concatenate [Double Sparse], transform the Double to Sparse and perform [Sparse Sparse]
result_set(Double::Empty());
}
}
- catch (ScilabError error)
+ catch (ast::ScilabError error)
{
throw error;
}
std::wostringstream os;
os << _W("Incompatible output argument.\n");
//os << ((Location)e.right_get().location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, e.right_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_get().location_get());
}
/*getting what to assign*/
std::wostringstream os;
os << _W("Incompatible output argument.\n");
//os << ((Location)e.right_get().location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, e.right_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_get().location_get());
}
if (pITL->getType() == GenericType::ScilabImplicitList)
delete pITR;
}
}
- catch (ScilabError error)
+ catch (ast::ScilabError error)
{
result_clear();
error.SetErrorLocation(e.location_get());
std::wostringstream os;
os << _W("Incompatible output argument.\n");
//os << ((Location)e.right_get().location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, e.right_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_get().location_get());
}
result_set(NULL);
std::wostringstream os;
os << _W("Incompatible output argument.\n");
//os << ((Location)e.right_get().location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, e.right_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_get().location_get());
}
if (pITR->getType() == GenericType::ScilabImplicitList)
std::wostringstream os;
os << _W("Incompatible output argument.\n");
//os << ((Location)e.right_get().location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, e.right_get().location_get());
+ throw ast::ScilabError(os.str(), 999, e.right_get().location_get());
}
if (pITR->getType() == GenericType::ScilabImplicitList)
delete pITR;
}
}
- catch (ScilabError error)
+ catch (ast::ScilabError error)
{
result_clear();
error.SetErrorLocation(e.location_get());
for (int i = 0 ; i < pVar->getSize() ; i++)
{
pIL = pVar->extractValue(i);
- symbol::Context::getInstance()->put(varName, *pIL);
+ symbol::Context::getInstance()->put(e.vardec_get().stack_get(), pIL);
e.body_get().accept(*this);
if (e.body_get().is_break())
for (int i = 0 ; i < pL->getSize() ; i++)
{
InternalType* pNew = pL->get(i);
- symbol::Context::getInstance()->put(e.vardec_get().name_get(), *pNew);
+ symbol::Context::getInstance()->put(e.vardec_get().stack_get(), pNew);
e.body_get().accept(*this);
if (e.body_get().is_break())
{
for (int i = 0 ; i < pVar->getCols() ; i++)
{
GenericType* pNew = pVar->getColumnValues(i);
- symbol::Context::getInstance()->put(e.vardec_get().name_get(), *pNew);
+ symbol::Context::getInstance()->put(e.vardec_get().stack_get(), pNew);
e.body_get().accept(*this);
if (e.body_get().is_break())
{
{
//symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *execMe.result_get());
InternalType* pITAns = result_get();
- symbol::Context::getInstance()->put(*m_pAns, *pITAns);
+ symbol::Context::getInstance()->put(m_pAns, pITAns);
if ((*itExp)->is_verbose() && ConfigVariable::isPromptShow())
{
//TODO manage multiple returns
// funcprot(2) : error
if (ConfigVariable::getFuncprot() == 1 && ConfigVariable::getWarningMode())
{
- types::InternalType* pITFunc = symbol::Context::getInstance()->get(symbol::Symbol(e.name_get().name_get()));
+ types::InternalType* pITFunc = symbol::Context::getInstance()->get(((FunctionDec&)e).stack_get());
if (pITFunc && pITFunc->isCallable())
{
}
else if (ConfigVariable::getFuncprot() == 2)
{
- types::InternalType* pITFunc = symbol::Context::getInstance()->get(symbol::Symbol(e.name_get().name_get()));
+ types::InternalType* pITFunc = symbol::Context::getInstance()->get(((FunctionDec&)e).stack_get());
if (pITFunc && pITFunc->isCallable())
{
std::list<Var *>::const_iterator i;
//get input parameters list
- std::list<symbol::Symbol> *pVarList = new std::list<symbol::Symbol>();
+ std::list<symbol::Variable*> *pVarList = new std::list<symbol::Variable*>();
const ArrayListVar *pListVar = &e.args_get();
for (i = pListVar->vars_get().begin() ; i != pListVar->vars_get().end() ; i++)
{
- pVarList->push_back(static_cast<SimpleVar*>(*i)->name_get());
+ pVarList->push_back(static_cast<SimpleVar*>(*i)->stack_get());
}
//get output parameters list
- std::list<symbol::Symbol> *pRetList = new std::list<symbol::Symbol>();
+ std::list<symbol::Variable*> *pRetList = new std::list<symbol::Variable*>();
const ArrayListVar *pListRet = &e.returns_get();
for (i = pListRet->vars_get().begin() ; i != pListRet->vars_get().end() ; i++)
{
- pRetList->push_back(static_cast<SimpleVar*>(*i)->name_get());
+ pRetList->push_back(static_cast<SimpleVar*>(*i)->stack_get());
}
// Location* newloc = const_cast<Location*>(&location_get())->clone();
types::Macro *pMacro = new types::Macro(e.name_get().name_get(), *pVarList, *pRetList,
static_cast<SeqExp&>(*exp), L"script");
pMacro->setFirstLine(e.location_get().first_line);
- symbol::Context::getInstance()->AddMacro(pMacro);
+ symbol::Context::getInstance()->addMacro(pMacro);
}
template <class T>
#include "alltypes.hxx"
-using namespace types;
-using namespace ast;
-
-size_t Ast::globalNodeNumber = 0;
+size_t ast::Ast::globalNodeNumber = 0;
static bool isIntTrue(InternalType* _pIT);
bool bConditionState(types::InternalType *_pITResult)
return NULL;
}
-const std::wstring* getStructNameFromExp(const Exp* _pExp)
+const std::wstring* getStructNameFromExp(const ast::Exp* _pExp)
{
- const FieldExp* pField = dynamic_cast<const FieldExp*>(_pExp);
- const SimpleVar* pVar = dynamic_cast<const SimpleVar*>(_pExp);
- const CallExp* pCall = dynamic_cast<const CallExp*>(_pExp);
+ const ast::FieldExp* pField = dynamic_cast<const ast::FieldExp*>(_pExp);
+ const ast::SimpleVar* pVar = dynamic_cast<const ast::SimpleVar*>(_pExp);
+ const ast::CallExp* pCall = dynamic_cast<const ast::CallExp*>(_pExp);
if (pField)
{
std::wostringstream os;
os << _W("Unknow expression");
//os << ((Location)e.right_exp_get().location_get()).location_getString() << std::endl;
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
return NULL;
}
//i1, ..., in : indexes
//dest : variable where insert data || NULL
//source : data to insert || extract indexes from source
-types::InternalType* callOverload(const Exp& e, std::wstring _strType, types::typed_list* _pArgs, types::InternalType* _source, types::InternalType* _dest)
+types::InternalType* callOverload(const ast::Exp& e, std::wstring _strType, types::typed_list* _pArgs, types::InternalType* _source, types::InternalType* _dest)
{
types::InternalType* pITOut = NULL;
types::typed_list in;
// For insertion in TList, call normal insertion if overload doesn't exits
if ((_dest && _dest->isTList() && pFunc == NULL) == false || _source->isListDelete())
{
- ExecVisitor exec;
+ ast::ExecVisitor exec;
if (Overload::call(function_name, in, 1, out, &exec))
{
//manage error
std::wostringstream os;
os << _W("Error in overload function: ") << function_name << std::endl;
- throw ScilabError(os.str(), 999, e.location_get());
+ throw ast::ScilabError(os.str(), 999, e.location_get());
}
}
}
-bool getFieldsFromExp(const Exp* _pExp, std::list<ExpHistory*>& fields)
+bool getFieldsFromExp(ast::Exp* _pExp, std::list<ExpHistory*>& fields)
{
- const FieldExp* pField = dynamic_cast<const FieldExp*>(_pExp);
- const SimpleVar* pVar = dynamic_cast<const SimpleVar*>(_pExp);
- const CallExp* pCall = dynamic_cast<const CallExp*>(_pExp);
- const CellCallExp* pCell = dynamic_cast<const CellCallExp*>(_pExp);
+ ast::FieldExp* pField = dynamic_cast<ast::FieldExp*>(_pExp);
+ ast::SimpleVar* pVar = dynamic_cast<ast::SimpleVar*>(_pExp);
+ ast::CallExp* pCall = dynamic_cast<ast::CallExp*>(_pExp);
+ ast::CellCallExp* pCell = dynamic_cast<ast::CellCallExp*>(_pExp);
if (pField)
{
}
else if (pCall)
{
- ExecVisitor execMe;
+ ast::ExecVisitor execMe;
typed_list* pCurrentArgs = execMe.GetArgumentList(pCall->args_get());
bool bErr = getFieldsFromExp(&pCall->name_get(), fields);
}
}
-types::InternalType* evaluateFields(const Exp* _pExp, std::list<ExpHistory*>& fields, InternalType* _pAssignValue)
+types::InternalType* evaluateFields(const ast::Exp* _pExp, std::list<ExpHistory*>& fields, InternalType* _pAssignValue)
{
std::list<ExpHistory*> evalFields;
{
// a{x}, where "a" doesn't exists
pIT = new Cell(1, 1);
- symbol::Context::getInstance()->put(pFirstField->getExp()->name_get(), *pIT);
+ symbol::Context::getInstance()->put(pFirstField->getExp()->stack_get(), pIT);
}
else if (fields.size() > 1)
{
//"a" does not exist or it is another type, create it with size 1,1 and return it
//create new structure variable
pIT = new Struct(1, 1);
- symbol::Context::getInstance()->put(pFirstField->getExp()->name_get(), *pIT);
+ symbol::Context::getInstance()->put(pFirstField->getExp()->stack_get(), pIT);
}
// else
// is a call exp
else if (pIT->getRef() > 1 && pIT->isHandle() == false)
{
pIT = pIT->clone();
- symbol::Context::getInstance()->put(pFirstField->getExp()->name_get(), *pIT);
+ symbol::Context::getInstance()->put(pFirstField->getExp()->stack_get(), pIT);
}
else if (pIT == _pAssignValue)
{
{
std::wostringstream os;
os << _W("Wrong insertion : use extraction with {} only on a Cell.");
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
if (pITCurrent->isStruct())
{
std::wostringstream os;
os << _W("Invalid index.");
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
// resize current struct
{
std::wostringstream os;
os << _W("Invalid index.");
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
// resize current Cell
{
std::wostringstream os;
os << _W("Invalid index.");
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
// resize current Cell
// only a(x)
std::wostringstream os;
os << _W("Wrong insertion in a Cell.");
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
}
}
{
std::wostringstream os;
os << _W("Wrong insertion in a Cell.");
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
}
else
{
std::wostringstream os;
os << _W("Wrong insertion in a Cell.");
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
pCell->insertCell(pArgs, _pAssignValue);
{
std::wostringstream os;
os << _W("Error in insertion of Struct.");
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
if (pEH->setCurrent(pIT))
{
std::wostringstream os;
os << _W("Error in insertion of TList.");
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
if (pEH->getParent()->setCurrent(pIT))
if (pEHParent == NULL)
{
- symbol::Context::getInstance()->put(pEH->getExp()->name_get(), *pEH->getCurrent());
+ symbol::Context::getInstance()->put(pEH->getExp()->stack_get(), pEH->getCurrent());
break;
}
{
std::wostringstream os;
os << _W("Error in insertion of Struct.");
- throw ScilabError(os.str(), 999, _pExp->location_get());
+ throw ast::ScilabError(os.str(), 999, _pExp->location_get());
}
if (pEHParent->setCurrent(pIT))
return symbol::Context::getInstance()->getCurrentLevel(pFirstField->getExp()->name_get());
}
-InternalType* insertionCall(const Exp& e, typed_list* _pArgs, InternalType* _pVar, InternalType* _pInsert)
+InternalType* insertionCall(const ast::Exp& e, typed_list* _pArgs, InternalType* _pVar, InternalType* _pInsert)
{
InternalType* pOut = NULL;
//fisrt extract implicit list
//manage error
std::wostringstream os;
os << _W("Invalid Index.\n");
- throw ScilabError(os.str(), 999, e.location_get());
+ throw ast::ScilabError(os.str(), 999, e.location_get());
}
pStr->addField(pS->get(0));
//manage error
std::wostringstream os;
os << _W("Invalid Index.\n");
- throw ScilabError(os.str(), 999, e.location_get());
+ throw ast::ScilabError(os.str(), 999, e.location_get());
}
pStruct->addField(pS->get(0));
//manage error
std::wostringstream os;
os << _W("Invalid Index.\n");
- throw ScilabError(os.str(), 999, e.location_get());
+ throw ast::ScilabError(os.str(), 999, e.location_get());
}
if (_pInsert->isListDelete())
typed_list in;
typed_list out;
optional_list opt;
- ExecVisitor exec;
+ ast::ExecVisitor exec;
in.push_back(pH);
in.push_back(pS);
void callOnPrompt(void)
{
+ static symbol::Variable* onPrompt = NULL;
+
+ if (onPrompt == NULL)
+ {
+ onPrompt = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"%onprompt"));
+ }
+
types::InternalType* pOnPrompt = NULL;
- pOnPrompt = symbol::Context::getInstance()->get(symbol::Symbol(L"%onprompt"));
+ pOnPrompt = onPrompt->get();
if (pOnPrompt != NULL && pOnPrompt->isCallable())
{
types::typed_list in;
types::typed_list out;
types::optional_list opt;
- ExecVisitor execCall;
+ ast::ExecVisitor execCall;
pOnPrompt->getAs<types::Callable>()->call(in, opt, 1, out, &execCall);
}
}
-List* getPropertyTree(Exp* e, List* pList)
+List* getPropertyTree(ast::Exp* e, List* pList)
{
//a.b
- SimpleVar* pVar = dynamic_cast<SimpleVar*>(e);
+ ast::SimpleVar* pVar = dynamic_cast<ast::SimpleVar*>(e);
if (pVar)
{
pList->append(new String(pVar->name_get().name_get().c_str()));
}
//a(x).b
- CallExp* pCall = dynamic_cast<CallExp*>(e);
+ ast::CallExp* pCall = dynamic_cast<ast::CallExp*>(e);
if (pCall)
{
pList = getPropertyTree(&pCall->name_get(), pList);
- ExecVisitor exec;
- std::list<Exp*> l = pCall->args_get();
- std::list<Exp*>::const_iterator it;
+ ast::ExecVisitor exec;
+ std::list<ast::Exp*> l = pCall->args_get();
+ std::list<ast::Exp*>::const_iterator it;
for (it = l.begin() ; it != l.end() ; it++)
{
- Exp* pArg = (*it);
+ ast::Exp* pArg = (*it);
try
{
pArg->accept(exec);
pList->append(exec.result_get());
exec.result_clear();
}
- catch (ScilabException e)
+ catch (ast::ScilabException e)
{
throw e;
}
}
//a.b.c
- FieldExp* pField = dynamic_cast<FieldExp*>(e);
+ ast::FieldExp* pField = dynamic_cast<ast::FieldExp*>(e);
if (pField)
{
pList = getPropertyTree(pField->head_get(), pList);
#define __SCI_TOOLS_H__
#include "machine.h"
-#include "dynlib_elementary_functions.h"
+#include "dynlib_core.h"
#define DATA_TYPE_SCALAR 1
#define SET_NB_COL(ptr,m) (((int*) (ptr))[-2] = (m))
#define SET_NB_ROW(ptr,n) (((int*) (ptr))[-3] = (n))
-ELEMENTARY_FUNCTIONS_IMPEXP void SciToF77(double *ptr, int size, int lda);
-ELEMENTARY_FUNCTIONS_IMPEXP void F77ToSci(double *ptr, int size, int lda);
-
-ELEMENTARY_FUNCTIONS_IMPEXP void double2z(double *ptr, double *ptr77z, int size, int lda);
-ELEMENTARY_FUNCTIONS_IMPEXP void z2double(double *ptrz, double *ptrsci, int size, int lda);
+//CORE_IMPEXP void SciToF77(double *ptr, int size, int lda);
+//CORE_IMPEXP void F77ToSci(double *ptr, int size, int lda);
+//
+//CORE_IMPEXP void double2z(double *ptr, double *ptr77z, int size, int lda);
+//CORE_IMPEXP void z2double(double *ptrz, double *ptrsci, int size, int lda);
#endif /* __SCI_TOOLS_H__ */
#include "machine.h"
-/**
- * Convert an Scilab array of double to a fortran format
- *
- * @param ptr the array of double
- * @param size size of the array
- * @param lda
- */
-//void SciToF77(double *ptr, int size, int lda);
-
-/**
- * Convert an Fortran array of double to a Scilab format
- *
- * @param ptr the array of double
- * @param size size of the array
- * @param lda
- */
-void F77ToSci(double *ptr, int size, int lda);
-void double2z(double *ptr, double *ptr77z, int size, int lda);
-void z2double(double *ptrz, double *ptrsci, int size, int lda);
-
/* from int */
extern int C2F(tpconv)(int *, int *, int *, void *, int *, void *, int *);
types::Function::ReturnValue sci_argn(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
+ static symbol::Variable* varIn = NULL;
+ static symbol::Variable* varOut = NULL;
+
int iRhs = static_cast<int>(in.size());
//check input arguments
if (iRhs > 1)
}
symbol::Context* pContext = symbol::Context::getInstance();
- InternalType *pOut = pContext->get(symbol::Symbol(L"nargout"));
- InternalType *pIn = pContext->get(symbol::Symbol(L"nargin"));
+
+ InternalType *pIn = NULL;
+ InternalType *pOut = NULL;
+
+ if (varIn == NULL)
+ {
+ varIn = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"nargin"));
+ }
+
+ if (varOut == NULL)
+ {
+ varOut = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"nargout"));
+ }
+
+ pIn = pContext->get(varIn);
+ pOut = pContext->get(varOut);
if (pIn == NULL || pOut == NULL)
{
types::typed_list::iterator inIterator;
int iWrongType = 1;
+ if (in.size() == 0)
+ {
+ //clear();
+ symbol::Context::getInstance()->removeAll();
+ return Function::OK;
+ }
+
// First check if all arguments are Single Strings.
for (inIterator = in.begin() ; inIterator != in.end() ; iWrongType++, inIterator++)
{
for (int i = 0 ; i < in.size() ; i++)
{
- symbol::Symbol pstVar = *new symbol::Symbol(in[i]->getAs<types::String>()->get(0));
+ symbol::Symbol pstVar(symbol::Symbol(in[i]->getAs<types::String>()->get(0)));
- //does it visible in current global scope
- if (pCtx->isGlobalVisible(pstVar) == false)
+ if (pCtx->isGlobalVisible(pstVar))
{
- //does it exist in global
- if (pCtx->isGlobalExists(pstVar) == false)
- {
- InternalType* pIT = pCtx->get(pstVar);
+ continue;
+ }
+
+ types::InternalType* pIT = NULL;
- //create a empty global variable => []
- pCtx->createEmptyGlobalValue(pstVar);
+ if (pCtx->isGlobal(pstVar))
+ {
+ pIT = pCtx->getGlobalValue(pstVar);
+ }
+ else
+ {
+ pIT = pCtx->getCurrentLevel(pstVar);
+ pCtx->setGlobal(pstVar);
+ }
- //set visible in current global scope
- pCtx->setGlobalVisible(pstVar);
+ //set global variable visible in current scope
+ pCtx->setGlobalVisible(pstVar, true);
- if (pIT)
- {
- //assign old local value
- pCtx->put(pstVar, *pIT);
- }
- }
- else
- {
- //set visible in current global scope
- pCtx->setGlobalVisible(pstVar);
- }
+ if (pIT)
+ {
+ //assign local value to new global variable
+ pCtx->put(pstVar, pIT);
}
+ else
+ {
+ pCtx->put(pstVar, types::Double::Empty());
+ }
+
}
return types::Function::OK;
}
return Function::Error;
}
- if (symbol::Context::getInstance()->isGlobalExists(symbol::Symbol(pS->get(0))))
+ if (symbol::Context::getInstance()->isGlobalVisible(symbol::Symbol(pS->get(0))))
{
out.push_back(new types::Bool(1));
}
*/
+#include <sstream>
#include "core_gw.hxx"
#include "function.hxx"
#include "context.hxx"
<ClInclude Include="..\..\includes\scimem.h" />
<ClInclude Include="..\..\includes\scirun.h" />
<ClInclude Include="..\..\includes\scisparse.h" />
+ <ClInclude Include="..\..\includes\sci_tools.h" />
<ClInclude Include="..\..\includes\sci_types.h" />
<ClInclude Include="..\..\includes\setformat.h" />
<ClInclude Include="..\..\includes\setieee.h" />
<ClInclude Include="..\..\includes\getmacrosname.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\includes\sci_tools.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\core.iss" />
#include "localization.h"
#include "Scierror.h"
-void SciToF77(double *ptr, int size, int lda)
-{
- int i;
- double *tab;
-
- if ((tab = (double *) MALLOC(size * sizeof(double))) == NULL)
- {
- Scierror(999, _("%s: No more memory.\n"), "SciToF77");
- return;
- }
-
- /* for (i = size; --i >= 0; ) { */
- /* tab[i] = ptr[i]; */
- /* } */
-
- memcpy(tab, ptr, size * sizeof(double));
-
- for (i = 0; i < size; ++i)
- {
- ptr[2 * i] = tab[i];
- ptr[2 * i + 1] = ptr[lda + i];
- }
-
- FREE(tab);
-} /* SciToF77 */
-
-
-void F77ToSci(double *ptr, int size, int lda)
-{
- int i;
- double *tab;
-
- if ((tab = (double *) MALLOC(size * sizeof(double))) == NULL)
- {
- Scierror(999, _("%s: No more memory.\n"), "F77ToSci");
- return;
- }
-
- for (i = 0; i < size; ++i)
- {
- tab[i] = ptr[2 * i + 1];
- ptr[i] = ptr[2 * i];
- }
-
- memcpy(ptr + lda, tab, size * sizeof(double));
-
- /* for (i = size; --i >= 0; ) { */
- /* ptr[lda+i] = tab[i]; */
- /* } */
-
- FREE(tab);
-} /* F77ToSci */
+//void SciToF77(double *ptr, int size, int lda)
+//{
+// int i;
+// double *tab;
+//
+// if ((tab = (double *) MALLOC(size * sizeof(double))) == NULL)
+// {
+// Scierror(999, _("%s: No more memory.\n"), "SciToF77");
+// return;
+// }
+//
+// /* for (i = size; --i >= 0; ) { */
+// /* tab[i] = ptr[i]; */
+// /* } */
+//
+// memcpy(tab, ptr, size * sizeof(double));
+//
+// for (i = 0; i < size; ++i)
+// {
+// ptr[2 * i] = tab[i];
+// ptr[2 * i + 1] = ptr[lda + i];
+// }
+//
+// FREE(tab);
+//} /* SciToF77 */
+//
+//
+//void F77ToSci(double *ptr, int size, int lda)
+//{
+// int i;
+// double *tab;
+//
+// if ((tab = (double *) MALLOC(size * sizeof(double))) == NULL)
+// {
+// Scierror(999, _("%s: No more memory.\n"), "F77ToSci");
+// return;
+// }
+//
+// for (i = 0; i < size; ++i)
+// {
+// tab[i] = ptr[2 * i + 1];
+// ptr[i] = ptr[2 * i];
+// }
+//
+// memcpy(ptr + lda, tab, size * sizeof(double));
+//
+// /* for (i = size; --i >= 0; ) { */
+// /* ptr[lda+i] = tab[i]; */
+// /* } */
+//
+// FREE(tab);
+//} /* F77ToSci */
/* double2z and z2double : same as above with two pointers dest and src
double2z ptr = src, ptr77z = dest (z format)
z2double ptr = src (z format) , ptrsci = dest */
-void
-double2z(double *ptr, double *ptr77z, int size, int lda)
-{
- int i;
- double *tab;
-
- if ((tab = (double *) MALLOC(size * sizeof(double))) == NULL)
- {
- Scierror(999, _("%s: No more memory.\n"), "double2z");
- return;
- }
-
- memcpy(tab, ptr, size * sizeof(double));
-
- for (i = 0; i < size; ++i)
- {
- ptr77z[2 * i] = tab[i];
- ptr77z[2 * i + 1] = ptr[lda + i];
- }
-
- FREE(tab);
-}
+//void double2z(double *ptr, double *ptr77z, int size, int lda)
+//{
+// int i;
+// double *tab;
+//
+// if ((tab = (double *) MALLOC(size * sizeof(double))) == NULL)
+// {
+// Scierror(999, _("%s: No more memory.\n"), "double2z");
+// return;
+// }
+//
+// memcpy(tab, ptr, size * sizeof(double));
+//
+// for (i = 0; i < size; ++i)
+// {
+// ptr77z[2 * i] = tab[i];
+// ptr77z[2 * i + 1] = ptr[lda + i];
+// }
+//
+// FREE(tab);
+//}
//
// The Scilab internal representation is block-ordered, that is
// R1, ..., Rn, I1, ..., In.
//
-void
-z2double(double *ptrz, double *ptrsci, int size, int lda)
-{
- int i;
- double *tab;
-
- if ((tab = (double *) MALLOC(size * sizeof(double))) == NULL)
- {
- Scierror(999, _("%s: No more memory.\n"), "z2double");
- return;
- }
- // Put the real parts in place and stores the imaginary parts
- // in the array tab.
- for (i = 0; i < size; ++i)
- {
- tab[i] = ptrz[2 * i + 1]; // imaginary part
- ptrsci[i] = ptrz[2 * i]; // real part
- }
- // Puts the imaginary parts in the imaginary block.
- memcpy(ptrsci + lda, tab, size * sizeof(double));
-
- FREE(tab);
-}
+//void z2double(double *ptrz, double *ptrsci, int size, int lda)
+//{
+// int i;
+// double *tab;
+//
+// if ((tab = (double *) MALLOC(size * sizeof(double))) == NULL)
+// {
+// Scierror(999, _("%s: No more memory.\n"), "z2double");
+// return;
+// }
+// // Put the real parts in place and stores the imaginary parts
+// // in the array tab.
+// for (i = 0; i < size; ++i)
+// {
+// tab[i] = ptrz[2 * i + 1]; // imaginary part
+// ptrsci[i] = ptrz[2 * i]; // real part
+// }
+// // Puts the imaginary parts in the imaginary block.
+// memcpy(ptrsci + lda, tab, size * sizeof(double));
+//
+// FREE(tab);
+//}
static Parser::ControlStatus processCommand(ScilabEngineInfo* _pSEI);
static void stateShow(Parser::ControlStatus status);
+using namespace ast;
+
ScilabEngineInfo* InitScilabEngineInfo()
{
ScilabEngineInfo* pSEI = (ScilabEngineInfo*)MALLOC(sizeof(ScilabEngineInfo));
SinglePoly *poPoly = pVar->get(0, 0);
poPoly->setCoef(_pdbl);
- symbol::Context::getInstance()->put(symbol::Symbol(_szName), *pVar);
+ symbol::Context::getInstance()->put(symbol::Symbol(_szName), pVar);
}
static void Add_Double_Constant(wstring _szName, double _dblReal, double _dblImg, bool _bComplex)
types::Double * pVal = new types::Double(1, 1, _bComplex);
pVal->set(0, 0, _dblReal);
pVal->setImg(0, 0, _dblImg);
- symbol::Context::getInstance()->put(symbol::Symbol(_szName), *pVal);
+ symbol::Context::getInstance()->put(symbol::Symbol(_szName), pVal);
}
static void Add_Boolean_Constant(wstring _szName, bool _bBool)
{
types::Bool * pVal = new types::Bool(_bBool);
- symbol::Context::getInstance()->put(symbol::Symbol(_szName), *pVal);
+ symbol::Context::getInstance()->put(symbol::Symbol(_szName), pVal);
}
static void Add_String_Constant(wstring _szName, const char *_pstString)
{
types::String * ps = new types::String(_pstString);
- symbol::Context::getInstance()->put(symbol::Symbol(_szName), *ps);
+ symbol::Context::getInstance()->put(symbol::Symbol(_szName), ps);
}
extern "C" {
#include "MALLOC.h"
#include "getfunctionsname.h"
+#include "charEncoding.h"
}
/*----------------------------------------------------------------------------------*/
char **getFunctionsName(int *sizearray)
{
std::list<std::wstring>* plMacrosList = symbol::Context::getInstance()->getFunctionsName();
- std::list<std::wstring>::iterator it;
*sizearray = (int)plMacrosList->size();
- char** functions = (char**)MALLOC(*sizearray * sizeof(char*));
+ char** functions = NULL;
+ if (*sizearray != 0)
+ {
+ functions = (char**)MALLOC(*sizearray * sizeof(char*));
- plMacrosList->sort();
+ plMacrosList->sort();
- int i = 0;
- for (it = plMacrosList->begin(); it != plMacrosList->end(); ++it, i++)
- {
- functions[i] = wide_string_to_UTF8((*it).c_str());
+ std::list<std::wstring>::iterator it = plMacrosList->begin();
+ for (int i = 0; it != plMacrosList->end(); ++it, i++)
+ {
+ functions[i] = wide_string_to_UTF8((*it).c_str());
+ }
+
+ delete plMacrosList;
}
- delete plMacrosList;
return functions;
}
extern "C" {
#include "MALLOC.h"
#include "getmacrosname.h"
+#include "charEncoding.h"
}
/*----------------------------------------------------------------------------------*/
char **getMacrosName(int *sizearray)
{
std::list<std::wstring>* plMacrosList = symbol::Context::getInstance()->getMacrosName();
- std::list<std::wstring>::iterator it;
//sort list
plMacrosList->sort();
plMacrosList->unique();
*sizearray = (int)plMacrosList->size();
- char** macros = (char**)MALLOC(*sizearray * sizeof(char*));
+ char** macros = NULL;
+ if (*sizearray != 0)
+ {
+ macros = (char**)MALLOC(*sizearray * sizeof(char*));
+ std::list<std::wstring>::iterator it = plMacrosList->begin();
+ for (int i = 0; it != plMacrosList->end(); ++it, i++)
+ {
+ macros[i] = wide_string_to_UTF8((*it).c_str());
+ }
- int i = 0;
- for (it = plMacrosList->begin(); it != plMacrosList->end(); ++it, i++)
- {
- macros[i] = wide_string_to_UTF8((*it).c_str());
+ delete plMacrosList;
}
- delete plMacrosList;
return macros;
}
/*----------------------------------------------------------------------------------*/
extern "C" {
#include "MALLOC.h"
#include "getvariablesname.h"
+#include "charEncoding.h"
}
/*----------------------------------------------------------------------------------*/
char **getVariablesName(int *sizearray, BOOL sorted)
{
std::list<std::wstring>* plVarNames = symbol::Context::getInstance()->getVarsName();
- std::list<std::wstring>::iterator it;
*sizearray = (int)plVarNames->size();
- char** variables = (char**)MALLOC(*sizearray * sizeof(char*));
+ char** variables = NULL;
- if (sorted)
+ if (*sizearray != 0)
{
- plVarNames->sort();
- }
+ variables = (char**)MALLOC(*sizearray * sizeof(char*));
- int i = 0;
- for (it = plVarNames->begin(); it != plVarNames->end(); ++it, i++)
- {
- variables[i] = wide_string_to_UTF8((*it).c_str());
+ if (sorted)
+ {
+ plVarNames->sort();
+ }
+
+ std::list<std::wstring>::iterator it = plVarNames->begin();
+ for (int i = 0; it != plVarNames->end(); ++it, i++)
+ {
+ variables[i] = wide_string_to_UTF8((*it).c_str());
+ }
+
+ delete plVarNames;
}
- delete plVarNames;
return variables;
}
__threadSignal Runner::m_awakeScilab;
__threadSignalLock Runner::m_awakeScilabLock;
+using namespace ast;
+
void Runner::init()
{
__InitSignal(&m_awakeScilab);
#include "scilabWrite.hxx"
#include "scilabexception.hxx"
+using namespace ast;
/*--------------------------------------------------------------------------*/
/*
* Command queue functions
<ClInclude Include="..\..\includes\rea2b.h" />
<ClInclude Include="..\..\includes\rea2db.h" />
<ClInclude Include="..\..\includes\scidcopy.h" />
- <ClInclude Include="..\..\includes\sci_tools.h" />
<ClInclude Include="..\..\includes\sign.h" />
<ClInclude Include="..\..\includes\sin.h" />
<ClInclude Include="..\..\includes\sqrt.h" />
<ClInclude Include="..\cpp\prod.hxx">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\..\includes\sci_tools.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="..\..\includes\gsort.hxx">
<Filter>Header Files</Filter>
</ClInclude>
}
-using namespace types;
-
-int getMode(typed_list &in, int _iProcess, int _iRef)
+int getMode(types::typed_list &in, int _iProcess, int _iRef)
{
int iMode = 0;
if (in[_iProcess]->isString())
{
- String* pS = in[_iProcess]->getAs<String>();
+ types::String* pS = in[_iProcess]->getAs<types::String>();
if (pS->getSize() != 1)
{
Scierror(999, _("%s: Wrong size for argument %d: (%d,%d) expected.\n"), "size", _iProcess + 1, 1, 1);
break;
}
}
- else if (in[1]->isDouble() && in[1]->getAs<Double>()->isComplex() == false)
+ else if (in[1]->isDouble() && in[1]->getAs<types::Double>()->isComplex() == false)
{
- Double* pD = in[_iProcess]->getAs<Double>();
+ types::Double* pD = in[_iProcess]->getAs<types::Double>();
if (pD->getSize() != 1)
{
Scierror(999, _("%s: Wrong size for argument %d: (%d,%d) expected.\n"), "size", _iProcess + 1, 1, 1);
if (iMode == -1)
{
iMode = 0;
- if (in[_iRef]->getAs<GenericType>()->getRows() > 1)
+ if (in[_iRef]->getAs<types::GenericType>()->getRows() > 1)
{
iMode = 1;
}
- else if (in[_iRef]->getAs<GenericType>()->getCols() > 1)
+ else if (in[_iRef]->getAs<types::GenericType>()->getCols() > 1)
{
iMode = 2;
}
#include "file.hxx"
using namespace std;
-using namespace types;
-
class FILEIO_IMPEXP FileManager
{
//static attributs instantiation
static int getFileMaxID();
static bool isOpened(wstring _stFilename);
static int getFileID(wstring _stFilename);
- static File* getFile(int _iID);
+ static types::File* getFile(int _iID);
static int getCurrentFile();
- static int addFile(File* _file);
+ static int addFile(types::File* _file);
static int getFirstFreeFileID();
static void deleteFile(int _iID);
static int getOpenedCount();
static void initialize();
static void destroy();
private :
- typedef std::vector<File*> vectFile;
+ typedef std::vector<types::File*> vectFile;
static vectFile m_fileList;
static int m_iCurrentFile; //memorize current using file
-
};
#endif /* __FILEMANAGER_HXX__ */
#include "deleteafile.h"
#include "localization.h"
}
+
+using namespace types;
+
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_deletefile(typed_list &in, int _iRetCount, typed_list &out)
{
#include "splitpath.h"
#include "localization.h"
}
+
+using namespace types;
+
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_fileext(typed_list &in, int _iRetCount, typed_list &out)
{
#define FILEPARTS_PATH_SELECTOR L"path"
#define FILEPARTS_FNAME_SELECTOR L"fname"
#define FILEPARTS_EXTENSION_SELECTOR L"extension"
+
+using namespace types;
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_fileparts(typed_list &in, int _iRetCount, typed_list &out)
{
#include "os_wcsicmp.h"
}
+using namespace types;
+
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_filesep(typed_list &in, int _iRetCount, typed_list &out)
{
#include "Scierror.h"
#include "localization.h"
}
-/*--------------------------------------------------------------------------*/
+using namespace types;
+/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_get_absolute_file_path(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
int dimsArray[2] = {1, 1};
#include "localization.h"
#include "getrelativefilename.h"
}
-/*--------------------------------------------------------------------------*/
+using namespace types;
+
+/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_getrelativefilename(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
wchar_t* wcsAbsDir = NULL;
#include "Scierror.h"
#include "localization.h"
}
-/*--------------------------------------------------------------------------*/
+using namespace types;
+/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mclearerr(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
int iRet = 0;
#include "localization.h"
#include "PATH_MAX.h"
}
+
+using namespace types;
+
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_meof(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
#include "Scierror.h"
#include "localization.h"
}
-/*--------------------------------------------------------------------------*/
+using namespace types;
+
+/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_merror(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
int iRet = 0;
#ifdef _MSC_VER
static BOOL forceSTDERRredirect = TRUE;
#endif
+
+using namespace types;
+using namespace ast;
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mfprintf(types::typed_list &in, int _iRetCount, types::typed_list &out)
#include "charEncoding.h"
#include "os_strdup.h"
}
+
+using namespace types;
+
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mget(typed_list &in, int _iRetCount, typed_list &out)
{
#include "expandPathVariable.h"
}
+using namespace types;
+
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mgetl(typed_list &in, int _iRetCount, typed_list &out)
{
#include "charEncoding.h"
#include "mgetstr.h"
}
+
+using namespace types;
+
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mgetstr(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
#include "charEncoding.h"
#include "os_strdup.h"
}
+
+using namespace types;
+
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mput(typed_list &in, int _iRetCount, typed_list &out)
{
#include "mclose.h"
#include "expandPathVariable.h"
}
+
+using namespace types;
+
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mputl(typed_list &in, int _iRetCount, typed_list &out)
{
#include "Scierror.h"
#include "charEncoding.h"
}
+
+using namespace types;
+
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mputstr(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
#define SEEK_CUR 1
#define SEEK_END 2
#endif
+
+using namespace types;
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mseek(types::typed_list &in, int _iRetCount, types::typed_list &out)
#include "mtell.h"
}
+using namespace types;
types::Function::ReturnValue sci_mtell(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
{
wchar_t *Alias;
wchar_t *VariableName;
+ symbol::Variable* var;
};
/*--------------------------------------------------------------------------*/
#define NB_ALIAS 7
static struct VARIABLEALIAS VARIABLES_words[NB_ALIAS] =
{
- {L"SCIHOME", L"SCIHOME"},
- {L"WSCI", L"WSCI"},
- {L"SCI", L"SCI"},
- {L"~", L"home"},
- {L"HOME", L"home"},
- {L"home", L"home"},
- {L"TMPDIR", L"TMPDIR"}
+ {L"SCIHOME", L"SCIHOME", NULL},
+ {L"WSCI", L"WSCI", NULL},
+ {L"SCI", L"SCI", NULL},
+ {L"~", L"home", NULL},
+ {L"HOME", L"home", NULL},
+ {L"home", L"home", NULL},
+ {L"TMPDIR", L"TMPDIR", NULL}
};
/*--------------------------------------------------------------------------*/
-static wchar_t *getVariableValueDefinedInScilab(wchar_t *wcVarName);
+static wchar_t *getVariableValueDefinedInScilab(VARIABLEALIAS* var);
static wchar_t *convertFileSeparators(wchar_t *wcStr);
/*--------------------------------------------------------------------------*/
wchar_t *expandPathVariableW(wchar_t *wcstr)
/* input is ALIAS without subdirectory */
if (wcscmp(VARIABLES_words[i].Alias, wcstr) == 0)
{
- wchar_t *wcexpanded = getVariableValueDefinedInScilab(VARIABLES_words[i].VariableName);
+ wchar_t *wcexpanded = getVariableValueDefinedInScilab(&VARIABLES_words[i]);
if (wcexpanded)
{
return convertFileSeparators(wcexpanded);
{
if ( (wcstr[lenAlias] == L'/') || (wcstr[lenAlias] == L'\\') )
{
- wchar_t * newBegin = getVariableValueDefinedInScilab(VARIABLES_words[i].VariableName);
+ wchar_t * newBegin = getVariableValueDefinedInScilab(&VARIABLES_words[i]);
if (newBegin)
{
int lengthnewBegin = (int)wcslen(newBegin);
return expanded;
}
/*--------------------------------------------------------------------------*/
-wchar_t *getVariableValueDefinedInScilab(wchar_t *wcVarName)
+wchar_t *getVariableValueDefinedInScilab(VARIABLEALIAS* _var)
{
- if (wcVarName)
+ if (_var)
{
- types::InternalType *pIT = symbol::Context::getInstance()->get(symbol::Symbol(wcVarName));
- if (pIT->isString() == false)
+ if (_var->var == NULL)
+ {
+ _var->var = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(_var->VariableName));
+ }
+
+ types::InternalType *pIT = _var->var->get();
+ if (pIT == NULL || pIT->isString() == false)
{
return NULL;
}
void FileManager::initialize()
{
- File* pErr = new File();
+ types::File* pErr = new types::File();
pErr->setFileMode(L"wb");
pErr->setFileDesc(stderr);
pErr->setFileSwap(0);
pErr->setFileType(1);
pErr->setFilename(L"stderr");
- File* pIn = new File();
+ types::File* pIn = new types::File();
pIn->setFileMode(L"rb");
pIn->setFileDesc(stdin);
pIn->setFileSwap(0);
pIn->setFileType(1);
pIn->setFilename(L"stdin");
- File* pOut = new File();
+ types::File* pOut = new types::File();
pOut->setFileMode(L"wb");
pOut->setFileDesc(stdout);
pOut->setFileSwap(0);
int items = *n1;
int n = *n1;
FILE* fa; // used in MGET_GEN_NC => MGET_NC
- File* pFile = FileManager::getFile(*fd);
+ types::File* pFile = FileManager::getFile(*fd);
*ierr = 0;
return;
}
- File* pFile = FileManager::getFile(*fd);
+ types::File* pFile = FileManager::getFile(*fd);
if (pFile && pFile->getFiledesc())
{
mget2(pFile->getFiledesc(), pFile->getFileSwap(), res, *n, type, ierr);
/*--------------------------------------------------------------------------*/
static wchar_t *removeEOL(wchar_t *_inString);
static char *convertAnsiToUtf(char *_inString);
-static wchar_t* getLine(wchar_t* _pstLine, int _iLineSize, File* _pFile);
+static wchar_t* getLine(wchar_t* _pstLine, int _iLineSize, types::File* _pFile);
/*--------------------------------------------------------------------------*/
#define UTF_16BE_BOM 0xFEFF // 0xFEFF = to_wide_string(0xEFBBBF)
/*--------------------------------------------------------------------------*/
wchar_t **mgetl(int fd, int nbLinesIn, int *nbLinesOut, int *ierr)
{
wchar_t **strLines = NULL;
- File* pFile = NULL;
+ types::File* pFile = NULL;
int iLineSizeMult = 1;
*ierr = MGETL_ERROR;
*nbLinesOut = 0;
return strLines;
}
/*--------------------------------------------------------------------------*/
-wchar_t* getLine(wchar_t* _pstLine, int _iLineSize, File* _pFile)
+wchar_t* getLine(wchar_t* _pstLine, int _iLineSize, types::File* _pFile)
{
if (_pFile->getFileModeAsInt() % 2 == 1)
{
wchar_t* mgetstr(int _iFileId, int _iSizeToRead)
{
wchar_t* pwstOut = NULL;
- File* pF = FileManager::getFile(_iFileId);
+ types::File* pF = FileManager::getFile(_iFileId);
if (pF != NULL)
{
return;
}
- File *pFile = FileManager::getFile(*fd);
+ types::File *pFile = FileManager::getFile(*fd);
if (pFile && pFile->getFiledesc())
{
mput2(pFile->getFiledesc(), pFile->getFileSwap(), res, *n, type, ierr);
mputlError mputl(int _iFileId, wchar_t **pstStrings, int _iSizeStrings, BOOL _CR)
{
int i = 0;
- File* pF = NULL;
+ types::File* pF = NULL;
if (pstStrings == NULL)
{
int irep;
#endif
- File* pF = FileManager::getFile(fd);
+ types::File* pF = FileManager::getFile(fd);
if (pF == NULL)
{
sciprint(_("%s: No input file associated to logical unit %d.\n"), "mseek", fd);
/*--------------------------------------------------------------------------*/
long long mtell(int fd)
{
- File* pF = FileManager::getFile(fd);
+ types::File* pF = FileManager::getFile(fd);
long long offset = -1;
if (pF == NULL)
{
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), (*j)->location_get().first_line, pCall->getName().c_str());
- throw ScilabMessage(szError);
+ throw ast::ScilabMessage(szError);
}
else
{
- throw ScilabMessage();
+ throw ast::ScilabMessage();
}
}
}
szAllError = szError + os.str();
os_swprintf(szError, bsiz, _W("at line % 5d of exec file called by :\n"), (*j)->location_get().first_line);
szAllError += szError;
- throw ScilabMessage(szAllError);
+ throw ast::ScilabMessage(szAllError);
}
else
{
if (execMe.result_get() != NULL && (pVar == NULL || bImplicitCall))
{
InternalType* pITAns = execMe.result_get();
- symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *pITAns);
+ symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), pITAns);
if ( (*j)->is_verbose() && bErrCatch == false)
{
//TODO manage multiple returns
mclose(iID);
//restore previous prompt mode
ConfigVariable::setPromptMode(oldVal);
- throw ScilabMessage(os.str(), 0, (*j)->location_get());
+ throw ast::ScilabMessage(os.str(), 0, (*j)->location_get());
}
}
mclose(iID);
- throw ScilabMessage((*j)->location_get());
+ throw ast::ScilabMessage((*j)->location_get());
}
- catch (ScilabError se)
+ catch (ast::ScilabError se)
{
if (ConfigVariable::getLastErrorNumber() == 0)
{
mclose(iID);
//restore previous prompt mode
ConfigVariable::setPromptMode(oldVal);
- //throw ScilabMessage(szError, 1, (*j)->location_get());
+ //throw ast::ScilabMessage(szError, 1, (*j)->location_get());
//print already done, so just foward exception but with message
throw ast::ScilabError();
}
{
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), (*j)->location_get().first_line, pCall->getName().c_str());
- throw ScilabMessage(szError);
+ throw ast::ScilabMessage(szError);
}
else
{
- throw ScilabMessage();
+ throw ast::ScilabMessage();
}
}
}
szAllError = szError + os.str();
os_swprintf(szError, bsiz, _W("in execstr instruction called by :\n"));
szAllError += szError;
- throw ScilabMessage(szAllError);
+ throw ast::ScilabMessage(szAllError);
}
else
{
if (execMe.result_get() != NULL && execMe.result_get()->isDeletable())
{
InternalType* pITAns = execMe.result_get();
- symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *pITAns);
+ symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), pITAns);
if ( (*j)->is_verbose() && bErrCatch == false)
{
std::wostringstream ostr;
//restore previous prompt mode
ConfigVariable::setPromptMode(oldVal);
- throw ScilabMessage(os.str(), 0, (*j)->location_get());
+ throw ast::ScilabMessage(os.str(), 0, (*j)->location_get());
}
}
- throw ScilabMessage((*j)->location_get());
+ throw ast::ScilabMessage((*j)->location_get());
}
else
{
break;
}
}
- catch (ScilabError se)
+ catch (ast::ScilabError se)
{
ConfigVariable::setSilentError(iOldSilentError);
// check on error number because error message can be empty.
sciprint(_("in execstr instruction called by :\n"));
//restore previous prompt mode
ConfigVariable::setPromptMode(oldVal);
- //throw ScilabMessage(szError, 1, (*j)->location_get());
+ //throw ast::ScilabMessage(szError, 1, (*j)->location_get());
//print already done, so just foward exception but with message
//throw ast::ScilabError();
return Function::Error;
pstLibName = L"";
}
- wstring libName(pstLibName);
- std::list<symbol::Symbol>* FuncList = pContext->getFunctionList(libName, false);
+ std::list<symbol::Symbol>* FuncList = pContext->getFunctionList(pstLibName);
String *pS = new String((int)FuncList->size(), 1);
#include "functions_gw.hxx"
#include "macrovarvisitor.hxx"
#include "list.hxx"
+#include "macro.hxx"
+#include "macrofile.hxx"
#include <iostream>
#include <fstream>
using namespace std;
InternalType* createString(std::list<std::wstring>& lst);
-void addIn(MacrovarVisitor& pVisit, std::list<symbol::Symbol>* pSym);
-void addOut(MacrovarVisitor& pVisit, std::list<symbol::Symbol>* pSym);
+void addIn(MacrovarVisitor& pVisit, std::list<symbol::Variable*>* pSym);
+void addOut(MacrovarVisitor& pVisit, std::list<symbol::Variable*>* pSym);
Function::ReturnValue sci_macrovar(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
return pS;
}
-void addOut(MacrovarVisitor& visit, std::list<symbol::Symbol>* pSym)
+void addOut(MacrovarVisitor& visit, std::list<symbol::Variable*>* pSym)
{
if (pSym == 0 || pSym->size() == 0)
{
return;
}
- std::list<symbol::Symbol>::iterator it = pSym->begin();
+ std::list<symbol::Variable*>::iterator it = pSym->begin();
for (int i = 0 ; it != pSym->end() ; it++, i++)
{
- visit.addOut((*it).name_get().c_str());
+ visit.addOut((*it)->name_get().name_get().c_str());
}
}
-void addIn(MacrovarVisitor& visit, std::list<symbol::Symbol>* pSym)
+void addIn(MacrovarVisitor& visit, std::list<symbol::Variable*>* pSym)
{
if (pSym == 0 || pSym->size() == 0)
{
return;
}
- std::list<symbol::Symbol>::iterator it = pSym->begin();
+ std::list<symbol::Variable*>::iterator it = pSym->begin();
for (int i = 0 ; it != pSym->end() ; it++, i++)
{
- visit.addIn((*it).name_get().c_str());
+ visit.addIn((*it)->name_get().name_get().c_str());
}
}
\ No newline at end of file
#include "functions_gw.hxx"
#include "context.hxx"
#include "string.hxx"
+#include "double.hxx"
extern "C" {
#include "Scierror.h"
/*--------------------------------------------------------------------------*/
using namespace types;
+using namespace std;
Function::ReturnValue sci_whereis(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
}
}
+ //protected all variables after scilab start
+ symbol::Context::getInstance()->scope_begin();
return bRet;
}
int iObjUID = 0;
types::InternalType* pOut = NULL;
- if (in.size() > 2)
+ if (in.size() < 1 || in.size() > 2)
{
Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "get", 1, 2);
return types::Function::Error;
if (p1->isDouble())
{
types::Double* pDbll1 = p1->getAs<types::Double>();
- if (pDbll1->isScalar())
+ if (pDbll1->isScalar() == false)
{
Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), "get", 1);
return types::Function::Error;
#include "gw_graphics.h"
}
-using namespace types;
-
int GraphicsModule::Load()
{
return 1;
#include "context.hxx"
#include "io_gw.hxx"
#include "filemanager.hxx"
+#include "function.hxx"
#include "string.hxx"
+#include "double.hxx"
extern "C"
{
return types::Function::OK;
}
/*--------------------------------------------------------------------------*/
-Function::ReturnValue sci_file_no_rhs(types::typed_list &in, int _iRetCount, types::typed_list &out)
+types::Function::ReturnValue sci_file_no_rhs(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
int iCount = FileManager::getOpenedCount();
if (iCount == 0)
{
for (int i = 0 ; i < _iRetCount ; i++)
{
- out.push_back(Double::Empty());
+ out.push_back(types::Double::Empty());
}
- return Function::OK;
+ return types::Function::OK;
}
int* piIds = FileManager::getIDs();
if (piIds)
{
- Double *pD = new Double(1, iCount);
+ types::Double *pD = new types::Double(1, iCount);
pD->setInt(piIds);
out.push_back(pD);
delete[] piIds;
wchar_t** pstTypes = FileManager::getTypesAsString();
if (pstTypes != NULL)
{
- String* pS = new String(1, iCount);
+ types::String* pS = new types::String(1, iCount);
pS->set(pstTypes);
out.push_back(pS);
for (int i = 0 ; i < iCount ; i++)
wchar_t** pstNames = FileManager::getFilenames();
if (pstNames != NULL)
{
- String* pS = new String(1, iCount);
+ types::String* pS = new types::String(1, iCount);
pS->set(pstNames);
out.push_back(pS);
for (int i = 0 ; i < iCount ; i++)
double* pdblModes = FileManager::getModes();
if (pdblModes != NULL)
{
- Double* pD = new Double(1, iCount);
+ types::Double* pD = new types::Double(1, iCount);
pD->set(pdblModes);
out.push_back(pD);
delete[] pdblModes;
double* pdblSwaps = FileManager::getSwaps();
if (pdblSwaps != NULL)
{
- Double* pD = new Double(1, iCount);
+ types::Double* pD = new types::Double(1, iCount);
pD->set(pdblSwaps);
out.push_back(pD);
delete[] pdblSwaps;
}
}
- return Function::OK;
+ return types::Function::OK;
}
/*--------------------------------------------------------------------------*/
-Function::ReturnValue sci_file_one_rhs(types::typed_list &in, int _iRetCount, types::typed_list &out)
+types::Function::ReturnValue sci_file_one_rhs(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
- if (in[0]->isDouble() == false || in[0]->getAs<Double>()->getSize() != 1)
+ if (in[0]->isDouble() == false || in[0]->getAs<types::Double>()->getSize() != 1)
{
Scierror(201, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "file", 1);
- return Function::Error;
+ return types::Function::Error;
}
- Double* pD = in[0]->getAs<Double>();
+ types::Double* pD = in[0]->getAs<types::Double>();
int iID = static_cast<int>(pD->getReal()[0]);
//check if double value is an integer to exclude decimal values
if (static_cast<double>(iID) != pD->getReal()[0])
{
Scierror(201, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "file", 1);
- return Function::Error;
+ return types::Function::Error;
}
- File *pF = FileManager::getFile(iID);
+ types::File *pF = FileManager::getFile(iID);
if (pF == NULL)
{
for (int i = 0 ; i < _iRetCount ; i++)
{
- out.push_back(Double::Empty());
+ out.push_back(types::Double::Empty());
}
- return Function::OK;
+ return types::Function::OK;
}
- out.push_back(new Double(iID));
+ out.push_back(new types::Double(iID));
if (_iRetCount > 1) /*type*/
{
wchar_t* pstType = os_wcsdup(pF->getFileTypeAsString().c_str());
if (pstType != NULL)
{
- String* pS = new String(pstType);
+ types::String* pS = new types::String(pstType);
out.push_back(pS);
delete[] pstType;
}
wchar_t* pstName = os_wcsdup(pF->getFilename().c_str());
if (pstName != NULL)
{
- String* pS = new String(pstName);
+ types::String* pS = new types::String(pstName);
out.push_back(pS);
delete[] pstName;
}
{
if (pF->getFileType() == 1)
{
- out.push_back(new Double((double)pF->getFileFortranMode()));
+ out.push_back(new types::Double((double)pF->getFileFortranMode()));
}
else // if(pF->getFileType() == 2)
{
- out.push_back(new Double((double)pF->getFileModeAsInt()));
+ out.push_back(new types::Double((double)pF->getFileModeAsInt()));
}
}
if (_iRetCount > 4) /* swap */
{
- out.push_back(new Double(pF->getFileSwap()));
+ out.push_back(new types::Double(pF->getFileSwap()));
}
- return Function::OK;
+ return types::Function::OK;
}
delete parser.getTree();
}
- symbol::Context::getInstance()->put(symbol::Symbol(pstLibName), *pLib);
+ symbol::Context::getInstance()->put(symbol::Symbol(pstLibName), pLib);
}
#include "configvariable.hxx"
#include "context.hxx"
#include "loadlib.hxx"
+#include "macrofile.hxx"
extern "C"
{
#define DEFAULT_ENCODING "UTF-8"
-static char *GetXmlFileEncoding(string _filename);
+static char *GetXmlFileEncoding(std::string _filename);
types::Library* loadlib(std::wstring _wstXML, bool _isFile, bool _bAddInContext)
{
types::Library* lib = NULL;
- wstring wstFile(_wstXML);
- wstring wstPath(_wstXML);
+ std::wstring wstFile(_wstXML);
+ std::wstring wstPath(_wstXML);
if (_isFile)
{
if (pstName && pstFileName)
{
- wstring stFilename(wstPath);
+ std::wstring stFilename(wstPath);
if (stFilename.empty() == false && *stFilename.rbegin() != DIR_SEPARATORW[0])
{
stFilename += DIR_SEPARATORW;
if (_bAddInContext)
{
- symbol::Context::getInstance()->put(symbol::Symbol(pstLibName), *lib);
+ symbol::Context::getInstance()->put(symbol::Symbol(pstLibName), lib);
}
xmlFreeDoc(doc);
return lib;
}
-static char *GetXmlFileEncoding(string _filename)
+static char *GetXmlFileEncoding(std::string _filename)
{
char *encoding = NULL;
xmlDocPtr doc = NULL;
static char *the_current_mex_name;
static void (*exitFcn)(void);
+using namespace ast;
+
mxClassID mxGetClassID(const mxArray *ptr)
{
types::InternalType *pIT = (types::InternalType *) ptr;
{
wchar_t szError[bsiz];
os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), (*j)->location_get().first_line, pCall->getName().c_str());
- throw ScilabMessage(szError);
+ throw ast::ScilabMessage(szError);
}
else
{
- throw ScilabMessage();
+ throw ast::ScilabMessage();
}
}
}
szAllError = szError + os.str();
os_swprintf(szError, bsiz, _W("in execstr instruction called by :\n"));
szAllError += szError;
- throw ScilabMessage(szAllError);
+ throw ast::ScilabMessage(szAllError);
}
else
{
//update ans variable.
if (execMe.result_get() != NULL && execMe.result_get()->isDeletable())
{
- symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *execMe.result_get());
+ symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), execMe.result_get());
if ((*j)->is_verbose() && bErrCatch == false)
{
std::wostringstream ostr;
//restore previous prompt mode
ConfigVariable::setPromptMode(oldVal);
- throw ScilabMessage(os.str(), 0, (*j)->location_get());
+ throw ast::ScilabMessage(os.str(), 0, (*j)->location_get());
}
}
- throw ScilabMessage((*j)->location_get());
+ throw ast::ScilabMessage((*j)->location_get());
}
else
{
break;
}
}
- catch (ScilabError se)
+ catch (ast::ScilabError se)
{
if (ConfigVariable::getLastErrorMessage() == L"")
{
os_swprintf(szError, bsiz, _W("at line % 5d of exec file called by :\n"), (*j)->location_get().first_line);
//restore previous prompt mode
ConfigVariable::setPromptMode(oldVal);
- throw ScilabMessage(szError, 1, (*j)->location_get());
+ throw ast::ScilabMessage(szError, 1, (*j)->location_get());
}
break;
}
wchar_t *dest = to_wide_string(varname);
if (strcmp(workspace, "base") == 0)
{
- context->putInPreviousScope(*(new symbol::Symbol(dest)), *(types::InternalType *) pm);
+ context->putInPreviousScope(context->getOrCreate(symbol::Symbol(dest)), (types::InternalType *) pm);
}
else if (strcmp(workspace, "caller") == 0)
{
- context->put(*(new symbol::Symbol(dest)), *(types::InternalType *) pm);
+ context->put(symbol::Symbol(dest), (types::InternalType *) pm);
}
else if (strcmp(workspace, "global") == 0)
{
- context->setGlobalValue(*(new symbol::Symbol(dest)), *(types::InternalType *) pm);
+ context->setGlobalVisible(symbol::Symbol(dest), true);
+ context->put(symbol::Symbol(dest), (types::InternalType *) pm);
}
else
{
Scierror(999, pstrMsg);
FREE(pstrMsg);
}
- catch (ast::ScilabMessage &m)
+ catch (ast::ScilabMessage& /*m*/)
{
}
return;
}
- scilabPref.heapSize = os_strdup(getAttribute(doc, xpathCtxt, HEAPSIZE_XPATH));
- scilabPref.adaptToDisplay = os_strdup(getAttribute(doc, xpathCtxt, ADAPTTODISPLAY_XPATH));
- scilabPref.columnsToDisplay = os_strdup(getAttribute(doc, xpathCtxt, COLUMNSTODISPLAY_XPATH));
- scilabPref.linesToDisplay = os_strdup(getAttribute(doc, xpathCtxt, LINESTODISPLAY_XPATH));
- scilabPref.historySaveAfter = os_strdup(getAttribute(doc, xpathCtxt, HISTORYSAVEAFTER_XPATH));
- scilabPref.historyFile = os_strdup(getAttribute(doc, xpathCtxt, HISTORYFILE_XPATH));
- scilabPref.historyLines = os_strdup(getAttribute(doc, xpathCtxt, HISTORYLINES_XPATH));
- scilabPref.historyEnable = os_strdup(getAttribute(doc, xpathCtxt, HISTORYENABLE_XPATH));
- scilabPref.ieee = os_strdup(getAttribute(doc, xpathCtxt, IEEE_XPATH));
- scilabPref.format = os_strdup(getAttribute(doc, xpathCtxt, FORMAT_XPATH));
- scilabPref.formatWidth = os_strdup(getAttribute(doc, xpathCtxt, FORMATWIDTH_XPATH));
- scilabPref.language = os_strdup(getAttribute(doc, xpathCtxt, LANGUAGE_XPATH));
- scilabPref.startup_dir_use = os_strdup(getAttribute(doc, xpathCtxt, STARTUP_DIR_USE_XPATH));
- scilabPref.startup_dir_default = os_strdup(getAttribute(doc, xpathCtxt, STARTUP_DIR_DEFAULT_XPATH));
- scilabPref.startup_dir_previous = os_strdup(getAttribute(doc, xpathCtxt, STARTUP_DIR_PREVIOUS_XPATH));
+ scilabPref.heapSize = os_strdup(getAttribute(doc, xpathCtxt, (char*)HEAPSIZE_XPATH));
+ scilabPref.adaptToDisplay = os_strdup(getAttribute(doc, xpathCtxt, (char*)ADAPTTODISPLAY_XPATH));
+ scilabPref.columnsToDisplay = os_strdup(getAttribute(doc, xpathCtxt, (char*)COLUMNSTODISPLAY_XPATH));
+ scilabPref.linesToDisplay = os_strdup(getAttribute(doc, xpathCtxt, (char*)LINESTODISPLAY_XPATH));
+ scilabPref.historySaveAfter = os_strdup(getAttribute(doc, xpathCtxt, (char*)HISTORYSAVEAFTER_XPATH));
+ scilabPref.historyFile = os_strdup(getAttribute(doc, xpathCtxt, (char*)HISTORYFILE_XPATH));
+ scilabPref.historyLines = os_strdup(getAttribute(doc, xpathCtxt, (char*)HISTORYLINES_XPATH));
+ scilabPref.historyEnable = os_strdup(getAttribute(doc, xpathCtxt, (char*)HISTORYENABLE_XPATH));
+ scilabPref.ieee = os_strdup(getAttribute(doc, xpathCtxt, (char*)IEEE_XPATH));
+ scilabPref.format = os_strdup(getAttribute(doc, xpathCtxt, (char*)FORMAT_XPATH));
+ scilabPref.formatWidth = os_strdup(getAttribute(doc, xpathCtxt, (char*)FORMATWIDTH_XPATH));
+ scilabPref.language = os_strdup(getAttribute(doc, xpathCtxt, (char*)LANGUAGE_XPATH));
+ scilabPref.startup_dir_use = os_strdup(getAttribute(doc, xpathCtxt, (char*)STARTUP_DIR_USE_XPATH));
+ scilabPref.startup_dir_default = os_strdup(getAttribute(doc, xpathCtxt, (char*)STARTUP_DIR_DEFAULT_XPATH));
+ scilabPref.startup_dir_previous = os_strdup(getAttribute(doc, xpathCtxt, (char*)STARTUP_DIR_PREVIOUS_XPATH));
xmlXPathFreeContext(xpathCtxt);
xmlFreeDoc(doc);
#include "function.hxx"
#include "context.hxx"
#include "string.hxx"
+#include "double.hxx"
#include "string_gw.hxx"
extern "C"
if (iOccurs == 0)
{
- out.push_back(Double::Empty());
+ out.push_back(types::Double::Empty());
if (_iRetCount > 1)
{
- out.push_back(Double::Empty());
+ out.push_back(types::Double::Empty());
}
if (_iRetCount > 2)
*_pBody = pBody;
//get inputs
- list<symbol::Symbol>* pIn = _pM->inputs_get();
+ std::list<symbol::Variable*>* pIn = _pM->inputs_get();
if (pIn->size() == 0)
{
{
String *pSIn = new String(1, (int)pIn->size());
- list<symbol::Symbol>::iterator itIn = pIn->begin();
+ list<symbol::Variable*>::iterator itIn = pIn->begin();
for (int i = 0 ; i < pIn->size() ; i++, itIn++)
{
- pSIn->set(i, (*itIn).name_get().c_str());
+ pSIn->set(i, (*itIn)->name_get().name_get().c_str());
}
*_pIn = pSIn;
}
//get outputs
- list<symbol::Symbol>* pOut = _pM->outputs_get();
+ list<symbol::Variable*>* pOut = _pM->outputs_get();
if (pOut->size() == 0)
{
*_pOut = Double::Empty();
{
String* pSOut = new String(1, (int)pOut->size());
- list<symbol::Symbol>::iterator itOut = pOut->begin();
+ list<symbol::Variable*>::iterator itOut = pOut->begin();
for (int i = 0 ; i < pOut->size() ; i++, itOut++)
{
- pSOut->set(i, (*itOut).name_get().c_str());
+ pSOut->set(i, (*itOut)->name_get().name_get().c_str());
}
*_pOut = pSOut;
#include "context.hxx"
#include "types.hxx"
#include "bool.hxx"
+#include "double.hxx"
#include "stripblanks.hxx"
/*--------------------------------------------------------------------------*/
extern "C"
if (in.size() < 1 || in.size() > 2)
{
Scierror(999, _("%s: Wrong number of input arguments: %d or %d expected.\n"), FUNCNAME, 1, 2);
- return Function::Error;
+ return types::Function::Error;
}
// check output parameters
if (_iRetCount != 1 && _iRetCount != -1)
{
Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), FUNCNAME, 1);
- return Function::Error;
+ return types::Function::Error;
}
if (in.size() == 2)
if (in[1]->isBool() == false || in[1]->getAs<types::Bool>()->getSize() != 1)
{
Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), FUNCNAME, 2);
- return Function::Error;
+ return types::Function::Error;
}
if (in[1]->getAs<types::Bool>()->get()[0] == 1)
switch (in[0]->getType())
{
- case InternalType::ScilabString:
+ case types::InternalType::ScilabString:
{
- String *pS = stripblanks(in[0]->getAs<types::String>(), bRemoveTab);
+ types::String *pS = stripblanks(in[0]->getAs<types::String>(), bRemoveTab);
if (pS == NULL)
{
Scierror(999, _("%s : No more memory.\n"), FUNCNAME);
- return Function::Error;
+ return types::Function::Error;
}
out.push_back(pS);
}
break;
- case InternalType::ScilabDouble://manage []
+ case types::InternalType::ScilabDouble://manage []
{
- if (in[0]->getAs<Double>()->getSize() != 0)
+ if (in[0]->getAs<types::Double>()->getSize() != 0)
{
Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings or empty matrix expected.\n"), FUNCNAME, 1);
- return Function::Error;
+ return types::Function::Error;
}
- out.push_back(Double::Empty());
+ out.push_back(types::Double::Empty());
}
break;
default:
Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings or empty matrix expected.\n"), FUNCNAME, 1);
- return Function::Error;
+ return types::Function::Error;
}
- return Function::OK;
+ return types::Function::OK;
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
static wchar_t* subwcs(const wchar_t *_pstStr, int _iStartPos, int _iEndPos);
/*--------------------------------------------------------------------------*/
-String * stripblanks(String *InputStrings, bool bRemoveTAB)
+types::String * stripblanks(types::String *InputStrings, bool bRemoveTAB)
{
- String *pOutputStrings = new String(InputStrings->getRows(), InputStrings->getCols());
+ types::String *pOutputStrings = new types::String(InputStrings->getRows(), InputStrings->getCols());
if (pOutputStrings)
{
pOutputStrings->set(InputStrings->get());
#include "dynlib_string.h"
#include "string.hxx"
-using namespace types;
-
/**
* remove blank or tab characters in a string matrix
* @param[in] String: input Strings
* @param[in] Bool: remove TAB if get() != 0
* @return String: output String
*/
-STRING_IMPEXP String * stripblanks(String *InputStrings, bool bWithTAB);
+STRING_IMPEXP types::String * stripblanks(types::String *InputStrings, bool bWithTAB);
#endif /* __STRIPBLANKS_HXX__ */
/*--------------------------------------------------------------------------*/
SYMBOL_CXX_SOURCES = \
src/cpp/symbol.cpp \
-src/cpp/context.cpp \
-src/cpp/scope.cpp \
-src/cpp/variables.cpp \
-src/cpp/libraries.cpp
+src/cpp/context.cpp
pkglib_LTLIBRARIES = libscisymbol.la
libscisymbol_la_DEPENDENCIES =
am__dirstamp = $(am__leading_dot)dirstamp
am__objects_1 = src/cpp/libscisymbol_la-symbol.lo \
- src/cpp/libscisymbol_la-context.lo \
- src/cpp/libscisymbol_la-scope.lo \
- src/cpp/libscisymbol_la-variables.lo \
- src/cpp/libscisymbol_la-libraries.lo
+ src/cpp/libscisymbol_la-context.lo
am_libscisymbol_la_OBJECTS = $(am__objects_1)
libscisymbol_la_OBJECTS = $(am_libscisymbol_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
yacc_present = @yacc_present@
SYMBOL_CXX_SOURCES = \
src/cpp/symbol.cpp \
-src/cpp/context.cpp \
-src/cpp/scope.cpp \
-src/cpp/variables.cpp \
-src/cpp/libraries.cpp
+src/cpp/context.cpp
pkglib_LTLIBRARIES = libscisymbol.la
libscisymbol_la_SOURCES = $(SYMBOL_CXX_SOURCES)
src/cpp/$(DEPDIR)/$(am__dirstamp)
src/cpp/libscisymbol_la-context.lo: src/cpp/$(am__dirstamp) \
src/cpp/$(DEPDIR)/$(am__dirstamp)
-src/cpp/libscisymbol_la-scope.lo: src/cpp/$(am__dirstamp) \
- src/cpp/$(DEPDIR)/$(am__dirstamp)
-src/cpp/libscisymbol_la-variables.lo: src/cpp/$(am__dirstamp) \
- src/cpp/$(DEPDIR)/$(am__dirstamp)
-src/cpp/libscisymbol_la-libraries.lo: src/cpp/$(am__dirstamp) \
- src/cpp/$(DEPDIR)/$(am__dirstamp)
libscisymbol.la: $(libscisymbol_la_OBJECTS) $(libscisymbol_la_DEPENDENCIES) $(EXTRA_libscisymbol_la_DEPENDENCIES)
$(AM_V_CXXLD)$(CXXLINK) -rpath $(pkglibdir) $(libscisymbol_la_OBJECTS) $(libscisymbol_la_LIBADD) $(LIBS)
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscisymbol_la-context.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscisymbol_la-libraries.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscisymbol_la-scope.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscisymbol_la-symbol.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscisymbol_la-variables.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscisymbol_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscisymbol_la-context.lo `test -f 'src/cpp/context.cpp' || echo '$(srcdir)/'`src/cpp/context.cpp
-src/cpp/libscisymbol_la-scope.lo: src/cpp/scope.cpp
-@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscisymbol_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscisymbol_la-scope.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscisymbol_la-scope.Tpo -c -o src/cpp/libscisymbol_la-scope.lo `test -f 'src/cpp/scope.cpp' || echo '$(srcdir)/'`src/cpp/scope.cpp
-@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscisymbol_la-scope.Tpo src/cpp/$(DEPDIR)/libscisymbol_la-scope.Plo
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/cpp/scope.cpp' object='src/cpp/libscisymbol_la-scope.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscisymbol_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscisymbol_la-scope.lo `test -f 'src/cpp/scope.cpp' || echo '$(srcdir)/'`src/cpp/scope.cpp
-
-src/cpp/libscisymbol_la-variables.lo: src/cpp/variables.cpp
-@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscisymbol_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscisymbol_la-variables.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscisymbol_la-variables.Tpo -c -o src/cpp/libscisymbol_la-variables.lo `test -f 'src/cpp/variables.cpp' || echo '$(srcdir)/'`src/cpp/variables.cpp
-@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscisymbol_la-variables.Tpo src/cpp/$(DEPDIR)/libscisymbol_la-variables.Plo
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/cpp/variables.cpp' object='src/cpp/libscisymbol_la-variables.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscisymbol_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscisymbol_la-variables.lo `test -f 'src/cpp/variables.cpp' || echo '$(srcdir)/'`src/cpp/variables.cpp
-
-src/cpp/libscisymbol_la-libraries.lo: src/cpp/libraries.cpp
-@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscisymbol_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscisymbol_la-libraries.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscisymbol_la-libraries.Tpo -c -o src/cpp/libscisymbol_la-libraries.lo `test -f 'src/cpp/libraries.cpp' || echo '$(srcdir)/'`src/cpp/libraries.cpp
-@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscisymbol_la-libraries.Tpo src/cpp/$(DEPDIR)/libscisymbol_la-libraries.Plo
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='src/cpp/libraries.cpp' object='src/cpp/libscisymbol_la-libraries.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscisymbol_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscisymbol_la-libraries.lo `test -f 'src/cpp/libraries.cpp' || echo '$(srcdir)/'`src/cpp/libraries.cpp
-
mostlyclean-libtool:
-rm -f *.lo
#ifndef __CONTEXT_HXX__
#define __CONTEXT_HXX__
-//#include "stack.hxx"
-//#include "heap.hxx"
-#include "scope.hxx"
-#include "variables.hxx"
-#include "internal.hxx"
+
#include "function.hxx"
-#include "macro.hxx"
-#include "macrofile.hxx"
+#include "typesdecl.hxx"
+#include "variables.hxx"
+#include "libraries.hxx"
#include "export_symbol.h"
namespace symbol
/** If key was associated to some Entry_T in the open scopes, return the
** most recent insertion. Otherwise return the empty pointer. */
- types::InternalType* get(const symbol::Symbol& key) const;
+ types::InternalType* get(const Symbol& key);
+ types::InternalType* get(const Variable* _var);
+ Variable* getOrCreate(const Symbol& _key);
/** If key was associated to some Entry_T in the last opened scope, return it.
** Otherwise return the empty pointer. */
- types::InternalType* getCurrentLevel(const symbol::Symbol& key) const;
+ types::InternalType* getCurrentLevel(const Symbol& key);
/** If key was associated to some Entry_T in the open scopes, return the
** most recent insertion DESPITE the current/last one. Otherwise return the empty pointer. */
- types::InternalType* getAllButCurrentLevel(const symbol::Symbol& key) const;
+ types::InternalType* getAllButCurrentLevel(const Symbol& key);
/** If key was associated to some Entry_T in the open scopes, return the
** most recent insertion. Otherwise return the empty pointer. */
- types::InternalType* getFunction(const symbol::Symbol& key) const;
+ types::InternalType* getFunction(const Symbol& key);
/*return function list in the module _stModuleName*/
- std::list<symbol::Symbol>* getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd = true);
+ std::list<Symbol>* getFunctionList(std::wstring _stModuleName);
std::list<std::wstring>* getVarsName();
std::list<std::wstring>* getMacrosName();
/* global functions */
/*return global variable visibility status*/
- bool isGlobalVisible(const symbol::Symbol& key) const;
-
- /*return global variable, search in global scope ( highest )*/
- types::InternalType* getGlobalValue(const symbol::Symbol& key) const;
+ bool isGlobalVisible(const Symbol& key);
/*return global variable existance status*/
- bool isGlobalExists(const symbol::Symbol& key) const;
-
- /*create or update a global variable*/
- void setGlobalValue(const symbol::Symbol& key, types::InternalType &value);
+ bool isGlobal(const Symbol& key);
/*remove global variable and all visibility references */
- void removeGlobal(const symbol::Symbol& key);
+ //clearglobal("a")
+ void removeGlobal(const Symbol& key);
/*remove all global variables and references */
+ //clearglobal
void removeGlobalAll();
- /*create an empty variable*/
- void createEmptyGlobalValue(const symbol::Symbol& key);
-
/*set variable visible/hidden in current global scope*/
- void setGlobalVisible(const symbol::Symbol& key, bool bVisible = true);
+ void setGlobalVisible(const Symbol& key, bool bVisible);
+ void setGlobal(const Symbol& key);
+
+ types::InternalType* getGlobalValue(const Symbol& _key);
/*add symbol and value in the stack*/
- bool put(const symbol::Symbol& key, types::InternalType& type);
+ void put(const Symbol& _key, types::InternalType* _pIT);
+ void put(Variable* _var, types::InternalType* _pIT);
/*add symbol and value in the previous scope*/
- bool putInPreviousScope(const symbol::Symbol& key, types::InternalType& type);
+ bool putInPreviousScope(Variable* _var, types::InternalType* _pIT);
/* remove symbol/value association */
- bool remove(const symbol::Symbol& key);
+ //clear("a")
+ bool remove(const Symbol& key);
+ //clear();
+ bool removeAll();
bool addFunction(types::Function *_info);
- bool AddMacro(types::Macro *_info);
- bool AddMacroFile(types::MacroFile *_info);
+ bool addMacro(types::Macro *_info);
+ bool addMacroFile(types::MacroFile *_info);
void print(std::wostream& ostr) const;
private :
- Scopes* m_scopes;
+ types::InternalType* get(const Symbol& key, int _iLevel);
+ bool clearCurrentScope(bool _bClose);
+
+ typedef std::map<Symbol, Variable*> VarList;
+ typedef std::stack<VarList*> VarStack;
+ std::list<Symbol>* globals;
+ VarStack varStack;
+ Variables variables;
+ Libraries libraries;
+ int m_iLevel;
Context();
static Context* me;
#ifndef __LIBRARIES_HXX__
#define __LIBRARIES_HXX__
-#include <map>
-#include <list>
-#include "types.hxx"
+#include <stack>
#include "symbol.hxx"
-#include "function.hxx"
+#include "types.hxx"
#include "library.hxx"
-#include "variables.hxx"
+#include "export_symbol.h"
namespace symbol
{
-class LibBox
+struct EXTERN_SYMBOL ScopedLibrary
{
-public :
- LibBox(int _iLevel, types::Library& _lib) : m_iLevel(_iLevel), m_pLib(&_lib) {};
- virtual ~LibBox() {};
+ ScopedLibrary(int _iLevel, types::Library* _pLib) : m_iLevel(_iLevel), m_pLib(_pLib) {};
- types::Library* getValue()
+ types::MacroFile* getMacroFile(const Symbol& _key)
{
- return m_pLib;
+ return m_pLib->get(_key.name_get());
}
- types::MacroFile* getMacroFile(const Symbol& _key);
- void setValue(types::Library& _lib)
+
+ int m_iLevel;
+ types::Library* m_pLib;
+};
+
+struct EXTERN_SYMBOL Library
+{
+ Library(const Symbol& _name) : name(_name) {};
+
+ void put(types::Library* _pLib, int _iLevel)
{
- m_pLib = &_lib;
+ if (empty() || top()->m_iLevel < _iLevel)
+ {
+ //create a new level
+ stack.push(new ScopedLibrary(_iLevel, _pLib));
+ _pLib->IncreaseRef();
+ }
+ else
+ {
+ //update current level
+ types::Library* pLib = top()->m_pLib;
+ if (pLib != _pLib)
+ {
+ pLib->DecreaseRef();
+ if (pLib->isDeletable())
+ {
+ delete pLib;
+ }
+
+ top()->m_pLib = _pLib;
+ _pLib->IncreaseRef();
+ }
+ }
}
- int getLevel()
+
+ types::MacroFile* get(const Symbol& _keyMacro) const
{
- return m_iLevel;
- };
- void setLevel(int _iLevel)
+ if (empty() == false)
+ {
+ return top()->getMacroFile(_keyMacro);
+ }
+
+ return NULL;
+ }
+
+ std::list<std::wstring>* getMacrosName()
+ {
+ if (empty() == false)
+ {
+ return top()->m_pLib->getMacrosName();
+ }
+
+ return new std::list<std::wstring>();
+ }
+
+ bool empty() const
+ {
+ return stack.empty();
+ }
+
+ ScopedLibrary* top() const
{
- m_iLevel = _iLevel;
- };
+ return stack.top();
+ }
+
+ void pop()
+ {
+ stack.pop();
+ }
+
private :
- int m_iLevel;
- types::Library* m_pLib;
+ typedef std::stack<ScopedLibrary*> StackLib;
+ StackLib stack;
+ Symbol name;
+ bool m_global;
};
-class Libraries
+struct Libraries
{
-private :
- typedef std::list<LibBox* > LibBoxList;
- typedef std::map<Symbol, LibBoxList*> LibMap;
- typedef std::list<Symbol> LibList;
- LibMap m_libmap;
- LibList m_liblist;
- int m_iLevel;
+ Libraries() {};
+
+ Library* getOrCreate(const Symbol& _key)
+ {
+ MapLibs::const_iterator it = libs.find(_key);
+ if (it == libs.end())
+ {
+ //create an empty StackedValues
+ Library* lib = new Library(_key);
+ libs[_key] = lib;
+ return lib;
+ }
-public :
- Libraries() : m_iLevel(-1) {}
+ return it->second;
+ }
- virtual ~Libraries() {}
+ void put(const Symbol& _keyLib, types::Library* _pLib, int _iLevel)
+ {
+ Library* lib = getOrCreate(_keyLib);
+ lib->put(_pLib, _iLevel);
+ }
- void IncreaseLevel()
+ types::InternalType* get(const Symbol& _key, int _iLevel)
{
- m_iLevel++;
+ MapLibs::reverse_iterator it = libs.rbegin();
+ for (; it != libs.rend() ; ++it)
+ {
+ if (it->second->empty() == false)
+ {
+ if (_iLevel == -1 || it->second->top()->m_iLevel == _iLevel)
+ {
+ types::MacroFile* pMF = it->second->get(_key);
+ if (pMF)
+ {
+ return (types::InternalType*)pMF;
+ }
+ }
+ }
+ }
+
+ return NULL;
}
- void DecreaseLevel()
+
+ bool remove(const Symbol& _key, int _iLevel)
{
- m_iLevel--;
+ MapLibs::iterator it = libs.find(_key);
+ if (it != libs.end())
+ {
+ if (it->second->empty() == false)
+ {
+ if (it->second->top()->m_iLevel == _iLevel)
+ {
+ types::Library* pIT = it->second->top()->m_pLib;
+ pIT->DecreaseRef();
+ if (pIT->isDeletable())
+ {
+ delete pIT;
+ }
+
+ it->second->pop();
+ return true;
+ }
+ }
+ }
+
+ return false;
}
- void put(const Symbol& _key, types::InternalType& _IT);
- types::MacroFile* get(const Symbol& _key) const;
- bool remove(const Symbol& _key);
+ std::list<std::wstring>* getMacrosName()
+ {
+ std::list<std::wstring>* names = new std::list<std::wstring>();
+ MapLibs::iterator it = libs.begin();
+ for (; it != libs.end() ; ++it)
+ {
+ std::list<std::wstring>* temp = it->second->getMacrosName();
+ names->insert(names->end(), temp->begin(), temp->end());
+ delete temp;
+ }
- std::list<std::wstring>* getMacrosName();
+ return names;
+ }
+private:
+ typedef std::map<Symbol, Library*> MapLibs;
+ MapLibs libs;
};
}
#endif /* !__LIBRARIES_HXX__ */
/*
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
-*
-* This file must be used under the terms of the CeCILL.
-* This source file is licensed as described in the file COPYING, which
-* you should have received as part of this distribution. The terms
-* are also available at
-* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-*
-*/
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2007-2008 - INRIA - Bruno JOFRET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
#ifndef __VARIABLES_HXX__
#define __VARIABLES_HXX__
-#include <map>
-#include <list>
-#include "types.hxx"
+#include <string>
+#include <stack>
#include "symbol.hxx"
-#include "function.hxx"
+#include "internal.hxx"
+#include "double.hxx"
+#include "export_symbol.h"
namespace symbol
{
-struct VarBox
+struct EXTERN_SYMBOL ScopedVariable
{
- VarBox(int _iLevel, types::InternalType* _pIT, bool _bGlobal = false, bool _bGlobalVisible = false);
+ ScopedVariable(int _iLevel, types::InternalType* _pIT)
+ : m_iLevel(_iLevel), m_pIT(_pIT), m_globalVisible(false) {}
int m_iLevel;
+ bool m_globalVisible;
types::InternalType* m_pIT;
- bool m_bGlobal;
- bool m_bGlobalVisible;
};
-class Variables
+struct EXTERN_SYMBOL Variable
{
+ Variable(const Symbol& _name) : name(_name), m_Global(false), m_GlobalValue(NULL) {};
+
+ void put(types::InternalType* _pIT, int _iLevel)
+ {
+ if (isGlobal() && isGlobalVisible(_iLevel))
+ {
+ setGlobalValue(_pIT);
+ return;
+ }
+
+ if (empty() || top()->m_iLevel < _iLevel)
+ {
+ //create a new level
+ stack.push(new ScopedVariable(_iLevel, _pIT));
+ _pIT->IncreaseRef();
+ }
+ else
+ {
+ //update current level
+ types::InternalType* pIT = top()->m_pIT;
+ if (pIT != _pIT)
+ {
+ pIT->DecreaseRef();
+ if (pIT->isDeletable())
+ {
+ delete pIT;
+ }
+
+ top()->m_pIT = _pIT;
+ _pIT->IncreaseRef();
+ }
+ }
+ }
+
+ types::InternalType* get() const
+ {
+ if (empty())
+ {
+ return NULL;
+ }
+
+ if (m_Global && top()->m_globalVisible)
+ {
+ return m_GlobalValue;
+ }
+ else
+ {
+ return top()->m_pIT;
+ }
+ }
+
+ bool empty() const
+ {
+ return stack.empty();
+ }
+
+ ScopedVariable* top() const
+ {
+ return stack.top();
+ }
+
+ void pop()
+ {
+ stack.pop();
+ }
+
+ Symbol name_get() const
+ {
+ return name;
+ }
+
+ //globals
+
+ void setGlobal(bool _bGlobal)
+ {
+ m_Global = _bGlobal;
+ }
+
+ bool isGlobal()
+ {
+ return m_Global;
+ }
+
+ bool isGlobalVisible(int _iLevel)
+ {
+ if (empty() == false)
+ {
+ if (top()->m_iLevel == _iLevel)
+ {
+ return top()->m_globalVisible;
+ }
+ }
+
+ return false;
+ }
+
+ void setGlobalVisible(int _iLevel, bool _bVisible)
+ {
+ if (empty() || top()->m_iLevel != _iLevel)
+ {
+ stack.push(new ScopedVariable(_iLevel, types::Double::Empty()));
+ }
+
+
+ top()->m_globalVisible = _bVisible;
+ }
+
+ void setGlobalValue(types::InternalType* _pIT)
+ {
+ if (m_GlobalValue != _pIT)
+ {
+ if (m_GlobalValue)
+ {
+ m_GlobalValue->DecreaseRef();
+ if (m_GlobalValue->isDeletable())
+ {
+ delete m_GlobalValue;
+ }
+ }
+
+ m_GlobalValue = _pIT;
+ if (_pIT != NULL)
+ {
+ _pIT->IncreaseRef();
+ }
+ }
+ }
+
+ types::InternalType* getGlobalValue()
+ {
+ return m_GlobalValue;
+ }
+
private :
- //current scope level
- int m_iLevel;
+ Symbol name;
+ types::InternalType* m_GlobalValue;
+ bool m_Global;
+ typedef std::stack<ScopedVariable*> StackVar;
+ StackVar stack;
+};
+
+struct Variables
+{
+ Variables() {};
+
+ Variable* getOrCreate(const Symbol& _key)
+ {
+ std::wstring toto = _key.name_get();
+ MapVars::const_iterator it = vars.find(_key);
+ if (it == vars.end())
+ {
+ //create an empty StackedValues
+ Variable* var = new Variable(_key);
+ vars[_key] = var;
+ return var;
+ }
+
+ return it->second;
+ }
+
+ void put(const Symbol& _key, types::InternalType* _pIT, int _iLevel)
+ {
+ Variable* var = getOrCreate(_key);
+ var->put(_pIT, _iLevel);
+ }
+
+ types::InternalType* get(const Symbol& _key, int _iLevel)
+ {
+ MapVars::const_iterator it = vars.find(_key);
+ if (it != vars.end() && it->second->empty() == false)
+ {
+ if (_iLevel == -1 || it->second->top()->m_iLevel == _iLevel)
+ {
+ return it->second->get();
+ }
+ }
+
+ return NULL;
+ }
+
+ types::InternalType* get(Variable* _var, int _iLevel)
+ {
+ if (_var != NULL && _var->empty() == false)
+ {
+ if (_iLevel == -1 || _var->top()->m_iLevel == _iLevel)
+ {
+ return _var->get();
+ }
+ }
+
+ return NULL;
+ }
+
+ types::InternalType* getAllButCurrentLevel(const Symbol& _key, int _iLevel)
+ {
+ MapVars::const_iterator it = vars.find(_key);
+ if (it != vars.end() && it->second->empty() == false)
+ {
+ if (it->second->top()->m_iLevel < _iLevel)
+ {
+ return it->second->get();
+ }
+ else
+ {
+ ScopedVariable* pSave = it->second->top();
+ it->second->pop();
+ types::InternalType* pIT = getAllButCurrentLevel(_key, _iLevel);
+ it->second->put(pSave->m_pIT, pSave->m_iLevel);
+ return pIT;
+ }
+ }
+
+ return NULL;
+ }
+
+ bool remove(Variable* _var, int _iLevel)
+ {
+ if (_var->empty() == false)
+ {
+ if (_var->top()->m_iLevel == _iLevel)
+ {
+ types::InternalType* pIT = _var->top()->m_pIT;
+ pIT->DecreaseRef();
+ if (pIT->isDeletable())
+ {
+ delete pIT;
+ }
+
+ _var->pop();
+ }
+ }
+
+ return true;
+ }
+
+ bool remove(const Symbol& _key, int _iLevel)
+ {
+ MapVars::iterator it = vars.find(_key);
+ if (it != vars.end())
+ {
+ Variable* pVar = it->second;
+ return remove(pVar, _iLevel);
+ }
- typedef std::list<VarBox* > VarBoxList;
- typedef std::map<Symbol, VarBoxList*> VarMap;
- typedef std::map<Symbol, types::InternalType*> GlobalMap;
- VarMap m_vars;
- GlobalMap m_globals;
+ return false;
+ }
- void removeGlobal(GlobalMap::iterator& _it);
-public :
- Variables() : m_iLevel(-1) {}
+ std::list<std::wstring>* getMacrosName()
+ {
+ std::list<std::wstring>* plOut = new std::list<std::wstring>();
+ MapVars::const_iterator it = vars.begin();
+ for (; it != vars.end(); ++it)
+ {
+ if (it->second->empty() == false)
+ {
+ types::InternalType* pIT = it->second->top()->m_pIT;
+ if (pIT && (pIT->isMacro() || pIT->isMacroFile()))
+ {
+ plOut->push_back(it->first.name_get().c_str());
+ }
+ }
+ }
- virtual ~Variables() {}
+ return plOut;
+ }
- void put(const Symbol& _key, types::InternalType& _pIT);
- void put(const Symbol& _key, types::InternalType& _iT, int _iLevel);
- void putInPreviousScope(const Symbol& _key, types::InternalType& _iT);
+ std::list<Symbol>* getFunctionList(std::wstring _stModuleName, int _iLevel)
+ {
+ std::list<Symbol>* symb = new std::list<Symbol>();
- types::InternalType* get(const Symbol& _key) const;
- types::InternalType* getCurrentLevel(const Symbol& _key) const;
- types::InternalType* getAllButCurrentLevel(const Symbol& _key) const;
- types::InternalType* getInSpecificLevel(const Symbol& _key, int _iLevel) const;
+ MapVars::iterator it = vars.begin();
+ for (; it != vars.end() ; ++it)
+ {
+ if (it->second->empty())
+ {
+ continue;
+ }
- std::list<symbol::Symbol>* getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd) const;
- std::list<std::wstring>* getVarsName();
- std::list<std::wstring>* getMacrosName();
- std::list<std::wstring>* getFunctionsName();
+ if ((it->second->top()->m_iLevel == _iLevel || _iLevel == 1) && it->second->top()->m_pIT->isCallable())
+ {
+ types::Callable* pCall = it->second->top()->m_pIT->getAs<types::Callable>();
+ if (_stModuleName == L"" || _stModuleName == pCall->getModule())
+ {
+ symb->push_back(it->first);
+ }
+ }
+ }
- /*globals*/
- bool isGlobalVisible(const symbol::Symbol& _key) const;
- void setGlobalVisible(const symbol::Symbol& _key, bool bVisible);
- void removeGlobal(const symbol::Symbol& _key);
- void removeGlobalAll();
- void createEmptyGlobalValue(const symbol::Symbol& _key);
- bool isGlobalExists(const symbol::Symbol& _key) const;
- types::InternalType* getGlobalValue(const symbol::Symbol& _key) const;
- void setGlobalValue(const symbol::Symbol& _key, types::InternalType& _value);
+ return symb;
+ }
- bool remove(const Symbol& _key);
+ bool putInPreviousScope(Variable* _var, types::InternalType* _pIT, int _iLevel)
+ {
+ if (_var->empty())
+ {
+ _var->put(_pIT, _iLevel);
+ }
+ else if (_var->top()->m_iLevel > _iLevel)
+ {
+ ScopedVariable* pVar = _var->top();
+ _var->pop();
+ putInPreviousScope(_var, _pIT, _iLevel);
+ _var->put(pVar->m_pIT, pVar->m_iLevel);
+ }
+ else
+ {
+ _var->put(_pIT, _iLevel);
+ }
- void IncreaseLevel()
+ return true;
+ }
+
+ //globals
+
+ void setGlobal(const Symbol& _key)
+ {
+ getOrCreate(_key)->setGlobal(true);
+ }
+
+ void setGlobalVisible(const Symbol& _key, bool _bVisible, int _iLevel)
{
- m_iLevel++;
+ Variable* pVar = getOrCreate(_key);
+ pVar->setGlobalVisible(_iLevel, _bVisible);
+ if (_bVisible)
+ {
+ pVar->setGlobal(true);
+ }
}
- void DecreaseLevel()
+
+ bool isGlobalVisible(const Symbol& _key, int _iLevel)
{
- m_iLevel--;
+ return getOrCreate(_key)->isGlobalVisible(_iLevel);
}
+
+ bool isGlobal(const Symbol& _key, int _iLevel)
+ {
+ return getOrCreate(_key)->isGlobal();
+ }
+
+ types::InternalType* getGlobalValue(const Symbol& _key)
+ {
+ return getOrCreate(_key)->getGlobalValue();
+ }
+
+ void removeGlobal(const Symbol& _key, int _iLevel)
+ {
+ Variable* pVar = getOrCreate(_key);
+ if (pVar->isGlobal())
+ {
+ pVar->setGlobal(false);
+ pVar->setGlobalValue(NULL);
+ }
+
+ remove(pVar, _iLevel);
+ }
+
+private:
+ typedef std::map<Symbol, Variable*> MapVars;
+ MapVars vars;
};
}
-#endif /* !__VARIABLES_HXX__ */
+
+#endif // !__VARIABLES_HXX__
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
*
*/
-
#include "context.hxx"
+#include "internal.hxx"
#include "function.hxx"
#include "macro.hxx"
#include "macrofile.hxx"
+#include "variables.hxx"
namespace symbol
{
Context::Context()
{
- m_scopes = new Scopes();
- m_scopes->scope_begin();
+ m_iLevel = 0;
+ varStack.push(new VarList());
+ globals = new std::list<Symbol>();
}
Context* Context::getInstance(void)
void Context::scope_begin()
{
- m_scopes->scope_begin();
+ m_iLevel++;
+ varStack.push(new VarList());
}
void Context::scope_end()
{
- m_scopes->scope_end();
+ //clear varList of current scope
+ if (varStack.empty() == false)
+ {
+ clearCurrentScope(true);
+ }
+
+ m_iLevel--;
+}
+
+bool Context::clearCurrentScope(bool _bClose)
+{
+ if (varStack.empty())
+ {
+ return true;
+ }
+
+ VarList* varList = varStack.top();
+ std::map<Symbol, Variable*>::iterator it = varList->begin();
+ for (; it != varList->end() ; ++it)
+ {
+ if (it->second->empty() == false && it->second->top()->m_iLevel == m_iLevel)
+ {
+ types::InternalType* pIT = it->second->top()->m_pIT;
+ pIT->DecreaseRef();
+ if (pIT->isDeletable())
+ {
+ delete pIT;
+ }
+
+ it->second->pop();
+ }
+ }
+
+ varList->clear();
+
+ if (_bClose)
+ {
+ delete varList;
+ varStack.pop();
+ }
+
+ return true;
+}
+
+Variable* Context::getOrCreate(const Symbol& _key)
+{
+ return variables.getOrCreate(_key);
+}
+
+types::InternalType* Context::get(const Symbol& _key)
+{
+ return get(_key, -1);
+}
+
+types::InternalType* Context::get(const Variable* _var)
+{
+ types::InternalType* pIT = _var->get();
+
+ if (pIT == NULL)
+ {
+ //look in libraries
+ pIT = libraries.get(_var->name_get(), -1);
+ if (pIT)
+ {
+ put((Variable*)_var, pIT);
+ }
+ }
+
+ return pIT;
}
-types::InternalType* Context::get(const symbol::Symbol& _key) const
+types::InternalType* Context::get(const Symbol& _key, int _iLevel)
{
- return m_scopes->get(_key);
+ types::InternalType* pIT = NULL;
+ if (_iLevel == m_iLevel || _iLevel == -1)
+ {
+ //look for in current VarList
+ VarList::iterator it = varStack.top()->find(_key);
+ if (it != varStack.top()->end())
+ {
+ if (it->second->empty() == false)
+ {
+ return it->second->top()->m_pIT;
+ }
+ }
+ }
+
+ if (pIT == NULL)
+ {
+ pIT = variables.get(_key, _iLevel);
+ if (pIT == NULL)
+ {
+ //find in libraries
+ pIT = libraries.get(_key, _iLevel);
+ if (pIT)
+ {
+ //add symbol to current scope
+ put(_key, pIT);
+ }
+ }
+ }
+
+ return pIT;
}
-types::InternalType* Context::getCurrentLevel(const symbol::Symbol& _key) const
+types::InternalType* Context::getCurrentLevel(const Symbol& _key)
{
- return m_scopes->getCurrentLevel(_key);
+ return variables.get(_key, m_iLevel);
}
-types::InternalType* Context::getAllButCurrentLevel(const symbol::Symbol& _key) const
+types::InternalType* Context::getAllButCurrentLevel(const Symbol& _key)
{
- return m_scopes->getAllButCurrentLevel(_key);
+ return variables.getAllButCurrentLevel(_key, m_iLevel);
}
-types::InternalType* Context::getFunction(const symbol::Symbol& _key) const
+types::InternalType* Context::getFunction(const Symbol& _key)
{
- return m_scopes->get(_key);
+ return get(_key);
}
-std::list<symbol::Symbol>* Context::getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd)
+std::list<Symbol>* Context::getFunctionList(std::wstring _stModuleName)
{
- return m_scopes->getFunctionList(_stModuleName, _bFromEnd);
+ return variables.getFunctionList(_stModuleName, m_iLevel);
}
std::list<std::wstring>* Context::getVarsName()
{
- return m_scopes->getVarsName();
+ return new std::list<std::wstring>();
+ //return scopes.getVarsName();
}
std::list<std::wstring>* Context::getMacrosName()
{
- return m_scopes->getMacrosName();
+ std::list<std::wstring>* vars = variables.getMacrosName();
+ std::list<std::wstring>* libs = libraries.getMacrosName();
+ vars->insert(vars->end(), libs->begin(), libs->end());
+ delete libs;
+ return vars;
}
std::list<std::wstring>* Context::getFunctionsName()
{
- return m_scopes->getFunctionsName();
+ return new std::list<std::wstring>();
+ //return scopes.getFunctionsName();
}
-bool Context::put(const symbol::Symbol& _key, types::InternalType &type)
+void Context::put(Variable* _var, types::InternalType* _pIT)
{
- m_scopes->put(_key, type);
- return true;
+ _var->put(_pIT, m_iLevel);
+ if (varStack.empty() == false)
+ {
+ (*varStack.top())[_var->name_get()] = _var;
+ }
}
-bool Context::remove(const symbol::Symbol& _key)
+void Context::put(const Symbol& _key, types::InternalType* _pIT)
{
- m_scopes->remove(_key);
- return true;
+ Variable* var = variables.getOrCreate(_key);
+ put(var, _pIT);
+ if (_pIT->isLibrary())
+ {
+ Library* lib = libraries.getOrCreate(_key);
+ lib->put((types::Library*)_pIT, m_iLevel);
+ }
}
-bool Context::putInPreviousScope(const symbol::Symbol& _key, types::InternalType &type)
+bool Context::remove(const Symbol& _key)
{
- m_scopes->putInPreviousScope(_key, type);
- return true;
+ if (variables.remove(_key, m_iLevel))
+ {
+ varStack.top()->erase(_key);
+ libraries.remove(_key, m_iLevel);
+ return true;
+ }
+
+ return false;
}
-bool Context::addFunction(types::Function *_info)
+bool Context::removeAll()
{
- m_scopes->addFunction(symbol::Symbol(_info->getName()), *_info);
+ return clearCurrentScope(false);
+}
+
+bool Context::putInPreviousScope(Variable* _var, types::InternalType* _pIT)
+{
+ //add variable in previous scope
+ variables.putInPreviousScope(_var, _pIT, m_iLevel - 1);
+
+ //add variable in stack of using variables
+ if (varStack.empty() == false)
+ {
+ VarList *list = varStack.top();
+ varStack.pop();
+ if (varStack.empty() == false)
+ {
+ (*varStack.top())[_var->name_get()] = _var;
+ varStack.push(list);
+ }
+ }
return true;
}
-bool Context::AddMacro(types::Macro *_info)
+bool Context::addFunction(types::Function *_info)
{
- m_scopes->put(symbol::Symbol(_info->getName()), *_info);
+ put(Symbol(_info->getName()), _info);
return true;
}
-bool Context::AddMacroFile(types::MacroFile *_info)
+bool Context::addMacro(types::Macro *_info)
{
- m_scopes->put(symbol::Symbol(_info->getName()), *_info);
+ put(Symbol(_info->getName()), _info);
return true;
}
-bool Context::isGlobalVisible(const symbol::Symbol& _key) const
+bool Context::addMacroFile(types::MacroFile *_info)
{
- return m_scopes->isGlobalVisible(_key);
+ put(Symbol(_info->getName()), _info);
+ return true;
}
-/*return global variable, search in global scope ( highest )*/
-types::InternalType* Context::getGlobalValue(const symbol::Symbol& _key) const
+bool Context::isGlobalVisible(const Symbol& _key)
{
- m_scopes->getGlobalValue(_key);
- return NULL;
+ return variables.isGlobalVisible(_key, m_iLevel);
}
/*return global variable existance status*/
-bool Context::isGlobalExists(const symbol::Symbol& _key) const
+bool Context::isGlobal(const Symbol& _key)
{
- return m_scopes->isGlobalExists(_key);
+ return variables.isGlobal(_key, m_iLevel);
}
-void Context::setGlobalValue(const symbol::Symbol& _key, types::InternalType &value)
+types::InternalType* Context::getGlobalValue(const Symbol& _key)
{
- m_scopes->setGlobalValue(_key, value);
+ return variables.getGlobalValue(_key);
}
-void Context::createEmptyGlobalValue(const symbol::Symbol& _key)
+void Context::setGlobalVisible(const Symbol& _key, bool bVisible)
{
- m_scopes->createEmptyGlobalValue(_key);
+ variables.setGlobalVisible(_key, bVisible, m_iLevel);
}
-void Context::setGlobalVisible(const symbol::Symbol& _key, bool bVisible)
+void Context::setGlobal(const Symbol& _key)
{
- m_scopes->setGlobalVisible(_key, bVisible);
+ variables.setGlobal(_key);
+ globals->push_back(_key);
}
-void Context::removeGlobal(const symbol::Symbol& _key)
+void Context::removeGlobal(const Symbol& _key)
{
- m_scopes->removeGlobal(_key);
+ variables.removeGlobal(_key, m_iLevel);
}
void Context::removeGlobalAll()
{
- m_scopes->removeGlobalAll();
+ std::list<Symbol>::iterator it = globals->begin();
+ for (; it != globals->end(); ++it)
+ {
+ removeGlobal(*it);
+ }
+
+ globals->clear();
}
void Context::print(std::wostream& ostr) const
{
ostr << L" Environment Variables:" << std::endl;
ostr << L"==========================" << std::endl;
- ostr << *m_scopes;
}
}
+++ /dev/null
-/*
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
-*
-* This file must be used under the terms of the CeCILL.
-* This source file is licensed as described in the file COPYING, which
-* you should have received as part of this distribution. The terms
-* are also available at
-* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-*
-*/
-
-#include "libraries.hxx"
-#include "context.hxx"
-
-namespace symbol
-{
-types::MacroFile* LibBox::getMacroFile(const Symbol& _key)
-{
- return m_pLib->get(_key.name_get());
-}
-
-void Libraries::put(const Symbol& _key, types::InternalType& _iT)
-{
- if (_iT.isLibrary() == false)
- {
- return;
- }
-
- types::Library* pLib = _iT.getAs<types::Library>();
-
- LibMap::iterator itVar = m_libmap.find(_key);
- LibBoxList* pL = NULL;
- LibBox* pBox = NULL;
-
- if (itVar != m_libmap.end())
- {
- //item alreay exists
-
- //check scope level
- LibBoxList::reverse_iterator itBox = itVar->second->rbegin();
-
- bool bInserted = false;
- for (; itBox != itVar->second->rend() ; itBox++)
- {
- pBox = *itBox;
- if ((*itBox)->getValue() == pLib)
- {
- return;
- }
-
- //update value
- (*itBox)->setValue(*pLib);
- bInserted = true;
- break;
- }
- }
- else
- {
- //new var
- pBox = new LibBox(m_iLevel, *pLib);
- pL = new LibBoxList();
- pL->push_back(pBox);
- m_libmap[_key] = pL;
- m_liblist.push_back(_key);
- }
-
- return;
-}
-
-types::MacroFile* Libraries::get(const Symbol& _key) const
-{
- types::MacroFile* pIT = NULL;
- LibList::const_reverse_iterator it = m_liblist.rbegin();
- for (; it != m_liblist.rend() ; ++it)
- {
- LibBoxList* l = m_libmap.find(*it)->second;
- LibBoxList::const_reverse_iterator itBox = l->rbegin();
- for (; itBox != l->rend(); ++itBox)
- {
- pIT = (*itBox)->getMacroFile(_key);
- if (pIT)
- {
- Context::getInstance()->AddMacroFile(pIT);
- return pIT;
- }
- }
- }
-
- return pIT;
-}
-
-bool Libraries::remove(const Symbol& _key)
-{
- LibMap::iterator itVar = m_libmap.find(_key);
- if (itVar != m_libmap.end())
- {
- LibBox* pBox = itVar->second->back();
- if (pBox->getLevel() != m_iLevel)
- {
- return false;
- }
-
- if (pBox->getValue())
- {
- delete pBox;
- }
-
- itVar->second->pop_back();
-
- //remove empty entries from variable map
- if (itVar->second->empty())
- {
- m_liblist.remove(itVar->first);
- m_libmap.erase(itVar);
- }
- return true;
- }
- else
- {
- return false;
- }
-}
-
-std::list<std::wstring>* Libraries::getMacrosName()
-{
- std::list<std::wstring>* plOut = new std::list<std::wstring>();
- types::Library* pLib = NULL;
- LibMap::const_iterator it = m_libmap.begin();
-
- for (; it != m_libmap.end(); it++)
- {
- pLib = it->second->back()->getValue();
- std::list<std::wstring>* tmpList = pLib->getMacrosName();
- plOut->insert(plOut->end(), tmpList->begin(), tmpList->end());
- delete tmpList;
- }
-
- return plOut;
-}
-
-}
+++ /dev/null
-/*
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
-*
-* This file must be used under the terms of the CeCILL.
-* This source file is licensed as described in the file COPYING, which
-* you should have received as part of this distribution. The terms
-* are also available at
-* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-*
-*/
-
-#include "variables.hxx"
-#include "callable.hxx"
-#include "double.hxx"
-
-namespace symbol
-{
-VarBox::VarBox(int _iLevel, types::InternalType* _pIT, bool _bGlobal, bool _bGlobalVisible)
- : m_iLevel(_iLevel), m_pIT(_pIT), m_bGlobal(_bGlobal), m_bGlobalVisible(_bGlobalVisible)
-{
- if (m_pIT)
- {
- m_pIT->IncreaseRef();
- }
-}
-
-void Variables::put(const Symbol& _key, types::InternalType& _pIT)
-{
- put(_key, _pIT, m_iLevel);
-}
-
-void Variables::put(const Symbol& _key, types::InternalType& _iT, int _iLevel)
-{
- if (isGlobalVisible(_key))
- {
- setGlobalValue(_key, _iT);
- return;
- }
- VarMap::iterator itVar = m_vars.find(_key);
- VarBoxList* pL = NULL;
- VarBox* pBox = NULL;
-
- if (itVar != m_vars.end())
- {
- //item alreay exists
-
- //check scope level
- VarBoxList::reverse_iterator itBox = itVar->second->rbegin();
-
- bool bInserted = false;
- for (; itBox != itVar->second->rend() ; itBox++)
- {
- pBox = *itBox;
- if ((*itBox)->m_iLevel > _iLevel)
- {
- continue;
- }
- else if ((*itBox)->m_iLevel < _iLevel)
- {
- pBox = new VarBox(_iLevel, &_iT);
- itVar->second->insert(itBox.base(), pBox);
- bInserted = true;
- break;
- }
- else if ((*itBox)->m_iLevel == _iLevel)
- {
- if ((*itBox)->m_pIT == &_iT)
- {
- return;
- }
-
- //increase ref
- _iT.IncreaseRef();
-
- (*itBox)->m_pIT->DecreaseRef();
- if ((*itBox)->m_pIT->isDeletable())
- {
- delete (*itBox)->m_pIT;
- }
-
- //update value
- (*itBox)->m_pIT = &_iT;
- bInserted = true;
- break;
- }
- }
-
- if (bInserted == false)
- {
- //for case of first var ref is in higher scope
- pBox = new VarBox(_iLevel, &_iT);
- itVar->second->push_front(pBox);
- }
- }
- else
- {
- //new var
- pBox = new VarBox(_iLevel, &_iT);
- pL = new VarBoxList();
- pL->push_back(pBox);
- m_vars[_key] = pL;
- }
-
- return;
-}
-
-void Variables::putInPreviousScope(const Symbol& _key, types::InternalType& _iT)
-{
- put(_key, _iT, Max(0, m_iLevel - 1));
-}
-
-types::InternalType* Variables::get(const Symbol& _key) const
-{
- if (isGlobalExists(_key) && isGlobalVisible(_key))
- {
- return getGlobalValue(_key);
- }
- else
- {
- VarMap::const_iterator itVar = m_vars.find(_key);
- if (itVar != m_vars.end())
- {
- if (m_iLevel != itVar->second->back()->m_iLevel && itVar->second->back()->m_bGlobal == true)
- {
- return getGlobalValue(_key);
- }
-
- return itVar->second->back()->m_pIT;
- }
- else
- {
- return NULL;
- }
- }
-}
-
-types::InternalType* Variables::getCurrentLevel(const Symbol& _key) const
-{
- if (isGlobalExists(_key) && isGlobalVisible(_key))
- {
- return getGlobalValue(_key);
- }
- else
- {
- VarMap::const_iterator itVar = m_vars.find(_key);
- if (itVar != m_vars.end() && itVar->second->back()->m_iLevel == m_iLevel)
- {
- return itVar->second->back()->m_pIT;
- }
- else
- {
- return NULL;
- }
- }
-}
-
-types::InternalType* Variables::getAllButCurrentLevel(const Symbol& _key) const
-{
- VarMap::const_iterator itVar = m_vars.find(_key);
- if (itVar != m_vars.end())
- {
- VarBoxList* pL = itVar->second;
- VarBoxList::iterator itBox = pL->begin();
- for (; itBox != pL->end() ; itBox++)
- {
- if ((*itBox)->m_iLevel < m_iLevel)
- {
- return (*itBox)->m_pIT;
- }
- }
- }
-
- return NULL;
-}
-
-types::InternalType* Variables::getInSpecificLevel(const Symbol& _key, int _iLevel) const
-{
- VarMap::const_iterator itVar = m_vars.find(_key);
- if (itVar != m_vars.end())
- {
- VarBoxList* pL = itVar->second;
- VarBoxList::iterator itBox = pL->begin();
- for (; itBox != pL->end() ; itBox++)
- {
- if ((*itBox)->m_iLevel == _iLevel)
- {
- return (*itBox)->m_pIT;
- }
- }
- }
-
- return NULL;
-}
-
-bool Variables::remove(const Symbol& _key)
-{
- VarMap::iterator itVar = m_vars.find(_key);
- if (itVar != m_vars.end())
- {
- VarBox* pBox = itVar->second->back();
- if (pBox->m_iLevel != m_iLevel)
- {
- return false;
- }
-
- if (pBox->m_pIT)
- {
- pBox->m_pIT->DecreaseRef();
- if (pBox->m_pIT->isDeletable())
- {
- delete pBox->m_pIT;
- }
-
- delete pBox;
- }
-
- itVar->second->pop_back();
-
- //remove empty entries from variable map
- if (itVar->second->empty())
- {
- m_vars.erase(itVar);
- }
- return true;
- }
- else
- {
- return false;
- }
-}
-
-std::list<std::wstring>* Variables::getVarsName()
-{
- std::list<std::wstring>* plOut = new std::list<std::wstring>();
- types::InternalType* pIT = NULL;
- VarMap::const_iterator it = m_vars.begin();
-
- for (; it != m_vars.end(); it++)
- {
- pIT = it->second->front()->m_pIT;
- if (pIT && pIT->isCallable() == false)
- {
- plOut->push_back(it->first.name_get().c_str());
- }
- }
-
- return plOut;
-}
-
-std::list<std::wstring>* Variables::getMacrosName()
-{
- std::list<std::wstring>* plOut = new std::list<std::wstring>();
- types::InternalType* pIT = NULL;
- VarMap::const_iterator it = m_vars.begin();
-
- for (; it != m_vars.end(); it++)
- {
- pIT = it->second->front()->m_pIT;
- if (pIT && (pIT->isMacro() || pIT->isMacroFile()))
- {
- plOut->push_back(it->first.name_get().c_str());
- }
- }
-
- return plOut;
-}
-
-std::list<std::wstring>* Variables::getFunctionsName()
-{
- std::list<std::wstring>* plOut = new std::list<std::wstring>();
- types::InternalType* pIT = NULL;
- VarMap::const_iterator it = m_vars.begin();
-
- for (; it != m_vars.end(); it++)
- {
- pIT = it->second->front()->m_pIT;
- if (pIT && pIT->isFunction())
- {
- plOut->push_back(it->first.name_get().c_str());
- }
- }
-
- return plOut;
-}
-
-std::list<symbol::Symbol>* Variables::getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd) const
-{
- bool bAll = _stModuleName == L"";
- std::list<symbol::Symbol>* lst = new std::list<symbol::Symbol>;
-
- VarMap::const_iterator it = m_vars.begin();
- for (; it != m_vars.end(); it++)
- {
- types::InternalType* pIT = NULL;
- if (it->second->size() == 0)
- {
- continue;
- }
-
- if (_bFromEnd)
- {
- pIT = it->second->front()->m_pIT;
- }
- else
- {
- VarBox* pBox = it->second->back();
- if (pBox->m_iLevel != m_iLevel)
- {
- continue;
- }
-
- pIT = pBox->m_pIT;
- }
-
- //exclude globals
- if (pIT == NULL)
- {
- continue;
- }
-
- if (pIT->isCallable() == false)
- {
- continue;
- }
-
- if (bAll)
- {
- lst->push_back(it->first);
- continue;
- }
-
- types::Callable* pC = pIT->getAs<types::Callable>();
- if (_stModuleName == pC->getModule())
- {
- lst->push_back(it->first);
- }
-
- }
- return lst;
-}
-
-bool Variables::isGlobalVisible(const symbol::Symbol& _key) const
-{
- VarMap::const_iterator itVar = m_vars.find(_key);
- if (itVar != m_vars.end())
- {
- VarBoxList* pL = itVar->second;
- VarBox* pBox = pL->back();
- if (pBox->m_iLevel == m_iLevel && pBox->m_bGlobal && pBox->m_bGlobalVisible)
- {
- return true;
- }
- }
-
- return false;
-}
-
-void Variables::setGlobalVisible(const symbol::Symbol& _key, bool bVisible)
-{
- VarBox* pBox = NULL;
- VarBoxList* pL = NULL;
-
- VarMap::const_iterator itVar = m_vars.find(_key);
- if (itVar != m_vars.end())
- {
- VarBoxList* pL = itVar->second;
- pBox = pL->back();
- if (pBox->m_iLevel == m_iLevel)
- {
- //update
-
- pBox->m_bGlobalVisible = true;
- pBox->m_bGlobal = true;
- }
- else
- {
- //add in existing VarBoxList
- pBox = new VarBox(m_iLevel, NULL);
- pBox->m_bGlobalVisible = true;
- pBox->m_bGlobal = true;
- pL->push_back(pBox);
- }
- }
- else
- {
- //create a new VarBoxList
- pBox = new VarBox(m_iLevel, NULL);
- pBox->m_bGlobalVisible = true;
- pBox->m_bGlobal = true;
- pL = new VarBoxList();
- pL->push_back(pBox);
- m_vars[_key] = pL;
- }
-}
-
-void Variables::removeGlobal(const symbol::Symbol& _key)
-{
- GlobalMap::iterator it = m_globals.find(_key);
- if (it != m_globals.end())
- {
- removeGlobal(it);
- }
-}
-
-void Variables::removeGlobal(GlobalMap::iterator& _it)
-{
- //remove all refs in scopes
- Symbol key = _it->first;
-
- VarMap::iterator itVar = m_vars.find(key);
- if (itVar != m_vars.end())
- {
- VarBoxList* pLBox = itVar->second;
- VarBoxList::iterator itBox = pLBox->begin();
- while (itBox != pLBox->end())
- {
- VarBox* pBox = (*itBox);
- if (pBox->m_pIT != NULL)
- {
- pBox->m_bGlobal = false;
- pBox->m_bGlobalVisible = false;
- itBox++;
- }
- else
- {
- VarBoxList::iterator itSave = itBox;
- itSave++;
- pLBox->erase(itBox);
- itBox = itSave;
- }
-
- }
-
- if (pLBox->empty())
- {
- m_vars.erase(key);
- }
- }
-
- _it->second->DecreaseRef();
- if (_it->second->isDeletable())
- {
- delete _it->second;
- }
-
- m_globals.erase(_it);
-}
-
-void Variables::removeGlobalAll()
-{
- //for all globals, remove them and all references in scopes
- GlobalMap::iterator it;
- while ((it = m_globals.begin()) != m_globals.end())
- {
- removeGlobal(it);
- }
-}
-
-void Variables::createEmptyGlobalValue(const symbol::Symbol& _key)
-{
- types::InternalType* pIT = types::Double::Empty();
- pIT->IncreaseRef();
- m_globals[_key] = pIT;
-}
-
-bool Variables::isGlobalExists(const symbol::Symbol& _key) const
-{
- return (m_globals.find(_key) != m_globals.end());
-}
-
-types::InternalType* Variables::getGlobalValue(const symbol::Symbol& _key) const
-{
- GlobalMap::const_iterator it = m_globals.find(_key);
- if (it != m_globals.end())
- {
- return it->second;
- }
- else
- {
- return NULL;
- }
-}
-
-void Variables::setGlobalValue(const symbol::Symbol& _key, types::InternalType& _value)
-{
- GlobalMap::iterator it = m_globals.find(_key);
- if (it != m_globals.end())
- {
- if (it->second != NULL)
- {
- it->second->DecreaseRef();
- if (it->second->isDeletable())
- {
- delete it->second;
- }
- }
-
- _value.IncreaseRef();
- m_globals[_key] = &_value;
- }
-}
-
-}
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\cpp\context.cpp" />
- <ClCompile Include="src\cpp\libraries.cpp" />
- <ClCompile Include="src\cpp\scope.cpp" />
<ClCompile Include="src\cpp\symbol.cpp" />
- <ClCompile Include="src\cpp\variables.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="includes\context.hxx" />
<ClInclude Include="includes\export_symbol.h" />
<ClInclude Include="includes\libraries.hxx" />
- <ClInclude Include="includes\scope.hxx" />
<ClInclude Include="includes\symbol.hxx" />
<ClInclude Include="includes\variables.hxx" />
</ItemGroup>
<ClCompile Include="src\cpp\symbol.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\cpp\variables.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="src\cpp\scope.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="src\cpp\libraries.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="includes\context.hxx">
<ClInclude Include="includes\symbol.hxx">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="includes\variables.hxx">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="includes\scope.hxx">
+ <ClInclude Include="includes\libraries.hxx">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="includes\libraries.hxx">
+ <ClInclude Include="includes\variables.hxx">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
{
//add SCI value in context as variable
types::String *pS = new types::String(_home);
- symbol::Context::getInstance()->put(symbol::Symbol(L"home"), *pS);
+ symbol::Context::getInstance()->put(symbol::Symbol(L"home"), pS);
std::wstring home(_home);
ConfigVariable::setHOME(home);
#include "getenvc.h"
}
+using namespace std;
/*--------------------------------------------------------------------------*/
wchar_t* getSCIHOMEW(void)
{
{
//add SCI value in context as variable
types::String *pS = new types::String(_sci_home);
- symbol::Context::getInstance()->put(symbol::Symbol(L"SCIHOME"), *pS);
+ symbol::Context::getInstance()->put(symbol::Symbol(L"SCIHOME"), pS);
std::wstring sci_home(_sci_home);
ConfigVariable::setSCIHOME(sci_home);
#include "getenvc.h"
}
+using namespace std;
char *getSCI(void)
{
return wide_string_to_UTF8(ConfigVariable::getSCIPath().c_str());
//SCI
wchar_t* pwstSCI = to_wide_string(pstSlash);
types::String *pSSCI = new types::String(pwstSCI);
- symbol::Context::getInstance()->put(symbol::Symbol(L"SCI"), *pSSCI);
+ symbol::Context::getInstance()->put(symbol::Symbol(L"SCI"), pSSCI);
//WSCI
wchar_t* pwstWSCI = NULL;
SlashToAntislash(_sci_path, pstBackSlash);
pwstWSCI = to_wide_string(pstBackSlash);
types::String *pSWSCI = new types::String(pwstWSCI);
- symbol::Context::getInstance()->put(symbol::Symbol(L"WSCI"), *pSWSCI);
+ symbol::Context::getInstance()->put(symbol::Symbol(L"WSCI"), pSWSCI);
delete[] pstBackSlash;
#else
pwstWSCI = to_wide_string(_sci_path);
{
//add SCI value in context as variable
types::String *pS = new types::String(_sci_tmpdir);
- symbol::Context::getInstance()->put(symbol::Symbol(L"TMPDIR"), *pS);
+ symbol::Context::getInstance()->put(symbol::Symbol(L"TMPDIR"), pS);
//add SCI value ConfigVariable
std::wstring sci_tmpdir(_sci_tmpdir);
#include "time_gw.hxx"
#include "function.hxx"
#include "callable.hxx"
-#include "arrayof.hxx"
+#include "double.hxx"
#include "timer.hxx"
static Timer timer;
#include "sparse.hxx"
#include "graphichandle.hxx"
#include "void.hxx"
+#include "library.hxx"
#endif /* !ALL_TYPES_HXX */
#ifndef __LIBRARY_HXX__
#define __LIBRARY_HXX__
-#include "macrofile.hxx"
+#include <list>
+#include "typesdecl.hxx"
#include "dynlib_types.h"
namespace types
#define __MACRO_HXX__
#include <list>
+#include <string>
+#include "context.hxx"
#include "types.hxx"
#include "callable.hxx"
#include "double.hxx"
#include "seqexp.hxx"
-using namespace std;
namespace types
{
class Macro : public Callable
{
public :
- Macro() : Callable(), m_ArgInSymb(symbol::Symbol(L"nargin")), m_ArgOutSymb(symbol::Symbol(L"nargout")) {}
- Macro(const std::wstring& _stName, std::list<symbol::Symbol> &_inputArgs, std::list<symbol::Symbol> &_outputArgs, ast::SeqExp &_body, const wstring& _stModule);
+ Macro() : Callable(),
+ m_Nargin(symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"nargin"))),
+ m_Nargout(symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"nargout"))),
+ m_Varargin(symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"varargin"))),
+ m_Varargout(symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"varargout")))
+ {
+ }
+
+ Macro(const std::wstring& _stName, std::list<symbol::Variable*> &_inputArgs, std::list<symbol::Variable*> &_outputArgs, ast::SeqExp &_body, const std::wstring& _stModule);
virtual ~Macro();
// FIXME : Should not return NULL;
ast::SeqExp* getBody();
/* return type as string ( double, int, cell, list, ... )*/
- virtual wstring getTypeStr()
+ virtual std::wstring getTypeStr()
{
return L"function";
}
/* return type as short string ( s, i, ce, l, ... )*/
- virtual wstring getShortTypeStr()
+ virtual std::wstring getShortTypeStr()
{
return L"function";
}
- list<symbol::Symbol>* inputs_get();
- list<symbol::Symbol>* outputs_get();
+ std::list<symbol::Variable*>* inputs_get();
+ std::list<symbol::Variable*>* outputs_get();
virtual int getNbInputArgument(void);
virtual int getNbOutputArgument(void);
private :
- std::list<symbol::Symbol>* m_inputArgs;
- std::list<symbol::Symbol>* m_outputArgs;
- ast::SeqExp* m_body;
- bool bAutoAlloc;
- symbol::Symbol m_ArgInSymb;
- symbol::Symbol m_ArgOutSymb;
- Double* m_pDblArgIn;
- Double* m_pDblArgOut;
+ std::list<symbol::Variable*>* m_inputArgs;
+ std::list<symbol::Variable*>* m_outputArgs;
+ ast::SeqExp* m_body;
+ bool bAutoAlloc;
+ symbol::Variable* m_Nargin;
+ symbol::Variable* m_Nargout;
+ symbol::Variable* m_Varargin;
+ symbol::Variable* m_Varargout;
+ Double* m_pDblArgIn;
+ Double* m_pDblArgOut;
};
}
#ifndef __MACROFILE_HXX__
#define __MACROFILE_HXX__
+#include <string>
#include "callable.hxx"
#include "macro.hxx"
{
public :
MacroFile(): Callable() {};
- MacroFile(wstring _stName, wstring _stPath, wstring _stModule);
+ MacroFile(std::wstring _stName, std::wstring _stPath, std::wstring _stModule);
virtual ~MacroFile();
//FIXME : Should not return NULL
void setFirstLine(int _iLine);
/* return type as string ( double, int, cell, list, ... )*/
- virtual wstring getTypeStr()
+ virtual std::wstring getTypeStr()
{
return L"function";
}
/* return type as short string ( s, i, ce, l, ... )*/
- virtual wstring getShortTypeStr()
+ virtual std::wstring getShortTypeStr()
{
return L"function";
}
private :
Macro* m_pMacro;
- wstring m_stPath;
+ std::wstring m_stPath;
};
}
-#endif /* !__MACRO_HXX__ */
+#endif /* !__MACROFILE_HXX__ */
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+namespace types
+{
+class MacroFile;
+class Macro;
+}
+
#include "types_gw.hxx"
#include "function.hxx"
#include "string.hxx"
+#include "macrofile.hxx"
#include "inspector.hxx"
#include "context.hxx"
std::list<symbol::Symbol>::iterator it = FuncName->begin();
for (int i = 0; it != FuncName->end() ; ++it, i++)
{
- Callable* pCall = pC->get(*it)->getAs<Callable>();
+ types::Callable* pCall = pC->get(*it)->getAs<types::Callable>();
//Function name
pOut->set(i, 0, pCall->getName().c_str());
pOut->set(i, 1, pCall->getModule().c_str());
if (pCall->isMacroFile())
{
- pOut->set(i, 3, pCall->getAs<MacroFile>()->getMacro() == NULL ? L"false" : L"true");
+ pOut->set(i, 3, pCall->getAs<types::MacroFile>()->getMacro() == NULL ? L"false" : L"true");
}
else
{
*
*/
+#include <sstream>
+#include "macrofile.hxx"
#include "library.hxx"
+
extern "C"
{
#include <wchar.h>
#include "os_swprintf.h"
#include "formatmode.h"
+#include "localization.h"
}
namespace types
#include "list.hxx"
#include "context.hxx"
#include "symbol.hxx"
-#include "localization.h"
#include "scilabWrite.hxx"
#include "scilabexception.hxx"
#include "configvariable.hxx"
extern "C"
{
+#include "localization.h"
#include "Scierror.h"
#include "sciprint.h"
#include "MALLOC.h"
namespace types
{
-Macro::Macro(const std::wstring& _stName, std::list<symbol::Symbol> &_inputArgs, std::list<symbol::Symbol> &_outputArgs, ast::SeqExp &_body, const wstring& _stModule):
- Callable(), m_inputArgs(&_inputArgs), m_outputArgs(&_outputArgs), m_body(&_body),
- m_ArgInSymb(symbol::Symbol(L"nargin")), m_ArgOutSymb(symbol::Symbol(L"nargout"))
+Macro::Macro(const std::wstring& _stName, std::list<symbol::Variable*>& _inputArgs, std::list<symbol::Variable*>& _outputArgs, ast::SeqExp &_body, const std::wstring& _stModule):
+ Callable(),
+ m_inputArgs(&_inputArgs), m_outputArgs(&_outputArgs), m_body(&_body),
+ m_Nargin(symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"nargin"))),
+ m_Nargout(symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"nargout"))),
+ m_Varargin(symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"varargin"))),
+ m_Varargout(symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"varargout")))
{
setName(_stName);
setModule(_stModule);
m_pDblArgIn->IncreaseRef(); //never delete
m_pDblArgOut = new Double(1);
m_pDblArgOut->IncreaseRef(); //never delete
+
}
Macro::~Macro()
optional_list::const_iterator it;
for (it = opt.begin() ; it != opt.end() ; it++)
{
- pContext->put(symbol::Symbol(it->first), *it->second);
+ pContext->put(symbol::Symbol(it->first), it->second);
}
//check excepted and input/output parameters numbers
// Scilab Macro can be called with less than prototyped arguments,
// but not more execpts with varargin
// varargin management
- if (m_inputArgs->size() > 0 && m_inputArgs->back().name_get() == L"varargin")
+ if (m_inputArgs->size() > 0 && m_inputArgs->back()->name_get().name_get() == L"varargin")
{
int iVarPos = static_cast<int>(in.size());
if (iVarPos > static_cast<int>(m_inputArgs->size()) - 1)
}
//add all standard variable in function context but not varargin
- std::list<symbol::Symbol>::const_iterator itName = m_inputArgs->begin();
+ std::list<symbol::Variable*>::iterator itName = m_inputArgs->begin();
typed_list::const_iterator itValue = in.begin();
while (iVarPos > 0)
{
- pContext->put((*itName), **itValue);
+ pContext->put(*itName, *itValue);
iVarPos--;
- itName++;
- itValue++;
+ ++itName;
+ ++itValue;
}
//create varargin only if previous variable are assigned
pL->append(*itValue);
itValue++;
}
- pContext->put(symbol::Symbol(L"varargin"), *pL);
+ pContext->put(m_Varargin, pL);
}
}
else if (in.size() > m_inputArgs->size())
{
ostr << _W("Arguments are:") << std::endl << std::endl;
ostr << " ";
- for (std::list<symbol::Symbol>::iterator it = m_inputArgs->begin() ; it != m_inputArgs->end() ; ++it)
+ for (std::list<symbol::Variable*>::iterator it = m_inputArgs->begin() ; it != m_inputArgs->end() ; ++it)
{
- ostr << (*it).name_get() << L" ";
+ ostr << (*it)->name_get() << L" ";
}
ostr << std::endl;
}
else
{
//assign value to variable in the new context
- std::list<symbol::Symbol>::const_iterator i;
+ std::list<symbol::Variable*>::iterator i;
typed_list::const_iterator j;
for (i = m_inputArgs->begin(), j = in.begin(); j != in.end (); ++j, ++i)
if (*j)
{
//prevent assignation of NULL value
- pContext->put((*i), **j);
+ pContext->put(*i, *j);
}
}
}
// varargout is a list
// varargout can containt more items than caller need
// varargout must containt at leat caller needs
- if (m_outputArgs->size() == 1 && m_outputArgs->back().name_get() == L"varargout")
+ if (m_outputArgs->size() == 1 && m_outputArgs->back()->name_get().name_get() == L"varargout")
{
bVarargout = true;
List* pL = new List();
- pContext->put(symbol::Symbol(L"varargout"), *pL);
+ pContext->put(m_Varargout, pL);
}
//common part with or without varargin/varargout
// Declare nargin & nargout in function context.
m_pDblArgIn->set(0, static_cast<double>(in.size()));
m_pDblArgOut->set(0, _iRetCount);
- pContext->put(m_ArgInSymb, *m_pDblArgIn);
- pContext->put(m_ArgOutSymb, *m_pDblArgOut);
+ pContext->put(m_Nargin, m_pDblArgIn);
+ pContext->put(m_Nargout, m_pDblArgOut);
//save current prompt mode
int oldVal = ConfigVariable::getPromptMode();
//varargout management
if (bVarargout)
{
- InternalType* pOut = pContext->get(symbol::Symbol(L"varargout"));
+ InternalType* pOut = pContext->get(m_Varargout);
if (pOut == NULL)
{
Scierror(999, _("Invalid index.\n"));
else
{
//normal output management
- std::list<symbol::Symbol>::const_iterator i;
+ std::list<symbol::Variable*>::iterator i;
for (i = m_outputArgs->begin(); i != m_outputArgs->end() && _iRetCount; ++i, --_iRetCount)
{
InternalType *pIT = pContext->get((*i));
}
else
{
- char* pst = wide_string_to_UTF8((*i).name_get().c_str());
+ char* pst = wide_string_to_UTF8((*i)->name_get().name_get().c_str());
Scierror(999, _("Undefined variable %s.\n"), pst);
FREE(pst);
return Callable::Error;
return RetVal;
}
-std::list<symbol::Symbol>* Macro::inputs_get()
+std::list<symbol::Variable*>* Macro::inputs_get()
{
return m_inputArgs;
}
-std::list<symbol::Symbol>* Macro::outputs_get()
+std::list<symbol::Variable*>* Macro::outputs_get()
{
return m_outputArgs;
}
int Macro::getNbOutputArgument(void)
{
- if (m_outputArgs->size() == 1 && m_outputArgs->back().name_get() == L"varargout")
+ if (m_outputArgs->size() == 1 && m_outputArgs->back()->name_get().name_get() == L"varargout")
{
return -1;
}
#include "configvariable.hxx"
#include "deserializervisitor.hxx"
-using namespace ast;
namespace types
{
-MacroFile::MacroFile(wstring _stName, wstring _stPath, wstring _stModule) : Callable(), m_stPath(_stPath), m_pMacro(NULL)
+MacroFile::MacroFile(std::wstring _stName, std::wstring _stPath, std::wstring _stModule) :
+ Callable(), m_stPath(_stPath), m_pMacro(NULL)
{
setName(_stName);
setModule(_stModule);
ast::Exp* tree = d->deserialize();
//find FunctionDec
- FunctionDec* pFD = NULL;
+ ast::FunctionDec* pFD = NULL;
std::list<ast::Exp *>::iterator j;
std::list<ast::Exp *>LExp = ((ast::SeqExp*)tree)->exps_get();
for (j = LExp.begin() ; j != LExp.end() ; j++)
{
- pFD = dynamic_cast<FunctionDec*>(*j);
+ pFD = dynamic_cast<ast::FunctionDec*>(*j);
if (pFD) // && pFD->name_get() == m_stName
{
symbol::Context* pContext = symbol::Context::getInstance();
MacroFile* pMacro = pContext->getFunction(pFD->name_get())->getAs<MacroFile>();
if (pMacro->m_pMacro == NULL)
{
- std::list<Var *>::const_iterator i;
+ std::list<ast::Var *>::const_iterator i;
//get input parameters list
- std::list<symbol::Symbol> *pVarList = new std::list<symbol::Symbol>();
- ArrayListVar *pListVar = (ArrayListVar *)&pFD->args_get();
+ std::list<symbol::Variable*> *pVarList = new std::list<symbol::Variable*>();
+ ast::ArrayListVar *pListVar = (ast::ArrayListVar *)&pFD->args_get();
for (i = pListVar->vars_get().begin() ; i != pListVar->vars_get().end() ; i++)
{
- pVarList->push_back(((SimpleVar*)(*i))->name_get());
+ pVarList->push_back(((ast::SimpleVar*)(*i))->stack_get());
}
//get output parameters list
- std::list<symbol::Symbol> *pRetList = new std::list<symbol::Symbol>();
- ArrayListVar *pListRet = (ArrayListVar *)&pFD->returns_get();
+ std::list<symbol::Variable*> *pRetList = new std::list<symbol::Variable*>();
+ ast::ArrayListVar *pListRet = (ast::ArrayListVar *)&pFD->returns_get();
for (i = pListRet->vars_get().begin() ; i != pListRet->vars_get().end() ; i++)
{
- pRetList->push_back(((SimpleVar*)(*i))->name_get());
+ pRetList->push_back(((ast::SimpleVar*)(*i))->stack_get());
}
- //types::Macro macro(VarList, RetList, (SeqExp&)e.body_get());
- //types::Macro *pMacro = new types::Macro(m_stName, *pVarList, *pRetList, (SeqExp&)e.body_get());
-
- pMacro->m_pMacro = new Macro(m_wstName, *pVarList, *pRetList, (SeqExp&)pFD->body_get(), m_wstModule);
+ pMacro->m_pMacro = new Macro(m_wstName, *pVarList, *pRetList, (ast::SeqExp&)pFD->body_get(), m_wstModule);
pMacro->setFirstLine(pFD->location_get().first_line);
}
}
<ClInclude Include="includes\tlist.hxx" />
<ClInclude Include="includes\tostring_common.hxx" />
<ClInclude Include="includes\types.hxx" />
+ <ClInclude Include="includes\typesdecl.hxx" />
<ClInclude Include="includes\types_tools.hxx" />
<ClInclude Include="includes\uint16.hxx" />
<ClInclude Include="includes\uint32.hxx" />
<ClInclude Include="includes\library.hxx">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="includes\typesdecl.hxx">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Library Include="..\..\bin\blasplus.lib" />