1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 17:55:39 +02:00

Bug 184083 - Patch for Bryan - Add base classes to for class instances and specialization in the PDOM.

This commit is contained in:
Doug Schaefer 2007-04-26 01:34:34 +00:00
parent b1cf95a962
commit 6342a2854c
8 changed files with 138 additions and 53 deletions

View file

@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Bryan Wilkinson (QNX)
*******************************************************************************/
/*
@ -30,8 +31,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
/**
* @author aniefer
*/
public class CPPBaseClause implements ICPPBase {
static public class CPPBaseProblem extends ProblemBinding implements ICPPBase {
public class CPPBaseClause implements ICPPBase, ICPPInternalBase {
static public class CPPBaseProblem extends ProblemBinding implements ICPPBase, ICPPInternalBase {
private ICPPClassType classProblem = null;
public CPPBaseProblem( IASTNode node, int id, char[] arg ) {
super( node, id, arg );
@ -53,6 +54,9 @@ public class CPPBaseClause implements ICPPBase {
public IName getBaseClassSpecifierName() {
return (IName) node;
}
public void setBaseClass(IBinding binding) throws DOMException {
throw new DOMException( this );
}
}
private ICPPASTBaseSpecifier base = null;
private IBinding baseClass = null;
@ -107,7 +111,7 @@ public class CPPBaseClause implements ICPPBase {
return base.isVirtual();
}
public void setBaseClass(ICPPClassType cls) {
public void setBaseClass(IBinding cls) {
baseClass = cls;
}
@ -115,4 +119,13 @@ public class CPPBaseClause implements ICPPBase {
return base.getName();
}
public Object clone(){
ICPPBase t = null;
try {
t = (ICPPBase) super.clone();
} catch ( CloneNotSupportedException e ) {
//not going to happen
}
return t;
}
}

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.index.IIndexType;
@ -54,18 +55,21 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
public ICPPBase[] getBases() throws DOMException {
ICPPClassType cls = (ICPPClassType) getSpecializedBinding();
if( cls != null ){
ICPPBase[] result = null;
ICPPBase [] bindings = cls.getBases();
for (int i = 0; i < bindings.length; i++) {
ICPPBase specBinding = (ICPPBase) ((ICPPInternalBase)bindings[i]).clone();
IBinding base = bindings[i].getBaseClass();
if (bindings[i] instanceof CPPBaseClause && base instanceof IType) {
if (base instanceof IType) {
IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap);
specBase = CPPSemantics.getUltimateType(specBase, false);
if (specBase instanceof ICPPClassType) {
((CPPBaseClause)bindings[i]).setBaseClass((ICPPClassType)specBase);
if (specBase instanceof IBinding) {
((ICPPInternalBase)specBinding).setBaseClass((IBinding)specBase);
}
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBinding);
}
}
return bindings;
return (ICPPBase[]) ArrayUtil.trim(ICPPBase.class, result);
}
return ICPPBase.EMPTY_BASE_ARRAY;
}

View file

@ -75,18 +75,21 @@ public class CPPClassSpecialization extends CPPSpecialization implements
*/
public ICPPBase[] getBases() throws DOMException {
if( getDefinition() == null ){
ICPPBase[] result = null;
ICPPBase[] bindings = ((ICPPClassType)getSpecializedBinding()).getBases();
for (int i = 0; i < bindings.length; i++) {
ICPPBase specBinding = (ICPPBase) ((ICPPInternalBase)bindings[i]).clone();
IBinding base = bindings[i].getBaseClass();
if (bindings[i] instanceof CPPBaseClause && base instanceof IType) {
if (base instanceof IType) {
IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap);
specBase = CPPSemantics.getUltimateType(specBase, false);
if (specBase instanceof ICPPClassType) {
((CPPBaseClause)bindings[i]).setBaseClass((ICPPClassType)specBase);
if (specBase instanceof IBinding) {
((ICPPInternalBase)specBinding).setBaseClass((IBinding)specBase);
}
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBinding);
}
}
return bindings;
return (ICPPBase[]) ArrayUtil.trim(ICPPBase.class, result);
}
ICPPASTBaseSpecifier[] bases = getCompositeTypeSpecifier().getBaseSpecifiers();

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
/**
* @author Bryan Wilkinson
*
*/
public interface ICPPInternalBase extends Cloneable {
public Object clone();
/**
* Set the base class.
*/
public void setBaseClass(IBinding binding) throws DOMException;
}

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBase;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@ -47,28 +48,43 @@ class CompositeCPPClassType extends CompositeCPPBinding implements ICPPClassType
return result;
}
private class CPPBaseDelegate implements ICPPBase, ICPPInternalBase {
private ICPPBase base;
CPPBaseDelegate(ICPPBase b) {
this.base = b;
}
public IBinding getBaseClass() throws DOMException {
return cf.getCompositeBinding((IIndexFragmentBinding)base.getBaseClass());
}
public IName getBaseClassSpecifierName() {
return base.getBaseClassSpecifierName();
}
public int getVisibility() throws DOMException {
return base.getVisibility();
}
public boolean isVirtual() throws DOMException {
return base.isVirtual();
}
public void setBaseClass(IBinding binding) throws DOMException {
((ICPPInternalBase)base).setBaseClass(binding);
}
public Object clone(){
return ((ICPPInternalBase)base).clone();
}
}
public ICPPBase[] getBases() throws DOMException {
final ICPPBase[] preresult = ((ICPPClassType)rbinding).getBases();
ICPPBase[] result = new ICPPBase[preresult.length];
for(int i=0; i<preresult.length; i++) {
final int n = i;
result[i] = new ICPPBase() {
public IBinding getBaseClass() throws DOMException {
return cf.getCompositeBinding((IIndexFragmentBinding)preresult[n].getBaseClass());
}
public int getVisibility() throws DOMException {
return preresult[n].getVisibility();
}
public boolean isVirtual() throws DOMException {
return preresult[n].isVirtual();
}
public IName getBaseClassSpecifierName() {
return preresult[n].getBaseClassSpecifierName();
}
};
result[i] = new CPPBaseDelegate(preresult[i]);
}
return result;
}

View file

@ -16,16 +16,18 @@ import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBase;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
*/
class PDOMCPPBase implements ICPPBase {
class PDOMCPPBase implements ICPPBase, ICPPInternalBase {
private static final int BASECLASS_SPECIFIER = 0;
private static final int NEXTBASE = 4;
@ -126,15 +128,25 @@ class PDOMCPPBase implements ICPPBase {
pdom.getDB().free(record);
}
private static class PDOMCPPBaseSpecialization implements ICPPBase {
private PDOMCPPBase base;
private IBinding baseClass;
public void setBaseClass(IBinding binding) {
throw new PDOMNotImplementedError();
}
public Object clone() {
return new PDOMCPPBaseClone(this);
}
private static class PDOMCPPBaseClone implements ICPPBase, ICPPInternalBase {
private ICPPBase base;
private IBinding baseClass = null;
public PDOMCPPBaseSpecialization(PDOMCPPBase base, IBinding baseClass) {
public PDOMCPPBaseClone(ICPPBase base) {
this.base = base;
this.baseClass = baseClass;
}
public IBinding getBaseClass() throws DOMException {
if (baseClass == null) {
return base.getBaseClass();
}
return baseClass;
}
public IName getBaseClassSpecifierName() {
@ -146,9 +158,11 @@ class PDOMCPPBase implements ICPPBase {
public boolean isVirtual() throws DOMException {
return base.isVirtual();
}
}
public ICPPBase createSpecialization(IBinding baseClass) {
return new PDOMCPPBaseSpecialization(this, baseClass);
public void setBaseClass(IBinding binding) {
baseClass = binding;
}
public Object clone() {
return new PDOMCPPBaseClone(this);
}
}
}

View file

@ -38,6 +38,7 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBase;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -85,13 +86,16 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
ICPPBase[] result = null;
for (int i = 0; i < pdomBases.length; i++) {
PDOMCPPBase pdomBase = (PDOMCPPBase) pdomBases[i];
IType type = (IType) pdomBase.getBaseClass();
type = CPPTemplates.instantiateType(type, getArgumentMap());
type = CPPSemantics.getUltimateType(type, false);
if (type instanceof IBinding) {
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result,
pdomBase.createSpecialization((IBinding) type));
ICPPBase origBase = pdomBases[i];
ICPPBase specBase = (ICPPBase) ((ICPPInternalBase)origBase).clone();
IBinding origClass = origBase.getBaseClass();
if (origClass instanceof IType) {
IType specClass = CPPTemplates.instantiateType((IType) origClass, getArgumentMap());
specClass = CPPSemantics.getUltimateType(specClass, true);
if (specClass instanceof IBinding) {
((ICPPInternalBase)specBase).setBaseClass((IBinding) specClass);
}
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBase);
}
}

View file

@ -38,6 +38,7 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBase;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -150,13 +151,16 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
ICPPBase[] result = null;
for (int i = 0; i < pdomBases.length; i++) {
PDOMCPPBase pdomBase = (PDOMCPPBase) pdomBases[i];
IType type = (IType) pdomBase.getBaseClass();
type = CPPTemplates.instantiateType(type, getArgumentMap());
type = CPPSemantics.getUltimateType(type, false);
if (type instanceof IBinding) {
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result,
pdomBase.createSpecialization((IBinding) type));
ICPPBase origBase = pdomBases[i];
ICPPBase specBase = (ICPPBase) ((ICPPInternalBase)origBase).clone();
IBinding origClass = origBase.getBaseClass();
if (origClass instanceof IType) {
IType specClass = CPPTemplates.instantiateType((IType) origClass, getArgumentMap());
specClass = CPPSemantics.getUltimateType(specClass, true);
if (specClass instanceof IBinding) {
((ICPPInternalBase)specBase).setBaseClass((IBinding) specClass);
}
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBase);
}
}