systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
sc_ast_matchers::InstanceMatcher Class Reference

Class InstanceMatcher. More...

#include <InstanceMatcher.h>

Inheritance diagram for sc_ast_matchers::InstanceMatcher:
Collaboration diagram for sc_ast_matchers::InstanceMatcher:

Public Types

typedef std::tuple< std::string, clang::Decl *, ModuleInstanceTypeInstanceDeclType
 
typedef std::vector< InstanceDeclTypeInstanceDeclarationsType
 
typedef std::pair< clang::Decl *, ModuleInstanceTypeModuleInstanceTuple
 
typedef std::map< clang::Decl *, ModuleInstanceTypeInstanceDeclarations
 

Public Member Functions

InstanceMatcheroperator= (const InstanceMatcher &from)
 
const InstanceDeclarationsgetInstanceMap ()
 
void setParentFieldDecl (clang::ValueDecl *parent_fd)
 
bool findInstanceByVariableType (clang::CXXRecordDecl *decl, std::vector< InstanceDeclType > &found_instances)
 
auto match_ctor_arg (const std::string &bind_arg_name, const std::string &bind_ctor_expr)
 
auto match_is_derived_sc_module (const std::string &bind_name)
 
void registerMatchers (MatchFinder &finder)
 
void parseVarDecl (clang::VarDecl *instance_decl, std::string &instance_name)
 
void parseFieldDecl (clang::FieldDecl *instance_decl, clang::ValueDecl *parent_decl, std::string instance_name, IndexMapType &index_map)
 
virtual void run (const MatchFinder::MatchResult &result)
 
void dump ()
 

Private Attributes

InstanceDeclarations instance_map_
 deprecated
 
clang::ValueDecl * parent_fd_
 

Detailed Description

Class InstanceMatcher.

Definition at line 70 of file InstanceMatcher.h.

Member Typedef Documentation

◆ InstanceDeclarations

◆ InstanceDeclarationsType

◆ InstanceDeclType

Definition at line 73 of file InstanceMatcher.h.

◆ ModuleInstanceTuple

Store all instances in a map. The map key should be the Decl*. This will work for both FieldDecl (instances within sub-modules) and VarDecl separate modules in sc_main().

Definition at line 81 of file InstanceMatcher.h.

Member Function Documentation

◆ dump()

void sc_ast_matchers::InstanceMatcher::dump ( )
inline

Definition at line 614 of file InstanceMatcher.h.

◆ findInstanceByVariableType()

bool sc_ast_matchers::InstanceMatcher::findInstanceByVariableType ( clang::CXXRecordDecl * decl,
std::vector< InstanceDeclType > & found_instances )
inline

Definition at line 116 of file InstanceMatcher.h.

◆ getInstanceMap()

const InstanceDeclarations & sc_ast_matchers::InstanceMatcher::getInstanceMap ( )
inline

Definition at line 108 of file InstanceMatcher.h.

◆ match_ctor_arg()

auto sc_ast_matchers::InstanceMatcher::match_ctor_arg ( const std::string & bind_arg_name,
const std::string & bind_ctor_expr )
inline

Definition at line 176 of file InstanceMatcher.h.

◆ match_is_derived_sc_module()

auto sc_ast_matchers::InstanceMatcher::match_is_derived_sc_module ( const std::string & bind_name)
inline

Definition at line 182 of file InstanceMatcher.h.

◆ operator=()

InstanceMatcher & sc_ast_matchers::InstanceMatcher::operator= ( const InstanceMatcher & from)
inline

Definition at line 103 of file InstanceMatcher.h.

◆ parseFieldDecl()

void sc_ast_matchers::InstanceMatcher::parseFieldDecl ( clang::FieldDecl * instance_decl,
clang::ValueDecl * parent_decl,
std::string instance_name,
IndexMapType & index_map )
inline

Get all the 1D, 2D and 3D array type pointers.

We need to set the array_type pointer to the deepest array. That is if it is a 3D array then we need to set it to the third dimension element type to get the correct CXXRecordDecl.

Find if an instance already exists. If it does exist.

Definition at line 393 of file InstanceMatcher.h.

◆ parseVarDecl()

void sc_ast_matchers::InstanceMatcher::parseVarDecl ( clang::VarDecl * instance_decl,
std::string & instance_name )
inline

This is the main object's constructor name

We do not get the instance name from within the field declaration. Get the type of the class of the field.

auto instance_name{cast<StringLiteral>(ctor_arg)->getString().str()};

Definition at line 348 of file InstanceMatcher.h.

◆ registerMatchers()

void sc_ast_matchers::InstanceMatcher::registerMatchers ( MatchFinder & finder)
inline

We will have two matchers.

Match when the following conditions are satisifed:

  • It is a FieldDecl
  • It has a type that is a C++ class that is derived from sc_module

These are field members within a class declaration. Hence, we only need to collect their FieldDecl pointers and their variable names. Their instance names would appear when the constructor of the class that has these field members within it. This constructor would use the initialization list to provide an argument, which would be the instance name.

Add the two matchers.

Definition at line 189 of file InstanceMatcher.h.

◆ run()

virtual void sc_ast_matchers::InstanceMatcher::run ( const MatchFinder::MatchResult & result)
inlinevirtual

If parent_fd_ has been set, then use that. Otherwise, pick it up from the matcher.

ctor_fd: Field initialized in the constructor. ctor_init: Constructor initializer. parent_fd: The FieldDecl whose CXXRecordDecl has the initialization. Thus, it is the parent FieldDecl.

For arrays, an InitListExpr is generated. For non-arrays, CXXConstructExpr is directly castable.

If it is an array, then get to its InitListExpr, and then get the first element's constructor.

Definition at line 511 of file InstanceMatcher.h.

◆ setParentFieldDecl()

void sc_ast_matchers::InstanceMatcher::setParentFieldDecl ( clang::ValueDecl * parent_fd)
inline

Definition at line 110 of file InstanceMatcher.h.

Member Data Documentation

◆ instance_map_

InstanceDeclarations sc_ast_matchers::InstanceMatcher::instance_map_
private

deprecated

Instances can come in two forms: FieldDecl: this is when they are members of a class. VarDecl : this is when they are simply variables such as in functions or in the main().

The way to identify them both together is to look at its base class Decl. Then use dyn_cast<> to detect whether it is one of the two above mentioned types. Map of Decl* => ModuleInstanceType

Definition at line 98 of file InstanceMatcher.h.

◆ parent_fd_

clang::ValueDecl* sc_ast_matchers::InstanceMatcher::parent_fd_
private

Definition at line 100 of file InstanceMatcher.h.


The documentation for this class was generated from the following file: