2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #ifndef incl_HHBBC_CONTEXT_H_
17 #define incl_HHBBC_CONTEXT_H_
19 #include <folly/Hash.h>
20 #include <folly/Optional.h>
22 #include "hphp/hhbbc/index.h"
23 #include "hphp/hhbbc/type-system.h"
25 #include "hphp/util/compact-vector.h"
27 namespace HPHP
{ namespace HHBBC
{
29 //////////////////////////////////////////////////////////////////////
33 //////////////////////////////////////////////////////////////////////
36 * A Context is a (unit, func, class) triple, where cls and func
37 * fields may be null in some situations. Most queries to the Index
38 * need a "context", to allow recording dependencies.
41 const php::Unit
* unit
;
43 const php::Class
* cls
;
45 using Hash
= ContextHash
;
48 size_t operator()(const Context
& c
) const {
49 return pointer_hash
<void>{}(c
.func
? (void*)c
.func
:
50 c
.cls
? (void*)c
.cls
: (void*)c
.unit
);
54 inline bool operator==(Context a
, Context b
) {
55 return a
.unit
== b
.unit
&& a
.func
== b
.func
&& a
.cls
== b
.cls
;
58 inline bool operator<(Context a
, Context b
) {
59 return std::make_tuple(a
.unit
, a
.func
, a
.cls
) <
60 std::make_tuple(b
.unit
, b
.func
, b
.cls
);
64 * Context for a call to a function. This is the function itself,
65 * plus the types and number of arguments, and the type of
66 * $this/get_called_context().
69 const php::Func
* callee
;
70 CompactVector
<Type
> args
;
74 inline bool operator==(const CallContext
& a
, const CallContext
& b
) {
75 return a
.callee
== b
.callee
&&
76 equivalently_refined(a
.args
, b
.args
) &&
77 equivalently_refined(a
.context
, b
.context
);
80 //////////////////////////////////////////////////////////////////////