mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 10:25:32 +02:00
Added toString method.
This commit is contained in:
parent
8a38316b33
commit
cd0bd1eebb
2 changed files with 81 additions and 68 deletions
|
@ -13,6 +13,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
@ -51,11 +52,13 @@ import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
*/
|
*/
|
||||||
public class CPPClassTemplate extends CPPTemplateDefinition implements
|
public class CPPClassTemplate extends CPPTemplateDefinition implements
|
||||||
ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTemplate, ICPPInternalClassTypeMixinHost {
|
ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTemplate,
|
||||||
|
ICPPInternalClassTypeMixinHost {
|
||||||
|
|
||||||
public static class CPPClassTemplateDelegate extends CPPClassType.CPPClassTypeDelegate implements ICPPClassTemplate, ICPPInternalClassTemplate {
|
public static class CPPClassTemplateDelegate extends CPPClassType.CPPClassTypeDelegate
|
||||||
public CPPClassTemplateDelegate( ICPPUsingDeclaration usingDecl, ICPPClassType cls ) {
|
implements ICPPClassTemplate, ICPPInternalClassTemplate {
|
||||||
super( usingDecl, cls );
|
public CPPClassTemplateDelegate(ICPPUsingDeclaration usingDecl, ICPPClassType cls) {
|
||||||
|
super(usingDecl, cls);
|
||||||
}
|
}
|
||||||
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() throws DOMException {
|
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() throws DOMException {
|
||||||
return ((ICPPClassTemplate)getBinding()).getPartialSpecializations();
|
return ((ICPPClassTemplate)getBinding()).getPartialSpecializations();
|
||||||
|
@ -63,31 +66,31 @@ ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTempla
|
||||||
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
|
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
|
||||||
return ((ICPPClassTemplate)getBinding()).getTemplateParameters();
|
return ((ICPPClassTemplate)getBinding()).getTemplateParameters();
|
||||||
}
|
}
|
||||||
public void addSpecialization( IType[] arguments, ICPPSpecialization specialization ) {
|
public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) {
|
||||||
final IBinding binding = getBinding();
|
final IBinding binding = getBinding();
|
||||||
if (binding instanceof ICPPInternalBinding) {
|
if (binding instanceof ICPPInternalBinding) {
|
||||||
((ICPPInternalTemplate)binding).addSpecialization( arguments, specialization );
|
((ICPPInternalTemplate)binding).addSpecialization(arguments, specialization);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public IBinding instantiate( IType[] arguments ) {
|
public IBinding instantiate(IType[] arguments) {
|
||||||
return ((ICPPInternalTemplateInstantiator)getBinding()).instantiate( arguments );
|
return ((ICPPInternalTemplateInstantiator)getBinding()).instantiate(arguments);
|
||||||
}
|
}
|
||||||
public ICPPSpecialization deferredInstance( IType[] arguments ) {
|
public ICPPSpecialization deferredInstance(IType[] arguments) {
|
||||||
return ((ICPPInternalTemplateInstantiator)getBinding()).deferredInstance( arguments );
|
return ((ICPPInternalTemplateInstantiator)getBinding()).deferredInstance(arguments);
|
||||||
}
|
}
|
||||||
public ICPPSpecialization getInstance( IType[] arguments ) {
|
public ICPPSpecialization getInstance(IType[] arguments) {
|
||||||
return ((ICPPInternalTemplateInstantiator)getBinding()).getInstance( arguments );
|
return ((ICPPInternalTemplateInstantiator)getBinding()).getInstance(arguments);
|
||||||
}
|
}
|
||||||
public void addPartialSpecialization( ICPPClassTemplatePartialSpecialization spec ) {
|
public void addPartialSpecialization(ICPPClassTemplatePartialSpecialization spec) {
|
||||||
final IBinding binding = getBinding();
|
final IBinding binding = getBinding();
|
||||||
if (binding instanceof ICPPInternalClassTemplate) {
|
if (binding instanceof ICPPInternalClassTemplate) {
|
||||||
((ICPPInternalClassTemplate)getBinding()).addPartialSpecialization( spec );
|
((ICPPInternalClassTemplate)getBinding()).addPartialSpecialization(spec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FindDefinitionAction extends CPPASTVisitor {
|
private class FindDefinitionAction extends CPPASTVisitor {
|
||||||
private char [] nameArray = CPPClassTemplate.this.getNameCharArray();
|
private char[] nameArray = CPPClassTemplate.this.getNameCharArray();
|
||||||
public IASTName result = null;
|
public IASTName result = null;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -97,27 +100,26 @@ ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTempla
|
||||||
shouldVisitDeclarators = true;
|
shouldVisitDeclarators = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int visit( IASTName name ){
|
public int visit(IASTName name) {
|
||||||
if( name instanceof ICPPASTTemplateId || name instanceof ICPPASTQualifiedName )
|
if (name instanceof ICPPASTTemplateId || name instanceof ICPPASTQualifiedName)
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
char [] c = name.toCharArray();
|
char[] c = name.toCharArray();
|
||||||
if( name.getParent() instanceof ICPPASTTemplateId )
|
if (name.getParent() instanceof ICPPASTTemplateId)
|
||||||
name = (IASTName) name.getParent();
|
name = (IASTName) name.getParent();
|
||||||
if( name.getParent() instanceof ICPPASTQualifiedName ){
|
if (name.getParent() instanceof ICPPASTQualifiedName) {
|
||||||
IASTName [] ns = ((ICPPASTQualifiedName)name.getParent()).getNames();
|
IASTName[] ns = ((ICPPASTQualifiedName)name.getParent()).getNames();
|
||||||
if( ns[ ns.length - 1 ] != name )
|
if (ns[ns.length - 1] != name)
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
name = (IASTName) name.getParent();
|
name = (IASTName) name.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( name.getParent() instanceof ICPPASTCompositeTypeSpecifier &&
|
if (name.getParent() instanceof ICPPASTCompositeTypeSpecifier &&
|
||||||
CharArrayUtils.equals( c, nameArray ) )
|
CharArrayUtils.equals(c, nameArray)) {
|
||||||
{
|
|
||||||
IBinding binding = name.resolveBinding();
|
IBinding binding = name.resolveBinding();
|
||||||
if( binding == CPPClassTemplate.this ){
|
if (binding == CPPClassTemplate.this) {
|
||||||
if( name instanceof ICPPASTQualifiedName ){
|
if (name instanceof ICPPASTQualifiedName) {
|
||||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||||
name = ns[ ns.length - 1 ];
|
name = ns[ns.length - 1];
|
||||||
}
|
}
|
||||||
result = name;
|
result = name;
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
|
@ -126,18 +128,18 @@ ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTempla
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int visit( IASTDeclaration declaration ){
|
public int visit(IASTDeclaration declaration) {
|
||||||
if(declaration instanceof IASTSimpleDeclaration || declaration instanceof ICPPASTTemplateDeclaration)
|
if (declaration instanceof IASTSimpleDeclaration || declaration instanceof ICPPASTTemplateDeclaration)
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
public int visit( IASTDeclSpecifier declSpec ){
|
public int visit(IASTDeclSpecifier declSpec) {
|
||||||
return (declSpec instanceof ICPPASTCompositeTypeSpecifier ) ? PROCESS_CONTINUE : PROCESS_SKIP;
|
return (declSpec instanceof ICPPASTCompositeTypeSpecifier) ? PROCESS_CONTINUE : PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
public int visit( IASTDeclarator declarator ) { return PROCESS_SKIP; }
|
public int visit(IASTDeclarator declarator) { return PROCESS_SKIP; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICPPClassTemplatePartialSpecialization [] partialSpecializations = null;
|
private ICPPClassTemplatePartialSpecialization[] partialSpecializations = null;
|
||||||
private ClassTypeMixin mixin;
|
private ClassTypeMixin mixin;
|
||||||
|
|
||||||
public CPPClassTemplate(IASTName name) {
|
public CPPClassTemplate(IASTName name) {
|
||||||
|
@ -145,41 +147,41 @@ ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTempla
|
||||||
this.mixin= new ClassTypeMixin(this);
|
this.mixin= new ClassTypeMixin(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICPPSpecialization deferredInstance( IType [] arguments ){
|
public ICPPSpecialization deferredInstance(IType[] arguments) {
|
||||||
ICPPSpecialization instance = getInstance( arguments );
|
ICPPSpecialization instance = getInstance(arguments);
|
||||||
if( instance == null ){
|
if (instance == null) {
|
||||||
instance = new CPPDeferredClassInstance( this, arguments );
|
instance = new CPPDeferredClassInstance(this, arguments);
|
||||||
addSpecialization( arguments, instance );
|
addSpecialization(arguments, instance);
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkForDefinition(){
|
public void checkForDefinition() {
|
||||||
FindDefinitionAction action = new FindDefinitionAction();
|
FindDefinitionAction action = new FindDefinitionAction();
|
||||||
IASTNode node = CPPVisitor.getContainingBlockItem( declarations[0] ).getParent();
|
IASTNode node = CPPVisitor.getContainingBlockItem(declarations[0]).getParent();
|
||||||
while( node instanceof ICPPASTTemplateDeclaration )
|
while(node instanceof ICPPASTTemplateDeclaration)
|
||||||
node = node.getParent();
|
node = node.getParent();
|
||||||
node.accept( action );
|
node.accept(action);
|
||||||
definition = action.result;
|
definition = action.result;
|
||||||
|
|
||||||
if( definition == null ){
|
if (definition == null) {
|
||||||
node.getTranslationUnit().accept( action );
|
node.getTranslationUnit().accept(action);
|
||||||
definition = action.result;
|
definition = action.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPartialSpecialization( ICPPClassTemplatePartialSpecialization spec ){
|
public void addPartialSpecialization(ICPPClassTemplatePartialSpecialization spec) {
|
||||||
partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.append( ICPPClassTemplatePartialSpecialization.class, partialSpecializations, spec );
|
partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.append(ICPPClassTemplatePartialSpecialization.class, partialSpecializations, spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){
|
public ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier() {
|
||||||
if( definition != null ){
|
if (definition != null) {
|
||||||
IASTNode node = definition.getParent();
|
IASTNode node = definition.getParent();
|
||||||
if( node instanceof ICPPASTQualifiedName )
|
if (node instanceof ICPPASTQualifiedName)
|
||||||
node = node.getParent();
|
node = node.getParent();
|
||||||
if( node instanceof ICPPASTCompositeTypeSpecifier )
|
if (node instanceof ICPPASTCompositeTypeSpecifier)
|
||||||
return (ICPPASTCompositeTypeSpecifier) node;
|
return (ICPPASTCompositeTypeSpecifier) node;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -202,7 +204,7 @@ ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTempla
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getKey() {
|
public int getKey() {
|
||||||
if( definition != null ) {
|
if (definition != null) {
|
||||||
ICPPASTCompositeTypeSpecifier cts= getCompositeTypeSpecifier();
|
ICPPASTCompositeTypeSpecifier cts= getCompositeTypeSpecifier();
|
||||||
if (cts != null) {
|
if (cts != null) {
|
||||||
return cts.getKey();
|
return cts.getKey();
|
||||||
|
@ -213,9 +215,9 @@ ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTempla
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( declarations != null && declarations.length > 0 ){
|
if (declarations != null && declarations.length > 0) {
|
||||||
IASTNode n = declarations[0].getParent();
|
IASTNode n = declarations[0].getParent();
|
||||||
if( n instanceof ICPPASTElaboratedTypeSpecifier ){
|
if (n instanceof ICPPASTElaboratedTypeSpecifier) {
|
||||||
return ((ICPPASTElaboratedTypeSpecifier)n).getKind();
|
return ((ICPPASTElaboratedTypeSpecifier)n).getKind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,20 +225,16 @@ ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTempla
|
||||||
return ICPPASTElaboratedTypeSpecifier.k_class;
|
return ICPPASTElaboratedTypeSpecifier.k_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() {
|
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() {
|
||||||
partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.trim( ICPPClassTemplatePartialSpecialization.class, partialSpecializations );
|
partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.trim(ICPPClassTemplatePartialSpecialization.class, partialSpecializations);
|
||||||
return partialSpecializations;
|
return partialSpecializations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICPPDelegate createDelegate( ICPPUsingDeclaration usingDecl ) {
|
public ICPPDelegate createDelegate(ICPPUsingDeclaration usingDecl) {
|
||||||
return new CPPClassTemplateDelegate( usingDecl, this );
|
return new CPPClassTemplateDelegate(usingDecl, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* */
|
public boolean isSameType(IType type) {
|
||||||
|
|
||||||
public boolean isSameType( IType type ) {
|
|
||||||
if (type == this)
|
if (type == this)
|
||||||
return true;
|
return true;
|
||||||
if (type instanceof ITypedef || type instanceof IIndexType || type instanceof ICPPDelegate)
|
if (type instanceof ITypedef || type instanceof IIndexType || type instanceof ICPPDelegate)
|
||||||
|
@ -244,7 +242,7 @@ ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTempla
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICPPBase [] getBases() {
|
public ICPPBase[] getBases() {
|
||||||
return mixin.getBases();
|
return mixin.getBases();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,4 +293,11 @@ ICPPClassTemplate, ICPPClassType, ICPPInternalClassType, ICPPInternalClassTempla
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* For debug purposes only
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
return ASTTypeUtil.getType(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -13,6 +13,7 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||||
|
@ -24,10 +25,10 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
*/
|
*/
|
||||||
public abstract class CPPInstance extends CPPSpecialization implements ICPPTemplateInstance {
|
public abstract class CPPInstance extends CPPSpecialization implements ICPPTemplateInstance {
|
||||||
private IType [] arguments;
|
private IType[] arguments;
|
||||||
|
|
||||||
public CPPInstance( ICPPScope scope, IBinding orig, ObjectMap argMap, IType [] arguments ){
|
public CPPInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] arguments) {
|
||||||
super( orig, scope, argMap );
|
super(orig, scope, argMap);
|
||||||
this.arguments = arguments;
|
this.arguments = arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,4 +45,11 @@ public abstract class CPPInstance extends CPPSpecialization implements ICPPTempl
|
||||||
public IType[] getArguments() {
|
public IType[] getArguments() {
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* For debug purposes only
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
|
return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue