View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2004-2005 Kevin Rogers
4   //
5   // This file is part of MillScript.
6   //
7   // MillScript is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.millscript.expr;
22  
23  import org.millscript.millscript.action.Action;
24  import org.millscript.millscript.alert.Alerts;
25  import org.millscript.millscript.functions.SlotFunction;
26  import org.millscript.millscript.vm.CompilerState;
27  
28  /**
29   * This class represents a <code>class</code> <code>slot</code> initialisation
30   * expression.
31   *
32   * @see org.millscript.millscript.expr.SpiceClassExpr
33   * @see org.millscript.millscript.action.SpiceClassSlotAction
34   */
35  public final class SpiceClassSlotExpr extends Expr< Action > {
36  
37      /**
38       * The accessor function for this slot.
39       */
40      private final SlotFunction slotFunction;
41  
42      /**
43       * The slots initial value expression.
44       */
45      private final Expr< ? > slotValue;
46  
47      /**
48       * Constructs a new <code>class</code> <code>slot</code> initialisation
49       * expression.
50       *
51       * @param sf    the accessor function for this slot
52       * @param sv    the initial value expression for this slot
53       */
54      public SpiceClassSlotExpr( final SlotFunction sf, final Expr< ? > sv ) {
55          this.slotFunction = sf;
56          this.slotValue = CheckExpr.make( sv );
57      }
58  
59      /**
60       * @see org.millscript.millscript.expr.Expr#compileIt()
61       */
62      @Override
63      public Action compileIt() {
64          throw(
65              Alerts.fault( "Trying to compile a naked SlotExpr" ).mishap()
66          );
67      }
68  
69      /**
70       * Returns the slot function which accesses this slot.
71       *
72       * @return  the SlotFunction to access this slot
73       */
74      public SlotFunction getSlotFunction() {
75          return slotFunction;
76      }
77  
78      /**
79       * Returns the expression for the initial value of this slot.
80       *
81       * @return  the Expr for the initial value of this slot
82       */
83      public Expr< ? > getSlotValue() {
84          return slotValue;
85      }
86  
87      /**
88       * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
89       */
90      @Override
91      public void resolve( final CompilerState state ) {
92          this.slotValue.resolve( state );
93      }
94  
95      /**
96       * @see org.millscript.millscript.expr.Expr#showComponents(int)
97       */
98      @Override
99      void showComponents( final int n ) {
100         this.slotValue.show( n );
101     }
102 
103 }