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 +----------------------------------------------------------------------+
25 #include "hphp/util/coro.h"
26 #include "hphp/util/extern-worker.h"
27 #include "hphp/util/file-cache.h"
28 #include "hphp/util/hash-map.h"
29 #include "hphp/util/mutex.h"
30 #include "hphp/util/optional.h"
32 #include "hphp/hhbbc/hhbbc.h"
35 ///////////////////////////////////////////////////////////////////////////////
37 struct AnalysisResult
;
38 using AnalysisResultPtr
= std::shared_ptr
<AnalysisResult
>;
41 * A package contains a list of directories and files that will be parsed
42 * and analyzed together. No files outside of a package will be considered
43 * in type inferences. One single AnalysisResult will be generated and it
44 * contains all classes, functions, variables, constants and their types.
45 * Therefore, a package is really toppest entry point for parsing.
48 Package(const char* root
, bool parseOnDemand
);
50 // Set up the async portion of Package. This cannot be done in the
51 // constructor because it must be done after hphp_process_init().
52 void createAsyncState();
53 // Optionally return a running thread clearing the async state
54 // (which can take a long time). If std::nullopt is returned, the
55 // state is already cleared.
56 Optional
<std::thread
> clearAsyncState();
58 void addSourceFile(const std::string
& fileName
);
59 void addInputList(const std::string
& listFileName
);
60 void addStaticFile(const std::string
& fileName
);
61 void addDirectory(const std::string
& path
);
62 void addStaticDirectory(const std::string
& path
);
66 AnalysisResultPtr
getAnalysisResult() { return m_ar
;}
67 void resetAr() { m_ar
.reset(); }
69 size_t getTotalParses() const { return m_total
.load(); }
70 size_t getParseCacheHits() const { return m_cacheHits
.load(); }
71 size_t getFileStores() const { return m_storedFiles
.load(); }
72 size_t getFileReads() const { return m_readFiles
.load(); }
74 const std::string
& getRoot() const { return m_root
;}
75 std::shared_ptr
<FileCache
> getFileCache();
82 folly::fs::path m_path
;
85 using FileAndSizeVec
= std::vector
<FileAndSize
>;
88 std::vector
<folly::fs::path
> m_files
;
92 using ParseGroups
= std::vector
<ParseGroup
>;
95 ParseGroups m_grouped
;
96 FileAndSizeVec m_ungrouped
;
101 coro::Task
<GroupResult
> groupDirectories(std::string
);
102 void groupFiles(ParseGroups
&, FileAndSizeVec
);
104 coro::Task
<FileAndSizeVec
> parseGroups(ParseGroups
);
105 coro::Task
<FileAndSizeVec
> parseGroup(ParseGroup
);
107 void addUnitEmitter(std::unique_ptr
<UnitEmitter
> ue
);
109 void resolveOnDemand(FileAndSizeVec
&, const SymbolRefs
&, bool report
= false);
113 folly_concurrent_hash_map_simd
<std::string
, bool> m_parsedFiles
;
115 std::atomic
<bool> m_parseFailed
;
117 AnalysisResultPtr m_ar
;
119 bool m_parseOnDemand
;
121 std::atomic
<size_t> m_cacheHits
;
122 std::atomic
<size_t> m_readFiles
;
123 std::atomic
<size_t> m_storedFiles
;
124 std::atomic
<size_t> m_total
;
126 folly_concurrent_hash_map_simd
<std::string
, bool> m_filesToParse
;
127 std::shared_ptr
<FileCache
> m_fileCache
;
128 std::set
<std::string
> m_directories
;
129 std::set
<std::string
> m_staticDirectories
;
130 hphp_fast_set
<std::string
> m_extraStaticFiles
;
131 folly_concurrent_hash_map_simd
<
132 std::string
, std::string
133 > m_discoveredStaticFiles
;
138 static extern_worker::Options
makeOptions();
140 coro::TicketExecutor m_executor
;
141 extern_worker::Client m_client
;
143 coro::AsyncValue
<extern_worker::Ref
<Config
>> m_config
;
145 extern_worker::RefCache
<SHA1
, RepoOptionsFlags
> m_repoOptions
;
147 std::unique_ptr
<AsyncState
> m_async
;
150 ///////////////////////////////////////////////////////////////////////////////