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 +----------------------------------------------------------------------+
16 #include "hphp/runtime/vm/as-shared.h"
18 #include <folly/gen/Base.h>
19 #include <folly/gen/String.h>
25 //////////////////////////////////////////////////////////////////////
29 using ContextMask
= uint32_t;
31 constexpr auto C
= static_cast<ContextMask
>(AttrContext::Class
);
32 constexpr auto F
= static_cast<ContextMask
>(AttrContext::Func
);
33 constexpr auto P
= static_cast<ContextMask
>(AttrContext::Prop
);
34 constexpr auto T
= static_cast<ContextMask
>(AttrContext::TraitImport
);
36 constexpr bool supported(ContextMask mask
, AttrContext a
) {
37 return mask
& static_cast<ContextMask
>(a
);
41 X(AttrPublic, F|P|T, "public"); \
42 X(AttrProtected, F|P|T, "protected"); \
43 X(AttrPrivate, F|P|T, "private"); \
44 X(AttrStatic, F|P, "static"); \
45 X(AttrInterface, C, "interface"); \
46 X(AttrNoExpandTrait, C, "no_expand_trait"); \
47 X(AttrAbstract, C|F|T, "abstract"); \
48 X(AttrNoOverride, C|F|T, "no_override"); \
49 X(AttrFinal, C|F|T, "final"); \
50 X(AttrTrait, C|F, "trait"); \
51 X(AttrUnique, C|F, "unique"); \
52 X(AttrBuiltin, C|F, "builtin"); \
53 X(AttrNoOverrideMagicGet, C, "nov_get"); \
54 X(AttrNoOverrideMagicSet, C, "nov_set"); \
55 X(AttrNoOverrideMagicIsset, C, "nov_isset"); \
56 X(AttrNoOverrideMagicUnset, C, "nov_unset");
60 //////////////////////////////////////////////////////////////////////
62 std::string
attrs_to_string(AttrContext ctx
, Attr attrs
) {
63 std::vector
<std::string
> vec
;
65 #define X(attr, mask, str) \
66 if (supported(mask, ctx) && (attrs & attr)) vec.push_back(str);
70 using namespace folly::gen
;
71 return from(vec
) | unsplit
<std::string
>(" ");
74 folly::Optional
<Attr
> string_to_attr(AttrContext ctx
,
75 const std::string
& name
) {
76 #define X(attr, mask, str) \
77 if (supported(mask, ctx) && name == str) return attr;
84 //////////////////////////////////////////////////////////////////////