2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 //file included in runvisitor.cpp
16 void RunVisitorT<T>::visitprivate(const AssignExp &e)
18 /*Create local exec visitor*/
21 SimpleVar * pVar = NULL;
22 if (e.getLeftExp().isSimpleVar())
24 pVar = static_cast<SimpleVar*>(&e.getLeftExp());
27 /*get king of left hand*/
31 /*getting what to assign*/
32 InternalType *pIT = e.getRightVal();
36 e.getRightExp().accept(*this);
38 if (getResultSize() != 1)
40 std::wostringstream os;
41 os << _W("Can not assign multiple value in a single variable") << std::endl;
42 //os << ((Location)e.getRightExp().getLocation()).getLocationString() << std::endl;
43 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
51 if (pIT->isImplicitList())
53 if (pIT->getAs<ImplicitList>()->isComputable())
55 InternalType *pTemp = pIT->getAs<ImplicitList>()->extractFullMatrix();
61 if (pIT->isAssignable() == false)
63 if (pIT->isListDelete())
65 //used to delete a variable in current scope
66 symbol::Context::getInstance()->remove(pVar->getSymbol());
73 if (e.getRightExp().isReturnExp())
75 //ReturnExp so, put the value in the previous scope
76 symbol::Context::getInstance()->putInPreviousScope(pVar->getStack(), pIT);
77 ((AssignExp*)&e)->setReturn();
81 symbol::Context::getInstance()->put(pVar->getStack(), pIT);
84 if (e.isVerbose() && ConfigVariable::isPromptShow())
86 std::wstring wstrName = pVar->getSymbol().getName();
87 std::wostringstream ostr;
88 ostr << wstrName << L" = " << std::endl << std::endl;
89 scilabWriteW(ostr.str().c_str());
90 std::wostringstream ostrName;
91 ostrName << SPACES_LIST << wstrName;
92 VariableToString(pIT, ostrName.str().c_str());
97 CellCallExp *pCell = dynamic_cast<CellCallExp*>(&e.getLeftExp());
100 InternalType *pOut = NULL;
102 /*getting what to assign*/
103 InternalType* pITR = e.getRightVal();
106 e.getRightExp().accept(*this);
114 // if the right hand is NULL.
115 std::wostringstream os;
116 os << _W("Unable to extract right part expression.\n");
117 throw ast::ScilabError(os.str(), 999, e.getLeftExp().getLocation());
120 std::list<ExpHistory*> fields;
121 if (getFieldsFromExp(pCell, fields) == false)
123 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
127 std::wostringstream os;
128 os << _W("Get fields from expression failed.");
129 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
134 pOut = evaluateFields(pCell, fields, pITR);
136 catch (ast::ScilabError error)
138 // catch error when call overload
139 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
141 (*i)->setDeleteCurrent(true);
149 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
158 std::wostringstream os;
159 os << _W("Fields evaluation failed.");
160 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
165 if (e.isVerbose() && ConfigVariable::isPromptShow())
167 std::wostringstream ostr;
170 const wstring *pstName = getStructNameFromExp(pCell);
171 ostr << SPACES_LIST << pstName;
175 ostr << SPACES_LIST << L"???";
178 VariableToString(pOut, ostr.str().c_str());
184 std::wostringstream os;
185 os << _W("Invalid Index.\n");
186 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
192 CallExp *pCall = dynamic_cast<CallExp*>(&e.getLeftExp());
196 InternalType *pOut = NULL;
198 /*getting what to assign*/
199 InternalType* pITR = e.getRightVal();
202 e.getRightExp().accept(*this);
210 // if the right hand is NULL.
211 std::wostringstream os;
212 os << _W("Unable to extract right part expression.\n");
213 throw ast::ScilabError(os.str(), 999, e.getLeftExp().getLocation());
216 std::list<ExpHistory*> fields;
217 if (getFieldsFromExp(pCall, fields) == false)
219 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
223 std::wostringstream os;
224 os << _W("Get fields from expression failed.");
225 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
228 // prevent delete after extractFullMatrix
229 // called in evaluateFields when pITR is an ImplicitList
234 pOut = evaluateFields(pCall, fields, pITR);
236 catch (ast::ScilabError error)
238 // catch error when call overload
239 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
250 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
260 std::wostringstream os;
261 os << _W("Fields evaluation failed.");
262 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
265 if (e.isVerbose() && ConfigVariable::isPromptShow())
267 std::wostringstream ostr;
268 ostr << *getStructNameFromExp(&pCall->getName()) << L" = " << std::endl;
270 scilabWriteW(ostr.str().c_str());
272 std::wostringstream ostrName;
273 ostrName << SPACES_LIST << *getStructNameFromExp(&pCall->getName());
274 VariableToString(pOut, ostrName.str().c_str());
281 if (e.getLeftExp().isAssignListExp())
283 AssignListExp *pList = e.getLeftExp().getAs<AssignListExp>();
285 int iLhsCount = (int)pList->getExps().size();
287 /*getting what to assign*/
289 exec.setExpectedSize(iLhsCount);
290 e.getRightExp().accept(exec);
292 if (exec.getResultSize() != iLhsCount)
294 std::wostringstream os;
295 os << _W("Incompatible assignation: trying to assign ") << exec.getResultSize();
296 os << _W(" values in ") << iLhsCount << _W(" variables.") << std::endl;
297 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
300 exps_t::const_reverse_iterator it;
301 int i = (int)iLhsCount - 1;
302 exps_t exps = pList->getExps();
303 for (it = exps.rbegin() ; it != exps.rend() ; it++, i--)
305 //create a new AssignExp and run it
306 types::InternalType* pIT = exec.getResult(i);
307 AssignExp pAssign((*it)->getLocation(), *(*it), *const_cast<Exp*>(&e.getRightExp()), pIT);
308 pAssign.setLrOwner(false);
309 pAssign.setVerbose(e.isVerbose());
310 pAssign.accept(*this);
311 //clear result to take care of [n,n]
312 exec.setResult(i, NULL);
318 FieldExp *pField = dynamic_cast<FieldExp*>(&e.getLeftExp());
322 //a.b can be a struct or a tlist/mlist or a handle
323 /*getting what to assign*/
325 e.getRightExp().accept(*this);
326 InternalType *pIT = getResult();
328 if (pIT->isImplicitList())
330 if (pIT->getAs<ImplicitList>()->isComputable())
332 InternalType *pTemp = pIT->getAs<ImplicitList>()->extractFullMatrix();
339 std::list<ExpHistory*> fields;
340 if (getFieldsFromExp(pField, fields) == false)
342 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
346 std::wostringstream os;
347 os << _W("Get fields from expression failed.");
348 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
351 if (evaluateFields(pField, fields, pIT) == NULL)
353 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
357 std::wostringstream os;
358 os << _W("Fields evaluation failed.");
359 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
362 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
367 if (e.isVerbose() && ConfigVariable::isPromptShow())
369 const wstring *pstName = getStructNameFromExp(pField);
371 types::InternalType* pPrint = symbol::Context::getInstance()->get(symbol::Symbol(*pstName));
372 std::wostringstream ostr;
373 ostr << *pstName << L" = " << std::endl << std::endl;
374 scilabWriteW(ostr.str().c_str());
376 std::wostringstream ostrName;
377 ostrName << SPACES_LIST << *pstName;
378 VariableToString(pPrint, ostrName.str().c_str());
385 std::wostringstream os;
386 os << _W("unknow script form");
387 //os << ((Location)e.getRightExp().getLocation()).getLocationString() << std::endl;
388 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
390 catch (ast::ScilabError error)