add an example to showcase a bug in closure generation
[hiphop-php.git] / hphp / runtime / vm / class-meth-data.h
blob9ef754370191f6a80ebdb182e9b5f0d5d24d26c5
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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 +----------------------------------------------------------------------+
17 #pragma once
19 #include "hphp/runtime/base/countable.h"
20 #include "hphp/util/type-scan.h"
21 #include "hphp/util/low-ptr.h"
23 namespace HPHP {
25 struct Class;
26 struct Func;
27 struct String;
29 struct ClsMethData {
30 #ifdef USE_LOWPTR
31 using low_storage_t = uint32_t;
32 using cls_meth_t = ClsMethData;
33 #else
34 using low_storage_t = uintptr_t;
35 using cls_meth_t = ClsMethData*;
36 #endif
38 ClsMethData() = default;
40 static cls_meth_t make(Class* cls, Func* func);
42 bool validate() const;
44 Class* getCls() const {
45 return reinterpret_cast<Class*>(m_cls);
48 Func* getFunc() const {
49 return reinterpret_cast<Func*>(m_func);
52 String getClsStr() const;
54 String getFuncStr() const;
56 static constexpr ptrdiff_t clsOffset() {
57 return offsetof(ClsMethData, m_cls);
60 static constexpr ptrdiff_t funcOffset() {
61 return offsetof(ClsMethData, m_func);
64 bool isPersistent() const;
66 private:
67 ClsMethData(Class* cls, Func* func);
69 low_storage_t m_cls;
70 low_storage_t m_func;
73 #ifdef USE_LOWPTR
74 static_assert(sizeof(ClsMethData) == 8);
75 static_assert(ClsMethData::clsOffset() == 0, "Class offset must be 0");
76 static_assert(ClsMethData::funcOffset() == 4, "Func offset must be 4");
77 #endif
78 } // namespace HPHP