updated Makefile.common
[org.ibex.core.git] / src / org / ibex / js / Trap.java
1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
2 package org.ibex.js;
3
4 /**
5  *  This class encapsulates a single trap placed on a given node. The
6  *  traps for a given property name on a given box are maintained as a
7  *  linked list stack, with the most recently placed trap at the head
8  *  of the list.
9  */
10 final class Trap {
11
12     final JS target;          ///< the box on which this trap was placed
13     final JS key;             ///< the property that the trap was placed on
14
15     final JSFunction f;       ///< the function for this trap
16     Trap next;                ///< the next trap down the trap stack
17
18     Trap(JS b, JS n, JSFunction f, Trap nx) {
19         target = b; key = n; this.f = f; this.next = nx;
20     }
21     
22     boolean isReadTrap()  { return f.numFormalArgs == 0; }
23     boolean isWriteTrap() { return f.numFormalArgs != 0; }
24     Trap readTrap()  { Trap t = this; while(t!=null && t.isWriteTrap()) t = t.next; return t; }
25     Trap writeTrap() { Trap t = this; while(t!=null && t.isReadTrap())  t = t.next; return t; }
26     Trap nextReadTrap()  { return next == null ? null : next.readTrap();  }
27     Trap nextWriteTrap() { return next == null ? null : next.writeTrap(); }
28 }