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> 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) {
151 && data.name() == name) {
161 void print(std::ostream& os)
const;
173 addData(
const Name& name,
175 const bool readsfrom,
176 const bool writesto) {
177 mAccesses.emplace_back(name, type, readsfrom, writesto);
191 std::vector<std::string>
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);
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);
226 std::vector<std::string> 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) {
254 access.mUses.emplace_back(&next);
265 for (
const auto& data : mAccesses) {
266 os <<
"Attribute: " << data.name() <<
", type: " <<
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: " <<
278 os <<
" " <<
"Usage : " << data.mUses.size() <<
'\n';
279 for (
const auto& dep : data.mUses) {
280 os <<
" " <<
"Attribute: " << dep->name() <<
" type: " <<
292 #endif // OPENVDB_AX_COMPILER_TARGET_REGISTRY_HAS_BEEN_INCLUDED bool dependson(const AccessData *data) const
Definition: AttributeRegistry.h:71
std::pair< bool, bool > accessPattern(const std::string &name, const ast::tokens::CoreType type) const
Definition: AttributeRegistry.h:114
bool isReadable(const std::string &name, const ast::tokens::CoreType type) const
Definition: AttributeRegistry.h:99
bool isRegistered(const std::string &name, const ast::tokens::CoreType type) const
Returns whether or not an access is registered.
Definition: AttributeRegistry.h:124
CoreType tokenFromTypeString(const std::string &type)
Definition: Tokens.h:66
bool writes() const
Definition: AttributeRegistry.h:64
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
static fileSize_t write(std::ostream &os, const GridHandle< BufferT > &handle, Codec codec)
const std::string & name() const
Definition: AttributeRegistry.h:66
std::string typeStringFromToken(const CoreType type)
Definition: Tokens.h:118
const std::string tokenname() const
Definition: AttributeRegistry.h:65
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.
static void read(std::istream &is, GridHandle< BufferT > &handle, Codec codec)
CoreType
Definition: Tokens.h:31
const std::vector< const AccessData * > & uses() const
Definition: AttributeRegistry.h:69
std::string Name
Definition: Name.h:17
const std::vector< const AccessData * > & deps() const
Definition: AttributeRegistry.h:68
bool affectsothers() const
Definition: AttributeRegistry.h:79
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
Definition: Exceptions.h:13
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
std::shared_ptr< const AttributeRegistry > ConstPtr
Definition: AttributeRegistry.h:42
ast::tokens::CoreType type() const
Definition: AttributeRegistry.h:67
std::vector< AccessData > AccessDataVec
Definition: AttributeRegistry.h:95
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...
Registered access details, including its name, type and whether a write handle is required...
Definition: AttributeRegistry.h:47
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:561
This class stores a list of access names, types and their dependency connections. ...
Definition: AttributeRegistry.h:38
const AccessDataVec & data() const
Returns a const reference to the vector of registered accesss.
Definition: AttributeRegistry.h:159
std::shared_ptr< AttributeRegistry > Ptr
Definition: AttributeRegistry.h:41
Attributes represent any access to a primitive value, typically associated with the '@' symbol syntax...
Definition: AST.h:1873
bool reads() const
Definition: AttributeRegistry.h:63
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
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.
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202