Logo Search packages:      
Sourcecode: uncrustify version File versions

void newlines_class_colon_pos ( void   ) 

Searches for CT_CLASS_COLON and moves them, if needed. Also breaks up the args

Definition at line 1530 of file newlines.cpp.

References chunk_get_next_nc(), chunk_get_next_ncnl(), chunk_get_prev_nc(), chunk_swap(), chunk_t::level, chunk_t::nl_count, and chunk_t::type.

Referenced by uncrustify_file().

{
   chunk_t    *pc;
   chunk_t    *next;
   chunk_t    *prev;
   tokenpos_e mode    = cpd.settings[UO_pos_class_colon].tp;
   chunk_t    *ccolon = NULL;

   for (pc = chunk_get_head(); pc != NULL; pc = chunk_get_next_ncnl(pc))
   {
      if ((ccolon == NULL) && (pc->type != CT_CLASS_COLON))
      {
         continue;
      }

      if (pc->type == CT_CLASS_COLON)
      {
         ccolon = pc;
         prev   = chunk_get_prev_nc(pc);
         next   = chunk_get_next_nc(pc);

         if (!chunk_is_newline(prev) && !chunk_is_newline(next) &&
             ((cpd.settings[UO_nl_class_init_args].a & AV_ADD) != 0))
         {
            newline_add_after(pc);
            prev = chunk_get_prev_nc(pc);
            next = chunk_get_next_nc(pc);
         }

         if (cpd.settings[UO_nl_class_init_args].a == AV_REMOVE)
         {
            if (chunk_is_newline(prev))
            {
               chunk_del(prev);
               prev = chunk_get_prev_nc(pc);
            }
            if (chunk_is_newline(next))
            {
               chunk_del(next);
               next = chunk_get_next_nc(pc);
            }
         }

         if (mode == TP_TRAIL)
         {
            if (chunk_is_newline(prev) && (prev->nl_count == 1))
            {
               chunk_swap(pc, prev);
            }
         }
         else if (mode == TP_LEAD)
         {
            if (chunk_is_newline(next) && (next->nl_count == 1))
            {
               chunk_swap(pc, next);
            }
         }
      }
      else
      {
         if ((pc->type == CT_BRACE_OPEN) || (pc->type == CT_SEMICOLON))
         {
            ccolon = NULL;
            continue;
         }

         if ((pc->type == CT_COMMA) && (pc->level == ccolon->level))
         {
            if ((cpd.settings[UO_nl_class_init_args].a & AV_ADD) != 0)
            {
               newline_add_after(pc);
            }
            else if (cpd.settings[UO_nl_class_init_args].a == AV_REMOVE)
            {
               next = chunk_get_next(pc);
               if ((next != NULL) && (next->type == CT_NEWLINE))
               {
                  chunk_del(next);
               }
            }
         }
      }
   }
}


Generated by  Doxygen 1.6.0   Back to index