JSDOC/CompressWhite.js
[gnome.introspection-doc-generator] / JSDOC / ScopeParser.js
index 86789cd..717bbf5 100644 (file)
@@ -14,7 +14,7 @@ ScopeParser = function(ts) {
     this.scopes = [];
     this.indexedScopes = {};
     this.timer = new Date() * 1;
-   
+    this.debug = false;
 }
 
 // list of keywords that should not be used in object literals.
@@ -163,7 +163,7 @@ ScopeParser.prototype = {
         this.ts.rewind();
         this.braceNesting = 0;
         this.scopes= [];
-        this.mode = 'CHECKING_SYMBOL_TREE';
+        this.mode = 'PASS2_SYMBOL_TREE';
         
         //println("MUNGING?");
         
@@ -205,7 +205,7 @@ ScopeParser.prototype = {
         while (token) {
           //  this.timerPrint("parseScope AFTER lookT: " + token.toString()); 
              
-            print(token.type + '.' + token.name+ ":" + token.data);
+            !this.debug|| print(token.type + '.' + token.name+ ":" + token.data);
             switch(token.type + '.' + token.name) {
                 case "KEYW.VAR":
                 case "KEYW.CONST": // not really relivant as it's only mozzy that does this.
@@ -213,7 +213,7 @@ ScopeParser.prototype = {
                     //this.log("parseScope GOT VAR/CONST : " + token.toString()); 
                     while (true) {
                         token = this.ts.nextTok();
-                        print( token.toString());
+                        !this.debug|| print( token.toString());
                       
                         if (!token) { // can return false at EOF!
                             break;
@@ -241,7 +241,7 @@ ScopeParser.prototype = {
                         }
 
                         token = this.ts.nextTok();
-                         print(token.toString());
+                        !this.debug|| print(token.toString());
                         /*
                         assert token.getType() == Token.SEMI ||
                                 token.getType() == Token.ASSIGN ||
@@ -254,8 +254,8 @@ ScopeParser.prototype = {
                             this.parseExpression();
                             //this.logR("parseScope DONE  : <B>ParseExpression</B> - tok is:" + this.ts.lookT(0).toString()); 
                             
-                            token = this.ts.lookTok(0);
-                            print("AFTER EXP: " + token.toString());
+                            token = this.ts.lookTok(1);
+                            !this.debug|| print("AFTER EXP: " + token.toString());
                             if (token.data == ';') {
                                 break;
                             }
@@ -369,11 +369,11 @@ ScopeParser.prototype = {
                         break;
                     }
                     symbol = token.data;
-                     if (this.mode == 'CHECKING_SYMBOL_TREE') {
+                    if (this.mode == 'PASS2_SYMBOL_TREE') {
                         
                         //println("GOT IDENT: -2 : " + this.ts.lookT(-2).toString() + " <BR> ..... -1 :  " +  this.ts.lookT(-1).toString() + " <BR> "); 
                         
-                        
+                        //print ("MUNGE?" + symbol);
                         
                         //println("GOT IDENT: <B>" + symbol + "</B><BR/>");
                              
@@ -457,7 +457,7 @@ ScopeParser.prototype = {
         // in the same brace nesting, bracket nesting and paren nesting.
         // Parse functions if any...
         //println("<i>EXP</i><BR/>");
-        print("PARSE EXPR");
+        !this.debug || print("PARSE EXPR");
         var symbol;
         var token;
         var currentScope;
@@ -475,54 +475,54 @@ ScopeParser.prototype = {
             currentScope = this.scopes[this.scopes.length-1];
             
             //println("<i>"+token.data+"</i>");
-            
-            switch (token.data.toUpperCase()) {
-
-                case ';':
-                case ',':
-                    if (this.braceNesting == expressionBraceNesting &&
-                            bracketNesting == 0 &&
-                            parensNesting == 0) {
-                        
-                        return;
-                    }
-                    break;
+            !this.debug|| print ("EXP" + token.toString());
+            switch (token.type) {
+                case 'PUNC':
+                    switch(token.data) {
+                         
+                        case ';':
+                        case ',':
+                            if (this.braceNesting == expressionBraceNesting &&
+                                    bracketNesting == 0 &&
+                                    parensNesting == 0) {
+                                
+                                return;
+                            }
+                            break;
 
-                case 'FUNCTION':
-                    this.parseFunctionDeclaration();
-                    break;
+                       
 
-                case '{': //Token.LC:
-                    isObjectLitAr.push(false);
-                    
-                    this.braceNesting++;
-                    break;
+                        case '{': //Token.LC:
+                            isObjectLitAr.push(false);
+                            
+                            this.braceNesting++;
+                            break;
 
-                case '}': //Token.RC:
-                    this.braceNesting--;
-                    isObjectLitAr.pop();
-                    
-                   // assert braceNesting >= expressionBraceNesting;
-                    break;
+                        case '}': //Token.RC:
+                            this.braceNesting--;
+                            isObjectLitAr.pop();
+                            
+                           // assert braceNesting >= expressionBraceNesting;
+                            break;
 
-                case '[': //Token.LB:
-                    bracketNesting++;
-                    break;
+                        case '[': //Token.LB:
+                            bracketNesting++;
+                            break;
 
-                case ']': //Token.RB:
-                    bracketNesting--;
-                    break;
+                        case ']': //Token.RB:
+                            bracketNesting--;
+                            break;
 
-                case '(': //Token.LP:
-                    parensNesting++;
-                    break;
+                        case '(': //Token.LP:
+                            parensNesting++;
+                            break;
 
-                case ')': //Token.RP:
-                    parensNesting--;
+                        case ')': //Token.RP:
+                            parensNesting--;
+                            break;
+                    }
                     break;
-            }
-            switch(token.type) {
-                   
+                    
                 case 'STRN': // used for object lit detection..
                     if (this.ts.lookTok(-1).data == "{" && this.ts.lookTok(1).data == ":" ) {
                         // then we are in an object lit.. -> we need to flag the brace as such...
@@ -548,16 +548,8 @@ ScopeParser.prototype = {
                     
                     break;
                 
-                  
-                    
-                /*
-                case Token.SPECIALCOMMENT:
-                    if (mode == BUILDING_SYMBOL_TREE) {
-                        protectScopeFromObfuscation(currentScope);
-                        this.warn("Using JScript conditional comments is not recommended." + (munge ? " Moreover, using JScript conditional comments reduces the level of compression!" : ""), true);
-                    }
-                    break;
-                */
+                      
+             
                 case 'NAME':
                
                     symbol = token.data;
@@ -577,7 +569,7 @@ ScopeParser.prototype = {
                         break;
                     }
                     
-                     if (this.mode == 'CHECKING_SYMBOL_TREE') {
+                     if (this.mode == 'PASS2_SYMBOL_TREE') {
 
                         identifier = this.getIdentifier(symbol, currentScope);
                         //println("<B>??</B>");
@@ -608,7 +600,16 @@ ScopeParser.prototype = {
                     
                     
                     //println("<B>EID</B>");
-                 case 'KEYW':    
+                 case 'KEYW':   
+                 
+                    if (token.name == "FUNCTION") {
+                        
+                        this.parseFunctionDeclaration();
+                        break;
+                    }
+               
+                    
+             
                     symbol = token.data;
                     if (this.mode == 'BUILDING_SYMBOL_TREE') {
 
@@ -677,7 +678,7 @@ ScopeParser.prototype = {
     
     parseFunctionDeclaration : function() 
     {
-
+       // print("PARSE FUNCTION");
         var symbol;
         var token;
         var currentScope  = false; 
@@ -714,9 +715,9 @@ ScopeParser.prototype = {
         
         // Parse function arguments.
         var argpos = 0;
-        while (!this.ts.lookTok().data == ')') { //(token = consumeToken()).getType() != Token.RP) {
+        while (this.ts.lookTok().data != ')') { //(token = consumeToken()).getType() != Token.RP) {
             token = this.ts.nextTok();
-           
+           // print ("FUNC ARGS: " + token.toString())
             //assert token.getType() == Token.NAME ||
             //        token.getType() == Token.COMMA;
             if (token.type == 'NAME' && this.mode == 'BUILDING_SYMBOL_TREE') {