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

#include <ComponentChecker.h>

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

Public Member Functions

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

Private Member Functions

bool transform (TranslationUnit &translationUnit) override
 

Static Private Member Functions

static void checkComponent (ErrorReport &report, const Component *enclosingComponent, const analysis::ComponentLookupAnalysis &componentLookup, const Component &component, const analysis::TypeBinding &binding)
 
static void checkComponentInit (ErrorReport &report, const Component *enclosingComponent, const analysis::ComponentLookupAnalysis &componentLookup, const ComponentInit &init, const analysis::TypeBinding &binding)
 
static const ComponentcheckComponentNameReference (ErrorReport &report, const Component *enclosingComponent, const analysis::ComponentLookupAnalysis &componentLookup, const std::string &name, const SrcLocation &loc, const analysis::TypeBinding &binding)
 
static void checkComponentNamespaces (ErrorReport &report, const Program &program)
 
static void checkComponentReference (ErrorReport &report, const Component *enclosingComponent, const analysis::ComponentLookupAnalysis &componentLookup, const ast::ComponentType &type, const SrcLocation &loc, const analysis::TypeBinding &binding)
 
static void checkComponents (ErrorReport &report, const Program &program, const analysis::ComponentLookupAnalysis &componentLookup)
 

Detailed Description

Definition at line 38 of file ComponentChecker.h.

Constructor & Destructor Documentation

◆ ~ComponentChecker()

souffle::ast::transform::ComponentChecker::~ComponentChecker ( )
overridedefault

Member Function Documentation

◆ checkComponent()

void souffle::ast::transform::ComponentChecker::checkComponent ( ErrorReport report,
const Component enclosingComponent,
const analysis::ComponentLookupAnalysis componentLookup,
const Component component,
const analysis::TypeBinding binding 
)
staticprivate

Definition at line 108 of file ComponentChecker.cpp.

