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