Exemple #1
0
/**
 * Scans through the whole list and does stuff.
 * It has to do some tricks to parse preprocessors.
 *
 * TODO: This can be cleaned up and simplified - we can look both forward and backward!
 */
void brace_cleanup(void)
{
   chunk_t            *pc;
   chunk_t            vs_chunk;
   struct parse_frame frm;
   int                pp_level;

   memset(&frm, 0, sizeof(frm));

   cpd.frame_count = 0;
   cpd.in_preproc  = CT_NONE;
   cpd.pp_level    = 0;

   pc = chunk_get_head();
   while (pc != NULL)
   {
      /* Check for leaving a #define body */
      if ((cpd.in_preproc != CT_NONE) && ((pc->flags & PCF_IN_PREPROC) == 0))
      {
         if (cpd.in_preproc == CT_PP_DEFINE)
         {
            /* out of the #define body, restore the frame */
            pf_pop(&frm);
         }

         cpd.in_preproc = CT_NONE;
      }

      /* Check for a preprocessor start */
      pp_level = cpd.pp_level;
      if (pc->type == CT_PREPROC)
      {
         pp_level = preproc_start(&frm, pc);
      }

      /* Do before assigning stuff from the frame */
      if ((cpd.lang_flags & LANG_PAWN) != 0)
      {
         if ((frm.pse[frm.pse_tos].type == CT_VBRACE_OPEN) &&
             (pc->type == CT_NEWLINE))
         {
            pc = pawn_check_vsemicolon(pc);
         }
      }

      /* Assume the level won't change */
      pc->level       = frm.level;
      pc->brace_level = frm.brace_level;
      pc->pp_level    = pp_level;


      /**
       * #define bodies get the full formatting treatment
       * Also need to pass in the initial '#' to close out any virtual braces.
       */
      if (!chunk_is_comment(pc) && !chunk_is_newline(pc) &&
          ((cpd.in_preproc == CT_PP_DEFINE) ||
           (cpd.in_preproc == CT_NONE)))
      {
         cpd.consumed = false;
         parse_cleanup(&frm, pc);
         print_stack(LBCSAFTER, (pc->type == CT_VBRACE_CLOSE) ? "Virt-}" : pc->str, &frm, pc);
      }
      pc = chunk_get_next(pc);
   }
}
Exemple #2
0
//TODO: This can be cleaned up and simplified - we can look both forward and backward!
void brace_cleanup(void)
{
   LOG_FUNC_ENTRY();
   chunk_t       *pc;
   parse_frame_t frm;

   cpd.unc_stage = unc_stage_e::BRACE_CLEANUP;

   memset(&frm, 0, sizeof(frm));

   cpd.frame_count = 0;
   cpd.in_preproc  = CT_NONE;
   cpd.pp_level    = 0;

   pc = chunk_get_head();
   while (pc != nullptr)
   {
      // Check for leaving a #define body
      if (cpd.in_preproc != CT_NONE && (pc->flags & PCF_IN_PREPROC) == 0)
      {
         if (cpd.in_preproc == CT_PP_DEFINE)
         {
            // out of the #define body, restore the frame
            pf_pop(&frm);
         }

         cpd.in_preproc = CT_NONE;
      }

      // Check for a preprocessor start
      size_t pp_level = cpd.pp_level;
      if (pc->type == CT_PREPROC)
      {
         pp_level = preproc_start(&frm, pc);
      }

      // Do before assigning stuff from the frame
      if (cpd.lang_flags & LANG_PAWN)
      {
         if (  (frm.pse[frm.pse_tos].type == CT_VBRACE_OPEN)
            && pc->type == CT_NEWLINE)
         {
            pc = pawn_check_vsemicolon(pc);
         }
      }

      // Assume the level won't change
      pc->level       = frm.level;
      pc->brace_level = frm.brace_level;
      pc->pp_level    = pp_level;


      /*
       * #define bodies get the full formatting treatment
       * Also need to pass in the initial '#' to close out any virtual braces.
       */
      if (  !chunk_is_comment(pc)
         && !chunk_is_newline(pc)
         && (cpd.in_preproc == CT_PP_DEFINE || cpd.in_preproc == CT_NONE))
      {
         cpd.consumed = false;
         parse_cleanup(&frm, pc);
         print_stack(LBCSAFTER, (pc->type == CT_VBRACE_CLOSE) ? "Virt-}" : pc->str.c_str(), &frm, pc);
      }
      pc = chunk_get_next(pc);
   }
} // brace_cleanup