Changeset 21406 in webkit
- Timestamp:
- May 11, 2007 9:15:45 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r21399 r21406 1 2007-05-11 Kimmo Kinnunen <kimmok@iki.fi> 2 3 Reviewed by Darin. 4 5 - Fixes http://bugs.webkit.org/show_bug.cgi?id=10878 6 (Incorrect decompilation for "4..x") 7 - Group numbers in dotted expressions in toString() output, so we 8 avoid the 4.x constructs when the original input is 4..x. 9 4..x means the same as 4. .x or (4).x or Number(4).x 10 11 * kjs/nodes2string.cpp: 12 (KJS::SourceStream::): 13 Add boolean flag to indicate that if next item is a number, it should be grouped. 14 Add new formatting enum which turns on the boolean flag. 15 (KJS::SourceStream::SourceStream): Added. Initialize the flag. 16 (SourceStream::operator<<): Added. New overloaded operator with double value as parameter. 17 (NumberNode::streamTo): Use the double operator 18 (ArrayNode::streamTo): 19 (DotAccessorNode::streamTo): 20 (FunctionCallDotNode::streamTo): 21 (FunctionCallParenDotNode::streamTo): 22 (PostfixDotNode::streamTo): 23 (DeleteDotNode::streamTo): 24 (PrefixDotNode::streamTo): 25 (AssignDotNode::streamTo): Use the new formatting enum to turn on the grouping flag. 26 1 27 2007-05-10 Lars Knoll <lars@trolltech.com> 2 28 -
trunk/JavaScriptCore/kjs/nodes2string.cpp
r21027 r21406 32 32 public: 33 33 enum Format { 34 Endl, Indent, Unindent 34 Endl, Indent, Unindent, DotExpr 35 35 }; 36 36 SourceStream() : m_groupIfNumber(false) {} 37 37 UString toString() const { return str; } 38 38 SourceStream& operator<<(const Identifier &); 39 39 SourceStream& operator<<(const UString &); 40 40 SourceStream& operator<<(const char *); 41 SourceStream& operator<<(double); 41 42 SourceStream& operator<<(char); 42 43 SourceStream& operator<<(Format f); 43 44 SourceStream& operator<<(const Node *); 44 45 template <typename T> SourceStream& operator<<(RefPtr<T> n) { return this->operator<<(n.get()); } 46 45 47 private: 46 48 UString str; /* TODO: buffer */ 47 49 UString ind; 50 bool m_groupIfNumber; 48 51 }; 49 52 } … … 53 56 SourceStream& SourceStream::operator<<(char c) 54 57 { 58 m_groupIfNumber = false; 55 59 UChar ch(c); 56 60 str += UString(&ch, 1); … … 60 64 SourceStream& SourceStream::operator<<(const char *s) 61 65 { 66 m_groupIfNumber = false; 62 67 str += UString(s); 63 68 return *this; 64 69 } 65 70 71 SourceStream& SourceStream::operator<<(double value) 72 { 73 if (m_groupIfNumber) 74 str.append("("); 75 76 str += UString::from(value); 77 78 if (m_groupIfNumber) 79 str.append(")"); 80 81 m_groupIfNumber = false; 82 return *this; 83 } 84 66 85 SourceStream& SourceStream::operator<<(const UString &s) 67 86 { 87 m_groupIfNumber = false; 68 88 str += s; 69 89 return *this; … … 72 92 SourceStream& SourceStream::operator<<(const Identifier &s) 73 93 { 94 m_groupIfNumber = false; 74 95 str += s.ustring(); 75 96 return *this; … … 80 101 if (n) 81 102 n->streamTo(*this); 103 m_groupIfNumber = false; 82 104 return *this; 83 105 } … … 85 107 SourceStream& SourceStream::operator<<(Format f) 86 108 { 109 m_groupIfNumber = false; 87 110 switch (f) { 88 111 case Endl: … … 95 118 ind = ind.substr(0, ind.size() - 2); 96 119 break; 120 case DotExpr: 121 m_groupIfNumber = true; 122 break; 97 123 } 98 124 … … 115 141 } 116 142 117 void NumberNode::streamTo(SourceStream &s) const { s << UString::from(value); }143 void NumberNode::streamTo(SourceStream &s) const { s << value; } 118 144 119 145 void StringNode::streamTo(SourceStream &s) const … … 206 232 void DotAccessorNode::streamTo(SourceStream &s) const 207 233 { 208 s << expr << "." << ident;234 s << SourceStream::DotExpr << expr << "." << ident; 209 235 } 210 236 … … 248 274 void FunctionCallDotNode::streamTo(SourceStream &s) const 249 275 { 250 s << base << "." << ident << args;276 s << SourceStream::DotExpr << base << "." << ident << args; 251 277 } 252 278 253 279 void FunctionCallParenDotNode::streamTo(SourceStream &s) const 254 280 { 255 s << "(" << base << "." << ident << ")" << args;281 s << "(" << SourceStream::DotExpr << base << "." << ident << ")" << args; 256 282 } 257 283 … … 276 302 void PostfixDotNode::streamTo(SourceStream &s) const 277 303 { 278 s << m_base << "." << m_ident;304 s << SourceStream::DotExpr << m_base << "." << m_ident; 279 305 if (m_oper == OpPlusPlus) 280 306 s << "++"; … … 304 330 void DeleteDotNode::streamTo(SourceStream &s) const 305 331 { 306 s << "delete " << m_base << "." << m_ident;332 s << "delete " << SourceStream::DotExpr << m_base << "." << m_ident; 307 333 } 308 334 … … 351 377 else 352 378 s << "--"; 353 s << m_base << "." << m_ident;379 s << SourceStream::DotExpr << m_base << "." << m_ident; 354 380 } 355 381 … … 539 565 void AssignDotNode::streamTo(SourceStream &s) const 540 566 { 541 s << m_base << "." << m_ident;567 s << SourceStream::DotExpr << m_base << "." << m_ident; 542 568 streamAssignmentOperatorTo(s, m_oper); 543 569 s << m_right;
Note: See TracChangeset
for help on using the changeset viewer.