souffle  2.0.2-371-g6315b36
Public Member Functions | Static Public Member Functions | Data Fields
souffle::ParserDriver Class Reference

#include <ParserDriver.h>

Collaboration diagram for souffle::ParserDriver:
Collaboration graph

Public Member Functions

void addClause (Own< ast::Clause > c)
 
void addComponent (Own< ast::Component > c)
 
std::set< RelationTagaddDeprecatedTag (RelationTag tag, SrcLocation tagLoc, std::set< RelationTag > tags)
 
void addDirective (Own< ast::Directive > d)
 
void addFunctorDeclaration (Own< ast::FunctorDeclaration > f)
 
void addInstantiation (Own< ast::ComponentInit > ci)
 
void addIoFromDeprecatedTag (ast::Relation &r)
 
void addPragma (Own< ast::Pragma > p)
 
void addRelation (Own< ast::Relation > r)
 
std::set< RelationTagaddReprTag (RelationTag tag, SrcLocation tagLoc, std::set< RelationTag > tags)
 
std::set< RelationTagaddTag (RelationTag tag, SrcLocation tagLoc, std::set< RelationTag > tags)
 
std::set< RelationTagaddTag (RelationTag tag, std::vector< RelationTag > incompatible, SrcLocation tagLoc, std::set< RelationTag > tags)
 
void addType (Own< ast::Type > type)
 
void error (const SrcLocation &loc, const std::string &msg)
 
void error (const std::string &msg)
 
Own< ast::SubsetTypemkDeprecatedSubType (ast::QualifiedName name, ast::QualifiedName attr, SrcLocation loc)
 
Own< ast::TranslationUnitparse (const std::string &code, ErrorReport &errorReport, DebugReport &debugReport)
 
Own< ast::TranslationUnitparse (const std::string &filename, FILE *in, ErrorReport &errorReport, DebugReport &debugReport)
 
void warning (const SrcLocation &loc, const std::string &msg)
 
virtual ~ParserDriver ()=default
 

Static Public Member Functions

static Own< ast::TranslationUnitparseTranslationUnit (const std::string &code, ErrorReport &errorReport, DebugReport &debugReport)
 
static Own< ast::TranslationUnitparseTranslationUnit (const std::string &filename, FILE *in, ErrorReport &errorReport, DebugReport &debugReport)
 

Data Fields

bool trace_scanning = false
 
Own< ast::TranslationUnittranslationUnit
 

Detailed Description

Definition at line 57 of file ParserDriver.h.

Constructor & Destructor Documentation

◆ ~ParserDriver()

virtual souffle::ParserDriver::~ParserDriver ( )
virtualdefault

Member Function Documentation

◆ addClause()

void souffle::ParserDriver::addClause ( Own< ast::Clause c)

Definition at line 176 of file ParserDriver.cpp.

176  {
177  ast::Program& program = translationUnit->getProgram();
178  program.addClause(std::move(c));
179 }

References souffle::ast::Program::addClause(), and translationUnit.

Here is the call graph for this function:

◆ addComponent()

void souffle::ParserDriver::addComponent ( Own< ast::Component c)

Definition at line 180 of file ParserDriver.cpp.

180  {
181  ast::Program& program = translationUnit->getProgram();
182  program.addComponent(std::move(c));
183 }

References souffle::ast::Program::addComponent(), and translationUnit.

Here is the call graph for this function:

◆ addDeprecatedTag()

std::set< RelationTag > souffle::ParserDriver::addDeprecatedTag ( RelationTag  tag,
SrcLocation  tagLoc,
std::set< RelationTag tags 
)

Definition at line 204 of file ParserDriver.cpp.

205  {
206  if (!Global::config().has("legacy")) {
207  warning(tagLoc, tfm::format("Deprecated %s qualifier was used", tag));
208  }
209  return addTag(tag, std::move(tagLoc), std::move(tags));
210 }

References addTag(), souffle::Global::config(), tinyformat::format(), and warning().

Here is the call graph for this function:

◆ addDirective()

void souffle::ParserDriver::addDirective ( Own< ast::Directive d)

Definition at line 129 of file ParserDriver.cpp.

