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