Пример #1
0
void
DRV_drive (const char *s)
{
  // Set the name of the IDL file we are parsing. This is useful to
  // the backend when it generates C++ headers and files.
  UTL_String *utl_string = 0;
  ACE_NEW (utl_string,
           UTL_String (s, true));

  idl_global->idl_src_file (utl_string);

  // Pass through CPP.
  if (idl_global->compile_flags () & IDL_CF_INFORMATIVE)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT("%C: preprocessing %C\n"),
                  idl_global->prog_name (),
                  s));
    }

  DRV_pre_proc (s);

  if (idl_global->compile_flags () & IDL_CF_ONLY_PREPROC)
    {
      // Go straight to cleanup, process the next file, if any.
      DRV_refresh ();
      return;
    }

  // Parse.
  if (idl_global->compile_flags () & IDL_CF_INFORMATIVE)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT("%C: parsing %C\n"),
                  idl_global->prog_name (),
                  s));
    }

  // Return value not used - error count stored in idl_global
  // and checked below.
  (void) FE_yyparse ();

  // This option creates a single IDL file that includes all
  // input files. The backend outputs their names individually.
  if (!idl_global->multi_file_input ())
    {
      // Filename set by FE_yyparse(), so we output it immediately after.
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT("processing %C\n"),
                  idl_global->filename ()->get_string ()));
    }

  // We must do this as late as possible to make sure any
  // forward declared structs or unions contained in a
  // primary key at some level have been fully defined.
  idl_global->check_primary_keys ();

  // If there were any errors, stop.
  if (idl_global->err_count () > 0)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("%C: %C: found %d error%s\n"),
                  idl_global->prog_name (),
                  s,
                  idl_global->err_count (),
                  (idl_global->err_count () > 1
                    ? ACE_TEXT ("s")
                    : ACE_TEXT ("")) ));

      // Backend will be cleaned up after the exception is caught.
      throw Bailout ();
    }

  // Dump the code.
  if ((idl_global->compile_flags () & IDL_CF_INFORMATIVE)
      && (idl_global->compile_flags () & IDL_CF_DUMP_AST))
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT("%C: dump %C\n"),
                  idl_global->prog_name (),
                  s));
    }

  if (idl_global->compile_flags () & IDL_CF_DUMP_AST)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("Dump of AST:\n")));

      idl_global->root ()->dump (*ACE_DEFAULT_LOG_STREAM);
    }

  // Call the main entry point for the BE.
  if (idl_global->compile_flags () & IDL_CF_INFORMATIVE)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT("%C: BE processing on %C\n"),
                  idl_global->prog_name (),
                  s));
    }

  // Make sure all forward declared structs and unions are defined
  // before proceeding to code generation.
  AST_check_fwd_decls ();

  if (0 == idl_global->err_count ())
    {
      BE_produce ();
    }
  else
    {
      throw Bailout ();
    }

  DRV_refresh ();
}
Пример #2
0
/*
** Drive the compilation
**
** LOGIC:
**
** 1. Initialize the CFE, stage 1. This builds the scope stack
** 2. Initialize the BE. This builds an instance of the generator
** 3. Initialize the CFE, stage 2. This builds the global scope
**    and populates it with the predefined types
** 4. Invoke FE_yyparse
** 5. Check for errors from FE_yyparse. If any, exit now
** 6. Check for undefined forward declared interfaces. If any, exit now
** 7. Check if asked to dump AST. If so, do.
** 8. Invoke BE.
*/
int DRV_drive (char *s)
{
    // Pass through CPP
    if (idl_global->compile_flags () & IDL_CF_INFORMATIVE)
        cerr << idl_global->prog_name ()
             << GTDEVEL(": preprocessing ")
             << s
             << "\n";

    idl_global->set_compilation_stage (IDL_GlobalData::CS_PreProcessing);

    DRV_pre_proc (s);
    // Initialize FE stage 1
    idl_global->set_compilation_stage (IDL_GlobalData::CS_InitStage1);

    (*DRV_FE_init_stage1) ();

    // Initialize BE
    idl_global->set_compilation_stage (IDL_GlobalData::CS_BEInit);

    idl_global->set_gen ((*DRV_BE_init) ());

    // Initialize FE stage 2
    idl_global->set_compilation_stage (IDL_GlobalData::CS_InitStage2);

    (*DRV_FE_init_stage2) ();

    // Parse
    if (idl_global->compile_flags () & IDL_CF_INFORMATIVE)
        cerr << idl_global->prog_name ()
             << GTDEVEL(": parsing ")
             << s
             << "\n";

    idl_global->set_compilation_stage (IDL_GlobalData::CS_Parsing);

    (*DRV_FE_yyparse) ();

    // If there were any errors, stop
    if (idl_global->err_count () > 0)
    {
        cerr << "\"" << idl_global->prog_name ()
             << "\": "
             << s
             << GTDEVEL (": found ");
        cerr << idl_global->err_count ()
             << GTDEVEL (" error");
        cerr << (idl_global->err_count () > 1 ? GTDEVEL ("s") : "") << "\n";
        // Call BE_abort to allow a BE to clean up after itself
        (*DRV_BE_abort) ();
        return((int) idl_global->err_count ());
    }

    // Dump the code
    if ((idl_global->compile_flags () & IDL_CF_INFORMATIVE)
            && (idl_global->compile_flags () & IDL_CF_DUMP_AST))
        cerr << idl_global->prog_name ()
             << GTDEVEL(": dump ")
             << s
             << "\n";

    if (idl_global->compile_flags () & IDL_CF_DUMP_AST)
    {
        cerr << GTDEVEL ("Dump of AST:\n");
        idl_global->root ()->dump (cerr);
    }

    // Call the main entry point for the BE
    if (idl_global->compile_flags () & IDL_CF_INFORMATIVE)
        cerr << idl_global->prog_name ()
             << GTDEVEL(": BE processing on ")
             << s
             << "\n";

    idl_global->set_compilation_stage (IDL_GlobalData::CS_Producing);

    (*DRV_BE_produce) ();

    // Exit cleanly
    if (idl_global->err_count() > 0)
    {
        BE_unlinkAllFiles ();
    }

    return ((int) idl_global->err_count());
}