This file is indexed.

/usr/include/yacas/lispenvironment.h is in yacas 1.3.6-2+b1.

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
/** \file lispenvironment.h
 *  General environment access.
 *
 */

#ifndef YACAS_LISPENVIRONMENT_H
#define YACAS_LISPENVIRONMENT_H

#include "yacasbase.h"
#include "lispobject.h"
#include "lisphash.h"
#include "lispevalhash.h"
#include "lispcleanupstack.h"
#include "lispuserfunc.h"
#include "deffile.h"
#include "lispio.h"
#include "stringio.h"
#include "lispglobals.h"
#include "xmltokenizer.h"
#include "errors.h"
#include "noncopyable.h"

#include <atomic>
#include <string>
#include <sstream>
#include <vector>

#include <unordered_set>

typedef std::unordered_set<LispStringSmartPtr, std::hash<const LispString*> > LispIdentifiers;


class LispDefFiles;

class LispInput;
class LispOutput;
class LispPrinter;
class LispOperators;
class LispUserFunction;
class LispMultiUserFunction;
class LispEvaluatorBase;
class BasicEvaluator;
class DefaultDebugger;
class LispEnvironment;


/// The Lisp environment.
/// This huge class is the central class of the Yacas program. It
/// implements a dialect of Lisp.

class LispEnvironment : public YacasBase, NonCopyable
{
public:
  /// \name Constructor and destructor
  //@{
  LispEnvironment(YacasCoreCommands &aCoreCommands,
                  LispUserFunctions& aUserFunctions,
                  LispGlobal& aGlobals,
                  LispHashTable& aHashTable,
                  std::ostream& aOutput,
                  LispPrinter& aPrinter,
                  LispOperators &aPreFixOperators,
                  LispOperators &aInFixOperators,
                  LispOperators &aPostFixOperators,
                  LispOperators &aBodiedOperators,
                  LispIdentifiers& protected_symbols,
                  LispInput*    aCurrentInput,
                  LispInt aStackSize);
  ~LispEnvironment();
  //@}

public:
  /// \name Lisp variables
  //@{

  /// Assign a value to a Lisp variable.
  /// \param aString name of the variable
  /// \param aValue value to be assigned to \a aString
  ///
  /// If there is a local variable with the name \a aString, the
  /// object \a aValue is assigned to it. Otherwise, a
  /// LispGlobalVariable is constructed, and it is associated with
  /// \a aValue in #iGlobals.
  /// \sa FindLocal
  void SetVariable(const LispString* aString, LispPtr& aValue, bool aGlobalLazyVariable);

  /// In debug mode, DebugModeVerifySettingGlobalVariables raises a warning if a global variable is set.
  void DebugModeVerifySettingGlobalVariables(LispPtr & aVariable, bool aGlobalLazyVariable);

  /// Get the value assigned to a variable.
  /// \param aVariable name of the variable
  /// \param aResult (on exit) value of \a aVariable
  ///
  /// - If there is a local variable with the name \a aString,
  ///   \a aResult is set to point to the value assigned to this local
  ///   variable.
  /// - If there is a global variable \a aString and its
  ///   #iEvalBeforeReturn is false, its value is returned via
  ///   \a aResult.
  /// - If there is a global variable \a aString and its
  ///   #iEvalBeforeReturn is true, its value is evaluated. The
  ///   result is assigned back to the variable, its
  ///   #iEvalBeforeReturn is set to false, and a copy of the result
  ///   is returned in \a aResult.
  /// - Otherwise, \a aResult is set to #nullptr.
  void GetVariable(const LispString* aVariable, LispPtr& aResult);

  void UnsetVariable(const LispString * aString);
  void PushLocalFrame(bool aFenced);
  void PopLocalFrame();
  void NewLocal(const LispString* aVariable, LispObject* aValue);
  void CurrentLocals(LispPtr& aResult);
  //@}

public:
  /// \name Lisp functions
  //@{

  /// Return the #iCoreCommands attribute.
  inline YacasCoreCommands& CoreCommands();

