Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 162   Methods: 11
NCLOC: 99   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SymtabManager.java 0% 0% 0% 0%
coverage
 1    package net.sourceforge.pmd.cpd.cppast;
 2   
 3    import java.util.Hashtable;
 4   
 5    /**
 6    * Manages the symbol table and scopes within a given compilation unit.
 7    */
 8    public class SymtabManager {
 9    /**
 10    * Global symbol table indexed by the name of the scope (class/function).
 11    */
 12    static Hashtable scopeTable = new Hashtable();
 13   
 14    /**
 15    * Stack of scopes. Currently max. nesting allowed is 100.
 16    */
 17    static Scope[] scopeStack = new Scope[100];
 18   
 19    /**
 20    * Current depth of scope nesting.
 21    */
 22    static int depth = 0;
 23   
 24    /**
 25    * Dummy at the bottom of the stack so that no need to check for null.
 26    */
 27    static {
 28  0 scopeStack[depth] = new Scope(null);
 29    }
 30   
 31    /**
 32    * Opens a new scope (with optional name and type flag).
 33    */
 34  0 public static Scope OpenScope(String scopeName, boolean isType) {
 35  0 Scope newScope;
 36   
 37  0 if (scopeName != null) {
 38  0 if (isType) {
 39  0 newScope = new ClassScope(scopeName, scopeStack[depth]);
 40  0 scopeStack[depth].PutTypeName(scopeName, newScope);
 41    } else {
 42  0 newScope = new Scope(scopeName, isType, scopeStack[depth]);
 43    }
 44   
 45  0 scopeTable.put(scopeName, newScope);
 46    } else
 47  0 newScope = new Scope(scopeStack[depth]);
 48   
 49  0 scopeStack[++depth] = newScope;
 50  0 return newScope;
 51    }
 52   
 53  0 public static void OpenScope(Scope sc) {
 54  0 scopeStack[++depth] = sc;
 55    }
 56   
 57  0 public static void PutTypeName(String name) {
 58  0 scopeStack[depth].PutTypeName(name);
 59    }
 60   
 61  0 public static boolean IsFullyScopedTypeName(String name) {
 62  0 if (name == null)
 63  0 return false;
 64   
 65  0 if (name.indexOf("::") == -1)
 66  0 return IsTypeName(name);
 67   
 68  0 Scope sc = GetScopeOfFullyScopedName(name);
 69   
 70  0 if (sc != null)
 71  0 return sc.IsTypeName(name.substring(name.lastIndexOf("::") + 2,
 72    name.length()));
 73   
 74  0 return false;
 75    }
 76   
 77  0 public static boolean IsTypeName(String name) {
 78  0 int i = depth;
 79   
 80  0 while (i >= 0) {
 81  0 if (scopeStack[i--].IsTypeName(name))
 82  0 return true;
 83    }
 84   
 85  0 return false;
 86    }
 87   
 88  0 public static void CloseScope() {
 89  0 depth--;
 90    }
 91   
 92    /**
 93    * For now, we just say if it is a class name, it is OK to call it a
 94    * constructor.
 95    */
 96  0 public static boolean IsCtor(String name) {
 97  0 if (name == null)
 98  0 return false;
 99   
 100  0 if (name.indexOf("::") == -1)
 101  0 return GetScope(name) != null;
 102   
 103  0 Scope sc = GetScopeOfFullyScopedName(name);
 104   
 105  0 if (sc != null && sc.parent != null)
 106  0 return sc.parent.GetScope(name.substring(name.lastIndexOf("::") + 2,
 107    name.length())) == sc;
 108   
 109  0 return false;
 110    }
 111   
 112  0 public static Scope GetCurScope() {
 113  0 return scopeStack[depth];
 114    }
 115   
 116  0 public static Scope GetScope(String name) {
 117  0 int i = depth;
 118  0 Scope sc = null;
 119   
 120  0 while (i >= 0)
 121  0 if ((sc = scopeStack[i--].GetScope(name)) != null)
 122  0 return sc;
 123   
 124  0 return null;
 125    }
 126   
 127    /**
 128    * Returns the Scope of B in A::B::C.
 129    */
 130  0 public static Scope GetScopeOfFullyScopedName(String name) {
 131  0 Scope sc;
 132  0 int i = 0, j = 0;
 133   
 134  0 if (name.indexOf("::") == -1)
 135  0 return GetScope(name);
 136   
 137  0 if (name.indexOf("::") == 0) {
 138  0 sc = scopeStack[1];
 139  0 j = 2;
 140    } else
 141  0 sc = GetCurScope();
 142   
 143  0 String tmp = name.substring(j, name.lastIndexOf("::"));
 144   
 145  0 while ((j = tmp.indexOf("::", i)) != -1) {
 146  0 sc = sc.GetScope(tmp.substring(i, j));
 147  0 i = j + 2;
 148   
 149  0 if (sc == null)
 150  0 return null;
 151    }
 152   
 153  0 if (sc == GetCurScope())
 154  0 return GetScope(tmp.substring(i, tmp.length()));
 155   
 156  0 return sc.GetScope(tmp.substring(i, tmp.length()));
 157    }
 158   
 159  0 public static boolean IsGlobalScope() {
 160  0 return depth == 1 || depth == 2;
 161    }
 162    }