This file is indexed.

/usr/include/scilab/runvisitor.hxx 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
/*
 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 *  Copyright (C) 2010-2010 - 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.
 *
 */

#ifndef AST_RUNVISITOR_HXX
#define AST_RUNVISITOR_HXX

#include "context.hxx"
#include "all.hxx"
#include "types.hxx"
#include "double.hxx"
#include "bool.hxx"
#include "polynom.hxx"
#include "colon.hxx"
#include "string.hxx"
#include "void.hxx"
#include "configvariable.hxx"
#include "overload.hxx"
#include "scilabWrite.hxx"
#include "variables.hxx"

extern "C" {
#include "more.h"
#include "sci_malloc.h"
}

namespace ast
{
class EXTERN_AST RunVisitor : public ConstVisitor
{
public:
    RunVisitor()
    {
        _expected_result = -1;
        _resultVect.push_back(nullptr);
        _result = nullptr;
        m_bSingleResult = true;
        m_pAns = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(L"ans"));
    }

    ~RunVisitor()
    {
        clearResult();
    }

    void clearResultButFirst()
    {
        if (!isSingleResult() && _resultVect.size() > 1)
        {
            for (std::vector<types::InternalType*>::iterator rv = _resultVect.begin() + 1, end = _resultVect.end(); rv != end; ++rv)
            {
                if (*rv != nullptr)
                {
                    (*rv)->killMe();
                    *rv = nullptr;
                }
            }
        }
    }

    void clearResult()
    {
        if (isSingleResult())
        {
            if (_result != nullptr)
            {
                //                    std::cout << "before single delete : " << _result << std::endl;
                _result->killMe();
                //                    std::cout << "after single delete" << std::endl;
            }
        }
        else
        {
            for (std::vector<types::InternalType*>::iterator rv = _resultVect.begin(); rv != _resultVect.end(); rv++)
            {
                if (*rv != nullptr)
                {
                    (*rv)->killMe();
                }
            }
        }
        _resultVect.clear();
        m_bSingleResult = true;
        _result = nullptr;
    }

public:
    void getInputs(const CallExp& e, exps_t& args, types::typed_list& inTmp, std::vector<std::wstring>& vectOptName, std::vector<int>& vectNbResult);

    int getExpectedSize(void)
    {
        return _expected_result;
    }

    void setExpectedSize(int _iSize)
    {
        _expected_result = _iSize;
    }

    int getResultSize(void)
    {
        if (isSingleResult())
        {
            if (_result == nullptr)
            {
                return 0;
            }
            else
            {
                return 1;
            }
        }
        else
        {
            return static_cast<int>(_resultVect.size());
        }
    }

    inline types::InternalType* getResult(void)
    {
        if (isSingleResult())
        {
            return _result;
        }
        else
        {
            return _resultVect[0];
        }
    }

    types::InternalType* getResult(int _iPos)
    {
        if (isSingleResult() && _iPos == 0)
        {
            return _result;
        }

        if (_iPos >= static_cast<int>(_resultVect.size()))
        {
            return nullptr;
        }
        return _resultVect[_iPos];
    }

    std::vector<types::InternalType*>* getResultList()
    {
        // TODO: this function is not used but it could lead to a memleak
        // (in the first case the vector is allocated and so must be freed)
        if (getResultSize() == 1)
        {
            std::vector<types::InternalType*>* pList = new std::vector<types::InternalType*>;
            pList->push_back(_result);
            return pList;
        }
        else
        {
            return &_resultVect;
        }
    }

    void setResult(int _iPos, const types::InternalType *gtVal)
    {
        m_bSingleResult = false;
        if (_iPos >= static_cast<int>(_resultVect.size()))
        {
            _resultVect.resize(_iPos + 1, nullptr);
        }

        _resultVect[_iPos] = const_cast<types::InternalType *>(gtVal);
    }

    inline void setResult(const types::InternalType *gtVal)
    {
        m_bSingleResult = true;
        _result = const_cast<types::InternalType *>(gtVal);
    }

    inline void setResult(const types::typed_list & out)
    {
        if (out.size() == 0)
        {
            setResult(nullptr);
        }
        else if (out.size() == 1)
        {
            setResult(out[0]);
        }
        else
        {
            m_bSingleResult = false;
            _resultVect.clear();
            for (types::typed_list::const_iterator it = out.begin(); it != out.end(); ++it)
            {
                _resultVect.push_back(*it);
            }
        }
    }

    inline bool isSingleResult()
    {
        return m_bSingleResult;
    }

    void cleanIn(const types::typed_list & in, const types::typed_list & out)
    {
        // Check if in contains entries which are in out too.
        // When an entry is in in and not in out, then in is killed.
        if (!in.empty())
        {
            for (types::typed_list::const_iterator o = out.begin(); o != out.end(); ++o)
            {
                if (*o)
                {
                    (*o)->IncreaseRef();
                }
            }

            for (types::typed_list::const_iterator i = in.begin(); i != in.end(); ++i)
            {
                if (*i)
                {
                    (*i)->DecreaseRef();
                    (*i)->killMe();
                }
            }

            for (types::typed_list::const_iterator o = out.begin(); o != out.end(); ++o)
            {
                if (*o)
                {
                    (*o)->DecreaseRef();
                }
            }
        }
    }

