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 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_VM_RECORD_EMIT_H_
18 #define incl_HPHP_VM_RECORD_EMIT_H_
20 #include "hphp/runtime/base/repo-auth-type.h"
21 #include "hphp/runtime/base/array-data.h"
23 #include "hphp/runtime/vm/func.h"
24 #include "hphp/runtime/vm/func-emitter.h"
25 #include "hphp/runtime/vm/record.h"
26 #include "hphp/runtime/vm/repo-helpers.h"
31 ///////////////////////////////////////////////////////////////////////////////
34 struct RecordEmitter
{
39 Field(const RecordEmitter
* re
,
42 const StringData
* userType
,
43 const TypeConstraint
& typeConstraint
,
44 const StringData
* docComment
,
45 const TypedValue
* val
,
46 RepoAuthType repoAuthType
,
47 UserAttributeMap userAttributes
);
49 const StringData
* name() const { return m_name
; }
50 const StringData
* mangledName() const { return m_mangledName
; }
51 Attr
attrs() const { return m_attrs
; }
52 const StringData
* userType() const { return m_userType
; }
53 const TypeConstraint
& typeConstraint() const { return m_typeConstraint
; }
54 const StringData
* docComment() const { return m_docComment
; }
55 const TypedValue
& val() const { return m_val
; }
56 RepoAuthType
repoAuthType() const { return m_repoAuthType
; }
57 UserAttributeMap
userAttributes() const { return m_userAttributes
; }
59 template<class SerDe
> void serde(SerDe
& sd
) {
74 void resolveArray(const RecordEmitter
* re
) {
75 m_repoAuthType
.resolveArray(re
->ue());
79 LowStringPtr m_name
{nullptr};
80 LowStringPtr m_mangledName
{nullptr};
81 Attr m_attrs
{AttrNone
};
82 LowStringPtr m_userType
{nullptr};
83 LowStringPtr m_docComment
{nullptr};
85 RepoAuthType m_repoAuthType
{};
86 TypeConstraint m_typeConstraint
{};
87 UserAttributeMap m_userAttributes
{};
90 using FieldMap
= IndexedStringMap
<Field
, true, Slot
>;
92 RecordEmitter(UnitEmitter
& ue
, Id id
, const std::string
& name
);
94 void init(int line1
, int line2
, Attr attrs
,
95 const StringData
* parentName
,
96 const StringData
* docComment
);
98 UnitEmitter
& ue() const { return m_ue
; }
99 const StringData
* name() const { return m_name
; }
100 const StringData
* parentName() const { return m_parent
; }
101 Attr
attrs() const { return m_attrs
; }
102 UserAttributeMap
userAttributes() const { return m_userAttributes
; }
103 void setUserAttributes(UserAttributeMap map
) {
104 m_userAttributes
= std::move(map
);
107 Id
id() const { return m_id
; }
109 void commit(RepoTxn
& txn
) const; // throws(RepoExc)
111 PreRecordDesc
* create(Unit
& unit
) const;
113 template<class SerDe
> void serdeMetaData(SerDe
&);
115 std::pair
<int,int> getLocation() const {
116 return std::make_pair(m_line1
, m_line2
);
118 const StringData
* docComment() const { return m_docComment
; }
120 const FieldMap::Builder
& fieldMap() const { return m_fieldMap
; }
121 using UpperBoundVec
= CompactVector
<TypeConstraint
>;
122 void addUpperBound(const StringData
*, const UpperBoundVec
&) {}
123 bool hasUpperBound(const StringData
*) { return false; }
124 bool addField(const StringData
* n
,
126 const StringData
* userType
,
127 const TypeConstraint
& typeConstraint
,
128 const UpperBoundVec
&, // unused
129 const StringData
* docComment
,
130 const TypedValue
* val
,
140 LowStringPtr m_parent
;
141 LowStringPtr m_docComment
;
143 UserAttributeMap m_userAttributes
;
144 FieldMap::Builder m_fieldMap
;
147 struct RecordRepoProxy
: RepoProxy
{
148 friend struct PreRecordDesc
;
149 friend struct RecordEmitter
;
151 explicit RecordRepoProxy(Repo
& repo
);
153 void createSchema(int repoId
, RepoTxn
& txn
); // throws(RepoExc)
155 struct InsertRecordStmt
: public RepoProxy::Stmt
{
156 InsertRecordStmt(Repo
& repo
, int repoId
) : Stmt(repo
, repoId
) {}
157 void insert(const RecordEmitter
& re
, RepoTxn
& txn
, int64_t unitSn
,
158 Id recordId
, const StringData
* name
); // throws(RepoExc)
161 struct GetRecordsStmt
: public RepoProxy::Stmt
{
162 GetRecordsStmt(Repo
& repo
, int repoId
) : Stmt(repo
, repoId
) {}
163 void get(UnitEmitter
& ue
); // throws(RepoExc)
166 InsertRecordStmt insertRecord
[RepoIdCount
];
167 GetRecordsStmt getRecords
[RepoIdCount
];
170 ///////////////////////////////////////////////////////////////////////////////