説明を見る。00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_STRING_STREAM_H_
00029 #define V8_STRING_STREAM_H_
00030
00031 namespace v8 { namespace internal {
00032
00033
00034 class StringAllocator {
00035 public:
00036 virtual ~StringAllocator() {}
00037
00038 virtual char* allocate(unsigned bytes) = 0;
00039
00040
00041
00042
00043 virtual char* grow(unsigned* bytes) = 0;
00044 };
00045
00046
00047
00048 class HeapStringAllocator: public StringAllocator {
00049 public:
00050 ~HeapStringAllocator() { DeleteArray(space_); }
00051 char* allocate(unsigned bytes);
00052 char* grow(unsigned* bytes);
00053 private:
00054 char* space_;
00055 };
00056
00057
00058
00059
00060
00061 class NoAllocationStringAllocator: public StringAllocator {
00062 public:
00063 explicit NoAllocationStringAllocator(unsigned bytes);
00064 NoAllocationStringAllocator(char* memory, unsigned size);
00065 char* allocate(unsigned bytes) { return space_; }
00066 char* grow(unsigned* bytes);
00067 private:
00068 unsigned size_;
00069 char* space_;
00070 };
00071
00072
00073 class FmtElm {
00074 public:
00075 FmtElm(int value) : type_(INT) { data_.u_int_ = value; }
00076 FmtElm(const char* value) : type_(C_STR) { data_.u_c_str_ = value; }
00077 FmtElm(Object* value) : type_(OBJ) { data_.u_obj_ = value; }
00078 FmtElm(Handle<Object> value) : type_(HANDLE) { data_.u_handle_ = value.location(); }
00079 FmtElm(void* value) : type_(INT) { data_.u_int_ = reinterpret_cast<int>(value); }
00080 private:
00081 friend class StringStream;
00082 enum Type { INT, C_STR, OBJ, HANDLE };
00083 Type type_;
00084 union {
00085 int u_int_;
00086 const char* u_c_str_;
00087 Object* u_obj_;
00088 Object** u_handle_;
00089 } data_;
00090 };
00091
00092
00093 class StringStream {
00094 public:
00095 explicit StringStream(StringAllocator* allocator):
00096 allocator_(allocator),
00097 capacity_(kInitialCapacity),
00098 length_(0),
00099 buffer_(allocator_->allocate(kInitialCapacity)) {
00100 buffer_[0] = 0;
00101 }
00102
00103 ~StringStream() {
00104 }
00105
00106 bool Put(char c);
00107 bool Put(String* str);
00108 bool Put(String* str, int start, int end);
00109 void Add(const char* format, Vector<FmtElm> elms);
00110 void Add(const char* format);
00111 void Add(const char* format, FmtElm arg0);
00112 void Add(const char* format, FmtElm arg0, FmtElm arg1);
00113 void Add(const char* format, FmtElm arg0, FmtElm arg1, FmtElm arg2);
00114
00115
00116 void OutputToStdOut();
00117 void Log();
00118 Handle<String> ToString();
00119 SmartPointer<char> ToCString();
00120
00121
00122 void PrintName(Object* o);
00123 void PrintFixedArray(FixedArray* array, unsigned int limit);
00124 void PrintByteArray(ByteArray* ba);
00125 void PrintUsingMap(JSObject* js_object);
00126 void PrintPrototype(JSFunction* fun, Object* receiver);
00127 void PrintSecurityTokenIfChanged(Object* function);
00128
00129 void PrintFunction(Object* function, Object* receiver, Code** code);
00130
00131
00132 void Reset() {
00133 length_ = 0;
00134 buffer_[0] = 0;
00135 }
00136
00137
00138 void PrintMentionedObjectCache();
00139 static void ClearMentionedObjectCache();
00140 #ifdef DEBUG
00141 static bool IsMentionedObjectCacheClear();
00142 #endif
00143
00144
00145 static const int kInitialCapacity = 16;
00146
00147 private:
00148 void PrintObject(Object* obj);
00149
00150 StringAllocator* allocator_;
00151 unsigned capacity_;
00152 unsigned length_;
00153 char* buffer_;
00154
00155 int space() const { return capacity_ - length_; }
00156 char* cursor() const { return buffer_ + length_; }
00157
00158 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream);
00159 };
00160
00161
00162 } }
00163
00164 #endif // V8_STRING_STREAM_H_