Exemple #1
0
/**
 * Aligns an OC message
 *
 * @param so   the square open of the message
 * @param span the span value
 */
static void align_oc_msg_colon(chunk_t *so)
{
   int        span = cpd.settings[UO_align_oc_msg_colon_span].n;
   chunk_t    *pc;
   chunk_t    *tmp;
   AlignStack cas;   /* for the colons */
   AlignStack nas;   /* for the parameter tag */
   int        level;
   bool       did_line;
   int        lcnt;  /* line count with no colon for span */
   bool       has_colon;


   nas.Reset();
   nas.m_right_align = true;

   cas.Start(span);

   level = so->level;
   pc    = chunk_get_next_ncnl(so, CNAV_PREPROC);

   did_line  = false;
   has_colon = false;
   lcnt      = 0;

   while ((pc != NULL) && (pc->level > level))
   {
      if (pc->level > (level + 1))
      {
         /* do nothing */
      }
      else if (chunk_is_newline(pc))
      {
         if (!has_colon)
         {
            ++lcnt;
         }
         did_line  = false;
         has_colon = !has_colon;
      }
      else if (!did_line && (lcnt - 1 < span) && (pc->type == CT_OC_COLON))
      {
         has_colon = true;
         cas.Add(pc);
         tmp = chunk_get_prev(pc);
         if ((tmp != NULL) &&
             ((tmp->type == CT_OC_MSG_FUNC) ||
              (tmp->type == CT_OC_MSG_NAME)))
         {
            nas.Add(tmp);
         }
         did_line = true;
      }
      pc = chunk_get_next(pc, CNAV_PREPROC);
   }
   nas.End();
   cas.End();
}
Exemple #2
0
/**
 * Aligns OC declarations on the colon
 * -(void) doSomething: (NSString*) param1
 *                with: (NSString*) param2
 */
static void align_oc_decl_colon(void)
{
   chunk_t    *pc = chunk_get_head();
   chunk_t    *tmp;
   chunk_t    *tmp2;
   AlignStack cas;   /* for the colons */
   AlignStack nas;   /* for the parameter label */
   int        level;
   bool       did_line;

   cas.Start(4);
   nas.Start(4);
   nas.m_right_align = true;

   while (pc != NULL)
   {
      if (pc->type != CT_OC_SCOPE)
      {
         pc = chunk_get_next(pc);
         continue;
      }

      nas.Reset();
      cas.Reset();

      level = pc->level;
      pc    = chunk_get_next_ncnl(pc, CNAV_PREPROC);

      did_line = false;

      while ((pc != NULL) && (pc->level >= level))
      {
         /* The decl ends with an open brace or semicolon */
         if ((pc->type == CT_BRACE_OPEN) || chunk_is_semicolon(pc))
         {
            break;
         }

         if (chunk_is_newline(pc))
         {
            nas.NewLines(pc->nl_count);
            cas.NewLines(pc->nl_count);
            did_line  = false;
         }
         else if (!did_line && (pc->type == CT_OC_COLON))
         {
            cas.Add(pc);

            tmp = chunk_get_prev(pc, CNAV_PREPROC);
            tmp2 = chunk_get_prev_ncnl(tmp, CNAV_PREPROC);

            /* Check for an un-labeled parameter */
            if ((tmp != NULL) &&
                (tmp2 != NULL)
                &&
                ((tmp->type == CT_WORD) ||
                 (tmp->type == CT_TYPE) ||
                 (tmp->type == CT_OC_MSG_DECL))
                &&
                ((tmp2->type == CT_WORD) ||
                 (tmp2->type == CT_TYPE) ||
                 (tmp2->type == CT_PAREN_CLOSE)))
            {
               nas.Add(tmp);
            }
            did_line = true;
         }
         pc = chunk_get_next(pc, CNAV_PREPROC);
      }
      nas.End();
      cas.End();
   }
}