"Fossies" - the Fresh Open Source Software Archive

Member "asymptote-2.61/access.h" (18 Nov 2019, 2976 Bytes) of package /linux/misc/asymptote-2.61.src.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "access.h" see the Fossies "Dox" file reference documentation.

    1 /*****
    2  * access.h
    3  * Andy Hammerlindl 2003/12/03
    4  *
    5  * Describes an "access," a representation of where a variable will be
    6  * stored at runtime, so that read, write, and call instructions can be
    7  * made.
    8  *****/
    9 
   10 #ifndef ACCESS_H
   11 #define ACCESS_H
   12 
   13 #include <cassert>
   14 
   15 #include "errormsg.h"
   16 #include "item.h"
   17 #include "vm.h"
   18 
   19 namespace vm {
   20   struct callable;
   21 }
   22 
   23 namespace trans {
   24   
   25 class frame;
   26 class coder;
   27 
   28 enum action {
   29   READ,
   30   WRITE,
   31   CALL
   32 };
   33 
   34 // These serves as the base class for the accesses.
   35 class access : public gc { 
   36 protected:
   37   // Generic compiler access error - if the compiler functions properly,
   38   // none of these should be reachable by the user.
   39   void error(position pos)
   40   {
   41     em.compiler(pos);
   42     em << "invalid use of access";
   43   }
   44 
   45 public:
   46   virtual ~access() = 0;
   47   
   48   // Encode a read/write/call of the access when nothing is on the stack.
   49   virtual void encode(action, position pos, coder &)
   50   {
   51     error(pos);
   52   }
   53   // Encode a read/write/call of the access when the frame "top" is on top
   54   // of the stack.
   55   virtual void encode(action, position pos, coder &, frame *)
   56   {
   57     error(pos);
   58   }
   59 };
   60 
   61 // This class represents identity conversions in casting.
   62 class identAccess : public access 
   63 {
   64   virtual void encode(action act, position, coder&);
   65 };
   66 
   67 // Represents a function that is implemented by a built-in C++ function.
   68 class bltinAccess : public access {
   69   vm::bltin f;
   70 
   71 public:
   72   bltinAccess(vm::bltin f)
   73     : f(f) {}
   74 
   75   void encode(action act, position pos, coder &e);
   76   void encode(action act, position pos, coder &e, frame *);
   77 };
   78 
   79 // Similar to bltinAccess, but works for any callable.
   80 class callableAccess : public access {
   81   vm::callable *f;
   82 
   83 public:
   84   callableAccess(vm::callable *f)
   85     : f(f) {}
   86 
   87   void encode(action act, position pos, coder &e);
   88   void encode(action act, position pos, coder &e, frame *);
   89 };
   90 
   91 // An access that puts a frame on the top of the stack.
   92 class frameAccess : public access {
   93   frame *f;
   94 
   95 public:
   96   frameAccess(frame *f)
   97     : f(f) {}
   98   
   99   void encode(action act, position pos, coder &e);
  100   void encode(action act, position pos, coder &e, frame *top);
  101 };
  102 
  103 // Represents the access of a local variable.
  104 class localAccess : public access {
  105   Int offset;
  106   frame *level;
  107 
  108 public:
  109   localAccess(Int offset, frame *level)
  110     : offset(offset), level(level) {}
  111 
  112   void encode(action act, position pos, coder &e);
  113   void encode(action act, position pos, coder &e, frame *top);
  114 };
  115 
  116 class qualifiedAccess : public access {
  117   // The location and frame of the record.
  118   access *qualifier;
  119   frame *qualifierLevel;  
  120 
  121   // The location of the field relative to the record.
  122   access *field;
  123 
  124 public:
  125   qualifiedAccess(access *qualifier, frame *qualifierLevel, access *field)
  126     : qualifier(qualifier), qualifierLevel(qualifierLevel), field(field) {}
  127 
  128   void encode(action act, position pos, coder &e);
  129   void encode(action act, position pos, coder &e, frame *top);
  130 };
  131 
  132 } // namespace trans
  133 
  134 #endif // ACCESS_H
  135