This file is indexed.

/usr/include/scilab/run_AssignExp.hpp is in scilab-include 6.0.1-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
/*
*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
*  Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
*
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
*
*/

//file included in runvisitor.cpp
namespace ast {

template<class T>
void RunVisitorT<T>::visitprivate(const AssignExp  &e)
{
    CoverageInstance::invokeAndStartChrono((void*)&e);
    symbol::Context* ctx = symbol::Context::getInstance();
    /*Create local exec visitor*/
    try
    {
        SimpleVar * pVar = NULL;
        if (e.getLeftExp().isSimpleVar())
        {
            pVar = static_cast<SimpleVar*>(&e.getLeftExp());
        }

        /*get king of left hand*/
        if (pVar)
        {
            // x = ?
            /*getting what to assign*/
            types::InternalType *pIT = e.getRightVal();
            if (pIT == NULL)
            {
                setExpectedSize(1);
                e.getRightExp().accept(*this);

                if (getResultSize() != 1)
                {
                    // avoid double deletion when rhs is deleted from exp and cleanResult
                    setResult(NULL);

                    std::wostringstream os;
                    os << _W("Can not assign multiple value in a single variable") << std::endl;
                    //os << ((Location)e.getRightExp().getLocation()).getLocationString() << std::endl;
                    throw ast::InternalError(os.str(), 999, e.getRightExp().getLocation());
                }

                pIT = getResult();
                //reset result
                setResult(NULL);
            }

            if (pIT->isImplicitList())
            {
                if (pIT->getAs<types::ImplicitList>()->isComputable())
                {
                    types::InternalType *pTemp = pIT->getAs<types::ImplicitList>()->extractFullMatrix();
                    pIT->killMe();
                    pIT = pTemp;
                }
            }

            if (pIT->isAssignable() == false)
            {
                if (pIT->isListDelete())
                {
                    //used to delete a variable in current scope
                    symbol::Symbol sym = pVar->getSymbol();
                    if (ctx->isprotected(sym) == false)
                    {
                        ctx->remove(sym);
                    }
                    else
                    {
                        std::wostringstream os;
                        os << _W("Redefining permanent variable.\n");
                        throw ast::InternalError(os.str(), 999, e.getLeftExp().getLocation());
                    }
                }

                setResult(NULL);
                CoverageInstance::stopChrono((void*)&e);
                return;
            }

            if (pIT->isList() && pIT->getRef() > 0)
            {
                // Prevent modification of all scilab variable
                // which point to this container when it is used
                // in setfield scilab function.
                // A clone on a container will not clone what it contain.
                pIT = pIT->clone();
            }

            if (e.getRightExp().isReturnExp())
            {
                //ReturnExp so, put the value in the previous scope
                if (ctx->putInPreviousScope(pVar->getStack(), pIT) == false)
                {
                    char pstError[1024];
                    char* pstFuncName = wide_string_to_UTF8(pVar->getSymbol().getName().data());
                    os_sprintf(pstError, _("It is not possible to redefine the %s primitive this way (see clearfun).\n"), pstFuncName);
                    wchar_t* pwstError = to_wide_string(pstError);
                    std::wstring wstError(pwstError);
                    FREE(pstFuncName);
                    FREE(pwstError);
                    pIT->killMe();
                    CoverageInstance::stopChrono((void*)&e);
                    throw InternalError(wstError, 999, e.getLocation());
                }

                ((AssignExp*)&e)->setReturn();
            }
            else
            {
                if (ctx->isprotected(pVar->getStack()) == false)
                {
                    ctx->put(pVar->getStack(), pIT);
                }
                else
                {
                    std::wostringstream os;
                    os << _W("Redefining permanent variable.\n");
                    throw ast::InternalError(os.str(), 999, e.getLeftExp().getLocation());
                }
            }

            if (e.isVerbose() && ConfigVariable::isPrintOutput())
            {
                std::wstring wstrName = pVar->getSymbol().getName();
                std::wostringstream ostr;
                ostr << L" " << wstrName << L"  = " << std::endl << std::endl;
                scilabWriteW(ostr.str().c_str());
                std::wostringstream ostrName;
                ostrName << wstrName;
                VariableToString(pIT, ostrName.str().c_str());
            }
            CoverageInstance::stopChrono((void*)&e);
            return;
        }

        if (e.getLeftExp().isCellCallExp())
        {
            CellCallExp *pCell = static_cast<CellCallExp*>(&e.getLeftExp());
            types::InternalType *pOut = NULL;

            /*getting what to assign*/
            types::InternalType* pITR = e.getRightVal();
            if (pITR == NULL)
            {
                e.getRightExp().accept(*this);
                pITR = getResult();
                //reset result
                setResult(NULL);
            }

            if (pITR == NULL)
            {
                // if the right hand is NULL.
                std::wostringstream os;
                os << _W("Unable to extract right part expression.\n");
                throw ast::InternalError(os.str(), 999, e.getLeftExp().getLocation());
            }

            std::list<ExpHistory*> fields;
            if (getFieldsFromExp(pCell, fields) == false)
            {
                for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
                {
                    delete *i;
                }
                std::wostringstream os;
                os << _W("Get fields from expression failed.");
                throw ast::InternalError(os.str(), 999, e.getRightExp().getLocation());
            }

            try
            {
                pOut = evaluateFields(pCell, fields, pITR);
            }
            catch (const InternalError& error)
            {
                // catch error when call overload
                for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
                {
                    (*i)->setDeleteCurrent(true);
                    delete *i;
                }

                pITR->killMe();
                throw error;
            }

            for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
            {
                delete *i;
            }

            pITR->killMe();

            if (pOut == NULL)
            {
                std::wostringstream os;
                os << _W("Fields evaluation failed.");
                throw ast::InternalError(os.str(), 999, e.getRightExp().getLocation());
            }

            if (pOut != NULL)
            {
                if (e.isVerbose() && ConfigVariable::isPrintOutput())
                {
                    std::wostringstream ostr;
                    ostr << L" " << *getStructNameFromExp(pCell) << L"  = " << std::endl;
                    ostr << std::endl;
                    scilabWriteW(ostr.str().c_str());

                    VariableToString(pOut, ostr.str().c_str());
                }
            }
            else
            {
                //manage error
                std::wostringstream os;
                os << _W("Invalid index.\n");
                throw ast::InternalError(os.str(), 999, e.getRightExp().getLocation());
            }

            CoverageInstance::stopChrono((void*)&e);
            return;
        }

        if (e.getLeftExp().isCallExp())
        {
            CallExp *pCall = static_cast<CallExp*>(&e.getLeftExp());
            //x(?) = ?
            types::InternalType *pOut = NULL;

            if (e.getRightExp().isReturnExp())
            {
                // We can't put in the previous scope a variable create like that : a(2)=resume(1)
                std::wostringstream os;
                os << _W("Indexing not allowed for output arguments of resume.\n");
                throw ast::InternalError(os.str(), 79, e.getLeftExp().getLocation());
            }

            /*getting what to assign*/
            types::InternalType* pITR = e.getRightVal();
            if (pITR == NULL)
            {
                e.getRightExp().accept(*this);
                pITR = getResult();
                //reset result
                setResult(NULL);
            }

            if (pITR == NULL)
            {
                // if the right hand is NULL.
                std::wostringstream os;
                os << _W("Unable to extract right part expression.\n");
                throw ast::InternalError(os.str(), 999, e.getLeftExp().getLocation());
            }

            bool alreadyProcessed = false;
            //a(...) without fields or whatever on arrayof derived types
            if (pCall->getName().isSimpleVar())
            {
                ast::SimpleVar* var = pCall->getName().getAs<ast::SimpleVar>();
                types::InternalType* pIT = ctx->getCurrentLevel(var->getStack());
                if (pIT && pIT->isArrayOf())
                {
                    if (ctx->isprotected(var->getStack()))
                    {
                        std::wostringstream os;
                        os << _W("Redefining permanent variable.\n");
                        throw ast::InternalError(os.str(), 999, pCall->getLocation());
                    }

                    // prevent delete after extractFullMatrix
                    // called in insertionCall when pITR is an ImplicitList
                    pITR->IncreaseRef();

                    types::typed_list* currentArgs = GetArgumentList(pCall->getArgs());

                    try
                    {
                        pOut = insertionCall(e, currentArgs, pIT, pITR);
                    }
                    catch (const InternalError& error)
                    {
                        pITR->DecreaseRef();
                        // call killMe on all arguments
                        cleanOut(*currentArgs);
                        delete currentArgs;
                        // insertion have done, call killMe on pITR
                        pITR->killMe();
                        throw error;
                    }

                    pITR->DecreaseRef();

                    // call killMe on all arguments
                    cleanOut(*currentArgs);
                    delete currentArgs;

                    // insertion have done, call killMe on pITR
                    pITR->killMe();

                    if (pOut == NULL)
                    {
                        std::wostringstream os;
                        os << _W("Submatrix incorrectly defined.\n");
                        throw ast::InternalError(os.str(), 999, e.getLocation());
                    }


                    //update variable with new value
                    if (pOut != pIT)
                    {
                        ctx->put(var->getStack(), pOut);
                    }

                    alreadyProcessed = true;
                }
            }

            if (alreadyProcessed == false)
            {
                std::list<ExpHistory*> fields;
                if (getFieldsFromExp(pCall, fields) == false)
                {
                    for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
                    {
                        delete *i;
                    }

                    std::wostringstream os;
                    os << _W("Instruction left hand side: waiting for a name.");
                    throw ast::InternalError(os.str(), 999, e.getRightExp().getLocation());
                }

                // prevent delete after extractFullMatrix
                // called in evaluateFields when pITR is an ImplicitList
                pITR->IncreaseRef();

                try
                {
                    pOut = evaluateFields(pCall, fields, pITR);
                }
                catch (const InternalError& error)
                {
                    // catch error when call overload
                    for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
                    {
                        delete *i;
                    }

                    pITR->DecreaseRef();
                    pITR->killMe();

                    throw error;
                }

                for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
                {
                    delete *i;
                }

                pITR->DecreaseRef();
                pITR->killMe();

                if (pOut == NULL)
                {
                    std::wostringstream os;
                    os << _W("Fields evaluation failed.");
                    throw ast::InternalError(os.str(), 999, e.getRightExp().getLocation());
                }
            }

            if (e.isVerbose() && ConfigVariable::isPrintOutput())
            {
                std::wostringstream ostr;
                ostr << L" " << *getStructNameFromExp(&pCall->getName()) << L"  = " << std::endl;
                ostr << std::endl;
                scilabWriteW(ostr.str().c_str());

                std::wostringstream ostrName;
                ostrName << *getStructNameFromExp(&pCall->getName());
                VariableToString(pOut, ostrName.str().c_str());
            }

            clearResult();
            CoverageInstance::stopChrono((void*)&e);

            return;
        }

        if (e.getLeftExp().isAssignListExp())
        {
            AssignListExp *pList = e.getLeftExp().getAs<AssignListExp>();
            //[x,y] = ?
            int iLhsCount = (int)pList->getExps().size();

            /*getting what to assign*/
            T exec;
            exec.setExpectedSize(iLhsCount);
            e.getRightExp().accept(exec);

            if (exec.getResultSize() < iLhsCount)
            {
                std::wostringstream os;
                os << _W("Incompatible assignation: trying to assign ") << exec.getResultSize();
                os << _W(" values in ") << iLhsCount << _W(" variables.") << std::endl;
                throw ast::InternalError(os.str(), 999, e.getRightExp().getLocation());
            }

            exps_t::const_reverse_iterator it;
            exps_t exps = pList->getExps();
            types::InternalType** pIT = new types::InternalType*[iLhsCount];
            int i = 0;
            for (i = iLhsCount - 1; i >= 0; i--)
            {
                //create a new AssignExp and run it
                pIT[i] = exec.getResult(i);
                //protet rhs against removal [a,b] = (b,a);
                pIT[i]->IncreaseRef();
            }

            for (i = iLhsCount - 1, it = exps.rbegin(); it != exps.rend(); it++, i--)
            {
                Exp* pExp = e.getRightExp().clone();
                AssignExp pAssign((*it)->getLocation(), *(*it), *pExp, pIT[i]);
                pAssign.setLrOwner(false);
                pAssign.setVerbose(e.isVerbose());
                pAssign.accept(*this);
                //clear result to take care of [n,n]
                exec.setResult(i, NULL);
                delete pExp;
            }

            for (i = iLhsCount - 1; i >= 0; i--)
            {
                //unprotect rhs
                pIT[i]->DecreaseRef();
                pIT[i]->killMe();
            }

            delete[] pIT;
            exec.clearResult();
            CoverageInstance::stopChrono((void*)&e);
            return;
        }

        if (e.getLeftExp().isFieldExp())
        {
            FieldExp *pField = static_cast<FieldExp*>(&e.getLeftExp());
            types::InternalType *pIT = e.getRightVal();
            if (pIT == NULL)
            {
                //a.b = x
                //a.b can be a struct or a tlist/mlist or a handle
                /*getting what to assign*/
                setExpectedSize(1);
                e.getRightExp().accept(*this);
                pIT = getResult();
                setResult(NULL);
            }

            if (pIT->isImplicitList())
            {
                if (pIT->getAs<types::ImplicitList>()->isComputable())
                {
                    types::InternalType *pTemp = pIT->getAs<types::ImplicitList>()->extractFullMatrix();
                    delete pIT;
                    setResult(NULL);
                    pIT = pTemp;
                }
            }

            std::list<ExpHistory*> fields;
            if (getFieldsFromExp(pField, fields) == false)
            {
                for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
                {
                    delete *i;
                }
                std::wostringstream os;
                os << _W("Get fields from expression failed.");
                throw ast::InternalError(os.str(), 999, e.getRightExp().getLocation());
            }

            try
            {
                if (evaluateFields(pField, fields, pIT) == NULL)
                {
                    for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
                    {
                        delete *i;
                    }
                    std::wostringstream os;
                    os << _W("Fields evaluation failed.");
                    throw ast::InternalError(os.str(), 999, e.getRightExp().getLocation());
                }
            }
            catch (const InternalError& error)
            {
                for (auto i : fields)
                {
                    delete i;
                }

                throw error;
            }

            for (auto i : fields)
            {
                delete i;
            }

            if (e.isVerbose() && ConfigVariable::isPrintOutput())
            {
                const std::wstring *pstName = getStructNameFromExp(pField);

                types::InternalType* pPrint = ctx->get(symbol::Symbol(*pstName));
                std::wostringstream ostr;
                ostr << L" " << *pstName << L"  = " << std::endl << std::endl;
                scilabWriteW(ostr.str().c_str());

                std::wostringstream ostrName;
                ostrName << *pstName;
                VariableToString(pPrint, ostrName.str().c_str());
            }

            clearResult();
            CoverageInstance::stopChrono((void*)&e);
            return;
        }

        std::wostringstream os;
        os << _W("unknown script form");
        //os << ((Location)e.getRightExp().getLocation()).getLocationString() << std::endl;
        throw ast::InternalError(os.str(), 999, e.getRightExp().getLocation());
    }
    catch (const InternalError& error)
    {
        CoverageInstance::stopChrono((void*)&e);
        throw error;
    }
}

} /* namespace ast */