add bitset operations and tests
[hiphop-php.git] / hphp / runtime / vm / srckey.cpp
blobee1bd5c556f596301247c587a4602759335ebebf
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 #include "hphp/runtime/vm/srckey.h"
19 #include <folly/Format.h>
21 #include "hphp/runtime/vm/hhbc.h"
23 namespace HPHP {
25 std::string SrcKey::showInst() const {
26 auto const u = unit();
27 return instrToString(u->at(offset()), u);
30 std::string show(SrcKey sk) {
31 auto func = sk.func();
32 auto unit = sk.unit();
33 const char *filepath = "*anonFile*";
34 if (unit->filepath()->data() && unit->filepath()->size()) {
35 filepath = unit->filepath()->data();
37 return folly::sformat("{}:{} in {}(id 0x{:#x})@{: >6}{}{}",
38 filepath, unit->getLineNumber(sk.offset()),
39 func->isPseudoMain() ? "pseudoMain"
40 : func->fullName()->data(),
41 (uint32_t)sk.funcID(), sk.offset(),
42 sk.resumed() ? "r" : "",
43 sk.hasThis() ? "t" : "",
44 sk.prologue() ? "p" : "");
47 std::string showShort(SrcKey sk) {
48 if (!sk.valid()) return "<invalid SrcKey>";
49 return folly::sformat(
50 "{}(id {:#x})@{}{}{}{}",
51 sk.func()->fullName(),
52 sk.funcID(),
53 sk.offset(),
54 sk.resumed() ? "r" : "",
55 sk.hasThis() ? "t" : "",
56 sk.prologue() ? "p" : ""
60 void sktrace(SrcKey sk, const char *fmt, ...) {
61 if (!Trace::enabled) return;
63 auto const u = sk.unit();
64 auto inst = instrToString(u->at(sk.offset()), u);
65 Trace::trace("%s: %20s ", show(sk).c_str(), inst.c_str());
66 va_list a;
67 va_start(a, fmt);
68 Trace::vtrace(fmt, a);
69 va_end(a);
72 std::string SrcKey::getSymbol() const {
73 const Func* f = func();
74 const Unit* u = unit();
76 if (f->isBuiltin()) {
77 return f->fullName()->data();
80 if (f->isPseudoMain()) {
81 return folly::format(
82 "{{pseudo-main}}::{}::line-{}",
83 u->filepath(),
84 u->getLineNumber(offset())
85 ).str();
88 if (f->isMethod() && !f->cls()) {
89 return folly::format(
90 "{}::{}::line-{}",
91 f->preClass()->name(),
92 f->name(),
93 u->getLineNumber(offset())
94 ).str();
97 // methods with a cls() and functions
98 return folly::format(
99 "{}::line-{}",
100 f->fullName(),
101 u->getLineNumber(offset())
102 ).str();