libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / m2 / mc-boot / GmcPretty.cc
blob0bffa1ff6feb4025432e5dc2e01a4b550207c48c
1 /* do not edit automatically generated by mc from mcPretty. */
2 /* This file is part of GNU Modula-2.
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 3, or (at your option) any later
7 version.
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3. If not see
16 <http://www.gnu.org/licenses/>. */
18 #include "config.h"
19 #include "system.h"
20 #include <stdbool.h>
21 # if !defined (PROC_D)
22 # define PROC_D
23 typedef void (*PROC_t) (void);
24 typedef struct { PROC_t proc; } PROC;
25 # endif
27 # if !defined (TRUE)
28 # define TRUE (1==1)
29 # endif
31 # if !defined (FALSE)
32 # define FALSE (1==0)
33 # endif
35 # include "GStorage.h"
36 #if defined(__cplusplus)
37 # undef NULL
38 # define NULL 0
39 #endif
40 #define _mcPretty_C
42 #include "GmcPretty.h"
43 # include "GDynamicStrings.h"
44 # include "GStorage.h"
46 typedef struct mcPretty_writeProc_p mcPretty_writeProc;
48 typedef struct mcPretty_writeLnProc_p mcPretty_writeLnProc;
50 typedef struct mcPretty__T1_r mcPretty__T1;
52 typedef mcPretty__T1 *mcPretty_pretty__opaque;
54 struct mcPretty__T1_r {
55 mcPretty_writeProc write_;
56 mcPretty_writeLnProc writeln;
57 bool needsSpace;
58 bool needsIndent;
59 unsigned int seekPos;
60 unsigned int curLine;
61 unsigned int curPos;
62 unsigned int indent;
63 mcPretty_pretty__opaque stacked;
68 initPretty - initialise a pretty print data structure.
71 extern "C" mcPretty_pretty mcPretty_initPretty (mcPretty_writeProc w, mcPretty_writeLnProc l);
74 dupPretty - duplicate a pretty print data structure.
77 extern "C" mcPretty_pretty mcPretty_dupPretty (mcPretty_pretty p);
80 killPretty - destroy a pretty print data structure.
81 Post condition: p is assigned to NIL.
84 extern "C" void mcPretty_killPretty (mcPretty_pretty *p);
87 pushPretty - duplicate, p. Push, p, and return the duplicate.
90 extern "C" mcPretty_pretty mcPretty_pushPretty (mcPretty_pretty p);
93 popPretty - pops the pretty object from the stack.
96 extern "C" mcPretty_pretty mcPretty_popPretty (mcPretty_pretty p);
99 getindent - returns the current indent value.
102 extern "C" unsigned int mcPretty_getindent (mcPretty_pretty p);
105 setindent - sets the current indent to, n.
108 extern "C" void mcPretty_setindent (mcPretty_pretty p, unsigned int n);
111 getcurpos - returns the current cursor position.
114 extern "C" unsigned int mcPretty_getcurpos (mcPretty_pretty s);
117 getseekpos - returns the seek position.
120 extern "C" unsigned int mcPretty_getseekpos (mcPretty_pretty s);
123 getcurline - returns the current line number.
126 extern "C" unsigned int mcPretty_getcurline (mcPretty_pretty s);
127 extern "C" void mcPretty_setNeedSpace (mcPretty_pretty s);
130 noSpace - unset needsSpace.
133 extern "C" void mcPretty_noSpace (mcPretty_pretty s);
136 print - print a string using, p.
139 extern "C" void mcPretty_print (mcPretty_pretty p, const char *a_, unsigned int _a_high);
142 prints - print a string using, p.
145 extern "C" void mcPretty_prints (mcPretty_pretty p, DynamicStrings_String s);
148 raw - print out string, s, without any translation of
149 escape sequences.
152 extern "C" void mcPretty_raw (mcPretty_pretty p, DynamicStrings_String s);
155 flushSpace -
158 static void flushSpace (mcPretty_pretty__opaque p);
161 flushIndent -
164 static void flushIndent (mcPretty_pretty__opaque p);
168 flushSpace -
171 static void flushSpace (mcPretty_pretty__opaque p)
173 if (p->needsSpace)
175 (*p->write_.proc) (' ');
176 p->needsSpace = false;
177 p->curPos += 1;
178 p->seekPos += 1;
184 flushIndent -
187 static void flushIndent (mcPretty_pretty__opaque p)
189 unsigned int i;
191 flushSpace (p);
192 if (p->needsIndent)
194 while (p->curPos < p->indent)
196 (*p->write_.proc) (' ');
197 p->curPos += 1;
198 p->seekPos += 1;
200 p->needsIndent = false;
206 initPretty - initialise a pretty print data structure.
209 extern "C" mcPretty_pretty mcPretty_initPretty (mcPretty_writeProc w, mcPretty_writeLnProc l)
211 mcPretty_pretty__opaque p;
213 Storage_ALLOCATE ((void **) &p, sizeof (mcPretty__T1));
214 p->write_ = w;
215 p->writeln = l;
216 p->needsSpace = false;
217 p->needsIndent = false;
218 p->curPos = 0;
219 p->curLine = 0;
220 p->seekPos = 0;
221 p->indent = 0;
222 p->stacked = static_cast<mcPretty_pretty__opaque> (NULL);
223 return static_cast<mcPretty_pretty> (p);
224 /* static analysis guarentees a RETURN statement will be used before here. */
225 __builtin_unreachable ();
230 dupPretty - duplicate a pretty print data structure.
233 extern "C" mcPretty_pretty mcPretty_dupPretty (mcPretty_pretty p)
235 mcPretty_pretty__opaque q;
237 Storage_ALLOCATE ((void **) &q, sizeof (mcPretty__T1));
238 (*q) = (*static_cast<mcPretty_pretty__opaque> (p));
239 return static_cast<mcPretty_pretty> (q);
240 /* static analysis guarentees a RETURN statement will be used before here. */
241 __builtin_unreachable ();
246 killPretty - destroy a pretty print data structure.
247 Post condition: p is assigned to NIL.
250 extern "C" void mcPretty_killPretty (mcPretty_pretty *p)
252 (*p) = static_cast<mcPretty_pretty> (NULL);
253 return;
254 Storage_DEALLOCATE ((void **) &(*p), sizeof (mcPretty__T1));
255 (*p) = static_cast<mcPretty_pretty> (NULL);
260 pushPretty - duplicate, p. Push, p, and return the duplicate.
263 extern "C" mcPretty_pretty mcPretty_pushPretty (mcPretty_pretty p)
265 mcPretty_pretty__opaque q;
267 q = static_cast<mcPretty_pretty__opaque> (mcPretty_dupPretty (p));
268 q->stacked = static_cast<mcPretty_pretty__opaque> (p);
269 return static_cast<mcPretty_pretty> (q);
270 /* static analysis guarentees a RETURN statement will be used before here. */
271 __builtin_unreachable ();
276 popPretty - pops the pretty object from the stack.
279 extern "C" mcPretty_pretty mcPretty_popPretty (mcPretty_pretty p)
281 mcPretty_pretty__opaque q;
283 q = static_cast<mcPretty_pretty__opaque> (p)->stacked;
284 q->needsIndent = static_cast<mcPretty_pretty__opaque> (p)->needsIndent;
285 q->needsSpace = static_cast<mcPretty_pretty__opaque> (p)->needsSpace;
286 q->curPos = static_cast<mcPretty_pretty__opaque> (p)->curPos;
287 q->seekPos = static_cast<mcPretty_pretty__opaque> (p)->seekPos;
288 q->curLine = static_cast<mcPretty_pretty__opaque> (p)->curLine;
289 mcPretty_killPretty (&p);
290 return static_cast<mcPretty_pretty> (q);
291 /* static analysis guarentees a RETURN statement will be used before here. */
292 __builtin_unreachable ();
297 getindent - returns the current indent value.
300 extern "C" unsigned int mcPretty_getindent (mcPretty_pretty p)
302 return static_cast<mcPretty_pretty__opaque> (p)->indent;
303 /* static analysis guarentees a RETURN statement will be used before here. */
304 __builtin_unreachable ();
309 setindent - sets the current indent to, n.
312 extern "C" void mcPretty_setindent (mcPretty_pretty p, unsigned int n)
314 static_cast<mcPretty_pretty__opaque> (p)->indent = n;
319 getcurpos - returns the current cursor position.
322 extern "C" unsigned int mcPretty_getcurpos (mcPretty_pretty s)
324 if (static_cast<mcPretty_pretty__opaque> (s)->needsSpace)
326 return static_cast<mcPretty_pretty__opaque> (s)->curPos+1;
328 else
330 return static_cast<mcPretty_pretty__opaque> (s)->curPos;
332 /* static analysis guarentees a RETURN statement will be used before here. */
333 __builtin_unreachable ();
338 getseekpos - returns the seek position.
341 extern "C" unsigned int mcPretty_getseekpos (mcPretty_pretty s)
343 return static_cast<mcPretty_pretty__opaque> (s)->seekPos;
344 /* static analysis guarentees a RETURN statement will be used before here. */
345 __builtin_unreachable ();
350 getcurline - returns the current line number.
353 extern "C" unsigned int mcPretty_getcurline (mcPretty_pretty s)
355 return static_cast<mcPretty_pretty__opaque> (s)->curLine;
356 /* static analysis guarentees a RETURN statement will be used before here. */
357 __builtin_unreachable ();
360 extern "C" void mcPretty_setNeedSpace (mcPretty_pretty s)
363 setneedSpace - sets needSpace flag to TRUE.
365 static_cast<mcPretty_pretty__opaque> (s)->needsSpace = true;
370 noSpace - unset needsSpace.
373 extern "C" void mcPretty_noSpace (mcPretty_pretty s)
375 static_cast<mcPretty_pretty__opaque> (s)->needsSpace = false;
380 print - print a string using, p.
383 extern "C" void mcPretty_print (mcPretty_pretty p, const char *a_, unsigned int _a_high)
385 DynamicStrings_String s;
386 char a[_a_high+1];
388 /* make a local copy of each unbounded array. */
389 memcpy (a, a_, _a_high+1);
391 s = DynamicStrings_InitString ((const char *) a, _a_high);
392 mcPretty_prints (p, s);
393 s = DynamicStrings_KillString (s);
398 prints - print a string using, p.
401 extern "C" void mcPretty_prints (mcPretty_pretty p, DynamicStrings_String s)
403 unsigned int l;
404 unsigned int i;
406 l = DynamicStrings_Length (s);
407 i = 0;
408 flushSpace (static_cast<mcPretty_pretty__opaque> (p));
409 while (i < l)
411 if ((((i+2) <= l) && ((DynamicStrings_char (s, static_cast<int> (i))) == '\\')) && ((DynamicStrings_char (s, static_cast<int> (i+1))) == 'n'))
413 static_cast<mcPretty_pretty__opaque> (p)->needsIndent = true;
414 static_cast<mcPretty_pretty__opaque> (p)->needsSpace = false;
415 static_cast<mcPretty_pretty__opaque> (p)->curPos = 0;
416 (*static_cast<mcPretty_pretty__opaque> (p)->writeln.proc) ();
417 static_cast<mcPretty_pretty__opaque> (p)->seekPos += 1;
418 static_cast<mcPretty_pretty__opaque> (p)->curLine += 1;
419 i += 1;
421 else
423 flushIndent (static_cast<mcPretty_pretty__opaque> (p));
424 (*static_cast<mcPretty_pretty__opaque> (p)->write_.proc) (DynamicStrings_char (s, static_cast<int> (i)));
425 static_cast<mcPretty_pretty__opaque> (p)->curPos += 1;
426 static_cast<mcPretty_pretty__opaque> (p)->seekPos += 1;
428 i += 1;
434 raw - print out string, s, without any translation of
435 escape sequences.
438 extern "C" void mcPretty_raw (mcPretty_pretty p, DynamicStrings_String s)
440 unsigned int l;
441 unsigned int i;
443 l = DynamicStrings_Length (s);
444 i = 0;
445 flushSpace (static_cast<mcPretty_pretty__opaque> (p));
446 flushIndent (static_cast<mcPretty_pretty__opaque> (p));
447 while (i < l)
449 (*static_cast<mcPretty_pretty__opaque> (p)->write_.proc) (DynamicStrings_char (s, static_cast<int> (i)));
450 static_cast<mcPretty_pretty__opaque> (p)->curPos += 1;
451 static_cast<mcPretty_pretty__opaque> (p)->seekPos += 1;
452 i += 1;
456 extern "C" void _M2_mcPretty_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
460 extern "C" void _M2_mcPretty_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])