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
, const StringData
* docComment
);
96 UnitEmitter
& ue() const { return m_ue
; }
97 const StringData
* name() const { return m_name
; }
98 Attr
attrs() const { return m_attrs
; }
99 UserAttributeMap
userAttributes() const { return m_userAttributes
; }
100 void setUserAttributes(UserAttributeMap map
) {
101 m_userAttributes
= std::move(map
);
104 Id
id() const { return m_id
; }
106 void commit(RepoTxn
& txn
) const; // throws(RepoExc)
108 Record
* create(Unit
& unit
) const;
110 template<class SerDe
> void serdeMetaData(SerDe
&);
112 std::pair
<int,int> getLocation() const {
113 return std::make_pair(m_line1
, m_line2
);
115 const StringData
* docComment() const { return m_docComment
; }
117 const FieldMap::Builder
& fieldMap() const { return m_fieldMap
; }
118 bool addField(const StringData
* n
,
120 const StringData
* userType
,
121 const TypeConstraint
& typeConstraint
,
122 const StringData
* docComment
,
123 const TypedValue
* val
,
133 LowStringPtr m_docComment
;
135 UserAttributeMap m_userAttributes
;
136 FieldMap::Builder m_fieldMap
;
139 struct RecordRepoProxy
: RepoProxy
{
140 friend struct Record
;
141 friend struct RecordEmitter
;
143 explicit RecordRepoProxy(Repo
& repo
);
145 void createSchema(int repoId
, RepoTxn
& txn
); // throws(RepoExc)
147 struct InsertRecordStmt
: public RepoProxy::Stmt
{
148 InsertRecordStmt(Repo
& repo
, int repoId
) : Stmt(repo
, repoId
) {}
149 void insert(const RecordEmitter
& re
, RepoTxn
& txn
, int64_t unitSn
,
150 Id recordId
, const StringData
* name
); // throws(RepoExc)
153 struct GetRecordsStmt
: public RepoProxy::Stmt
{
154 GetRecordsStmt(Repo
& repo
, int repoId
) : Stmt(repo
, repoId
) {}
155 void get(UnitEmitter
& ue
); // throws(RepoExc)
158 InsertRecordStmt insertRecord
[RepoIdCount
];
159 GetRecordsStmt getRecords
[RepoIdCount
];
162 ///////////////////////////////////////////////////////////////////////////////