  /// Add a command to the list of core commands.
  /// \param aEvaluatorFunc C function evaluating the core command
  /// \param aString name of the command
  /// \param aNrArgs number of arguments
  /// \param aFlags flags, see YacasEvaluator::FunctionFlags
  void SetCommand(YacasEvalCaller aEvaluatorFunc, const LispChar * aString,LispInt aNrArgs,LispInt aFlags);

  void RemoveCommand(LispChar * aString);
  void RemoveCoreCommand(LispChar * aString);

  inline  LispHashTable& HashTable();
  LispUserFunction* UserFunction(LispPtr& aArguments);
  LispUserFunction* UserFunction(const LispString* aName,LispInt aArity);

  /// Return LispMultiUserFunction with given name.
  /// \param aArguments name of the multi user function
  ///
  /// The table of user functions, #iUserFunctions, is consulted. If
  /// a user function with the given name exists, it is returned.
  /// Otherwise, a new LispMultiUserFunction is constructed, added
  /// to #iUserFunctions, and returned.
  LispMultiUserFunction* MultiUserFunction(const LispString* aArguments);

  LispDefFiles& DefFiles();
  void DeclareRuleBase(const LispString* aOperator, LispPtr& aParameters,
                       LispInt aListed);
  void DeclareMacroRuleBase(const LispString* aOperator, LispPtr& aParameters,
                       LispInt aListed);
  void DefineRule(const LispString* aOperator,LispInt aArity,
                          LispInt aPrecedence, LispPtr& aPredicate,
                          LispPtr& aBody);
  void DefineRulePattern(const LispString* aOperator,LispInt aArity,
                         LispInt aPrecedence, LispPtr& aPredicate,
                         LispPtr& aBody);


  void UnFenceRule(const LispString* aOperator,LispInt aArity);
  void Retract(const LispString* aOperator,LispInt aArity);
  void HoldArgument(const LispString* aOperator, const LispString* aVariable);

  void Protect(const LispString*);
  void UnProtect(const LispString*);
  bool Protected(const LispString*) const;
  //@}

  const LispString * FindCachedFile(const LispChar * aFileName);

public:
  /// \name Precision
  //@{

  /// set precision to a given number of decimal digits
  void SetPrecision(LispInt aPrecision);
  LispInt Precision(void) const;
  LispInt BinaryPrecision(void) const;
  //@}

public:
  void SetPrettyPrinter(const LispString* aPrettyPrinter);
  const LispString* PrettyPrinter();

  void SetPrettyReader(const LispString* aPrettyReader);
  const LispString* PrettyReader();

public:
  LispInt GetUniqueId();
public:
  LispPrinter& CurrentPrinter();

public:
  /// \name Operators
  //@{
  LispOperators& PreFix();
  LispOperators& InFix();
  LispOperators& PostFix();
  LispOperators& Bodied();
  //@}

public:
  /// \name Input and output
  //@{
  LispInput* CurrentInput();
  void SetCurrentInput(LispInput* aInput);
public:
  std::ostream& CurrentOutput();
  void SetCurrentOutput(std::ostream&);
  //@}

protected:
  /// current precision for user interaction, in decimal and in binary
  LispInt iPrecision;
  LispInt iBinaryPrecision;
public:
  std::vector<std::string> iInputDirectories;
  DeletingLispCleanup iCleanup;
  LispInt iEvalDepth;
  LispInt iMaxEvalDepth;
#ifdef YACAS_NO_ATOMIC_TYPES
  volatile bool
#else
  std::atomic_bool
#endif // YACAS_NO_ATOMIC_TYPES
    stop_evaluation;
  LispEvaluatorBase* iEvaluator;

public: // Error information when some error occurs.
  InputStatus iInputStatus;
  bool secure;
public: // pre-found
  RefPtr<LispObject> iTrue;
  RefPtr<LispObject> iFalse;

