souffle  2.0.2-371-g6315b36
Public Member Functions | Static Public Attributes | Private Attributes
souffle::ast::analysis::ComponentLookupAnalysis Class Reference

#include <ComponentLookup.h>

Inheritance diagram for souffle::ast::analysis::ComponentLookupAnalysis:
Inheritance graph
Collaboration diagram for souffle::ast::analysis::ComponentLookupAnalysis:
Collaboration graph

Public Member Functions

 ComponentLookupAnalysis ()
 
const ComponentgetComponent (const Component *scope, const std::string &name, const TypeBinding &activeBinding) const
 Performs a lookup operation for a component with the given name within the addressed scope. More...
 
void run (const TranslationUnit &translationUnit) override
 run analysis for a Ast translation unit More...
 
- Public Member Functions inherited from souffle::ast::analysis::Analysis
 Analysis (std::string identifier)
 
virtual const std::string & getName () const
 get name of the analysis More...
 
virtual void print (std::ostream &) const
 print the analysis result in HTML format More...
 
virtual ~Analysis ()=default
 

Static Public Attributes

static constexpr const char * name = "component-lookup"
 

Private Attributes

std::map< const Component *, const Component * > enclosingComponent
 
std::set< const Component * > globalScopeComponents
 
std::map< const Component *, std::set< const Component * > > nestedComponents
 

Additional Inherited Members

- Protected Attributes inherited from souffle::ast::analysis::Analysis
const std::string identifier
 

Detailed Description

Definition at line 78 of file ComponentLookup.h.

Constructor & Destructor Documentation

◆ ComponentLookupAnalysis()

souffle::ast::analysis::ComponentLookupAnalysis::ComponentLookupAnalysis ( )
inline

Definition at line 82 of file ComponentLookup.h.

Member Function Documentation

◆ getComponent()

const Component * souffle::ast::analysis::ComponentLookupAnalysis::getComponent ( const Component scope,
const std::string &  name,
const TypeBinding activeBinding 
) const

Performs a lookup operation for a component with the given name within the addressed scope.

Parameters
scopethe component scope to lookup in (null for global scope)
namethe name of the component to be looking for
Returns
a pointer to the obtained component or null if there is no such component.

Definition at line 48 of file ComponentLookup.cpp.

53  {
54  for (const Component* cur : searchScope->getComponents()) {
55  if (cur->getComponentType()->getName() == toString(boundName)) {
56  return cur;
57  }
58  }
59  auto found = enclosingComponent.find(searchScope);
60  if (found != enclosingComponent.end()) {
61  searchScope = found->second;
62  } else {
63  searchScope = nullptr;
64  break;
65  }
66  }
67 
68  // check global scope
69  for (const Component* cur : globalScopeComponents) {
70  if (cur->getComponentType()->getName() == toString(boundName)) {
71  return cur;
72  }
73  }
74 
75  // no such component in scope
76  return nullptr;
77 }
78 
79 } // namespace souffle::ast::analysis

◆ run()

void souffle::ast::analysis::ComponentLookupAnalysis::run ( const TranslationUnit )
overridevirtual

run analysis for a Ast translation unit

Implements souffle::ast::analysis::Analysis.

Definition at line 33 of file ComponentLookup.cpp.

33  {
34  nestedComponents[&cur];
35  for (Component* nestedComponent : cur.getComponents()) {
36  nestedComponents[&cur].insert(nestedComponent);
37  enclosingComponent[nestedComponent] = &cur;
38  }
39  });
40 }
41 
43  const Component* scope, const std::string& name, const TypeBinding& activeBinding) const {
44  // forward according to binding (we do not do this recursively on purpose)
45  QualifiedName boundName = activeBinding.find(name);
46  if (boundName.empty()) {

References souffle::ast::Component::getComponents(), and nestedComponents.

Here is the call graph for this function:

Field Documentation

◆ enclosingComponent

std::map<const Component*, const Component*> souffle::ast::analysis::ComponentLookupAnalysis::enclosingComponent
private

Definition at line 102 of file ComponentLookup.h.

◆ globalScopeComponents

std::set<const Component*> souffle::ast::analysis::ComponentLookupAnalysis::globalScopeComponents
private

Definition at line 98 of file ComponentLookup.h.

◆ name

constexpr const char* souffle::ast::analysis::ComponentLookupAnalysis::name = "component-lookup"
staticconstexpr

Definition at line 80 of file ComponentLookup.h.

◆ nestedComponents

std::map<const Component*, std::set<const Component*> > souffle::ast::analysis::ComponentLookupAnalysis::nestedComponents
private

Definition at line 100 of file ComponentLookup.h.

Referenced by run().


The documentation for this class was generated from the following files:
souffle::ast::analysis::ComponentLookupAnalysis::getComponent
const Component * getComponent(const Component *scope, const std::string &name, const TypeBinding &activeBinding) const
Performs a lookup operation for a component with the given name within the addressed scope.
Definition: ComponentLookup.cpp:48
souffle::ast::analysis::ComponentLookupAnalysis::globalScopeComponents
std::set< const Component * > globalScopeComponents
Definition: ComponentLookup.h:98
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::analysis::ComponentLookupAnalysis::name
static constexpr const char * name
Definition: ComponentLookup.h:80
souffle::ast::analysis::ComponentLookupAnalysis::nestedComponents
std::map< const Component *, std::set< const Component * > > nestedComponents
Definition: ComponentLookup.h:100
souffle::ast::analysis::ComponentLookupAnalysis::enclosingComponent
std::map< const Component *, const Component * > enclosingComponent
Definition: ComponentLookup.h:102