    inline void cleanInOut(const types::typed_list & in, const types::typed_list & out)
    {
        cleanIn(in, out);
        cleanOut(out);
    }

    void cleanOut(const types::typed_list & out)
    {
        if (!out.empty())
        {
            for (types::typed_list::const_iterator o = out.begin(); o != out.end(); ++o)
            {
                if (*o)
                {
                    (*o)->killMe();
                }
            }
        }
    }

    void cleanOpt(const types::optional_list & opt, const types::typed_list & out)
    {
        if (!opt.empty())
        {
            for (types::typed_list::const_iterator o = out.begin(); o != out.end(); ++o)
            {
                if (*o)
                {
                    (*o)->IncreaseRef();
                }
            }

            for (types::optional_list::const_iterator o = opt.begin(); o != opt.end(); ++o)
            {
                if (o->second)
                {
                    //decreasef ref after increaseref in callexp
                    o->second->DecreaseRef();
                    o->second->killMe();
                }
            }

            for (types::typed_list::const_iterator o = out.begin(); o != out.end(); ++o)
            {
                if (*o)
                {
                    (*o)->DecreaseRef();
                }
            }
        }
    }

    /*-------------.
    | Attributes.  |
    `-------------*/
protected:
    std::vector<types::InternalType*>    _resultVect;
    types::InternalType*    _result;
    bool m_bSingleResult;
    int _expected_result;
    symbol::Variable* m_pAns;
};

template <class T>
class EXTERN_AST RunVisitorT : public RunVisitor
{
public :
    RunVisitorT() : RunVisitor()
    {
    }

    types::typed_list* GetArgumentList(exps_t const & _plstArg)
    {
        types::typed_list* pArgs = new types::typed_list();
        for (exps_t::const_iterator it = _plstArg.begin() ; it != _plstArg.end() ; ++it)
        {
            (*it)->accept(*this);
            if (getResultSize() > 1)
            {
                const int size = getResultSize();
                for (int i = 0 ; i < size; i++)
                {
                    pArgs->push_back(getResult(i));
                }
            }
            else
            {
                if (getResult())
                {
                    pArgs->push_back(getResult());
                }
                //else optional argument skipped
            }
        }
        //to be sure, delete operation does not delete result
        setResult(nullptr);
        return pArgs;
    }

public :
    //process in another node
    void visitprivate(const MatrixLineExp &/*e*/) {}
    void visitprivate(const CommentExp &/*e*/) {}
    void visitprivate(const ArrayListVar &/*e*/) {}
    void visitprivate(const CaseExp &/*e*/) {}
    void visitprivate(const AssignListExp  &/*e*/) {}

    void visitprivate(const CellExp &e);
    void visitprivate(const FieldExp &e);
    void visitprivate(const IfExp &e);
    void visitprivate(const WhileExp &e);
    void visitprivate(const ForExp  &e);
    void visitprivate(const ReturnExp &e);
    void visitprivate(const SelectExp &e);
    void visitprivate(const SeqExp  &e);
    void visitprivate(const NotExp &e);
    void visitprivate(const TransposeExp &e);
    void visitprivate(const FunctionDec &e);
    void visitprivate(const ListExp &e);
    void visitprivate(const AssignExp &e);
    void visitprivate(const OpExp &e);
    void visitprivate(const LogicalOpExp &e);
    void visitprivate(const MatrixExp &e);
    void visitprivate(const CallExp &e);
    void visitprivate(const CellCallExp &e);
    void visitprivate(const OptimizedExp &e);
    void visitprivate(const MemfillExp &e);
    void visitprivate(const DAXPYExp &e);
    void visitprivate(const IntSelectExp &e);
    void visitprivate(const StringSelectExp &e);
    void visitprivate(const TryCatchExp &e);

    void visitprivate(const StringExp & e);
    void visitprivate(const DoubleExp & e);
    void visitprivate(const BoolExp & e);
    void visitprivate(const NilExp & e);
    void visitprivate(const SimpleVar & e);
    void visitprivate(const ColonVar & e);
    void visitprivate(const DollarVar & e);
    void visitprivate(const BreakExp & e);
    void visitprivate(const ContinueExp & e);
    void visitprivate(const ArrayListExp & e);
    void visitprivate(const VarDec & e);

    types::InternalType* callOverloadOpExp(OpExp::Oper _oper, types::InternalType* _paramL, types::InternalType* _paramR);
    types::InternalType* callOverloadMatrixExp(const std::wstring& strType, types::InternalType* _paramL, types::InternalType* _paramR);
};
}

#endif // !AST_RUNVISITOR_HXX