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" 23 #include <openvdb/version.h> 28 #include <unordered_map> 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;
91 const std::pair<bool, bool> mAccess;
92 std::vector<const AccessData*> mUses;
93 std::vector<const AccessData*> mDependencies;
102 return this->accessPattern(name, type).first;
111 return this->accessPattern(name, type).second;
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;
127 return this->accessIndex(name, type) != -1;
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,
176 const bool readsfrom,
177 const bool writesto) {
178 mAccesses.emplace_back(name, type, readsfrom, writesto);
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) {
205 ast::Attribute::nametypeFromToken(attrib, &name, &type);
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) {
223 ast::Attribute::nametypeFromToken(attrib, &name, &type);
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: " <<
293 #endif // OPENVDB_AX_COMPILER_TARGET_REGISTRY_HAS_BEEN_INCLUDED std::pair< bool, bool > accessPattern(const std::string &name, const ast::tokens::CoreType type) const
Definition: AttributeRegistry.h:115
Attributes represent any access to a primitive value, typically associated with the '@' symbol syntax...
Definition: AST.h:1874
const std::string & name() const
Definition: AttributeRegistry.h:67
A Tree is the highest concrete (non-abstract) node in the entire AX AST hierarchy. It represents an entire conversion of a valid AX string.
Definition: AST.h:562
bool reads() const
Definition: AttributeRegistry.h:64
std::shared_ptr< AttributeRegistry > Ptr
Definition: AttributeRegistry.h:42
std::vector< AccessData > AccessDataVec
Definition: AttributeRegistry.h:96
bool isRegistered(const std::string &name, const ast::tokens::CoreType type) const
Returns whether or not an access is registered.
Definition: AttributeRegistry.h:125
OPENVDB_AX_API 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.
bool writes() const
Definition: AttributeRegistry.h:65
const std::vector< const AccessData * > & deps() const
Definition: AttributeRegistry.h:69
bool affectsothers() const
Definition: AttributeRegistry.h:80
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
CoreType
Definition: Tokens.h:31
Definition: Exceptions.h:13
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
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...
ast::tokens::CoreType type() const
Definition: AttributeRegistry.h:68
const std::vector< const AccessData * > & uses() const
Definition: AttributeRegistry.h:70
std::string typeStringFromToken(const CoreType type)
Definition: Tokens.h:118
bool dependson(const AccessData *data) const
Definition: AttributeRegistry.h:72
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.
Registered access details, including its name, type and whether a write handle is required...
Definition: AttributeRegistry.h:48
const AccessDataVec & data() const
Returns a const reference to the vector of registered accesss.
Definition: AttributeRegistry.h:160
This class stores a list of access names, types and their dependency connections. ...
Definition: AttributeRegistry.h:39
CoreType tokenFromTypeString(const std::string &type)
Definition: Tokens.h:66
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
std::string Name
Definition: Name.h:19
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
const std::string tokenname() const
Definition: AttributeRegistry.h:66
std::shared_ptr< const AttributeRegistry > ConstPtr
Definition: AttributeRegistry.h:43
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
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218