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_HPHP_REPO_AUTOLOAD_MAP_BUILDER_H_
17 #define incl_HPHP_REPO_AUTOLOAD_MAP_BUILDER_H_
19 #include "hphp/runtime/base/repo-autoload-map.h"
20 #include "hphp/runtime/base/string-data.h"
21 #include "hphp/runtime/base/string-functors.h"
22 #include "hphp/runtime/vm/blob-helper.h"
23 #include "hphp/util/hash-map.h"
25 #include <tbb/concurrent_hash_map.h>
29 //////////////////////////////////////////////////////////////////////
31 struct PreClassEmitter
;
36 struct RepoAutoloadMapBuilder
{
40 RepoAutoloadMapBuilder::init();
44 RepoAutoloadMapBuilder::fini();
48 template <typename Compare
>
49 using Map
= tbb::concurrent_hash_map
<
55 using CaseInsensitiveMap
= Map
<StringDataHashICompare
>;
56 using CaseSensitiveMap
= Map
<StringDataHashCompare
>;
59 virtual void addClass(const PreClassEmitter
& ce
, int unitSn
) = 0;
60 virtual void addFunc(const FuncEmitter
& fe
, int unitSn
) = 0;
61 virtual void addTypeAlias(const TypeAlias
& fe
, int unitSn
) = 0;
62 virtual void addConstant(const Constant
& fe
, int unitSn
) = 0;
63 virtual void serde(BlobEncoder
& sd
) = 0;
66 friend struct FuncEmitter
;
68 struct BuilderNoop
: public BuilderBase
{
69 void addClass(const PreClassEmitter
& ce
, int unitSn
) {};
70 void addFunc(const FuncEmitter
& fe
, int unitSn
) {};
71 void addTypeAlias(const TypeAlias
& fe
, int unitSn
) {};
72 void addConstant(const Constant
& fe
, int unitSn
) {};
73 void serde(BlobEncoder
& sd
) {
74 assertx(false && "Can not call serde on BuilderNoop");
78 struct BuilderCollect
: public BuilderBase
{
79 void addClass(const PreClassEmitter
& ce
, int unitSn
);
80 void addFunc(const FuncEmitter
& fe
, int unitSn
);
81 void addTypeAlias(const TypeAlias
& fe
, int unitSn
);
82 void addConstant(const Constant
& fe
, int unitSn
);
83 void serde(BlobEncoder
& sd
);
86 CaseInsensitiveMap m_classes
;
87 CaseInsensitiveMap m_funcs
;
88 CaseInsensitiveMap m_typeAliases
;
89 CaseSensitiveMap m_constants
;
92 static std::unique_ptr
<RepoAutoloadMap
> serde(BlobDecoder
& sd
);
94 static RepoAutoloadMapBuilder::BuilderBase
& get();
96 template<class Compare
>
97 static void serdeMap(BlobEncoder
& sd
, Map
<Compare
> map
) {
99 for (auto it
= map
.begin(); it
!= map
.end(); ++it
) {
107 static Map
serdeMap(BlobDecoder
& sd
) {
111 for (size_t i
= 0; i
< size
; i
++) {
112 const StringData
* str
;
122 static Guard
collect() {
131 //////////////////////////////////////////////////////////////////////