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