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 "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.braceNesting) {
286                         var ls = this.scopes.pop();
287                         ls.getUsedSymbols();
288                         print("<<<<<<<EXIT SCOPE" +this.scopes.length);
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         print("<<<<<<<EXIT SCOPE ERR?" +this.scopes.length);
459     },
460
461
462     parseExpression : function() {
463
464         // Parse the expression until we encounter a comma or a semi-colon
465         // in the same brace nesting, bracket nesting and paren nesting.
466         // Parse functions if any...
467         //println("<i>EXP</i><BR/>");
468         !this.debug || print("PARSE EXPR");
469         var symbol;
470         var token;
471         var currentScope;
472         var identifier;
473
474         var expressionBraceNesting = this.braceNesting;
475         var bracketNesting = 0;
476         var parensNesting = 0;
477         var isInObjectLitAr;
478         var isObjectLitAr = [ false ];
479         while (token = this.ts.lookTok()) {
480      
481
482             
483             currentScope = this.scopes[this.scopes.length-1];
484             
485             //println("<i>"+token.data+"</i>");
486             !this.debug|| print ("EXP" + token.toString());
487             switch (token.type) {
488                 case 'PUNC':
489                     switch(token.data) {
490                          
491                         case ';':
492                         case ',':
493                             if (this.braceNesting == expressionBraceNesting &&
494                                     bracketNesting == 0 &&
495                                     parensNesting == 0) {
496                                 
497                                 return;
498                             }
499                             break;
500
501                        
502
503                         case '{': //Token.LC:
504                             isObjectLitAr.push(false);
505                             print(">>>>> OBJ PUSH(false)");
506                             this.braceNesting++;
507                             break;
508
509                         case '}': //Token.RC:
510                             this.braceNesting--;
511                             isObjectLitAr.pop();
512                             print(">>>>> OBJ POP");    
513                            // assert braceNesting >= expressionBraceNesting;
514                             break;
515
516                         case '[': //Token.LB:
517                             bracketNesting++;
518                             break;
519
520                         case ']': //Token.RB:
521                             bracketNesting--;
522                             break;
523
524                         case '(': //Token.LP:
525                             parensNesting++;
526                             break;
527
528                         case ')': //Token.RP:
529                             parensNesting--;
530                             break;
531                     }
532                     break;
533                     
534                 case 'STRN': // used for object lit detection..
535                     if (this.ts.lookTok(-1).data == "{" && this.ts.lookTok(1).data == ":" ) {
536                         // then we are in an object lit.. -> we need to flag the brace as such...
537                         isObjectLitAr.pop();
538                         isObjectLitAr.push(true);
539                         print(">>>>> OBJ PUSH(true)");
540                     }
541                     
542                     
543                      
544                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
545                     if (isInObjectLitAr &&  this.ts.lookTok(1).data == ":"  &&
546                         ( this.ts.lookTok(-1).data == "{"  ||  this.ts.lookTok(-1).data == "," )) {
547                         // see if we can replace..
548                         // remove the quotes..
549                         var str = token.data.substring(1,token.data.length-1);
550                         if (/^[a-z_]+$/i.test(str) && ScopeParser.idents.indexOf(str) < 0) {
551                             token.outData = str;
552                         }
553                         
554                          
555                         
556                     }
557                     
558                     break;
559                 
560                       
561              
562                 case 'NAME':
563                
564                     symbol = token.data;
565                     if (this.ts.lookTok(-1).data == "{"  && this.ts.lookTok(1).data == ":") {
566                         // then we are in an object lit.. -> we need to flag the brace as such...
567                         isObjectLitAr.pop();
568                         isObjectLitAr.push(true);
569                          print(">>>>> OBJ PUSH(true)");
570                         break;
571                     }
572                     isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1];
573                     if (isInObjectLitAr && this.ts.lookTok(-1).data == "," && this.ts.lookTok(1).data == ":") {
574                         break;
575                     }
576                     
577                     if (this.ts.lookTok(-1).data == ".") {
578                         //skip '.'
579                         break;
580                     }
581                     
582                      if (this.mode == 'PASS2_SYMBOL_TREE') {
583
584                         identifier = this.getIdentifier(symbol, currentScope);
585                         //println("<B>??</B>");
586                         if (identifier == false) {
587
588                             if (symbol.length <= 3 &&  Scope.builtin.indexOf(symbol) < 0) {
589                                 // Here, we found an undeclared and un-namespaced symbol that is
590                                 // 3 characters or less in length. Declare it in the global scope.
591                                 // We don't need to declare longer symbols since they won't cause
592                                 // any conflict with other munged symbols.
593                                 this.globalScope.declareIdentifier(symbol, token);
594                                 this.warn("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')', true);
595                             } else {
596                                 //println("undeclared")
597                             }
598                             
599                             
600                         } else {
601                             //println("<B>++</B>");
602                             token.identifier = identifier;
603                             identifier.refcount++;
604                         }
605                         
606                     }
607                     break;
608                     
609                     
610                     
611                     
612                     //println("<B>EID</B>");
613                  case 'KEYW':   
614                  
615                     if (token.name == "FUNCTION") {
616                         
617                         this.parseFunctionDeclaration();
618                         break;
619                     }
620                
621                     
622              
623                     symbol = token.data;
624                     if (this.mode == 'BUILDING_SYMBOL_TREE') {
625
626                         if (symbol == "eval") {
627                             if (this.ts.look(-1).type == 'COMM') {
628                                 // look for eval:var:noreplace\n
629                                 var _t = this;
630                                 this.ts.look(-1).data.replace(/eval:var:([a-z]+)/ig, function(m, a) {
631                                     var hi = _t.getIdentifier(a, currentScope);
632                                    //println("PROTECT "+a+" from munge" + (hi ? "FOUND" : "MISSING"));
633                                     if (hi) {
634                                       //  println("PROTECT "+a+" from munge");
635                                         hi.toMunge = false;
636                                     }
637                                     
638                                     
639                                 });
640                                 
641                             } else {
642                                 this.protectScopeFromObfuscation(currentScope);
643                                 this.warn("Using 'eval' is not recommended." + (this.munge ? " Moreover, using 'eval' reduces the level of compression!" : ""), true);
644                             }
645                             
646
647                         }
648                         break;
649                     } 
650                    
651             }
652             if (!this.ts.nextTok()) break;
653         }
654     },
655
656
657     parseCatch : function() {
658
659         var symbol;
660         var token;
661         var currentScope;
662         var identifier;
663
664         //token = getToken(-1);
665         //assert token.getType() == Token.CATCH;
666         token = this.ts.nextTok();
667         //assert token.getType() == Token.LP; (
668         token = this.ts.nextTok();
669         //assert token.getType() == Token.NAME;
670         
671         symbol = token.data;
672         currentScope = this.scopes[this.scopes.length-1];
673
674         if (this.mode == 'BUILDING_SYMBOL_TREE') {
675             // We must declare the exception identifier in the containing function
676             // scope to avoid errors related to the obfuscation process. No need to
677             // display a warning if the symbol was already declared here...
678             currentScope.declareIdentifier(symbol, token);
679         } else {
680             //?? why inc the refcount?? - that should be set when building the tree???
681             identifier = this.getIdentifier(symbol, currentScope);
682             identifier.refcount++;
683         }
684
685         token = this.ts.nextTok();
686         //assert token.getType() == Token.RP; // )
687     },
688     
689     parseFunctionDeclaration : function() 
690     {
691        // print("PARSE FUNCTION");
692         var symbol;
693         var token;
694         var currentScope  = false; 
695         var fnScope = false;
696         var identifier;
697         //this.logR("<B>PARSING FUNCTION</B>");
698         currentScope = this.scopes[this.scopes.length-1];
699
700         token = this.ts.nextTok();
701         if (token.type == "NAME") {
702             if (this.mode == 'BUILDING_SYMBOL_TREE') {
703                 // Get the name of the function and declare it in the current scope.
704                 symbol = token.data;
705                 if (currentScope.getIdentifier(symbol) != false) {
706                     this.warn("The function " + symbol + " has already been declared in the same scope...", true);
707                 }
708                 currentScope.declareIdentifier(symbol,token);
709             }
710             token =  this.ts.nextTok();
711         }
712
713         //assert token.getType() == Token.LP;
714         if (this.mode == 'BUILDING_SYMBOL_TREE') {
715             fnScope = new Scope(this.braceNesting, currentScope, token.n, '');
716             
717             //println("STORING SCOPE" + this.ts.cursor);
718             
719             this.indexedScopes[this.ts.cursor] = fnScope;
720             
721         } else {
722             //println("FETCHING SCOPE" + this.ts.cursor);
723             fnScope = this.indexedScopes[this.ts.cursor];
724           
725         }
726         
727         // Parse function arguments.
728         var argpos = 0;
729         while (this.ts.lookTok().data != ')') { //(token = consumeToken()).getType() != Token.RP) {
730             token = this.ts.nextTok();
731            // print ("FUNC ARGS: " + token.toString())
732             //assert token.getType() == Token.NAME ||
733             //        token.getType() == Token.COMMA;
734             if (token.type == 'NAME' && this.mode == 'BUILDING_SYMBOL_TREE') {
735                 symbol = token.data;
736                 identifier = fnScope.declareIdentifier(symbol,token);
737                 if (symbol == "$super" && argpos == 0) {
738                     // Exception for Prototype 1.6...
739                     identifier.preventMunging();
740                 }
741                 argpos++;
742             }
743         }
744
745         token = this.ts.nextTok();
746         // assert token.getType() == Token.LC;
747         this.braceNesting++;
748
749         token = this.ts.nextTok();
750         if (token.type == "STRN" && this.ts.lookTok(1).data == ';') {
751             /*
752             
753             NOT SUPPORTED YET!?!!?!
754             
755             // This is a hint. Hints are empty statements that look like
756             // "localvar1:nomunge, localvar2:nomunge"; They allow developers
757             // to prevent specific symbols from getting obfuscated (some heretic
758             // implementations, such as Prototype 1.6, require specific variable
759             // names, such as $super for example, in order to work appropriately.
760             // Note: right now, only "nomunge" is supported in the right hand side
761             // of a hint. However, in the future, the right hand side may contain
762             // other values.
763             consumeToken();
764             String hints = token.getValue();
765             // Remove the leading and trailing quotes...
766             hints = hints.substring(1, hints.length() - 1).trim();
767             StringTokenizer st1 = new StringTokenizer(hints, ",");
768             while (st1.hasMoreTokens()) {
769                 String hint = st1.nextToken();
770                 int idx = hint.indexOf(':');
771                 if (idx <= 0 || idx >= hint.length() - 1) {
772                     if (mode == BUILDING_SYMBOL_TREE) {
773                         // No need to report the error twice, hence the test...
774                         this.warn("Invalid hint syntax: " + hint, true);
775                     }
776                     break;
777                 }
778                 String variableName = hint.substring(0, idx).trim();
779                 String variableType = hint.substring(idx + 1).trim();
780                 if (mode == BUILDING_SYMBOL_TREE) {
781                     fnScope.addHint(variableName, variableType);
782                 } else if (mode == CHECKING_SYMBOL_TREE) {
783                     identifier = fnScope.getIdentifier(variableName);
784                     if (identifier != null) {
785                         if (variableType.equals("nomunge")) {
786                             identifier.preventMunging();
787                         } else {
788                             this.warn("Unsupported hint value: " + hint, true);
789                         }
790                     } else {
791                         this.warn("Hint refers to an unknown identifier: " + hint, true);
792                     }
793                 }
794             }
795             */
796         }
797
798         this.parseScope(fnScope);
799         // now pop it off the stack!!!
800        
801         
802         
803     },
804     
805     protectScopeFromObfuscation : function(scope) {
806             //assert scope != null;
807         
808         if (scope == this.globalScope) {
809             // The global scope does not get obfuscated,
810             // so we don't need to worry about it...
811             return;
812         }
813
814         // Find the highest local scope containing the specified scope.
815         while (scope && scope.parent != this.globalScope) {
816             scope = scope.parent;
817         }
818
819         //assert scope.getParentScope() == globalScope;
820         scope.preventMunging();
821     },
822     
823     getIdentifier: function(symbol, scope) {
824         var identifier;
825         while (scope != false) {
826             identifier = scope.getIdentifier(symbol);
827             //println("ScopeParser.getIdentgetUsedSymbols("+symbol+")=" + scope.getUsedSymbols().join(','));
828             if (identifier) {
829                 return identifier;
830             }
831             scope = scope.parent;
832         }
833         return false;
834     }
835 };