1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }