View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 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.SpiceClassInitAction;
24  import org.millscript.millscript.vm.CompilerState;
25  
26  /**
27   * This class represents a definition of a <code>class</code> <code>init</code>
28   * procedure.
29   */
30  public final class SpiceClassInitExpr extends Expr< SpiceClassInitAction > implements OneResult {
31  
32      /**
33       * The name of the class this method belongs to, for the dispatch
34       * parameter.
35       */
36      private final NameExpr classNameExpr;
37  
38      /**
39       * The <code>init</code> procedure.
40       */
41      private final LambdaExpr init;
42  
43      /**
44       * Constructs a new init expression for the specified initialiser.
45       *
46       * @param name  the name of the class this init constructs
47       * @param lambda    the initialiser procedure
48       */
49      public SpiceClassInitExpr( final NameExpr name, final LambdaExpr lambda ) {
50          this.classNameExpr = name;
51          this.init = lambda;
52      }
53  
54      /**
55       * @see org.millscript.millscript.expr.Expr#compileIt()
56       */
57      @Override
58      public SpiceClassInitAction compileIt() {
59          return new SpiceClassInitAction( this.classNameExpr.compile(), this.init.compile() );
60      }
61  
62      /**
63       * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
64       */
65      @Override
66      public void resolve( final CompilerState state ) {
67          this.classNameExpr.resolve( state );
68          this.init.resolve( state );
69      }
70  
71      /**
72       * @see org.millscript.millscript.expr.Expr#showComponents(int)
73       */
74      @Override
75      void showComponents( final int n ) {
76          this.classNameExpr.show( n );
77          this.init.show( n );
78      }
79  
80  }