118  : component.getBaseComponents()) {
120  report, enclosingComponent, componentLookup, *cur, component.getSrcLoc(), activeBinding);
121 
122  // Note: type parameters can also be atomic types like number, or anything defined through .type
123  // The original semantic check permitted any identifier (existing or non-existing) to be actual
124  // parameter
125  // In order to maintain the compatibility, we do not check the actual parameters
126 
127  // for (const std::string& param : cur.getTypeParameters()) {
128  // checkComponentNameReference(report, scope, param, component.getSrcLoc(), activeBinding);
129  //}
130  }
131 
132  // get all parents
133  std::set<const Component*> parents;
134  std::function<void(const Component&)> collectParents = [&](const Component& cur) {
135  for (const auto& base : cur.getBaseComponents()) {
136  auto c = componentLookup.getComponent(enclosingComponent, base->getName(), binding);
137  if (c == nullptr) {
138  continue;
139  }
140  if (parents.insert(c).second) {
141  collectParents(*c);
142  }
143  }
144  };
145  collectParents(component);
146 
147  // check overrides
148  for (const Relation* relation : component.getRelations()) {
149  if (component.getOverridden().count(relation->getQualifiedName().getQualifiers()[0]) != 0u) {
150  report.addError("Override of non-inherited relation " +
151  relation->getQualifiedName().getQualifiers()[0] + " in component " +
152  component.getComponentType()->getName(),
153  component.getSrcLoc());
154  }
155  }
156  for (const Component* parent : parents) {
157  for (const Relation* relation : parent->getRelations()) {
158  if ((component.getOverridden().count(relation->getQualifiedName().getQualifiers()[0]) != 0u) &&
159  !relation->hasQualifier(RelationQualifier::OVERRIDABLE)) {
160  report.addError("Override of non-overridable relation " +
161  relation->getQualifiedName().getQualifiers()[0] + " in component " +
162  component.getComponentType()->getName(),
163  component.getSrcLoc());
164  }
165  }
166  }
167 
168  // check for a cycle
169  if (parents.find(&component) != parents.end()) {
170  report.addError(
171  "Invalid cycle in inheritance for component " + component.getComponentType()->getName(),
172  component.getSrcLoc());
173  }
174 
175  // -- nested components --
176 
177  // check nested components
178  for (const auto& cur : component.getComponents()) {
179  checkComponent(report, &component, componentLookup, *cur, activeBinding);
180  }
181 
182  // check nested instantiations
183  for (const auto& cur : component.getInstantiations()) {
184  checkComponentInit(report, &component, componentLookup, *cur, activeBinding);
185  }
186 }
187 
189  ErrorReport& report, const Program& program, const ComponentLookupAnalysis& componentLookup) {
190  for (Component* cur : program.getComponents()) {
191  checkComponent(report, nullptr, componentLookup, *cur, TypeBinding());
192  }

◆ checkComponentInit()

void souffle::ast::transform::ComponentChecker::checkComponentInit ( ErrorReport report,
const Component enclosingComponent,
const analysis::ComponentLookupAnalysis componentLookup,
const ComponentInit init,
const analysis::TypeBinding binding 
)
staticprivate

Definition at line 91 of file ComponentChecker.cpp.

104  {
105  // -- inheritance --
106 

◆ checkComponentNameReference()

const Component * souffle::ast::transform::ComponentChecker::checkComponentNameReference ( ErrorReport report,
const Component enclosingComponent,
const analysis::ComponentLookupAnalysis componentLookup,
const std::string &  name,
const SrcLocation loc,
const analysis::TypeBinding binding 
)
staticprivate

Definition at line 56 of file ComponentChecker.cpp.

61  {
62  report.addError("Referencing undefined component " + name, loc);
63  return nullptr;
64  }
65 
66  return c;
67 }
68 
69 void ComponentChecker::checkComponentReference(ErrorReport& report, const Component* enclosingComponent,
70  const ComponentLookupAnalysis& componentLookup, const ast::ComponentType& type,
71  const SrcLocation& loc, const TypeBinding& binding) {
72  // check whether targeted component exists
73  const Component* c = checkComponentNameReference(

◆ checkComponentNamespaces()

void souffle::ast::transform::ComponentChecker::checkComponentNamespaces ( ErrorReport report,
const Program program 
)
staticprivate

Definition at line 206 of file ComponentChecker.cpp.

206  : program.getTypes()) {
207  const std::string name = toString(type->getQualifiedName());
208  if (names.count(name) == 0u) {
209  names[name] = type->getSrcLoc();
210  }
211  }
212 
213  for (const auto& rel : program.getRelations()) {
214  const std::string name = toString(rel->getQualifiedName());
215  if (names.count(name) == 0u) {
216  names[name] = rel->getSrcLoc();
217  }
218  }
219 
220  // Note: Nested component and instance names are not obtained.
221  for (const auto& comp : program.getComponents()) {
222  const std::string name = toString(comp->getComponentType()->getName());
223  if (names.count(name) != 0u) {
224  report.addError("Name clash on component " + name, comp->getSrcLoc());
225  } else {
226  names[name] = comp->getSrcLoc();
227  }
228  }
229 
230  for (const auto& inst : program.getComponentInstantiations()) {
231  const std::string name = toString(inst->getInstanceName());
232  if (names.count(name) != 0u) {
233  report.addError("Name clash on instantiation " + name, inst->getSrcLoc());
234  } else {
235  names[name] = inst->getSrcLoc();
236  }
237  }
238 }
239 } // namespace souffle::ast::transform

References souffle::toString().

Here is the call graph for this function:

◆ checkComponentReference()

void souffle::ast::transform::ComponentChecker::checkComponentReference ( ErrorReport report,
const Component enclosingComponent,
const analysis::ComponentLookupAnalysis componentLookup,
const ast::ComponentType type,
const SrcLocation loc,
const analysis::TypeBinding binding 
)
staticprivate