129  {
130  ast::Program& program = translationUnit->getProgram();
131  if (directive->getType() == ast::DirectiveType::printsize) {
132  for (const auto& cur : program.getDirectives()) {
133  if (cur->getQualifiedName() == directive->getQualifiedName() &&
134  cur->getType() == ast::DirectiveType::printsize) {
135  Diagnostic err(Diagnostic::Type::ERROR,
136  DiagnosticMessage("Redefinition of printsize directives for relation " +
137  toString(directive->getQualifiedName()),
138  directive->getSrcLoc()),
139  {DiagnosticMessage("Previous definition", cur->getSrcLoc())});
140  translationUnit->getErrorReport().addDiagnostic(err);
141  return;
142  }
143  }
144  } else if (directive->getType() == ast::DirectiveType::limitsize) {
145  for (const auto& cur : program.getDirectives()) {
146  if (cur->getQualifiedName() == directive->getQualifiedName() &&
147  cur->getType() == ast::DirectiveType::limitsize) {
148  Diagnostic err(Diagnostic::Type::ERROR,
149  DiagnosticMessage("Redefinition of limitsize directives for relation " +
150  toString(directive->getQualifiedName()),
151  directive->getSrcLoc()),
152  {DiagnosticMessage("Previous definition", cur->getSrcLoc())});
153  translationUnit->getErrorReport().addDiagnostic(err);
154  return;
155  }
156  }
157  }
158  program.addDirective(std::move(directive));
159 }

References souffle::ast::Program::addDirective(), err, souffle::Diagnostic::ERROR, souffle::ast::Program::getDirectives(), souffle::ast::limitsize, souffle::ast::printsize, souffle::toString(), and translationUnit.

Referenced by addIoFromDeprecatedTag().

Here is the call graph for this function:

◆ addFunctorDeclaration()

void souffle::ParserDriver::addFunctorDeclaration ( Own< ast::FunctorDeclaration f)

Definition at line 101 of file ParserDriver.cpp.

101  {
102  const std::string& name = f->getName();
103  ast::Program& program = translationUnit->getProgram();
104  const ast::FunctorDeclaration* existingFunctorDecl = getIf(program.getFunctorDeclarations(),
105  [&](const ast::FunctorDeclaration* current) { return current->getName() == name; });
106  if (existingFunctorDecl != nullptr) {
107  Diagnostic err(Diagnostic::Type::ERROR,
108  DiagnosticMessage("Redefinition of functor " + toString(name), f->getSrcLoc()),
109  {DiagnosticMessage("Previous definition", existingFunctorDecl->getSrcLoc())});
110  translationUnit->getErrorReport().addDiagnostic(err);
111  } else {
112  program.addFunctorDeclaration(std::move(f));
113  }
114 }

References souffle::ast::Program::addFunctorDeclaration(), err, souffle::Diagnostic::ERROR, souffle::ast::Program::getFunctorDeclarations(), souffle::getIf(), souffle::toString(), and translationUnit.

Here is the call graph for this function:

◆ addInstantiation()

void souffle::ParserDriver::addInstantiation ( Own< ast::ComponentInit ci)

Definition at line 184 of file ParserDriver.cpp.

184  {
185  ast::Program& program = translationUnit->getProgram();
186  program.addInstantiation(std::move(ci));
187 }

References souffle::ast::Program::addInstantiation(), and translationUnit.

Here is the call graph for this function:

◆ addIoFromDeprecatedTag()

void souffle::ParserDriver::addIoFromDeprecatedTag ( ast::Relation r)

Definition at line 189 of file ParserDriver.cpp.

189  {
190  if (rel.hasQualifier(RelationQualifier::INPUT)) {
191  addDirective(mk<ast::Directive>(ast::DirectiveType::input, rel.getQualifiedName(), rel.getSrcLoc()));
192  }
193 
194  if (rel.hasQualifier(RelationQualifier::OUTPUT)) {
195  addDirective(mk<ast::Directive>(ast::DirectiveType::output, rel.getQualifiedName(), rel.getSrcLoc()));
196  }
197 
198  if (rel.hasQualifier(RelationQualifier::PRINTSIZE)) {
199  addDirective(
200  mk<ast::Directive>(ast::DirectiveType::printsize, rel.getQualifiedName(), rel.getSrcLoc()));
201  }
202 }

