@@ -608,12 +608,12 @@ ASTindex::childname (size_t i) const
608608
609609ASTstructselect::ASTstructselect (OSLCompilerImpl *comp, ASTNode *expr,
610610 ustring field)
611- : ASTNode (structselect_node, comp, 0 , expr), m_field( field),
611+ : ASTfieldselect (structselect_node, comp, expr, field),
612612 m_structid(-1 ), m_fieldid(-1 ), m_fieldsym(NULL )
613613{
614614 m_fieldsym = find_fieldsym (m_structid, m_fieldid);
615615 if (m_fieldsym) {
616- m_fieldname = m_fieldsym->name ();
616+ m_fullname = m_fieldsym->name ();
617617 m_typespec = m_fieldsym->typespec ();
618618 }
619619}
@@ -626,12 +626,7 @@ ASTstructselect::ASTstructselect (OSLCompilerImpl *comp, ASTNode *expr,
626626Symbol *
627627ASTstructselect::find_fieldsym (int &structid, int &fieldid)
628628{
629- if (! lvalue ()->typespec ().is_structure () &&
630- ! lvalue ()->typespec ().is_structure_array ()) {
631- error (" type '%s' does not have a member '%s'" ,
632- type_c_str (lvalue ()->typespec ()), m_field);
633- return NULL ;
634- }
629+ ASSERT (lvalue ()->typespec ().is_structure_based ());
635630
636631 ustring structsymname;
637632 TypeSpec structtype;
@@ -677,8 +672,7 @@ ASTstructselect::find_structsym (ASTNode *structnode, ustring &structname,
677672 // or array of structs) down to a symbol that represents the
678673 // particular field. In the process, we set structname and its
679674 // type structtype.
680- ASSERT (structnode->typespec ().is_structure () ||
681- structnode->typespec ().is_structure_array ());
675+ ASSERT (structnode->typespec ().is_structure_based ());
682676 if (structnode->nodetype () == variable_ref_node) {
683677 // The structnode is a top-level struct variable
684678 ASTvariable_ref *var = (ASTvariable_ref *) structnode;
@@ -725,6 +719,21 @@ ASTstructselect::print (std::ostream &out, int indentlevel) const
725719
726720
727721
722+ ASTfieldselect* ASTfieldselect::create (OSLCompilerImpl *comp, ASTNode *expr,
723+ ustring field) {
724+ if (expr->typespec ().is_structure_based ())
725+ return new ASTstructselect (comp, expr, field);
726+
727+ comp->error (comp->filename (), comp->lineno (),
728+ " type '%s' does not have a member '%s'" ,
729+ comp->type_c_str (expr->typespec ()), field);
730+
731+ // Don't leak expr node
732+ delete expr;
733+ return nullptr ;
734+ }
735+
736+
728737const char *
729738ASTconditional_statement::childname (size_t i) const
730739{
0 commit comments