Definition at line 75 of file ComponentChecker.cpp.

75  {
76  return;
77  }
78 
79  // check number of type parameters
80  if (c->getComponentType()->getTypeParameters().size() != type.getTypeParameters().size()) {
81  report.addError("Invalid number of type parameters for component " + type.getName(), loc);
82  }
83 }
84 
85 void ComponentChecker::checkComponentInit(ErrorReport& report, const Component* enclosingComponent,
86  const ComponentLookupAnalysis& componentLookup, const ComponentInit& init,
87  const TypeBinding& binding) {
89  report, enclosingComponent, componentLookup, *init.getComponentType(), init.getSrcLoc(), binding);

◆ checkComponents()

void souffle::ast::transform::ComponentChecker::checkComponents ( ErrorReport report,
const Program program,
const analysis::ComponentLookupAnalysis componentLookup 
)
staticprivate

Definition at line 194 of file ComponentChecker.cpp.

194  : program.getComponentInstantiations()) {
195  checkComponentInit(report, nullptr, componentLookup, *cur, TypeBinding());
196  }
197 }
198 
199 // Check that component names are disjoint from type and relation names.
200 void ComponentChecker::checkComponentNamespaces(ErrorReport& report, const Program& program) {
201  std::map<std::string, SrcLocation> names;
202 
203  // Type and relation name error reporting performed by the SemanticChecker instead

◆ clone()

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

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

Definition at line 52 of file ComponentChecker.h.

◆ getName()

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

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

Definition at line 48 of file ComponentChecker.h.

◆ transform()

bool souffle::ast::transform::ComponentChecker::transform ( TranslationUnit translationUnit)
overrideprivatevirtual

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

Definition at line 47 of file ComponentChecker.cpp.

52  {
53  const QualifiedName& forwarded = binding.find(name);
54  if (!forwarded.empty()) {

The documentation for this class was generated from the following files:
souffle::ast::transform::ComponentChecker::checkComponents
static void checkComponents(ErrorReport &report, const Program &program, const analysis::ComponentLookupAnalysis &componentLookup)
Definition: ComponentChecker.cpp:194
souffle::ast::transform::ComponentChecker::checkComponentNameReference
static const Component * checkComponentNameReference(ErrorReport &report, const Component *enclosingComponent, const analysis::ComponentLookupAnalysis &componentLookup, const std::string &name, const SrcLocation &loc, const analysis::TypeBinding &binding)
Definition: ComponentChecker.cpp:56
souffle::ast::transform::ComponentChecker::checkComponent
static void checkComponent(ErrorReport &report, const Component *enclosingComponent, const analysis::ComponentLookupAnalysis &componentLookup, const Component &component, const analysis::TypeBinding &binding)
Definition: ComponentChecker.cpp:108
souffle::RelationQualifier::OVERRIDABLE
@ OVERRIDABLE
souffle::ast::transform::ComponentChecker::checkComponentInit
static void checkComponentInit(ErrorReport &report, const Component *enclosingComponent, const analysis::ComponentLookupAnalysis &componentLookup, const ComponentInit &init, const analysis::TypeBinding &binding)
Definition: ComponentChecker.cpp:91
relation
Relation & relation
Definition: Reader.h:130
base
T & base
Definition: Reader.h:60
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::transform::ComponentChecker::checkComponentReference
static void checkComponentReference(ErrorReport &report, const Component *enclosingComponent, const analysis::ComponentLookupAnalysis &componentLookup, const ast::ComponentType &type, const SrcLocation &loc, const analysis::TypeBinding &binding)
Definition: ComponentChecker.cpp:75
souffle::ast::transform::ComponentChecker::checkComponentNamespaces
static void checkComponentNamespaces(ErrorReport &report, const Program &program)
Definition: ComponentChecker.cpp:206
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
std::type
ElementType type
Definition: span.h:640