summaryrefslogtreecommitdiff
path: root/graphics/asymptote/virtualfieldaccess.cc
blob: aed130f33a6676eaa944f85521283b84c5062e1b (plain)
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
/*****
 * virtualfieldaccess.cc
 * Andy Hammerlindl 2009/07/23
 *
 * Implements the access subclass used to read and write virtual fields.
 *****/

#include "virtualfieldaccess.h"
#include "coder.h"

namespace trans {

void virtualFieldAccess::encode(action act, position pos, coder &e)
{
  switch(act) {
    case CALL:
      if (caller) {
        caller->encode(CALL, pos, e);
      } else {
        this->encode(READ, pos, e);
        e.encode(inst::popcall);
      }
      return;
    case READ:
      assert(getter);
      getter->encode(CALL, pos, e);
      return;
    case WRITE:
      if (setter)
        setter->encode(CALL, pos, e);
      else {
        em.error(pos);
        em << "virtual field is read-only";
      }
      return;
  }
}

void virtualFieldAccess::encode(action act, position pos, coder &e, frame *)
{
  e.encode(inst::pop);
  encode(act, pos, e);
}

} // namespace trans