1 package net.sourceforge.pmd.cpd.cppast;
2
3 import java.util.Hashtable;
4
5 public class Scope {
6 /***
7 * Name of the scope (set only for class/function scopes).
8 */
9 String scopeName;
10
11 /***
12 * Indicates whether this is a class scope or not.
13 */
14 boolean type;
15
16 /***
17 * (partial) table of type symbols introduced in this scope.
18 */
19 Hashtable typeTable = new Hashtable();
20
21 /***
22 * Parent scope. (null if it is the global scope).
23 */
24 Scope parent;
25
26 /***
27 * Creates a scope object with a given name.
28 */
29 public Scope(String name, boolean isType, Scope p) {
30 scopeName = name;
31 type = isType;
32 parent = p;
33 }
34
35 /***
36 * Creates an unnamed scope (like for compound statements).
37 */
38 public Scope(Scope p) {
39 type = false;
40 parent = p;
41 }
42
43 /***
44 * Inserts a name into the table to say that it is the name of a type.
45 */
46 public void PutTypeName(String name) {
47 typeTable.put(name, name);
48 }
49
50 /***
51 * A type with a scope (class/struct/union).
52 */
53 public void PutTypeName(String name, Scope sc) {
54 typeTable.put(name, sc);
55 }
56
57 /***
58 * Checks if a given name is the name of a type in this scope.
59 */
60 public boolean IsTypeName(String name) {
61 return typeTable.get(name) != null;
62 }
63
64 public Scope GetScope(String name) {
65 Object sc = typeTable.get(name);
66
67 if (sc instanceof Scope || sc instanceof ClassScope)
68 return (Scope) sc;
69
70 return null;
71 }
72 }