souffle  2.0.2-371-g6315b36
Aggregate.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 Aggregate.h
12  *
13  * Defines methods for determining the scope of variables
14  * occurring in a clause (whether they are injected, local, or witnesses)
15  *
16  ***********************************************************************/
17 
18 #pragma once
19 
20 #include "ast/Aggregator.h"
21 #include "ast/Argument.h"
22 #include "ast/Clause.h"
23 #include "ast/Program.h"
24 #include "ast/TranslationUnit.h"
25 #include "ast/Variable.h"
26 #include <set>
27 #include <string>
28 
29 namespace souffle::ast::analysis {
30 /**
31  * Computes the set of local variables
32  * in an aggregate expression.
33  **/
34 std::set<std::string> getLocalVariables(
35  const TranslationUnit& tu, const Clause& clause, const Aggregator& aggregate);
36 
37 /**
38  * Computes the set of witness variables that are used in the aggregate
39  **/
40 std::set<std::string> getWitnessVariables(
41  const TranslationUnit& tu, const Clause& clause, const Aggregator& aggregate);
42 /**
43  * Find the set of variable names occurring outside of the given aggregate.
44  * This is equivalent to taking the set minus of the set of all variable names
45  * occurring in the clause minus the set of all variable names occurring in the aggregate.
46  **/
47 std::set<std::string> getVariablesOutsideAggregate(const Clause& clause, const Aggregator& aggregate);
48 
49 /**
50  * Find a new relation name. I use this when I create new relations either for
51  * aggregate bodies or singleton aggregates.
52  **/
53 std::string findUniqueRelationName(const Program& program, std::string base);
54 /**
55  * Find a variable name using base to form a string like base1
56  * Use this when you need to limit the scope of a variable to the inside of an aggregate.
57  **/
58 std::string findUniqueVariableName(const Clause& clause, std::string base);
59 /**
60  * Given an aggregate and a clause, we find all the variables that have been
61  * injected into the aggregate.
62  * This means that the variable occurs grounded in an outer scope.
63  **/
64 std::set<std::string> getInjectedVariables(
65  const TranslationUnit& tu, const Clause& clause, const Aggregator& aggregate);
66 
67 } // namespace souffle::ast::analysis
TranslationUnit.h
souffle::ast::analysis::getLocalVariables
std::set< std::string > getLocalVariables(const TranslationUnit &tu, const Clause &clause, const Aggregator &aggregate)
Computes the set of local variables in an aggregate expression.
Definition: Aggregate.cpp:55
base
T & base
Definition: Reader.h:60
Argument.h
souffle::ast::analysis::getVariablesOutsideAggregate
std::set< std::string > getVariablesOutsideAggregate(const Clause &clause, const Aggregator &aggregate)
Computes the set of variables occurring outside the aggregate.
Definition: Aggregate.cpp:164
souffle::ast::analysis::findUniqueRelationName
std::string findUniqueRelationName(const Program &program, std::string base)
Find a new relation name.
Definition: Aggregate.cpp:190
Aggregator.h
souffle::ast::analysis::findUniqueVariableName
std::string findUniqueVariableName(const Clause &clause, std::string base)
Find a variable name using base to form a string like base1 Use this when you need to limit the scope...
Definition: Aggregate.cpp:179
Program.h
Clause.h
souffle::ast::analysis
Definition: Aggregate.cpp:39
souffle::ast::analysis::getWitnessVariables
std::set< std::string > getWitnessVariables(const TranslationUnit &tu, const Clause &clause, const Aggregator &aggregate)
Computes the set of witness variables that are used in the aggregate A variable is a witness if it oc...
Definition: Aggregate.cpp:75
Variable.h
souffle::ast::analysis::getInjectedVariables
std::set< std::string > getInjectedVariables(const TranslationUnit &tu, const Clause &clause, const Aggregator &aggregate)
Given an aggregate and a clause, we find all the variables that have been injected into the aggregate...
Definition: Aggregate.cpp:205