| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 switch (c) { | 86 switch (c) { |
| 87 case '0': case '1': case '2': case '3': case '4': case '5': | 87 case '0': case '1': case '2': case '3': case '4': case '5': |
| 88 case '6': case '7': case '8': case '9': case '.': case '-': | 88 case '6': case '7': case '8': case '9': case '.': case '-': |
| 89 return true; | 89 return true; |
| 90 default: | 90 default: |
| 91 return false; | 91 return false; |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 | 95 |
| 96 void StringStream::Add(const char* format, Vector<FmtElm> elms) { | 96 void StringStream::Add(Vector<const char> format, Vector<FmtElm> elms) { |
| 97 // If we already ran out of space then return immediately. | 97 // If we already ran out of space then return immediately. |
| 98 if (space() == 0) | 98 if (space() == 0) |
| 99 return; | 99 return; |
| 100 int offset = 0; | 100 int offset = 0; |
| 101 int elm = 0; | 101 int elm = 0; |
| 102 while (format[offset] != '\0') { | 102 while (offset < format.length()) { |
| 103 if (format[offset] != '%' || elm == elms.length()) { | 103 if (format[offset] != '%' || elm == elms.length()) { |
| 104 Put(format[offset]); | 104 Put(format[offset]); |
| 105 offset++; | 105 offset++; |
| 106 continue; | 106 continue; |
| 107 } | 107 } |
| 108 // Read this formatting directive into a temporary buffer | 108 // Read this formatting directive into a temporary buffer |
| 109 EmbeddedVector<char, 24> temp; | 109 EmbeddedVector<char, 24> temp; |
| 110 int format_length = 0; | 110 int format_length = 0; |
| 111 // Skip over the whole control character sequence until the | 111 // Skip over the whole control character sequence until the |
| 112 // format element type | 112 // format element type |
| 113 temp[format_length++] = format[offset++]; | 113 temp[format_length++] = format[offset++]; |
| 114 // '\0' is not a control character so we don't have to | 114 while (offset < format.length() && IsControlChar(format[offset])) |
| 115 // explicitly check for the end of the string | |
| 116 while (IsControlChar(format[offset])) | |
| 117 temp[format_length++] = format[offset++]; | 115 temp[format_length++] = format[offset++]; |
| 116 if (offset >= format.length()) |
| 117 return; |
| 118 char type = format[offset]; | 118 char type = format[offset]; |
| 119 if (type == '\0') return; | |
| 120 temp[format_length++] = type; | 119 temp[format_length++] = type; |
| 121 temp[format_length] = '\0'; | 120 temp[format_length] = '\0'; |
| 122 offset++; | 121 offset++; |
| 123 FmtElm current = elms[elm++]; | 122 FmtElm current = elms[elm++]; |
| 124 switch (type) { | 123 switch (type) { |
| 125 case 's': { | 124 case 's': { |
| 126 ASSERT_EQ(FmtElm::C_STR, current.type_); | 125 ASSERT_EQ(FmtElm::C_STR, current.type_); |
| 127 const char* value = current.data_.u_c_str_; | 126 const char* value = current.data_.u_c_str_; |
| 128 Add(value); | 127 Add(value); |
| 129 break; | 128 break; |
| 130 } | 129 } |
| 130 case 'w': { |
| 131 ASSERT_EQ(FmtElm::LC_STR, current.type_); |
| 132 Vector<const uc16> value = *current.data_.u_lc_str_; |
| 133 for (int i = 0; i < value.length(); i++) |
| 134 Put(value[i]); |
| 135 break; |
| 136 } |
| 131 case 'o': { | 137 case 'o': { |
| 132 ASSERT_EQ(FmtElm::OBJ, current.type_); | 138 ASSERT_EQ(FmtElm::OBJ, current.type_); |
| 133 Object* obj = current.data_.u_obj_; | 139 Object* obj = current.data_.u_obj_; |
| 134 PrintObject(obj); | 140 PrintObject(obj); |
| 135 break; | 141 break; |
| 136 } | 142 } |
| 137 case 'i': case 'd': case 'u': case 'x': case 'c': case 'p': { | 143 case 'i': case 'd': case 'u': case 'x': case 'c': case 'p': { |
| 138 int value = current.data_.u_int_; | 144 int value = current.data_.u_int_; |
| 139 EmbeddedVector<char, 24> formatted; | 145 EmbeddedVector<char, 24> formatted; |
| 140 OS::SNPrintF(formatted, temp.start(), value); | 146 int length = OS::SNPrintF(formatted, temp.start(), value); |
| 141 Add(formatted.start()); | 147 Add(Vector<const char>(formatted.start(), length)); |
| 142 break; | 148 break; |
| 143 } | 149 } |
| 144 default: | 150 default: |
| 145 UNREACHABLE(); | 151 UNREACHABLE(); |
| 146 break; | 152 break; |
| 147 } | 153 } |
| 148 } | 154 } |
| 149 | 155 |
| 150 // Verify that the buffer is 0-terminated and doesn't contain any | 156 // Verify that the buffer is 0-terminated |
| 151 // other 0-characters. | |
| 152 ASSERT(buffer_[length_] == '\0'); | 157 ASSERT(buffer_[length_] == '\0'); |
| 153 ASSERT(strlen(buffer_) == length_); | |
| 154 } | 158 } |
| 155 | 159 |
| 156 | 160 |
| 157 void StringStream::PrintObject(Object* o) { | 161 void StringStream::PrintObject(Object* o) { |
| 158 o->ShortPrint(this); | 162 o->ShortPrint(this); |
| 159 if (o->IsString()) { | 163 if (o->IsString()) { |
| 160 if (String::cast(o)->length() <= String::kMaxMediumStringSize) { | 164 if (String::cast(o)->length() <= String::kMaxMediumStringSize) { |
| 161 return; | 165 return; |
| 162 } | 166 } |
| 163 } else if (o->IsNumber() || o->IsOddball()) { | 167 } else if (o->IsNumber() || o->IsOddball()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 174 Add("#%d#", debug_object_cache->length()); | 178 Add("#%d#", debug_object_cache->length()); |
| 175 debug_object_cache->Add(HeapObject::cast(o)); | 179 debug_object_cache->Add(HeapObject::cast(o)); |
| 176 } else { | 180 } else { |
| 177 Add("@%p", o); | 181 Add("@%p", o); |
| 178 } | 182 } |
| 179 } | 183 } |
| 180 } | 184 } |
| 181 | 185 |
| 182 | 186 |
| 183 void StringStream::Add(const char* format) { | 187 void StringStream::Add(const char* format) { |
| 188 Add(CStrVector(format)); |
| 189 } |
| 190 |
| 191 |
| 192 void StringStream::Add(Vector<const char> format) { |
| 184 Add(format, Vector<FmtElm>::empty()); | 193 Add(format, Vector<FmtElm>::empty()); |
| 185 } | 194 } |
| 186 | 195 |
| 187 | 196 |
| 188 void StringStream::Add(const char* format, FmtElm arg0) { | 197 void StringStream::Add(const char* format, FmtElm arg0) { |
| 189 const char argc = 1; | 198 const char argc = 1; |
| 190 FmtElm argv[argc] = { arg0 }; | 199 FmtElm argv[argc] = { arg0 }; |
| 191 Add(format, Vector<FmtElm>(argv, argc)); | 200 Add(CStrVector(format), Vector<FmtElm>(argv, argc)); |
| 192 } | 201 } |
| 193 | 202 |
| 194 | 203 |
| 195 void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1) { | 204 void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1) { |
| 196 const char argc = 2; | 205 const char argc = 2; |
| 197 FmtElm argv[argc] = { arg0, arg1 }; | 206 FmtElm argv[argc] = { arg0, arg1 }; |
| 198 Add(format, Vector<FmtElm>(argv, argc)); | 207 Add(CStrVector(format), Vector<FmtElm>(argv, argc)); |
| 199 } | 208 } |
| 200 | 209 |
| 201 | 210 |
| 202 void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1, | 211 void StringStream::Add(const char* format, FmtElm arg0, FmtElm arg1, |
| 203 FmtElm arg2) { | 212 FmtElm arg2) { |
| 204 const char argc = 3; | 213 const char argc = 3; |
| 205 FmtElm argv[argc] = { arg0, arg1, arg2 }; | 214 FmtElm argv[argc] = { arg0, arg1, arg2 }; |
| 206 Add(format, Vector<FmtElm>(argv, argc)); | 215 Add(CStrVector(format), Vector<FmtElm>(argv, argc)); |
| 207 } | 216 } |
| 208 | 217 |
| 209 | 218 |
| 210 SmartPointer<char> StringStream::ToCString() { | 219 SmartPointer<char> StringStream::ToCString() { |
| 211 char* str = NewArray<char>(length_ + 1); | 220 char* str = NewArray<char>(length_ + 1); |
| 212 memcpy(str, buffer_, length_); | 221 memcpy(str, buffer_, length_); |
| 213 str[length_] = '\0'; | 222 str[length_] = '\0'; |
| 214 return SmartPointer<char>(str); | 223 return SmartPointer<char>(str); |
| 215 } | 224 } |
| 216 | 225 |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 unsigned new_bytes = *bytes * 2; | 541 unsigned new_bytes = *bytes * 2; |
| 533 if (new_bytes > size_) { | 542 if (new_bytes > size_) { |
| 534 new_bytes = size_; | 543 new_bytes = size_; |
| 535 } | 544 } |
| 536 *bytes = new_bytes; | 545 *bytes = new_bytes; |
| 537 return space_; | 546 return space_; |
| 538 } | 547 } |
| 539 | 548 |
| 540 | 549 |
| 541 } } // namespace v8::internal | 550 } } // namespace v8::internal |
| OLD | NEW |