souffle  2.0.2-371-g6315b36
IOType.cpp
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 IOTypeAnalysis.cpp
12  *
13  * Implements methods to identify a relation as input, output, or printsize.
14  *
15  ***********************************************************************/
16 
17 #include "ast/analysis/IOType.h"
18 #include "ast/Directive.h"
19 #include "ast/Program.h"
20 #include "ast/QualifiedName.h"
21 #include "ast/Relation.h"
22 #include "ast/TranslationUnit.h"
23 #include "ast/utility/Utils.h"
24 #include "ast/utility/Visitor.h"
26 #include <cassert>
27 #include <ostream>
28 #include <vector>
29 
30 namespace souffle::ast::analysis {
31 
32 void IOTypeAnalysis::run(const TranslationUnit& translationUnit) {
33  const Program& program = translationUnit.getProgram();
34  visitDepthFirst(program, [&](const Directive& directive) {
35  auto* relation = getRelation(program, directive.getQualifiedName());
36  if (relation == nullptr) {
37  return;
38  }
39  switch (directive.getType()) {
44  outputRelations.insert(relation);
45  break;
48  assert(directive.hasParameter("n") && "limitsize has no n directive");
49  limitSize[relation] = stoi(directive.getParameter("n"));
50  break;
51  }
52  });
53 }
54 
55 void IOTypeAnalysis::print(std::ostream& os) const {
56  auto show = [](std::ostream& os, const Relation* r) { os << r->getQualifiedName(); };
57  os << "input relations: {" << join(inputRelations, ", ", show) << "}\n";
58  os << "output relations: {" << join(outputRelations, ", ", show) << "}\n";
59  os << "printsize relations: {" << join(printSizeRelations, ", ", show) << "}\n";
60  os << "limitsize relations: {" << join(limitSizeRelations, ", ", show) << "}\n";
61 }
62 
63 } // namespace souffle::ast::analysis
souffle::ast::analysis::IOTypeAnalysis::print
void print(std::ostream &os) const override
print the analysis result in HTML format
Definition: IOType.cpp:61
TranslationUnit.h
souffle::ast::analysis::IOTypeAnalysis::printSizeRelations
std::set< const Relation * > printSizeRelations
Definition: IOType.h:80
IOType.h
Directive.h
relation
Relation & relation
Definition: Reader.h:130
souffle::ast::analysis::IOTypeAnalysis::limitSize
std::map< const Relation *, std::size_t > limitSize
Definition: IOType.h:82
Relation.h
Utils.h
souffle::ast::analysis::IOTypeAnalysis::limitSizeRelations
std::set< const Relation * > limitSizeRelations
Definition: IOType.h:81
souffle::ast::getRelation
Relation * getRelation(const Program &program, const QualifiedName &name)
Returns the relation with the given name in the program.
Definition: Utils.cpp:101
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::analysis::IOTypeAnalysis::outputRelations
std::set< const Relation * > outputRelations
Definition: IOType.h:79
souffle::ast::DirectiveType::printsize
@ printsize
souffle::ast::DirectiveType::input
@ input
QualifiedName.h
souffle::ast::analysis::IOTypeAnalysis::run
void run(const TranslationUnit &translationUnit) override
run analysis for a Ast translation unit
Definition: IOType.cpp:38
Program.h
souffle::ast::DirectiveType::output
@ output
StreamUtil.h
souffle::ast::DirectiveType::limitsize
@ limitsize
Visitor.h
souffle::ast::analysis
Definition: Aggregate.cpp:39
souffle::ast::visitDepthFirst
void visitDepthFirst(const Node &root, Visitor< R, Ps... > &visitor, Args &... args)
A utility function visiting all nodes within the ast rooted by the given node recursively in a depth-...
Definition: Visitor.h:273
souffle::ast::analysis::IOTypeAnalysis::inputRelations
std::set< const Relation * > inputRelations
Definition: IOType.h:78