souffle
2.0.2-371-g6315b36
FunctorOps.h
Go to the documentation of this file.
1
/*
2
* Souffle - A Datalog Compiler
3
* Copyright (c) 2019, 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 FunctorOps.h
12
*
13
* Defines intrinsic functor operators for AST and RAM
14
*
15
***********************************************************************/
16
17
#pragma once
18
19
#include "
souffle/TypeAttribute.h
"
20
#include <cstdlib>
21
#include <functional>
22
#include <iosfwd>
23
#include <string>
24
#include <string_view>
25
#include <vector>
26
27
namespace
souffle
{
28
29
enum class
FunctorOp
{
30
/** Unary Functor Operators */
31
ORD
,
// ordinal number of a string
32
STRLEN
,
// length of a string
33
NEG
,
// Signed numeric negation
34
FNEG
,
// Float numeric negation
35
BNOT
,
// Signed bitwise negation
36
UBNOT
,
// Unsigned bitwise negation
37
LNOT
,
// Signed logical negation
38
ULNOT
,
// Unsigned logical negation
39
40
F2I
,
// float to signed
41
F2S
,
// float to symbol
42
F2U
,
// float to unsigned
43
I2F
,
// signed to signed
44
I2S
,
// signed to symbol (overload base case)
45
I2U
,
// signed to unsigned
46
S2F
,
// symbol to float (overload base case)
47
S2I
,
// symbol to signed (overload base case)
48
S2U
,
// symbol to unsigned (overload base case)
49
U2F
,
// unsigned to float
50
U2I
,
// unsigned to signed
51
U2S
,
// unsigned to symbol
52
53
/** Binary Functor Operators */
54
ADD
,
// addition
55
SUB
,
// subtraction
56
MUL
,
// multiplication
57
DIV
,
// division
58
EXP
,
// exponent
59
MAX
,
// max of two numbers
60
MIN
,
// min of two numbers
61
MOD
,
// modulus
62
BAND
,
// bitwise and
63
BOR
,
// bitwise or
64
BXOR
,
// bitwise exclusive or
65
BSHIFT_L
,
// bitwise shift left
66
BSHIFT_R
,
// bitwise shift right
67
BSHIFT_R_UNSIGNED
,
// bitwise shift right (unsigned)
68
LAND
,
// logical and
69
LOR
,
// logical or
70
LXOR
,
// logical xor
71
UADD
,
// addition
72
USUB
,
// subtraction
73
UMUL
,
// multiplication
74
UDIV
,
// division
75
UEXP
,
// exponent
76
UMAX
,
// max of two numbers
77
UMIN
,
// min of two numbers
78
UMOD
,
// modulus
79
UBAND
,
// bitwise and
80
UBOR
,
// bitwise or
81
UBXOR
,
// bitwise exclusive or
82
UBSHIFT_L
,
// bitwise shift right
83
UBSHIFT_R
,
// bitwise shift right
84
UBSHIFT_R_UNSIGNED
,
// bitwise shift right (unsigned)
85
ULAND
,
// logical and
86
ULOR
,
// logical or
87
ULXOR
,
// logical xor
88
FADD
,
// addition
89
FSUB
,
// subtraction
90
FMUL
,
// multiplication
91
FDIV
,
// division
92
FEXP
,
// exponent
93
FMAX
,
// max of two floats
94
FMIN
,
// min of two floats
95
SMAX
,
// max of two symbols
96
SMIN
,
// min of two symbols
97
98
// Produces values within a numeric range. Format is `range(bgn, endExcl, step = 1)`.
99
// e.g. `range(0, 5)` produces the sequence `0, 1, 2, 3, 4`.
100
// `range(5, 3.75, -0.5)` produces the sequence `5, 4.5, 4`.
101
// `range(5, x, 0)` produces the sequence `5` iff `x` != 5.
102
RANGE
,
103
URANGE
,
104
FRANGE
,
105
106
CAT
,
// string concatenation
107
108
/** Ternary Functor Operators */
109
SUBSTR
,
// substring
110
};
111
112
std::ostream&
operator<<
(std::ostream& os,
FunctorOp
op);
113
114
struct
IntrinsicFunctorInfo {
115
std::string
symbol
;
116
std::vector<TypeAttribute>
params
;
117
TypeAttribute
result
;
118
FunctorOp
op
;
119
bool
variadic
=
false
;
// varadic => params.size() == 1
120
bool
multipleResults
=
false
;
121
};
122
123
using
IntrinsicFunctors
= std::vector<std::reference_wrapper<const IntrinsicFunctorInfo>>;
124
IntrinsicFunctors
functorBuiltIn
(
FunctorOp
);
125
IntrinsicFunctors
functorBuiltIn
(std::string_view symbol);
126
IntrinsicFunctors
functorBuiltIn
(std::string_view symbol,
const
std::vector<TypeAttribute>& params);
127
128
// Checks whether a functor operation can have a given argument count.
129
bool
isValidFunctorOpArity
(std::string_view symbol,
size_t
arity);
130
131
/**
132
* Indicate whether a functor is overloaded.
133
* At the moment, the signed versions are treated as representatives (because parser always returns a signed
134
* version).
135
*/
136
bool
isOverloadedFunctor
(std::string_view symbol);
137
138
// Prefix negation operator is a special case. There are no other unary symbolic
139
// operators. Internally we name it `negate`, but when pretty printing we want
140
// to special case this and emit `-`.
141
constexpr
char
FUNCTOR_INTRINSIC_PREFIX_NEGATE_NAME
[] =
"negate"
;
142
143
/**
144
* Determines whether a functor should be written using infix notation (e.g. `a + b + c`)
145
* or prefix notation (e.g. `+(a,b,c)`)
146
*
147
* Generally follow Haskell convention: functions w/ symbolic names are infix, otherwise prefix.
148
* NOTE: The surface syntax occasionally uses alpha infix operators
149
* For backwards compatibility we translate these into symbolic ops.
150
*/
151
bool
isInfixFunctorOp
(std::string_view symbol);
152
bool
isInfixFunctorOp
(
FunctorOp
op);
153
154
/**
155
* Given a type of an an attribute it returns the appropriate min/max functor operation
156
*/
157
158
FunctorOp
getMinOp
(
const
std::string&
type
);
159
FunctorOp
getMaxOp
(
const
std::string&
type
);
160
}
// end of namespace souffle
souffle::FunctorOp::DIV
@ DIV
souffle::IntrinsicFunctorInfo::multipleResults
bool multipleResults
Definition:
FunctorOps.h:126
souffle::FunctorOp::UEXP
@ UEXP
souffle::FunctorOp::UBOR
@ UBOR
souffle::FunctorOp::U2I
@ U2I
souffle::FunctorOp::FDIV
@ FDIV
souffle::FunctorOp::UBSHIFT_R
@ UBSHIFT_R
souffle::FunctorOp::I2S
@ I2S
souffle::FunctorOp::UBXOR
@ UBXOR
souffle::FunctorOp::FMIN
@ FMIN
souffle::IntrinsicFunctorInfo::symbol
std::string symbol
Definition:
FunctorOps.h:121
TypeAttribute
Type attribute class.
souffle::FunctorOp::UBSHIFT_R_UNSIGNED
@ UBSHIFT_R_UNSIGNED
souffle::FunctorOp::FADD
@ FADD
souffle::getMaxOp
FunctorOp getMaxOp(const std::string &type)
Definition:
FunctorOps.cpp:276
souffle::FunctorOp::FMUL
@ FMUL
souffle::FunctorOp::USUB
@ USUB
souffle::FunctorOp::URANGE
@ URANGE
souffle::isOverloadedFunctor
bool isOverloadedFunctor(std::string_view symbol)
Indicate whether a functor is overloaded.
souffle::FunctorOp::ULAND
@ ULAND
souffle::FunctorOp::EXP
@ EXP
souffle::FunctorOp::UMAX
@ UMAX
souffle::FunctorOp::STRLEN
@ STRLEN
souffle::FunctorOp::NEG
@ NEG
souffle::IntrinsicFunctorInfo::variadic
bool variadic
Definition:
FunctorOps.h:125
souffle::FunctorOp::ORD
@ ORD
Unary Functor Operators.
souffle::FunctorOp::U2F
@ U2F
souffle::FunctorOp::FNEG
@ FNEG
souffle::FunctorOp::LNOT
@ LNOT
souffle::FunctorOp::BXOR
@ BXOR
souffle::FunctorOp::MOD
@ MOD
souffle::FunctorOp::BSHIFT_L
@ BSHIFT_L
souffle::IntrinsicFunctors
std::vector< std::reference_wrapper< const IntrinsicFunctorInfo > > IntrinsicFunctors
Definition:
FunctorOps.h:129
souffle::FunctorOp::UBNOT
@ UBNOT
souffle::FunctorOp::LOR
@ LOR
souffle::FunctorOp::FRANGE
@ FRANGE
souffle::getMinOp
FunctorOp getMinOp(const std::string &type)
Given a type of an an attribute it returns the appropriate min/max functor operation.
Definition:
FunctorOps.cpp:267
souffle::FunctorOp::CAT
@ CAT
souffle::FunctorOp::UBSHIFT_L
@ UBSHIFT_L
souffle::FunctorOp::UMUL
@ UMUL
souffle::FunctorOp::ULOR
@ ULOR
souffle::FunctorOp::U2S
@ U2S
souffle::FunctorOp::RANGE
@ RANGE
souffle::IntrinsicFunctorInfo::params
std::vector< TypeAttribute > params
Definition:
FunctorOps.h:122
souffle::IntrinsicFunctorInfo::op
FunctorOp op
Definition:
FunctorOps.h:124
souffle::isValidFunctorOpArity
bool isValidFunctorOpArity(std::string_view symbol, size_t arity)
Definition:
FunctorOps.cpp:240
souffle::FunctorOp::LAND
@ LAND
souffle::FunctorOp::SMAX
@ SMAX
souffle::FunctorOp::I2F
@ I2F
souffle::FunctorOp::BOR
@ BOR
souffle::FunctorOp::BNOT
@ BNOT
souffle::FunctorOp::FEXP
@ FEXP
souffle::FunctorOp::S2I
@ S2I
souffle::operator<<
std::ostream & operator<<(std::ostream &os, AggregateOp op)
Definition:
AggregateOp.h:51
souffle::FunctorOp
FunctorOp
Definition:
FunctorOps.h:35
souffle::FunctorOp::UMIN
@ UMIN
souffle::FunctorOp::F2I
@ F2I
souffle::functorBuiltIn
IntrinsicFunctors functorBuiltIn(FunctorOp op)
Definition:
FunctorOps.cpp:224
souffle::FunctorOp::S2F
@ S2F
souffle::FunctorOp::UMOD
@ UMOD
souffle::FunctorOp::FSUB
@ FSUB
souffle::FunctorOp::BSHIFT_R_UNSIGNED
@ BSHIFT_R_UNSIGNED
souffle::FunctorOp::F2U
@ F2U
souffle::FunctorOp::BAND
@ BAND
souffle::FunctorOp::F2S
@ F2S
souffle::FunctorOp::UBAND
@ UBAND
souffle::FunctorOp::SUB
@ SUB
souffle::FunctorOp::ULXOR
@ ULXOR
souffle::FunctorOp::UDIV
@ UDIV
souffle
Definition:
AggregateOp.h:25
souffle::FunctorOp::BSHIFT_R
@ BSHIFT_R
souffle::FunctorOp::UADD
@ UADD
souffle::FunctorOp::MUL
@ MUL
souffle::FunctorOp::SMIN
@ SMIN
souffle::IntrinsicFunctorInfo::result
TypeAttribute result
Definition:
FunctorOps.h:123
souffle::isInfixFunctorOp
bool isInfixFunctorOp(std::string_view symbol)
Determines whether a functor should be written using infix notation (e.g.
Definition:
FunctorOps.cpp:252
souffle::FunctorOp::ADD
@ ADD
Binary Functor Operators.
souffle::FunctorOp::S2U
@ S2U
souffle::FunctorOp::SUBSTR
@ SUBSTR
Ternary Functor Operators.
souffle::FunctorOp::MAX
@ MAX
souffle::FunctorOp::FMAX
@ FMAX
souffle::FunctorOp::I2U
@ I2U
std::type
ElementType type
Definition:
span.h:640
TypeAttribute.h
souffle::FunctorOp::MIN
@ MIN
souffle::FunctorOp::ULNOT
@ ULNOT
souffle::FUNCTOR_INTRINSIC_PREFIX_NEGATE_NAME
constexpr char FUNCTOR_INTRINSIC_PREFIX_NEGATE_NAME[]
Definition:
FunctorOps.h:147
souffle::FunctorOp::LXOR
@ LXOR
Generated by
1.8.17