souffle
2.0.2-371-g6315b36
|
Go to the documentation of this file.
62 #include <type_traits>
69 struct ast_visitor_tag {};
80 template <
typename R = void,
typename... Params>
98 virtual R
visit(
const Node& node, Params... args) {
101 #define FORWARD(Kind) \
102 if (const auto* n = dynamic_cast<const Kind*>(&node)) return visit##Kind(*n, args...);
148 fatal(
"unsupported type: %s",
typeid(node).name());
152 #define LINK(Node, Parent) \
153 virtual R visit##Node(const Node& n, Params... args) { \
154 return visit##Parent(n, args...); \
159 LINK(RecordType, Type);
160 LINK(AlgebraicDataType, Type);
161 LINK(UnionType, Type);
165 LINK(Variable, Argument)
166 LINK(UnnamedVariable, Argument)
167 LINK(Counter, Argument)
168 LINK(TypeCast, Argument)
169 LINK(SubroutineArgument, Argument)
170 LINK(BranchInit, Argument)
172 LINK(NumericConstant, Constant)
173 LINK(StringConstant, Constant)
174 LINK(NilConstant, Constant)
175 LINK(Constant, Argument)
177 LINK(IntrinsicFunctor, Functor)
178 LINK(UserDefinedFunctor, Functor)
180 LINK(RecordInit, Term)
185 LINK(Aggregator, Argument)
187 LINK(Argument, Node);
191 LINK(ProvenanceNegation, Negation)
192 LINK(Negation, Literal)
195 LINK(BooleanConstraint, Constraint)
196 LINK(BinaryConstraint, Constraint)
197 LINK(Constraint, Literal)
200 LINK(ComponentType, Node);
201 LINK(ComponentInit, Node);
202 LINK(Component, Node);
206 LINK(Attribute, Node);
208 LINK(Relation, Node);
214 virtual R
visitNode(
const Node& , Params... ) {
228 template <
typename R,
typename... Ps,
typename... Args>
230 visitor(root, args...);
232 if (cur !=
nullptr) {
247 template <
typename R,
typename... Ps,
typename... Args>
249 for (
const Node* cur : root.getChildNodes()) {
250 if (cur !=
nullptr) {
254 visitor(root, args...);
266 template <
typename R,
typename... Ps,
typename... Args>
267 void visitDepthFirst(
const Node& root, Visitor<R, Ps...>& visitor, Args&... args) {
277 template <
typename R,
typename N>
278 struct LambdaVisitor :
public Visitor<void> {
279 std::function<R(
const N&)>
lambda;
282 if (
const auto*
n =
dynamic_cast<const N*
>(&node)) {
291 template <
typename R,
typename N>
299 template <
typename T>
301 static constexpr
size_t value = std::is_base_of<ast_visitor_tag, T>::value;
304 template <
typename T>
305 struct is_ast_visitor<const T> :
public is_ast_visitor<T> {};
307 template <
typename T>
320 template <
typename R,
typename N>
323 visitDepthFirst<void>(root, visitor);
335 template <typename Lambda, typename R = typename lambda_traits<Lambda>::result_type,
338 const Node& root,
const Lambda& fun) {
351 template <
typename T,
typename Lambda>
353 for (
const auto& cur : list) {
367 template <
typename T,
typename Lambda>
369 for (
const auto& cur : list) {
383 template <
typename R,
typename N>
386 visitDepthFirstPostOrder<void>(root, visitor);
398 template <typename Lambda, typename R = typename lambda_traits<Lambda>::result_type,
401 const Node& root,
const Lambda& fun) {
The generic base type of all AstVisitors realizing the dispatching of visitor calls.
Boolean constraint class.
void visitDepthFirstPostOrder(const Node &root, Visitor< R, Ps... > &visitor, Args &... args)
A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-...
LambdaVisitor(std::function< R(const N &)> lambda)
A type trait enabling the deduction of type properties of lambdas.
LambdaVisitor< R, N > makeLambdaVisitor(const std::function< R(const N &)> &fun)
A factory function for creating LambdaVisitor instances.
A specialized visitor wrapping a lambda function – an auxiliary type required for visitor convenience...
Component initialization class.
Defines the nil constant.
Defines a relation with a name, attributes, qualifiers, and internal representation.
Intermediate representation of a horn clause.
A type being a subset of another type.
A union type combining a list of types into a new, aggregated type.
Defines the argument class for subrountines.
virtual R visitNode(const Node &, Params...)
The base case for all visitors – if no more specific overload was defined.
User-Defined functor class.
A variable to be utilized within constraints to be handled by the constraint solver.
virtual std::vector< const Node * > getChildNodes() const
Obtain list of all embedded child nodes.
counter functor (incrementing a value after each invocation)
A record type combining a list of fields into a new, aggregated type.
Component type of a component.
A tag type required for the is_ast_visitor type trait to identify AstVisitors.
The program class consists of relations, clauses and types.
Node is a superclass for all RAM IR classes.
Representation of a global option.
virtual R visit(const Node &node, Params... args)
The main entry for a visit process conducting the dispatching of a visit to the various sub-types of ...
Subclass of Literal that represents a negated atom, * e.g., !parent(x,y).
std::function< R(const N &)> lambda
R operator()(const Node &node, Params... args)
The main entry for the user allowing visitors to be utilized as functions.
Defines a type cast class for expressions.
Negation of an atom negated atom.
Intrinsic Functor class for functors are in-built.
void visitDepthFirstPreOrder(const Node &root, Visitor< R, Ps... > &visitor, Args &... args)
A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-...
void visit(const Node &node) override
Abstract class for syntactic elements in an input program.
Defines the aggregator class.
void fatal(const char *format, const Args &... args)
A type trait determining whether a given type is a visitor or not.
Initialization of ADT instance.
void visitDepthFirst(const Node &root, Visitor< R, Ps... > &visitor, Args &... args)
A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-...
static constexpr size_t value
std::vector< Own< A > > VecOwn
Combination of types using sums and products.
Defines a record initialization class.
virtual ~Visitor()=default
A virtual destructor.