View Javadoc

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