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.CheckNoneAction;
24 import org.millscript.millscript.vm.CompilerState;
25
26 /**
27 * This class implements a check none expression. A check none expression is
28 * guaranteed to return no results.
29 *
30 * @see CheckNoneAction
31 */
32 public final class CheckNoneExpr extends Expr< CheckNoneAction > implements ZeroResults {
33
34 /**
35 * Returns an expression that is guaranteed to return no results. This
36 * method provides some compile-time optimisation, as it avoids creating
37 * additional unnecessary objects in the expression tree. If the specified
38 * expression already returns no results, it is simply returned, otherwise
39 * if it returns an unknown number of results, a new check none expression
40 * is created.
41 *
42 * @param x the expression which must return no results
43 * @return the specified expression if it already returns no results,
44 * otherwise a new {@link CheckNoneExpr}
45 */
46 public static Expr< ? > make( final Expr< ? > x ) {
47 return x.arity() == 0 ? x : new CheckNoneExpr( x );
48 }
49
50 /**
51 * The expression which must return no results.
52 */
53 private final Expr< ? > cont;
54
55 /**
56 * Creates a new check none expression, to check the specified expression
57 * returns no results.
58 *
59 * @param x the expression which must return no results
60 */
61 public CheckNoneExpr( final Expr< ? > x ) {
62 cont = x;
63 }
64
65 /**
66 * @see org.millscript.millscript.expr.Expr#compileIt()
67 */
68 @Override
69 public CheckNoneAction compileIt() {
70 return new CheckNoneAction( cont.compile() );
71 }
72
73 /**
74 * @see org.millscript.millscript.expr.Expr#resolve(org.millscript.millscript.vm.CompilerState)
75 */
76 @Override
77 public void resolve( final CompilerState state ) {
78 this.cont.resolve( state );
79 }
80
81 /**
82 * @see org.millscript.millscript.expr.Expr#showComponents(int)
83 */
84 @Override
85 void showComponents( final int n ) {
86 this.cont.show( n );
87 }
88
89 }