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());
132 pOut = evaluateFields(pCell, fields, pITR);
133 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
140 std::wostringstream os;
141 os << _W("Fields evaluation failed.");
142 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
147 if (e.isVerbose() && ConfigVariable::isPromptShow())
149 std::wostringstream ostr;
152 ostr << SPACES_LIST << pVar->getSymbol().getName();
156 ostr << SPACES_LIST << L"???";
159 VariableToString(pOut, ostr.str().c_str());
165 std::wostringstream os;
166 os << _W("Invalid Index.\n");
167 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
173 CallExp *pCall = dynamic_cast<CallExp*>(&e.getLeftExp());
177 InternalType *pOut = NULL;
179 /*getting what to assign*/
180 InternalType* pITR = e.getRightVal();
183 e.getRightExp().accept(*this);
191 // if the right hand is NULL.
192 std::wostringstream os;
193 os << _W("Unable to extract right part expression.\n");
194 throw ast::ScilabError(os.str(), 999, e.getLeftExp().getLocation());
197 std::list<ExpHistory*> fields;
198 if (getFieldsFromExp(pCall, fields) == false)
200 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
204 std::wostringstream os;
205 os << _W("Get fields from expression failed.");
206 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
209 pOut = evaluateFields(pCall, fields, pITR);
210 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
217 std::wostringstream os;
218 os << _W("Fields evaluation failed.");
219 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
222 if (e.isVerbose() && ConfigVariable::isPromptShow())
224 std::wostringstream ostr;
225 ostr << *getStructNameFromExp(&pCall->getName()) << L" = " << std::endl;
227 scilabWriteW(ostr.str().c_str());
229 std::wostringstream ostrName;
230 ostrName << SPACES_LIST << *getStructNameFromExp(&pCall->getName());
231 VariableToString(pOut, ostrName.str().c_str());
240 if (e.getLeftExp().isAssignListExp())
242 AssignListExp *pList = e.getLeftExp().getAs<AssignListExp>();
244 int iLhsCount = (int)pList->getExps().size();
246 /*getting what to assign*/
248 exec.setExpectedSize(iLhsCount);
249 e.getRightExp().accept(exec);
251 if (exec.getResultSize() != iLhsCount)
253 std::wostringstream os;
254 os << _W("Incompatible assignation: trying to assign ") << exec.getResultSize();
255 os << _W(" values in ") << iLhsCount << _W(" variables.") << std::endl;
256 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
259 exps_t::const_reverse_iterator it;
260 int i = (int)iLhsCount - 1;
261 exps_t exps = pList->getExps();
262 for (it = exps.rbegin() ; it != exps.rend() ; it++, i--)
264 //create a new AssignExp and run it
265 types::InternalType* pIT = exec.getResult(i);
266 AssignExp pAssign((*it)->getLocation(), *(*it), *const_cast<Exp*>(&e.getRightExp()), pIT);
267 pAssign.setLrOwner(false);
268 pAssign.setVerbose(e.isVerbose());
269 pAssign.accept(*this);
270 //clear result to take care of [n,n]
271 exec.setResult(i, NULL);
277 FieldExp *pField = dynamic_cast<FieldExp*>(&e.getLeftExp());
281 //a.b can be a struct or a tlist/mlist or a handle
282 /*getting what to assign*/
284 e.getRightExp().accept(*this);
285 InternalType *pIT = getResult();
287 if (pIT->isImplicitList())
289 if (pIT->getAs<ImplicitList>()->isComputable())
291 InternalType *pTemp = pIT->getAs<ImplicitList>()->extractFullMatrix();
298 std::list<ExpHistory*> fields;
299 if (getFieldsFromExp(pField, fields) == false)
301 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
305 std::wostringstream os;
306 os << _W("Get fields from expression failed.");
307 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
310 if (evaluateFields(pField, fields, pIT) == NULL)
312 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
316 std::wostringstream os;
317 os << _W("Fields evaluation failed.");
318 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
321 for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
326 if (e.isVerbose() && ConfigVariable::isPromptShow())
328 const wstring *pstName = getStructNameFromExp(pField);
330 types::InternalType* pPrint = symbol::Context::getInstance()->get(symbol::Symbol(*pstName));
331 std::wostringstream ostr;
332 ostr << *pstName << L" = " << std::endl << std::endl;
333 scilabWriteW(ostr.str().c_str());
335 std::wostringstream ostrName;
336 ostrName << SPACES_LIST << *pstName;
337 VariableToString(pPrint, ostrName.str().c_str());
344 std::wostringstream os;
345 os << _W("unknow script form");
346 //os << ((Location)e.getRightExp().getLocation()).getLocationString() << std::endl;
347 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
349 catch (ast::ScilabError error)