2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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_OPTION_H_
18 #define incl_HPHP_OPTION_H_
20 #include "hphp/util/hdf.h"
24 #include "hphp/util/string-bag.h"
25 #include "hphp/util/deprecated/base.h"
26 #include "hphp/util/deprecated/declare-boost-types.h"
29 ///////////////////////////////////////////////////////////////////////////////
30 DECLARE_BOOST_TYPES(BlockScope
);
31 DECLARE_BOOST_TYPES(FileScope
);
37 * Load options from different sources.
39 static void Load(Hdf
&config
);
40 static void Load(); // load default options
43 * Directories to add to a package.
45 static std::string RootDirectory
;
46 static std::set
<std::string
> PackageDirectories
;
49 * Files to add to a package.
51 static std::set
<std::string
> PackageFiles
;
54 * File path patterns for excluding files from a package scan of programs.
56 static std::set
<std::string
> PackageExcludeDirs
;
57 static std::set
<std::string
> PackageExcludeFiles
;
58 static std::set
<std::string
> PackageExcludePatterns
;
59 static std::set
<std::string
> PackageExcludeStaticFiles
;
60 static std::set
<std::string
> PackageExcludeStaticDirs
;
61 static std::set
<std::string
> PackageExcludeStaticPatterns
;
63 static bool IsFileExcluded(const std::string
&file
,
64 const std::set
<std::string
> &patterns
);
65 static void FilterFiles(std::vector
<std::string
> &files
,
66 const std::set
<std::string
> &patterns
);
69 * Directories in which files are parsed on-demand, when parse-on-demand
72 static std::vector
<std::string
> ParseOnDemandDirs
;
75 * Whether to store PHP source files in static file cache.
77 static bool CachePHPFile
;
80 * Legal root directory expressions in an include expression. For example,
82 * include_once $PHP_ROOT . '/lib.php';
84 * Here, "$PHP_ROOT" is a legal include root. Stores what it resolves to.
86 * Option::IncludeRoots["$PHP_ROOT"] = "";
87 * Option::IncludeRoots["$LIB_ROOT"] = "lib";
89 static std::map
<std::string
, std::string
> IncludeRoots
;
90 static std::map
<std::string
, std::string
> AutoloadRoots
;
91 static std::vector
<std::string
> IncludeSearchPaths
;
94 * PHP include root expression to use when generating PHP trimmed code.
96 static std::string DefaultIncludeRoot
;
99 * PHP functions that will take a function name and make a dynamic call.
101 static std::map
<std::string
, int> DynamicFunctionCalls
;
106 static bool PreOptimization
;
107 static bool PostOptimization
;
108 static bool AnalyzePerfectVirtuals
;
109 static bool HardTypeHints
;
112 * Flags that only affect HHBBC right now. See hhbbc/hhbbc.h for
115 static bool HardConstProp
;
118 * Separate compilation
120 static bool SeparateCompilation
;
121 static bool SeparateCompLib
;
124 * CodeGenerator options for PHP.
126 static bool GeneratePickledPHP
;
127 static bool GenerateInlinedPHP
;
128 static bool GenerateTrimmedPHP
;
129 static bool GenerateInferredTypes
; // comments on constant/variable tables
130 static bool ConvertSuperGlobals
; // $GLOBALS['var'] => global $var
131 static bool ConvertQOpExpressions
; // $var = $exp ? $yes : $no => if-else
132 static std::string ProgramPrologue
;
133 static std::string TrimmedPrologue
;
134 static std::vector
<std::string
> DynamicFunctionPrefixes
;
135 static std::vector
<std::string
> DynamicFunctionPostfixes
;
136 static std::vector
<std::string
> DynamicMethodPrefixes
;
137 static std::vector
<std::string
> DynamicMethodPostfixes
;
138 static std::vector
<std::string
> DynamicClassPrefixes
;
139 static std::vector
<std::string
> DynamicClassPostfixes
;
140 static std::set
<std::string
, stdltistr
> DynamicInvokeFunctions
;
141 static std::set
<std::string
> VolatileClasses
;
142 static std::map
<std::string
,std::string
> AutoloadClassMap
;
143 static std::map
<std::string
,std::string
> AutoloadFuncMap
;
144 static std::map
<std::string
,std::string
> AutoloadConstMap
;
145 static std::string AutoloadRoot
;
148 * CodeGenerator options for HHBC.
150 static bool GenerateTextHHBC
;
151 static bool GenerateBinaryHHBC
;
152 static std::string RepoCentralPath
;
153 static bool RepoDebugInfo
;
156 * Names of hot and cold functions to be marked in sources.
158 static std::map
<std::string
, std::string
> FunctionSections
;
161 * A somewhat unique prefix for system identifiers.
163 static std::string IdPrefix
;
164 static std::string LambdaPrefix
;
165 static std::string Tab
;
168 * Name resolution helpers.
170 static const char *UserFilePrefix
;
173 * Turn it off for cleaner unit tests.
175 static bool KeepStatementsWithNoEffect
;
178 * When we have an include inside a function or a method, how many levels
179 * do we expand? If 0, we rely on "require" vs. "include" to give explicit
180 * instructions. If 1, we only inline just one level, and all deeper
181 * includes are considered as libraries, and they will be moved to top
182 * level. If -1, we completely disable conditional include handling.
184 static int ConditionalIncludeExpandLevel
;
187 * Maximum number of examplar programs to store in each output.
189 static int DependencyMaxProgram
;
190 static int CodeErrorMaxProgram
;
193 * Whether or not name matches dynamic function/class prefx/postfix lists.
195 static bool IsDynamicFunction(bool method
, const std::string
&name
);
196 static bool IsDynamicClass(const std::string
&name
);
199 * Whether or not name matches AUTOLOAD files. If not, returns empty. If
200 * yes, returns root directory for the file.
202 static std::string
GetAutoloadRoot(const std::string
&name
);
205 * Turning a file name into an identifier. When id is false, preserve
208 static std::string
MangleFilename(const std::string
&name
, bool id
);
211 NoEval
= 0, // calling eval is a fatal
212 LimitedEval
= 1, // eval is supported in a limited way with no perf hit
213 FullEval
= 2 // eval is supported but with a performance hit
216 static EvalLevel EnableEval
;
218 static std::string ProgramName
;
220 static bool ParseTimeOpts
;
221 static bool OutputHHBC
;
222 static bool EnableHipHopSyntax
;
223 static bool EnableZendCompat
;
224 static bool JitEnableRenameFunction
;
225 static bool EnableHipHopExperimentalSyntax
;
226 static bool EnableShortTags
;
227 static bool EnableAspTags
;
228 static bool EnableXHP
;
229 static bool IntsOverflowToInts
;
230 static int ParserThreadCount
;
232 static int GetScannerType();
235 * "Dynamic" means a function or a method can be invoked dynamically.
236 * "Volatile" means a class or a function can be declared dynamically.
238 static bool AllDynamic
;
239 static bool AllVolatile
;
244 static int InvokeFewArgsCount
;
245 static int InlineFunctionThreshold
;
246 static bool EliminateDeadCode
;
247 static bool CopyProp
;
248 static bool LocalCopyProp
;
249 static bool StringLoopOpts
;
250 static int AutoInline
;
251 static bool ArrayAccessIdempotent
;
256 static bool GenerateDocComments
;
257 static bool ControlFlow
;
258 static bool VariableCoalescing
;
260 static bool WholeProgram
;
261 static bool UseHHBBC
; // see hhbbc/README
262 static bool RecordErrors
;
263 static std::string DocJson
; // filename to dump doc JSON to
265 static bool (*PersistenceHook
)(BlockScopeRawPtr scope
, FileScopeRawPtr fs
);
267 static StringBag OptionStrings
;
269 static void LoadRootHdf(const Hdf
&roots
, std::map
<std::string
,
271 static void LoadRootHdf(const Hdf
&roots
, std::vector
<std::string
> &vec
);
272 static void OnLoad();
274 static bool IsDynamic(const std::string
&name
,
275 const std::vector
<std::string
> &prefixes
,
276 const std::vector
<std::string
> &postfixes
);
279 //////////////////////////////////////////////////////////////////////
282 * Hook called after Option is set up to propagate various options to
283 * HHBBC's option structure.
285 * This exists this way because we don't want to have libhhbbc depend
286 * on all of libhphp_analysis---the dependency goes the other way.
288 void initialize_hhbbc_options();
290 ///////////////////////////////////////////////////////////////////////////////
292 #endif // incl_HPHP_OPTION_H_