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>
27#include <unordered_map>
41 using Ptr = std::shared_ptr<AttributeRegistry>;
42 using ConstPtr = std::shared_ptr<const AttributeRegistry>;
59 , mAccess(readsFrom, writesTo)
63 bool reads()
const {
return mAccess.first; }
64 bool writes()
const {
return mAccess.second; }
65 const std::string
tokenname()
const {
return mAttrib.tokenname(); }
66 const std::string&
name()
const {
return mAttrib.name(); }
68 const std::vector<const AccessData*>&
deps()
const {
return mDependencies; }
69 const std::vector<const AccessData*>&
uses()
const {
return mUses; }
73 for (
auto& dep : mDependencies) {
74 if (dep == data)
return true;
80 for (
auto& dep : mUses) {
81 if (dep !=
this)
return true;
90 const std::pair<bool, bool> mAccess;
91 std::vector<const AccessData*> mUses;
92 std::vector<const AccessData*> mDependencies;
101 return this->accessPattern(name, type).first;
110 return this->accessPattern(name, type).second;
113 inline std::pair<bool,bool>
116 auto* data = this->get(name, type);
117 if (!data)
return std::pair<bool,bool>(
false,
false);
118 return data->mAccess;
126 return this->accessIndex(name, type) != -1;
137 for (
const auto& data : mAccesses) {
138 if (data.type() == type && data.name() == name) {
149 for (
const auto& data : mAccesses) {
150 if ((type == ast::tokens::UNKNOWN || data.type() == type)
151 && data.name() == name) {
161 void print(std::ostream& os)
const;
173 addData(
const Name& name,
174 const ast::tokens::CoreType type,
175 const bool readsfrom,
176 const bool writesto) {
177 mAccesses.emplace_back(name, type, readsfrom, writesto);
180 AccessDataVec mAccesses;
191 std::vector<std::string> read, write, all;
192 ast::catalogueAttributeTokens(tree, &read, &write, &all);
195 std::unordered_map<std::string, size_t> indexmap;
198 [&](
const std::vector<std::string>& attribs,
200 const bool writeFlag)
202 std::string name, type;
203 for (
const auto& attrib : attribs) {
204 ast::Attribute::nametypeFromToken(attrib, &name, &type);
206 ast::tokens::tokenFromTypeString(type);
207 registry->addData(name, typetoken, readFlag, writeFlag);
208 indexmap[attrib] = idx++;
214 dataBuilder(read,
true,
false);
215 dataBuilder(write,
false,
true);
216 dataBuilder(all,
true,
true);
218 auto depBuilder = [&](
const std::vector<std::string>& attribs) {
220 std::string name, type;
221 for (
const auto& attrib : attribs) {
222 ast::Attribute::nametypeFromToken(attrib, &name, &type);
224 ast::tokens::tokenFromTypeString(type);
226 std::vector<std::string> deps;
227 ast::attributeDependencyTokens(tree, name, typetoken, deps);
228 if (deps.empty())
continue;
230 assert(indexmap.find(attrib) != indexmap.cend());
231 const size_t index = indexmap.at(attrib);
232 AccessData& access = registry->mAccesses[index];
233 for (
const std::string& dep : deps) {
234 assert(indexmap.find(dep) != indexmap.cend());
235 const size_t depindex = indexmap.at(dep);
236 access.mDependencies.emplace_back(®istry->mAccesses[depindex]);
249 for (
AccessData& access : registry->mAccesses) {
250 for (
const AccessData& next : registry->mAccesses) {
253 if (next.dependson(&access)) {
254 access.mUses.emplace_back(&next);
262inline void AttributeRegistry::print(std::ostream& os)
const
265 for (
const auto& data : mAccesses) {
266 os <<
"Attribute: " << data.name() <<
", type: " <<
267 ast::tokens::typeStringFromToken(data.type()) <<
'\n';
268 os <<
" " <<
"Index : " << idx <<
'\n';
269 os << std::boolalpha;
270 os <<
" " <<
"Reads From : " << data.reads() <<
'\n';
271 os <<
" " <<
"Writes To : " << data.writes() <<
'\n';
272 os << std::noboolalpha;
273 os <<
" " <<
"Dependencies : " << data.mDependencies.size() <<
'\n';
274 for (
const auto& dep : data.mDependencies) {
275 os <<
" " <<
"Attribute: " << dep->name() <<
" type: " <<
276 ast::tokens::typeStringFromToken(dep->type()) <<
'\n';
278 os <<
" " <<
"Usage : " << data.mUses.size() <<
'\n';
279 for (
const auto& dep : data.mUses) {
280 os <<
" " <<
"Attribute: " << dep->name() <<
" type: " <<
281 ast::tokens::typeStringFromToken(dep->type()) <<
'\n';
Provides the definition for every abstract and concrete derived class which represent a particular ab...
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:39
std::shared_ptr< AttributeRegistry > Ptr
Definition AttributeRegistry.h:41
const AccessData * get(const std::string &name, const ast::tokens::CoreType type) const
Definition AttributeRegistry.h:147
int64_t accessIndex(const std::string &name, const ast::tokens::CoreType type) const
Returns whether or not an access is registered.
Definition AttributeRegistry.h:133
bool isReadable(const std::string &name, const ast::tokens::CoreType type) const
Definition AttributeRegistry.h:99
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:108
bool isRegistered(const std::string &name, const ast::tokens::CoreType type) const
Returns whether or not an access is registered.
Definition AttributeRegistry.h:124
std::vector< AccessData > AccessDataVec
Definition AttributeRegistry.h:95
std::pair< bool, bool > accessPattern(const std::string &name, const ast::tokens::CoreType type) const
Definition AttributeRegistry.h:114
const AccessDataVec & data() const
Returns a const reference to the vector of registered accesss.
Definition AttributeRegistry.h:159
std::shared_ptr< const AttributeRegistry > ConstPtr
Definition AttributeRegistry.h:42
CoreType
Definition Tokens.h:32
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:48
ast::tokens::CoreType type() const
Definition AttributeRegistry.h:67
const std::string tokenname() const
Definition AttributeRegistry.h:65
const std::string & name() const
Definition AttributeRegistry.h:66
bool reads() const
Definition AttributeRegistry.h:63
const std::vector< const AccessData * > & uses() const
Definition AttributeRegistry.h:69
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:54
const std::vector< const AccessData * > & deps() const
Definition AttributeRegistry.h:68
bool dependson(const AccessData *data) const
Definition AttributeRegistry.h:71
bool affectsothers() const
Definition AttributeRegistry.h:79
bool writes() const
Definition AttributeRegistry.h:64
Attributes represent any access to a primitive value, typically associated with the '@' symbol syntax...
Definition AST.h:1874
A Tree is the highest concrete (non-abstract) node in the entire AX AST hierarchy....
Definition AST.h:562
#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:212