1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Patch for Bryan - 167098 - support for method and constructor templates.

This commit is contained in:
Doug Schaefer 2007-04-16 15:34:54 +00:00
parent 829bdef1da
commit a6b615d032
15 changed files with 788 additions and 57 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2007 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
@ -136,7 +136,16 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/ */
public boolean isStatic( boolean resolveAll ) { public boolean isStatic( boolean resolveAll ) {
return ((ICPPInternalFunction)getTemplateDefinition()).isStatic( resolveAll ); ICPPFunction func = (ICPPFunction) getTemplateDefinition();
if (func instanceof ICPPInternalFunction) {
return ((ICPPInternalFunction)getTemplateDefinition()).isStatic( resolveAll );
} else {
try {
return func.isStatic();
} catch (DOMException e) {
return false;
}
}
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -22,7 +22,12 @@ import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
public class InternalTemplateInstantiatorUtil { public class InternalTemplateInstantiatorUtil {
public static ICPPSpecialization deferredInstance(IType[] arguments, ICompositesFactory cf, IIndexBinding rbinding) { public static ICPPSpecialization deferredInstance(IType[] arguments, ICompositesFactory cf, IIndexBinding rbinding) {
ICPPSpecialization spec= ((ICPPInternalTemplateInstantiator)rbinding).deferredInstance(arguments); ICPPSpecialization spec= ((ICPPInternalTemplateInstantiator)rbinding).deferredInstance(arguments);
return (ICPPSpecialization) cf.getCompositeBinding((IIndexFragmentBinding)spec); if (spec instanceof IIndexFragmentBinding) {
return (ICPPSpecialization) cf.getCompositeBinding((IIndexFragmentBinding)spec);
} else {
//can result in a non-index binding
return spec;
}
} }
public static ICPPSpecialization getInstance(IType[] arguments, ICompositesFactory cf, IIndexBinding rbinding) { public static ICPPSpecialization getInstance(IType[] arguments, ICompositesFactory cf, IIndexBinding rbinding) {
@ -35,7 +40,7 @@ public class InternalTemplateInstantiatorUtil {
if (ins instanceof IIndexFragmentBinding) { if (ins instanceof IIndexFragmentBinding) {
return (IBinding) cf.getCompositeBinding((IIndexFragmentBinding)ins); return (IBinding) cf.getCompositeBinding((IIndexFragmentBinding)ins);
} else { } else {
//instantiation of an index template can result in a non-index binding //can result in a non-index binding
return ins; return ins;
} }
} }

View file

@ -72,7 +72,7 @@ import org.eclipse.core.runtime.Status;
public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
protected Database db; protected Database db;
public static final int VERSION = 29; public static final int VERSION = 30;
// 0 - the beginning of it all // 0 - the beginning of it all
// 1 - first change to kick off upgrades // 1 - first change to kick off upgrades
// 2 - added file inclusions // 2 - added file inclusions
@ -103,6 +103,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
// 27 - templates: classes, functions, limited nesting support, only template type parameters // 27 - templates: classes, functions, limited nesting support, only template type parameters
// 28 - templates: class instance/specialization base classes // 28 - templates: class instance/specialization base classes
// 29 - includes: fixed modelling of unresolved includes (180159) // 29 - includes: fixed modelling of unresolved includes (180159)
// 30 - templates: method/constructor templates, typedef specializations
public static final int LINKAGES = Database.DATA_AREA; public static final int LINKAGES = Database.DATA_AREA;
public static final int FILE_INDEX = Database.DATA_AREA + 4; public static final int FILE_INDEX = Database.DATA_AREA + 4;

View file

@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -36,7 +37,7 @@ import org.eclipse.core.runtime.CoreException;
* @author Bryan Wilkinson * @author Bryan Wilkinson
* *
*/ */
public class PDOMCPPClassTemplateSpecialization extends class PDOMCPPClassTemplateSpecialization extends
PDOMCPPClassSpecialization implements ICPPClassTemplate, ICPPInternalTemplateInstantiator { PDOMCPPClassSpecialization implements ICPPClassTemplate, ICPPInternalTemplateInstantiator {
private static final int INSTANCES = PDOMCPPClassSpecialization.RECORD_SIZE + 0; private static final int INSTANCES = PDOMCPPClassSpecialization.RECORD_SIZE + 0;
@ -74,7 +75,11 @@ public class PDOMCPPClassTemplateSpecialization extends
} }
public ICPPSpecialization deferredInstance(IType[] arguments) { public ICPPSpecialization deferredInstance(IType[] arguments) {
return getInstance( arguments ); ICPPSpecialization instance = getInstance( arguments );
if( instance == null ){
instance = new CPPDeferredClassInstance( this, arguments );
}
return instance;
} }
private static class InstanceFinder implements IPDOMVisitor { private static class InstanceFinder implements IPDOMVisitor {

View file

@ -0,0 +1,41 @@
/*******************************************************************************
* 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.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
* @author Bryan Wilkinson
*
*/
class PDOMCPPConstructorTemplate extends PDOMCPPMethodTemplate implements
ICPPConstructor {
public PDOMCPPConstructorTemplate(PDOM pdom, PDOMNode parent, ICPPConstructor method) throws CoreException {
super(pdom, parent, method);
}
public PDOMCPPConstructorTemplate(PDOM pdom, int record) {
super(pdom, record);
}
public boolean isExplicit() throws DOMException {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.EXPLICIT_CONSTRUCTOR_OFFSET);
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_CONSTRUCTOR_TEMPLATE;
}
}

View file

@ -0,0 +1,52 @@
/*******************************************************************************
* 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.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
* @author Bryan Wilkinson
*
*/
class PDOMCPPConstructorTemplateSpecialization extends
PDOMCPPMethodTemplateSpecialization implements ICPPConstructor {
/**
* The size in bytes of a PDOMCPPConstructorTemplateSpecialization record in the database.
*/
protected static final int RECORD_SIZE = PDOMCPPMethodTemplateSpecialization.RECORD_SIZE + 0;
public PDOMCPPConstructorTemplateSpecialization(PDOM pdom, PDOMNode parent, ICPPConstructor constructor, PDOMBinding specialized)
throws CoreException {
super(pdom, parent, constructor, specialized);
}
public PDOMCPPConstructorTemplateSpecialization(PDOM pdom, int bindingRecord) {
super(pdom, bindingRecord);
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_CONSTRUCTOR_TEMPLATE_SPECIALIZATION;
}
public boolean isExplicit() throws DOMException {
return ((ICPPConstructor)getSpecializedBinding()).isExplicit();
}
}

View file

@ -28,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; 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.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
@ -43,7 +44,7 @@ import org.eclipse.core.runtime.CoreException;
* @author Bryan Wilkinson * @author Bryan Wilkinson
* *
*/ */
public class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements
ICPPFunctionTemplate, ICPPInternalTemplateInstantiator, ICPPFunctionTemplate, ICPPInternalTemplateInstantiator,
IPDOMMemberOwner, ICPPTemplateScope, IIndexScope { IPDOMMemberOwner, ICPPTemplateScope, IIndexScope {
@ -101,7 +102,11 @@ public class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements
} }
public ICPPSpecialization deferredInstance(IType[] arguments) { public ICPPSpecialization deferredInstance(IType[] arguments) {
return getInstance(arguments); ICPPSpecialization instance = getInstance(arguments);
if( instance == null ){
instance = new CPPDeferredFunctionInstance( this, arguments );
}
return instance;
} }
private static class InstanceFinder implements IPDOMVisitor { private static class InstanceFinder implements IPDOMVisitor {

View file

@ -0,0 +1,146 @@
/*******************************************************************************
* 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.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
* @author Bryan Wilkinson
*
*/
class PDOMCPPFunctionTemplateSpecialization extends
PDOMCPPFunctionSpecialization implements ICPPFunctionTemplate,
ICPPInternalTemplateInstantiator, IPDOMMemberOwner {
private static final int INSTANCES = PDOMCPPFunctionSpecialization.RECORD_SIZE + 0;
private static final int SPECIALIZATIONS = PDOMCPPFunctionSpecialization.RECORD_SIZE + 4;
/**
* The size in bytes of a PDOMCPPFunctionTemplateSpecialization record in the database.
*/
protected static final int RECORD_SIZE = PDOMCPPFunctionSpecialization.RECORD_SIZE + 8;
public PDOMCPPFunctionTemplateSpecialization(PDOM pdom, PDOMNode parent, ICPPFunctionTemplate template, PDOMBinding specialized)
throws CoreException {
super(pdom, parent, (ICPPFunction) template, specialized);
}
public PDOMCPPFunctionTemplateSpecialization(PDOM pdom, int bindingRecord) {
super(pdom, bindingRecord);
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_FUNCTION_TEMPLATE_SPECIALIZATION;
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
ICPPFunctionTemplate template = (ICPPFunctionTemplate) getSpecializedBinding();
return template.getTemplateParameters();
}
public ICPPSpecialization deferredInstance(IType[] arguments) {
ICPPSpecialization instance = getInstance(arguments);
if( instance == null ){
instance = new CPPDeferredFunctionInstance( this, arguments );
}
return instance;
}
private static class InstanceFinder implements IPDOMVisitor {
private ICPPSpecialization instance = null;
private IType[] arguments;
public InstanceFinder(IType[] arguments) {
this.arguments = arguments;
}
public boolean visit(IPDOMNode node) throws CoreException {
if (instance == null && node instanceof PDOMCPPSpecialization) {
PDOMCPPSpecialization spec = (PDOMCPPSpecialization) node;
if (spec.matchesArguments(arguments)) {
instance = spec;
}
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {
}
public ICPPSpecialization getInstance() {
return instance;
}
}
public ICPPSpecialization getInstance(IType[] arguments) {
try {
InstanceFinder visitor = new InstanceFinder(arguments);
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl());
list.accept(visitor);
if (visitor.getInstance() == null) {
list = new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl());
list.accept(visitor);
}
return visitor.getInstance();
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
}
public IBinding instantiate(IType[] arguments) {
return CPPTemplates.instantiateTemplate(this, arguments, getArgumentMap());
}
public void addChild(PDOMNode child) throws CoreException {
addMember(child);
}
public void addMember(PDOMNode member) throws CoreException {
if (member instanceof ICPPTemplateInstance) {
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl());
list.addMember(member);
} else if (member instanceof ICPPSpecialization) {
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl());
list.addMember(member);
}
}
public void accept(IPDOMVisitor visitor) throws CoreException {
super.accept(visitor);
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl());
list.accept(visitor);
}
}

View file

@ -48,7 +48,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
@ -109,44 +108,51 @@ class PDOMCPPLinkage extends PDOMLinkage {
public static final int CPP_CONSTRUCTOR= PDOMLinkage.LAST_NODE_TYPE + 14; public static final int CPP_CONSTRUCTOR= PDOMLinkage.LAST_NODE_TYPE + 14;
public static final int CPP_REFERENCE_TYPE= PDOMLinkage.LAST_NODE_TYPE + 15; public static final int CPP_REFERENCE_TYPE= PDOMLinkage.LAST_NODE_TYPE + 15;
public static final int CPP_FUNCTION_TEMPLATE= PDOMLinkage.LAST_NODE_TYPE + 16; public static final int CPP_FUNCTION_TEMPLATE= PDOMLinkage.LAST_NODE_TYPE + 16;
public static final int CPP_CLASS_TEMPLATE= PDOMLinkage.LAST_NODE_TYPE + 17; public static final int CPP_METHOD_TEMPLATE= PDOMLinkage.LAST_NODE_TYPE + 17;
public static final int CPP_CLASS_TEMPLATE_PARTIAL_SPEC= PDOMLinkage.LAST_NODE_TYPE + 18; public static final int CPP_CONSTRUCTOR_TEMPLATE= PDOMLinkage.LAST_NODE_TYPE + 18;
public static final int CPP_FUNCTION_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 19; public static final int CPP_CLASS_TEMPLATE= PDOMLinkage.LAST_NODE_TYPE + 19;
public static final int CPP_DEFERRED_FUNCTION_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 20; public static final int CPP_CLASS_TEMPLATE_PARTIAL_SPEC= PDOMLinkage.LAST_NODE_TYPE + 20;
public static final int CPP_CLASS_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 21; public static final int CPP_FUNCTION_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 21;
public static final int CPP_DEFERRED_CLASS_INSTANCE= PDOMCPPLinkage.LAST_NODE_TYPE + 22; public static final int CPP_METHOD_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 22;
public static final int CPP_TEMPLATE_TYPE_PARAMETER= PDOMLinkage.LAST_NODE_TYPE + 23; public static final int CPP_DEFERRED_FUNCTION_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 23;
public static final int CPP_TEMPLATE_NON_TYPE_PARAMETER= PDOMLinkage.LAST_NODE_TYPE + 24; public static final int CPP_CLASS_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 24;
public static final int CPP_PARAMETER_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 25; public static final int CPP_DEFERRED_CLASS_INSTANCE= PDOMCPPLinkage.LAST_NODE_TYPE + 25;
public static final int CPP_FIELD_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 26; public static final int CPP_TEMPLATE_TYPE_PARAMETER= PDOMLinkage.LAST_NODE_TYPE + 26;
public static final int CPP_FUNCTION_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 27; public static final int CPP_TEMPLATE_TEMPLATE_PARAMETER= PDOMLinkage.LAST_NODE_TYPE + 27;
public static final int CPP_METHOD_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 28; public static final int CPP_TEMPLATE_NON_TYPE_PARAMETER= PDOMLinkage.LAST_NODE_TYPE + 28;
public static final int CPP_CONSTRUCTOR_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 29; public static final int CPP_PARAMETER_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 29;
public static final int CPP_CLASS_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 30; public static final int CPP_FIELD_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 30;
public static final int CPP_CLASS_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 31; public static final int CPP_FUNCTION_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 31;
public static final int CPP_METHOD_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 32;
public static final int CPP_CONSTRUCTOR_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 33;
public static final int CPP_CLASS_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 34;
public static final int CPP_FUNCTION_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 35;
public static final int CPP_METHOD_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 36;
public static final int CPP_CONSTRUCTOR_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 37;
public static final int CPP_CLASS_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 38;
public static final int CPP_TYPEDEF_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 39;
private class ConfigureTemplate implements Runnable { private class ConfigureTemplate implements Runnable {
PDOMBinding template; ICPPTemplateDefinition template;
ICPPTemplateDefinition binding;
public ConfigureTemplate(PDOMBinding template, ICPPTemplateDefinition binding) { public ConfigureTemplate(ICPPTemplateDefinition template) {
this.template = template; this.template = template;
this.binding = binding;
} }
public void run() { public void run() {
try { try {
ICPPTemplateParameter[] params = binding.getTemplateParameters(); ICPPTemplateParameter[] params = template.getTemplateParameters();
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
if (params[i] != null && !(params[i] instanceof ProblemBinding)) { if (params[i] != null && !(params[i] instanceof ProblemBinding)) {
addBinding(params[i]); addBinding(params[i]);
} }
} }
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e);
} catch (DOMException e) { } catch (DOMException e) {
CCorePlugin.log(e);
} finally { } finally {
template = null; template = null;
binding = null;
} }
} }
} }
@ -167,7 +173,9 @@ class PDOMCPPLinkage extends PDOMLinkage {
partial.addArgument(args[i]); partial.addArgument(args[i]);
} }
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e);
} catch (DOMException e) { } catch (DOMException e) {
CCorePlugin.log(e);
} finally { } finally {
partial = null; partial = null;
binding = null; binding = null;
@ -197,7 +205,9 @@ class PDOMCPPLinkage extends PDOMLinkage {
template.setFirstParameter(new PDOMCPPParameter(pdom, PDOMCPPLinkage.this, params[i], pt)); template.setFirstParameter(new PDOMCPPParameter(pdom, PDOMCPPLinkage.this, params[i], pt));
} }
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e);
} catch (DOMException e) { } catch (DOMException e) {
CCorePlugin.log(e);
} finally { } finally {
template = null; template = null;
binding = null; binding = null;
@ -289,7 +299,10 @@ class PDOMCPPLinkage extends PDOMLinkage {
parent, (ICPPClassType) binding, pdomSpecialized); parent, (ICPPClassType) binding, pdomSpecialized);
} }
} else if (binding instanceof ICPPTemplateInstance) { } else if (binding instanceof ICPPTemplateInstance) {
if (binding instanceof ICPPFunction && pdomSpecialized instanceof ICPPFunction) { if (binding instanceof ICPPMethod && pdomSpecialized instanceof ICPPMethod) {
pdomBinding = new PDOMCPPMethodInstance(pdom, parent,
(ICPPMethod) binding, pdomSpecialized);
} else if (binding instanceof ICPPFunction && pdomSpecialized instanceof ICPPFunction) {
pdomBinding = new PDOMCPPFunctionInstance(pdom, parent, pdomBinding = new PDOMCPPFunctionInstance(pdom, parent,
(ICPPFunction) binding, pdomSpecialized); (ICPPFunction) binding, pdomSpecialized);
} else if (binding instanceof ICPPClassType && pdomSpecialized instanceof ICPPClassType) { } else if (binding instanceof ICPPClassType && pdomSpecialized instanceof ICPPClassType) {
@ -309,6 +322,17 @@ class PDOMCPPLinkage extends PDOMLinkage {
} else if (binding instanceof ICPPMethod) { } else if (binding instanceof ICPPMethod) {
pdomBinding = new PDOMCPPMethodSpecialization(pdom, parent, pdomBinding = new PDOMCPPMethodSpecialization(pdom, parent,
(ICPPMethod) binding, pdomSpecialized); (ICPPMethod) binding, pdomSpecialized);
} else if (binding instanceof ICPPFunctionTemplate) {
if (binding instanceof ICPPConstructor) {
pdomBinding = new PDOMCPPConstructorTemplateSpecialization(
pdom, parent, (ICPPConstructor) binding, pdomSpecialized);
} else if (binding instanceof ICPPMethod) {
pdomBinding = new PDOMCPPMethodTemplateSpecialization(
pdom, parent, (ICPPMethod) binding, pdomSpecialized);
} else if (binding instanceof ICPPFunction) {
pdomBinding = new PDOMCPPFunctionTemplateSpecialization(
pdom, parent, (ICPPFunctionTemplate) binding, pdomSpecialized);
}
} else if (binding instanceof ICPPFunction) { } else if (binding instanceof ICPPFunction) {
pdomBinding = new PDOMCPPFunctionSpecialization(pdom, parent, pdomBinding = new PDOMCPPFunctionSpecialization(pdom, parent,
(ICPPFunction) binding, pdomSpecialized); (ICPPFunction) binding, pdomSpecialized);
@ -318,7 +342,20 @@ class PDOMCPPLinkage extends PDOMLinkage {
} else if (binding instanceof ICPPClassType) { } else if (binding instanceof ICPPClassType) {
pdomBinding = new PDOMCPPClassSpecialization(pdom, parent, pdomBinding = new PDOMCPPClassSpecialization(pdom, parent,
(ICPPClassType) binding, pdomSpecialized); (ICPPClassType) binding, pdomSpecialized);
} else if (binding instanceof ITypedef) {
pdomBinding = new PDOMCPPTypedefSpecialization(pdom, parent,
(ITypedef) binding, pdomSpecialized);
} }
} else if (binding instanceof ICPPTemplateParameter) {
if (binding instanceof ICPPTemplateTypeParameter) {
pdomBinding = new PDOMCPPTemplateTypeParameter(pdom, parent, (ICPPTemplateTypeParameter)binding);
}
// TODO other template parameter types
// else if (binding instanceof ICPPTemplateTemplateParameter) {
// pdomBinding = new PDOMCPPTemplateTemplateParameter(pdom, parent, (ICPPTemplateTemplateParameter)binding);
// } else if (binding instanceof ICPPTemplateNonTypeParameter) {
// pdomBinding = new PDOMCPPTemplateNonTypeParameter(pdom, parent, (ICPPTemplateNonTypeParameter)binding);
// }
} else if (binding instanceof ICPPField ) { } else if (binding instanceof ICPPField ) {
if (parent instanceof PDOMCPPClassType || parent instanceof PDOMCPPClassSpecialization) { if (parent instanceof PDOMCPPClassType || parent instanceof PDOMCPPClassSpecialization) {
pdomBinding = new PDOMCPPField(pdom, parent, (ICPPField) binding); pdomBinding = new PDOMCPPField(pdom, parent, (ICPPField) binding);
@ -330,9 +367,9 @@ class PDOMCPPLinkage extends PDOMLinkage {
} }
} else if (binding instanceof ICPPFunctionTemplate) { } else if (binding instanceof ICPPFunctionTemplate) {
if (binding instanceof ICPPConstructor) { if (binding instanceof ICPPConstructor) {
//TODO pdomBinding= new PDOMCPPConstructorTemplate(pdom, parent, (ICPPConstructor) binding);
} else if (binding instanceof ICPPMethod) { } else if (binding instanceof ICPPMethod) {
//TODO pdomBinding= new PDOMCPPMethodTemplate(pdom, parent, (ICPPMethod) binding);
} else if (binding instanceof ICPPFunction) { } else if (binding instanceof ICPPFunction) {
pdomBinding= new PDOMCPPFunctionTemplate(pdom, parent, (ICPPFunctionTemplate) binding); pdomBinding= new PDOMCPPFunctionTemplate(pdom, parent, (ICPPFunctionTemplate) binding);
} }
@ -364,35 +401,32 @@ class PDOMCPPLinkage extends PDOMLinkage {
(PDOMCPPEnumeration)pdomEnumeration); (PDOMCPPEnumeration)pdomEnumeration);
} else if (binding instanceof ITypedef) { } else if (binding instanceof ITypedef) {
pdomBinding = new PDOMCPPTypedef(pdom, parent, (ITypedef)binding); pdomBinding = new PDOMCPPTypedef(pdom, parent, (ITypedef)binding);
} else if (binding instanceof ICPPTemplateTypeParameter) {
pdomBinding = new PDOMCPPTemplateTypeParameter(pdom, parent, (ICPPTemplateTypeParameter)binding);
} }
if(pdomBinding!=null) { if(pdomBinding!=null) {
parent.addChild(pdomBinding); parent.addChild(pdomBinding);
} }
pushPostProcess(pdomBinding, binding); pushPostProcesses(pdomBinding, binding);
return pdomBinding; return pdomBinding;
} }
private void pushPostProcess(PDOMBinding pdomBinding, IBinding binding) throws CoreException, DOMException { private void pushPostProcesses(PDOMBinding pdomBinding, IBinding binding) throws CoreException, DOMException {
if (pdomBinding instanceof PDOMCPPClassTemplatePartialSpecialization && if (pdomBinding instanceof PDOMCPPClassTemplatePartialSpecialization &&
binding instanceof ICPPClassTemplatePartialSpecialization) { binding instanceof ICPPClassTemplatePartialSpecialization) {
PDOMCPPClassTemplatePartialSpecialization pdomSpec = (PDOMCPPClassTemplatePartialSpecialization) pdomBinding; PDOMCPPClassTemplatePartialSpecialization pdomSpec = (PDOMCPPClassTemplatePartialSpecialization) pdomBinding;
ICPPClassTemplatePartialSpecialization spec = (ICPPClassTemplatePartialSpecialization) binding; ICPPClassTemplatePartialSpecialization spec = (ICPPClassTemplatePartialSpecialization) binding;
postProcesses.add(postProcesses.size(), new ConfigurePartialSpecialization(pdomSpec, spec)); pushPostProcess(new ConfigurePartialSpecialization(pdomSpec, spec));
} }
if (pdomBinding instanceof PDOMCPPFunctionTemplate && binding instanceof ICPPFunction) { if (pdomBinding instanceof PDOMCPPFunctionTemplate && binding instanceof ICPPFunction) {
PDOMCPPFunctionTemplate pdomTemplate = (PDOMCPPFunctionTemplate) pdomBinding; PDOMCPPFunctionTemplate pdomTemplate = (PDOMCPPFunctionTemplate) pdomBinding;
ICPPFunction function = (ICPPFunction) binding; ICPPFunction function = (ICPPFunction) binding;
postProcesses.add(postProcesses.size(), new ConfigureFunctionTemplate(pdomTemplate, function)); pushPostProcess(new ConfigureFunctionTemplate(pdomTemplate, function));
} }
if ((pdomBinding instanceof PDOMCPPClassTemplate || pdomBinding instanceof PDOMCPPFunctionTemplate) && if (pdomBinding instanceof ICPPTemplateDefinition && binding instanceof ICPPTemplateDefinition) {
binding instanceof ICPPTemplateDefinition) {
ICPPTemplateDefinition template = (ICPPTemplateDefinition) binding; ICPPTemplateDefinition template = (ICPPTemplateDefinition) binding;
postProcesses.add(postProcesses.size(), new ConfigureTemplate(pdomBinding, template)); pushPostProcess(new ConfigureTemplate(template));
} }
} }
@ -421,7 +455,9 @@ class PDOMCPPLinkage extends PDOMLinkage {
if (binding instanceof ICPPClassType) if (binding instanceof ICPPClassType)
return CPP_DEFERRED_CLASS_INSTANCE; return CPP_DEFERRED_CLASS_INSTANCE;
} else if (binding instanceof ICPPTemplateInstance) { } else if (binding instanceof ICPPTemplateInstance) {
if (binding instanceof ICPPFunction) if (binding instanceof ICPPMethod)
return CPP_METHOD_INSTANCE;
else if (binding instanceof ICPPFunction)
return CPP_FUNCTION_INSTANCE; return CPP_FUNCTION_INSTANCE;
else if (binding instanceof ICPPClassType) else if (binding instanceof ICPPClassType)
return CPP_CLASS_INSTANCE; return CPP_CLASS_INSTANCE;
@ -433,12 +469,29 @@ class PDOMCPPLinkage extends PDOMLinkage {
return CPP_CONSTRUCTOR_SPECIALIZATION; return CPP_CONSTRUCTOR_SPECIALIZATION;
else if (binding instanceof ICPPMethod) else if (binding instanceof ICPPMethod)
return CPP_METHOD_SPECIALIZATION; return CPP_METHOD_SPECIALIZATION;
else if (binding instanceof ICPPFunction) else if (binding instanceof ICPPFunctionTemplate) {
if (binding instanceof ICPPConstructor)
return CPP_CONSTRUCTOR_TEMPLATE_SPECIALIZATION;
else if (binding instanceof ICPPMethod)
return CPP_METHOD_TEMPLATE_SPECIALIZATION;
else if (binding instanceof ICPPFunction)
return CPP_FUNCTION_TEMPLATE_SPECIALIZATION;
} else if (binding instanceof ICPPFunction)
return CPP_FUNCTION_SPECIALIZATION; return CPP_FUNCTION_SPECIALIZATION;
else if (binding instanceof ICPPClassTemplate) else if (binding instanceof ICPPClassTemplate)
return CPP_CLASS_TEMPLATE_SPECIALIZATION; return CPP_CLASS_TEMPLATE_SPECIALIZATION;
else if (binding instanceof ICPPClassType) else if (binding instanceof ICPPClassType)
return CPP_CLASS_SPECIALIZATION; return CPP_CLASS_SPECIALIZATION;
else if (binding instanceof ITypedef)
return CPP_TYPEDEF_SPECIALIZATION;
} else if (binding instanceof ICPPTemplateParameter) {
if (binding instanceof ICPPTemplateTypeParameter)
return CPP_TEMPLATE_TYPE_PARAMETER;
// TODO other template parameter types
// else if (binding instanceof ICPPTemplateTemplateParameter)
// return CPP_TEMPLATE_TEMPLATE_PARAMETER;
// else if (binding instanceof ICPPTemplateNonTypeParameter)
// return CPP_TEMPLATE_NON_TYPE_PARAMETER;
} else if (binding instanceof ICPPField) } else if (binding instanceof ICPPField)
// this must be before variables // this must be before variables
return CPPFIELD; return CPPFIELD;
@ -446,13 +499,12 @@ class PDOMCPPLinkage extends PDOMLinkage {
return CPPVARIABLE; return CPPVARIABLE;
else if (binding instanceof ICPPFunctionTemplate) { else if (binding instanceof ICPPFunctionTemplate) {
// this must be before functions // this must be before functions
if (binding instanceof ICPPConstructor) { if (binding instanceof ICPPConstructor)
//TODO return CPP_CONSTRUCTOR_TEMPLATE;
} else if (binding instanceof ICPPMethod) { else if (binding instanceof ICPPMethod)
//TODO return CPP_METHOD_TEMPLATE;
} else if (binding instanceof ICPPFunction) { else if (binding instanceof ICPPFunction)
return CPP_FUNCTION_TEMPLATE; return CPP_FUNCTION_TEMPLATE;
}
} else if (binding instanceof ICPPConstructor) } else if (binding instanceof ICPPConstructor)
// before methods // before methods
return CPP_CONSTRUCTOR; return CPP_CONSTRUCTOR;
@ -476,10 +528,6 @@ class PDOMCPPLinkage extends PDOMLinkage {
return CPPENUMERATOR; return CPPENUMERATOR;
else if (binding instanceof ITypedef) else if (binding instanceof ITypedef)
return CPPTYPEDEF; return CPPTYPEDEF;
else if (binding instanceof ICPPTemplateTypeParameter)
return CPP_TEMPLATE_TYPE_PARAMETER;
else if (binding instanceof ICPPTemplateNonTypeParameter)
return CPP_TEMPLATE_NON_TYPE_PARAMETER;
return 0; return 0;
} }
@ -557,6 +605,10 @@ class PDOMCPPLinkage extends PDOMLinkage {
} }
} }
private void pushPostProcess(Runnable process) {
postProcesses.add(postProcesses.size(), process);
}
private Runnable popPostProcess() { private Runnable popPostProcess() {
return (Runnable) postProcesses.remove(postProcesses.size() - 1); return (Runnable) postProcesses.remove(postProcesses.size() - 1);
} }
@ -598,12 +650,18 @@ class PDOMCPPLinkage extends PDOMLinkage {
return new PDOMCPPReferenceType(pdom, record); return new PDOMCPPReferenceType(pdom, record);
case CPP_FUNCTION_TEMPLATE: case CPP_FUNCTION_TEMPLATE:
return new PDOMCPPFunctionTemplate(pdom, record); return new PDOMCPPFunctionTemplate(pdom, record);
case CPP_METHOD_TEMPLATE:
return new PDOMCPPMethodTemplate(pdom, record);
case CPP_CONSTRUCTOR_TEMPLATE:
return new PDOMCPPConstructorTemplate(pdom, record);
case CPP_CLASS_TEMPLATE: case CPP_CLASS_TEMPLATE:
return new PDOMCPPClassTemplate(pdom, record); return new PDOMCPPClassTemplate(pdom, record);
case CPP_CLASS_TEMPLATE_PARTIAL_SPEC: case CPP_CLASS_TEMPLATE_PARTIAL_SPEC:
return new PDOMCPPClassTemplatePartialSpecialization(pdom, record); return new PDOMCPPClassTemplatePartialSpecialization(pdom, record);
case CPP_FUNCTION_INSTANCE: case CPP_FUNCTION_INSTANCE:
return new PDOMCPPFunctionInstance(pdom, record); return new PDOMCPPFunctionInstance(pdom, record);
case CPP_METHOD_INSTANCE:
return new PDOMCPPMethodInstance(pdom, record);
case CPP_DEFERRED_FUNCTION_INSTANCE: case CPP_DEFERRED_FUNCTION_INSTANCE:
return new PDOMCPPDeferredFunctionInstance(pdom, record); return new PDOMCPPDeferredFunctionInstance(pdom, record);
case CPP_CLASS_INSTANCE: case CPP_CLASS_INSTANCE:
@ -612,6 +670,11 @@ class PDOMCPPLinkage extends PDOMLinkage {
return new PDOMCPPDeferredClassInstance(pdom, record); return new PDOMCPPDeferredClassInstance(pdom, record);
case CPP_TEMPLATE_TYPE_PARAMETER: case CPP_TEMPLATE_TYPE_PARAMETER:
return new PDOMCPPTemplateTypeParameter(pdom, record); return new PDOMCPPTemplateTypeParameter(pdom, record);
// TODO other template parameter types
// case CPP_TEMPLATE_TEMPLATE_PARAMETER:
// return new PDOMCPPTemplateTemplateParameter(pdom, record);
// case CPP_TEMPLATE_NON_TYPE_PARAMETER:
// return new PDOMCPPTemplateNonTypeParameter(pdom, record);
case CPP_FIELD_SPECIALIZATION: case CPP_FIELD_SPECIALIZATION:
return new PDOMCPPFieldSpecialization(pdom, record); return new PDOMCPPFieldSpecialization(pdom, record);
case CPP_FUNCTION_SPECIALIZATION: case CPP_FUNCTION_SPECIALIZATION:
@ -622,8 +685,16 @@ class PDOMCPPLinkage extends PDOMLinkage {
return new PDOMCPPConstructorSpecialization(pdom, record); return new PDOMCPPConstructorSpecialization(pdom, record);
case CPP_CLASS_SPECIALIZATION: case CPP_CLASS_SPECIALIZATION:
return new PDOMCPPClassSpecialization(pdom, record); return new PDOMCPPClassSpecialization(pdom, record);
case CPP_FUNCTION_TEMPLATE_SPECIALIZATION:
return new PDOMCPPFunctionTemplateSpecialization(pdom, record);
case CPP_METHOD_TEMPLATE_SPECIALIZATION:
return new PDOMCPPMethodTemplateSpecialization(pdom, record);
case CPP_CONSTRUCTOR_TEMPLATE_SPECIALIZATION:
return new PDOMCPPConstructorTemplateSpecialization(pdom, record);
case CPP_CLASS_TEMPLATE_SPECIALIZATION: case CPP_CLASS_TEMPLATE_SPECIALIZATION:
return new PDOMCPPClassTemplateSpecialization(pdom, record); return new PDOMCPPClassTemplateSpecialization(pdom, record);
case CPP_TYPEDEF_SPECIALIZATION:
return new PDOMCPPTypedefSpecialization(pdom, record);
default: default:
return super.getNode(record); return super.getNode(record);
} }

View file

@ -0,0 +1,69 @@
/*******************************************************************************
* 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.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
* @author Bryan Wilkinson
*
*/
class PDOMCPPMethodInstance extends PDOMCPPFunctionInstance implements
ICPPMethod {
/**
* The size in bytes of a PDOMCPPMethodInstance record in the database.
*/
protected static final int RECORD_SIZE = PDOMCPPFunctionInstance.RECORD_SIZE + 0;
public PDOMCPPMethodInstance(PDOM pdom, PDOMNode parent, ICPPMethod method, PDOMBinding instantiated)
throws CoreException {
super(pdom, parent, method, instantiated);
}
public PDOMCPPMethodInstance(PDOM pdom, int bindingRecord) {
super(pdom, bindingRecord);
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_METHOD_INSTANCE;
}
public boolean isDestructor() throws DOMException {
return ((ICPPMethod)getTemplateDefinition()).isDestructor();
}
public boolean isImplicit() {
return ((ICPPMethod)getTemplateDefinition()).isImplicit();
}
public boolean isVirtual() throws DOMException {
return ((ICPPMethod)getTemplateDefinition()).isVirtual();
}
public ICPPClassType getClassOwner() throws DOMException {
return ((ICPPMethod)getTemplateDefinition()).getClassOwner();
}
public int getVisibility() throws DOMException {
return ((ICPPMethod)getTemplateDefinition()).getVisibility();
}
}

View file

@ -0,0 +1,125 @@
/*******************************************************************************
* 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.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.Util;
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.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation;
import org.eclipse.core.runtime.CoreException;
/**
* @author Bryan Wilkinson
*
*/
class PDOMCPPMethodTemplate extends PDOMCPPFunctionTemplate implements
ICPPMethod {
/**
* Offset of remaining annotation information (relative to the beginning of
* the record).
*/
protected static final int ANNOTATION1 = PDOMCPPFunctionTemplate.RECORD_SIZE; // byte
/**
* The size in bytes of a PDOMCPPMethodTemplate record in the database.
*/
protected static final int RECORD_SIZE = PDOMCPPFunctionTemplate.RECORD_SIZE + 1;
/**
* The bit offset of CV qualifier flags within ANNOTATION1.
*/
private static final int CV_OFFSET = PDOMCPPAnnotation.MAX_EXTRA_OFFSET + 1;
public PDOMCPPMethodTemplate(PDOM pdom, PDOMNode parent,
ICPPMethod method) throws CoreException {
super(pdom, parent, (ICPPFunctionTemplate) method);
Database db = pdom.getDB();
try {
ICPPFunctionType type = (ICPPFunctionType) method.getType();
byte annotation = 0;
annotation |= PDOMCAnnotation.encodeCVQualifiers(type) << CV_OFFSET;
annotation |= PDOMCPPAnnotation.encodeExtraAnnotation(method);
db.putByte(record + ANNOTATION1, annotation);
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
public PDOMCPPMethodTemplate(PDOM pdom, int bindingRecord) {
super(pdom, bindingRecord);
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_METHOD_TEMPLATE;
}
public boolean isDestructor() throws DOMException {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.DESTRUCTOR_OFFSET);
}
public boolean isImplicit() {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.IMPLICIT_METHOD_OFFSET);
}
public boolean isVirtual() throws DOMException {
return getBit(getByte(record + ANNOTATION1), PDOMCPPAnnotation.VIRTUAL_OFFSET);
}
public ICPPClassType getClassOwner() throws DOMException {
try {
return (ICPPClassType) getParentNode();
} catch (CoreException e) {
CCorePlugin.log(e);
return null;
}
}
public int getVisibility() throws DOMException {
return PDOMCPPAnnotation.getVisibility(getByte(record + ANNOTATION));
}
public boolean isConst() {
return getBit(getByte(record + ANNOTATION1), PDOMCAnnotation.CONST_OFFSET + CV_OFFSET);
}
public boolean isVolatile() {
return getBit(getByte(record + ANNOTATION1), PDOMCAnnotation.VOLATILE_OFFSET + CV_OFFSET);
}
public boolean isExtern() throws DOMException {
// ISO/IEC 14882:2003 9.2.6
return false;
}
public boolean isAuto() throws DOMException {
// ISO/IEC 14882:2003 9.2.6
return false;
}
public boolean isRegister() throws DOMException {
// ISO/IEC 14882:2003 9.2.6
return false;
}
}

View file

@ -0,0 +1,91 @@
/*******************************************************************************
* 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.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
* @author Bryan Wilkinson
*
*/
class PDOMCPPMethodTemplateSpecialization extends
PDOMCPPFunctionTemplateSpecialization implements ICPPMethod {
/**
* The size in bytes of a PDOMCPPMethodTemplateSpecialization record in the database.
*/
protected static final int RECORD_SIZE = PDOMCPPFunctionTemplateSpecialization.RECORD_SIZE + 0;
public PDOMCPPMethodTemplateSpecialization(PDOM pdom, PDOMNode parent, ICPPMethod method, PDOMBinding specialized)
throws CoreException {
super(pdom, parent, (ICPPFunctionTemplate) method, specialized);
}
public PDOMCPPMethodTemplateSpecialization(PDOM pdom, int bindingRecord) {
super(pdom, bindingRecord);
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_METHOD_TEMPLATE_SPECIALIZATION;
}
public boolean isDestructor() throws DOMException {
IBinding spec = getSpecializedBinding();
if (spec instanceof ICPPMethod) {
((ICPPMethod)spec).isDestructor();
}
return false;
}
public boolean isImplicit() {
IBinding spec = getSpecializedBinding();
if (spec instanceof ICPPMethod) {
((ICPPMethod)spec).isImplicit();
}
return false;
}
public boolean isVirtual() throws DOMException {
IBinding spec = getSpecializedBinding();
if (spec instanceof ICPPMethod) {
((ICPPMethod)spec).isVirtual();
}
return false;
}
public ICPPClassType getClassOwner() throws DOMException {
IBinding spec = getSpecializedBinding();
if (spec instanceof ICPPMethod) {
((ICPPMethod)spec).getClassOwner();
}
return null;
}
public int getVisibility() throws DOMException {
IBinding spec = getSpecializedBinding();
if (spec instanceof ICPPMethod) {
((ICPPMethod)spec).getVisibility();
}
return 0;
}
}

View file

@ -36,7 +36,7 @@ import org.eclipse.core.runtime.CoreException;
* *
* @author Bryan Wilkinson * @author Bryan Wilkinson
*/ */
public class PDOMCPPOverloaderUtil { class PDOMCPPOverloaderUtil {
/** /**
* Returns the signature for the binding. Returns an empty string if a * Returns the signature for the binding. Returns an empty string if a

View file

@ -0,0 +1,111 @@
/*******************************************************************************
* 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.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
* @author Bryan Wilkinson
*
*/
class PDOMCPPTypedefSpecialization extends PDOMCPPSpecialization
implements ITypedef, ITypeContainer, IIndexType {
private static final int TYPE = PDOMCPPSpecialization.RECORD_SIZE + 0;
protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 4;
public PDOMCPPTypedefSpecialization(PDOM pdom, PDOMNode parent, ITypedef typedef, PDOMBinding specialized)
throws CoreException {
super(pdom, parent, (ICPPSpecialization) typedef, specialized);
try {
IType type = typedef.getType();
PDOMNode typeNode = parent.getLinkageImpl().addType(this, type);
if (typeNode != null)
pdom.getDB().putInt(record + TYPE, typeNode.getRecord());
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
}
public PDOMCPPTypedefSpecialization(PDOM pdom, int record) {
super(pdom, record);
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_TYPEDEF_SPECIALIZATION;
}
public IType getType() throws DOMException {
try {
PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + TYPE));
return node instanceof IType ? (IType)node : null;
} catch (CoreException e) {
CCorePlugin.log(e);
return null;
}
}
public boolean isSameType(IType o) {
if( o.equals(this) )
return true;
if( o instanceof ITypedef )
try {
IType t = getType();
if( t != null )
return t.isSameType( ((ITypedef)o).getType());
return false;
} catch ( DOMException e ) {
return false;
}
try {
IType t = getType();
if( t != null )
return t.isSameType( o );
} catch ( DOMException e ) {
return false;
}
return false;
}
public void setType(IType type) { fail(); }
/* (non-Javadoc)
* @see java.lang.Object#clone()
*/
public Object clone() {
IType t = null;
try {
t = (IType) super.clone();
} catch ( CloneNotSupportedException e ) {
//not going to happen
}
return t;
}
}

View file

@ -650,7 +650,7 @@ public class CompletionTests extends AbstractContentAssistTest {
} }
//void gfunc(){C3 c3; c3.t/*cursor*/ //void gfunc(){C3 c3; c3.t/*cursor*/
public void _testTemplateMethod() throws Exception { public void testTemplateMethod() throws Exception {
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=172436 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=172436
final String[] expected= { final String[] expected= {
"tConvert(void)" "tConvert(void)"