16 #ifndef OPENVDB_AX_COMPILER_TARGET_REGISTRY_HAS_BEEN_INCLUDED
17 #define OPENVDB_AX_COMPILER_TARGET_REGISTRY_HAS_BEEN_INCLUDED
19 #include "../ast/AST.h"
20 #include "../ast/Tokens.h"
21 #include "../ast/Scanners.h"
25 #include <unordered_map>
39 using Ptr = std::shared_ptr<AttributeRegistry>;
40 using ConstPtr = std::shared_ptr<const AttributeRegistry>;
57 , mAccess(readsFrom, writesTo)
61 bool reads()
const {
return mAccess.first; }
62 bool writes()
const {
return mAccess.second; }
63 const std::string
tokenname()
const {
return mAttrib.tokenname(); }
64 const std::string&
name()
const {
return mAttrib.name(); }
66 const std::vector<const AccessData*>&
deps()
const {
return mDependencies; }
67 const std::vector<const AccessData*>&
uses()
const {
return mUses; }
70 for (
auto& dep : mDependencies) {
71 if (dep == data)
return true;
77 for (
auto& dep : mUses) {
78 if (dep !=
this)
return true;
87 const std::pair<bool, bool> mAccess;
88 std::vector<const AccessData*> mUses;
89 std::vector<const AccessData*> mDependencies;
98 return this->accessPattern(name, type).first;
107 return this->accessPattern(name, type).second;
110 inline std::pair<bool,bool>
113 for (
const auto& data : mAccesses) {
115 && data.name() == name) {
119 return std::pair<bool,bool>(
false,
false);
127 return this->accessIndex(name, type) != -1;
138 for (
const auto& data : mAccesses) {
139 if (data.type() == type && data.name() == name) {
150 void print(std::ostream& os)
const;
162 addData(
const Name& name,
164 const bool readsfrom,
165 const bool writesto) {
166 mAccesses.emplace_back(name, type, readsfrom, writesto);
169 AccessDataVec mAccesses;
180 std::vector<std::string> read, write, all;
184 std::unordered_map<std::string, size_t> indexmap;
187 [&](
const std::vector<std::string>& attribs,
189 const bool writeFlag)
191 std::string name, type;
192 for (
const auto& attrib : attribs) {
193 ast::Attribute::nametypeFromToken(attrib, &name, &type);
196 registry->addData(name, typetoken, readFlag, writeFlag);
197 indexmap[attrib] = idx++;
203 dataBuilder(read,
true,
false);
204 dataBuilder(write,
false,
true);
205 dataBuilder(all,
true,
true);
207 auto depBuilder = [&](
const std::vector<std::string>& attribs) {
209 std::string name, type;
210 for (
const auto& attrib : attribs) {
211 ast::Attribute::nametypeFromToken(attrib, &name, &type);
215 std::vector<std::string> deps;
217 if (deps.empty())
continue;
219 assert(indexmap.find(attrib) != indexmap.cend());
220 const size_t index = indexmap.at(attrib);
221 AccessData& access = registry->mAccesses[index];
222 for (
const std::string& dep : deps) {
223 assert(indexmap.find(dep) != indexmap.cend());
224 const size_t depindex = indexmap.at(dep);
225 access.mDependencies.emplace_back(®istry->mAccesses[depindex]);
238 for (
AccessData& access : registry->mAccesses) {
239 for (
const AccessData& next : registry->mAccesses) {
243 access.mUses.emplace_back(&next);
254 for (
const auto& data : mAccesses) {
255 os <<
"Attribute: " << data.name() <<
", type: " <<
257 os <<
" " <<
"Index : " << idx <<
'\n';
258 os << std::boolalpha;
259 os <<
" " <<
"Reads From : " << data.reads() <<
'\n';
260 os <<
" " <<
"Writes To : " << data.writes() <<
'\n';
261 os << std::noboolalpha;
262 os <<
" " <<
"Dependencies : " << data.mDependencies.size() <<
'\n';
263 for (
const auto& dep : data.mDependencies) {
264 os <<
" " <<
"Attribute: " << dep->name() <<
" type: " <<
267 os <<
" " <<
"Usage : " << data.mUses.size() <<
'\n';
268 for (
const auto& dep : data.mUses) {
269 os <<
" " <<
"Attribute: " << dep->name() <<
" type: " <<
This class stores a list of access names, types and their dependency connections.
Definition: AttributeRegistry.h:37
std::shared_ptr< AttributeRegistry > Ptr
Definition: AttributeRegistry.h:39
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:96
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:105
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:92
std::pair< bool, bool > accessPattern(const std::string &name, const ast::tokens::CoreType type) const
Definition: AttributeRegistry.h:111
const AccessDataVec & data() const
Returns a const reference to the vector of registered accesss.
Definition: AttributeRegistry.h:148
std::shared_ptr< const AttributeRegistry > ConstPtr
Definition: AttributeRegistry.h:40
std::string typeStringFromToken(const CoreType type)
Definition: Tokens.h:118
CoreType
Definition: Tokens.h:32
@ UNKNOWN
Definition: Tokens.h:63
CoreType tokenFromTypeString(const std::string &type)
Definition: Tokens.h:66
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...
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.
void print(const ast::Node &node, const bool numberStatements=true, std::ostream &os=std::cout, const char *indent=" ")
Writes a descriptive printout of a Node hierarchy into a target stream.
std::string Name
Definition: Name.h:17
Definition: openvdb/Exceptions.h:13
Registered access details, including its name, type and whether a write handle is required.
Definition: AttributeRegistry.h:46
ast::tokens::CoreType type() const
Definition: AttributeRegistry.h:65
const std::string tokenname() const
Definition: AttributeRegistry.h:63
bool reads() const
Definition: AttributeRegistry.h:61
const std::vector< const AccessData * > & deps() const
Definition: AttributeRegistry.h:66
const std::vector< const AccessData * > & uses() const
Definition: AttributeRegistry.h:67
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:52
bool dependson(const AccessData *data) const
Definition: AttributeRegistry.h:69
bool affectsothers() const
Definition: AttributeRegistry.h:76
const std::string & name() const
Definition: AttributeRegistry.h:64
bool writes() const
Definition: AttributeRegistry.h:62
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
Library and file format version numbers.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:101
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:153