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