summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.78.1/src/pragma_cleanup.cpp
blob: 336a127297b0c6cfea06ebf2022b14aa5703f036 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
 * @file pragma_cleanup.cpp
 *
 * @author  Guy Maurel
 * @license GPL v2+
 */

#include "pragma_cleanup.h"

#include "chunk.h"
#include "unc_tools.h"


void pragma_cleanup()
{
   LOG_FUNC_ENTRY();

   bool  preproc_found   = false;
   bool  pragma_found    = false;
   bool  parameter_found = false;

   Chunk *pc = Chunk::GetHead();

   while (pc->IsNotNullChunk())
   {
      LOG_CHUNK(LTOK, pc);

      if (!preproc_found)
      {
         if (pc->Is(CT_PREPROC))
         {
            LOG_FMT(LMCB, "%s(%d): PREPROC found: orig line %zu, orig col is %zu\n",
                    __func__, __LINE__, pc->GetOrigLine(), pc->GetOrigCol());
            log_pcf_flags(LMCB, pc->GetFlags());
            preproc_found = true;
         }
      }
      else
      {
         if (!pragma_found)
         {
            if (pc->Is(CT_PP_PRAGMA))
            {
               LOG_FMT(LMCB, "%s(%d): PP_PRAGMA found: orig line %zu, orig col is %zu\n",
                       __func__, __LINE__, pc->GetOrigLine(), pc->GetOrigCol());
               log_pcf_flags(LMCB, pc->GetFlags());
               pragma_found = true;
            }
         }
         else
         {
            if (!parameter_found)
            {
               LOG_FMT(LMCB, "%s(%d): PARAMETER found: orig line %zu, orig col is %zu, Text is '%s'\n",
                       __func__, __LINE__, pc->GetOrigLine(), pc->GetOrigCol(), pc->Text());
               log_pcf_flags(LMCB, pc->GetFlags());

               if (strcmp(pc->Text(), "endasm") == 0)
               {
                  pc->SetType(CT_PP_ENDASM);
               }
               else if (strcmp(pc->Text(), "region") == 0)
               {
                  pc->SetType(CT_PP_REGION);
               }
               //else if (strcmp(pc->Text(), "comment") == 0)
               //{
               //   pc->SetType(CT_PP_COMMENT);
               //}
               else
               {
                  pc->SetType(CT_PP_PRAGMA);
               }
               parameter_found = true;
            }
            else
            {
               LOG_FMT(LMCB, "%s(%d): orig line is %zu, orig col is %zu, Text is '%s'\n",
                       __func__, __LINE__, pc->GetOrigLine(), pc->GetOrigCol(), pc->Text());

               if (pc->IsNewline())
               {
                  // reset
                  preproc_found   = false;
                  pragma_found    = false;
                  parameter_found = false;
               }
               else
               {
                  pc->SetType(CT_PP_IGNORE);
               }
            }
         }
      }
      pc = pc->GetNext();
   }
   //prot_the_line(__func__, __LINE__, 3, 0);
} // pragma_cleanup