Esempio n. 1
0
File: phase.c Progetto: wormt/bcc
void read_dirc( struct parse* parse, struct pos* pos ) {
   // Directives can only appear in the upmost region.
   if ( parse->region != parse->task->region_upmost ) {
      p_diag( parse, DIAG_POS_ERR, pos,
         "directive not in upmost region" );
      p_bail( parse );
   }
   if ( parse->tk == TK_IMPORT ) {
      p_read_tk( parse );
      if ( parse->source->imported ) {
         p_test_tk( parse, TK_LIT_STRING );
         p_read_tk( parse );
      }
      else {
         read_include( parse, pos, true );
      }
   }
   else if ( strcmp( parse->tk_text, "include" ) == 0 ) {
      p_read_tk( parse );
      if ( parse->source->imported ) {
         p_test_tk( parse, TK_LIT_STRING );
         p_read_tk( parse );
      }
      else {
         read_include( parse, pos, false );
      }
   }
   else if ( strcmp( parse->tk_text, "define" ) == 0 ||
      strcmp( parse->tk_text, "libdefine" ) == 0 ) {
      read_define( parse );
   }
   else if ( strcmp( parse->tk_text, "library" ) == 0 ) {
      p_read_tk( parse );
      read_library( parse, pos );
   }
   else if ( strcmp( parse->tk_text, "encryptstrings" ) == 0 ) {
      parse->task->library->encrypt_str = true;
      p_read_tk( parse );
   }
   else if ( strcmp( parse->tk_text, "nocompact" ) == 0 ) {
      parse->task->library->format = FORMAT_BIG_E;
      p_read_tk( parse );
   }
   else if (
      // NOTE: Not sure what these two are.
      strcmp( parse->tk_text, "wadauthor" ) == 0 ||
      strcmp( parse->tk_text, "nowadauthor" ) == 0 ) {
      p_diag( parse, DIAG_POS_ERR, pos, "directive `%s` not supported",
         parse->tk_text );
      p_bail( parse );
   }
   else {
      p_diag( parse, DIAG_POS_ERR, pos,
         "unknown directive '%s'", parse->tk_text );
      p_bail( parse );
   }
}
Esempio n. 2
0
File: cpp.c Progetto: rui314/8cc-old
static void read_directive(CppContext *ctx) {
    Token *tok;
    if (read_if(ctx, "define"))       read_define(ctx);
    else if (read_if(ctx, "undef"))   read_undef(ctx);
    else if (read_if(ctx, "if"))      handle_cond_incl(ctx, COND_IF);
    else if (read_if(ctx, "elif"))    handle_cond_incl(ctx, COND_ELIF);
    else if (read_if(ctx, "else"))    handle_cond_incl(ctx, COND_ELSE);
    else if (read_if(ctx, "ifdef"))   handle_cond_incl(ctx, COND_IFDEF);
    else if (read_if(ctx, "ifndef"))  handle_cond_incl(ctx, COND_IFNDEF);
    else if (read_if(ctx, "endif"))   handle_cond_incl(ctx, COND_ENDIF);
    else if (read_if(ctx, "include")) handle_include(ctx);
    else if (read_if(ctx, "line"))    handle_line_directive(ctx);
    else if (read_if(ctx, "pragma"))  handle_pragma(ctx);
    else if ( (tok = read_if(ctx, "error")) ) {
        read_error_directive(ctx, tok);
    } else {
        tok = read_cpp_token(ctx);
        if (tok && tok->toktype == TOKTYPE_NEWLINE)
            // 6.10.7 NULL directive.  Do nothing.
            return;
        error_token(tok, "unsupported preprocessor directive: '%s'", token_to_string(tok));
    }
}