47 /* Removed for MCC BUG
48 Set::operator const ListSet*() const { assert(0); return NULL; } */
49 const ListSet *Set::asListSet() const { assert(0); return NULL; }
50 class CoSet;
51 /* Removed for MCC BUG
52 Set::operator const CoSet*() const { assert(0); return NULL; } */
53 const CoSet *Set::asCoSet() const { assert(0); return NULL; }
54
55 //------------------------------setstr-----------------------------------------
56 // Create a string with a printable representation of a set.
57 // The caller must deallocate the string.
58 char *Set::setstr() const
59 {
60 if( this == NULL ) return os::strdup("{no set}");
61 Set &set = clone(); // Virtually copy the basic set.
62 set.Sort(); // Sort elements for in-order retrieval
63
64 uint len = 128; // Total string space
65 char *buf = NEW_C_HEAP_ARRAY(char,len, mtCompiler);// Some initial string space
66
67 register char *s = buf; // Current working string pointer
68 *s++ = '{';
69 *s = '\0';
70
71 // For all elements of the Set
72 uint hi = (uint)-2, lo = (uint)-2;
73 for( SetI i(&set); i.test(); ++i ) {
74 if( hi+1 == i.elem ) { // Moving sequentially thru range?
75 hi = i.elem; // Yes, just update hi end of range
76 } else { // Else range ended
77 if( buf+len-s < 25 ) { // Generous trailing space for upcoming numbers
78 int offset = (int)(s-buf);// Not enuf space; compute offset into buffer
79 len <<= 1; // Double string size
80 buf = REALLOC_C_HEAP_ARRAY(char,buf,len, mtCompiler); // Reallocate doubled size
81 s = buf+offset; // Get working pointer into new bigger buffer
82 }
83 if( lo != (uint)-2 ) { // Startup? No! Then print previous range.
84 if( lo != hi ) sprintf(s,"%d-%d,",lo,hi);
85 else sprintf(s,"%d,",lo);
86 s += strlen(s); // Advance working string
87 }
99 else sprintf(s,"%d}",lo);
100 } else strcat(s,"}");
101 // Don't delete the clone 'set' since it is allocated on Arena.
102 return buf;
103 }
104
105 //------------------------------print------------------------------------------
106 // Handier print routine
107 void Set::print() const
108 {
109 char *printable_set = setstr();
110 tty->print_cr("%s", printable_set);
111 FreeHeap(printable_set);
112 }
113
114 //------------------------------parse------------------------------------------
115 // Convert a textual representation of a Set, to a Set and union into "this"
116 // Set. Return the amount of text parsed in "len", or zero in "len".
117 int Set::parse(const char *s)
118 {
119 register char c; // Parse character
120 register const char *t = s; // Save the starting position of s.
121 do c = *s++; // Skip characters
122 while( c && (c <= ' ') ); // Till no more whitespace or EOS
123 if( c != '{' ) return 0; // Oops, not a Set openner
124 if( *s == '}' ) return 2; // The empty Set
125
126 // Sets are filled with values of the form "xx," or "xx-yy," with the comma
127 // a "}" at the very end.
128 while( 1 ) { // While have elements in the Set
129 char *u; // Pointer to character ending parse
130 uint hi, i; // Needed for range handling below
131 uint elem = (uint)strtoul(s,&u,10);// Get element
132 if( u == s ) return 0; // Bogus crude
133 s = u; // Skip over the number
134 c = *s++; // Get the number seperator
135 switch ( c ) { // Different seperators
136 case '}': // Last simple element
137 case ',': // Simple element
138 (*this) <<= elem; // Insert the simple element into the Set
139 break; // Go get next element
140 case '-': // Range
|
47 /* Removed for MCC BUG
48 Set::operator const ListSet*() const { assert(0); return NULL; } */
49 const ListSet *Set::asListSet() const { assert(0); return NULL; }
50 class CoSet;
51 /* Removed for MCC BUG
52 Set::operator const CoSet*() const { assert(0); return NULL; } */
53 const CoSet *Set::asCoSet() const { assert(0); return NULL; }
54
55 //------------------------------setstr-----------------------------------------
56 // Create a string with a printable representation of a set.
57 // The caller must deallocate the string.
58 char *Set::setstr() const
59 {
60 if( this == NULL ) return os::strdup("{no set}");
61 Set &set = clone(); // Virtually copy the basic set.
62 set.Sort(); // Sort elements for in-order retrieval
63
64 uint len = 128; // Total string space
65 char *buf = NEW_C_HEAP_ARRAY(char,len, mtCompiler);// Some initial string space
66
67 char *s = buf; // Current working string pointer
68 *s++ = '{';
69 *s = '\0';
70
71 // For all elements of the Set
72 uint hi = (uint)-2, lo = (uint)-2;
73 for( SetI i(&set); i.test(); ++i ) {
74 if( hi+1 == i.elem ) { // Moving sequentially thru range?
75 hi = i.elem; // Yes, just update hi end of range
76 } else { // Else range ended
77 if( buf+len-s < 25 ) { // Generous trailing space for upcoming numbers
78 int offset = (int)(s-buf);// Not enuf space; compute offset into buffer
79 len <<= 1; // Double string size
80 buf = REALLOC_C_HEAP_ARRAY(char,buf,len, mtCompiler); // Reallocate doubled size
81 s = buf+offset; // Get working pointer into new bigger buffer
82 }
83 if( lo != (uint)-2 ) { // Startup? No! Then print previous range.
84 if( lo != hi ) sprintf(s,"%d-%d,",lo,hi);
85 else sprintf(s,"%d,",lo);
86 s += strlen(s); // Advance working string
87 }
99 else sprintf(s,"%d}",lo);
100 } else strcat(s,"}");
101 // Don't delete the clone 'set' since it is allocated on Arena.
102 return buf;
103 }
104
105 //------------------------------print------------------------------------------
106 // Handier print routine
107 void Set::print() const
108 {
109 char *printable_set = setstr();
110 tty->print_cr("%s", printable_set);
111 FreeHeap(printable_set);
112 }
113
114 //------------------------------parse------------------------------------------
115 // Convert a textual representation of a Set, to a Set and union into "this"
116 // Set. Return the amount of text parsed in "len", or zero in "len".
117 int Set::parse(const char *s)
118 {
119 char c; // Parse character
120 const char *t = s; // Save the starting position of s.
121 do c = *s++; // Skip characters
122 while( c && (c <= ' ') ); // Till no more whitespace or EOS
123 if( c != '{' ) return 0; // Oops, not a Set openner
124 if( *s == '}' ) return 2; // The empty Set
125
126 // Sets are filled with values of the form "xx," or "xx-yy," with the comma
127 // a "}" at the very end.
128 while( 1 ) { // While have elements in the Set
129 char *u; // Pointer to character ending parse
130 uint hi, i; // Needed for range handling below
131 uint elem = (uint)strtoul(s,&u,10);// Get element
132 if( u == s ) return 0; // Bogus crude
133 s = u; // Skip over the number
134 c = *s++; // Get the number seperator
135 switch ( c ) { // Different seperators
136 case '}': // Last simple element
137 case ',': // Simple element
138 (*this) <<= elem; // Insert the simple element into the Set
139 break; // Go get next element
140 case '-': // Range
|