1
/*******************************************************************************
2
* Copyright (c) 2005, 2010 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Andrew Niefer (IBM) - Initial API and implementation
10
* Bryan Wilkinson (QNX)
11
* Andrew Ferguson (Symbian)
12
* Sergey Prigogin (Google)
13
* Markus Schorn (Wind River Systems)
14
*******************************************************************************/
15
package org.eclipse.cdt.internal.core.dom.parser.cpp;
17
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
18
import org.eclipse.cdt.core.dom.ast.IBinding;
19
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
20
import org.eclipse.cdt.core.dom.ast.IType;
21
import org.eclipse.cdt.core.dom.ast.ITypedef;
22
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
23
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
24
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
25
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
26
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
27
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
30
* The result of instantiating a class template.
32
public class CPPClassInstance extends CPPClassSpecialization implements ICPPTemplateInstance {
33
private ICPPTemplateArgument[] arguments;
35
public CPPClassInstance(ICPPClassType orig, IBinding owner, CPPTemplateParameterMap argMap, ICPPTemplateArgument[] args) {
36
super(orig, owner, argMap);
40
public ICPPTemplateDefinition getTemplateDefinition() {
41
return (ICPPTemplateDefinition) getSpecializedBinding();
44
public ICPPTemplateArgument[] getTemplateArguments() {
48
public boolean isExplicitSpecialization() {
49
return !(getCompositeScope() instanceof ICPPClassSpecializationScope);
53
public IType[] getArguments() {
54
return CPPTemplates.getArguments(getTemplateArguments());
58
* For debug purposes only
61
public String toString() {
62
return getName() + " " + ASTTypeUtil.getArgumentListString(arguments, true); //$NON-NLS-1$
66
public boolean equals(Object obj) {
67
return obj instanceof ICPPClassType && isSameType((ICPPClassType) obj);
71
public boolean isSameType(IType type) {
74
if (type instanceof ITypedef)
75
return type.isSameType(this);
77
return isSameClassInstance(this, type);
80
public static boolean isSameClassInstance(ICPPClassSpecialization classInstance, IType type) {
81
assert classInstance instanceof ICPPTemplateInstance;
83
// require a class instance
84
if (!(type instanceof ICPPClassSpecialization) || !(type instanceof ICPPTemplateInstance) ||
85
type instanceof IProblemBinding) {
89
final ICPPClassSpecialization classSpec2 = (ICPPClassSpecialization) type;
90
final ICPPClassType orig1= classInstance.getSpecializedBinding();
91
final ICPPClassType orig2= classSpec2.getSpecializedBinding();
92
if (!orig1.isSameType(orig2))
95
return CPPTemplates.haveSameArguments((ICPPTemplateInstance) classInstance, (ICPPTemplateInstance) type);