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.MethodOverrideAction;
24  import org.millscript.millscript.vm.CompilerState;
25  
26  /**
27   * This class implements a method override expression. This is used to
28   * introduce an override to a pre-existing method.
29   *
30   * @see org.millscript.millscript.syntax.DefineSyntax
31   * @see org.millscript.millscript.syntax.MethodOverrideSyntax
32   * @see org.millscript.millscript.action.MethodOverrideAction
33   */
34  public final class MethodOverrideExpr extends Expr< MethodOverrideAction > implements OneResult {
35  
36      /**
37       * The name of the class this method belongs to, for the dispatch
38       * parameter.
39       */
40      private final NameExpr classNameExpr;
41  
42      /**
43       * The lambda expression, for the body of the method override.
44       */
45      private final LambdaExpr lambda;
46  
47      /**
48       * The name of the method we are making an override for.
49       */
50      private final NameExpr methodNameExpr;
51  
52      /**
53       * Creates a new method override expression, to override the specified
54       * method with the new body for the specified type signature.
55       *
56       * @param mn    the name expression for the method we are overriding
57       * @param cn    the name expression for the Spice class to dispatch on
58       * @param e the lamba expression for the override method body
59       */
60      public MethodOverrideExpr( final NameExpr mn, final NameExpr cn, final LambdaExpr e ) {
61          classNameExpr = cn;
62          methodNameExpr = mn;
63          lambda = e;
64      }
65  
66      /**
67       * @see org.millscript.millscript.expr.Expr#compileIt()
68       */
69      @Override
70      public MethodOverrideAction compileIt() {
71          return new MethodOverrideAction( methodNameExpr.compileIt(), classNameExpr.compileIt(), lambda.compileIt() );
72      }
73  
74      /**
75       * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
76       */
77      @Override
78      public void resolve( final CompilerState state ) {
79          this.classNameExpr.resolve( state );
80          this.methodNameExpr.resolve( state );
81          this.lambda.resolve( state );
82      }
83  
84      /**
85       * @see org.millscript.millscript.expr.Expr#showComponents(int)
86       */
87      @Override
88      void showComponents( final int n ) {
89          this.classNameExpr.show( n );
90          this.methodNameExpr.show( n );
91          this.lambda.show( n );
92      }
93  
94  }