Give `NowTask` some teeth
[hiphop-php.git] / hphp / runtime / vm / as-base.cpp
blob02adfc9a8bf7b6219cbb2c0de5f2d2faf2053d01
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/runtime/vm/as-base.h"
18 #include "hphp/runtime/vm/as-base-hhas.h"
20 #if defined(FOLLY_PACKAGE_VERSION)
21 // This file is included in the hackc binary build where we can't easily include
22 // folly.
23 #error Folly not allowed in this source file.
24 #endif
26 namespace HPHP {
28 namespace {
29 std::string join_with_spaces(const std::vector<std::string> &input) {
30 size_t len = 0;
31 for (const auto& piece: input) {
32 len += piece.length() + 1;
35 std::string result;
36 result.reserve(len);
38 for (const auto& piece: input) {
39 if (!result.empty()) {
40 result.push_back(' ');
42 result.append(piece);
45 return result;
47 } // anonymous namespace
49 std::vector<std::string> attrs_to_vec(AttrContext ctx, Attr attrs) {
50 std::vector<std::string> vec;
52 #define X(attr, mask, str) \
53 if (supported(mask, ctx) && (attrs & attr)) vec.push_back(str);
54 HHAS_ATTRS
55 #undef X
57 return vec;
60 std::string attrs_to_string(AttrContext ctx, Attr attrs) {
61 return join_with_spaces(attrs_to_vec(ctx, attrs));
64 std::string type_flags_to_string(TypeConstraintFlags flags) {
65 std::vector<std::string> vec;
67 #define X(flag, str) \
68 if (contains(flags, TypeConstraintFlags::flag)) vec.push_back(str);
69 HHAS_TYPE_FLAGS
70 #undef X
72 return join_with_spaces(vec);
75 std::string fcall_flags_to_string(FCallArgsFlags flags) {
76 std::vector<std::string> vec;
78 #define X(flag, str) \
79 if (flags & FCallArgsFlags::flag) vec.push_back(str);
80 HHAS_FCALL_FLAGS
81 #undef X
83 return join_with_spaces(vec);
86 std::string iter_args_flags_to_string(IterArgsFlags flags) {
87 std::vector<std::string> vec;
89 #define X(flag, str) \
90 if (has_flag(flags, IterArgsFlags::flag)) vec.push_back(str);
91 HHAS_ITER_ARGS_FLAGS
92 #undef X
94 return join_with_spaces(vec);