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 +----------------------------------------------------------------------+
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 //////////////////////////////////////////////////////////////////////
29 bool method_map_contains(const MethodMap
& mmap
,
34 if (auto const m
= folly::get_ptr(mmap
, unit
->toCppString())) {
39 if (auto const m
= folly::get_ptr(mmap
, cls
->toCppString())) {
40 if (m
->empty()) return true;
41 return func
&& m
->count(func
->toCppString());
46 if (auto const m
= folly::get_ptr(mmap
, func
->toCppString())) {
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
;
66 return is_trace_function(cls
? cls
->name
: nullptr,
67 func
? func
->name
: nullptr,
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
;
78 return is_trace_function(ctx
.cls
? ctx
.cls
->name
: nullptr,
79 ctx
.func
? ctx
.func
->name
: nullptr,
83 bool is_trace_function(SString cls
,
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
;
98 return trace_bump_for(cls
? cls
->name
: nullptr,
99 func
? func
->name
: nullptr,
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
;
110 return trace_bump_for(ctx
.cls
? ctx
.cls
->name
: nullptr,
111 ctx
.func
? ctx
.func
->name
: nullptr,
115 int trace_bump_for(SString cls
,
118 return is_trace_function(cls
, func
, unit
) ? kTraceFuncBump
:
119 ((unit
&& is_systemlib_part(unit
)) ? kSystemLibBump
: 0);
122 //////////////////////////////////////////////////////////////////////