Use interfaces for types in ET type tests
[hiphop-php.git] / hphp / hack / test / hhi / expr_tree.hhi
blob842ad6897e03583b014498e851ecdae3d042d70c
1 <?hh
3 class Code {
4   const type TAst = mixed;
6   public static function makeTree<<<__Explicit>> TInfer>(
7     ?ExprPos $pos,
8     shape(
9       'splices' => dict<string, mixed>,
10       'functions' => vec<mixed>,
11       'static_methods' => vec<mixed>,
12     ) $metadata,
13     (function(Code): Code::TAst) $ast,
14   ): ExprTree<Code, Code::TAst, TInfer> {
15     throw new Exception();
16   }
18   // Virtual types (These do not have to be implemented)
19   public static function intType(): ExampleInt {
20     throw new Exception();
21   }
22   public static function floatType(): ExampleFloat {
23     throw new Exception();
24   }
25   public static function boolType(): ExampleBool {
26     throw new Exception();
27   }
28   public static function stringType(): ExampleString {
29     throw new Exception();
30   }
31   public static function nullType(): null {
32     throw new Exception();
33   }
34   public static function voidType(): ExampleVoid {
35     throw new Exception();
36   }
37   public static function symbolType<T>(
38     (function(ExampleContext): Awaitable<ExprTree<Code, Code::TAst, T>>) $_,
39   ): T {
40     throw new Exception();
41   }
43   // Desugared nodes (These should be implemented)
44   public function visitInt(?ExprPos $_, int $_): Code::TAst {
45     throw new Exception();
46   }
47   public function visitFloat(?ExprPos $_, float $_): Code::TAst {
48     throw new Exception();
49   }
50   public function visitBool(?ExprPos $_, bool $_): Code::TAst {
51     throw new Exception();
52   }
53   public function visitString(?ExprPos $_, string $_): Code::TAst {
54     throw new Exception();
55   }
56   public function visitNull(?ExprPos $_): Code::TAst {
57     throw new Exception();
58   }
60   public function visitBinop(
61     ?ExprPos $_,
62     Code::TAst $lhs,
63     string $op,
64     Code::TAst $rhs,
65   ): Code::TAst {
66     throw new Exception();
67   }
69   public function visitUnop(
70     ?ExprPos $_,
71     Code::TAst $operand,
72     string $operator,
73   ): Code::TAst {
74     throw new Exception();
75   }
77   public function visitLocal(?ExprPos $_, string $_): Code::TAst {
78     throw new Exception();
79   }
81   public function visitLambda(
82     ?ExprPos $_,
83     vec<string> $_args,
84     vec<Code::TAst> $_body,
85   ): Code::TAst {
86     throw new Exception();
87   }
89   public function visitGlobalFunction<T>(
90     ?ExprPos $_,
91     (function(ExampleContext): Awaitable<ExprTree<Code, Code::TAst, T>>) $_,
92   ): Code::TAst {
93     throw new Exception();
94   }
96   public function visitStaticMethod<T>(
97     ?ExprPos $_,
98     (function(ExampleContext): Awaitable<ExprTree<Code, Code::TAst, T>>) $_,
99   ): Code::TAst {
100     throw new Exception();
101   }
103   public function visitCall(
104     ?ExprPos $_,
105     Code::TAst $_callee,
106     vec<Code::TAst> $_args,
107   ): Code::TAst {
108     throw new Exception();
109   }
111   public function visitAssign(
112     ?ExprPos $_,
113     Code::TAst $_,
114     Code::TAst $_,
115   ): Code::TAst {
116     throw new Exception();
117   }
119   public function visitTernary(
120     ?ExprPos $_,
121     Code::TAst $_condition,
122     ?Code::TAst $_truthy,
123     Code::TAst $_falsy,
124   ): Code::TAst {
125     throw new Exception();
126   }
128   // Statements.
129   public function visitIf(
130     ?ExprPos $_,
131     Code::TAst $_cond,
132     vec<Code::TAst> $_then_body,
133     vec<Code::TAst> $_else_body,
134   ): Code::TAst {
135     throw new Exception();
136   }
137   public function visitWhile(
138     ?ExprPos $_,
139     Code::TAst $_cond,
140     vec<Code::TAst> $_body,
141   ): Code::TAst {
142     throw new Exception();
143   }
144   public function visitReturn(?ExprPos $_, ?Code::TAst $_): Code::TAst {
145     throw new Exception();
146   }
147   public function visitFor(
148     ?ExprPos $_,
149     vec<Code::TAst> $_,
150     ?Code::TAst $_,
151     vec<Code::TAst> $_,
152     vec<Code::TAst> $_,
153   ): Code::TAst {
154     throw new Exception();
155   }
156   public function visitBreak(?ExprPos $_): Code::TAst {
157     throw new Exception();
158   }
159   public function visitContinue(?ExprPos $_): Code::TAst {
160     throw new Exception();
161   }
162   public function visitPropertyAccess(
163     ?ExprPos $_,
164     Code::TAst $_,
165     string $_,
166   ): Code::TAst {
167     throw new Exception();
168   }
169   public function visitXhp(
170     ?ExprPos $_,
171     string $_,
172     dict<string, Code::TAst> $_,
173     vec<Code::TAst> $_,
174   ): Code::TAst {
175     throw new Exception();
176   }
178   public function visitInstanceMethod(
179     ?ExprPos $_,
180     Code::TAst $_obj,
181     string $_method_name,
182   ): Code::TAst {
183     throw new Exception();
184   }
186   public function splice<T>(
187     ?ExprPos $_,
188     string $_key,
189     Spliceable<Code, Code::TAst, T> $_,
190   ): Code::TAst {
191     throw new Exception();
192   }
195 interface Spliceable<TVisitor, TResult, +TInfer> {
196   public function visit(TVisitor $v): TResult;
199 final class ExprTree<TVisitor, TResult, +TInfer>
200   implements Spliceable<TVisitor, TResult, TInfer> {
201   public function __construct(
202     private ?ExprPos $pos,
203     private shape(
204       'splices' => dict<string, mixed>,
205       'functions' => vec<mixed>,
206       'static_methods' => vec<mixed>,
207     ) $metadata,
208     private (function(TVisitor): TResult) $ast,
209     private (function(): TInfer) $err,
210   ) {}
212   public function visit(TVisitor $v): TResult {
213     return ($this->ast)($v);
214   }
217 type ExprPos = shape(...);
219 interface ExampleMixed {
220   public function __tripleEquals(ExampleMixed $_): ExampleBool;
221   public function __notTripleEquals(ExampleMixed $_): ExampleBool;
223 interface ExampleInt extends ExampleMixed {
224   public function __plus(ExampleInt $_): ExampleInt;
225   public function __minus(ExampleInt $_): ExampleInt;
226   public function __star(ExampleInt $_): ExampleInt;
227   public function __slash(ExampleInt $_): ExampleInt;
228   public function __percent(ExampleInt $_): ExampleInt;
229   public function __negate(): ExampleInt;
231   public function __lessThan(ExampleInt $_): ExampleBool;
232   public function __lessThanEqual(ExampleInt $_): ExampleBool;
233   public function __greaterThan(ExampleInt $_): ExampleBool;
234   public function __greaterThanEqual(ExampleInt $_): ExampleBool;
236   public function __amp(ExampleInt $_): ExampleInt;
237   public function __bar(ExampleInt $_): ExampleInt;
238   public function __caret(ExampleInt $_): ExampleInt;
239   public function __lessThanLessThan(ExampleInt $_): ExampleInt;
240   public function __greaterThanGreaterThan(ExampleInt $_): ExampleInt;
241   public function __tilde(): ExampleInt;
244 interface ExampleBool extends ExampleMixed {
245   public function __ampamp(ExampleBool $_): ExampleBool;
246   public function __barbar(ExampleBool $_): ExampleBool;
247   public function __bool(): bool;
248   public function __exclamationMark(): ExampleBool;
251 interface ExampleString extends ExampleMixed, XHPChild {
252   public function __dot(ExampleString $_): ExampleString;
255 interface ExampleFloat extends ExampleMixed {}
257 final class ExampleContext {}
259 interface ExampleVoid {}