57df9120611513cddbc2ce6cfcd835be95d675b4
[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         token = this.ts.lookTok(1);
212         while (token) {
213           //  this.timerPrint("parseScope AFTER lookT: " + token.toString()); 
214              
215             //this.log(token.data);
216             if (token.type == 'NAME') {
217             //    print('*' + token.data);
218             }
219             switch(token.type + '.' + token.name) {
220                 case "KEYW.VAR":
221                 case "KEYW.CONST": // not really relivant as it's only mozzy that does this.
222                     
223                     //this.log("parseScope GOT VAR/CONST : " + token.toString()); 
224                     while (true) {
225                         token = this.ts.nextTok();
226                         !this.debug|| print( token.toString());
227                       
228                         if (!token) { // can return false at EOF!
229                             break;
230                         }
231                         if (token.name == "VAR") { // kludge..
232                             continue;
233                         }
234                         //this.logR("parseScope GOT VAR  : <B>" + token.toString() + "</B>"); 
235                         if (token.type !="NAME") {
236                             print(token.toString());
237                             print( "var without ident");
238                             Seed.quit()
239                         }
240                         
241
242                         if (this.mode == "BUILDING_SYMBOL_TREE") {
243                             identifier = scope.getIdentifier(token.data) ;
244                             
245                             if (identifier == false) {
246                                 scope.declareIdentifier(token.data, token);
247                             } else {
248                                 token.identifier = identifier;
249                                 this.warn("(SCOPE) The variable " + token.data  + ' (line:' + token.line + ")  has already been declared in the same scope...");
250                             }
251                         }
252
253                         token = this.ts.nextTok();
254                         !this.debug|| print(token.toString());
255                         /*
256                         assert token.getType() == Token.SEMI ||
257                                 token.getType() == Token.ASSIGN ||
258                                 token.getType() == Token.COMMA ||
259                                 token.getType() == Token.IN;
260                         */
261                         if (token.name == "IN") {
262                             break;
263                         } else {
264                             //var bn = this.braceNesting;
265                             this.parseExpression();
266                             //this.braceNesting = bn;
267                             //this.logR("parseScope DONE  : <B>ParseExpression</B> - tok is:" + this.ts.lookT(0).toString()); 
268                             
269                             token = this.ts.lookTok(1);
270                             !this.debug|| print("AFTER EXP: " + token.toString());
271                             if (token.data == ';') {
272                                 break;
273                             }
274                         }
275                     }
276                     break;
277                 case "KEYW.FUNCTION":
278                     //println("<i>"+token.data+"</i>");
279                      var bn = this.braceNesting;
280                     this.parseFunctionDeclaration();
281                      this.braceNesting = bn;
282                     break;
283
284                 case "PUNC.LEFT_CURLY": // {
285                     //println("<i>"+token.data+"</i>");
286                     isObjectLitAr.push(false);
287                     this.braceNesting++;
288                     
289                     //print(">>>>>> OBJLIT PUSH(false)" + this.braceNesting);
290                     break;
291
292                 case "PUNC.RIGHT_CURLY": // }
293                     //println("<i>"+token.data+"</i>");
294                     this.braceNesting--;
295                     isObjectLitAr.pop();
296                     //print(">>>>>> OBJLIT POP"+ this.braceNesting);
297                         //assert braceNesting >= scope.getBra ceNesting();
298                     
299                     if (this.braceNesting < expressionBraceNesting) {
300                         var ls = this.scopes.pop();
301                         ls.getUsedSymbols();
302                         // eat symbol if we are currently at { 
303                         if (this.ts.look(0).data == '{') {
304                             this.ts.nextTok();
305                         }
306                         
307                         //print("<<<<<<<EXIT SCOPE" +this.scopes.length);
308                         return;
309                     }
310                     break;
311
312                 case "KEYW.WITH":
313                     //println("<i>"+token.data+"</i>");   
314                     if (this.mode == "BUILDING_SYMBOL_TREE") {
315                         // Inside a 'with' block, it is impossible to figure out
316                         // statically whether a symbol is a local variable or an
317                         // object member. As a consequence, the only thing we can
318                         // do is turn the obfuscation off for the highest scope
319                         // containing the 'with' block.
320                         this.protectScopeFromObfuscation(scope);
321                         this.warn("Using 'with' is not recommended." + (this.munge ? " Moreover, using 'with' reduces the level of compression!" : ""), true);
322                     }
323                     break;
324
325                 case "KEYW.CATCH":
326                     //println("<i>"+token.data+"</i>");
327                     this.parseCatch();
328                     break;
329                 /*
330                 case Token.SPECIALCOMMENT:
331                         if (mode == BUILDING_SYMBOL_TREE) {
332                             protectScopeFromObfuscation(scope);
333                             this.warn("Using JScript conditional comments is not recommended." + (munge ? " Moreover, using JScript conditional comments reduces the level of compression." : ""), true);
334                         }
335                         break;
336                 */
337                 
338                 case "STRN.DOUBLE_QUOTE": // used for object lit detection..
339                 case "STRN.SINGLE_QUOTE":
340                     //println("<i>"+token.data+"</i>");
341                     if (this.ts.lookTok(-1).data == '{' && this.ts.lookTok(1).data == ':') {
342                         // then we are in an object lit.. -> we need to flag the brace as such...
343                         isObjectLitAr.pop();
344                         isObjectLitAr.push(true);
345                         //print(">>>>>> OBJLIT REPUSH(true)");
346                     }
347                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
348                     
349                     if (isInObjectLitAr &&  this.ts.lookTok(1).data == ':' &&
350                         ( this.ts.lookTok(-1).data == '{'  ||  this.ts.lookTok(-1).data == ':' )) {
351                         // see if we can replace..
352                         // remove the quotes..
353                         // should do a bit more checking!!!! (what about wierd char's in the string..
354                         var str = token.data.substring(1,token.data.length-1);
355                         if (/^[a-z_]+$/i.test(str) && ScopeParser.idents.indexOf(str) < 0) {
356                             token.outData = str;
357                         }
358                         
359                          
360                         
361                     }
362                     
363                     
364                     
365                     break;
366                 
367                 case "NAME.NAME":
368                 
369                     //print("DEAL WITH NAME:");
370                     // got identifier..
371                     
372                     // look for  { ** : <- indicates obj literal.. ** this could occur with numbers ..
373                     if ((this.ts.lookTok(-1).data == "{") && (this.ts.lookTok(1).data == ":")) {
374                         isObjectLitAr.pop();
375                         isObjectLitAr.push(true);
376                         //print(">>>>>> OBJLIT REPUSH(true)");
377                         //println("<i>"+token.data+"</i>");
378                         break;
379                     }
380                    // print("DEAL WITH obj lit:");
381                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
382                     
383                     if (isInObjectLitAr && (this.ts.lookTok(1).data == ":") && (this.ts.lookTok(-1).data == ",")) {
384                         // skip, it's an object lit key..
385                         //println("<i>"+token.data+"</i>");
386                         break;
387                     }
388                     
389                     
390                     // skip anyting with "." before it..!!
391                      
392                     if (this.ts.lookTok(-1).data == ".") {
393                         // skip, it's an object prop.
394                         //println("<i>"+token.data+"</i>");
395                         break;
396                     }
397                     symbol = token.data;
398                     if (this.mode == 'PASS2_SYMBOL_TREE') {
399                         
400                         //println("GOT IDENT: -2 : " + this.ts.lookT(-2).toString() + " <BR> ..... -1 :  " +  this.ts.lookT(-1).toString() + " <BR> "); 
401                         
402                         //print ("MUNGE?" + symbol);
403                         
404                         //println("GOT IDENT: <B>" + symbol + "</B><BR/>");
405                              
406                             //println("GOT IDENT (2): <B>" + symbol + "</B><BR/>");
407                         identifier = this.getIdentifier(symbol, scope);
408                         
409                         if (identifier == false) {
410 // BUG!find out where builtin is defined...
411                             if (symbol.length <= 3 &&  Scope.builtin.indexOf(symbol) < 0) {
412                                 // Here, we found an undeclared and un-namespaced symbol that is
413                                 // 3 characters or less in length. Declare it in the global scope.
414                                 // We don't need to declare longer symbols since they won't cause
415                                 // any conflict with other munged symbols.
416                                 this.globalScope.declareIdentifier(symbol, token);
417                                 this.warn("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')', true);
418                             }
419                             
420                             //println("GOT IDENT IGNORE(3): <B>" + symbol + "</B><BR/>");
421                         } else {
422                             token.identifier = identifier;
423                             identifier.refcount++;
424                         }
425                     }   
426                     
427                     break;
428                     //println("<B>SID</B>");
429                 default:
430                     if (token.type != 'KEYW') {
431                         break;
432                     }
433                    // print("Check eval:");
434                 
435                     symbol = token.data;
436                     
437                      if (this.mode == 'BUILDING_SYMBOL_TREE') {
438
439                         if (symbol == "eval") {
440                             // look back one and see if we can find a comment!!!
441                             if (this.ts.look(-1).type == "COMM") {
442                                 // look for eval:var:noreplace\n
443                                 var _t = this;
444                                 this.ts.look(-1).data.replace(/eval:var:([a-z_]+)/ig, function(m, a) {
445                                     
446                                     var hi = _t.getIdentifier(a, scope);
447                                    // println("PROTECT "+a+" from munge" + (hi ? "FOUND" : "MISSING"));
448                                     if (hi) {
449                                      //   println("PROTECT "+a+" from munge");
450                                         hi.toMunge = false;
451                                     }
452                                     
453                                 });
454                                 
455                                 
456                             } else {
457                                 
458                             
459                                 this.protectScopeFromObfuscation(scope);
460                                 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);
461                             }
462
463                         }
464
465                     }
466                     break;
467                 
468                 
469             } // end switch
470             
471             
472             //this.timerPrint("parseScope TOK : " + token.toString()); 
473             token = this.ts.nextTok();
474             //if (this.ts.nextT()) break;
475             
476         }
477         //print("<<<<<<<EXIT SCOPE ERR?" +this.scopes.length);
478     },
479
480
481     parseExpression : function() {
482
483         // Parse the expression until we encounter a comma or a semi-colon
484         // in the same brace nesting, bracket nesting and paren nesting.
485         // Parse functions if any...
486         //println("<i>EXP</i><BR/>");
487         !this.debug || print("PARSE EXPR");
488         var symbol;
489         var token;
490         var currentScope;
491         var identifier;
492
493         var expressionBraceNesting = this.braceNesting;
494         var bracketNesting = 0;
495         var parensNesting = 0;
496         var isInObjectLitAr;
497         var isObjectLitAr = [ false ];
498         while (token = this.ts.lookTok()) {
499      
500
501             
502             currentScope = this.scopes[this.scopes.length-1];
503             
504             //println("<i>"+token.data+"</i>");
505             //this.log("EXP:" + token.data);
506             switch (token.type) {
507                 case 'PUNC':
508                     switch(token.data) {
509                          
510                         case ';':
511                         case ',':
512                             if (this.braceNesting == expressionBraceNesting &&
513                                     bracketNesting == 0 &&
514                                     parensNesting == 0) {
515                                 
516                                 return;
517                             }
518                             break;
519
520                        
521
522                         case '{': //Token.LC:
523                             isObjectLitAr.push(false);
524                             
525                             this.braceNesting++;
526                             ///print(">>>>> EXP PUSH(false)"+this.braceNesting);
527                             break;
528
529                         case '}': //Token.RC:
530                             this.braceNesting--;
531                             isObjectLitAr.pop();
532                             //print(">>>>> EXP POP" + this.braceNesting);    
533                            // assert braceNesting >= expressionBraceNesting;
534                             break;
535
536                         case '[': //Token.LB:
537                             bracketNesting++;
538                             break;
539
540                         case ']': //Token.RB:
541                             bracketNesting--;
542                             break;
543
544                         case '(': //Token.LP:
545                             parensNesting++;
546                             break;
547
548                         case ')': //Token.RP:
549                             parensNesting--;
550                             break;
551                     }
552                     break;
553                     
554                 case 'STRN': // used for object lit detection..
555                     if (this.ts.lookTok(-1).data == "{" && this.ts.lookTok(1).data == ":" ) {
556                         // then we are in an object lit.. -> we need to flag the brace as such...
557                         isObjectLitAr.pop();
558                         isObjectLitAr.push(true);
559                         //print(">>>>> EXP PUSH(true)");
560                     }
561                     
562                     
563                      
564                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
565                     if (isInObjectLitAr &&  this.ts.lookTok(1).data == ":"  &&
566                         ( this.ts.lookTok(-1).data == "{"  ||  this.ts.lookTok(-1).data == "," )) {
567                         // see if we can replace..
568                         // remove the quotes..
569                         var str = token.data.substring(1,token.data.length-1);
570                         if (/^[a-z_]+$/i.test(str) && ScopeParser.idents.indexOf(str) < 0) {
571                             token.outData = str;
572                         }
573                         
574                          
575                         
576                     }
577                     
578                     break;
579                 
580                       
581              
582                 case 'NAME':
583                
584                     symbol = token.data;
585                   
586                     if (this.ts.look(0).data == "{"  && this.ts.lookTok(2).data == ":") {
587                         // then we are in an object lit.. -> we need to flag the brace as such...
588                         isObjectLitAr.pop();
589                         isObjectLitAr.push(true);
590                          //print(">>>>> EXP  PUSH(true)");
591                         break;
592                     }
593                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
594                     if (isInObjectLitAr && this.ts.lookTok(0).data == "," && this.ts.lookTok(2).data == ":") {
595                         break;
596                     }
597                     //print(this.ts.lookTok(0).data);
598                     if (this.ts.lookTok(0).data == ".") {
599                         //skip '.'
600                         break;
601                     }
602                     
603                      if (this.mode == 'PASS2_SYMBOL_TREE') {
604
605                         identifier = this.getIdentifier(symbol, currentScope);
606                         //println("<B>??</B>");
607                         if (identifier == false) {
608
609                             if (symbol.length <= 3 &&  Scope.builtin.indexOf(symbol) < 0) {
610                                 // Here, we found an undeclared and un-namespaced symbol that is
611                                 // 3 characters or less in length. Declare it in the global scope.
612                                 // We don't need to declare longer symbols since they won't cause
613                                 // any conflict with other munged symbols.
614                                 this.globalScope.declareIdentifier(symbol, token);
615                                 this.warn("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')', true);
616                             } else {
617                                 //println("undeclared")
618                             }
619                             
620                             
621                         } else {
622                             //println("<B>++</B>");
623                             token.identifier = identifier;
624                             identifier.refcount++;
625                         }
626                         
627                     }
628                     break;
629                     
630                     
631                     
632                     
633                     //println("<B>EID</B>");
634                  case 'KEYW':   
635                  
636                     if (token.name == "FUNCTION") {
637                         
638                         this.parseFunctionDeclaration();
639                         break;
640                     }
641                
642                     
643              
644                     symbol = token.data;
645                     if (this.mode == 'BUILDING_SYMBOL_TREE') {
646
647                         if (symbol == "eval") {
648                             if (this.ts.look(-1).type == 'COMM') {
649                                 // look for eval:var:noreplace\n
650                                 var _t = this;
651                                 this.ts.look(-1).data.replace(/eval:var:([a-z]+)/ig, function(m, a) {
652                                     var hi = _t.getIdentifier(a, currentScope);
653                                    //println("PROTECT "+a+" from munge" + (hi ? "FOUND" : "MISSING"));
654                                     if (hi) {
655                                       //  println("PROTECT "+a+" from munge");
656                                         hi.toMunge = false;
657                                     }
658                                     
659                                     
660                                 });
661                                 
662                             } else {
663                                 this.protectScopeFromObfuscation(currentScope);
664                                 this.warn("Using 'eval' is not recommended." + (this.munge ? " Moreover, using 'eval' reduces the level of compression!" : ""), true);
665                             }
666                             
667
668                         }
669                         break;
670                     } 
671                    
672             }
673             if (!this.ts.nextTok()) break;
674         }
675     },
676
677
678     parseCatch : function() {
679
680         var symbol;
681         var token;
682         var currentScope;
683         var identifier;
684
685         //token = getToken(-1);
686         //assert token.getType() == Token.CATCH;
687         token = this.ts.nextTok();
688         //assert token.getType() == Token.LP; (
689         token = this.ts.nextTok();
690         //assert token.getType() == Token.NAME;
691         
692         symbol = token.data;
693         currentScope = this.scopes[this.scopes.length-1];
694
695         if (this.mode == 'BUILDING_SYMBOL_TREE') {
696             // We must declare the exception identifier in the containing function
697             // scope to avoid errors related to the obfuscation process. No need to
698             // display a warning if the symbol was already declared here...
699             currentScope.declareIdentifier(symbol, token);
700         } else {
701             //?? why inc the refcount?? - that should be set when building the tree???
702             identifier = this.getIdentifier(symbol, currentScope);
703             identifier.refcount++;
704         }
705
706         token = this.ts.nextTok();
707         //assert token.getType() == Token.RP; // )
708     },
709     
710     parseFunctionDeclaration : function() 
711     {
712        // print("PARSE FUNCTION");
713         var symbol;
714         var token;
715         var currentScope  = false; 
716         var fnScope = false;
717         var identifier;
718         //this.logR("<B>PARSING FUNCTION</B>");
719         currentScope = this.scopes[this.scopes.length-1];
720
721         token = this.ts.nextTok();
722         if (token.type == "NAME") {
723             if (this.mode == 'BUILDING_SYMBOL_TREE') {
724                 // Get the name of the function and declare it in the current scope.
725                 symbol = token.data;
726                 if (currentScope.getIdentifier(symbol) != false) {
727                     this.warn("The function " + symbol + " has already been declared in the same scope...", true);
728                 }
729                 currentScope.declareIdentifier(symbol,token);
730             }
731             token =  this.ts.nextTok();
732         }
733
734         //assert token.getType() == Token.LP;
735         if (this.mode == 'BUILDING_SYMBOL_TREE') {
736             fnScope = new Scope(this.braceNesting, currentScope, token.n, '');
737             
738             //println("STORING SCOPE" + this.ts.cursor);
739             
740             this.indexedScopes[this.ts.cursor] = fnScope;
741             
742         } else {
743             //qln("FETCHING SCOPE" + this.ts.cursor);
744             fnScope = this.indexedScopes[this.ts.cursor];
745           
746         }
747         
748         // Parse function arguments.
749         var argpos = 0;
750         while (this.ts.lookTok().data != ')') { //(token = consumeToken()).getType() != Token.RP) {
751             token = this.ts.nextTok();
752            // print ("FUNC ARGS: " + token.toString())
753             //assert token.getType() == Token.NAME ||
754             //        token.getType() == Token.COMMA;
755             if (token.type == 'NAME' && this.mode == 'BUILDING_SYMBOL_TREE') {
756                 symbol = token.data;
757                 identifier = fnScope.declareIdentifier(symbol,token);
758                 if (symbol == "$super" && argpos == 0) {
759                     // Exception for Prototype 1.6...
760                     identifier.preventMunging();
761                 }
762                 argpos++;
763             }
764         }
765
766         token = this.ts.nextTok();
767         // assert token.getType() == Token.LC;
768         this.braceNesting++;
769
770         token = this.ts.nextTok();
771         if (token.type == "STRN" && this.ts.lookTok(1).data == ';') {
772             /*
773             
774             NOT SUPPORTED YET!?!!?!
775             
776             // This is a hint. Hints are empty statements that look like
777             // "localvar1:nomunge, localvar2:nomunge"; They allow developers
778             // to prevent specific symbols from getting obfuscated (some heretic
779             // implementations, such as Prototype 1.6, require specific variable
780             // names, such as $super for example, in order to work appropriately.
781             // Note: right now, only "nomunge" is supported in the right hand side
782             // of a hint. However, in the future, the right hand side may contain
783             // other values.
784             consumeToken();
785             String hints = token.getValue();
786             // Remove the leading and trailing quotes...
787             hints = hints.substring(1, hints.length() - 1).trim();
788             StringTokenizer st1 = new StringTokenizer(hints, ",");
789             while (st1.hasMoreTokens()) {
790                 String hint = st1.nextToken();
791                 int idx = hint.indexOf(':');
792                 if (idx <= 0 || idx >= hint.length() - 1) {
793                     if (mode == BUILDING_SYMBOL_TREE) {
794                         // No need to report the error twice, hence the test...
795                         this.warn("Invalid hint syntax: " + hint, true);
796                     }
797                     break;
798                 }
799                 String variableName = hint.substring(0, idx).trim();
800                 String variableType = hint.substring(idx + 1).trim();
801                 if (mode == BUILDING_SYMBOL_TREE) {
802                     fnScope.addHint(variableName, variableType);
803                 } else if (mode == CHECKING_SYMBOL_TREE) {
804                     identifier = fnScope.getIdentifier(variableName);
805                     if (identifier != null) {
806                         if (variableType.equals("nomunge")) {
807                             identifier.preventMunging();
808                         } else {
809                             this.warn("Unsupported hint value: " + hint, true);
810                         }
811                     } else {
812                         this.warn("Hint refers to an unknown identifier: " + hint, true);
813                     }
814                 }
815             }
816             */
817         }
818
819         this.parseScope(fnScope);
820         // now pop it off the stack!!!
821        
822         
823         
824     },
825     
826     protectScopeFromObfuscation : function(scope) {
827             //assert scope != null;
828         
829         if (scope == this.globalScope) {
830             // The global scope does not get obfuscated,
831             // so we don't need to worry about it...
832             return;
833         }
834
835         // Find the highest local scope containing the specified scope.
836         while (scope && scope.parent != this.globalScope) {
837             scope = scope.parent;
838         }
839
840         //assert scope.getParentScope() == globalScope;
841         scope.preventMunging();
842     },
843     
844     getIdentifier: function(symbol, scope) {
845         var identifier;
846         while (scope != false) {
847             identifier = scope.getIdentifier(symbol);
848             //println("ScopeParser.getIdentgetUsedSymbols("+symbol+")=" + scope.getUsedSymbols().join(','));
849             if (identifier) {
850                 return identifier;
851             }
852             scope = scope.parent;
853         }
854         return false;
855     }
856 };