Changeset 1207
- Timestamp:
- 07/05/08 10:17:33 (6 months ago)
- Files:
-
- trunk/descent.core/src/descent/internal/compiler/lookup/LazyAggregateDeclaration.java (added)
- trunk/descent.core/src/descent/internal/compiler/lookup/LazyClassDeclaration.java (modified) (5 diffs)
- trunk/descent.core/src/descent/internal/compiler/lookup/LazyInterfaceDeclaration.java (modified) (4 diffs)
- trunk/descent.core/src/descent/internal/compiler/lookup/LazyStructDeclaration.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/descent.core/src/descent/internal/compiler/lookup/LazyClassDeclaration.java
r1203 r1207 1 1 package descent.internal.compiler.lookup; 2 2 3 import java.util.ArrayList;4 import java.util.List;5 6 import descent.core.IJavaElement;7 3 import descent.core.JavaModelException; 8 import descent.internal.compiler.lookup.ModuleBuilder.FillResult;9 4 import descent.internal.compiler.parser.BaseClasses; 10 5 import descent.internal.compiler.parser.ClassDeclaration; … … 12 7 import descent.internal.compiler.parser.DsymbolTable; 13 8 import descent.internal.compiler.parser.Dsymbols; 14 import descent.internal.compiler.parser.HashtableOfCharArrayAndObject;15 9 import descent.internal.compiler.parser.IdentifierExp; 16 10 import descent.internal.compiler.parser.Loc; 17 import descent.internal.compiler.parser.ProtDeclaration;18 11 import descent.internal.compiler.parser.Scope; 19 12 import descent.internal.compiler.parser.ScopeDsymbol; 20 13 import descent.internal.compiler.parser.SemanticContext; 21 import descent.internal.compiler.parser.StorageClassDeclaration;22 14 import descent.internal.core.util.Util; 23 15 24 public class LazyClassDeclaration extends ClassDeclaration implements ILazy {16 public class LazyClassDeclaration extends ClassDeclaration implements ILazyAggregate { 25 17 26 18 private final ModuleBuilder builder; 27 private HashtableOfCharArrayAndObject javaElementMembersCache;28 private List<Dsymbol> pendingPublicImports;29 private List<Dsymbol> pendingPrivateImports;30 19 31 20 private Scope semanticScope; … … 33 22 private Scope semantic3Scope; 34 23 35 private boolean cancelLazyness;24 private final LazyAggregateDeclaration lazy; 36 25 37 26 public LazyClassDeclaration(Loc loc, IdentifierExp id, BaseClasses baseclasses, ModuleBuilder builder) { 38 27 super(loc, id, baseclasses); 39 28 this.builder = builder; 29 this.lazy = new LazyAggregateDeclaration(this); 40 30 } 41 31 … … 82 72 @Override 83 73 public Dsymbol search(Loc loc, char[] ident, int flags, SemanticContext context) { 84 if (cancelLazyness) { 85 return super.search(loc, ident, flags, context); 86 } 87 88 Dsymbol s = symtab != null ? symtab.lookup(ident) : null; 89 90 if (s == null) { 91 if (javaElementMembersCache == null) { 92 javaElementMembersCache = new HashtableOfCharArrayAndObject(); 93 List<Dsymbol> privateImports = new ArrayList<Dsymbol>(); 94 List<Dsymbol> publicImports = new ArrayList<Dsymbol>(); 95 FillResult result = null ; 96 try { 97 result = builder.fillJavaElementMembersCache(this, this.javaElement.getChildren(), javaElementMembersCache, members, privateImports, publicImports, context); 98 } catch (JavaModelException e) { 99 Util.log(e); 100 } 101 102 if (result.hasMixinDeclaration || result.hasStaticIf) { 103 cancelLazyness = true; 104 members = new Dsymbols(); 105 try { 106 builder.fill(getModule(), members, javaElement.getChildren(), null); 107 } catch (JavaModelException e) { 108 Util.log(e); 109 } 110 111 for(Dsymbol sym : members) { 112 sym.addMember(semanticScope, this, 0, context); 113 runMissingSemantic(sym, context); 114 } 115 116 return search(loc, ident, flags, context); 117 } 118 119 if (!privateImports.isEmpty()) { 120 pendingPrivateImports = privateImports; 121 } 122 if (!publicImports.isEmpty()) { 123 pendingPublicImports = publicImports; 124 } 125 126 // Anonymous enums are "hard" for me :-P 127 if (result.hasAnonEnum) { 128 return search(loc, ident, flags, context); 129 } 130 } 131 132 Object target = javaElementMembersCache.get(ident); 133 if (target != null) { 134 if (this.symtab == null) { 135 this.symtab = new DsymbolTable(); 136 } 137 138 if (target instanceof IJavaElement) { 139 try { 140 builder.fill(this.getModule(), members, null, (IJavaElement) target); 141 } catch (JavaModelException e) { 142 Util.log(e); 143 } 144 145 s = members.get(members.size() - 1); 146 s.addMember(this.semanticScope, this, 0, context); 147 runMissingSemantic(s, context); 148 } else { 149 Dsymbols symbols = new Dsymbols(); 150 151 List<IJavaElement> elemsList = (List<IJavaElement>) target; 152 for(IJavaElement elem : elemsList) { 153 try { 154 builder.fill(this.getModule(), members, null, (IJavaElement) elem); 155 } catch (JavaModelException e) { 156 Util.log(e); 157 } 158 159 s = members.get(members.size() - 1); 160 if (semanticScope != null) { 161 s.addMember(semanticScope, this, 0, context); 162 } 163 164 symbols.add(s); 165 } 166 167 for(Dsymbol sym : symbols) { 168 runMissingSemantic(sym, context); 169 } 170 171 s = symbols.get(0); 172 } 173 174 while(s.isAttribDeclaration() != null) { 175 if (s instanceof ProtDeclaration) { 176 s = ((ProtDeclaration) s).decl.get(0); 177 } else if (s instanceof StorageClassDeclaration){ 178 s = ((StorageClassDeclaration) s).decl.get(0); 179 } 180 } 181 } 182 } 183 184 if (s == null) { 185 if ((flags & 1) == 0) { 186 if (pendingPrivateImports != null) { 187 for(Dsymbol imp : pendingPrivateImports) { 188 imp.addMember(semanticScope, this, 0, context); 189 runMissingSemantic(imp, context); 190 } 191 pendingPrivateImports = null; 192 } 193 } 194 if (pendingPublicImports != null) { 195 for(Dsymbol imp : pendingPublicImports) { 196 imp.addMember(semanticScope, this, 0, context); 197 runMissingSemantic(imp, context); 198 } 199 pendingPublicImports = null; 200 } 201 } 202 203 if (s == null) { 204 s = super.search(loc, ident, flags, context); 205 } 206 207 return s; 74 return lazy.search(loc, ident, flags, context); 208 75 } 209 76 210 77 public void runMissingSemantic(Dsymbol sym, SemanticContext context) { 211 context.muteProblems++; 212 if (semanticScope != null) { 213 sym.semantic(semanticScope, context); 214 } 215 if (semantic2Scope != null) { 216 sym.semantic2(semantic2Scope, context); 217 } 218 if (semantic3Scope != null) { 219 sym.semantic3(semantic3Scope, context); 220 } 221 context.muteProblems--; 78 lazy.runMissingSemantic(sym, context); 222 79 } 223 80 … … 234 91 } 235 92 93 public ModuleBuilder builder() { 94 return builder; 95 } 96 97 public void members(Dsymbols dsymbols) { 98 this.members = dsymbols; 99 } 100 101 public Dsymbols members() { 102 return members; 103 } 104 105 public Scope semanticScope() { 106 return semanticScope; 107 } 108 109 public Scope semantic2Scope() { 110 return semantic2Scope; 111 } 112 113 public Scope semantic3Scope() { 114 return semantic3Scope; 115 } 116 117 public Dsymbol super_search(Loc loc, char[] ident, int flags, SemanticContext context) { 118 return super.search(loc, ident, flags, context); 119 } 120 121 public DsymbolTable symtab() { 122 return symtab; 123 } 124 125 public void symtab(DsymbolTable table) { 126 this.symtab = table; 127 } 128 236 129 } trunk/descent.core/src/descent/internal/compiler/lookup/LazyInterfaceDeclaration.java
r1203 r1207 1 1 package descent.internal.compiler.lookup; 2 2 3 import java.util.ArrayList;4 import java.util.List;5 6 import descent.core.IJavaElement;7 3 import descent.core.JavaModelException; 8 import descent.internal.compiler.lookup.ModuleBuilder.FillResult;9 4 import descent.internal.compiler.parser.BaseClasses; 10 5 import descent.internal.compiler.parser.Dsymbol; 11 6 import descent.internal.compiler.parser.DsymbolTable; 12 7 import descent.internal.compiler.parser.Dsymbols; 13 import descent.internal.compiler.parser.HashtableOfCharArrayAndObject;14 8 import descent.internal.compiler.parser.IdentifierExp; 15 9 import descent.internal.compiler.parser.InterfaceDeclaration; 16 10 import descent.internal.compiler.parser.Loc; 17 import descent.internal.compiler.parser.ProtDeclaration;18 11 import descent.internal.compiler.parser.Scope; 19 12 import descent.internal.compiler.parser.ScopeDsymbol; 20 13 import descent.internal.compiler.parser.SemanticContext; 21 import descent.internal.compiler.parser.StorageClassDeclaration;22 14 import descent.internal.core.util.Util; 23 15 24 public class LazyInterfaceDeclaration extends InterfaceDeclaration implements ILazy {16 public class LazyInterfaceDeclaration extends InterfaceDeclaration implements ILazyAggregate { 25 17 26 18 private final ModuleBuilder builder; 27 private HashtableOfCharArrayAndObject javaElementMembersCache;28 private List<Dsymbol> pendingPublicImports;29 private List<Dsymbol> pendingPrivateImports;30 19 31 20 private Scope semanticScope; … … 33 22 private Scope semantic3Scope; 34 23 35 private boolean cancelLazyness;24 private LazyAggregateDeclaration lazy; 36 25 37 26 public LazyInterfaceDeclaration(Loc loc, IdentifierExp id, BaseClasses baseclasses, ModuleBuilder builder) { 38 27 super(loc, id, baseclasses); 39 28 this.builder = builder; 29 this.lazy = new LazyAggregateDeclaration(this); 40 30 } 41 31 … … 82 72 @Override 83 73 public Dsymbol search(Loc loc, char[] ident, int flags, SemanticContext context) { 84 if (cancelLazyness) { 85 return super.search(loc, ident, flags, context); 86 } 87 88 Dsymbol s = symtab != null ? symtab.lookup(ident) : null; 89 90 if (s == null) { 91 if (javaElementMembersCache == null) { 92 javaElementMembersCache = new HashtableOfCharArrayAndObject(); 93 List<Dsymbol> privateImports = new ArrayList<Dsymbol>(); 94 List<Dsymbol> publicImports = new ArrayList<Dsymbol>(); 95 FillResult result = null ; 96 try { 97 result = builder.fillJavaElementMembersCache(this, this.javaElement.getChildren(), javaElementMembersCache, members, privateImports, publicImports, context); 98 } catch (JavaModelException e) { 99 Util.log(e); 100 } 101 102 if (result.hasMixinDeclaration || result.hasStaticIf) { 103 cancelLazyness = true; 104 members = new Dsymbols(); 105 try { 106 builder.fill(getModule(), members, javaElement.getChildren(), null); 107 } catch (JavaModelException e) { 108 Util.log(e); 109 } 110 111 for(Dsymbol sym : members) { 112 sym.addMember(semanticScope, this, 0, context); 113 runMissingSemantic(sym, context); 114 } 115 116 return search(loc, ident, flags, context); 117 } 118 119 if (!privateImports.isEmpty()) { 120 pendingPrivateImports = privateImports; 121 } 122 if (!publicImports.isEmpty()) { 123 pendingPublicImports = publicImports; 124 } 125 126 // Anonymous enums are "hard" for me :-P 127 if (result.hasAnonEnum) { 128 return search(loc, ident, flags, context); 129 } 130 } 131 132 Object target = javaElementMembersCache.get(ident); 133 if (target != null) { 134 if (this.symtab == null) { 135 this.symtab = new DsymbolTable(); 136 } 137 138 if (target instanceof IJavaElement) { 139 try { 140 builder.fill(this.getModule(), members, null, (IJavaElement) target); 141 } catch (JavaModelException e) { 142 Util.log(e); 143 } 144 145 s = members.get(members.size() - 1); 146 s.addMember(this.semanticScope, this, 0, context); 147 runMissingSemantic(s, context); 148 } else { 149 Dsymbols symbols = new Dsymbols(); 150 151 List<IJavaElement> elemsList = (List<IJavaElement>) target; 152 for(IJavaElement elem : elemsList) { 153 try { 154 builder.fill(this.getModule(), members, null, (IJavaElement) elem); 155 } catch (JavaModelException e) { 156 Util.log(e); 157 } 158 159 s = members.get(members.size() - 1); 160 if (semanticScope != null) { 161 s.addMember(semanticScope, this, 0, context); 162 } 163 164 symbols.add(s); 165 } 166 167 for(Dsymbol sym : symbols) { 168 runMissingSemantic(sym, context); 169 } 170 171 s = symbols.get(0); 172 } 173 174 while(s.isAttribDeclaration() != null) { 175 if (s instanceof ProtDeclaration) { 176 s = ((ProtDeclaration) s).decl.get(0); 177 } else if (s instanceof StorageClassDeclaration){ 178 s = ((StorageClassDeclaration) s).decl.get(0); 179 } 180 } 181 } 182 } 183 184 if (s == null) { 185 if ((flags & 1) == 0) { 186 if (pendingPrivateImports != null) { 187 for(Dsymbol imp : pendingPrivateImports) { 188 imp.addMember(semanticScope, this, 0, context); 189 runMissingSemantic(imp, context); 190 } 191 pendingPrivateImports = null; 192 } 193 } 194 if (pendingPublicImports != null) { 195 for(Dsymbol imp : pendingPublicImports) { 196 imp.addMember(semanticScope, this, 0, context); 197 runMissingSemantic(imp, context); 198 } 199 pendingPublicImports = null; 200 } 201 } 202 203 if (s == null) { 204 s = super.search(loc, ident, flags, context); 205 } 206 207 return s; 74 return lazy.search(loc, ident, flags, context); 208 75 } 209 76 210 77 public void runMissingSemantic(Dsymbol sym, SemanticContext context) { 211 context.muteProblems++; 212 if (semanticScope != null) { 213 sym.semantic(semanticScope, context); 214 } 215 if (semantic2Scope != null) { 216 sym.semantic2(semantic2Scope, context); 217 } 218 if (semantic3Scope != null) { 219 sym.semantic3(semantic3Scope, context); 220 } 221 context.muteProblems--; 78 lazy.runMissingSemantic(sym, context); 222 79 } 223 80 … … 233 90 return ident; 234 91 } 92 93 public ModuleBuilder builder() { 94 return builder; 95 } 96 97 public void members(Dsymbols dsymbols) { 98 this.members = dsymbols; 99 } 100 101 public Dsymbols members() { 102 return members; 103 } 104 105 public Scope semanticScope() { 106 return semanticScope; 107 } 108 109 public Scope semantic2Scope() { 110 return semantic2Scope; 111 } 112 113 public Scope semantic3Scope() { 114 return semantic3Scope; 115 } 116 117 public Dsymbol super_search(Loc loc, char[] ident, int flags, SemanticContext context) { 118 return super.search(loc, ident, flags, context); 119 } 120 121 public DsymbolTable symtab() { 122 return symtab; 123 } 124 125 public void symtab(DsymbolTable table) { 126 this.symtab = table; 127 } 235 128 236 129 } trunk/descent.core/src/descent/internal/compiler/lookup/LazyStructDeclaration.java
r1203 r1207 1 1 package descent.internal.compiler.lookup; 2 2 3 import java.util.ArrayList;4 import java.util.List;5 6 import descent.core.IJavaElement;7 3 import descent.core.JavaModelException; 8 import descent.internal.compiler.lookup.ModuleBuilder.FillResult;9 4 import descent.internal.compiler.parser.Dsymbol; 10 5 import descent.internal.compiler.parser.DsymbolTable; 11 6 import descent.internal.compiler.parser.Dsymbols; 12 import descent.internal.compiler.parser.HashtableOfCharArrayAndObject;13 7 import descent.internal.compiler.parser.IdentifierExp; 14 8 import descent.internal.compiler.parser.Loc; 15 import descent.internal.compiler.parser.ProtDeclaration;16 9 import descent.internal.compiler.parser.Scope; 17 10 import descent.internal.compiler.parser.ScopeDsymbol; 18 11 import descent.internal.compiler.parser.SemanticContext; 19 import descent.internal.compiler.parser.StorageClassDeclaration;20 12 import descent.internal.compiler.parser.StructDeclaration; 21 13 import descent.internal.core.util.Util; 22 14 23 public class LazyStructDeclaration extends StructDeclaration implements ILazy {15 public class LazyStructDeclaration extends StructDeclaration implements ILazyAggregate { 24 16 25 17 private final ModuleBuilder builder; 26 private HashtableOfCharArrayAndObject javaElementMembersCache;27 private List<Dsymbol> pendingPublicImports;28 private List<Dsymbol> pendingPrivateImports;29 18 30 19 private Scope semanticScope; … … 32 21 private Scope semantic3Scope; 33 22 34 private boolean cancelLazyness;23 private final LazyAggregateDeclaration lazy; 35 24 36 25 public LazyStructDeclaration(Loc loc, IdentifierExp id, ModuleBuilder builder) { 37 26 super(loc, id); 38 27 this.builder = builder; 28 this.lazy = new LazyAggregateDeclaration(this); 39 29 } 40 30 … … 73 63 @Override 74 64 public Dsymbol search(Loc loc, char[] ident, int flags, SemanticContext context) { 75 if (cancelLazyness) { 76 return super.search(loc, ident, flags, context); 77 } 78 79 Dsymbol s = symtab != null ? symtab.lookup(ident) : null; 80 81 if (s == null) { 82 if (javaElementMembersCache == null) { 83 javaElementMembersCache = new HashtableOfCharArrayAndObject(); 84 List<Dsymbol> privateImports = new ArrayList<Dsymbol>(); 85 List<Dsymbol> publicImports = new ArrayList<Dsymbol>(); 86 FillResult result = null ; 87 try { 88 result = builder.fillJavaElementMembersCache(this, this.javaElement.getChildren(), javaElementMembersCache, members, privateImports, publicImports, context); 89 } catch (JavaModelException e) { 90 Util.log(e); 91 } 92 93 if (result.hasMixinDeclaration || result.hasStaticIf) { 94 cancelLazyness = true; 95 members = new Dsymbols(); 96 try { 97 builder.fill(getModule(), members, javaElement.getChildren(), null); 98 } catch (JavaModelException e) { 99 Util.log(e); 100 } 101 102 for(Dsymbol sym : members) { 103 sym.addMember(semanticScope, this, 0, context); 104 runMissingSemantic(sym, context); 105 } 106 107 return search(loc, ident, flags, context); 108 } 109 110 if (!privateImports.isEmpty()) { 111 pendingPrivateImports = privateImports; 112 } 113 if (!publicImports.isEmpty()) { 114 pendingPublicImports = publicImports; 115 } 116 117 // Anonymous enums are "hard" for me :-P 118 if (result.hasAnonEnum) { 119 return search(loc, ident, flags, context); 120 } 121 } 122 123 Object target = javaElementMembersCache.get(ident); 124 if (target != null) { 125 if (this.symtab == null) { 126 this.symtab = new DsymbolTable(); 127 } 128 129 if (target instanceof IJavaElement) { 130 try { 131 builder.fill(this.getModule(), members, null, (IJavaElement) target); 132 } catch (JavaModelException e) { 133 Util.log(e); 134 } 135 136 s = members.get(members.size() - 1); 137 s.addMember(this.semanticScope, this, 0, context); 138 runMissingSemantic(s, context); 139 } else { 140 Dsymbols symbols = new Dsymbols(); 141 142 List<IJavaElement> elemsList = (List<IJavaElement>) target; 143 for(IJavaElement elem : elemsList) { 144 try { 145 builder.fill(this.getModule(), members, null, (IJavaElement) elem); 146 } catch (JavaModelException e) { 147 Util.log(e); 148 } 149 150 s = members.get(members.size() - 1); 151 if (semanticScope != null) { 152 s.addMember(semanticScope, this, 0, context); 153 } 154 155 symbols.add(s); 156 } 157 158 for(Dsymbol sym : symbols) { 159 runMissingSemantic(sym, context); 160 } 161 162 s = symbols.get(0); 163 } 164 165 while(s.isAttribDeclaration() != null) { 166 if (s instanceof ProtDeclaration) { 167 s = ((ProtDeclaration) s).decl.get(0); 168 } else if (s instanceof StorageClassDeclaration){ 169 s = ((StorageClassDeclaration) s).decl.get(0); 170 } 171 } 172 } 173 } 174 175 if (s == null) { 176 if ((flags & 1) == 0) { 177 if (pendingPrivateImports != null) { 178 for(Dsymbol imp : pendingPrivateImports) { 179 imp.addMember(semanticScope, this, 0, context); 180 runMissingSemantic(imp, context); 181 } 182 pendingPrivateImports = null; 183 } 184 } 185 if (pendingPublicImports != null) { 186 for(Dsymbol imp : pendingPublicImports) { 187 imp.addMember(semanticScope, this, 0, context); 188 runMissingSemantic(imp, context); 189 } 190 pendingPublicImports = null; 191 } 192 } 193 194 if (s == null) { 195 s = super.search(loc, ident, flags, context); 196 } 197 198 return s; 65 return lazy.search(loc, ident, flags, context); 199 66 } 200 67 201 68 public void runMissingSemantic(Dsymbol sym, SemanticContext context) { 202 context.muteProblems++; 203 if (semanticScope != null) { 204 sym.semantic(semanticScope, context); 205 } 206 if (semantic2Scope != null) { 207 sym.semantic2(semantic2Scope, context); 208 } 209 if (semantic3Scope != null) { 210 sym.semantic3(semantic3Scope, context); 211 } 212 context.muteProblems--; 69 lazy.runMissingSemantic(sym, context); 213 70 } 214 71 … … 224 81 return ident; 225 82 } 83 84 public ModuleBuilder builder() { 85 return builder; 86 } 87 88 public void members(Dsymbols dsymbols) { 89 this.members = dsymbols; 90 } 91 92 public Dsymbols members() { 93 return members; 94 } 95 96 public Scope semanticScope() { 97 return semanticScope; 98 } 99 100 public Scope semantic2Scope() { 101 return semantic2Scope; 102 } 103 104 public Scope semantic3Scope() { 105 return semantic3Scope; 106 } 107 108 public Dsymbol super_search(Loc loc, char[] ident, int flags, SemanticContext context) { 109 return super.search(loc, ident, flags, context); 110 } 111 112 public DsymbolTable symtab() { 113 return symtab; 114 } 115 116 public void symtab(DsymbolTable table) { 117 this.symtab = table; 118 } 226 119 227 120 }
