souffle  2.0.2-371-g6315b36
UserDefinedFunctor.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2020 The Souffle Developers. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file UserDefinedFunctor.h
12  *
13  * Defines the user-defined functor class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Argument.h"
20 #include "ast/Functor.h"
21 #include "ast/Node.h"
22 #include "parser/SrcLocation.h"
23 #include "souffle/TypeAttribute.h"
26 #include <cassert>
27 #include <cstddef>
28 #include <optional>
29 #include <ostream>
30 #include <string>
31 #include <utility>
32 #include <vector>
33 
34 namespace souffle::ast {
35 
36 /**
37  * @class UserDefinedFunctor
38  * @brief User-Defined functor class
39  */
40 class UserDefinedFunctor : public Functor {
41 public:
42  explicit UserDefinedFunctor(std::string name) : Functor({}, {}), name(std::move(name)){};
43 
44  UserDefinedFunctor(std::string name, VecOwn<Argument> args, SrcLocation loc = {})
45  : Functor(std::move(args), std::move(loc)), name(std::move(name)){};
46 
47  /** return the name */
48  const std::string& getName() const {
49  return name;
50  }
51 
52  UserDefinedFunctor* clone() const override {
54  if (finalTranslatorReturnType.has_value()) {
55  res->setFinalReturnType(finalTranslatorReturnType.value());
56  }
57  return res;
58  }
59 
60  void setFinalReturnType(TypeAttribute newType) {
61  finalTranslatorReturnType = newType;
62  }
63 
64  std::optional<TypeAttribute> getFinalReturnType() const {
66  }
67 
68 protected:
69  void print(std::ostream& os) const override {
70  os << '@' << name << "(" << join(args) << ")";
71  }
72 
73  bool equal(const Node& node) const override {
74  const auto& other = static_cast<const UserDefinedFunctor&>(node);
75  return name == other.name && Functor::equal(node);
76  }
77 
78  /** Name */
79  const std::string name;
80 
81  // TODO (azreika): remove after refactoring translator
82  std::optional<TypeAttribute> finalTranslatorReturnType;
83 };
84 
85 } // namespace souffle::ast
souffle::ast::Term::args
VecOwn< Argument > args
Arguments.
Definition: Term.h:86
souffle::ast::UserDefinedFunctor::getName
const std::string & getName() const
return the name
Definition: UserDefinedFunctor.h:54
Functor.h
TypeAttribute
Type attribute class.
SrcLocation.h
souffle::ast::UserDefinedFunctor
User-Defined functor class.
Definition: UserDefinedFunctor.h:46
Argument.h
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
ContainerUtil.h
souffle::ast::UserDefinedFunctor::clone
UserDefinedFunctor * clone() const override
Create clone.
Definition: UserDefinedFunctor.h:58
souffle::join
detail::joined_sequence< Iter, Printer > join(const Iter &a, const Iter &b, const std::string &sep, const Printer &p)
Creates an object to be forwarded to some output stream for printing sequences of elements interspers...
Definition: StreamUtil.h:175
souffle::ast::UserDefinedFunctor::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: UserDefinedFunctor.h:75
souffle::ast::UserDefinedFunctor::equal
bool equal(const Node &node) const override
Abstract equality check for two AST nodes.
Definition: UserDefinedFunctor.h:79
Node.h
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
souffle::ast::UserDefinedFunctor::name
const std::string name
Name.
Definition: UserDefinedFunctor.h:85
souffle::ast::UserDefinedFunctor::UserDefinedFunctor
UserDefinedFunctor(std::string name)
Definition: UserDefinedFunctor.h:48
StreamUtil.h
souffle::ast::UserDefinedFunctor::getFinalReturnType
std::optional< TypeAttribute > getFinalReturnType() const
Definition: UserDefinedFunctor.h:70
souffle::ast::UserDefinedFunctor::finalTranslatorReturnType
std::optional< TypeAttribute > finalTranslatorReturnType
Definition: UserDefinedFunctor.h:88
souffle::ast::Node::getSrcLoc
const SrcLocation & getSrcLoc() const
Return source location of the Node.
Definition: Node.h:46
souffle::ast
Definition: Aggregator.h:35
souffle::ast::Term::equal
bool equal(const Node &node) const override
Abstract equality check for two AST nodes.
Definition: Term.h:80
souffle::ast::UserDefinedFunctor::setFinalReturnType
void setFinalReturnType(TypeAttribute newType)
Definition: UserDefinedFunctor.h:66
TypeAttribute.h