1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 86654 - Cache final overrider maps in the AST

Change-Id: I33d79c160b7aa7b014042ea06e0b851abc9cb608
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2015-07-18 22:29:21 -04:00
parent d9a2c02fbf
commit 8af3f1df86
2 changed files with 31 additions and 3 deletions

View file

@ -12,6 +12,9 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -33,6 +36,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPInheritance.FinalOverriderMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContent;
@ -46,6 +50,9 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
private final CPPScopeMapper fScopeMapper= new CPPScopeMapper(this);
private CPPASTAmbiguityResolver fAmbiguityResolver;
// Caches
private Map<ICPPClassType, FinalOverriderMap> fFinalOverriderMapCache = new HashMap<>();
public CPPASTTranslationUnit() {
}
@ -211,4 +218,8 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST
fAmbiguityResolver.resolvePendingAmbiguities(node);
}
}
public Map<ICPPClassType, FinalOverriderMap> getFinalOverriderMapCache() {
return fFinalOverriderMapCache;
}
}

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.parser.util.CollectionUtils;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
/**
@ -96,13 +97,29 @@ public class CPPInheritance {
/**
* Returns the final overrider map for a class hierarchy.
*
* Final overrider maps are cached in the AST.
*
* @param classType the root of the class hierarchy
* @param point the point of template instantiation, if applicable
* @param point The point of template instantiation, if applicable.
* Also used to access the cache in the AST.
* @return the computed final overrider map
*/
public static FinalOverriderMap getFinalOverriderMap(ICPPClassType classType, IASTNode point) {
return FinalOverriderAnalysis.computeFinalOverriderMap(classType, point);
Map<ICPPClassType, FinalOverriderMap> cache = null;
if (point != null && point.getTranslationUnit() instanceof CPPASTTranslationUnit) {
cache = ((CPPASTTranslationUnit) point.getTranslationUnit()).getFinalOverriderMapCache();
}
FinalOverriderMap result = null;
if (cache != null) {
result = cache.get(classType);
}
if (result == null) {
result = FinalOverriderAnalysis.computeFinalOverriderMap(classType, point);
}
if (result != null && cache != null) {
cache.put(classType, result);
}
return result;
}
private static class FinalOverriderAnalysis {