MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenShadingLanguage / find_structsym

Method find_structsym

src/liboslcomp/ast.cpp:671–705  ·  view source on GitHub ↗

structnode is an AST node representing a struct. It could be a struct variable, or a field of a struct (which is itself a struct), or an array element of a struct. Whatever, here we figure out some vital information about it: the name of the symbol representing the struct, and its type.

Source from the content-addressed store, hash-verified

669/// vital information about it: the name of the symbol representing the
670/// struct, and its type.
671void
672ASTstructselect::find_structsym (ASTNode *structnode, ustring &structname,
673 TypeSpec &structtype)
674{
675 // This node selects a field from a struct. The purpose of this
676 // method is to "flatten" the possibly-nested (struct in struct, and
677 // or array of structs) down to a symbol that represents the
678 // particular field. In the process, we set structname and its
679 // type structtype.
680 ASSERT (structnode->typespec().is_structure() ||
681 structnode->typespec().is_structure_array());
682 if (structnode->nodetype() == variable_ref_node) {
683 // The structnode is a top-level struct variable
684 ASTvariable_ref *var = (ASTvariable_ref *) structnode;
685 structname = var->name();
686 structtype = var->typespec();
687 }
688 else if (structnode->nodetype() == structselect_node) {
689 // The structnode is itself a field of another struct.
690 ASTstructselect *thestruct = (ASTstructselect *) structnode;
691 int structid, fieldid;
692 Symbol *sym = thestruct->find_fieldsym (structid, fieldid);
693 structname = sym->name();
694 structtype = sym->typespec();
695 }
696 else if (structnode->nodetype() == index_node) {
697 // The structnode is an element of an array of structs:
698 ASTindex *arrayref = (ASTindex *) structnode;
699 find_structsym (arrayref->lvalue().get(), structname, structtype);
700 structtype.make_array (0); // clear its arrayness
701 }
702 else {
703 ASSERT (0 && "Malformed ASTstructselect");
704 }
705}
706
707
708

Callers

nothing calls this directly

Calls 8

is_structure_arrayMethod · 0.80
nodetypeMethod · 0.80
find_fieldsymMethod · 0.80
make_arrayMethod · 0.80
is_structureMethod · 0.45
nameMethod · 0.45
getMethod · 0.45
lvalueMethod · 0.45

Tested by

no test coverage detected