JSDOC/ScopeParser.vala
[gnome.introspection-doc-generator] / JSDOC / ScopeParser.vala
index 68ea187..73072b3 100644 (file)
@@ -647,7 +647,7 @@ namespace JSDOC {
                                        }
                                        // key value..
                                        
-                                       this.ts = new TokenStream(token.props[prop].val);
+                                       this.ts = new TokenStream(val.vals);
                                        this.parseExpression(scope);
                                        
                                    }
@@ -659,11 +659,12 @@ namespace JSDOC {
                                }
                                
                                
-                               var _this = this;
-                               token.items.forEach(function(expr) {
-                                     _this.ts = new TokenStream(expr);
-                                     _this.parseExpression(scope)
-                               });
+                               foreach(var expr in token.items) {
+                                     this.ts = new TokenStream(expr);
+                                     this.parseExpression(scope);
+                               }
                                this.ts = curTS;
                            
                            
@@ -675,9 +676,9 @@ namespace JSDOC {
                            
                             
                                
-                           case ')': //Token.RP:
-                           case ']': //Token.RB:
-                           case '}': //Token.RB:
+                           case ")": //Token.RP:
+                           case "]": //Token.RB:
+                           case "}": //Token.RB:
                                //print("<< EXIT EXPRESSION");
                                return;
                               
@@ -691,7 +692,7 @@ namespace JSDOC {
                        }
                        break;
                        
-                   case 'STRN': // used for object lit detection..
+                   case "STRN": // used for object lit detection..
                        //if (this.mode == 'BUILDING_SYMBOL_TREE')    
                            //print("EXPR-STR:" + JSON.stringify(token, null, 4));
                   
@@ -700,14 +701,14 @@ namespace JSDOC {
                    
                          
                 
-                   case 'NAME':
-                       if (this.mode == 'BUILDING_SYMBOL_TREE') {
+                   case "NAME":
+                       if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
                            
                            //print("EXPR-NAME:" + JSON.stringify(token, null, 4));
                        } else {
                            //print("EXPR-NAME:" + token.toString());
                        }
-                       symbol = token.data;
+                       var symbol = token.data;
                        //print("in NAME = " + token.toString());
                        //print("in NAME 0: " + this.ts.look(0).toString());
                        //print("in NAME 2: " + this.ts.lookTok(2).toString());
@@ -718,13 +719,13 @@ namespace JSDOC {
                            //skip '.'
                            break;
                        }
-                       if (symbol == 'this') {
+                       if (symbol == "this") {
                            break;
-                          }
+                   }
                        
-                       if (this.mode == 'PASS2_SYMBOL_TREE') {
+                       if (this.mode == ScopeParserMode.PASS2_SYMBOL_TREE) {
 
-                           identifier = this.getIdentifier(symbol, scope, token);
+                           var identifier = this.getIdentifier(symbol, scope, token);
                            //println("<B>??</B>");
                            if (identifier == false) {
 
@@ -734,7 +735,7 @@ namespace JSDOC {
                                    // We don't need to declare longer symbols since they won't cause
                                    // any conflict with other munged symbols.
                                    this.globalScope.declareIdentifier(symbol, token);
-                                   this.warn("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')', true);
+                                   this.warn("Found an undeclared symbol: " + symbol + " (line:" + token.line + ")", true);
                                    //print("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')');
                                    //throw "OOPS";
                                } else {
@@ -755,7 +756,7 @@ namespace JSDOC {
                        
                        
                        //println("<B>EID</B>");
-                   case 'KEYW':   
+                   case "KEYW":   
                        //if (this.mode == 'BUILDING_SYMBOL_TREE') 
                        //    print("EXPR-KEYW:" + JSON.stringify(token, null, 4));
                        
@@ -767,8 +768,8 @@ namespace JSDOC {
                        }
                   
                         
-                       symbol = token.data;
-                       if (this.mode == 'BUILDING_SYMBOL_TREE') {
+                       var symbol = token.data;
+                       if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
                            
                            if (token.name == "EVAL") {
                                //print(JSON.stringify(token,null,4));
@@ -809,19 +810,15 @@ namespace JSDOC {
            }
            //print("<< EXIT EXPRESSION");
            this.expN--;
-       },
+       }
 
 
-       parseCatch : function(scope) {
+       void parseCatch(scope) {
 
-           var symbol;
-           var token;
-            
-           var identifier;
            
            //token = getToken(-1);
            //assert token.getType() == Token.CATCH;
-           token = this.ts.nextTok(1);
+           var token = this.ts.nextTok(1);
            token = this.ts.nextTok(1);
            
            
@@ -830,40 +827,38 @@ namespace JSDOC {
            //token = this.ts.nextTok();
            //assert token.getType() == Token.NAME;
            
-           symbol = token.items[0][0].data;
+           var symbol = token.items[0][0].data;
            
 
-           if (this.mode == 'BUILDING_SYMBOL_TREE') {
+           if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
                // We must declare the exception identifier in the containing function
                // scope to avoid errors related to the obfuscation process. No need to
                // display a warning if the symbol was already declared here...
                scope.declareIdentifier(symbol, token.items[0][0]);
            } else {
                //?? why inc the refcount?? - that should be set when building the tree???
-               identifier = this.getIdentifier(symbol, scope, token.items[0][0]);
+               var identifier = this.getIdentifier(symbol, scope, token.items[0][0]);
                identifier.refcount++;
            }
            
            //token = this.ts.nextTok();
            //assert token.getType() == Token.RP; // )
-       },
+       }
        
-       parseFunctionDeclaration : function(scope) 
+       void parseFunctionDeclaration (Scope scope) 
        {
            //print("PARSE FUNCTION");
-           var symbol;
-           var token;
            
            var fnScope = false;
-           var identifier;
+           
            var b4braceNesting = this.braceNesting + 0;
            
            //this.logR("<B>PARSING FUNCTION</B>");
            
 
-           token = this.ts.nextTok();
+           var token = this.ts.nextTok();
            if (token.type == "NAME") {
-               if (this.mode == 'BUILDING_SYMBOL_TREE') {
+               if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
                    // Get the name of the function and declare it in the current scope.
                    symbol = token.data;
                    if (scope.getIdentifier(symbol,token) != false) {
@@ -882,9 +877,9 @@ namespace JSDOC {
                 
            }
            
-           
+           Scope fnScope;
            //assert token.getType() == Token.LP;
-           if (this.mode == 'BUILDING_SYMBOL_TREE') {
+           if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
                fnScope = new Scope(1, scope, token.n, '', token);
                
                //println("STORING SCOPE" + this.ts.cursor);
@@ -899,15 +894,15 @@ namespace JSDOC {
            //  print('FUNC-PARSE:' + JSON.stringify(token,null,4));
            // Parse function arguments.
            var args = token.items;
-           for (var argpos =0; argpos < args.length; argpos++) {
+           for (var argpos =0; argpos < args.size; argpos++) {
                 
-               token = args[argpos][0];
+               token = args.get(argpos).get(0);
                //print ("FUNC ARGS: " + token.toString())
                //assert token.getType() == Token.NAME ||
                //        token.getType() == Token.COMMA;
-               if (token.type == 'NAME' && this.mode == 'BUILDING_SYMBOL_TREE') {
-                   symbol = token.data;
-                   identifier = fnScope.declareIdentifier(symbol,token);
+               if (token.type == "NAME" && this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
+                   var symbol = token.data;
+                   var identifier = fnScope.declareIdentifier(symbol,token);
                    if (symbol == "$super" && argpos == 0) {
                        // Exception for Prototype 1.6...
                        identifier.preventMunging();
@@ -926,11 +921,9 @@ namespace JSDOC {
            //token = this.ts.nextTok();
            //print(token.toString());
            var outTS = this.ts;
-           var _this = this;
-           token.items.forEach(function(tar) {
-               _this.ts = new TokenStream(tar);
-               _this.parseScope(fnScope);
-               
+               foreach(var tar in token.items) {
+               this.ts = new TokenStream(tar);
+               this.parseScope(fnScope);
                
            });
            
@@ -943,9 +936,9 @@ namespace JSDOC {
            //print("ENDFN -1: " + this.ts.lookTok(-1).toString());
            //print("ENDFN 0: " + this.ts.lookTok(0).toString());
            //print("ENDFN 1: " + this.ts.lookTok(1).toString());
-       },
+       }
        
-       protectScopeFromObfuscation : function(scope) {
+       void protectScopeFromObfuscation (scope) {
                //assert scope != null;
            
            if (scope == this.globalScope) {
@@ -963,16 +956,18 @@ namespace JSDOC {
            scope.preventMunging();
        },
        
-       getIdentifier: function(symbol, scope, token) {
-           var identifier;
-           while (scope != false) {
+       string getIdentifier(string symbol, Scope in_scope, Token token) 
+       {
+           string identifier;
+           var scope in_scope;
+           while (scope != null) {
                identifier = scope.getIdentifier(symbol, token);
                //println("ScopeParser.getIdentgetUsedSymbols("+symbol+")=" + scope.getUsedSymbols().join(','));
-               if (identifier) {
+               if (identifier.length) {
                    return identifier;
                }
                scope = scope.parent;
            }
-           return false;
+           return "";
        }
 };