Logo Search packages:      
Sourcecode: uncrustify version File versions

void brace_cleanup ( void   ) 

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!

define bodies get the full formatting treatment Also need to pass in the initial '#' to close out any virtual braces.

Definition at line 107 of file brace_cleanup.cpp.

References chunk_t::brace_level, chunk_t::flags, chunk_t::level, parse_cleanup(), pawn_check_vsemicolon(), pf_pop(), chunk_t::pp_level, preproc_start(), chunk_t::str, and chunk_t::type.

Referenced by uncrustify_file().

{
   chunk_t            *pc;
   chunk_t            vs_chunk;
   struct parse_frame frm;
   int pp_level;

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

   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);
   }
}


Generated by  Doxygen 1.6.0   Back to index