source: webkit/trunk/JavaScriptCore/kjs/nodes2string.cpp@ 3098

Last change on this file since 3098 was 3098, checked in by darin, 22 years ago

top level:

Reviewed by Don and Maciej.

  • force-clean-timestamp: Trigger a full build since we are setting MACOSX_DEPLOYMENT_TARGET to 10.2, which requires remaking all PFEs.

Tools:

  • Scripts/check-copyright: Added.

JavaScriptCore:

Reviewed by Don and Maciej.

  • fixed 3129115 -- need Apple copyright added to open source documents
  • tons of files: Added our copyright to files we modified, and updated all to standard format.
  • other changes
  • JavaScriptCore.pbproj/project.pbxproj: Set MACOSX_DEPLOYMENT_TARGET to 10.2. Also removed completion.cpp.
  • kjs/completion.cpp: Removed.
  • kjs/completion.h: Made the Completion constructor inline.
  • kjs/grammar.y: Removed an obsolete "pretend ifdef". No need to put these in APPLE_CHANGES now.

WebFoundation:

Reviewed by Don and Maciej.

  • English.lproj/StringsNotToBeLocalized.txt: Updated for recent changes.
  • WebFoundation.pbproj/project.pbxproj: Set MACOSX_DEPLOYMENT_TARGET to 10.2.

WebCore:

Reviewed by Don and Maciej.

  • fixed 3129115 -- need Apple copyright added to open source documents
  • tons of files: Added copyright message to files we modified and standardized format of copyrights too.
  • fixed 3129235 -- assert in LRUList visiting apple.com if "Display images" preference is off
  • khtml/misc/loader.cpp: (Cache::getLRUListFor): Use the first list for 0-sized objects. (Cache::removeFromLRUList): Allow 0-sized objects.
  • other changes
  • khtml/rendering/render_style.h: Remove bogus unused private constructor.
  • kwq/KWQFont.h: Added copy constructor and assignment operator.
  • kwq/KWQFont.mm: (QFont::QFont): Copy constructor now retains the NSFont. The old version didn't which could cause retain/release problems. (QFont::operator=): Retain the new NSFont and release the old one.
  • WebCore.pbproj/project.pbxproj: Set MACOSX_DEPLOYMENT_TARGET to 10.2.

WebKit:

Reviewed by Don and Maciej.

  • WebView.subproj/WebUserAgentSpoofTable.gperf: Added a couple of new domains to the list we spoof as Mac IE, and added comments.
  • WebView.subproj/WebUserAgentSpoofTable.c: Regenerated.
  • WebKit.pbproj/project.pbxproj: Set MACOSX_DEPLOYMENT_TARGET to 10.2

WebBrowser:

