1 | package org.eclipse.jdt.core.dom.scope; |
---|---|
2 | |
3 | import java.util.HashMap; |
4 | import java.util.Map; |
5 | |
6 | public class ASTScope { |
7 | |
8 | public enum CompisiteScopeType { |
9 | CompisiteScopeNon, |
10 | CompisiteScopeFuncDecl, |
11 | CompisiteScopeTypeDecl, |
12 | CompisiteScopeTypeRecv, |
13 | CompisiteScopeStructAssign |
14 | } |
15 | |
16 | public static final String ScopePathSep = ":"; |
17 | public static final String ScopeDefineSep = ":"; |
18 | public static final String ScopeQualNameSep = "."; |
19 | public static final String ScopePackageName = "pkg"; |
20 | |
21 | public static String ScopeBlockStmt = "BlockStmt"; |
22 | public static String ScopeElts = "Elts"; |
23 | |
24 | public String identName = ""; |
25 | public String fullPath = ""; |
26 | public Map<String, ASTScope> childScopeMap = new HashMap<String, ASTScope>(); |
27 | public ASTScope parentScope = null; |
28 | public ASTScope topScope = null; |
29 | |
30 | public Map<String, ASTDefineNode> defineNodeMap = new HashMap<String, ASTDefineNode>(); |
31 | /* |
32 | * type name for the node use, key: nodename_line_column, |
33 | * nodeName:{path:xxx:xxxx:xxxx.nodeName} |
34 | */ |
35 | public Map<String, String> nodeUseSelectorPathMap = new HashMap<String, String>(); |
36 | |
37 | public ASTScope(String ident, ASTScope parent) { |
38 | this.identName = ident; |
39 | this.parentScope = parent; |
40 | if (parent != null) { |
41 | this.fullPath = parent.fullPath + ScopePathSep + ident; |
42 | this.topScope = parent.topScope; |
43 | } else { |
44 | this.fullPath = ident; |
45 | this.topScope = this; |
46 | } |
47 | } |
48 | |
49 | public ASTScope createChild(String ident) { |
50 | |
51 | ASTScope child = childScopeMap.get(ident); |
52 | if (child != null) { |
53 | return child; |
54 | } |
55 | child = new ASTScope(ident, this); |
56 | childScopeMap.put(ident, child); |
57 | return child; |
58 | } |
59 | |
60 | public ASTScope getChildScope(String scopeName) { |
61 | return childScopeMap.get(scopeName); |
62 | } |
63 | |
64 | public void dump() { |
65 | System.out.println("scope: " + this.fullPath); |
66 | for (Map.Entry<String, ASTDefineNode> entry : defineNodeMap.entrySet()) { |
67 | ASTDefineNode astDefNode = entry.getValue(); |
68 | System.out.println( |
69 | "\t" + entry.getKey() + " " + astDefNode.identName + " (" + astDefNode.astPosistion.line + "," |
70 | + astDefNode.astPosistion.column + ")"); |
71 | } |
72 | |
73 | for (Map.Entry<String, ASTScope> entry : childScopeMap.entrySet()) { |
74 | ASTScope astScope = entry.getValue(); |
75 | astScope.dump(); |
76 | } |
77 | } |
78 | |
79 | public ASTDefineNode addDefineNode(String nodeName, String nodeTypeName, ASTDefineNode.DefineType defineType, |
80 | ASTPosition astPos) { |
81 | ASTDefineNode defineNode = new ASTDefineNode(nodeName, nodeTypeName, defineType, this, astPos); |
82 | defineNodeMap.put(nodeName, defineNode); |
83 | return defineNode; |
84 | } |
85 | |
86 | public void setNodeUseSelectorPath(String nodeName, String nodeUsePath) { |
87 | this.nodeUseSelectorPathMap.put(nodeName, nodeUsePath); |
88 | } |
89 | |
90 | public String getNodeUseSelectorPath(String nodeName) { |
91 | return this.nodeUseSelectorPathMap.get(nodeName); |
92 | } |
93 | |
94 | public ASTDefineNode getDefineNode(String nodeName) { |
95 | ASTScope iterScope = this; |
96 | |
97 | while (iterScope != null) { |
98 | ASTDefineNode astDefNode = iterScope.defineNodeMap.get(nodeName); |
99 | if (astDefNode != null) { |
100 | return astDefNode; |
101 | } |
102 | iterScope = iterScope.parentScope; |
103 | } |
104 | return null; |
105 | } |
106 | |
107 | } |
108 |
Members