JSDOC/ScopeParser.js
[gnome.introspection-doc-generator] / JSDOC / ScopeParser.js
1 //<Script type="text/javascript">
2
3 Scope = imports['JSDOC/Scope.js'].Scope;
4
5 /**
6 * Scope stuff
7
8 * // FIXME - I need this to do next() without doccomments..
9 */
10
11 ScopeParser = function(ts) {
12     this.ts = ts; // {TokenStream}
13     this.warnings = [];
14     this.scopes = [];
15     this.indexedScopes = {};
16     this.timer = new Date() * 1;
17     this.debug = false;
18 }
19
20 // list of keywords that should not be used in object literals.
21 ScopeParser.idents = [
22         "break",         
23         "case",          
24         "continue",     
25         "default",      
26         "delete",       
27         "do",            
28         "else",         
29         "export",       
30         "false",        
31         "for",          
32         "function",     
33         "if",           
34         "import",       
35         "in",           
36         "new",          
37         "null",         
38         "return",       
39         "switch",       
40         "this",         
41         "true",         
42         "typeof",       
43         "var",          
44         "void",         
45         "while",        
46         "with",         
47
48         "catch",        
49         "class",        
50         "const",        
51         "debugger",     
52         "enum",         
53         "extends",      
54         "finally",      
55         "super",        
56         "throw",         
57         "try",          
58
59         "abstract",     
60         "boolean",      
61         "byte",         
62         "char",         
63         "double",       
64         "final",        
65         "float",        
66         "goto",         
67         "implements", 
68         "instanceof",
69         "int",           
70         "interface",     
71         "long",          
72         "native",       
73         "package",      
74         "private",      
75         "protected",     
76         "public",        
77         "short",        
78         "static",       
79         "synchronized",  
80         "throws",        
81         "transient",     
82                 "include",       
83                 "undefined"
84 ];
85
86
87 ScopeParser.prototype = {
88     timer: 0,
89     timerPrint: function (str) {
90         var ntime = new Date() * 1;
91         var tdif =  ntime -this.timer;
92         this.timer = ntime;
93         var pref = '';
94         if (tdif > 100) { //slower ones..
95             pref = '***';
96         }
97         println(pref+'['+tdif+']'+str);
98         
99     },
100     warn: function(s) {
101         //print('****************' + s);
102         this.warnings.push(s);
103         //println("WARNING:" + htmlescape(s) + "<BR>");
104     },
105     // defaults should not be initialized here =- otherwise they get duped on new, rather than initalized..
106     warnings : false,
107     ts : false,
108     scopes : false,
109     global : false,
110     mode : "", //"BUILDING_SYMBOL_TREE",
111     braceNesting : 0,
112     indexedScopes : false,
113     munge: true,
114
115
116
117
118
119     buildSymbolTree : function()
120     {
121         //println("<PRE>");
122         
123         this.ts.rewind();
124         this.braceNesting = 0;
125         this.scopes = [];
126         
127         
128         
129         
130         this.globalScope = new  Scope(-1, false, -1, '');
131         indexedScopes = { 0 : this.globalScope };
132         
133         this.mode = 'BUILDING_SYMBOL_TREE';
134         this.parseScope(this.globalScope);
135         
136         //print("---------------END PASS 1 ---------------- ");
137         
138     },
139     mungeSymboltree : function()
140     {
141
142         if (!this.munge) {
143             return;
144         }
145
146         // One problem with obfuscation resides in the use of undeclared
147         // and un-namespaced global symbols that are 3 characters or less
148         // in length. Here is an example:
149         //
150         //     var declaredGlobalVar;
151         //
152         //     function declaredGlobalFn() {
153         //         var localvar;
154         //         localvar = abc; // abc is an undeclared global symbol
155         //     }
156         //
157         // In the example above, there is a slim chance that localvar may be
158         // munged to 'abc', conflicting with the undeclared global symbol
159         // abc, creating a potential bug. The following code detects such
160         // global symbols. This must be done AFTER the entire file has been
161         // parsed, and BEFORE munging the symbol tree. Note that declaring
162         // extra symbols in the global scope won't hurt.
163         //
164         // Note: Since we go through all the tokens to do this, we also use
165         // the opportunity to count how many times each identifier is used.
166
167         this.ts.rewind();
168         this.braceNesting = 0;
169         this.scopes= [];
170         this.mode = 'PASS2_SYMBOL_TREE';
171         
172         //println("MUNGING?");
173         
174         this.parseScope(this.globalScope);
175         this.globalScope.munge();
176     },
177
178
179     log : function(str)
180     {
181         print ("                    ".substring(0, this.braceNesting*2) + str);
182         
183         //println("<B>LOG:</B>" + htmlescape(str) + "<BR/>\n");
184     },
185     logR : function(str)
186     {
187             //println("<B>LOG:</B>" + str + "<BR/>");
188     },
189
190
191
192
193
194
195     parseScope : function(scope) // parse a token stream..
196     {
197         //this.timerPrint("parseScope EnterScope"); 
198         //this.log(">>> ENTER SCOPE" + this.scopes.length);
199         var symbol;
200         var token;
201         
202         var identifier;
203
204         var expressionBraceNesting = this.braceNesting;
205         
206         var parensNesting = 0;
207         
208         var isObjectLitAr = [ false ];
209         var isInObjectLitAr;
210         this.scopes.push(scope);
211         
212         var scopeIndent = ''; 
213         this.scopes.forEach(function() {
214             scopeIndent += '   '; 
215         });
216         
217         token = this.ts.lookTok(1);
218         while (token) {
219           //  this.timerPrint("parseScope AFTER lookT: " + token.toString()); 
220              
221             //this.log(token.data);
222             if (token.type == 'NAME') {
223             //    print('*' + token.data);
224             }
225             switch(token.type + '.' + token.name) {
226                 case "KEYW.VAR":
227                 case "KEYW.CONST": // not really relivant as it's only mozzy that does this.
228                     
229                     //this.log("parseScope GOT VAR/CONST : " + token.toString()); 
230                     while (true) {
231                         token = this.ts.nextTok();
232                         !this.debug|| print( token.toString());
233                       
234                         if (!token) { // can return false at EOF!
235                             break;
236                         }
237                         if (token.name == "VAR" || token.data == ',') { // kludge..
238                             continue;
239                         }
240                         //this.logR("parseScope GOT VAR  : <B>" + token.toString() + "</B>"); 
241                         if (token.type !="NAME") {
242                             for(var i = Math.max(this.ts.cursor-10,0); i < this.ts.cursor+1; i++) {
243                                 print(this.ts.tokens[i].toString());
244                             }
245                             
246                             print( "var without ident");
247                             Seed.quit()
248                         }
249                         
250
251                         if (this.mode == "BUILDING_SYMBOL_TREE") {
252                             identifier = scope.getIdentifier(token.data) ;
253                             
254                             if (identifier == false) {
255                                 scope.declareIdentifier(token.data, token);
256                             } else {
257                                 token.identifier = identifier;
258                                 this.warn("(SCOPE) The variable " + token.data  + ' (line:' + token.line + ")  has already been declared in the same scope...");
259                             }
260                         }
261
262                         token = this.ts.nextTok();
263                         !this.debug|| print(token.toString());
264                         /*
265                         assert token.getType() == Token.SEMI ||
266                                 token.getType() == Token.ASSIGN ||
267                                 token.getType() == Token.COMMA ||
268                                 token.getType() == Token.IN;
269                         */
270                         if (token.name == "IN") {
271                             break;
272                         } else {
273                             //var bn = this.braceNesting;
274                             this.parseExpression();
275                             //this.braceNesting = bn;
276                             //this.logR("parseScope DONE  : <B>ParseExpression</B> - tok is:" + this.ts.lookT(0).toString()); 
277                             
278                             token = this.ts.lookTok(1);
279                             !this.debug|| print("AFTER EXP: " + token.toString());
280                             if (token.data == ';') {
281                                 break;
282                             }
283                         }
284                     }
285                     break;
286                 case "KEYW.FUNCTION":
287                     //println("<i>"+token.data+"</i>");
288                      var bn = this.braceNesting;
289                     this.parseFunctionDeclaration();
290                      this.braceNesting = bn;
291                     break;
292
293                 case "PUNC.LEFT_CURLY": // {
294                     //println("<i>"+token.data+"</i>");
295                     isObjectLitAr.push(false);
296                     this.braceNesting++;
297                     
298                     //print(">>>>>> OBJLIT PUSH(false)" + this.braceNesting);
299                     break;
300
301                 case "PUNC.RIGHT_CURLY": // }
302                     //println("<i>"+token.data+"</i>");
303                     this.braceNesting--;
304                     isObjectLitAr.pop();
305                     //print(">>>>>> OBJLIT POP"+ this.braceNesting);
306                         //assert braceNesting >= scope.getBra ceNesting();
307                     
308                     if (this.braceNesting < expressionBraceNesting) {
309                         var ls = this.scopes.pop();
310                         ls.getUsedSymbols();
311                         // eat symbol if we are currently at { 
312                         if (this.ts.look(0).data == '{') {
313                             this.ts.nextTok();
314                         }
315                         
316                         //print("<<<<<<<EXIT SCOPE" +this.scopes.length);
317                         return;
318                     }
319                     break;
320
321                 case "KEYW.WITH":
322                     //println("<i>"+token.data+"</i>");   
323                     if (this.mode == "BUILDING_SYMBOL_TREE") {
324                         // Inside a 'with' block, it is impossible to figure out
325                         // statically whether a symbol is a local variable or an
326                         // object member. As a consequence, the only thing we can
327                         // do is turn the obfuscation off for the highest scope
328                         // containing the 'with' block.
329                         this.protectScopeFromObfuscation(scope);
330                         this.warn("Using 'with' is not recommended." + (this.munge ? " Moreover, using 'with' reduces the level of compression!" : ""), true);
331                     }
332                     break;
333
334                 case "KEYW.CATCH":
335                     //println("<i>"+token.data+"</i>");
336                     this.parseCatch();
337                     break;
338                 /*
339                 case Token.SPECIALCOMMENT:
340                         if (mode == BUILDING_SYMBOL_TREE) {
341                             protectScopeFromObfuscation(scope);
342                             this.warn("Using JScript conditional comments is not recommended." + (munge ? " Moreover, using JScript conditional comments reduces the level of compression." : ""), true);
343                         }
344                         break;
345                 */
346                 
347                 case "STRN.DOUBLE_QUOTE": // used for object lit detection..
348                 case "STRN.SINGLE_QUOTE":
349                     //println("<i>"+token.data+"</i>");
350                     if (this.ts.lookTok(-1).data == '{' && this.ts.lookTok(1).data == ':') {
351                         // then we are in an object lit.. -> we need to flag the brace as such...
352                         isObjectLitAr.pop();
353                         isObjectLitAr.push(true);
354                         //print(">>>>>> OBJLIT REPUSH(true)");
355                     }
356                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
357                     
358                     if (isInObjectLitAr &&  this.ts.lookTok(1).data == ':' &&
359                         ( this.ts.lookTok(-1).data == '{'  ||  this.ts.lookTok(-1).data == ':' )) {
360                         // see if we can replace..
361                         // remove the quotes..
362                         // should do a bit more checking!!!! (what about wierd char's in the string..
363                         var str = token.data.substring(1,token.data.length-1);
364                         if (/^[a-z_]+$/i.test(str) && ScopeParser.idents.indexOf(str) < 0) {
365                             token.outData = str;
366                         }
367                         
368                          
369                         
370                     }
371                     
372                     
373                     
374                     break;
375                 
376                 case "NAME.NAME":
377                 
378                     //print("DEAL WITH NAME:");
379                     // got identifier..
380                     
381                     // look for  { ** : <- indicates obj literal.. ** this could occur with numbers ..
382                     if ((this.ts.lookTok(-1).data == "{") && (this.ts.lookTok(1).data == ":")) {
383                         isObjectLitAr.pop();
384                         isObjectLitAr.push(true);
385                         //print(">>>>>> OBJLIT REPUSH(true)");
386                         //println("<i>"+token.data+"</i>");
387                         break;
388                     }
389                    // print("DEAL WITH obj lit:");
390                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
391                     
392                     if (isInObjectLitAr && (this.ts.lookTok(1).data == ":") && (this.ts.lookTok(-1).data == ",")) {
393                         // skip, it's an object lit key..
394                         //println("<i>"+token.data+"</i>");
395                         break;
396                     }
397                     
398                     
399                     // skip anyting with "." before it..!!
400                      
401                     if (this.ts.lookTok(-1).data == ".") {
402                         // skip, it's an object prop.
403                         //println("<i>"+token.data+"</i>");
404                         break;
405                     }
406                     symbol = token.data;
407                     if (this.mode == 'PASS2_SYMBOL_TREE') {
408                         
409                         //println("GOT IDENT: -2 : " + this.ts.lookT(-2).toString() + " <BR> ..... -1 :  " +  this.ts.lookT(-1).toString() + " <BR> "); 
410                         
411                         //print ("MUNGE?" + symbol);
412                         
413                         //println("GOT IDENT: <B>" + symbol + "</B><BR/>");
414                              
415                             //println("GOT IDENT (2): <B>" + symbol + "</B><BR/>");
416                         identifier = this.getIdentifier(symbol, scope);
417                         
418                         if (identifier == false) {
419 // BUG!find out where builtin is defined...
420                             if (symbol.length <= 3 &&  Scope.builtin.indexOf(symbol) < 0) {
421                                 // Here, we found an undeclared and un-namespaced symbol that is
422                                 // 3 characters or less in length. Declare it in the global scope.
423                                 // We don't need to declare longer symbols since they won't cause
424                                 // any conflict with other munged symbols.
425                                 this.globalScope.declareIdentifier(symbol, token);
426                                 this.warn("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')', true);
427                             }
428                             
429                             //println("GOT IDENT IGNORE(3): <B>" + symbol + "</B><BR/>");
430                         } else {
431                             token.identifier = identifier;
432                             identifier.refcount++;
433                         }
434                     }   
435                     
436                     break;
437                     //println("<B>SID</B>");
438                 default:
439                     if (token.type != 'KEYW') {
440                         break;
441                     }
442                    // print("Check eval:");
443                 
444                     symbol = token.data;
445                     
446                      if (this.mode == 'BUILDING_SYMBOL_TREE') {
447
448                         if (symbol == "eval") {
449                             // look back one and see if we can find a comment!!!
450                             if (this.ts.look(-1).type == "COMM") {
451                                 // look for eval:var:noreplace\n
452                                 var _t = this;
453                                 this.ts.look(-1).data.replace(/eval:var:([a-z_]+)/ig, function(m, a) {
454                                     
455                                     var hi = _t.getIdentifier(a, scope);
456                                    // println("PROTECT "+a+" from munge" + (hi ? "FOUND" : "MISSING"));
457                                     if (hi) {
458                                      //   println("PROTECT "+a+" from munge");
459                                         hi.toMunge = false;
460                                     }
461                                     
462                                 });
463                                 
464                                 
465                             } else {
466                                 
467                             
468                                 this.protectScopeFromObfuscation(scope);
469                                 this.warn("Using 'eval' is not recommended. (use  eval:var:noreplace in comments to optimize) " + (this.munge ? " Moreover, using 'eval' reduces the level of compression!" : ""), true);
470                             }
471
472                         }
473
474                     }
475                     break;
476                 
477                 
478             } // end switch
479             
480             
481             //this.timerPrint("parseScope TOK : " + token.toString()); 
482             token = this.ts.nextTok();
483             //if (this.ts.nextT()) break;
484             
485         }
486         //print("<<<<<<<EXIT SCOPE ERR?" +this.scopes.length);
487     },
488
489
490     parseExpression : function() {
491
492         // Parse the expression until we encounter a comma or a semi-colon
493         // in the same brace nesting, bracket nesting and paren nesting.
494         // Parse functions if any...
495         //println("<i>EXP</i><BR/>");
496         !this.debug || print("PARSE EXPR");
497         var symbol;
498         var token;
499         var currentScope;
500         var identifier;
501
502         var expressionBraceNesting = this.braceNesting;
503         var bracketNesting = 0;
504         var parensNesting = 0;
505         var isInObjectLitAr;
506         var isObjectLitAr = [ false ];
507         while (token = this.ts.lookTok()) {
508      
509
510             
511             currentScope = this.scopes[this.scopes.length-1];
512             
513             //println("<i>"+token.data+"</i>");
514             //this.log("EXP:" + token.data);
515             switch (token.type) {
516                 case 'PUNC':
517                     switch(token.data) {
518                          
519                         case ';':
520                         case ',':
521                             if (this.braceNesting == expressionBraceNesting &&
522                                     bracketNesting == 0 &&
523                                     parensNesting == 0) {
524                                 
525                                 return;
526                             }
527                             break;
528
529                        
530
531                         case '{': //Token.LC:
532                             isObjectLitAr.push(false);
533                             
534                             this.braceNesting++;
535                             ///print(">>>>> EXP PUSH(false)"+this.braceNesting);
536                             break;
537
538                         case '}': //Token.RC:
539                             this.braceNesting--;
540                             isObjectLitAr.pop();
541                             //print(">>>>> EXP POP" + this.braceNesting);    
542                            // assert braceNesting >= expressionBraceNesting;
543                             break;
544
545                         case '[': //Token.LB:
546                             bracketNesting++;
547                             break;
548
549                         case ']': //Token.RB:
550                             bracketNesting--;
551                             break;
552
553                         case '(': //Token.LP:
554                             parensNesting++;
555                             break;
556
557                         case ')': //Token.RP:
558                             parensNesting--;
559                             break;
560                     }
561                     break;
562                     
563                 case 'STRN': // used for object lit detection..
564                     if (this.ts.lookTok(-1).data == "{" && this.ts.lookTok(1).data == ":" ) {
565                         // then we are in an object lit.. -> we need to flag the brace as such...
566                         isObjectLitAr.pop();
567                         isObjectLitAr.push(true);
568                         //print(">>>>> EXP PUSH(true)");
569                     }
570                     
571                     
572                      
573                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
574                     if (isInObjectLitAr &&  this.ts.lookTok(1).data == ":"  &&
575                         ( this.ts.lookTok(-1).data == "{"  ||  this.ts.lookTok(-1).data == "," )) {
576                         // see if we can replace..
577                         // remove the quotes..
578                         var str = token.data.substring(1,token.data.length-1);
579                         if (/^[a-z_]+$/i.test(str) && ScopeParser.idents.indexOf(str) < 0) {
580                             token.outData = str;
581                         }
582                         
583                          
584                         
585                     }
586                     
587                     break;
588                 
589                       
590              
591                 case 'NAME':
592                
593                     symbol = token.data;
594                     print("in NAME = " + token.toString());
595                     print("in NAME 0: " + this.ts.look(0).toString());
596                     print("in NAME 2: " + this.ts.lookTok(2).toString());
597                     if (this.ts.look(0).data == "{"  && this.ts.lookTok(2).data == ":") {
598                         // then we are in an object lit.. -> we need to flag the brace as such...
599                         isObjectLitAr.pop();
600                         isObjectLitAr.push(true);
601                          //print(">>>>> EXP  PUSH(true)");
602                         break;
603                     }
604                     
605                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
606                     print ("isInObjectLitAr : " + isInObjectLitAr + ' ' + token.toString());
607                     
608                     if (isInObjectLitAr && this.ts.lookTok(0).data == "," && this.ts.lookTok(2).data == ":") {
609                         break;
610                     }
611                     //print(this.ts.lookTok(0).data);
612                     if (this.ts.lookTok(0).data == ".") {
613                         //skip '.'
614                         break;
615                     }
616                     
617                      if (this.mode == 'PASS2_SYMBOL_TREE') {
618
619                         identifier = this.getIdentifier(symbol, currentScope);
620                         //println("<B>??</B>");
621                         if (identifier == false) {
622
623                             if (symbol.length <= 3 &&  Scope.builtin.indexOf(symbol) < 0) {
624                                 // Here, we found an undeclared and un-namespaced symbol that is
625                                 // 3 characters or less in length. Declare it in the global scope.
626                                 // We don't need to declare longer symbols since they won't cause
627                                 // any conflict with other munged symbols.
628                                 this.globalScope.declareIdentifier(symbol, token);
629                                 this.warn("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')', true);
630                             } else {
631                                 //println("undeclared")
632                             }
633                             
634                             
635                         } else {
636                             //println("<B>++</B>");
637                             token.identifier = identifier;
638                             identifier.refcount++;
639                         }
640                         
641                     }
642                     break;
643                     
644                     
645                     
646                     
647                     //println("<B>EID</B>");
648                  case 'KEYW':   
649                  
650                     if (token.name == "FUNCTION") {
651                         
652                         this.parseFunctionDeclaration();
653                         break;
654                     }
655                
656                     
657              
658                     symbol = token.data;
659                     if (this.mode == 'BUILDING_SYMBOL_TREE') {
660
661                         if (symbol == "eval") {
662                             if (this.ts.look(-1).type == 'COMM') {
663                                 // look for eval:var:noreplace\n
664                                 var _t = this;
665                                 this.ts.look(-1).data.replace(/eval:var:([a-z]+)/ig, function(m, a) {
666                                     var hi = _t.getIdentifier(a, currentScope);
667                                    //println("PROTECT "+a+" from munge" + (hi ? "FOUND" : "MISSING"));
668                                     if (hi) {
669                                       //  println("PROTECT "+a+" from munge");
670                                         hi.toMunge = false;
671                                     }
672                                     
673                                     
674                                 });
675                                 
676                             } else {
677                                 this.protectScopeFromObfuscation(currentScope);
678                                 this.warn("Using 'eval' is not recommended." + (this.munge ? " Moreover, using 'eval' reduces the level of compression!" : ""), true);
679                             }
680                             
681
682                         }
683                         break;
684                     } 
685                    
686             }
687             if (!this.ts.nextTok()) break;
688         }
689     },
690
691
692     parseCatch : function() {
693
694         var symbol;
695         var token;
696         var currentScope;
697         var identifier;
698
699         //token = getToken(-1);
700         //assert token.getType() == Token.CATCH;
701         token = this.ts.nextTok();
702         //assert token.getType() == Token.LP; (
703         token = this.ts.nextTok();
704         //assert token.getType() == Token.NAME;
705         
706         symbol = token.data;
707         currentScope = this.scopes[this.scopes.length-1];
708
709         if (this.mode == 'BUILDING_SYMBOL_TREE') {
710             // We must declare the exception identifier in the containing function
711             // scope to avoid errors related to the obfuscation process. No need to
712             // display a warning if the symbol was already declared here...
713             currentScope.declareIdentifier(symbol, token);
714         } else {
715             //?? why inc the refcount?? - that should be set when building the tree???
716             identifier = this.getIdentifier(symbol, currentScope);
717             identifier.refcount++;
718         }
719
720         token = this.ts.nextTok();
721         //assert token.getType() == Token.RP; // )
722     },
723     
724     parseFunctionDeclaration : function() 
725     {
726        // print("PARSE FUNCTION");
727         var symbol;
728         var token;
729         var currentScope  = false; 
730         var fnScope = false;
731         var identifier;
732         //this.logR("<B>PARSING FUNCTION</B>");
733         currentScope = this.scopes[this.scopes.length-1];
734
735         token = this.ts.nextTok();
736         if (token.type == "NAME") {
737             if (this.mode == 'BUILDING_SYMBOL_TREE') {
738                 // Get the name of the function and declare it in the current scope.
739                 symbol = token.data;
740                 if (currentScope.getIdentifier(symbol) != false) {
741                     this.warn("The function " + symbol + " has already been declared in the same scope...", true);
742                 }
743                 currentScope.declareIdentifier(symbol,token);
744             }
745             token =  this.ts.nextTok();
746         }
747
748         //assert token.getType() == Token.LP;
749         if (this.mode == 'BUILDING_SYMBOL_TREE') {
750             fnScope = new Scope(this.braceNesting, currentScope, token.n, '');
751             
752             //println("STORING SCOPE" + this.ts.cursor);
753             
754             this.indexedScopes[this.ts.cursor] = fnScope;
755             
756         } else {
757             //qln("FETCHING SCOPE" + this.ts.cursor);
758             fnScope = this.indexedScopes[this.ts.cursor];
759           
760         }
761         
762         // Parse function arguments.
763         var argpos = 0;
764         while (this.ts.lookTok().data != ')') { //(token = consumeToken()).getType() != Token.RP) {
765             token = this.ts.nextTok();
766            // print ("FUNC ARGS: " + token.toString())
767             //assert token.getType() == Token.NAME ||
768             //        token.getType() == Token.COMMA;
769             if (token.type == 'NAME' && this.mode == 'BUILDING_SYMBOL_TREE') {
770                 symbol = token.data;
771                 identifier = fnScope.declareIdentifier(symbol,token);
772                 if (symbol == "$super" && argpos == 0) {
773                     // Exception for Prototype 1.6...
774                     identifier.preventMunging();
775                 }
776                 argpos++;
777             }
778         }
779
780         token = this.ts.nextTok();
781         // assert token.getType() == Token.LC;
782         this.braceNesting++;
783
784         token = this.ts.nextTok();
785         if (token.type == "STRN" && this.ts.lookTok(1).data == ';') {
786             /*
787             
788             NOT SUPPORTED YET!?!!?!
789             
790             // This is a hint. Hints are empty statements that look like
791             // "localvar1:nomunge, localvar2:nomunge"; They allow developers
792             // to prevent specific symbols from getting obfuscated (some heretic
793             // implementations, such as Prototype 1.6, require specific variable
794             // names, such as $super for example, in order to work appropriately.
795             // Note: right now, only "nomunge" is supported in the right hand side
796             // of a hint. However, in the future, the right hand side may contain
797             // other values.
798             consumeToken();
799             String hints = token.getValue();
800             // Remove the leading and trailing quotes...
801             hints = hints.substring(1, hints.length() - 1).trim();
802             StringTokenizer st1 = new StringTokenizer(hints, ",");
803             while (st1.hasMoreTokens()) {
804                 String hint = st1.nextToken();
805                 int idx = hint.indexOf(':');
806                 if (idx <= 0 || idx >= hint.length() - 1) {
807                     if (mode == BUILDING_SYMBOL_TREE) {
808                         // No need to report the error twice, hence the test...
809                         this.warn("Invalid hint syntax: " + hint, true);
810                     }
811                     break;
812                 }
813                 String variableName = hint.substring(0, idx).trim();
814                 String variableType = hint.substring(idx + 1).trim();
815                 if (mode == BUILDING_SYMBOL_TREE) {
816                     fnScope.addHint(variableName, variableType);
817                 } else if (mode == CHECKING_SYMBOL_TREE) {
818                     identifier = fnScope.getIdentifier(variableName);
819                     if (identifier != null) {
820                         if (variableType.equals("nomunge")) {
821                             identifier.preventMunging();
822                         } else {
823                             this.warn("Unsupported hint value: " + hint, true);
824                         }
825                     } else {
826                         this.warn("Hint refers to an unknown identifier: " + hint, true);
827                     }
828                 }
829             }
830             */
831         }
832
833         this.parseScope(fnScope);
834         // now pop it off the stack!!!
835        
836         
837         
838     },
839     
840     protectScopeFromObfuscation : function(scope) {
841             //assert scope != null;
842         
843         if (scope == this.globalScope) {
844             // The global scope does not get obfuscated,
845             // so we don't need to worry about it...
846             return;
847         }
848
849         // Find the highest local scope containing the specified scope.
850         while (scope && scope.parent != this.globalScope) {
851             scope = scope.parent;
852         }
853
854         //assert scope.getParentScope() == globalScope;
855         scope.preventMunging();
856     },
857     
858     getIdentifier: function(symbol, scope) {
859         var identifier;
860         while (scope != false) {
861             identifier = scope.getIdentifier(symbol);
862             //println("ScopeParser.getIdentgetUsedSymbols("+symbol+")=" + scope.getUsedSymbols().join(','));
863             if (identifier) {
864                 return identifier;
865             }
866             scope = scope.parent;
867         }
868         return false;
869     }
870 };