Reviewed by Don and Maciej.

  • fixed 3106686 -- Remove "world leak" debugging window before beta
  • Test/PageLoadTestController.m: (-[PageLoadTestController windowDidLoad]): (Not part of the bug fix.) Changed the combo box so it automatically sizes to the number of pltsuite files so we don't have to edit the nib all the time. (-[PageLoadTestController anyWindowWillClose:]): Don't do any world leak test when the window closes. The one in the page load test window is still there.
  • Debug/DebugUtilities.m: (-[NSApplication validate_toggleAlwaysCheckForWorldLeaks:]): Don't enable or check the debug menu item at all. Put an ifdef in so we can turn it on later.
  • fixed 3124310 -- remove "app refuses to launch" code before shipping
  • main.m: (main): Remove all the licensing code.
  • other changes
  • BrowserNSNetServiceExtras.m: Made all locally-defined-and used functions static so we would know if any were unused and for cleanliness. (-[NSNetService hostName:andPort:]): Remove some silly assertions. (decode_name): Change printf for errors to ERROR. (decode_srv): Ditto. (decode_txt): Removed because it's unused. (skip_question): Ditto. (MyDictionaryKeyHashCallBack): Removed silly assertion. (MyCreateCFDictionaryFromTXT): Ditto.
  • WebBrowser.pbproj/project.pbxproj: Set MACOSX_DEPLOYMENT_TARGET to 10.2
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 2002 Harri Porten ([email protected])
5 * Copyright (C) 2002 Apple Computer, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 *
22 */
23
24#include "nodes.h"
25
26namespace KJS {
27 /**
28 * A simple text streaming class that helps with code indentation.
29 */
30 class SourceStream {
31 public:
32 enum Format {
33 Endl, Indent, Unindent
34 };
35
36 UString toString() const { return str; }
37 SourceStream& operator<<(const Identifier &);
38 SourceStream& operator<<(const UString &);
39 SourceStream& operator<<(const char *);
40 SourceStream& operator<<(char);
41 SourceStream& operator<<(Format f);
42 SourceStream& operator<<(const Node *);
43 private:
44 UString str; /* TODO: buffer */
45 UString ind;
46 };
47};
48
49using namespace KJS;
50
51SourceStream& SourceStream::operator<<(char c)
52{
53 str += UString(c);
54 return *this;
55}
56
57SourceStream& SourceStream::operator<<(const char *s)
58{
59 str += UString(s);
60 return *this;
61}
62
63SourceStream& SourceStream::operator<<(const UString &s)
64{
65 str += s;
66 return *this;
67}
68
69SourceStream& SourceStream::operator<<(const Identifier &s)
70{
71 str += s.ustring();
72 return *this;
73}
74
75SourceStream& SourceStream::operator<<(const Node *n)
76{
77 if (n)
78 n->streamTo(*this);
79 return *this;
80}
81
82SourceStream& SourceStream::operator<<(Format f)
83{
84 if (f == Endl)
85 str += "\n" + ind;
86 else if (f == Indent)
87 ind += " ";
88 else
89 ind = ind.substr(0, ind.size() - 2);
90
91 return *this;
92}
93
94UString Node::toString() const
95{
96 SourceStream str;
97 streamTo(str);
98
99 return str.toString();
100}
101
102void NullNode::streamTo(SourceStream &s) const { s << "null"; }
103
104void BooleanNode::streamTo(SourceStream &s) const
105{
106 s << (value ? "true" : "false");
107}
108
109void NumberNode::streamTo(SourceStream &s) const { s << UString::from(value); }
110
111void StringNode::streamTo(SourceStream &s) const
112{
113 s << '"' << value << '"';
114}
115
116void RegExpNode::streamTo(SourceStream &s) const { s << pattern; }
117
118void ThisNode::streamTo(SourceStream &s) const { s << "this"; }
119
120void ResolveNode::streamTo(SourceStream &s) const { s << ident; }
121
122void ElisionNode::streamTo(SourceStream &s) const
123{
124 if (elision)
125 s << elision << ",";
126 else
127 s << ",";
128}
129
130void ElementNode::streamTo(SourceStream &s) const
131{
132 if (list)
133 s << list << ",";
134 s << elision << node;
135}
136
137void ArrayNode::streamTo(SourceStream &s) const
138{
139 s << "[" << element << elision << "]";
140}
141
142void ObjectLiteralNode::streamTo(SourceStream &s) const
143{
144 if (list)
145 s << "{ " << list << " }";
146 else
147 s << "{ }";
148}
149
150void PropertyValueNode::streamTo(SourceStream &s) const
151{
152 if (list)
153 s << list << ", ";
154 s << name << ": " << assign;
155}
156
157void PropertyNode::streamTo(SourceStream &s) const
158{
159 if (str.isNull())
160 s << UString::from(numeric);
161 else
162 s << str;
163}
164
165void AccessorNode1::streamTo(SourceStream &s) const
166{
167 s << expr1 << "[" << expr2 << "]";
168}
169
170void AccessorNode2::streamTo(SourceStream &s) const
171{
172 s << expr << "." << ident;
173}
174
175void ArgumentListNode::streamTo(SourceStream &s) const
176{
177 if (list)
178 s << list << ", ";
179 s << expr;
180}
181
182void ArgumentsNode::streamTo(SourceStream &s) const
183{
184 s << "(" << list << ")";
185}
186
187void NewExprNode::streamTo(SourceStream &s) const
188{
189 s << "new " << expr << args;
190}
191
192void FunctionCallNode::streamTo(SourceStream &s) const
193{
194 s << expr << args;
195}
196
197void PostfixNode::streamTo(SourceStream &s) const
198{
199 s << expr;
200 if (oper == OpPlusPlus)
201 s << "++";
202 else
203 s << "--";
204}
205
206void DeleteNode::streamTo(SourceStream &s) const
207{
208 s << "delete " << expr;
209}
210
211void VoidNode::streamTo(SourceStream &s) const
212{
213 s << "void " << expr;
214}
215
216void TypeOfNode::streamTo(SourceStream &s) const
217{
218 s << "typeof " << expr;
219}
220
221void PrefixNode::streamTo(SourceStream &s) const
222{
223 s << expr << (oper == OpPlusPlus ? "++" : "--");
224}
225
226void UnaryPlusNode::streamTo(SourceStream &s) const
227{
228 s << "+" << expr;
229}
230
231void NegateNode::streamTo(SourceStream &s) const
232{
233 s << "-" << expr;
234}
235
236void BitwiseNotNode::streamTo(SourceStream &s) const
237{
238 s << "~" << expr;
239}
240
241void LogicalNotNode::streamTo(SourceStream &s) const
242{
243 s << "!" << expr;
244}
245
246void MultNode::streamTo(SourceStream &s) const
247{
248 s << term1 << oper << term2;
249}
250
251void AddNode::streamTo(SourceStream &s) const
252{
253 s << term1 << oper << term2;
254}
255
256void ShiftNode::streamTo(SourceStream &s) const
257{
258 s << term1;
259 if (oper == OpLShift)
260 s << "<<";
261 else if (oper == OpRShift)
262 s << ">>";
263 else
264 s << ">>>";
265 s << term2;
266}
267
268void RelationalNode::streamTo(SourceStream &s) const
269{
270 s << expr1;
271 switch (oper) {
272 case OpLess:
273 s << " < ";
274 break;
275 case OpGreater:
276 s << " > ";
277 break;
278 case OpLessEq:
279 s << " <= ";
280 break;
281 case OpGreaterEq:
282 s << " >= ";
283 break;
284 case OpInstanceOf:
285 s << " instanceof ";
286 break;
287 case OpIn:
288 s << " in ";
289 break;
290 default:
291 ;
292 }
293 s << expr2;
294}
295
296void EqualNode::streamTo(SourceStream &s) const
297{
298 s << expr1;
299 switch (oper) {
300 case OpEqEq:
301 s << " == ";
302 break;
303 case OpNotEq:
304 s << " != ";
305 break;
306 case OpStrEq:
307 s << " === ";
308 break;
309 case OpStrNEq:
310 s << " !== ";
311 break;
312 default:
313 ;
314 }
315 s << expr2;
316}
317
318void BitOperNode::streamTo(SourceStream &s) const
319{
320 s << expr1;
321 if (oper == OpBitAnd)
322 s << " & ";
323 else if (oper == OpBitXOr)
324 s << " ^ ";
325 else
326 s << " | ";
327 s << expr2;
328}
329
330void BinaryLogicalNode::streamTo(SourceStream &s) const
331{
332 s << expr1 << (oper == OpAnd ? " && " : " || ") << expr2;
333}
334
335void ConditionalNode::streamTo(SourceStream &s) const
336{
337 s << logical << " ? " << expr1 << " : " << expr2;
338}
339
340void AssignNode::streamTo(SourceStream &s) const
341{
342 s << left;
343 const char *opStr;
344 switch (oper) {
345 case OpEqual:
346 opStr = " = ";
347 break;
348 case OpMultEq:
349 opStr = " *= ";
350 break;
351 case OpDivEq:
352 opStr = " /= ";
353 break;
354 case OpPlusEq:
355 opStr = " += ";
356 break;
357 case OpMinusEq:
358 opStr = " -= ";
359 break;
360 case OpLShift:
361 opStr = " <<= ";
362 break;
363 case OpRShift:
364 opStr = " >>= ";
365 break;
366 case OpURShift:
367 opStr = " >>= ";
368 break;
369 case OpAndEq:
370 opStr = " &= ";
371 break;
372 case OpXOrEq:
373 opStr = " ^= ";
374 break;
375 case OpOrEq:
376 opStr = " |= ";
377 break;
378 case OpModEq:
379 opStr = " %= ";
380 break;
381 default:
382 opStr = " ?= ";
383 }
384 s << opStr << expr;
385}
386
387void CommaNode::streamTo(SourceStream &s) const
388{
389 s << expr1 << ", " << expr2;
390}
391
392void StatListNode::streamTo(SourceStream &s) const
393{
394 s << list << statement;
395}
396
397void AssignExprNode::streamTo(SourceStream &s) const
398{
399 s << " = " << expr;
400}
401
402void VarDeclNode::streamTo(SourceStream &s) const
403{
404 s << ident << init;
405}
406
407void VarDeclListNode::streamTo(SourceStream &s) const
408{
409 if (list)
410 s << list << ", ";
411 s << var;
412}
413
414void VarStatementNode::streamTo(SourceStream &s) const
415{
416 s << SourceStream::Endl << "var " << list << ";";
417}
418
419void BlockNode::streamTo(SourceStream &s) const
420{
421 s << SourceStream::Endl << "{" << SourceStream::Indent
422 << source << SourceStream::Unindent << SourceStream::Endl << "}";
423}
424
425void EmptyStatementNode::streamTo(SourceStream &s) const
426{
427 s << SourceStream::Endl << ";";
428}
429
430void ExprStatementNode::streamTo(SourceStream &s) const
431{
432 s << SourceStream::Endl << expr << ";";
433}
434
435void IfNode::streamTo(SourceStream &s) const
436{
437 s << SourceStream::Endl << "if (" << expr << ")" << SourceStream::Indent
438 << statement1 << SourceStream::Unindent;
439 if (statement2)
440 s << SourceStream::Endl << "else" << SourceStream::Indent
441 << statement2 << SourceStream::Unindent;
442}
443
444void DoWhileNode::streamTo(SourceStream &s) const
445{
446 s << SourceStream::Endl << "do " << SourceStream::Indent
447 << statement << SourceStream::Unindent << SourceStream::Endl
448 << "while (" << expr << ");";
449}
450
451void WhileNode::streamTo(SourceStream &s) const
452{
453 s << SourceStream::Endl << "while (" << expr << ")" << SourceStream::Indent
454 << statement << SourceStream::Unindent;
455}
456
457void ForNode::streamTo(SourceStream &s) const
458{
459 s << SourceStream::Endl << "for ("
460 << expr1 // TODO: doesn't properly do "var i = 0"
461 << "; " << expr2
462 << "; " << expr3
463 << ")" << SourceStream::Indent << statement << SourceStream::Unindent;
464}
465
466void ForInNode::streamTo(SourceStream &s) const
467{
468 s << SourceStream::Endl << "for (";
469 if (varDecl)
470 s << "var " << varDecl;
471 if (init)
472 s << " = " << init;
473 s << " in " << expr << ")" << SourceStream::Indent
474 << statement << SourceStream::Unindent;
475}
476
477void ContinueNode::streamTo(SourceStream &s) const
478{
479 s << SourceStream::Endl << "continue";
480 if (!ident.isNull())
481 s << " " << ident;
482 s << ";";
483}
484
485void BreakNode::streamTo(SourceStream &s) const
486{
487 s << SourceStream::Endl << "break";
488 if (!ident.isNull())
489 s << " " << ident;
490 s << ";";
491}
492
493void ReturnNode::streamTo(SourceStream &s) const
494{
495 s << SourceStream::Endl << "return";
496 if (value)
497 s << " " << value;
498 s << ";";
499}
500
501void WithNode::streamTo(SourceStream &s) const
502{
503 s << SourceStream::Endl << "with (" << expr << ") "
504 << statement;
505}
506
507void CaseClauseNode::streamTo(SourceStream &s) const
508{
509 s << SourceStream::Endl;
510 if (expr)
511 s << "case " << expr;
512 else
513 s << "default";
514 s << ":" << SourceStream::Indent;
515 if (list)
516 s << list;
517 s << SourceStream::Unindent;
518}
519
520void ClauseListNode::streamTo(SourceStream &s) const
521{
522 const ClauseListNode *l = this;
523 do {
524 s << l;
525 l = l->nx;
526 } while (l);
527}
528
529void CaseBlockNode::streamTo(SourceStream &s) const
530{
531 const ClauseListNode *cl = list1;
532 while (cl) {
533 s << cl->clause();
534 cl = cl->next();
535 }
536 if (def)
537 s << def;
538 cl = list2;
539 while (cl) {
540 s << cl->clause();
541 cl = cl->next();
542 }
543}
544
545void SwitchNode::streamTo(SourceStream &s) const
546{
547 s << SourceStream::Endl << "switch (" << expr << ") {"
548 << SourceStream::Indent << block << SourceStream::Unindent
549 << SourceStream::Endl << "}";
550}
551
552void LabelNode::streamTo(SourceStream &s) const
553{
554 s << SourceStream::Endl << label << ":" << SourceStream::Indent
555 << statement << SourceStream::Unindent;
556}
557
558void ThrowNode::streamTo(SourceStream &s) const
559{
560 s << SourceStream::Endl << "throw " << expr << ";";
561}
562
563void CatchNode::streamTo(SourceStream &s) const
564{
565 s << SourceStream::Endl << "catch (" << ident << ")" << block;
566}
567
568void FinallyNode::streamTo(SourceStream &s) const
569{
570 s << SourceStream::Endl << "finally " << block;
571}
572
573void TryNode::streamTo(SourceStream &s) const
574{
575 s << "try " << block
576 << _catch
577 << _final;
578}
579
580void ParameterNode::streamTo(SourceStream &s) const
581{
582 s << id;
583 if (next)
584 s << ", " << next;
585}
586
587void FunctionBodyNode::streamTo(SourceStream &s) const {
588 s << SourceStream::Endl << "{" << SourceStream::Indent
589 << source << SourceStream::Unindent << SourceStream::Endl << "}";
590}
591
592void FuncDeclNode::streamTo(SourceStream &s) const {
593 s << "function " << ident << "(";
594 if (param)
595 s << param;
596 s << ")" << body;
597}
598
599void FuncExprNode::streamTo(SourceStream &s) const
600{
601 s << "function " << "("
602 << param
603 << ")" << body;
604}
605
606void SourceElementNode::streamTo(SourceStream &s) const
607{
608 if (statement)
609 s << statement;
610 else
611 s << function;
612}
613
614void SourceElementsNode::streamTo(SourceStream &s) const
615{
616 s << elements << element;
617}
618
Note: See TracBrowser for help on using the repository browser.