mojoshader_compiler.c
changeset 969 ab7676343b60
parent 968 fc6cebb74350
child 970 108ca3392d46
equal deleted inserted replaced
968:fc6cebb74350 969:ab7676343b60
  2608         case MOJOSHADER_AST_STRUCT_MEMBER:
  2608         case MOJOSHADER_AST_STRUCT_MEMBER:
  2609             assert(0 && "Should be done by MOJOSHADER_AST_STRUCT_DECLARATION.");
  2609             assert(0 && "Should be done by MOJOSHADER_AST_STRUCT_DECLARATION.");
  2610             return NULL;
  2610             return NULL;
  2611 
  2611 
  2612         case MOJOSHADER_AST_VARIABLE_DECLARATION:
  2612         case MOJOSHADER_AST_VARIABLE_DECLARATION:
       
  2613         {
       
  2614             MOJOSHADER_astVariableDeclaration *decl = &ast->vardecl;
       
  2615 
  2613             // this is true now, but we'll fill in ->datatype no matter what.
  2616             // this is true now, but we'll fill in ->datatype no matter what.
  2614             assert((ast->vardecl.datatype && !ast->vardecl.anonymous_datatype) ||
  2617             assert((decl->datatype && !decl->anonymous_datatype) ||
  2615                    (!ast->vardecl.datatype && ast->vardecl.anonymous_datatype));
  2618                    (!decl->datatype && decl->anonymous_datatype));
  2616 
  2619 
  2617             // An anonymous struct? That AST node does the heavy lifting.
  2620             // An anonymous struct? That AST node does the heavy lifting.
  2618             if (ast->vardecl.anonymous_datatype != NULL)
  2621             if (decl->anonymous_datatype != NULL)
  2619                 datatype = type_check_ast(ctx, ast->vardecl.anonymous_datatype);
  2622                 datatype = type_check_ast(ctx, decl->anonymous_datatype);
  2620             else
  2623             else
  2621             {
  2624             {
  2622                 datatype = build_datatype(ctx, (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_CONST) != 0,
  2625                 datatype = build_datatype(ctx, (decl->attributes & MOJOSHADER_AST_VARATTR_CONST) != 0,
  2623                                           ast->vardecl.datatype, ast->vardecl.details);
  2626                                           decl->datatype, decl->details);
  2624             } // else
  2627             } // else
  2625 
  2628 
  2626             ast->vardecl.datatype = datatype;
  2629             while (decl != NULL)
  2627 
       
  2628             push_variable(ctx, ast->vardecl.details->identifier, datatype);
       
  2629             if (ast->vardecl.initializer != NULL)
       
  2630             {
  2630             {
  2631                 datatype2 = type_check_ast(ctx, ast->vardecl.initializer);
  2631                 decl->datatype = datatype;
  2632                 add_type_coercion(ctx, NULL, datatype, &ast->vardecl.initializer, datatype2);
  2632                 push_variable(ctx, decl->details->identifier, datatype);
  2633             } // if
  2633                 if (decl->initializer != NULL)
  2634 
  2634                 {
  2635             type_check_ast(ctx, ast->vardecl.annotations);
  2635                     datatype2 = type_check_ast(ctx, decl->initializer);
  2636             type_check_ast(ctx, ast->vardecl.lowlevel);
  2636                     add_type_coercion(ctx, NULL, datatype, &decl->initializer, datatype2);
  2637 
  2637                 } // if
  2638             datatype2 = type_check_ast(ctx, ast->vardecl.next);
  2638 
  2639             return ast->vardecl.datatype;
  2639                 type_check_ast(ctx, decl->annotations);
       
  2640                 type_check_ast(ctx, decl->lowlevel);
       
  2641                 decl = decl->next;
       
  2642             } // while
       
  2643 
       
  2644             return datatype;
       
  2645         } // case
  2640 
  2646 
  2641         case MOJOSHADER_AST_ANNOTATION:
  2647         case MOJOSHADER_AST_ANNOTATION:
  2642         {
  2648         {
  2643             MOJOSHADER_astAnnotations *anno = &ast->annotations;
  2649             MOJOSHADER_astAnnotations *anno = &ast->annotations;
  2644             while (anno)
  2650             while (anno)