souffle  2.0.2-371-g6315b36
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
souffle::ast::analysis::ConstraintAnalysis< AnalysisVar > Class Template Reference

A base class for ConstraintAnalysis collecting constraints for an analysis by visiting every node of a given AST. More...

#include <Constraint.h>

Inheritance diagram for souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >:
Inheritance graph
Collaboration diagram for souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >:
Collaboration graph

Public Types

using constraint_type = std::shared_ptr< Constraint< AnalysisVar > >
 
using solution_type = std::map< const Argument *, value_type >
 
using value_type = typename AnalysisVar::property_space::value_type
 

Public Member Functions

solution_type analyse (const Clause &clause, std::ostream *debugOutput=nullptr)
 Runs this constraint analysis on the given clause. More...
 
virtual void collectConstraints (const Clause &clause)
 
- Public Member Functions inherited from souffle::ast::Visitor< void >
void operator() (const Node &node, Params... args)
 The main entry for the user allowing visitors to be utilized as functions. More...
 
virtual void visit (const Node &node, Params... args)
 The main entry for a visit process conducting the dispatching of a visit to the various sub-types of Nodes. More...
 
virtual ~Visitor ()=default
 A virtual destructor. More...
 

Protected Member Functions

void addConstraint (const constraint_type &constraint)
 Adds another constraint to the internally maintained list of constraints. More...
 
AnalysisVar getVar (const Argument &arg)
 A utility function mapping an Argument to its associated analysis variable. More...
 
AnalysisVar getVar (const Argument *arg)
 A utility function mapping an Argument to its associated analysis variable. More...
 
- Protected Member Functions inherited from souffle::ast::Visitor< void >
 LINK (AlgebraicDataType, Type)
 
 LINK (Argument, Node)
 
 LINK (Attribute, Node)
 
 LINK (Clause, Node)
 
 LINK (Component, Node)
 
 LINK (ComponentInit, Node)
 
 LINK (ComponentType, Node)
 
 LINK (Literal, Node)
 
 LINK (Pragma, Node)
 
 LINK (Program, Node)
 
 LINK (RecordType, Type)
 
 LINK (Relation, Node)
 
 LINK (SubsetType, Type)
 
 LINK (Type, Node)
 
 LINK (UnionType, Type)
 
virtual void visitNode (const Node &, Params...)
 The base case for all visitors – if no more specific overload was defined. More...
 

Protected Attributes

Assignment< AnalysisVar > assignment
 
Problem< AnalysisVar > constraints
 The list of constraints making underlying this analysis. More...
 
std::map< std::string, AnalysisVar > variables
 A map mapping variables to unique instances to facilitate the unification of variables. More...
 

Detailed Description

template<typename AnalysisVar>
class souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >

A base class for ConstraintAnalysis collecting constraints for an analysis by visiting every node of a given AST.

The collected constraints are then utilized to obtain the desired analysis result.

Template Parameters
AnalysisVarthe type of variable (and included property space) to be utilized by this analysis.

Definition at line 64 of file Constraint.h.

Member Typedef Documentation

◆ constraint_type

template<typename AnalysisVar >
using souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::constraint_type = std::shared_ptr<Constraint<AnalysisVar> >

Definition at line 67 of file Constraint.h.

◆ solution_type

template<typename AnalysisVar >
using souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::solution_type = std::map<const Argument*, value_type>

Definition at line 68 of file Constraint.h.

◆ value_type

template<typename AnalysisVar >
using souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::value_type = typename AnalysisVar::property_space::value_type

Definition at line 66 of file Constraint.h.

Member Function Documentation

◆ addConstraint()

template<typename AnalysisVar >
void souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::addConstraint ( const constraint_type constraint)
inlineprotected

Adds another constraint to the internally maintained list of constraints.

Definition at line 129 of file Constraint.h.

◆ analyse()

template<typename AnalysisVar >
solution_type souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::analyse ( const Clause clause,
std::ostream *  debugOutput = nullptr 
)
inline

Runs this constraint analysis on the given clause.

Parameters
clausethe close to be analysed
debuga flag enabling the printing of debug information
Returns
an assignment mapping a property to each argument in the given clause

Definition at line 81 of file Constraint.h.

81  {
82  *debugOutput << "Clause: " << clause << "\n";
83  *debugOutput << "Problem:\n" << constraints << "\n";
84  *debugOutput << "Solution:\n" << assignment << "\n";
85  }
86 
87  // convert assignment to result
88  solution_type solution;
89  visitDepthFirst(clause, [&](const Argument& arg) { solution[&arg] = assignment[getVar(arg)]; });
90  return solution;
91  }
92 
93 protected:
94  /**
95  * A utility function mapping an Argument to its associated analysis variable.
96  *
97  * @param arg the AST argument to be mapped

◆ collectConstraints()

template<typename AnalysisVar >
virtual void souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::collectConstraints ( const Clause clause)
inlinevirtual

◆ getVar() [1/2]

template<typename AnalysisVar >
AnalysisVar souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::getVar ( const Argument arg)
inlineprotected

A utility function mapping an Argument to its associated analysis variable.

Parameters
argthe AST argument to be mapped
Returns
the analysis variable representing its associated value

Definition at line 106 of file Constraint.h.

108  {var->getName(), AnalysisVar(var)}).first;
109  return res->second;
110  }
111 
112  /**
113  * A utility function mapping an Argument to its associated analysis variable.
114  *
115  * @param arg the AST argument to be mapped
116  * @return the analysis variable representing its associated value

◆ getVar() [2/2]

template<typename AnalysisVar >
AnalysisVar souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::getVar ( const Argument arg)
inlineprotected

A utility function mapping an Argument to its associated analysis variable.

Parameters
argthe AST argument to be mapped
Returns
the analysis variable representing its associated value

Definition at line 124 of file Constraint.h.

Field Documentation

◆ assignment

template<typename AnalysisVar >
Assignment<AnalysisVar> souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::assignment
protected

◆ constraints

template<typename AnalysisVar >
Problem<AnalysisVar> souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::constraints
protected

The list of constraints making underlying this analysis.

Definition at line 136 of file Constraint.h.

Referenced by souffle::ast::analysis::ConstraintAnalysis< TypeVar >::analyse(), and souffle::ast::analysis::ConstraintAnalysis< TypeVar >::collectConstraints().

◆ variables

template<typename AnalysisVar >
std::map<std::string, AnalysisVar> souffle::ast::analysis::ConstraintAnalysis< AnalysisVar >::variables
protected

A map mapping variables to unique instances to facilitate the unification of variables.

Definition at line 139 of file Constraint.h.


The documentation for this class was generated from the following file:
souffle::ast::analysis::ConstraintAnalysis::getVar
AnalysisVar getVar(const Argument &arg)
A utility function mapping an Argument to its associated analysis variable.
Definition: Constraint.h:106
souffle::ast::analysis::ConstraintAnalysis::assignment
Assignment< AnalysisVar > assignment
Definition: Constraint.h:133
souffle::ast::analysis::ConstraintAnalysis::solution_type
std::map< const Argument *, value_type > solution_type
Definition: Constraint.h:68
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::ConstraintAnalysis::constraints
Problem< AnalysisVar > constraints
The list of constraints making underlying this analysis.
Definition: Constraint.h:136