Logo Search packages:      
Sourcecode: uncrustify version File versions

chunk_t* output_comment_cpp ( chunk_t first  ) 

Outputs the CPP comment at pc. CPP comment combining is done here

Returns:
the last chunk output'd

Only combine the next comment if they are both at indent level or the second one is NOT at indent or less

A trailing comment cannot be combined with a comment at indent level or less

Definition at line 444 of file output.cpp.

References chunk_t::column, chunk_t::column_indent, chunk_t::len, chunk_t::nl_count, chunk_t::parent_type, chunk_t::str, and chunk_t::type.

{
   int col    = first->column;
   int col_br = first->column_indent;

   /* Make sure we have at least one space past the last token */
   if (first->parent_type == CT_COMMENT_END)
   {
      chunk_t *prev = chunk_get_prev(first);
      if (prev != NULL)
      {
         int col_min = prev->column + prev->len + 1;
         if (col < col_min)
         {
            col = col_min;
         }
      }
   }

   /* Bump out to the column */
   output_indent(col, col_br);

   if (!cpd.settings[UO_cmt_cpp_to_c].b)
   {
      add_text_len(first->str, first->len);
      return(first);
   }

   /* If we are grouping, see if there is something to group */
   bool combined = false;
   if (cpd.settings[UO_cmt_cpp_group].b)
   {
      /* next is a newline by definition */
      chunk_t *next = chunk_get_next(first);
      if ((next != NULL) && (next->nl_count == 1))
      {
         next = chunk_get_next(next);

         /**
          * Only combine the next comment if they are both at indent level or
          * the second one is NOT at indent or less
          *
          * A trailing comment cannot be combined with a comment at indent
          * level or less
          */
         if ((next != NULL) &&
             (next->type == CT_COMMENT_CPP) &&
             (((next->column == 1) && (first->column == 1)) ||
              ((next->column == col_br) && (first->column == col_br)) ||
              ((next->column > col_br) && (first->parent_type == CT_COMMENT_END))))
         {
            combined = true;
         }
      }
   }

   if (!combined)
   {
      /* nothing to group: just output a single line */
      add_text_len("/*", 2);
      if ((first->str[2] != ' ') && (first->str[2] != '\t'))
      {
         add_char(' ');
      }
      add_converted_comment(first);
      add_text_len(" */", 3);
      return(first);
   }

   chunk_t *pc   = first;
   chunk_t *last = first;

   /* Output the first line */
   add_text_len("/*", 2);
   if (combined && cpd.settings[UO_cmt_cpp_nl_start].b)
   {
      /* I suppose someone more clever could do this without a goto or
       * repeating too much code...
       */
      goto cpp_newline;
   }
   goto cpp_addline;

   /* Output combined lines */
   while ((pc = chunk_get_next(pc)) != NULL)
   {
      if ((pc->type == CT_NEWLINE) && (pc->nl_count == 1))
      {
         continue;
      }
      if (pc->type != CT_COMMENT_CPP)
      {
         break;
      }
      if (((pc->column == 1) && (first->column == 1)) ||
          ((pc->column == col_br) && (first->column == col_br)) ||
          ((pc->column > col_br) && (first->parent_type == CT_COMMENT_END)))
      {
         last = pc;

cpp_newline:
         add_char('\n');
         output_indent(col, col_br);
         add_char(' ');
         add_spaces_before_star();
         add_char(cpd.settings[UO_cmt_star_cont].b ? '*' : ' ');
         add_spaces_after_star();

cpp_addline:
         if ((pc->str[2] != ' ') && (pc->str[2] != '\t'))
         {
            add_char(' ');
         }
         add_converted_comment(pc);
      }
   }

   if (cpd.settings[UO_cmt_cpp_nl_end].b)
   {
      add_char('\n');
      output_indent(col, col_br);
   }
   add_text_len(" */", 3);
   return(last);
}


Generated by  Doxygen 1.6.0   Back to index