souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions | Protected Attributes
souffle::ast::FunctorDeclaration Class Reference

User-defined functor declaration. More...

#include <FunctorDeclaration.h>

Inheritance diagram for souffle::ast::FunctorDeclaration:
Inheritance graph
Collaboration diagram for souffle::ast::FunctorDeclaration:
Collaboration graph

Public Member Functions

FunctorDeclarationclone () const override
 Create a clone (i.e. More...
 
 FunctorDeclaration (std::string name, std::vector< TypeAttribute > argsTypes, TypeAttribute returnType, bool stateful, SrcLocation loc={})
 
const std::vector< TypeAttribute > & getArgsTypes () const
 Return type. More...
 
size_t getArity () const
 Return number of arguments. More...
 
const std::string & getName () const
 Return name. More...
 
TypeAttribute getReturnType () const
 Get return type. More...
 
bool isStateful () const
 Check whether functor is stateful. More...
 
- Public Member Functions inherited from souffle::ast::Node
virtual void apply (const NodeMapper &)
 Apply the mapper to all child nodes. More...
 
std::string extloc () const
 Return source location of the syntactic element. More...
 
virtual std::vector< const Node * > getChildNodes () const
 Obtain a list of all embedded AST child nodes. More...
 
const SrcLocationgetSrcLoc () const
 Return source location of the Node. More...
 
 Node (SrcLocation loc={})
 
bool operator!= (const Node &other) const
 Inequality check for two AST nodes. More...
 
bool operator== (const Node &other) const
 Equivalence check for two AST nodes. More...
 
void setSrcLoc (SrcLocation l)
 Set source location for the Node. More...
 
virtual ~Node ()=default
 

Protected Member Functions

bool equal (const Node &node) const override
 Abstract equality check for two AST nodes. More...
 
void print (std::ostream &out) const override
 Output to a given output stream. More...
 

Protected Attributes

const std::vector< TypeAttributeargsTypes
 Types of arguments. More...
 
const std::string name
 Name of functor. More...
 
const TypeAttribute returnType
 Type of the return value. More...
 
const bool stateful
 Stateful flag. More...
 

Detailed Description

User-defined functor declaration.

Example: .declfun foo(x:number, y:number):number

Definition at line 49 of file FunctorDeclaration.h.

Constructor & Destructor Documentation

◆ FunctorDeclaration()

souffle::ast::FunctorDeclaration::FunctorDeclaration ( std::string  name,
std::vector< TypeAttribute argsTypes,
TypeAttribute  returnType,
bool  stateful,
SrcLocation  loc = {} 
)
inline

Definition at line 51 of file FunctorDeclaration.h.

53  {
54  return name;
55  }
56 

References name.

Member Function Documentation

◆ clone()

FunctorDeclaration* souffle::ast::FunctorDeclaration::clone ( ) const
inlineoverridevirtual

Create a clone (i.e.

deep copy) of this node

Implements souffle::ast::Node.

Definition at line 83 of file FunctorDeclaration.h.

83  {
84  switch (type) {
85  case TypeAttribute::Signed: return "number";

References souffle::Float, souffle::Signed, and souffle::Symbol.

◆ equal()

bool souffle::ast::FunctorDeclaration::equal ( const Node ) const
inlineoverrideprotectedvirtual

Abstract equality check for two AST nodes.

Reimplemented from souffle::ast::Node.

Definition at line 109 of file FunctorDeclaration.h.

◆ getArgsTypes()

const std::vector<TypeAttribute>& souffle::ast::FunctorDeclaration::getArgsTypes ( ) const
inline

Return type.

Definition at line 64 of file FunctorDeclaration.h.

68  {

◆ getArity()

size_t souffle::ast::FunctorDeclaration::getArity ( ) const
inline

Return number of arguments.

Definition at line 74 of file FunctorDeclaration.h.

77  {

◆ getName()

const std::string& souffle::ast::FunctorDeclaration::getName ( ) const
inline

Return name.

Definition at line 59 of file FunctorDeclaration.h.

63  {

Referenced by souffle::ast::analysis::TypeAnalysis::run().

◆ getReturnType()

TypeAttribute souffle::ast::FunctorDeclaration::getReturnType ( ) const
inline

Get return type.

Definition at line 69 of file FunctorDeclaration.h.

73  {

◆ isStateful()

bool souffle::ast::FunctorDeclaration::isStateful ( ) const
inline

Check whether functor is stateful.

Definition at line 79 of file FunctorDeclaration.h.

81  :
82  void print(std::ostream& out) const override {

◆ print()

void souffle::ast::FunctorDeclaration::print ( std::ostream &  os) const
inlineoverrideprotectedvirtual

Output to a given output stream.

Implements souffle::ast::Node.

Definition at line 88 of file FunctorDeclaration.h.

88  : return "unsigned";
89  case TypeAttribute::Record: break;
90  case TypeAttribute::ADT: break;
91  }
92  fatal("unhandled `TypeAttribute`");
93  };
94 
96  out, ".declfun %s(%s): %s", name, join(map(argsTypes, convert), ","), convert(returnType));
97  if (stateful) {
98  out << " stateful";
99  }
100  out << std::endl;
101  }
102 
103  bool equal(const Node& node) const override {
104  const auto& other = static_cast<const FunctorDeclaration&>(node);
105  return name == other.name && argsTypes == other.argsTypes && returnType == other.returnType &&
106  stateful == other.stateful;
107  }

Field Documentation

◆ argsTypes

const std::vector<TypeAttribute> souffle::ast::FunctorDeclaration::argsTypes
protected

Types of arguments.

Definition at line 119 of file FunctorDeclaration.h.

◆ name

const std::string souffle::ast::FunctorDeclaration::name
protected

Name of functor.

Definition at line 116 of file FunctorDeclaration.h.

Referenced by FunctorDeclaration().

◆ returnType

const TypeAttribute souffle::ast::FunctorDeclaration::returnType
protected

Type of the return value.

Definition at line 122 of file FunctorDeclaration.h.

◆ stateful

const bool souffle::ast::FunctorDeclaration::stateful
protected

Stateful flag.

Definition at line 125 of file FunctorDeclaration.h.


The documentation for this class was generated from the following file:
souffle::TypeAttribute::Record
@ Record
tinyformat::format
void format(std::ostream &out, const char *fmt)
Definition: tinyformat.h:1089
souffle::ast::FunctorDeclaration::name
const std::string name
Name of functor.
Definition: FunctorDeclaration.h:116
souffle::map
auto map(const std::vector< A > &xs, F &&f)
Applies a function to each element of a vector and returns the results.
Definition: ContainerUtil.h:158
souffle::TypeAttribute::Signed
@ Signed
souffle::ast::FunctorDeclaration::argsTypes
const std::vector< TypeAttribute > argsTypes
Types of arguments.
Definition: FunctorDeclaration.h:119
souffle::ast::FunctorDeclaration::equal
bool equal(const Node &node) const override
Abstract equality check for two AST nodes.
Definition: FunctorDeclaration.h:109
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::FunctorDeclaration::FunctorDeclaration
FunctorDeclaration(std::string name, std::vector< TypeAttribute > argsTypes, TypeAttribute returnType, bool stateful, SrcLocation loc={})
Definition: FunctorDeclaration.h:51
souffle::TypeAttribute::ADT
@ ADT
souffle::ast::FunctorDeclaration::print
void print(std::ostream &out) const override
Output to a given output stream.
Definition: FunctorDeclaration.h:88
souffle::ast::FunctorDeclaration::returnType
const TypeAttribute returnType
Type of the return value.
Definition: FunctorDeclaration.h:122
souffle::fatal
void fatal(const char *format, const Args &... args)
Definition: MiscUtil.h:198
souffle::ast::FunctorDeclaration::stateful
const bool stateful
Stateful flag.
Definition: FunctorDeclaration.h:125
souffle::ast::Node::Node
Node(SrcLocation loc={})
Definition: Node.h:42
std::type
ElementType type
Definition: span.h:640