  RefPtr<LispObject> iEndOfFile;
  RefPtr<LispObject> iEndStatement;
  RefPtr<LispObject> iProgOpen;
  RefPtr<LispObject> iProgClose;
  RefPtr<LispObject> iNth;
  RefPtr<LispObject> iBracketOpen;
  RefPtr<LispObject> iBracketClose;
  RefPtr<LispObject> iListOpen;
  RefPtr<LispObject> iListClose;
  RefPtr<LispObject> iComma;
  RefPtr<LispObject> iList;
  RefPtr<LispObject> iProg;

  LispInt iLastUniqueId;

public: // Error reporting
  std::ostringstream iErrorOutput;
  DefaultDebugger* iDebugger;

private:
    LispPtr *FindLocal(const LispString * aVariable);

    struct LispLocalVariable {
        LispLocalVariable(const LispString* var, LispObject* val):
        var(var), val(val)
        {
            ++var->iReferenceCount;
        }

        LispLocalVariable(const LispLocalVariable& v):
        var(v.var), val(v.val)
        {
            ++var->iReferenceCount;
        }

        ~LispLocalVariable()
        {
            --var->iReferenceCount;
        }

        const LispString* var;
        LispPtr val;
    };

    struct LocalVariableFrame {
        LocalVariableFrame(std::size_t first, bool fenced):
        first(first), fenced(fenced)
        {
        }

        std::size_t first;
        bool fenced;
    };

    std::vector<LispLocalVariable> _local_vars;
    std::vector<LocalVariableFrame> _local_frames;

public:
  std::ostream* iInitialOutput;

private:
  /// Hash of core commands with associated YacasEvaluator
  YacasCoreCommands& iCoreCommands;

  LispUserFunctions& iUserFunctions;
  LispHashTable& iHashTable;
  LispDefFiles   iDefFiles;
  LispPrinter&   iPrinter;
  std::ostream*    iCurrentOutput;

  /// Hash of global variables with their values
  LispGlobal&    iGlobals;

  LispOperators& iPreFixOperators;
  LispOperators& iInFixOperators;
  LispOperators& iPostFixOperators;
  LispOperators& iBodiedOperators;

  LispIdentifiers& protected_symbols;

  LispInput* iCurrentInput;

  const LispString* iPrettyReader;
  const LispString* iPrettyPrinter;
public:
  LispTokenizer iDefaultTokenizer;
  CommonLispTokenizer iCommonLispTokenizer;
  XmlTokenizer  iXmlTokenizer;
  LispTokenizer* iCurrentTokenizer;

public:
  /** YacasArgStack implements a stack of pointers to objects that can be used to pass
  *  arguments to functions, and receive results back.
  */
  class YacasArgStack {
  public:
    explicit YacasArgStack(std::size_t aStackSize):
      iStackCnt(0)
    {
      iStack.resize( aStackSize );
    }

    std::size_t GetStackTop() const
    {
        return iStackCnt;
    }

    void PushArgOnStack(LispObject* aObject)
    {
      if (iStackCnt >= iStack.size())
        RaiseStackOverflowError();

      iStack[iStackCnt++] = aObject;
    }

    LispPtr& GetElement(std::size_t aPos)
    {
      assert(aPos<iStackCnt);
      return iStack[aPos];
    }

    void PopTo(std::size_t aTop)
    {
      assert(aTop<=iStackCnt);
      iStackCnt=aTop;
    }

  private:
    void RaiseStackOverflowError() const
    {
      throw LispErrGeneric("Argument stack reached maximum. Please extend argument stack with --stack argument on the command line.");
    }

    // Invariants:
    //    0 <= iStackCnt <= iStack.Size()
    std::vector<LispPtr> iStack;
    std::size_t iStackCnt;    // number of items on the stack
  };

  YacasArgStack iStack;
};

inline LispInt LispEnvironment::Precision(void) const
{
    return iPrecision;
}

inline LispInt LispEnvironment::BinaryPrecision(void) const
{
  return iBinaryPrecision;
}



inline YacasCoreCommands& LispEnvironment::CoreCommands()
{
    return iCoreCommands;
}


