Changeset 29802 in webkit for trunk/JavaScriptCore/kjs/nodes2string.cpp
- Timestamp:
- Jan 25, 2008, 11:54:50 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/nodes2string.cpp
r28973 r29802 42 42 class SourceStream { 43 43 public: 44 SourceStream() : m_numberNeedsParens(false), m_ precedence(PrecExpression) { }44 SourceStream() : m_numberNeedsParens(false), m_atStartOfStatement(true), m_precedence(PrecExpression) { } 45 45 UString toString() const { return m_string; } 46 46 SourceStream& operator<<(const Identifier&); … … 61 61 UString m_spacesForIndentation; 62 62 bool m_numberNeedsParens; 63 bool m_atStartOfStatement; 63 64 Precedence m_precedence; 64 65 }; … … 151 152 { 152 153 m_numberNeedsParens = false; 154 m_atStartOfStatement = false; 153 155 UChar ch(c); 154 156 m_string.append(ch); … … 159 161 { 160 162 m_numberNeedsParens = false; 163 m_atStartOfStatement = false; 161 164 m_string += s; 162 165 return *this; … … 167 170 bool needParens = m_numberNeedsParens; 168 171 m_numberNeedsParens = false; 172 m_atStartOfStatement = false; 169 173 170 174 if (needParens) … … 180 184 { 181 185 m_numberNeedsParens = false; 186 m_atStartOfStatement = false; 182 187 m_string += s; 183 188 return *this; … … 187 192 { 188 193 m_numberNeedsParens = false; 194 m_atStartOfStatement = false; 189 195 m_string += s.ustring(); 190 196 return *this; … … 193 199 SourceStream& SourceStream::operator<<(const Node* n) 194 200 { 195 bool needParens = m_precedence != PrecExpression && n->precedence() > m_precedence;201 bool needParens = (m_precedence != PrecExpression && n->precedence() > m_precedence) || (m_atStartOfStatement && n->needsParensIfLeftmost()); 196 202 m_precedence = PrecExpression; 197 203 if (n) { … … 208 214 { 209 215 m_numberNeedsParens = false; 216 m_atStartOfStatement = true; 210 217 m_string.append('\n'); 211 218 m_string.append(m_spacesForIndentation); … … 216 223 { 217 224 m_numberNeedsParens = false; 225 m_atStartOfStatement = false; 218 226 m_spacesForIndentation += " "; 219 227 return *this; … … 223 231 { 224 232 m_numberNeedsParens = false; 233 m_atStartOfStatement = false; 225 234 m_spacesForIndentation = m_spacesForIndentation.substr(0, m_spacesForIndentation.size() - 2); 226 235 return *this;
Note:
See TracChangeset
for help on using the changeset viewer.