Enforce Pos_or_decl.t in reasons for decl types
[hiphop-php.git] / hphp / compiler / package.h
blob00375ae97388e1e5683ede6f9fb1423f12e00971
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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 #pragma once
19 #include <map>
20 #include <memory>
21 #include <set>
22 #include <vector>
24 #include <folly/Optional.h>
26 #include "hphp/util/file-cache.h"
27 #include "hphp/util/mutex.h"
28 #include "hphp/hhbbc/hhbbc.h"
30 namespace HPHP {
31 ///////////////////////////////////////////////////////////////////////////////
33 struct AnalysisResult;
34 using AnalysisResultPtr = std::shared_ptr<AnalysisResult>;
36 /**
37 * A package contains a list of directories and files that will be parsed
38 * and analyzed together. No files outside of a package will be considered
39 * in type inferences. One single AnalysisResult will be generated and it
40 * contains all classes, functions, variables, constants and their types.
41 * Therefore, a package is really toppest entry point for parsing.
43 struct Package {
44 explicit Package(const char *root, bool bShortTags = true);
46 void addAllFiles(bool force); // add from Option::PackageDirectories/Files
48 void addSourceFile(const std::string& fileName, bool check = false);
49 void addInputList(const std::string& listFileName);
50 void addStaticFile(const std::string& fileName);
51 void addDirectory(const std::string &path, bool force);
52 void addStaticDirectory(const std::string& path);
53 void addSourceDirectory(const std::string& path, bool force);
55 bool parse(bool check, std::thread& unit_emitter_thread);
56 bool parseImpl(const std::string* fileName);
58 AnalysisResultPtr getAnalysisResult() { return m_ar;}
59 void resetAr() { m_ar.reset(); }
60 int getFileCount() const { return m_filesToParse.size();}
61 int getLineCount() const { return m_lineCount;}
62 int getCharCount() const { return m_charCount;}
64 void saveStatsToFile(const char *filename, int totalSeconds) const;
66 const std::string& getRoot() const { return m_root;}
67 std::shared_ptr<FileCache> getFileCache();
69 void addUnitEmitter(std::unique_ptr<UnitEmitter> ue);
70 private:
72 std::unique_ptr<UnitEmitter> createSymlinkWrapper(
73 const std::string& full_path, const std::string& file_name,
74 std::unique_ptr<UnitEmitter> org_ue);
76 std::string m_root;
77 std::set<std::string> m_filesToParse;
79 void *m_dispatcher;
81 Mutex m_mutex;
82 AnalysisResultPtr m_ar;
83 int m_lineCount;
84 int m_charCount;
86 std::shared_ptr<FileCache> m_fileCache;
87 std::map<std::string,bool> m_directories;
88 std::set<std::string> m_staticDirectories;
89 std::set<std::string> m_extraStaticFiles;
90 std::map<std::string,std::string> m_discoveredStaticFiles;
91 folly::Optional<HHBBC::UnitEmitterQueue> m_ueq;
92 hphp_fast_set<std::string> m_locally_cached_bytecode;
95 ///////////////////////////////////////////////////////////////////////////////