inline LispHashTable& LispEnvironment::HashTable()
{
    return iHashTable;
}



// Local lisp stack, unwindable by the exception handler
class LispLocalFrame : public LispBase
{
public:
    LispLocalFrame(LispEnvironment& aEnvironment, bool aFenced)
        : iEnvironment(aEnvironment)
    {
        iEnvironment.PushLocalFrame(aFenced);
        SAFEPUSH(iEnvironment,*this);
    };
    virtual ~LispLocalFrame()
    {
        SAFEPOP(iEnvironment);
        Delete();
    };
    virtual void Delete();
private:
    LispEnvironment& iEnvironment;
};



class LispSecureFrame : public LispBase
{
public:
  LispSecureFrame(LispEnvironment& aEnvironment):
      iEnvironment(aEnvironment), previous_secure(aEnvironment.secure)
  {
    iEnvironment.secure = true;
    SAFEPUSH(iEnvironment,*this);
  };
  virtual ~LispSecureFrame()
  {
    SAFEPOP(iEnvironment);
    Delete();
  };
  virtual void Delete();
private:
  LispEnvironment& iEnvironment;
  bool previous_secure;
};


// LispLocalInput takes ownership over the LispInput class
class LispLocalInput : public LispBase, NonCopyable
{
public:
  LispLocalInput(LispEnvironment& aEnvironment, LispInput* aInput)
      : iEnvironment(aEnvironment),iPreviousInput(iEnvironment.CurrentInput())
  {
    iEnvironment.SetCurrentInput(aInput);
    SAFEPUSH(iEnvironment,*this);
  };
  virtual ~LispLocalInput()
  {
    SAFEPOP(iEnvironment);
    Delete();
  };
  virtual void Delete();

private:
  LispEnvironment& iEnvironment;
  LispInput* iPreviousInput;
};


// LispLocalInput takes ownership over the LispInput class
class LispLocalOutput : public LispBase, NonCopyable
{
public:
  LispLocalOutput(LispEnvironment& aEnvironment, std::ostream& aOutput)
      : iEnvironment(aEnvironment), iPreviousOutput(&iEnvironment.CurrentOutput())
  {
    iPreviousOutput = &iEnvironment.CurrentOutput();
    iEnvironment.SetCurrentOutput(aOutput);
    SAFEPUSH(iEnvironment,*this);
  };
  virtual ~LispLocalOutput()
  {
    SAFEPOP(iEnvironment);
    Delete();
  };
  virtual void Delete();

private:
  LispEnvironment& iEnvironment;
  std::ostream* iPreviousOutput;
};

class LispLocalEvaluator : public YacasBase, NonCopyable
{
public:
  LispLocalEvaluator(LispEnvironment& aEnvironment,LispEvaluatorBase* aNewEvaluator);
  ~LispLocalEvaluator();

private:
  LispEvaluatorBase* iPreviousEvaluator;
  LispEnvironment& iEnvironment;
};

class LispLocalTrace : public YacasBase, NonCopyable
{
public:
  LispLocalTrace(LispUserFunction* aUserFunc);
  ~LispLocalTrace();
private:
  LispUserFunction* iUserFunc;
};

class LocalArgs : public YacasBase, NonCopyable
{
public:
  LocalArgs(LispPtr* aPtrs) : iPtrs(aPtrs) {};
  ~LocalArgs()
  {
    if (iPtrs)
      delete[] iPtrs;
  }

private:
  LispPtr* iPtrs;
};



inline void LispEnvironment::SetPrettyReader(const LispString* aPrettyReader)
{
  iPrettyReader = aPrettyReader;
}
inline const LispString* LispEnvironment::PrettyReader()
{
  return iPrettyReader;
}

inline void LispEnvironment::SetPrettyPrinter(const LispString * aPrettyPrinter)
{
  iPrettyPrinter = aPrettyPrinter;
}
inline const LispString* LispEnvironment::PrettyPrinter()
{
  return iPrettyPrinter;
}


#endif