16#ifndef OPENVDB_AX_COMPILER_TARGET_REGISTRY_HAS_BEEN_INCLUDED
17#define OPENVDB_AX_COMPILER_TARGET_REGISTRY_HAS_BEEN_INCLUDED
23#include <openvdb/version.h>
28#include <unordered_map>
39class AttributeRegistry
42 using Ptr = std::shared_ptr<AttributeRegistry>;
43 using ConstPtr = std::shared_ptr<const AttributeRegistry>;
60 , mAccess(readsFrom, writesTo)
64 bool reads()
const {
return mAccess.first; }
65 bool writes()
const {
return mAccess.second; }
66 const std::string
tokenname()
const {
return mAttrib.tokenname(); }
67 const std::string&
name()
const {
return mAttrib.name(); }
69 const std::vector<const AccessData*>&
deps()
const {
return mDependencies; }
70 const std::vector<const AccessData*>&
uses()
const {
return mUses; }
74 for (
auto& dep : mDependencies) {
75 if (dep ==
data)
return true;
81 for (
auto& dep : mUses) {
82 if (dep !=
this)
return true;
88 friend AttributeRegistry;
91 const std::pair<bool, bool> mAccess;
92 std::vector<const AccessData*> mUses;
93 std::vector<const AccessData*> mDependencies;
114 inline std::pair<bool,bool>
117 auto*
data = this->
get(name, type);
118 if (!
data)
return std::pair<bool,bool>(
false,
false);
119 return data->mAccess;
138 for (
const auto&
data : mAccesses) {
139 if (
data.type() == type &&
data.name() == name) {
150 for (
const auto&
data : mAccesses) {
152 &&
data.name() == name) {
162 void print(std::ostream& os)
const;
174 addData(
const Name& name,
175 const ast::tokens::CoreType type,
176 const bool readsfrom,
177 const bool writesto) {
178 mAccesses.emplace_back(name, type, readsfrom, writesto);
181 AccessDataVec mAccesses;
192 std::vector<std::string> read, write, all;
196 std::unordered_map<std::string, size_t> indexmap;
199 [&](
const std::vector<std::string>& attribs,
201 const bool writeFlag)
203 std::string name, type;
204 for (
const auto& attrib : attribs) {
208 registry->addData(name, typetoken, readFlag, writeFlag);
209 indexmap[attrib] = idx++;
215 dataBuilder(read,
true,
false);
216 dataBuilder(write,
false,
true);
217 dataBuilder(all,
true,
true);
219 auto depBuilder = [&](
const std::vector<std::string>& attribs) {
221 std::string name, type;
222 for (
const auto& attrib : attribs) {
227 std::vector<std::string> deps;
229 if (deps.empty())
continue;
232 const size_t index = indexmap.at(attrib);
233 AccessData& access = registry->mAccesses[index];
234 for (
const std::string& dep : deps) {
236 const size_t depindex = indexmap.at(dep);
237 access.mDependencies.emplace_back(®istry->mAccesses[depindex]);
250 for (
AccessData& access : registry->mAccesses) {
251 for (
const AccessData& next : registry->mAccesses) {
255 access.mUses.emplace_back(&next);
266 for (
const auto&
data : mAccesses) {
267 os <<
"Attribute: " <<
data.name() <<
", type: " <<
269 os <<
" " <<
"Index : " << idx <<
'\n';
270 os << std::boolalpha;
271 os <<
" " <<
"Reads From : " <<
data.reads() <<
'\n';
272 os <<
" " <<
"Writes To : " <<
data.writes() <<
'\n';
273 os << std::noboolalpha;
274 os <<
" " <<
"Dependencies : " <<
data.mDependencies.size() <<
'\n';
275 for (
const auto& dep :
data.mDependencies) {
276 os <<
" " <<
"Attribute: " << dep->name() <<
" type: " <<
279 os <<
" " <<
"Usage : " <<
data.mUses.size() <<
'\n';
280 for (
const auto& dep :
data.mUses) {
281 os <<
" " <<
"Attribute: " << dep->name() <<
" type: " <<
Provides the definition for every abstract and concrete derived class which represent a particular ab...
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Retrieve intrinsic information from AX AST by performing various traversal algorithms.
Various function and operator tokens used throughout the AST and code generation.
This class stores a list of access names, types and their dependency connections.
Definition AttributeRegistry.h:40
std::shared_ptr< AttributeRegistry > Ptr
Definition AttributeRegistry.h:42
const AccessData * get(const std::string &name, const ast::tokens::CoreType type) const
Definition AttributeRegistry.h:148
int64_t accessIndex(const std::string &name, const ast::tokens::CoreType type) const
Returns whether or not an access is registered.
Definition AttributeRegistry.h:134
bool isReadable(const std::string &name, const ast::tokens::CoreType type) const
Definition AttributeRegistry.h:100
bool isWritable(const std::string &name, const ast::tokens::CoreType type) const
Returns whether or not an access is required to be written to. If no access with this name has been r...
Definition AttributeRegistry.h:109
bool isRegistered(const std::string &name, const ast::tokens::CoreType type) const
Returns whether or not an access is registered.
Definition AttributeRegistry.h:125
std::vector< AccessData > AccessDataVec
Definition AttributeRegistry.h:96
std::pair< bool, bool > accessPattern(const std::string &name, const ast::tokens::CoreType type) const
Definition AttributeRegistry.h:115
static AttributeRegistry::Ptr create(const ast::Tree &tree)
Definition AttributeRegistry.h:189
void print(std::ostream &os) const
Definition AttributeRegistry.h:263
const AccessDataVec & data() const
Returns a const reference to the vector of registered accesss.
Definition AttributeRegistry.h:160
std::shared_ptr< const AttributeRegistry > ConstPtr
Definition AttributeRegistry.h:43
std::string typeStringFromToken(const CoreType type)
Definition Tokens.h:118
CoreType tokenFromTypeString(const std::string &type)
Definition Tokens.h:66
CoreType
Definition Tokens.h:32
@ UNKNOWN
Definition Tokens.h:63
OPENVDB_AX_API void catalogueAttributeTokens(const ast::Node &node, std::vector< std::string > *readOnly, std::vector< std::string > *writeOnly, std::vector< std::string > *readWrite)
Parse all attributes into three unique vectors which represent how they are accessed within the synta...
OPENVDB_AX_API void attributeDependencyTokens(const ast::Tree &tree, const std::string &name, const tokens::CoreType type, std::vector< std::string > &dependencies)
Populate a list of attribute names which the given attribute depends on.
Definition PointDataGrid.h:170
std::string Name
Definition Name.h:19
Definition Exceptions.h:13
Registered access details, including its name, type and whether a write handle is required.
Definition AttributeRegistry.h:49
ast::tokens::CoreType type() const
Definition AttributeRegistry.h:68
const std::string tokenname() const
Definition AttributeRegistry.h:66
const std::string & name() const
Definition AttributeRegistry.h:67
bool reads() const
Definition AttributeRegistry.h:64
const std::vector< const AccessData * > & uses() const
Definition AttributeRegistry.h:70
AccessData(const Name &name, const ast::tokens::CoreType type, const bool readsFrom, const bool writesTo)
Storage for access name, type and writesTo details.
Definition AttributeRegistry.h:55
const std::vector< const AccessData * > & deps() const
Definition AttributeRegistry.h:69
bool dependson(const AccessData *data) const
Definition AttributeRegistry.h:72
bool affectsothers() const
Definition AttributeRegistry.h:80
bool writes() const
Definition AttributeRegistry.h:65
Attributes represent any access to a primitive value, typically associated with the '@' symbol syntax...
Definition AST.h:1875
static bool nametypeFromToken(const std::string &token, std::string *name, std::string *type)
Static method which splits a valid attribute token into its name and type counterparts....
Definition AST.h:1975
A Tree is the highest concrete (non-abstract) node in the entire AX AST hierarchy....
Definition AST.h:563
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218