summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.72.0/src/flag_parens.cpp
blob: 251bfa2dce65e07b950a2a73b3357d496962608f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
 * @file flag_parens.cpp
 *
 * @author  Guy Maurel
 * @license GPL v2+
 */

#include "flag_parens.h"
#include "uncrustify.h"


chunk_t *flag_parens(chunk_t *po, pcf_flags_t flags, c_token_t opentype, c_token_t parenttype, bool parent_all)
{
   LOG_FUNC_ENTRY();
   chunk_t *paren_close;

   paren_close = chunk_skip_to_match(po, scope_e::PREPROC);

   if (paren_close == nullptr)
   {
      LOG_FMT(LERR, "%s(%d): no match for '%s' at [%zu:%zu]",
              __func__, __LINE__, po->text(), po->orig_line, po->orig_col);
      log_func_stack_inline(LERR);
      cpd.error_count++;
      return(nullptr);
   }
   LOG_FMT(LFLPAREN, "%s(%d): between  po is '%s', orig_line is %zu, orig_col is %zu, and\n",
           __func__, __LINE__, po->text(), po->orig_line, po->orig_col);
   LOG_FMT(LFLPAREN, "%s(%d): paren_close is '%s', orig_line is %zu, orig_col is %zu, type is %s, parent_type is %s\n",
           __func__, __LINE__, paren_close->text(), paren_close->orig_line, paren_close->orig_col,
           get_token_name(opentype), get_token_name(parenttype));
   log_func_stack_inline(LFLPAREN);

   // the last chunk must be also modified. Issue #2149
   chunk_t *after_paren_close = chunk_get_next(paren_close);

   if (po != paren_close)
   {
      if (  flags != PCF_NONE
         || (parent_all && parenttype != CT_NONE))
      {
         chunk_t *pc;

         for (pc = chunk_get_next(po, scope_e::PREPROC);
              pc != nullptr && pc != after_paren_close;
              pc = chunk_get_next(pc, scope_e::PREPROC))
         {
            chunk_flags_set(pc, flags);

            if (parent_all)
            {
               set_chunk_parent(pc, parenttype);
            }
         }
      }

      if (opentype != CT_NONE)
      {
         set_chunk_type(po, opentype);
         set_chunk_type(paren_close, (c_token_t)(opentype + 1));
      }

      if (parenttype != CT_NONE)
      {
         set_chunk_parent(po, parenttype);
         set_chunk_parent(paren_close, parenttype);
      }
   }
   return(chunk_get_next_ncnl(paren_close, scope_e::PREPROC));
} // flag_parens