@@ -694,12 +694,12 @@ ASTindex::childname (size_t i) const
694694
695695ASTstructselect::ASTstructselect (OSLCompilerImpl *comp, ASTNode *expr,
696696 ustring field)
697- : ASTNode (structselect_node, comp, 0 , expr), m_field( field),
697+ : ASTfieldselect (structselect_node, comp, expr, field),
698698 m_structid(-1 ), m_fieldid(-1 ), m_fieldsym(NULL )
699699{
700700 m_fieldsym = find_fieldsym (m_structid, m_fieldid);
701701 if (m_fieldsym) {
702- m_fieldname = m_fieldsym->name ();
702+ m_fullname = m_fieldsym->name ();
703703 m_typespec = m_fieldsym->typespec ();
704704 }
705705}
@@ -712,12 +712,7 @@ ASTstructselect::ASTstructselect (OSLCompilerImpl *comp, ASTNode *expr,
712712Symbol *
713713ASTstructselect::find_fieldsym (int &structid, int &fieldid)
714714{
715- if (! lvalue ()->typespec ().is_structure () &&
716- ! lvalue ()->typespec ().is_structure_array ()) {
717- error (" type '%s' does not have a member '%s'" ,
718- type_c_str (lvalue ()->typespec ()), m_field);
719- return NULL ;
720- }
715+ ASSERT (lvalue ()->typespec ().is_structure_based ());
721716
722717 ustring structsymname;
723718 TypeSpec structtype;
@@ -763,8 +758,7 @@ ASTstructselect::find_structsym (ASTNode *structnode, ustring &structname,
763758 // or array of structs) down to a symbol that represents the
764759 // particular field. In the process, we set structname and its
765760 // type structtype.
766- ASSERT (structnode->typespec ().is_structure () ||
767- structnode->typespec ().is_structure_array ());
761+ ASSERT (structnode->typespec ().is_structure_based ());
768762 if (structnode->nodetype () == variable_ref_node) {
769763 // The structnode is a top-level struct variable
770764 ASTvariable_ref *var = (ASTvariable_ref *) structnode;
@@ -811,6 +805,21 @@ ASTstructselect::print (std::ostream &out, int indentlevel) const
811805
812806
813807
808+ ASTfieldselect* ASTfieldselect::create (OSLCompilerImpl *comp, ASTNode *expr,
809+ ustring field) {
810+ if (expr->typespec ().is_structure_based ())
811+ return new ASTstructselect (comp, expr, field);
812+
813+ comp->error (comp->filename (), comp->lineno (),
814+ " type '%s' does not have a member '%s'" ,
815+ comp->type_c_str (expr->typespec ()), field);
816+
817+ // Don't leak expr node
818+ delete expr;
819+ return nullptr ;
820+ }
821+
822+
814823const char *
815824ASTconditional_statement::childname (size_t i) const
816825{
0 commit comments