summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.72.0/debian/patches/007_issue_3040.diff
blob: 99d4887f1b21714d41e3a8af59273df1031486fc (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Backported commits 5f3f392a and fb66774e from upstream. This solves upstream issues 3040.

--- a/src/braces.cpp
+++ b/src/braces.cpp
@@ -1290,7 +1290,7 @@
 static chunk_t *mod_case_brace_add(chunk_t *cl_colon)
 {
    LOG_FUNC_ENTRY();
-   LOG_FMT(LMCB, "%s(%d): line %zu",
+   LOG_FMT(LMCB, "%s(%d): line %zu\n",
            __func__, __LINE__, cl_colon->orig_line);
 
    chunk_t *pc   = cl_colon;
@@ -1309,7 +1309,28 @@
          && (  chunk_is_token(pc, CT_CASE)
             || chunk_is_token(pc, CT_BREAK)))
       {
-         last = pc;
+         // check if previous line is a preprocessor                     Issue #3040
+         chunk_t *prev = chunk_get_prev_ncnl(pc);
+         LOG_FMT(LMCB, "%s(%d): prev->text() is '%s', orig_line %zu\n",
+                 __func__, __LINE__, prev->text(), prev->orig_line);
+
+         if (  chunk_is_preproc(prev)
+            && chunk_is_not_token(prev, CT_PP_ENDIF))
+         {
+            // previous line is a preprocessor, but NOT #endif
+            while (chunk_is_preproc(prev))
+            {
+               prev = chunk_get_prev_ncnl(prev);
+            }
+            chunk_t *next_prev = chunk_get_next_ncnl(prev);
+            LOG_FMT(LMCB, "%s(%d): next_prev->text() is '%s', orig_line %zu\n",
+                    __func__, __LINE__, next_prev->text(), next_prev->orig_line);
+            last = next_prev;
+         }
+         else
+         {
+            last = pc;
+         }
          break;
       }
    }
--- /dev/null
+++ b/tests/config/Issue_3040.cfg
@@ -0,0 +1,7 @@
+indent_columns                  = 2
+indent_switch_case              = 2
+nl_before_case                  = true
+nl_after_case                   = true
+eat_blanks_before_close_brace   = true
+mod_move_case_break             = true
+mod_case_brace                  = force
--- a/tests/cpp.test
+++ b/tests/cpp.test
@@ -827,6 +827,7 @@
 34322  issue_2623_1.cfg                     cpp/issue_2623.cpp
 34323  issue_2623_2.cfg                     cpp/issue_2623.cpp
 34324  issue_2623_3.cfg                     cpp/issue_2623.cpp
+34326  Issue_3040.cfg                       cpp/Issue_3040.cpp
 
 # Adopt some UT tests
 10000  empty.cfg                            cpp/621_this-spacing.cpp
--- /dev/null
+++ b/tests/expected/cpp/34326-Issue_3040.cpp
@@ -0,0 +1,62 @@
+void main()
+{
+  switch (opcode ) {
+
+    case LocaleCompare:
+    {
+      return Number(localeCompare(s, a0.toString(exec)));
+    }
+
+#ifndef KJS_PURE_ECMA
+    case Big:
+    {
+      result = String("<big>" + s + "</big>");
+      break;
+    }
+#endif
+  }
+
+  switch (ev->command)
+  {
+    case (MIDI_NOTEON):
+    {
+      ev->note = *ptrdata; ptrdata++; currentpos++;
+      ev->vel  = *ptrdata; ptrdata++; currentpos++;
+      if (ev->vel==0)
+	note[ev->chn][ev->note]=FALSE;
+      else
+	note[ev->chn][ev->note]=TRUE;
+
+#ifdef TRACKDEBUG2
+      if (ev->chn==6) {
+	if (ev->vel==0) printfdebug("Note Onf\n");
+	else printfdebug("Note On\n");
+      };
+#endif
+      break;
+    }
+
+    case (MIDI_NOTEOFF):
+    {
+#ifdef TRACKDEBUG2
+      if (ev->chn==6) printfdebug("Note Off\n");
+#endif
+      ev->note = *ptrdata; ptrdata++; currentpos++;
+      ev->vel  = *ptrdata; ptrdata++; currentpos++;
+      note[ev->chn][ev->note]=FALSE;
+
+      break;
+    }
+
+    case (MIDI_KEY_PRESSURE):
+    {
+#ifdef TRACKDEBUG2
+      if (ev->chn==6) printfdebug ("Key press\n");
+#endif
+      ev->note = *ptrdata; ptrdata++; currentpos++;
+      ev->vel  = *ptrdata; ptrdata++; currentpos++;
+      break;
+    }
+  }
+}
+
--- /dev/null
+++ b/tests/input/cpp/Issue_3040.cpp
@@ -0,0 +1,52 @@
+void main()
+{
+  switch (opcode ) {
+
+    case LocaleCompare:
+      return Number(localeCompare(s, a0.toString(exec)));
+
+#ifndef KJS_PURE_ECMA
+    case Big:
+      result = String("<big>" + s + "</big>");
+      break;
+#endif
+
+  }
+
+  switch (ev->command)
+  {
+    case (MIDI_NOTEON):
+      ev->note = *ptrdata; ptrdata++; currentpos++;
+      ev->vel  = *ptrdata; ptrdata++; currentpos++;
+      if (ev->vel==0)
+	note[ev->chn][ev->note]=FALSE;
+      else
+	note[ev->chn][ev->note]=TRUE;
+
+#ifdef TRACKDEBUG2
+      if (ev->chn==6) {
+	if (ev->vel==0) printfdebug("Note Onf\n");
+	else printfdebug("Note On\n");
+      };
+#endif
+      break;
+    case (MIDI_NOTEOFF) :
+#ifdef TRACKDEBUG2
+      if (ev->chn==6) printfdebug("Note Off\n");
+#endif
+      ev->note = *ptrdata;ptrdata++;currentpos++; 
+      ev->vel  = *ptrdata;ptrdata++;currentpos++;
+      note[ev->chn][ev->note]=FALSE;
+
+      break;
+    case (MIDI_KEY_PRESSURE) :
+#ifdef TRACKDEBUG2
+      if (ev->chn==6) printfdebug ("Key press\n");
+#endif
+      ev->note = *ptrdata;ptrdata++;currentpos++; 
+      ev->vel  = *ptrdata;ptrdata++;currentpos++;
+      break;
+
+		}
+}
+