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