JSDOC/Scope.js
[gnome.introspection-doc-generator] / JSDOC / Scope.js
index e912736..425a385 100644 (file)
@@ -6,11 +6,12 @@
 * // FIXME - I need this to do next() without doccomments..
 */
 
-Identifier = imports['JSDOC/Identifier.js'].Identifier
-XObject = imports.XObject.XObject; 
+const Identifier = imports.Identifier.Identifier
+const XObject = imports.XObject.XObject; 
 
+Scope.id = 1;
 
-function Scope(braceN, parent, startTokN, lastIdent)
+function Scope(braceN, parent, startTokN, lastIdent, token)
 {
     if (lastIdent.length) {
        //  println("NEW SCOPE: " + lastIdent);
@@ -18,14 +19,15 @@ function Scope(braceN, parent, startTokN, lastIdent)
     
     this.braceN = braceN
     this.parent = parent;
-    this.id = startTokN;
+    this.id = Scope.id++;
     this.identifiers = { };
     this.subScopes = [];
     this.hints = { };
     this.ident = lastIdent;
-    
-    
-    //println("ADD SCOPE(" + this.id + ") TO "+ (parent ? this.parent.id : 'TOP') + "<BR/>");
+    this.gid = Scope.gid++;
+    this.token = token;
+    //print("ADD SCOPE(" + this.gid + ") TO "+ (parent ? this.parent.gid : 'TOP') + ' : ' + 
+    //    (token ? token.toString() : ''));
     
     if (parent) {
         this.parent.subScopes.push(this);
@@ -52,9 +54,38 @@ Scope.prototype = {
     
     munged : false,
     protectedVars : {}, // only used by to parent..
-    declareIdentifier : function(symbol, token) {
+    
+    /**
+     * dump the scope to StdOut...
+     * 
+     */
+    dump : function(indent) 
+    {
+        indent = indent || '';
+        var str = '';
+        for (var k in this.identifiers) {
+            str += str.length ? ", " : "";
+            str += k + '=>' + this.identifiers[k].mungedValue;
+        }
+        
+        print(
+            indent + "Scope: " + this.id + "\n" +
+            
+            indent + "Started: " + ( this.token ? this.token.toString(): 'TOP' ) + "\n" +
+            indent + "- " + str + "\n"
+        );
+        this.subScopes.forEach(function(s) {
+            s.dump(indent + ' ');
+        });
+        
+        
+    },
+    
+    
+    declareIdentifier : function(symbol, token) 
+    {
         
-        //println("ADD IDENT(" + this.id + "):<B>" + symbol+"</B><BR/>");
+        //print("SCOPE : " + this.gid +  " :SYM: " + symbol + " " + token.toString()+"");
         
         if (typeof(this.identifiers[symbol])== 'undefined') {
             
@@ -69,11 +100,22 @@ Scope.prototype = {
                 // then it's global... 
                 this.identifiers[symbol].toMunge  = false;
         }
+         
+        
         this.addToParentScope(symbol);
         return this.identifiers[symbol];
     },
-    getIdentifier : function(symbol) {
-        return (typeof(this.identifiers[symbol])== 'undefined') ? false : this.identifiers[symbol];
+    getIdentifier : function(symbol, token) {
+        if (typeof(this.identifiers[symbol])== 'undefined') {
+            if (['String', 'Date'].indexOf(symbol)> -1) {
+                return false;
+            }
+            
+            //print("SCOPE : " + this.gid +" = SYMBOL NOT FOUND?" + token.toString());
+            return false;
+        }
+         //print("SCOPE : " + this.gid +" = FOUND:" + token.toString());
+        return this.identifiers[symbol];
     },
     
     addHint : function(varName, varType) {
@@ -176,10 +218,12 @@ Scope.prototype = {
 
         // Do not munge symbols in the global scope!
         if (this.parent) {
-            print("MUNGE: SCOPE");
-            for (var i in this.identifiers) {
-                print("MUNGE VAR:" + i);
+            
+            var all = [];
+            for (var ii in this.identifiers) {
+                all.push(ii);
             }
+            //print("MUNGE: " + all.join(', '));
             
             //println("MUNGE: Building FreeSyms:" + this.id+"</BR>");
             
@@ -208,23 +252,26 @@ Scope.prototype = {
                 
                 
                 if (!this.identifiers[i].toMunge) {
+                    //print("SKIP toMunge==false : " + i)
                     continue;
                 }
                 
                 if (this.isProtectedVar(i)) {
+                    //print("SKIP PROTECTED: " + i)
                     continue; // 
                 }
                 
                 
                 
-                if (this.identifiers[i].constructor !=  Identifier) {
-                    continue;
-                }
+                //if (this.identifiers[i].constructor !=  Identifier) {
+                //    print("SKIP NOT IDENTIFIER : " + i)
+                //    continue;
+               // }
                // println("IDENT:" +i+'</BR>');
                 
                 if (!repsym.length) {
                     if (!freeSymbols.length) {
-                        addSyms(JSDOC.Scope.twos); 
+                        addSyms(Scope.twos); 
                     }
                     repsym = freeSymbols.shift(); // pop off beginngin???
                 }
@@ -236,7 +283,7 @@ Scope.prototype = {
                 //println([     repsym,mungedValue ]);
                 
                 if (this.mungeM && repsym.length < mungedValue.length) {
-                    println("REPLACE:"+ mungedValue +" with " + repsym + "<BR>");    
+                    //print("REPLACE:"+ mungedValue +" with " + repsym );    
                     mungedValue = repsym;
                     repsym = '';
                 }
@@ -247,8 +294,8 @@ Scope.prototype = {
         }
         this.munged = true;
         //println("Doing sub scopes");
-        for (var i = 0; i < this.subScopes.length; i++) {
-            var ss = this.subScopes[i];
+        for (var j = 0; j < this.subScopes.length; j++) {
+            var ss = this.subScopes[j];
             ss.munge();
         }
     }
@@ -308,4 +355,4 @@ XObject.extend(Scope, {
 })
 // init the scope constants..
 Scope.init();
\ No newline at end of file
+Scope.gid = 0;
\ No newline at end of file