mojoshader_preprocessor.c
changeset 910 3ee487d85ecb
parent 898 7f55db1ec3c1
child 913 483458775ec5
equal deleted inserted replaced
909:1859faa45249 910:3ee487d85ecb
    42     int isfail;
    42     int isfail;
    43     int out_of_memory;
    43     int out_of_memory;
    44     char failstr[256];
    44     char failstr[256];
    45     int recursion_count;
    45     int recursion_count;
    46     int asm_comments;
    46     int asm_comments;
       
    47     int parsing_pragma;
    47     Conditional *conditional_pool;
    48     Conditional *conditional_pool;
    48     IncludeState *include_stack;
    49     IncludeState *include_stack;
    49     IncludeState *include_pool;
    50     IncludeState *include_pool;
    50     Define *define_hashtable[256];
    51     Define *define_hashtable[256];
    51     Define *define_pool;
    52     Define *define_pool;
   159         TOKENCASE(TOKEN_PP_IFNDEF);
   160         TOKENCASE(TOKEN_PP_IFNDEF);
   160         TOKENCASE(TOKEN_PP_ELSE);
   161         TOKENCASE(TOKEN_PP_ELSE);
   161         TOKENCASE(TOKEN_PP_ELIF);
   162         TOKENCASE(TOKEN_PP_ELIF);
   162         TOKENCASE(TOKEN_PP_ENDIF);
   163         TOKENCASE(TOKEN_PP_ENDIF);
   163         TOKENCASE(TOKEN_PP_ERROR);
   164         TOKENCASE(TOKEN_PP_ERROR);
       
   165         TOKENCASE(TOKEN_PP_PRAGMA);
   164         TOKENCASE(TOKEN_INCOMPLETE_COMMENT);
   166         TOKENCASE(TOKEN_INCOMPLETE_COMMENT);
   165         TOKENCASE(TOKEN_BAD_CHARS);
   167         TOKENCASE(TOKEN_BAD_CHARS);
   166         TOKENCASE(TOKEN_EOI);
   168         TOKENCASE(TOKEN_EOI);
   167         TOKENCASE(TOKEN_PREPROCESSING_ERROR);
   169         TOKENCASE(TOKEN_PREPROCESSING_ERROR);
   168         #undef TOKENCASE
   170         #undef TOKENCASE
  2192         {
  2194         {
  2193             handle_pp_undef(ctx);
  2195             handle_pp_undef(ctx);
  2194             continue;  // will return at top of loop.
  2196             continue;  // will return at top of loop.
  2195         } // else if
  2197         } // else if
  2196 
  2198 
       
  2199         else if (token == TOKEN_PP_PRAGMA)
       
  2200         {
       
  2201             ctx->parsing_pragma = 1;
       
  2202         } // else if
       
  2203 
  2197         if (token == TOKEN_IDENTIFIER)
  2204         if (token == TOKEN_IDENTIFIER)
  2198         {
  2205         {
  2199             if (handle_pp_identifier(ctx))
  2206             if (handle_pp_identifier(ctx))
  2200                 continue;  // pushed the include_stack.
  2207                 continue;  // pushed the include_stack.
  2201         } // else if
  2208         } // else if
  2202 
  2209 
  2203         else if (token == ((Token) '\n'))
  2210         else if (token == ((Token) '\n'))
  2204         {
  2211         {
  2205             print_debug_lexing_position(state);
  2212             print_debug_lexing_position(state);
  2206             // preprocessor is line-oriented, nothing else gets newlines.
  2213             if (ctx->parsing_pragma)  // let this one through.
  2207             continue;  // get the next thing.
  2214                 ctx->parsing_pragma = 0;
       
  2215             else
       
  2216             {
       
  2217                 // preprocessor is line-oriented, nothing else gets newlines.
       
  2218                 continue;  // get the next thing.
       
  2219             } // else
  2208         } // else if
  2220         } // else if
  2209 
  2221 
  2210         assert(!skipping);
  2222         assert(!skipping);
  2211         *_token = token;
  2223         *_token = token;
  2212         *_len = state->tokenlen;
  2224         *_len = state->tokenlen;
  2380                     (!add_to_buffer(&buffer, endline, sizeof (endline), m, d));
  2392                     (!add_to_buffer(&buffer, endline, sizeof (endline), m, d));
  2381 
  2393 
  2382                 isnewline = 1;
  2394                 isnewline = 1;
  2383             } // if
  2395             } // if
  2384         } // if
  2396         } // if
       
  2397 
       
  2398         else if (token == ((Token) '\n'))
       
  2399         {
       
  2400             if (!out_of_memory)
       
  2401             {
       
  2402                 out_of_memory =
       
  2403                     (!add_to_buffer(&buffer, endline, sizeof (endline), m, d));
       
  2404             } // if
       
  2405             isnewline = 1;
       
  2406         } // else if
  2385 
  2407 
  2386         else if (token == ((Token) '{'))
  2408         else if (token == ((Token) '{'))
  2387         {
  2409         {
  2388             if (!out_of_memory)
  2410             if (!out_of_memory)
  2389             {
  2411             {