References addDirective(), souffle::ast::input, souffle::INPUT, souffle::ast::output, souffle::OUTPUT, souffle::ast::printsize, souffle::PRINTSIZE, and rel().

Here is the call graph for this function:

◆ addPragma()

void souffle::ParserDriver::addPragma ( Own< ast::Pragma p)

Definition at line 96 of file ParserDriver.cpp.

96  {
97  ast::Program& program = translationUnit->getProgram();
98  program.addPragma(std::move(p));
99 }

References souffle::ast::Program::addPragma(), p, and translationUnit.

Here is the call graph for this function:

◆ addRelation()

void souffle::ParserDriver::addRelation ( Own< ast::Relation r)

Definition at line 116 of file ParserDriver.cpp.

116  {
117  const auto& name = r->getQualifiedName();
118  ast::Program& program = translationUnit->getProgram();
119  if (ast::Relation* prev = getRelation(program, name)) {
120  Diagnostic err(Diagnostic::Type::ERROR,
121  DiagnosticMessage("Redefinition of relation " + toString(name), r->getSrcLoc()),
122  {DiagnosticMessage("Previous definition", prev->getSrcLoc())});
123  translationUnit->getErrorReport().addDiagnostic(err);
124  } else {
125  program.addRelation(std::move(r));
126  }
127 }

References souffle::ast::Program::addRelation(), err, souffle::Diagnostic::ERROR, souffle::ast::getRelation(), souffle::toString(), and translationUnit.

Here is the call graph for this function:

◆ addReprTag()

std::set< RelationTag > souffle::ParserDriver::addReprTag ( RelationTag  tag,
SrcLocation  tagLoc,
std::set< RelationTag tags 
)

Definition at line 212 of file ParserDriver.cpp.

213  {
214  return addTag(tag, {RelationTag::BTREE, RelationTag::BRIE, RelationTag::EQREL}, std::move(tagLoc),
215  std::move(tags));
216 }

References addTag(), souffle::BRIE, souffle::BTREE, and souffle::EQREL.

Here is the call graph for this function:

◆ addTag() [1/2]

std::set< RelationTag > souffle::ParserDriver::addTag ( RelationTag  tag,
SrcLocation  tagLoc,
std::set< RelationTag tags 
)

Definition at line 218 of file ParserDriver.cpp.

218  {
219  return addTag(tag, {tag}, std::move(tagLoc), std::move(tags));
220 }

Referenced by addDeprecatedTag(), and addReprTag().

◆ addTag() [2/2]

std::set< RelationTag > souffle::ParserDriver::addTag ( RelationTag  tag,
std::vector< RelationTag incompatible,
SrcLocation  tagLoc,
std::set< RelationTag tags 
)

Definition at line 222 of file ParserDriver.cpp.

223  {
224  if (any_of(incompatible, [&](auto&& x) { return contains(tags, x); })) {
225  error(tagLoc, tfm::format("%s qualifier already set", join(incompatible, "/")));
226  }
227 
228  tags.insert(tag);
229  return tags;
230 }

References souffle::any_of(), souffle::contains(), error(), tinyformat::format(), and souffle::join().

Here is the call graph for this function:

◆ addType()

void souffle::ParserDriver::addType ( Own< ast::Type type)

Definition at line 161 of file ParserDriver.cpp.

161  {
162  ast::Program& program = translationUnit->getProgram();
163  const auto& name = type->getQualifiedName();
164  auto* existingType = getIf(program.getTypes(),
165  [&](const ast::Type* current) { return current->getQualifiedName() == name; });
166  if (existingType != nullptr) {
167  Diagnostic err(Diagnostic::Type::ERROR,
168  DiagnosticMessage("Redefinition of type " + toString(name), type->getSrcLoc()),
169  {DiagnosticMessage("Previous definition", existingType->getSrcLoc())});
170  translationUnit->getErrorReport().addDiagnostic(err);
171  } else {
172  program.addType(std::move(type));
173  }
174 }

References souffle::ast::Program::addType(), err, souffle::Diagnostic::ERROR, souffle::getIf(), souffle::ast::Program::getTypes(), souffle::toString(), and translationUnit.

Here is the call graph for this function:

◆ error() [1/2]

void souffle::ParserDriver::error ( const SrcLocation loc,
const std::string &  msg 
)

Definition at line 243 of file ParserDriver.cpp.

243  {
244  translationUnit->getErrorReport().addError(msg, loc);
245 }

References translationUnit.

Referenced by addTag().

◆ error() [2/2]

void souffle::ParserDriver::error ( const std::string &  msg)

Definition at line 246 of file ParserDriver.cpp.

246  {
247  translationUnit->getErrorReport().addDiagnostic(
248  Diagnostic(Diagnostic::Type::ERROR, DiagnosticMessage(msg)));
249 }

References souffle::Diagnostic::ERROR, and translationUnit.

◆ mkDeprecatedSubType()

Own< ast::SubsetType > souffle::ParserDriver::mkDeprecatedSubType ( ast::QualifiedName  name,
ast::QualifiedName  attr,
SrcLocation  loc 
)

Definition at line 232 of file ParserDriver.cpp.

233  {
234  if (!Global::config().has("legacy")) {
235  warning(loc, "Deprecated type declaration used");
236  }
237  return mk<ast::SubsetType>(std::move(name), std::move(baseTypeName), std::move(loc));
238 }

References souffle::Global::config(), and warning().

Here is the call graph for this function:

◆ parse() [1/2]

Own< ast::TranslationUnit > souffle::ParserDriver::parse ( const std::string &  code,
ErrorReport errorReport,
DebugReport debugReport 
)

Definition at line 67 of file ParserDriver.cpp.

68  {
69  translationUnit = mk<ast::TranslationUnit>(mk<ast::Program>(), errorReport, debugReport);
70 
71  scanner_data data;
72  data.yyfilename = "<in-memory>";
73  yyscan_t scanner;
74  yylex_init_extra(&data, &scanner);
75  yy_scan_string(code.c_str(), scanner);
76  yy::parser parser(*this, scanner);
77  parser.parse();
78 
79  yylex_destroy(scanner);
80 
81  return std::move(translationUnit);
82 }

References TCB_SPAN_NAMESPACE_NAME::detail::data(), translationUnit, yy_scan_string(), yylex_destroy(), and yylex_init_extra().

Here is the call graph for this function:

◆ parse() [2/2]

Own< ast::TranslationUnit > souffle::ParserDriver::parse ( const std::string &  filename,
FILE *  in,
ErrorReport errorReport,
DebugReport debugReport 
)

Definition at line 50 of file ParserDriver.cpp.

51  {
52  translationUnit = mk<ast::TranslationUnit>(mk<ast::Program>(), errorReport, debugReport);
53  yyscan_t scanner;
54  scanner_data data;
55  data.yyfilename = filename;
56  yylex_init_extra(&data, &scanner);
57  yyset_in(in, scanner);
58 
59  yy::parser parser(*this, scanner);
60  parser.parse();
61 
62  yylex_destroy(scanner);
63 
64  return std::move(translationUnit);
65 }

References TCB_SPAN_NAMESPACE_NAME::detail::data(), translationUnit, yylex_destroy(), yylex_init_extra(), and yyset_in().

Referenced by parseTranslationUnit().

Here is the call graph for this function:

◆ parseTranslationUnit() [1/2]

Own< ast::TranslationUnit > souffle::ParserDriver::parseTranslationUnit ( const std::string &  code,
ErrorReport errorReport,
DebugReport debugReport 
)
static

Definition at line 90 of file ParserDriver.cpp.

91  {
92  ParserDriver parser;
93  return parser.parse(code, errorReport, debugReport);
94 }

References parse().

Here is the call graph for this function:

◆ parseTranslationUnit() [2/2]

Own< ast::TranslationUnit > souffle::ParserDriver::parseTranslationUnit ( const std::string &  filename,
FILE *  in,
ErrorReport errorReport,
DebugReport debugReport 
)
static

Definition at line 84 of file ParserDriver.cpp.

85  {
86  ParserDriver parser;
87  return parser.parse(filename, in, errorReport, debugReport);
88 }

References parse().

Referenced by souffle::ast::transform::test::TEST().

Here is the call graph for this function:

◆ warning()

void souffle::ParserDriver::warning ( const SrcLocation loc,
const std::string &  msg 
)

