Deshim VirtualExecutor in folly
[hiphop-php.git] / hphp / hhbbc / options-util.cpp
blobc4d799458ac9b6f5a6f23dab9b667743dfeaed5c
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 +----------------------------------------------------------------------+
16 #include "hphp/hhbbc/options-util.h"
18 #include "hphp/hhbbc/context.h"
19 #include "hphp/hhbbc/options.h"
20 #include "hphp/hhbbc/representation.h"
21 #include "hphp/hhbbc/unit-util.h"
23 namespace HPHP::HHBBC {
25 //////////////////////////////////////////////////////////////////////
27 namespace {
29 bool method_map_contains(const MethodMap& mmap,
30 SString cls,
31 SString func,
32 SString unit) {
33 if (unit) {
34 if (auto const m = folly::get_ptr(mmap, unit->toCppString())) {
35 return m->empty();
38 if (cls) {
39 if (auto const m = folly::get_ptr(mmap, cls->toCppString())) {
40 if (m->empty()) return true;
41 return func && m->count(func->toCppString());
43 return false;
45 if (func) {
46 if (auto const m = folly::get_ptr(mmap, func->toCppString())) {
47 return m->empty();
50 return false;
55 //////////////////////////////////////////////////////////////////////
57 bool is_trace_function(const php::Class* cls,
58 const php::Func* func,
59 const php::Unit* inUnit) {
60 auto const unit = [&] () -> SString {
61 if (inUnit) return inUnit->filename;
62 if (cls) return cls->unit;
63 if (func) return func->unit;
64 return nullptr;
65 }();
66 return is_trace_function(cls ? cls->name : nullptr,
67 func ? func->name : nullptr,
68 unit);
71 bool is_trace_function(const Context& ctx) {
72 auto const unit = [&] () -> SString {
73 if (ctx.unit) return ctx.unit;
74 if (ctx.cls) return ctx.cls->unit;
75 if (ctx.func) return ctx.func->unit;
76 return nullptr;
77 }();
78 return is_trace_function(ctx.cls ? ctx.cls->name : nullptr,
79 ctx.func ? ctx.func->name : nullptr,
80 unit);
83 bool is_trace_function(SString cls,
84 SString func,
85 SString unit) {
86 return method_map_contains(options.TraceFunctions, cls, func, unit);
89 int trace_bump_for(const php::Class* cls,
90 const php::Func* func,
91 const php::Unit* inUnit) {
92 auto const unit = [&] () -> SString {
93 if (inUnit) return inUnit->filename;
94 if (cls) return cls->unit;
95 if (func) return func->unit;
96 return nullptr;
97 }();
98 return trace_bump_for(cls ? cls->name : nullptr,
99 func ? func->name : nullptr,
100 unit);
103 int trace_bump_for(const Context& ctx) {
104 auto const unit = [&] () -> SString {
105 if (ctx.unit) return ctx.unit;
106 if (ctx.cls) return ctx.cls->unit;
107 if (ctx.func) return ctx.func->unit;
108 return nullptr;
109 }();
110 return trace_bump_for(ctx.cls ? ctx.cls->name : nullptr,
111 ctx.func ? ctx.func->name : nullptr,
112 unit);
115 int trace_bump_for(SString cls,
116 SString func,
117 SString unit) {
118 return is_trace_function(cls, func, unit) ? kTraceFuncBump :
119 ((unit && is_systemlib_part(unit)) ? kSystemLibBump : 0);
122 //////////////////////////////////////////////////////////////////////