1 28 29 package com.caucho.es.parser; 30 31 import java.io.IOException ; 32 33 36 class SpecialExpr extends Expr { 37 final static int THIS = 't'; 38 final static int HAS_NEXT = 'm'; 39 final static int NEXT = 'n'; 40 final static int EXCEPTION = 'e'; 41 final static int ARRAY = 'a'; 42 43 private int code; 44 private String str; 45 private Expr expr; 46 47 SpecialExpr(Block block, int code) 48 { 49 super(block); 50 51 if (code == THIS) 52 block.function.setThis(); 53 this.code = code; 54 } 55 56 SpecialExpr(Block block, int code, String str) 57 { 58 super(block); 59 60 this.code = code; 61 this.str = str; 62 } 63 64 SpecialExpr(Block block, int code, Expr expr) 65 { 66 super(block); 67 68 this.code = code; 69 this.expr = expr; 70 } 71 72 int getType() 73 { 74 switch (code) { 75 case HAS_NEXT: 76 return TYPE_BOOLEAN; 77 78 case THIS: 79 case NEXT: 80 case EXCEPTION: 81 case ARRAY: 82 return TYPE_ES; 83 84 default: 85 throw new RuntimeException (); 86 } 87 } 88 89 void printBooleanImpl() throws IOException 90 { 91 switch (code) { 92 case HAS_NEXT: 93 cl.print(str + ".hasNext()"); 94 break; 95 96 default: 97 throw new RuntimeException (); 98 } 99 } 100 101 void printImpl() throws IOException 102 { 103 switch (code) { 104 case THIS: 105 cl.print("_this"); 106 break; 107 108 case NEXT: 109 cl.print("((ESBase) " + str + ".next())"); 110 break; 111 112 case EXCEPTION: 113 cl.print("_env.wrap(new ESWrapperException(" + str + "))"); 114 break; 115 116 case ARRAY: 117 cl.print("_env.array("); 118 expr.print(); 119 cl.print(")"); 120 break; 121 122 default: 123 throw new RuntimeException (); 124 } 125 } 126 } 127 128 | Popular Tags |