/
GroundedTermsChecker.cpp
98 lines (89 loc) · 2.89 KB
/
GroundedTermsChecker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Souffle - A Datalog Compiler
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved
* Licensed under the Universal Permissive License v 1.0 as shown at:
* - https://opensource.org/licenses/UPL
* - <souffle root>/licenses/SOUFFLE-UPL.txt
*/
/************************************************************************
*
* @file SemanticChecker.cpp
*
* Implementation of the grounded terms checker pass.
*
***********************************************************************/
#include "ast/transform/GroundedTermsChecker.h"
#include "AggregateOp.h"
#include "BinaryConstraintOps.h"
#include "ErrorReport.h"
#include "FunctorOps.h"
#include "Global.h"
#include "GraphUtils.h"
#include "RamTypes.h"
#include "RelationTag.h"
#include "SrcLocation.h"
#include "ast/Abstract.h"
#include "ast/Argument.h"
#include "ast/Attribute.h"
#include "ast/Clause.h"
#include "ast/IO.h"
#include "ast/Literal.h"
#include "ast/Node.h"
#include "ast/Program.h"
#include "ast/QualifiedName.h"
#include "ast/Relation.h"
#include "ast/TranslationUnit.h"
#include "ast/Type.h"
#include "ast/TypeSystem.h"
#include "ast/Utils.h"
#include "ast/Visitor.h"
#include "ast/analysis/Ground.h"
#include "ast/analysis/IOType.h"
#include "ast/analysis/PrecedenceGraph.h"
#include "ast/analysis/RecursiveClauses.h"
#include "ast/analysis/RelationSchedule.h"
#include "ast/analysis/SCCGraph.h"
#include "ast/analysis/Type.h"
#include "ast/analysis/TypeEnvironment.h"
#include "utility/ContainerUtil.h"
#include "utility/FunctionalUtil.h"
#include "utility/MiscUtil.h"
#include "utility/StreamUtil.h"
#include "utility/StringUtil.h"
#include "utility/tinyformat.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <typeinfo>
#include <utility>
#include <vector>
namespace souffle {
void GroundedTermsChecker::verify(AstTranslationUnit& translationUnit) {
auto&& program = *translationUnit.getProgram();
auto&& report = translationUnit.getErrorReport();
// -- check grounded variables and records --
visitDepthFirst(program.getClauses(), [&](const AstClause& clause) {
if (isFact(clause)) return; // only interested in rules
auto isGrounded = getGroundedTerms(translationUnit, clause);
std::set<std::string> reportedVars;
// all terms in head need to be grounded
for (auto&& cur : getVariables(clause)) {
if (!isGrounded[cur] && reportedVars.insert(cur->getName()).second) {
report.addError("Ungrounded variable " + cur->getName(), cur->getSrcLoc());
}
}
// all records need to be grounded
for (auto&& cur : getRecords(clause)) {
if (!isGrounded[cur]) {
report.addError("Ungrounded record", cur->getSrcLoc());
}
}
});
}
} // end of namespace souffle