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
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
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/>. */
21 # if !defined (PROC_D)
23 typedef void (*PROC_t
) (void);
24 typedef struct { PROC_t proc
; } PROC
;
35 # include "GStorage.h"
36 #if defined(__cplusplus)
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
;
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
152 extern "C" void mcPretty_raw (mcPretty_pretty p
, DynamicStrings_String s
);
158 static void flushSpace (mcPretty_pretty__opaque p
);
164 static void flushIndent (mcPretty_pretty__opaque p
);
171 static void flushSpace (mcPretty_pretty__opaque p
)
175 (*p
->write_
.proc
) (' ');
176 p
->needsSpace
= false;
187 static void flushIndent (mcPretty_pretty__opaque p
)
194 while (p
->curPos
< p
->indent
)
196 (*p
->write_
.proc
) (' ');
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
));
216 p
->needsSpace
= false;
217 p
->needsIndent
= false;
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
);
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;
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
;
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
)
406 l
= DynamicStrings_Length (s
);
408 flushSpace (static_cast<mcPretty_pretty__opaque
> (p
));
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;
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;
434 raw - print out string, s, without any translation of
438 extern "C" void mcPretty_raw (mcPretty_pretty p
, DynamicStrings_String s
)
443 l
= DynamicStrings_Length (s
);
445 flushSpace (static_cast<mcPretty_pretty__opaque
> (p
));
446 flushIndent (static_cast<mcPretty_pretty__opaque
> (p
));
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;
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
[])