souffle  2.0.2-371-g6315b36
Public Member Functions | Private Member Functions
souffle::ast::transform::IODefaultsTransformer Class Reference

Transformation pass to set defaults for IO operations. More...

#include <IODefaults.h>

Inheritance diagram for souffle::ast::transform::IODefaultsTransformer:
Inheritance graph
Collaboration diagram for souffle::ast::transform::IODefaultsTransformer:
Collaboration graph

Public Member Functions

IODefaultsTransformerclone () const override
 
std::string getName () const override
 
- Public Member Functions inherited from souffle::ast::transform::Transformer
bool apply (TranslationUnit &translationUnit)
 
virtual ~Transformer ()=default
 

Private Member Functions

std::string getRelationName (const Directive *node)
 Get the relation name from the qualified name. More...
 
bool setDefaults (TranslationUnit &translationUnit)
 Set IO defaults. More...
 
bool transform (TranslationUnit &translationUnit) override
 

Detailed Description

Transformation pass to set defaults for IO operations.

Definition at line 41 of file IODefaults.h.

Member Function Documentation

◆ clone()

IODefaultsTransformer* souffle::ast::transform::IODefaultsTransformer::clone ( ) const
inlineoverridevirtual

Implements souffle::ast::transform::Transformer.

Definition at line 53 of file IODefaults.h.

68  {

◆ getName()

std::string souffle::ast::transform::IODefaultsTransformer::getName ( ) const
inlineoverridevirtual

Implements souffle::ast::transform::Transformer.

Definition at line 49 of file IODefaults.h.

68  {

◆ getRelationName()

std::string souffle::ast::transform::IODefaultsTransformer::getRelationName ( const Directive node)
inlineprivate

Get the relation name from the qualified name.

Returns
Valid relation name from the concatenated qualified name.

Definition at line 137 of file IODefaults.h.

◆ setDefaults()

bool souffle::ast::transform::IODefaultsTransformer::setDefaults ( TranslationUnit translationUnit)
inlineprivate

Set IO defaults.

If no IO type is specified, use 'file' If no name is set, use the relation name. Add the operation type to the directives list. If a global fact directory is specified, add to the directives list. If a global output directory is specified, add to the directives list. If stdout is requested at the command line ('-D-'), change all output to stdout. If a printsize operation is requested, set IO type and operation accordingly.

Parameters
translationUnit
Returns
true if any changes were made

Definition at line 80 of file IODefaults.h.

83  {
84  io->addParameter("name", getRelationName(io));
85  changed = true;
86  }
87 
88  // Set the operation type (input/output/printsize)
89  if (!io->hasParameter("operation")) {
90  if (io->getType() == ast::DirectiveType::input) {
91  io->addParameter("operation", "input");
92  changed = true;
93  // Configure input directory
94  if (Global::config().has("fact-dir")) {
95  io->addParameter("fact-dir", Global::config().get("fact-dir"));
96  }
97  } else if (io->getType() == ast::DirectiveType::output) {
98  io->addParameter("operation", "output");
99  changed = true;
100  // Configure output directory
101  if (Global::config().has("output-dir")) {
102  if (Global::config().has("output-dir", "-")) {
103  io->addParameter("IO", "stdout");
104  io->addParameter("headers", "true");
105  } else {
106  io->addParameter("output-dir", Global::config().get("output-dir"));
107  }
108  }
109  } else if (io->getType() == ast::DirectiveType::printsize) {
110  io->addParameter("operation", "printsize");
111  io->addParameter("IO", "stdoutprintsize");
112  changed = true;
113  }
114  }
115  }
116 
117  return changed;
118  }
119 
120  /**
121  * Get the relation name from the qualified name.
122  *
123  * @return Valid relation name from the concatenated qualified name.
124  */
125  std::string getRelationName(const Directive* node) {
126  return toString(join(node->getQualifiedName().getQualifiers(), "."));
127  }
128 };
129 
130 } // namespace souffle::ast::transform

◆ transform()

bool souffle::ast::transform::IODefaultsTransformer::transform ( TranslationUnit translationUnit)
inlineoverrideprivatevirtual

Implements souffle::ast::transform::Transformer.

Definition at line 58 of file IODefaults.h.

68  {

References souffle::ast::Program::getDirectives(), souffle::ast::TranslationUnit::getProgram(), and souffle::ast::limitsize.

Here is the call graph for this function:

The documentation for this class was generated from the following file:
souffle::ast::transform::IODefaultsTransformer::getRelationName
std::string getRelationName(const Directive *node)
Get the relation name from the qualified name.
Definition: IODefaults.h:137
souffle::toString
const std::string & toString(const std::string &str)
A generic function converting strings into strings (trivial case).
Definition: StringUtil.h:234
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::DirectiveType::printsize
@ printsize
TCB_SPAN_NAMESPACE_NAME::get
constexpr auto get(span< E, S > s) -> decltype(s[N])
Definition: span.h:599
souffle::ast::DirectiveType::input
@ input
souffle::Global::config
static MainConfig & config()
Definition: Global.h:141
souffle::ast::DirectiveType::output
@ output