Logo Search packages:      
Sourcecode: uncrustify version File versions

void newlines_bool_pos ( void   ) 

Searches for CT_BOOL (|| or && or ^^) operators and moves them, if needed. Will not move CT_BOOL tokens that are on their own line or have other than exactly 1 newline before (UO_pos_bool == TRAIL) or after (UO_pos_bool == LEAD).

Definition at line 1474 of file newlines.cpp.

References chunk_get_next_nc(), chunk_get_next_ncnl(), chunk_get_prev_nc(), chunk_t::flags, 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_bool].tp;

   if (mode == TP_IGNORE)
   {
      return;
   }

   for (pc = chunk_get_head(); pc != NULL; pc = chunk_get_next_ncnl(pc))
   {
      if (pc->type == CT_BOOL)
      {
         prev = chunk_get_prev_nc(pc);
         next = chunk_get_next_nc(pc);

         /* if both are newlines or neither are newlines, skip this chunk */
         if (chunk_is_newline(prev) == chunk_is_newline(next))
         {
            continue;
         }

         /*NOTE: may end up processing a chunk twice if changed */
         if (mode == TP_TRAIL)
         {
            if (chunk_is_newline(prev) && (prev->nl_count == 1))
            {
               /* Back up to the next non-comment item */
               prev = chunk_get_prev_nc(prev);
               if ((prev != NULL) && !chunk_is_newline(prev) &&
                   !(prev->flags & PCF_IN_PREPROC))
               {
                  chunk_move_after(pc, prev);
               }
            }
         }
         else  /* (mode == TP_LEAD) */
         {
            if (chunk_is_newline(next) && (next->nl_count == 1))
            {
               /* move the CT_BOOL to after the newline */
               chunk_move_after(pc, next);
            }
         }
      }
   }
}


Generated by  Doxygen 1.6.0   Back to index