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