Definition at line 240 of file ParserDriver.cpp.

240  {
241  translationUnit->getErrorReport().addWarning(msg, loc);
242 }

References translationUnit.

Referenced by addDeprecatedTag(), and mkDeprecatedSubType().

Field Documentation

◆ trace_scanning

bool souffle::ParserDriver::trace_scanning = false

Definition at line 82 of file ParserDriver.h.

◆ translationUnit

Own<ast::TranslationUnit> souffle::ParserDriver::translationUnit

The documentation for this class was generated from the following files:
err
std::string & err
Definition: json11.h:664
souffle::RelationTag::EQREL
@ EQREL
tinyformat::format
void format(std::ostream &out, const char *fmt)
Definition: tinyformat.h:1089
souffle::ParserDriver::addDirective
void addDirective(Own< ast::Directive > d)
Definition: ParserDriver.cpp:129
souffle::contains
bool contains(const C &container, const typename C::value_type &element)
A utility to check generically whether a given element is contained in a given container.
Definition: ContainerUtil.h:75
souffle::RelationQualifier::PRINTSIZE
@ PRINTSIZE
yyset_in
void yyset_in(FILE *in_str, yyscan_t scanner)
souffle::toString
const std::string & toString(const std::string &str)
A generic function converting strings into strings (trivial case).
Definition: StringUtil.h:234
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::any_of
bool any_of(const Container &c, UnaryPredicate p)
A generic test checking whether any elements within a container satisfy a certain predicate.
Definition: FunctionalUtil.h:124
souffle::ast::DirectiveType::printsize
@ printsize
souffle::Diagnostic::Type::ERROR
@ ERROR
souffle::ParserDriver::translationUnit
Own< ast::TranslationUnit > translationUnit
Definition: ParserDriver.h:61
souffle::ast::DirectiveType::input
@ input
souffle::RelationQualifier::INPUT
@ INPUT
souffle::getIf
C::value_type getIf(const C &container, std::function< bool(const typename C::value_type)> pred)
Returns the first element in a container that satisfies a given predicate, nullptr otherwise.
Definition: ContainerUtil.h:101
souffle::Global::config
static MainConfig & config()
Definition: Global.h:141
souffle::ParserDriver::addTag
std::set< RelationTag > addTag(RelationTag tag, SrcLocation tagLoc, std::set< RelationTag > tags)
Definition: ParserDriver.cpp:218
souffle::ast::DirectiveType::output
@ output
souffle::ast::DirectiveType::limitsize
@ limitsize
yy_scan_string
YY_BUFFER_STATE yy_scan_string(const char *, yyscan_t scanner)
souffle::ParserDriver::error
void error(const SrcLocation &loc, const std::string &msg)
Definition: ParserDriver.cpp:243
TCB_SPAN_NAMESPACE_NAME::detail::data
constexpr auto data(C &c) -> decltype(c.data())
Definition: span.h:210
yylex_init_extra
int yylex_init_extra(scanner_data *data, yyscan_t *scanner)
yylex_destroy
int yylex_destroy(yyscan_t scanner)
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ParserDriver::warning
void warning(const SrcLocation &loc, const std::string &msg)
Definition: ParserDriver.cpp:240
souffle::yyscan_t
void * yyscan_t
Definition: ParserDriver.h:48
souffle::RelationQualifier::OUTPUT
@ OUTPUT
std::type
ElementType type
Definition: span.h:640
souffle::RelationTag::BRIE
@ BRIE
souffle::RelationTag::BTREE
@ BTREE
p
a horizontalBars(j=m=void 0===a.axisX.type?new c.AutoScaleAxis(c.Axis.units.x, b.normalized.series, o, c.extend({}, a.axisX,{highLow:d, referenceValue:0})):a.axisX.type.call(c, c.Axis.units.x, b.normalized.series, o, c.extend({}, a.axisX,{highLow:d, referenceValue:0})), l=n=void 0===a.axisY.type?new c.StepAxis(c.Axis.units.y, b.normalized.series, o,{ticks:k}):a.axisY.type.call(c, c.Axis.units.y, b.normalized.series, o, a.axisY)) var p
Definition: htmlJsChartistMin.h:15