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 explicit Package(const char* root
);
50 void addAllFiles(bool force
); // add from Option::PackageDirectories/Files
52 // Set up the async portion of Package. This cannot be done in the
53 // constructor because it must be done after hphp_process_init().
54 void createAsyncState();
55 // Optionally return a running thread clearing the async state
56 // (which can take a long time). If std::nullopt is returned, the
57 // state is already cleared.
58 Optional
<std::thread
> clearAsyncState();
60 void addSourceFile(const std::string
& fileName
, bool check
= false);
61 void addInputList(const std::string
& listFileName
);
62 void addStaticFile(const std::string
& fileName
);
63 void addDirectory(const std::string
&path
, bool force
);
64 void addStaticDirectory(const std::string
& path
);
68 AnalysisResultPtr
getAnalysisResult() { return m_ar
;}
69 void resetAr() { m_ar
.reset(); }
70 int getFileCount() const { return m_filesToParse
.size();}
71 int getLineCount() const { return m_lineCount
;}
72 int getCharCount() const { return m_charCount
;}
74 size_t getTotalParses() const { return m_total
.load(); }
75 size_t getParseCacheHits() const { return m_cacheHits
.load(); }
76 size_t getFileStores() const { return m_storedFiles
.load(); }
77 size_t getFileReads() const { return m_readFiles
.load(); }
79 void saveStatsToFile(const char *filename
, int totalSeconds
) const;
81 const std::string
& getRoot() const { return m_root
;}
82 std::shared_ptr
<FileCache
> getFileCache();
89 folly::fs::path m_path
;
92 using FileAndSizeVec
= std::vector
<FileAndSize
>;
95 explicit ParseGroup(bool b
) : m_check
{b
} {}
96 std::vector
<folly::fs::path
> m_files
;
101 using ParseGroups
= std::vector
<ParseGroup
>;
104 ParseGroups m_grouped
;
105 FileAndSizeVec m_ungrouped
;
110 coro::Task
<GroupResult
> groupDirectories(std::string
, bool);
111 void groupFiles(ParseGroups
&, FileAndSizeVec
, bool);
113 coro::Task
<FileAndSizeVec
> parseGroups(ParseGroups
);
114 coro::Task
<FileAndSizeVec
> parseGroup(ParseGroup
);
116 void addUnitEmitter(std::unique_ptr
<UnitEmitter
> ue
);
120 folly_concurrent_hash_map_simd
<std::string
, bool> m_parsedFiles
;
122 std::atomic
<bool> m_parseFailed
;
124 AnalysisResultPtr m_ar
;
125 std::atomic
<int> m_lineCount
;
126 std::atomic
<int> m_charCount
;
128 std::atomic
<size_t> m_cacheHits
;
129 std::atomic
<size_t> m_readFiles
;
130 std::atomic
<size_t> m_storedFiles
;
131 std::atomic
<size_t> m_total
;
133 folly_concurrent_hash_map_simd
<std::string
, bool> m_filesToParse
;
134 std::shared_ptr
<FileCache
> m_fileCache
;
135 std::map
<std::string
,bool> m_directories
;
136 std::set
<std::string
> m_staticDirectories
;
137 hphp_fast_set
<std::string
> m_extraStaticFiles
;
138 folly_concurrent_hash_map_simd
<
139 std::string
, std::string
140 > m_discoveredStaticFiles
;
145 static extern_worker::Options
makeOptions();
147 coro::TicketExecutor m_executor
;
148 extern_worker::Client m_client
;
150 coro::AsyncValue
<extern_worker::Ref
<Config
>> m_config
;
152 extern_worker::RefCache
<SHA1
, RepoOptionsFlags
> m_repoOptions
;
154 std::unique_ptr
<AsyncState
> m_async
;
157 ///////////////////////////////////////////////////////////////////////////////