mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +02:00
Bug 167098 - Patch for Bryan - Add support for C++ constructor instances.
This commit is contained in:
parent
8c367212a0
commit
f1bffec1a7
6 changed files with 144 additions and 24 deletions
|
@ -0,0 +1,40 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author Bryan Wilkinson
|
||||
*
|
||||
*/
|
||||
public class CPPConstructorInstance extends CPPMethodInstance implements
|
||||
ICPPConstructor {
|
||||
|
||||
/**
|
||||
* @param scope
|
||||
* @param orig
|
||||
* @param argMap
|
||||
* @param args
|
||||
*/
|
||||
public CPPConstructorInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) {
|
||||
super(scope, orig, argMap, args);
|
||||
}
|
||||
|
||||
public boolean isExplicit() throws DOMException {
|
||||
return ((ICPPConstructor)getTemplateDefinition()).isExplicit();
|
||||
}
|
||||
}
|
|
@ -638,6 +638,11 @@ public class CPPSemantics {
|
|||
return binding;
|
||||
}
|
||||
|
||||
protected static IBinding postResolution( IBinding binding, IASTName name) {
|
||||
LookupData data = createLookupData( name, true );
|
||||
return postResolution(binding, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param binding
|
||||
* @param data
|
||||
|
@ -702,10 +707,10 @@ public class CPPSemantics {
|
|||
}
|
||||
if( binding instanceof ICPPClassType && data.considerConstructors ){
|
||||
ICPPClassType cls = (ICPPClassType) binding;
|
||||
if( data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPInternalTemplate ){
|
||||
if( data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition ){
|
||||
ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName;
|
||||
IType [] args = CPPTemplates.createTypeArray( id.getTemplateArguments() );
|
||||
IBinding inst = ((ICPPInternalTemplate)cls).instantiate( args );
|
||||
IBinding inst = ((ICPPInternalTemplateInstantiator)cls).instantiate( args );
|
||||
cls = inst instanceof ICPPClassType ? (ICPPClassType)inst : cls;
|
||||
}
|
||||
if( cls != null ){
|
||||
|
|
|
@ -276,7 +276,8 @@ public class CPPTemplates {
|
|||
if( template != null && template instanceof ICPPInternalTemplateInstantiator){
|
||||
IASTNode [] args = id.getTemplateArguments();
|
||||
IType [] types = CPPTemplates.createTypeArray( args );
|
||||
return ((ICPPInternalTemplateInstantiator) template).instantiate(types);
|
||||
template = ((ICPPInternalTemplateInstantiator) template).instantiate(types);
|
||||
return CPPSemantics.postResolution(template, id);
|
||||
}
|
||||
} else {
|
||||
//functions are instatiated as part of the resolution process
|
||||
|
@ -616,6 +617,8 @@ public class CPPTemplates {
|
|||
ICPPTemplateInstance instance = null;
|
||||
if( decl instanceof ICPPClassType ){
|
||||
instance = new CPPClassInstance( scope, decl, argMap, args );
|
||||
} else if( decl instanceof ICPPConstructor ) {
|
||||
instance = new CPPConstructorInstance( scope, decl, argMap, args );
|
||||
} else if( decl instanceof ICPPMethod ) {
|
||||
instance = new CPPMethodInstance( scope, decl, argMap, args );
|
||||
} else if( decl instanceof ICPPFunction ) {
|
||||
|
@ -1493,6 +1496,18 @@ public class CPPTemplates {
|
|||
if( map != null && pType != null && map.containsKey( pType ) ){
|
||||
pType = (IType) map.get( pType );
|
||||
}
|
||||
|
||||
//14.1s8 function to pointer and array to pointer conversions
|
||||
if( pType instanceof IFunctionType )
|
||||
{
|
||||
pType = new CPPPointerType( pType );
|
||||
} else if( pType instanceof IArrayType ){
|
||||
try {
|
||||
pType = new CPPPointerType( ((IArrayType)pType).getType() );
|
||||
} catch (DOMException e) {
|
||||
pType = e.getProblem();
|
||||
}
|
||||
}
|
||||
Cost cost = CPPSemantics.checkStandardConversionSequence( argument, pType );
|
||||
|
||||
if( cost == null || cost.rank == Cost.NO_MATCH_RANK ){
|
||||
|
|
|
@ -75,7 +75,7 @@ import org.eclipse.core.runtime.Status;
|
|||
public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||
protected Database db;
|
||||
|
||||
public static final int VERSION = 32;
|
||||
public static final int VERSION = 33;
|
||||
// 0 - the beginning of it all
|
||||
// 1 - first change to kick off upgrades
|
||||
// 2 - added file inclusions
|
||||
|
@ -109,7 +109,8 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
// 30 - templates: method/constructor templates, typedef specializations
|
||||
// 31 - macros: added file locations
|
||||
// 32 - support standalone function types (181936)
|
||||
|
||||
// 33 - templates: constructor instances
|
||||
|
||||
public static final int LINKAGES = Database.DATA_AREA;
|
||||
public static final int FILE_INDEX = Database.DATA_AREA + 4;
|
||||
public static final int PROPERTIES = Database.DATA_AREA + 8;
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*******************************************************************************
|
||||
* 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.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
|
||||
*
|
||||
*/
|
||||
public class PDOMCPPConstructorInstance extends PDOMCPPMethodInstance implements
|
||||
ICPPConstructor {
|
||||
|
||||
/**
|
||||
* The size in bytes of a PDOMCPPConstructorInstance record in the database.
|
||||
*/
|
||||
protected static final int RECORD_SIZE = PDOMCPPMethodInstance.RECORD_SIZE + 0;
|
||||
|
||||
public PDOMCPPConstructorInstance(PDOM pdom, PDOMNode parent, ICPPMethod method, PDOMBinding instantiated)
|
||||
throws CoreException {
|
||||
super(pdom, parent, method, instantiated);
|
||||
}
|
||||
|
||||
public PDOMCPPConstructorInstance(PDOM pdom, int bindingRecord) {
|
||||
super(pdom, bindingRecord);
|
||||
}
|
||||
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public int getNodeType() {
|
||||
return PDOMCPPLinkage.CPP_METHOD_INSTANCE;
|
||||
}
|
||||
|
||||
public boolean isExplicit() throws DOMException {
|
||||
return ((ICPPConstructor)getTemplateDefinition()).isExplicit();
|
||||
}
|
||||
}
|
|
@ -114,24 +114,23 @@ class PDOMCPPLinkage extends PDOMLinkage {
|
|||
public static final int CPP_CLASS_TEMPLATE_PARTIAL_SPEC= PDOMLinkage.LAST_NODE_TYPE + 20;
|
||||
public static final int CPP_FUNCTION_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 21;
|
||||
public static final int CPP_METHOD_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 22;
|
||||
public static final int CPP_DEFERRED_FUNCTION_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 23;
|
||||
public static final int CPP_CLASS_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 24;
|
||||
public static final int CPP_DEFERRED_CLASS_INSTANCE= PDOMCPPLinkage.LAST_NODE_TYPE + 25;
|
||||
public static final int CPP_TEMPLATE_TYPE_PARAMETER= PDOMLinkage.LAST_NODE_TYPE + 26;
|
||||
public static final int CPP_TEMPLATE_TEMPLATE_PARAMETER= PDOMLinkage.LAST_NODE_TYPE + 27;
|
||||
public static final int CPP_TEMPLATE_NON_TYPE_PARAMETER= PDOMLinkage.LAST_NODE_TYPE + 28;
|
||||
public static final int CPP_PARAMETER_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 29;
|
||||
public static final int CPP_FIELD_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 30;
|
||||
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;
|
||||
public static final int CPP_FUNCTION_TYPE= PDOMLinkage.LAST_NODE_TYPE + 40;
|
||||
public static final int CPP_CONSTRUCTOR_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 23;
|
||||
public static final int CPP_DEFERRED_FUNCTION_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 24;
|
||||
public static final int CPP_CLASS_INSTANCE= PDOMLinkage.LAST_NODE_TYPE + 25;
|
||||
public static final int CPP_DEFERRED_CLASS_INSTANCE= PDOMCPPLinkage.LAST_NODE_TYPE + 26;
|
||||
public static final int CPP_PARAMETER_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 27;
|
||||
public static final int CPP_FIELD_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 28;
|
||||
public static final int CPP_FUNCTION_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 29;
|
||||
public static final int CPP_METHOD_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 30;
|
||||
public static final int CPP_CONSTRUCTOR_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 31;
|
||||
public static final int CPP_CLASS_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 32;
|
||||
public static final int CPP_FUNCTION_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 33;
|
||||
public static final int CPP_METHOD_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 34;
|
||||
public static final int CPP_CONSTRUCTOR_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 35;
|
||||
public static final int CPP_CLASS_TEMPLATE_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 36;
|
||||
public static final int CPP_TYPEDEF_SPECIALIZATION= PDOMLinkage.LAST_NODE_TYPE + 37;
|
||||
public static final int CPP_TEMPLATE_TYPE_PARAMETER= PDOMLinkage.LAST_NODE_TYPE + 38;
|
||||
public static final int CPP_FUNCTION_TYPE= PDOMLinkage.LAST_NODE_TYPE + 39;
|
||||
|
||||
private class ConfigureTemplate implements Runnable {
|
||||
ICPPTemplateDefinition template;
|
||||
|
@ -291,7 +290,10 @@ class PDOMCPPLinkage extends PDOMLinkage {
|
|||
parent, (ICPPClassType) binding, pdomSpecialized);
|
||||
}
|
||||
} else if (binding instanceof ICPPTemplateInstance) {
|
||||
if (binding instanceof ICPPMethod && pdomSpecialized instanceof ICPPMethod) {
|
||||
if (binding instanceof ICPPConstructor && pdomSpecialized instanceof ICPPConstructor) {
|
||||
pdomBinding = new PDOMCPPConstructorInstance(pdom, parent,
|
||||
(ICPPConstructor) binding, pdomSpecialized);
|
||||
} else if (binding instanceof ICPPMethod && pdomSpecialized instanceof ICPPMethod) {
|
||||
pdomBinding = new PDOMCPPMethodInstance(pdom, parent,
|
||||
(ICPPMethod) binding, pdomSpecialized);
|
||||
} else if (binding instanceof ICPPFunction && pdomSpecialized instanceof ICPPFunction) {
|
||||
|
@ -447,6 +449,8 @@ class PDOMCPPLinkage extends PDOMLinkage {
|
|||
if (binding instanceof ICPPClassType)
|
||||
return CPP_DEFERRED_CLASS_INSTANCE;
|
||||
} else if (binding instanceof ICPPTemplateInstance) {
|
||||
if (binding instanceof ICPPConstructor)
|
||||
return CPP_CONSTRUCTOR_INSTANCE;
|
||||
if (binding instanceof ICPPMethod)
|
||||
return CPP_METHOD_INSTANCE;
|
||||
else if (binding instanceof ICPPFunction)
|
||||
|
@ -659,6 +663,8 @@ class PDOMCPPLinkage extends PDOMLinkage {
|
|||
return new PDOMCPPFunctionInstance(pdom, record);
|
||||
case CPP_METHOD_INSTANCE:
|
||||
return new PDOMCPPMethodInstance(pdom, record);
|
||||
case CPP_CONSTRUCTOR_INSTANCE:
|
||||
return new PDOMCPPConstructorInstance(pdom, record);
|
||||
case CPP_DEFERRED_FUNCTION_INSTANCE:
|
||||
return new PDOMCPPDeferredFunctionInstance(pdom, record);
|
||||
case CPP_CLASS_INSTANCE:
|
||||
|
|
Loading…
Add table
Reference in a new issue