-
Notifications
You must be signed in to change notification settings - Fork 139
/
FeatureMayAlwaysSet.h
100 lines (70 loc) · 2.61 KB
/
FeatureMayAlwaysSet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <initializer_list>
#include <ostream>
#include <json/json.h>
#include <sparta/AbstractDomain.h>
#include <sparta/PatriciaTreeOverUnderSetAbstractDomain.h>
#include <sparta/PatriciaTreeSet.h>
#include <mariana-trench/Feature.h>
#include <mariana-trench/FeatureSet.h>
#include <mariana-trench/IncludeMacros.h>
namespace marianatrench {
/**
* Represents the sets of may and always features.
* May-features are features that happen on at least one of the flows.
* Always-features are features that happen on all flows.
*/
class FeatureMayAlwaysSet final
: public sparta::AbstractDomain<FeatureMayAlwaysSet> {
private:
using OverUnderSet =
sparta::PatriciaTreeOverUnderSetAbstractDomain<const Feature*>;
private:
explicit FeatureMayAlwaysSet(OverUnderSet set) : set_(std::move(set)) {}
public:
/* Create the empty may-always feature set. */
FeatureMayAlwaysSet() = default;
/* Create the may-always feature set with the given always-features. */
explicit FeatureMayAlwaysSet(std::initializer_list<const Feature*> features);
FeatureMayAlwaysSet(const FeatureSet& may, const FeatureSet& always);
static FeatureMayAlwaysSet make_may(
std::initializer_list<const Feature*> features);
static FeatureMayAlwaysSet make_may(const FeatureSet& features);
static FeatureMayAlwaysSet make_always(
std::initializer_list<const Feature*> features);
static FeatureMayAlwaysSet make_always(const FeatureSet& features);
INCLUDE_DEFAULT_COPY_CONSTRUCTORS_AND_ASSIGNMENTS(FeatureMayAlwaysSet)
INCLUDE_ABSTRACT_DOMAIN_METHODS(FeatureMayAlwaysSet, OverUnderSet, set_)
/* Return true if this is neither top nor bottom. */
bool is_value() const {
return set_.is_value();
}
bool empty() const {
return set_.empty();
}
/* Return may-features, excluding always-features. */
FeatureSet may() const;
FeatureSet always() const;
void add_may(const Feature* feature);
void add_may(const FeatureSet& features);
void add_always(const Feature* feature);
void add_always(const FeatureSet& feature);
void add(const FeatureMayAlwaysSet& other);
static FeatureMayAlwaysSet from_json(
const Json::Value& value,
Context& context,
bool check_unexpected_members = true);
Json::Value to_json() const;
friend std::ostream& operator<<(
std::ostream& out,
const FeatureMayAlwaysSet& features);
private:
OverUnderSet set_;
};
} // namespace marianatrench