libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / m2 / mc-boot / GDynamicStrings.cc
blob2b182b9b2c0de0fafef57a3f9be0f7f2bb8e2c8d
1 /* do not edit automatically generated by mc from DynamicStrings. */
2 /* DynamicStrings.mod provides a dynamic string type and procedures.
4 Copyright (C) 2001-2024 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
7 This file is part of GNU Modula-2.
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
28 #include "config.h"
29 #include "system.h"
30 #include <stdbool.h>
31 # if !defined (PROC_D)
32 # define PROC_D
33 typedef void (*PROC_t) (void);
34 typedef struct { PROC_t proc; } PROC;
35 # endif
37 # if !defined (TRUE)
38 # define TRUE (1==1)
39 # endif
41 # if !defined (FALSE)
42 # define FALSE (1==0)
43 # endif
45 # include "GStorage.h"
46 #if defined(__cplusplus)
47 # undef NULL
48 # define NULL 0
49 #endif
50 #define _DynamicStrings_C
52 #include "GDynamicStrings.h"
53 # include "Glibc.h"
54 # include "GStrLib.h"
55 # include "GStorage.h"
56 # include "GAssertion.h"
57 # include "GSYSTEM.h"
58 # include "GASCII.h"
59 # include "GM2RTS.h"
61 # define MaxBuf 127
62 # define PoisonOn false
63 # define DebugOn false
64 # define CheckOn false
65 # define TraceOn false
66 typedef struct DynamicStrings_Contents_r DynamicStrings_Contents;
68 typedef struct DynamicStrings_DebugInfo_r DynamicStrings_DebugInfo;
70 typedef struct DynamicStrings_stringRecord_r DynamicStrings_stringRecord;
72 typedef struct DynamicStrings_descriptor_r DynamicStrings_descriptor;
74 typedef DynamicStrings_descriptor *DynamicStrings_Descriptor;
76 typedef struct DynamicStrings_frameRec_r DynamicStrings_frameRec;
78 typedef DynamicStrings_frameRec *DynamicStrings_frame;
80 typedef struct DynamicStrings__T3_a DynamicStrings__T3;
82 typedef enum {DynamicStrings_inuse, DynamicStrings_marked, DynamicStrings_onlist, DynamicStrings_poisoned} DynamicStrings_desState;
84 typedef DynamicStrings_stringRecord *DynamicStrings_String__opaque;
86 struct DynamicStrings_DebugInfo_r {
87 DynamicStrings_String__opaque next;
88 void * file;
89 unsigned int line;
90 void * proc;
93 struct DynamicStrings_descriptor_r {
94 bool charStarUsed;
95 void * charStar;
96 unsigned int charStarSize;
97 bool charStarValid;
98 DynamicStrings_desState state;
99 DynamicStrings_String__opaque garbage;
102 struct DynamicStrings_frameRec_r {
103 DynamicStrings_String__opaque alloc;
104 DynamicStrings_String__opaque dealloc;
105 DynamicStrings_frame next;
108 struct DynamicStrings__T3_a { char array[(MaxBuf-1)+1]; };
109 struct DynamicStrings_Contents_r {
110 DynamicStrings__T3 buf;
111 unsigned int len;
112 DynamicStrings_String__opaque next;
115 struct DynamicStrings_stringRecord_r {
116 DynamicStrings_Contents contents;
117 DynamicStrings_Descriptor head;
118 DynamicStrings_DebugInfo debug;
121 static bool Initialized;
122 static DynamicStrings_frame frameHead;
123 static DynamicStrings_String__opaque captured;
126 InitString - creates and returns a String type object.
127 Initial contents are, a.
130 extern "C" DynamicStrings_String DynamicStrings_InitString (const char *a_, unsigned int _a_high);
133 KillString - frees String, s, and its contents.
134 NIL is returned.
137 extern "C" DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s);
140 Fin - finishes with a string, it calls KillString with, s.
141 The purpose of the procedure is to provide a short cut
142 to calling KillString and then testing the return result.
145 extern "C" void DynamicStrings_Fin (DynamicStrings_String s);
148 InitStringCharStar - initializes and returns a String to contain the C string.
151 extern "C" DynamicStrings_String DynamicStrings_InitStringCharStar (void * a);
154 InitStringChar - initializes and returns a String to contain the single character, ch.
157 extern "C" DynamicStrings_String DynamicStrings_InitStringChar (char ch);
160 Mark - marks String, s, ready for garbage collection.
163 extern "C" DynamicStrings_String DynamicStrings_Mark (DynamicStrings_String s);
166 Length - returns the length of the String, s.
169 extern "C" unsigned int DynamicStrings_Length (DynamicStrings_String s);
172 ConCat - returns String, a, after the contents of, b, have been appended.
175 extern "C" DynamicStrings_String DynamicStrings_ConCat (DynamicStrings_String a, DynamicStrings_String b);
178 ConCatChar - returns String, a, after character, ch, has been appended.
181 extern "C" DynamicStrings_String DynamicStrings_ConCatChar (DynamicStrings_String a, char ch);
184 Assign - assigns the contents of, b, into, a.
185 String, a, is returned.
188 extern "C" DynamicStrings_String DynamicStrings_Assign (DynamicStrings_String a, DynamicStrings_String b);
191 ReplaceChar - returns string s after it has changed all occurances of from to to.
194 extern "C" DynamicStrings_String DynamicStrings_ReplaceChar (DynamicStrings_String s, char from, char to);
197 Dup - duplicate a String, s, returning the copy of s.
200 extern "C" DynamicStrings_String DynamicStrings_Dup (DynamicStrings_String s);
203 Add - returns a new String which contains the contents of a and b.
206 extern "C" DynamicStrings_String DynamicStrings_Add (DynamicStrings_String a, DynamicStrings_String b);
209 Equal - returns TRUE if String, a, and, b, are equal.
212 extern "C" bool DynamicStrings_Equal (DynamicStrings_String a, DynamicStrings_String b);
215 EqualCharStar - returns TRUE if contents of String, s, is the same as the
216 string, a.
219 extern "C" bool DynamicStrings_EqualCharStar (DynamicStrings_String s, void * a);
222 EqualArray - returns TRUE if contents of String, s, is the same as the
223 string, a.
226 extern "C" bool DynamicStrings_EqualArray (DynamicStrings_String s, const char *a_, unsigned int _a_high);
229 Mult - returns a new string which is n concatenations of String, s.
232 extern "C" DynamicStrings_String DynamicStrings_Mult (DynamicStrings_String s, unsigned int n);
235 Slice - returns a new string which contains the elements
236 low..high-1
238 strings start at element 0
239 Slice(s, 0, 2) will return elements 0, 1 but not 2
240 Slice(s, 1, 3) will return elements 1, 2 but not 3
241 Slice(s, 2, 0) will return elements 2..max
242 Slice(s, 3, -1) will return elements 3..max-1
243 Slice(s, 4, -2) will return elements 4..max-2
246 extern "C" DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, int high);
249 Index - returns the indice of the first occurance of, ch, in
250 String, s. -1 is returned if, ch, does not exist.
251 The search starts at position, o.
254 extern "C" int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o);
257 RIndex - returns the indice of the last occurance of, ch,
258 in String, s. The search starts at position, o.
259 -1 is returned if, ch, is not found. The search
260 is performed left to right.
263 extern "C" int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o);
266 ReverseIndex - returns the indice of the last occurance of ch
267 in String s. The search starts at position o
268 and searches from right to left. The start position
269 may be indexed negatively from the right (-1 is the
270 last index).
271 The return value if ch is found will always be positive.
272 -1 is returned if ch is not found.
275 extern "C" int DynamicStrings_ReverseIndex (DynamicStrings_String s, char ch, int o);
278 RemoveComment - assuming that, comment, is a comment delimiter
279 which indicates anything to its right is a comment
280 then strip off the comment and also any white space
281 on the remaining right hand side.
282 It leaves any white space on the left hand side alone.
285 extern "C" DynamicStrings_String DynamicStrings_RemoveComment (DynamicStrings_String s, char comment);
288 RemoveWhitePrefix - removes any leading white space from String, s.
289 A new string is returned.
292 extern "C" DynamicStrings_String DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s);
295 RemoveWhitePostfix - removes any leading white space from String, s.
296 A new string is returned.
299 extern "C" DynamicStrings_String DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s);
302 ToUpper - returns string, s, after it has had its lower case characters
303 replaced by upper case characters.
304 The string, s, is not duplicated.
307 extern "C" DynamicStrings_String DynamicStrings_ToUpper (DynamicStrings_String s);
310 ToLower - returns string, s, after it has had its upper case characters
311 replaced by lower case characters.
312 The string, s, is not duplicated.
315 extern "C" DynamicStrings_String DynamicStrings_ToLower (DynamicStrings_String s);
318 CopyOut - copies string, s, to a.
321 extern "C" void DynamicStrings_CopyOut (char *a, unsigned int _a_high, DynamicStrings_String s);
324 char - returns the character, ch, at position, i, in String, s.
327 extern "C" char DynamicStrings_char (DynamicStrings_String s, int i);
330 string - returns the C style char * of String, s.
333 extern "C" void * DynamicStrings_string (DynamicStrings_String s);
336 InitStringDB - the debug version of InitString.
339 extern "C" DynamicStrings_String DynamicStrings_InitStringDB (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line);
342 InitStringCharStarDB - the debug version of InitStringCharStar.
345 extern "C" DynamicStrings_String DynamicStrings_InitStringCharStarDB (void * a, const char *file_, unsigned int _file_high, unsigned int line);
348 InitStringCharDB - the debug version of InitStringChar.
351 extern "C" DynamicStrings_String DynamicStrings_InitStringCharDB (char ch, const char *file_, unsigned int _file_high, unsigned int line);
354 MultDB - the debug version of MultDB.
357 extern "C" DynamicStrings_String DynamicStrings_MultDB (DynamicStrings_String s, unsigned int n, const char *file_, unsigned int _file_high, unsigned int line);
360 DupDB - the debug version of Dup.
363 extern "C" DynamicStrings_String DynamicStrings_DupDB (DynamicStrings_String s, const char *file_, unsigned int _file_high, unsigned int line);
366 SliceDB - debug version of Slice.
369 extern "C" DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low, int high, const char *file_, unsigned int _file_high, unsigned int line);
372 PushAllocation - pushes the current allocation/deallocation lists.
375 extern "C" void DynamicStrings_PushAllocation (void);
378 PopAllocation - test to see that all strings are deallocated since
379 the last push. Then it pops to the previous
380 allocation/deallocation lists.
382 If halt is true then the application terminates
383 with an exit code of 1.
386 extern "C" void DynamicStrings_PopAllocation (bool halt);
389 PopAllocationExemption - test to see that all strings are deallocated, except
390 string e since the last push.
391 Post-condition: it pops to the previous allocation/deallocation
392 lists.
394 If halt is true then the application terminates
395 with an exit code of 1.
398 extern "C" DynamicStrings_String DynamicStrings_PopAllocationExemption (bool halt, DynamicStrings_String e);
401 writeStringDesc write out debugging information about string, s. */
403 static void writeStringDesc (DynamicStrings_String__opaque s);
406 writeNspace -
409 static void writeNspace (unsigned int n);
412 DumpStringInfo -
415 static void DumpStringInfo (DynamicStrings_String__opaque s, unsigned int i);
418 DumpStringInfo -
421 static void stop (void);
424 doDSdbEnter -
427 static void doDSdbEnter (void);
430 doDSdbExit -
433 static void doDSdbExit (DynamicStrings_String__opaque s);
436 DSdbEnter -
439 static void DSdbEnter (void);
442 DSdbExit -
445 static void DSdbExit (DynamicStrings_String__opaque s);
446 static unsigned int Capture (DynamicStrings_String__opaque s);
449 Min -
452 static unsigned int Min (unsigned int a, unsigned int b);
455 Max -
458 static unsigned int Max (unsigned int a, unsigned int b);
461 writeString - writes a string to stdout.
464 static void writeString (const char *a_, unsigned int _a_high);
467 writeCstring - writes a C string to stdout.
470 static void writeCstring (void * a);
473 writeCard -
476 static void writeCard (unsigned int c);
479 writeLongcard -
482 static void writeLongcard (long unsigned int l);
485 writeAddress - writes out the address of a with a C style hex prefix.
488 static void writeAddress (void * a);
491 writeLn - writes a newline.
494 static void writeLn (void);
497 AssignDebug - assigns, file, and, line, information to string, s.
500 static DynamicStrings_String__opaque AssignDebug (DynamicStrings_String__opaque s, const char *file_, unsigned int _file_high, unsigned int line, const char *proc_, unsigned int _proc_high);
503 IsOn - returns TRUE if, s, is on one of the debug lists.
506 static bool IsOn (DynamicStrings_String__opaque list, DynamicStrings_String__opaque s);
509 AddTo - adds string, s, to, list.
512 static void AddTo (DynamicStrings_String__opaque *list, DynamicStrings_String__opaque s);
515 SubFrom - removes string, s, from, list.
518 static void SubFrom (DynamicStrings_String__opaque *list, DynamicStrings_String__opaque s);
521 AddAllocated - adds string, s, to the head of the allocated list.
524 static void AddAllocated (DynamicStrings_String__opaque s);
527 AddDeallocated - adds string, s, to the head of the deallocated list.
530 static void AddDeallocated (DynamicStrings_String__opaque s);
533 IsOnAllocated - returns TRUE if the string, s, has ever been allocated.
536 static bool IsOnAllocated (DynamicStrings_String__opaque s);
539 IsOnDeallocated - returns TRUE if the string, s, has ever been deallocated.
542 static bool IsOnDeallocated (DynamicStrings_String__opaque s);
545 SubAllocated - removes string, s, from the list of allocated strings.
548 static void SubAllocated (DynamicStrings_String__opaque s);
551 SubDeallocated - removes string, s, from the list of deallocated strings.
554 static void SubDeallocated (DynamicStrings_String__opaque s);
557 SubDebugInfo - removes string, s, from the list of allocated strings.
560 static void SubDebugInfo (DynamicStrings_String__opaque s);
563 AddDebugInfo - adds string, s, to the list of allocated strings.
566 static void AddDebugInfo (DynamicStrings_String__opaque s);
569 ConcatContents - add the contents of string, a, where, h, is the
570 total length of, a. The offset is in, o.
573 static void ConcatContents (DynamicStrings_Contents *c, const char *a_, unsigned int _a_high, unsigned int h, unsigned int o);
576 DeallocateCharStar - deallocates any charStar.
579 static void DeallocateCharStar (DynamicStrings_String__opaque s);
582 CheckPoisoned - checks for a poisoned string, s.
585 static DynamicStrings_String__opaque CheckPoisoned (DynamicStrings_String__opaque s);
588 MarkInvalid - marks the char * version of String, s, as invalid.
591 static void MarkInvalid (DynamicStrings_String__opaque s);
594 ConcatContentsAddress - concatenate the string, a, where, h, is the
595 total length of, a.
598 static void ConcatContentsAddress (DynamicStrings_Contents *c, void * a, unsigned int h);
601 AddToGarbage - adds String, b, onto the garbage list of, a. Providing
602 the state of b is marked. The state is then altered to
603 onlist. String, a, is returned.
606 static DynamicStrings_String__opaque AddToGarbage (DynamicStrings_String__opaque a, DynamicStrings_String__opaque b);
609 IsOnGarbage - returns TRUE if, s, is on string, e, garbage list.
612 static bool IsOnGarbage (DynamicStrings_String__opaque e, DynamicStrings_String__opaque s);
615 IsWhite - returns TRUE if, ch, is a space or a tab.
618 static bool IsWhite (char ch);
621 DumpState -
624 static void DumpState (DynamicStrings_String__opaque s);
627 DumpStringSynopsis -
630 static void DumpStringSynopsis (DynamicStrings_String__opaque s);
633 DumpString - displays the contents of string, s.
636 static void DumpString (DynamicStrings_String__opaque s);
639 Init - initialize the module.
642 static void Init (void);
646 writeStringDesc write out debugging information about string, s. */
648 static void writeStringDesc (DynamicStrings_String__opaque s)
650 writeCstring (s->debug.file);
651 writeString ((const char *) ":", 1);
652 writeCard (s->debug.line);
653 writeString ((const char *) ":", 1);
654 writeCstring (s->debug.proc);
655 writeString ((const char *) " ", 1);
656 writeAddress (reinterpret_cast <void *> (s));
657 writeString ((const char *) " ", 1);
658 switch (s->head->state)
660 case DynamicStrings_inuse:
661 writeString ((const char *) "still in use (", 14);
662 writeCard (s->contents.len);
663 writeString ((const char *) ") characters", 12);
664 break;
666 case DynamicStrings_marked:
667 writeString ((const char *) "marked", 6);
668 break;
670 case DynamicStrings_onlist:
671 writeString ((const char *) "on a (lost) garbage list", 24);
672 break;
674 case DynamicStrings_poisoned:
675 writeString ((const char *) "poisoned", 8);
676 break;
679 default:
680 writeString ((const char *) "unknown state", 13);
681 break;
687 writeNspace -
690 static void writeNspace (unsigned int n)
692 while (n > 0)
694 writeString ((const char *) " ", 1);
695 n -= 1;
701 DumpStringInfo -
704 static void DumpStringInfo (DynamicStrings_String__opaque s, unsigned int i)
706 if (s != NULL)
708 writeNspace (i);
709 writeStringDesc (s);
710 writeLn ();
711 if (s->head->garbage != NULL)
713 writeNspace (i);
714 writeString ((const char *) "garbage list:", 13);
715 writeLn ();
716 do {
717 s = s->head->garbage;
718 DumpStringInfo (s, i+1);
719 writeLn ();
720 } while (! (s == NULL));
727 DumpStringInfo -
730 static void stop (void)
736 doDSdbEnter -
739 static void doDSdbEnter (void)
741 if (CheckOn)
743 DynamicStrings_PushAllocation ();
749 doDSdbExit -
752 static void doDSdbExit (DynamicStrings_String__opaque s)
754 if (CheckOn)
756 s = static_cast<DynamicStrings_String__opaque> (DynamicStrings_PopAllocationExemption (true, static_cast<DynamicStrings_String> (s)));
762 DSdbEnter -
765 static void DSdbEnter (void)
771 DSdbExit -
774 static void DSdbExit (DynamicStrings_String__opaque s)
778 static unsigned int Capture (DynamicStrings_String__opaque s)
781 * #undef GM2_DEBUG_DYNAMICSTINGS
782 * #if defined(GM2_DEBUG_DYNAMICSTINGS)
783 * # define DSdbEnter doDSdbEnter
784 * # define DSdbExit doDSdbExit
785 * # define CheckOn TRUE
786 * # define TraceOn TRUE
787 * #endif
789 captured = s;
790 return 1;
791 /* static analysis guarentees a RETURN statement will be used before here. */
792 __builtin_unreachable ();
797 Min -
800 static unsigned int Min (unsigned int a, unsigned int b)
802 if (a < b)
804 return a;
806 else
808 return b;
810 /* static analysis guarentees a RETURN statement will be used before here. */
811 __builtin_unreachable ();
816 Max -
819 static unsigned int Max (unsigned int a, unsigned int b)
821 if (a > b)
823 return a;
825 else
827 return b;
829 /* static analysis guarentees a RETURN statement will be used before here. */
830 __builtin_unreachable ();
835 writeString - writes a string to stdout.
838 static void writeString (const char *a_, unsigned int _a_high)
840 int i;
841 char a[_a_high+1];
843 /* make a local copy of each unbounded array. */
844 memcpy (a, a_, _a_high+1);
846 i = static_cast<int> (libc_write (1, const_cast<void*> (static_cast<const void*>(a)), static_cast<size_t> (StrLib_StrLen ((const char *) a, _a_high))));
851 writeCstring - writes a C string to stdout.
854 static void writeCstring (void * a)
856 int i;
858 if (a == NULL)
860 writeString ((const char *) "(null)", 6);
862 else
864 i = static_cast<int> (libc_write (1, a, libc_strlen (a)));
870 writeCard -
873 static void writeCard (unsigned int c)
875 char ch;
876 int i;
878 if (c > 9)
880 writeCard (c / 10);
881 writeCard (c % 10);
883 else
885 ch = ((char) ( ((unsigned int) ('0'))+c));
886 i = static_cast<int> (libc_write (1, &ch, static_cast<size_t> (1)));
892 writeLongcard -
895 static void writeLongcard (long unsigned int l)
897 char ch;
898 int i;
900 if (l > 16)
902 writeLongcard (l / 16);
903 writeLongcard (l % 16);
905 else if (l < 10)
907 /* avoid dangling else. */
908 ch = ((char) ( ((unsigned int) ('0'))+((unsigned int ) (l))));
909 i = static_cast<int> (libc_write (1, &ch, static_cast<size_t> (1)));
911 else if (l < 16)
913 /* avoid dangling else. */
914 ch = ((char) (( ((unsigned int) ('a'))+((unsigned int ) (l)))-10));
915 i = static_cast<int> (libc_write (1, &ch, static_cast<size_t> (1)));
921 writeAddress - writes out the address of a with a C style hex prefix.
924 static void writeAddress (void * a)
926 typedef struct writeAddress__T4_a writeAddress__T4;
928 struct writeAddress__T4_a { char array[30+1]; };
929 writeAddress__T4 buffer;
931 libc_snprintf (&buffer, static_cast<size_t> (sizeof (buffer)), (const char *) "0x%", 3, a);
932 writeString ((const char *) &buffer.array[0], 30);
937 writeLn - writes a newline.
940 static void writeLn (void)
942 char ch;
943 int i;
945 ch = ASCII_lf;
946 i = static_cast<int> (libc_write (1, &ch, static_cast<size_t> (1)));
951 AssignDebug - assigns, file, and, line, information to string, s.
954 static DynamicStrings_String__opaque AssignDebug (DynamicStrings_String__opaque s, const char *file_, unsigned int _file_high, unsigned int line, const char *proc_, unsigned int _proc_high)
956 void * f;
957 void * p;
958 char file[_file_high+1];
959 char proc[_proc_high+1];
961 /* make a local copy of each unbounded array. */
962 memcpy (file, file_, _file_high+1);
963 memcpy (proc, proc_, _proc_high+1);
965 f = const_cast<void*> (static_cast<const void*>(file));
966 p = const_cast<void*> (static_cast<const void*>(proc));
967 Storage_ALLOCATE (&s->debug.file, (StrLib_StrLen ((const char *) file, _file_high))+1);
968 if ((libc_strncpy (s->debug.file, f, (StrLib_StrLen ((const char *) file, _file_high))+1)) == NULL)
969 {} /* empty. */
970 s->debug.line = line;
971 Storage_ALLOCATE (&s->debug.proc, (StrLib_StrLen ((const char *) proc, _proc_high))+1);
972 if ((libc_strncpy (s->debug.proc, p, (StrLib_StrLen ((const char *) proc, _proc_high))+1)) == NULL)
973 {} /* empty. */
974 return s;
975 /* static analysis guarentees a RETURN statement will be used before here. */
976 __builtin_unreachable ();
981 IsOn - returns TRUE if, s, is on one of the debug lists.
984 static bool IsOn (DynamicStrings_String__opaque list, DynamicStrings_String__opaque s)
986 while ((list != s) && (list != NULL))
988 list = list->debug.next;
990 return list == s;
991 /* static analysis guarentees a RETURN statement will be used before here. */
992 __builtin_unreachable ();
997 AddTo - adds string, s, to, list.
1000 static void AddTo (DynamicStrings_String__opaque *list, DynamicStrings_String__opaque s)
1002 if ((*list) == NULL)
1004 (*list) = s;
1005 s->debug.next = static_cast<DynamicStrings_String__opaque> (NULL);
1007 else
1009 s->debug.next = (*list);
1010 (*list) = s;
1016 SubFrom - removes string, s, from, list.
1019 static void SubFrom (DynamicStrings_String__opaque *list, DynamicStrings_String__opaque s)
1021 DynamicStrings_String__opaque p;
1023 if ((*list) == s)
1025 (*list) = s->debug.next;
1027 else
1029 p = (*list);
1030 while ((p->debug.next != NULL) && (p->debug.next != s))
1032 p = p->debug.next;
1034 if (p->debug.next == s)
1036 p->debug.next = s->debug.next;
1038 else
1040 /* not found, quit */
1041 return;
1044 s->debug.next = static_cast<DynamicStrings_String__opaque> (NULL);
1049 AddAllocated - adds string, s, to the head of the allocated list.
1052 static void AddAllocated (DynamicStrings_String__opaque s)
1054 Init ();
1055 AddTo (&frameHead->alloc, s);
1060 AddDeallocated - adds string, s, to the head of the deallocated list.
1063 static void AddDeallocated (DynamicStrings_String__opaque s)
1065 Init ();
1066 AddTo (&frameHead->dealloc, s);
1071 IsOnAllocated - returns TRUE if the string, s, has ever been allocated.
1074 static bool IsOnAllocated (DynamicStrings_String__opaque s)
1076 DynamicStrings_frame f;
1078 Init ();
1079 f = frameHead;
1080 do {
1081 if (IsOn (f->alloc, s))
1083 return true;
1085 else
1087 f = f->next;
1089 } while (! (f == NULL));
1090 return false;
1091 /* static analysis guarentees a RETURN statement will be used before here. */
1092 __builtin_unreachable ();
1097 IsOnDeallocated - returns TRUE if the string, s, has ever been deallocated.
1100 static bool IsOnDeallocated (DynamicStrings_String__opaque s)
1102 DynamicStrings_frame f;
1104 Init ();
1105 f = frameHead;
1106 do {
1107 if (IsOn (f->dealloc, s))
1109 return true;
1111 else
1113 f = f->next;
1115 } while (! (f == NULL));
1116 return false;
1117 /* static analysis guarentees a RETURN statement will be used before here. */
1118 __builtin_unreachable ();
1123 SubAllocated - removes string, s, from the list of allocated strings.
1126 static void SubAllocated (DynamicStrings_String__opaque s)
1128 DynamicStrings_frame f;
1130 Init ();
1131 f = frameHead;
1132 do {
1133 if (IsOn (f->alloc, s))
1135 SubFrom (&f->alloc, s);
1136 return;
1138 else
1140 f = f->next;
1142 } while (! (f == NULL));
1147 SubDeallocated - removes string, s, from the list of deallocated strings.
1150 static void SubDeallocated (DynamicStrings_String__opaque s)
1152 DynamicStrings_frame f;
1154 Init ();
1155 f = frameHead;
1156 do {
1157 if (IsOn (f->dealloc, s))
1159 SubFrom (&f->dealloc, s);
1160 return;
1162 else
1164 f = f->next;
1166 } while (! (f == NULL));
1171 SubDebugInfo - removes string, s, from the list of allocated strings.
1174 static void SubDebugInfo (DynamicStrings_String__opaque s)
1176 if (IsOnDeallocated (s))
1178 Assertion_Assert (! DebugOn);
1179 /* string has already been deallocated */
1180 return;
1182 if (IsOnAllocated (s))
1184 SubAllocated (s);
1185 AddDeallocated (s);
1187 else
1189 /* string has not been allocated */
1190 Assertion_Assert (! DebugOn);
1196 AddDebugInfo - adds string, s, to the list of allocated strings.
1199 static void AddDebugInfo (DynamicStrings_String__opaque s)
1201 s->debug.next = static_cast<DynamicStrings_String__opaque> (NULL);
1202 s->debug.file = NULL;
1203 s->debug.line = 0;
1204 s->debug.proc = NULL;
1205 if (CheckOn)
1207 AddAllocated (s);
1213 ConcatContents - add the contents of string, a, where, h, is the
1214 total length of, a. The offset is in, o.
1217 static void ConcatContents (DynamicStrings_Contents *c, const char *a_, unsigned int _a_high, unsigned int h, unsigned int o)
1219 unsigned int i;
1220 char a[_a_high+1];
1222 /* make a local copy of each unbounded array. */
1223 memcpy (a, a_, _a_high+1);
1225 i = (*c).len;
1226 while ((o < h) && (i < MaxBuf))
1228 (*c).buf.array[i] = a[o];
1229 o += 1;
1230 i += 1;
1232 if (o < h)
1234 (*c).len = MaxBuf;
1235 Storage_ALLOCATE ((void **) &(*c).next, sizeof (DynamicStrings_stringRecord));
1236 (*c).next->head = NULL;
1237 (*c).next->contents.len = 0;
1238 (*c).next->contents.next = static_cast<DynamicStrings_String__opaque> (NULL);
1239 ConcatContents (&(*c).next->contents, (const char *) a, _a_high, h, o);
1240 AddDebugInfo ((*c).next);
1241 (*c).next = AssignDebug ((*c).next, (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 722, (const char *) "ConcatContents", 14);
1243 else
1245 (*c).len = i;
1251 DeallocateCharStar - deallocates any charStar.
1254 static void DeallocateCharStar (DynamicStrings_String__opaque s)
1256 if ((s != NULL) && (s->head != NULL))
1258 if (s->head->charStarUsed && (s->head->charStar != NULL))
1260 Storage_DEALLOCATE (&s->head->charStar, s->head->charStarSize);
1262 s->head->charStarUsed = false;
1263 s->head->charStar = NULL;
1264 s->head->charStarSize = 0;
1265 s->head->charStarValid = false;
1271 CheckPoisoned - checks for a poisoned string, s.
1274 static DynamicStrings_String__opaque CheckPoisoned (DynamicStrings_String__opaque s)
1276 if (((PoisonOn && (s != NULL)) && (s->head != NULL)) && (s->head->state == DynamicStrings_poisoned))
1278 M2RTS_HALT (-1);
1279 __builtin_unreachable ();
1281 return s;
1282 /* static analysis guarentees a RETURN statement will be used before here. */
1283 __builtin_unreachable ();
1288 MarkInvalid - marks the char * version of String, s, as invalid.
1291 static void MarkInvalid (DynamicStrings_String__opaque s)
1293 if (PoisonOn)
1295 s = CheckPoisoned (s);
1297 if (s->head != NULL)
1299 s->head->charStarValid = false;
1305 ConcatContentsAddress - concatenate the string, a, where, h, is the
1306 total length of, a.
1309 static void ConcatContentsAddress (DynamicStrings_Contents *c, void * a, unsigned int h)
1311 typedef char *ConcatContentsAddress__T1;
1313 ConcatContentsAddress__T1 p;
1314 unsigned int i;
1315 unsigned int j;
1317 j = 0;
1318 i = (*c).len;
1319 p = static_cast<ConcatContentsAddress__T1> (a);
1320 while ((j < h) && (i < MaxBuf))
1322 (*c).buf.array[i] = (*p);
1323 i += 1;
1324 j += 1;
1325 p += 1;
1327 if (j < h)
1329 /* avoid dangling else. */
1330 (*c).len = MaxBuf;
1331 Storage_ALLOCATE ((void **) &(*c).next, sizeof (DynamicStrings_stringRecord));
1332 (*c).next->head = NULL;
1333 (*c).next->contents.len = 0;
1334 (*c).next->contents.next = static_cast<DynamicStrings_String__opaque> (NULL);
1335 ConcatContentsAddress (&(*c).next->contents, reinterpret_cast <void *> (p), h-j);
1336 AddDebugInfo ((*c).next);
1337 if (TraceOn)
1339 (*c).next = AssignDebug ((*c).next, (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 917, (const char *) "ConcatContentsAddress", 21);
1342 else
1344 (*c).len = i;
1345 (*c).next = static_cast<DynamicStrings_String__opaque> (NULL);
1351 AddToGarbage - adds String, b, onto the garbage list of, a. Providing
1352 the state of b is marked. The state is then altered to
1353 onlist. String, a, is returned.
1356 static DynamicStrings_String__opaque AddToGarbage (DynamicStrings_String__opaque a, DynamicStrings_String__opaque b)
1358 DynamicStrings_String__opaque c;
1360 if (PoisonOn)
1362 a = CheckPoisoned (a);
1363 b = CheckPoisoned (b);
1366 IF (a#NIL) AND (a#b) AND (a^.head^.state=marked)
1367 THEN
1368 writeString('warning trying to add to a marked string') ; writeLn
1369 END ;
1371 if (((((a != b) && (a != NULL)) && (b != NULL)) && (b->head->state == DynamicStrings_marked)) && (a->head->state == DynamicStrings_inuse))
1373 c = a;
1374 while (c->head->garbage != NULL)
1376 c = c->head->garbage;
1378 c->head->garbage = b;
1379 b->head->state = DynamicStrings_onlist;
1380 if (CheckOn)
1382 SubDebugInfo (b);
1385 return a;
1386 /* static analysis guarentees a RETURN statement will be used before here. */
1387 __builtin_unreachable ();
1392 IsOnGarbage - returns TRUE if, s, is on string, e, garbage list.
1395 static bool IsOnGarbage (DynamicStrings_String__opaque e, DynamicStrings_String__opaque s)
1397 if ((e != NULL) && (s != NULL))
1399 while (e->head->garbage != NULL)
1401 if (e->head->garbage == s)
1403 return true;
1405 else
1407 e = e->head->garbage;
1411 return false;
1412 /* static analysis guarentees a RETURN statement will be used before here. */
1413 __builtin_unreachable ();
1418 IsWhite - returns TRUE if, ch, is a space or a tab.
1421 static bool IsWhite (char ch)
1423 return (ch == ' ') || (ch == ASCII_tab);
1424 /* static analysis guarentees a RETURN statement will be used before here. */
1425 __builtin_unreachable ();
1430 DumpState -
1433 static void DumpState (DynamicStrings_String__opaque s)
1435 switch (s->head->state)
1437 case DynamicStrings_inuse:
1438 writeString ((const char *) "still in use (", 14);
1439 writeCard (s->contents.len);
1440 writeString ((const char *) ") characters", 12);
1441 break;
1443 case DynamicStrings_marked:
1444 writeString ((const char *) "marked", 6);
1445 break;
1447 case DynamicStrings_onlist:
1448 writeString ((const char *) "on a garbage list", 17);
1449 break;
1451 case DynamicStrings_poisoned:
1452 writeString ((const char *) "poisoned", 8);
1453 break;
1456 default:
1457 writeString ((const char *) "unknown state", 13);
1458 break;
1464 DumpStringSynopsis -
1467 static void DumpStringSynopsis (DynamicStrings_String__opaque s)
1469 writeCstring (s->debug.file);
1470 writeString ((const char *) ":", 1);
1471 writeCard (s->debug.line);
1472 writeString ((const char *) ":", 1);
1473 writeCstring (s->debug.proc);
1474 writeString ((const char *) " string ", 8);
1475 writeAddress (reinterpret_cast <void *> (s));
1476 writeString ((const char *) " ", 1);
1477 DumpState (s);
1478 if (IsOnAllocated (s))
1480 writeString ((const char *) " globally allocated", 19);
1482 else if (IsOnDeallocated (s))
1484 /* avoid dangling else. */
1485 writeString ((const char *) " globally deallocated", 21);
1487 else
1489 /* avoid dangling else. */
1490 writeString ((const char *) " globally unknown", 17);
1492 writeLn ();
1497 DumpString - displays the contents of string, s.
1500 static void DumpString (DynamicStrings_String__opaque s)
1502 DynamicStrings_String__opaque t;
1504 if (s != NULL)
1506 DumpStringSynopsis (s);
1507 if ((s->head != NULL) && (s->head->garbage != NULL))
1509 writeString ((const char *) "display chained strings on the garbage list", 43);
1510 writeLn ();
1511 t = s->head->garbage;
1512 while (t != NULL)
1514 DumpStringSynopsis (t);
1515 t = t->head->garbage;
1523 Init - initialize the module.
1526 static void Init (void)
1528 if (! Initialized)
1530 Initialized = true;
1531 frameHead = NULL;
1532 DynamicStrings_PushAllocation ();
1538 InitString - creates and returns a String type object.
1539 Initial contents are, a.
1542 extern "C" DynamicStrings_String DynamicStrings_InitString (const char *a_, unsigned int _a_high)
1544 DynamicStrings_String__opaque s;
1545 char a[_a_high+1];
1547 /* make a local copy of each unbounded array. */
1548 memcpy (a, a_, _a_high+1);
1550 Storage_ALLOCATE ((void **) &s, sizeof (DynamicStrings_stringRecord));
1551 s->contents.len = 0;
1552 s->contents.next = static_cast<DynamicStrings_String__opaque> (NULL);
1553 ConcatContents (&s->contents, (const char *) a, _a_high, StrLib_StrLen ((const char *) a, _a_high), 0);
1554 Storage_ALLOCATE ((void **) &s->head, sizeof (DynamicStrings_descriptor));
1555 s->head->charStarUsed = false;
1556 s->head->charStar = NULL;
1557 s->head->charStarSize = 0;
1558 s->head->charStarValid = false;
1559 s->head->garbage = static_cast<DynamicStrings_String__opaque> (NULL);
1560 s->head->state = DynamicStrings_inuse;
1561 AddDebugInfo (s);
1562 if (TraceOn)
1564 s = AssignDebug (s, (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 758, (const char *) "InitString", 10);
1566 return static_cast<DynamicStrings_String> (s);
1567 /* static analysis guarentees a RETURN statement will be used before here. */
1568 __builtin_unreachable ();
1573 KillString - frees String, s, and its contents.
1574 NIL is returned.
1577 extern "C" DynamicStrings_String DynamicStrings_KillString (DynamicStrings_String s)
1579 DynamicStrings_String__opaque t;
1581 if (PoisonOn)
1583 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
1585 if (s != NULL)
1587 if (CheckOn)
1589 /* avoid gcc warning by using compound statement even if not strictly necessary. */
1590 if (IsOnAllocated (static_cast<DynamicStrings_String__opaque> (s)))
1592 SubAllocated (static_cast<DynamicStrings_String__opaque> (s));
1594 else if (IsOnDeallocated (static_cast<DynamicStrings_String__opaque> (s)))
1596 /* avoid dangling else. */
1597 SubDeallocated (static_cast<DynamicStrings_String__opaque> (s));
1600 if (static_cast<DynamicStrings_String__opaque> (s)->head != NULL)
1602 static_cast<DynamicStrings_String__opaque> (s)->head->state = DynamicStrings_poisoned;
1603 static_cast<DynamicStrings_String__opaque> (s)->head->garbage = static_cast<DynamicStrings_String__opaque> (DynamicStrings_KillString (static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (s)->head->garbage)));
1604 if (! PoisonOn)
1606 DeallocateCharStar (static_cast<DynamicStrings_String__opaque> (s));
1608 if (! PoisonOn)
1610 Storage_DEALLOCATE ((void **) &static_cast<DynamicStrings_String__opaque> (s)->head, sizeof (DynamicStrings_descriptor));
1611 static_cast<DynamicStrings_String__opaque> (s)->head = NULL;
1614 t = static_cast<DynamicStrings_String__opaque> (DynamicStrings_KillString (static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (s)->contents.next)));
1615 if (! PoisonOn)
1617 Storage_DEALLOCATE ((void **) &s, sizeof (DynamicStrings_stringRecord));
1620 return static_cast<DynamicStrings_String> (NULL);
1621 /* static analysis guarentees a RETURN statement will be used before here. */
1622 __builtin_unreachable ();
1627 Fin - finishes with a string, it calls KillString with, s.
1628 The purpose of the procedure is to provide a short cut
1629 to calling KillString and then testing the return result.
1632 extern "C" void DynamicStrings_Fin (DynamicStrings_String s)
1634 if ((DynamicStrings_KillString (s)) != NULL)
1636 M2RTS_HALT (-1);
1637 __builtin_unreachable ();
1643 InitStringCharStar - initializes and returns a String to contain the C string.
1646 extern "C" DynamicStrings_String DynamicStrings_InitStringCharStar (void * a)
1648 DynamicStrings_String__opaque s;
1650 Storage_ALLOCATE ((void **) &s, sizeof (DynamicStrings_stringRecord));
1651 s->contents.len = 0;
1652 s->contents.next = static_cast<DynamicStrings_String__opaque> (NULL);
1653 if (a != NULL)
1655 ConcatContentsAddress (&s->contents, a, static_cast<unsigned int> (libc_strlen (a)));
1657 Storage_ALLOCATE ((void **) &s->head, sizeof (DynamicStrings_descriptor));
1658 s->head->charStarUsed = false;
1659 s->head->charStar = NULL;
1660 s->head->charStarSize = 0;
1661 s->head->charStarValid = false;
1662 s->head->garbage = static_cast<DynamicStrings_String__opaque> (NULL);
1663 s->head->state = DynamicStrings_inuse;
1664 AddDebugInfo (s);
1665 if (TraceOn)
1667 s = AssignDebug (s, (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 957, (const char *) "InitStringCharStar", 18);
1669 return static_cast<DynamicStrings_String> (s);
1670 /* static analysis guarentees a RETURN statement will be used before here. */
1671 __builtin_unreachable ();
1676 InitStringChar - initializes and returns a String to contain the single character, ch.
1679 extern "C" DynamicStrings_String DynamicStrings_InitStringChar (char ch)
1681 typedef struct InitStringChar__T5_a InitStringChar__T5;
1683 struct InitStringChar__T5_a { char array[1+1]; };
1684 InitStringChar__T5 a;
1685 DynamicStrings_String__opaque s;
1687 a.array[0] = ch;
1688 a.array[1] = ASCII_nul;
1689 s = static_cast<DynamicStrings_String__opaque> (DynamicStrings_InitString ((const char *) &a.array[0], 1));
1690 if (TraceOn)
1692 s = AssignDebug (s, (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 977, (const char *) "InitStringChar", 14);
1694 return static_cast<DynamicStrings_String> (s);
1695 /* static analysis guarentees a RETURN statement will be used before here. */
1696 __builtin_unreachable ();
1701 Mark - marks String, s, ready for garbage collection.
1704 extern "C" DynamicStrings_String DynamicStrings_Mark (DynamicStrings_String s)
1706 if (PoisonOn)
1708 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
1710 if ((s != NULL) && (static_cast<DynamicStrings_String__opaque> (s)->head->state == DynamicStrings_inuse))
1712 static_cast<DynamicStrings_String__opaque> (s)->head->state = DynamicStrings_marked;
1714 return s;
1715 /* static analysis guarentees a RETURN statement will be used before here. */
1716 __builtin_unreachable ();
1721 Length - returns the length of the String, s.
1724 extern "C" unsigned int DynamicStrings_Length (DynamicStrings_String s)
1726 if (s == NULL)
1728 return 0;
1730 else
1732 return static_cast<DynamicStrings_String__opaque> (s)->contents.len+(DynamicStrings_Length (static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (s)->contents.next)));
1734 /* static analysis guarentees a RETURN statement will be used before here. */
1735 __builtin_unreachable ();
1740 ConCat - returns String, a, after the contents of, b, have been appended.
1743 extern "C" DynamicStrings_String DynamicStrings_ConCat (DynamicStrings_String a, DynamicStrings_String b)
1745 DynamicStrings_String__opaque t;
1747 if (PoisonOn)
1749 a = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (a)));
1750 b = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (b)));
1752 if (a == b)
1754 return DynamicStrings_ConCat (a, DynamicStrings_Mark (DynamicStrings_Dup (b)));
1756 else if (a != NULL)
1758 /* avoid dangling else. */
1759 a = static_cast<DynamicStrings_String> (AddToGarbage (static_cast<DynamicStrings_String__opaque> (a), static_cast<DynamicStrings_String__opaque> (b)));
1760 MarkInvalid (static_cast<DynamicStrings_String__opaque> (a));
1761 t = static_cast<DynamicStrings_String__opaque> (a);
1762 while (b != NULL)
1764 while ((t->contents.len == MaxBuf) && (t->contents.next != NULL))
1766 t = t->contents.next;
1768 ConcatContents (&t->contents, (const char *) &static_cast<DynamicStrings_String__opaque> (b)->contents.buf.array[0], (MaxBuf-1), static_cast<DynamicStrings_String__opaque> (b)->contents.len, 0);
1769 b = static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (b)->contents.next);
1772 if ((a == NULL) && (b != NULL))
1774 M2RTS_HALT (-1);
1775 __builtin_unreachable ();
1777 return a;
1778 /* static analysis guarentees a RETURN statement will be used before here. */
1779 __builtin_unreachable ();
1784 ConCatChar - returns String, a, after character, ch, has been appended.
1787 extern "C" DynamicStrings_String DynamicStrings_ConCatChar (DynamicStrings_String a, char ch)
1789 typedef struct ConCatChar__T6_a ConCatChar__T6;
1791 struct ConCatChar__T6_a { char array[1+1]; };
1792 ConCatChar__T6 b;
1793 DynamicStrings_String__opaque t;
1795 if (PoisonOn)
1797 a = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (a)));
1799 b.array[0] = ch;
1800 b.array[1] = ASCII_nul;
1801 t = static_cast<DynamicStrings_String__opaque> (a);
1802 MarkInvalid (static_cast<DynamicStrings_String__opaque> (a));
1803 while ((t->contents.len == MaxBuf) && (t->contents.next != NULL))
1805 t = t->contents.next;
1807 ConcatContents (&t->contents, (const char *) &b.array[0], 1, 1, 0);
1808 return a;
1809 /* static analysis guarentees a RETURN statement will be used before here. */
1810 __builtin_unreachable ();
1815 Assign - assigns the contents of, b, into, a.
1816 String, a, is returned.
1819 extern "C" DynamicStrings_String DynamicStrings_Assign (DynamicStrings_String a, DynamicStrings_String b)
1821 if (PoisonOn)
1823 a = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (a)));
1824 b = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (b)));
1826 if ((a != NULL) && (b != NULL))
1828 static_cast<DynamicStrings_String__opaque> (a)->contents.next = static_cast<DynamicStrings_String__opaque> (DynamicStrings_KillString (static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (a)->contents.next)));
1829 static_cast<DynamicStrings_String__opaque> (a)->contents.len = 0;
1831 return DynamicStrings_ConCat (a, b);
1832 /* static analysis guarentees a RETURN statement will be used before here. */
1833 __builtin_unreachable ();
1838 ReplaceChar - returns string s after it has changed all occurances of from to to.
1841 extern "C" DynamicStrings_String DynamicStrings_ReplaceChar (DynamicStrings_String s, char from, char to)
1843 DynamicStrings_String__opaque t;
1844 unsigned int i;
1846 t = static_cast<DynamicStrings_String__opaque> (s);
1847 while (t != NULL)
1849 i = 0;
1850 while (i < t->contents.len)
1852 if (t->contents.buf.array[i] == from)
1854 t->contents.buf.array[i] = to;
1856 i += 1;
1858 t = t->contents.next;
1860 return s;
1861 /* static analysis guarentees a RETURN statement will be used before here. */
1862 __builtin_unreachable ();
1867 Dup - duplicate a String, s, returning the copy of s.
1870 extern "C" DynamicStrings_String DynamicStrings_Dup (DynamicStrings_String s)
1872 if (PoisonOn)
1874 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
1876 s = DynamicStrings_Assign (DynamicStrings_InitString ((const char *) "", 0), s);
1877 if (TraceOn)
1879 s = static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (s), (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 1198, (const char *) "Dup", 3));
1881 return s;
1882 /* static analysis guarentees a RETURN statement will be used before here. */
1883 __builtin_unreachable ();
1888 Add - returns a new String which contains the contents of a and b.
1891 extern "C" DynamicStrings_String DynamicStrings_Add (DynamicStrings_String a, DynamicStrings_String b)
1893 if (PoisonOn)
1895 a = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (a)));
1896 b = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (b)));
1898 a = DynamicStrings_ConCat (DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "", 0), a), b);
1899 if (TraceOn)
1901 a = static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (a), (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 1218, (const char *) "Add", 3));
1903 return a;
1904 /* static analysis guarentees a RETURN statement will be used before here. */
1905 __builtin_unreachable ();
1910 Equal - returns TRUE if String, a, and, b, are equal.
1913 extern "C" bool DynamicStrings_Equal (DynamicStrings_String a, DynamicStrings_String b)
1915 unsigned int i;
1917 if (PoisonOn)
1919 a = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (a)));
1920 b = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (b)));
1922 if ((DynamicStrings_Length (a)) == (DynamicStrings_Length (b)))
1924 while ((a != NULL) && (b != NULL))
1926 i = 0;
1927 Assertion_Assert (static_cast<DynamicStrings_String__opaque> (a)->contents.len == static_cast<DynamicStrings_String__opaque> (b)->contents.len);
1928 while (i < static_cast<DynamicStrings_String__opaque> (a)->contents.len)
1930 if (static_cast<DynamicStrings_String__opaque> (a)->contents.buf.array[i] != static_cast<DynamicStrings_String__opaque> (b)->contents.buf.array[i])
1932 return false;
1934 i += 1;
1936 a = static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (a)->contents.next);
1937 b = static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (b)->contents.next);
1939 return true;
1941 else
1943 return false;
1945 /* static analysis guarentees a RETURN statement will be used before here. */
1946 __builtin_unreachable ();
1951 EqualCharStar - returns TRUE if contents of String, s, is the same as the
1952 string, a.
1955 extern "C" bool DynamicStrings_EqualCharStar (DynamicStrings_String s, void * a)
1957 DynamicStrings_String__opaque t;
1959 if (PoisonOn)
1961 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
1963 t = static_cast<DynamicStrings_String__opaque> (DynamicStrings_InitStringCharStar (a));
1964 if (TraceOn)
1966 t = AssignDebug (t, (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 1275, (const char *) "EqualCharStar", 13);
1968 t = AddToGarbage (t, static_cast<DynamicStrings_String__opaque> (s));
1969 if (DynamicStrings_Equal (static_cast<DynamicStrings_String> (t), s))
1971 t = static_cast<DynamicStrings_String__opaque> (DynamicStrings_KillString (static_cast<DynamicStrings_String> (t)));
1972 return true;
1974 else
1976 t = static_cast<DynamicStrings_String__opaque> (DynamicStrings_KillString (static_cast<DynamicStrings_String> (t)));
1977 return false;
1979 /* static analysis guarentees a RETURN statement will be used before here. */
1980 __builtin_unreachable ();
1985 EqualArray - returns TRUE if contents of String, s, is the same as the
1986 string, a.
1989 extern "C" bool DynamicStrings_EqualArray (DynamicStrings_String s, const char *a_, unsigned int _a_high)
1991 DynamicStrings_String__opaque t;
1992 char a[_a_high+1];
1994 /* make a local copy of each unbounded array. */
1995 memcpy (a, a_, _a_high+1);
1997 if (PoisonOn)
1999 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
2001 t = static_cast<DynamicStrings_String__opaque> (DynamicStrings_InitString ((const char *) a, _a_high));
2002 if (TraceOn)
2004 t = AssignDebug (t, (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 1305, (const char *) "EqualArray", 10);
2006 t = AddToGarbage (t, static_cast<DynamicStrings_String__opaque> (s));
2007 if (DynamicStrings_Equal (static_cast<DynamicStrings_String> (t), s))
2009 t = static_cast<DynamicStrings_String__opaque> (DynamicStrings_KillString (static_cast<DynamicStrings_String> (t)));
2010 return true;
2012 else
2014 t = static_cast<DynamicStrings_String__opaque> (DynamicStrings_KillString (static_cast<DynamicStrings_String> (t)));
2015 return false;
2017 /* static analysis guarentees a RETURN statement will be used before here. */
2018 __builtin_unreachable ();
2023 Mult - returns a new string which is n concatenations of String, s.
2026 extern "C" DynamicStrings_String DynamicStrings_Mult (DynamicStrings_String s, unsigned int n)
2028 if (PoisonOn)
2030 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
2032 if (n <= 0)
2034 s = static_cast<DynamicStrings_String> (AddToGarbage (static_cast<DynamicStrings_String__opaque> (DynamicStrings_InitString ((const char *) "", 0)), static_cast<DynamicStrings_String__opaque> (s)));
2036 else
2038 s = DynamicStrings_ConCat (DynamicStrings_Mult (s, n-1), s);
2040 if (TraceOn)
2042 s = static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (s), (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 1337, (const char *) "Mult", 4));
2044 return s;
2045 /* static analysis guarentees a RETURN statement will be used before here. */
2046 __builtin_unreachable ();
2051 Slice - returns a new string which contains the elements
2052 low..high-1
2054 strings start at element 0
2055 Slice(s, 0, 2) will return elements 0, 1 but not 2
2056 Slice(s, 1, 3) will return elements 1, 2 but not 3
2057 Slice(s, 2, 0) will return elements 2..max
2058 Slice(s, 3, -1) will return elements 3..max-1
2059 Slice(s, 4, -2) will return elements 4..max-2
2062 extern "C" DynamicStrings_String DynamicStrings_Slice (DynamicStrings_String s, int low, int high)
2064 DynamicStrings_String__opaque d;
2065 DynamicStrings_String__opaque t;
2066 int start;
2067 int stop;
2068 int o;
2070 if (PoisonOn)
2072 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
2074 if (low < 0)
2076 low = ((int ) (DynamicStrings_Length (s)))+low;
2078 if (high <= 0)
2080 high = ((int ) (DynamicStrings_Length (s)))+high;
2082 else
2084 /* make sure high is <= Length (s) */
2085 high = Min (DynamicStrings_Length (s), static_cast<unsigned int> (high));
2087 d = static_cast<DynamicStrings_String__opaque> (DynamicStrings_InitString ((const char *) "", 0));
2088 d = AddToGarbage (d, static_cast<DynamicStrings_String__opaque> (s));
2089 o = 0;
2090 t = d;
2091 while (s != NULL)
2093 if (low < (o+((int ) (static_cast<DynamicStrings_String__opaque> (s)->contents.len))))
2095 if (o > high)
2097 s = static_cast<DynamicStrings_String> (NULL);
2099 else
2101 /* found sliceable unit */
2102 if (low < o)
2104 start = 0;
2106 else
2108 start = low-o;
2110 stop = Max (Min (MaxBuf, static_cast<unsigned int> (high-o)), 0);
2111 while (t->contents.len == MaxBuf)
2113 if (t->contents.next == NULL)
2115 Storage_ALLOCATE ((void **) &t->contents.next, sizeof (DynamicStrings_stringRecord));
2116 t->contents.next->head = NULL;
2117 t->contents.next->contents.len = 0;
2118 AddDebugInfo (t->contents.next);
2119 if (TraceOn)
2121 t->contents.next = AssignDebug (t->contents.next, (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 1405, (const char *) "Slice", 5);
2124 t = t->contents.next;
2126 ConcatContentsAddress (&t->contents, &static_cast<DynamicStrings_String__opaque> (s)->contents.buf.array[start], static_cast<unsigned int> (stop-start));
2127 o += static_cast<DynamicStrings_String__opaque> (s)->contents.len;
2128 s = static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (s)->contents.next);
2131 else
2133 o += static_cast<DynamicStrings_String__opaque> (s)->contents.len;
2134 s = static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (s)->contents.next);
2137 if (TraceOn)
2139 d = AssignDebug (d, (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 1422, (const char *) "Slice", 5);
2141 return static_cast<DynamicStrings_String> (d);
2142 /* static analysis guarentees a RETURN statement will be used before here. */
2143 __builtin_unreachable ();
2148 Index - returns the indice of the first occurance of, ch, in
2149 String, s. -1 is returned if, ch, does not exist.
2150 The search starts at position, o.
2153 extern "C" int DynamicStrings_Index (DynamicStrings_String s, char ch, unsigned int o)
2155 unsigned int i;
2156 unsigned int k;
2158 if (PoisonOn)
2160 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
2162 k = 0;
2163 while (s != NULL)
2165 if ((k+static_cast<DynamicStrings_String__opaque> (s)->contents.len) < o)
2167 k += static_cast<DynamicStrings_String__opaque> (s)->contents.len;
2169 else
2171 i = o-k;
2172 while (i < static_cast<DynamicStrings_String__opaque> (s)->contents.len)
2174 if (static_cast<DynamicStrings_String__opaque> (s)->contents.buf.array[i] == ch)
2176 return k+i;
2178 i += 1;
2180 k += i;
2181 o = k;
2183 s = static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (s)->contents.next);
2185 return -1;
2186 /* static analysis guarentees a RETURN statement will be used before here. */
2187 __builtin_unreachable ();
2192 RIndex - returns the indice of the last occurance of, ch,
2193 in String, s. The search starts at position, o.
2194 -1 is returned if, ch, is not found. The search
2195 is performed left to right.
2198 extern "C" int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o)
2200 unsigned int i;
2201 unsigned int k;
2202 int j;
2204 if (PoisonOn)
2206 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
2208 j = -1;
2209 k = 0;
2210 while (s != NULL)
2212 if ((k+static_cast<DynamicStrings_String__opaque> (s)->contents.len) < o)
2214 k += static_cast<DynamicStrings_String__opaque> (s)->contents.len;
2216 else
2218 if (o < k)
2220 i = 0;
2222 else
2224 i = o-k;
2226 while (i < static_cast<DynamicStrings_String__opaque> (s)->contents.len)
2228 if (static_cast<DynamicStrings_String__opaque> (s)->contents.buf.array[i] == ch)
2230 j = k;
2232 k += 1;
2233 i += 1;
2236 s = static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (s)->contents.next);
2238 return j;
2239 /* static analysis guarentees a RETURN statement will be used before here. */
2240 __builtin_unreachable ();
2245 ReverseIndex - returns the indice of the last occurance of ch
2246 in String s. The search starts at position o
2247 and searches from right to left. The start position
2248 may be indexed negatively from the right (-1 is the
2249 last index).
2250 The return value if ch is found will always be positive.
2251 -1 is returned if ch is not found.
2254 extern "C" int DynamicStrings_ReverseIndex (DynamicStrings_String s, char ch, int o)
2256 unsigned int c;
2258 if (PoisonOn)
2260 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
2262 if (o < 0)
2264 o = ((int ) (DynamicStrings_Length (s)))+o;
2265 if (o < 0)
2267 return -1;
2270 if (((unsigned int ) (o)) < (DynamicStrings_Length (s)))
2272 while (o >= 0)
2274 if ((DynamicStrings_char (s, o)) == ch)
2276 return o;
2278 else
2280 o -= 1;
2284 return -1;
2285 /* static analysis guarentees a RETURN statement will be used before here. */
2286 __builtin_unreachable ();
2291 RemoveComment - assuming that, comment, is a comment delimiter
2292 which indicates anything to its right is a comment
2293 then strip off the comment and also any white space
2294 on the remaining right hand side.
2295 It leaves any white space on the left hand side alone.
2298 extern "C" DynamicStrings_String DynamicStrings_RemoveComment (DynamicStrings_String s, char comment)
2300 int i;
2302 i = DynamicStrings_Index (s, comment, 0);
2303 if (i == 0)
2305 s = DynamicStrings_InitString ((const char *) "", 0);
2307 else if (i > 0)
2309 /* avoid dangling else. */
2310 s = DynamicStrings_RemoveWhitePostfix (DynamicStrings_Slice (DynamicStrings_Mark (s), 0, i));
2312 if (TraceOn)
2314 s = static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (s), (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 1576, (const char *) "RemoveComment", 13));
2316 return s;
2317 /* static analysis guarentees a RETURN statement will be used before here. */
2318 __builtin_unreachable ();
2323 RemoveWhitePrefix - removes any leading white space from String, s.
2324 A new string is returned.
2327 extern "C" DynamicStrings_String DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s)
2329 unsigned int i;
2331 i = 0;
2332 while (IsWhite (DynamicStrings_char (s, static_cast<int> (i))))
2334 i += 1;
2336 s = DynamicStrings_Slice (s, (int ) (i), 0);
2337 if (TraceOn)
2339 s = static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (s), (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 1688, (const char *) "RemoveWhitePrefix", 17));
2341 return s;
2342 /* static analysis guarentees a RETURN statement will be used before here. */
2343 __builtin_unreachable ();
2348 RemoveWhitePostfix - removes any leading white space from String, s.
2349 A new string is returned.
2352 extern "C" DynamicStrings_String DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s)
2354 int i;
2356 i = ((int ) (DynamicStrings_Length (s)))-1;
2357 while ((i >= 0) && (IsWhite (DynamicStrings_char (s, i))))
2359 i -= 1;
2361 s = DynamicStrings_Slice (s, 0, i+1);
2362 if (TraceOn)
2364 s = static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (s), (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, 1710, (const char *) "RemoveWhitePostfix", 18));
2366 return s;
2367 /* static analysis guarentees a RETURN statement will be used before here. */
2368 __builtin_unreachable ();
2373 ToUpper - returns string, s, after it has had its lower case characters
2374 replaced by upper case characters.
2375 The string, s, is not duplicated.
2378 extern "C" DynamicStrings_String DynamicStrings_ToUpper (DynamicStrings_String s)
2380 char ch;
2381 unsigned int i;
2382 DynamicStrings_String__opaque t;
2384 if (s != NULL)
2386 MarkInvalid (static_cast<DynamicStrings_String__opaque> (s));
2387 t = static_cast<DynamicStrings_String__opaque> (s);
2388 while (t != NULL)
2390 i = 0;
2391 while (i < t->contents.len)
2393 ch = t->contents.buf.array[i];
2394 if ((ch >= 'a') && (ch <= 'z'))
2396 t->contents.buf.array[i] = ((char) (( ((unsigned int) (ch))- ((unsigned int) ('a')))+ ((unsigned int) ('A'))));
2398 i += 1;
2400 t = t->contents.next;
2403 return s;
2404 /* static analysis guarentees a RETURN statement will be used before here. */
2405 __builtin_unreachable ();
2410 ToLower - returns string, s, after it has had its upper case characters
2411 replaced by lower case characters.
2412 The string, s, is not duplicated.
2415 extern "C" DynamicStrings_String DynamicStrings_ToLower (DynamicStrings_String s)
2417 char ch;
2418 unsigned int i;
2419 DynamicStrings_String__opaque t;
2421 if (s != NULL)
2423 MarkInvalid (static_cast<DynamicStrings_String__opaque> (s));
2424 t = static_cast<DynamicStrings_String__opaque> (s);
2425 while (t != NULL)
2427 i = 0;
2428 while (i < t->contents.len)
2430 ch = t->contents.buf.array[i];
2431 if ((ch >= 'A') && (ch <= 'Z'))
2433 t->contents.buf.array[i] = ((char) (( ((unsigned int) (ch))- ((unsigned int) ('A')))+ ((unsigned int) ('a'))));
2435 i += 1;
2437 t = t->contents.next;
2440 return s;
2441 /* static analysis guarentees a RETURN statement will be used before here. */
2442 __builtin_unreachable ();
2447 CopyOut - copies string, s, to a.
2450 extern "C" void DynamicStrings_CopyOut (char *a, unsigned int _a_high, DynamicStrings_String s)
2452 unsigned int i;
2453 unsigned int l;
2455 l = Min (_a_high+1, DynamicStrings_Length (s));
2456 i = 0;
2457 while (i < l)
2459 const_cast<char *>(a)[i] = DynamicStrings_char (s, static_cast<int> (i));
2460 i += 1;
2462 if (i <= _a_high)
2464 const_cast<char *>(a)[i] = ASCII_nul;
2470 char - returns the character, ch, at position, i, in String, s.
2473 extern "C" char DynamicStrings_char (DynamicStrings_String s, int i)
2475 unsigned int c;
2477 if (PoisonOn)
2479 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
2481 if (i < 0)
2483 c = (unsigned int ) (((int ) (DynamicStrings_Length (s)))+i);
2485 else
2487 c = i;
2489 while ((s != NULL) && (c >= static_cast<DynamicStrings_String__opaque> (s)->contents.len))
2491 c -= static_cast<DynamicStrings_String__opaque> (s)->contents.len;
2492 s = static_cast<DynamicStrings_String> (static_cast<DynamicStrings_String__opaque> (s)->contents.next);
2494 if ((s == NULL) || (c >= static_cast<DynamicStrings_String__opaque> (s)->contents.len))
2496 return ASCII_nul;
2498 else
2500 return static_cast<DynamicStrings_String__opaque> (s)->contents.buf.array[c];
2502 /* static analysis guarentees a RETURN statement will be used before here. */
2503 __builtin_unreachable ();
2508 string - returns the C style char * of String, s.
2511 extern "C" void * DynamicStrings_string (DynamicStrings_String s)
2513 typedef char *string__T2;
2515 DynamicStrings_String__opaque a;
2516 unsigned int l;
2517 unsigned int i;
2518 string__T2 p;
2520 if (PoisonOn)
2522 s = static_cast<DynamicStrings_String> (CheckPoisoned (static_cast<DynamicStrings_String__opaque> (s)));
2524 if (s == NULL)
2526 return NULL;
2528 else
2530 if (! static_cast<DynamicStrings_String__opaque> (s)->head->charStarValid)
2532 l = DynamicStrings_Length (s);
2533 if (! (static_cast<DynamicStrings_String__opaque> (s)->head->charStarUsed && (static_cast<DynamicStrings_String__opaque> (s)->head->charStarSize > l)))
2535 DeallocateCharStar (static_cast<DynamicStrings_String__opaque> (s));
2536 Storage_ALLOCATE (&static_cast<DynamicStrings_String__opaque> (s)->head->charStar, l+1);
2537 static_cast<DynamicStrings_String__opaque> (s)->head->charStarSize = l+1;
2538 static_cast<DynamicStrings_String__opaque> (s)->head->charStarUsed = true;
2540 p = static_cast<string__T2> (static_cast<DynamicStrings_String__opaque> (s)->head->charStar);
2541 a = static_cast<DynamicStrings_String__opaque> (s);
2542 while (a != NULL)
2544 i = 0;
2545 while (i < a->contents.len)
2547 (*p) = a->contents.buf.array[i];
2548 i += 1;
2549 p += 1;
2551 a = a->contents.next;
2553 (*p) = ASCII_nul;
2554 static_cast<DynamicStrings_String__opaque> (s)->head->charStarValid = true;
2556 return static_cast<DynamicStrings_String__opaque> (s)->head->charStar;
2558 /* static analysis guarentees a RETURN statement will be used before here. */
2559 __builtin_unreachable ();
2564 InitStringDB - the debug version of InitString.
2567 extern "C" DynamicStrings_String DynamicStrings_InitStringDB (const char *a_, unsigned int _a_high, const char *file_, unsigned int _file_high, unsigned int line)
2569 char a[_a_high+1];
2570 char file[_file_high+1];
2572 /* make a local copy of each unbounded array. */
2573 memcpy (a, a_, _a_high+1);
2574 memcpy (file, file_, _file_high+1);
2576 return static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (DynamicStrings_InitString ((const char *) a, _a_high)), (const char *) file, _file_high, line, (const char *) "InitString", 10));
2577 /* static analysis guarentees a RETURN statement will be used before here. */
2578 __builtin_unreachable ();
2583 InitStringCharStarDB - the debug version of InitStringCharStar.
2586 extern "C" DynamicStrings_String DynamicStrings_InitStringCharStarDB (void * a, const char *file_, unsigned int _file_high, unsigned int line)
2588 char file[_file_high+1];
2590 /* make a local copy of each unbounded array. */
2591 memcpy (file, file_, _file_high+1);
2593 return static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (DynamicStrings_InitStringCharStar (a)), (const char *) file, _file_high, line, (const char *) "InitStringCharStar", 18));
2594 /* static analysis guarentees a RETURN statement will be used before here. */
2595 __builtin_unreachable ();
2600 InitStringCharDB - the debug version of InitStringChar.
2603 extern "C" DynamicStrings_String DynamicStrings_InitStringCharDB (char ch, const char *file_, unsigned int _file_high, unsigned int line)
2605 char file[_file_high+1];
2607 /* make a local copy of each unbounded array. */
2608 memcpy (file, file_, _file_high+1);
2610 return static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (DynamicStrings_InitStringChar (ch)), (const char *) file, _file_high, line, (const char *) "InitStringChar", 14));
2611 /* static analysis guarentees a RETURN statement will be used before here. */
2612 __builtin_unreachable ();
2617 MultDB - the debug version of MultDB.
2620 extern "C" DynamicStrings_String DynamicStrings_MultDB (DynamicStrings_String s, unsigned int n, const char *file_, unsigned int _file_high, unsigned int line)
2622 char file[_file_high+1];
2624 /* make a local copy of each unbounded array. */
2625 memcpy (file, file_, _file_high+1);
2627 return static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (DynamicStrings_Mult (s, n)), (const char *) file, _file_high, line, (const char *) "Mult", 4));
2628 /* static analysis guarentees a RETURN statement will be used before here. */
2629 __builtin_unreachable ();
2634 DupDB - the debug version of Dup.
2637 extern "C" DynamicStrings_String DynamicStrings_DupDB (DynamicStrings_String s, const char *file_, unsigned int _file_high, unsigned int line)
2639 char file[_file_high+1];
2641 /* make a local copy of each unbounded array. */
2642 memcpy (file, file_, _file_high+1);
2644 return static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (DynamicStrings_Dup (s)), (const char *) file, _file_high, line, (const char *) "Dup", 3));
2645 /* static analysis guarentees a RETURN statement will be used before here. */
2646 __builtin_unreachable ();
2651 SliceDB - debug version of Slice.
2654 extern "C" DynamicStrings_String DynamicStrings_SliceDB (DynamicStrings_String s, int low, int high, const char *file_, unsigned int _file_high, unsigned int line)
2656 char file[_file_high+1];
2658 /* make a local copy of each unbounded array. */
2659 memcpy (file, file_, _file_high+1);
2661 DSdbEnter ();
2662 s = static_cast<DynamicStrings_String> (AssignDebug (static_cast<DynamicStrings_String__opaque> (DynamicStrings_Slice (s, low, high)), (const char *) file, _file_high, line, (const char *) "Slice", 5));
2663 DSdbExit (static_cast<DynamicStrings_String__opaque> (s));
2664 return s;
2665 /* static analysis guarentees a RETURN statement will be used before here. */
2666 __builtin_unreachable ();
2671 PushAllocation - pushes the current allocation/deallocation lists.
2674 extern "C" void DynamicStrings_PushAllocation (void)
2676 DynamicStrings_frame f;
2678 if (CheckOn)
2680 Init ();
2681 Storage_ALLOCATE ((void **) &f, sizeof (DynamicStrings_frameRec));
2682 f->next = frameHead;
2683 f->alloc = static_cast<DynamicStrings_String__opaque> (NULL);
2684 f->dealloc = static_cast<DynamicStrings_String__opaque> (NULL);
2685 frameHead = f;
2691 PopAllocation - test to see that all strings are deallocated since
2692 the last push. Then it pops to the previous
2693 allocation/deallocation lists.
2695 If halt is true then the application terminates
2696 with an exit code of 1.
2699 extern "C" void DynamicStrings_PopAllocation (bool halt)
2701 if (CheckOn)
2703 if ((DynamicStrings_PopAllocationExemption (halt, static_cast<DynamicStrings_String> (NULL))) == NULL)
2704 {} /* empty. */
2710 PopAllocationExemption - test to see that all strings are deallocated, except
2711 string e since the last push.
2712 Post-condition: it pops to the previous allocation/deallocation
2713 lists.
2715 If halt is true then the application terminates
2716 with an exit code of 1.
2719 extern "C" DynamicStrings_String DynamicStrings_PopAllocationExemption (bool halt, DynamicStrings_String e)
2721 DynamicStrings_String__opaque s;
2722 bool b;
2724 Init ();
2725 if (CheckOn)
2727 /* avoid gcc warning by using compound statement even if not strictly necessary. */
2728 if (frameHead == NULL)
2730 stop ();
2731 M2RTS_Halt ((const char *) "mismatched number of PopAllocation's compared to PushAllocation's", 65, (const char *) "../../gcc/m2/gm2-libs/DynamicStrings.mod", 40, (const char *) "PopAllocationExemption", 22, 174);
2733 else
2735 /* writeString ("mismatched number of PopAllocation's compared to PushAllocation's") */
2736 if (frameHead->alloc != NULL)
2738 b = false;
2739 s = frameHead->alloc;
2740 while (s != NULL)
2742 if (! (((e == s) || (IsOnGarbage (static_cast<DynamicStrings_String__opaque> (e), s))) || (IsOnGarbage (s, static_cast<DynamicStrings_String__opaque> (e)))))
2744 if (! b)
2746 writeString ((const char *) "the following strings have been lost", 36);
2747 writeLn ();
2748 b = true;
2750 DumpStringInfo (s, 0);
2752 s = s->debug.next;
2754 if (b && halt)
2756 libc_exit (1);
2759 frameHead = frameHead->next;
2762 return e;
2763 /* static analysis guarentees a RETURN statement will be used before here. */
2764 __builtin_unreachable ();
2767 extern "C" void _M2_DynamicStrings_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
2769 Initialized = false;
2770 Init ();
2773 extern "C" void _M2_DynamicStrings_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])