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