diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 6d4b93dbcc8..a54ab746461 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -858,4 +858,21 @@ public class AST2TemplateTests extends AST2BaseTest { assertTrue( A1 instanceof ICPPTemplateInstance ); assertSame( ((ICPPTemplateInstance)A1).getOriginalBinding(), A ); } + + public void testTemplateParameterDeclarations() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append( "template void f( T ); \n"); //$NON-NLS-1$ + buffer.append( "template void f( T ) {} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); + CPPNameCollector col = new CPPNameCollector(); + tu.accept( col ); + + ICPPTemplateParameter T1 = (ICPPTemplateParameter) col.getName(4).resolveBinding(); + ICPPTemplateParameter T2 = (ICPPTemplateParameter) col.getName(2).resolveBinding(); + + assertSame( T1, T2 ); + + assertInstances( col, T1, 4 ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java index 9191b863dc3..9b963d2ddb7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java @@ -213,5 +213,42 @@ public class ArrayUtil { return array; } + + /** + * Insert the obj at the beginning of the array, shifting the whole thing one index + * @param c + * @param array + * @param idx + * @param obj + * @return + */ + public static Object[] prepend(Class c, Object[] array, Object obj) { + if( obj == null ) + return array; + if( array == null || array.length == 0){ + array = (Object[]) Array.newInstance( c, DEFAULT_LENGTH ); + array[0] = obj; + return array; + } + + int i = 0; + for( ; i < array.length; i++ ){ + if( array[i] == null ){ + array[i] = obj; + return array; + } + } + if( i < array.length ){ + System.arraycopy( array, 0, array, 1, array.length - i ); + array[0] = obj; + } else { + Object [] temp = (Object[]) Array.newInstance( c, array.length * 2 ); + System.arraycopy( array, 0, temp, 1, array.length ); + temp[0] = obj; + array = temp; + } + + return array; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 830aa713033..14f804b8800 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -384,12 +384,28 @@ public class CPPClassType implements ICPPClassType, ICPPInternalClassType { //keep the lowest offset declaration in [0] if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){ - IASTName temp = declarations[0]; - declarations[0] = name; - node = temp; + declarations = (IASTName[]) ArrayUtil.prepend( IASTName.class, declarations, name ); + } else { + declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); + } + } + + public void removeDeclaration(IASTNode node) { + if( definition == node ){ + definition = null; + return; + } + if( declarations != null ) { + for (int i = 0; i < declarations.length; i++) { + if( node == declarations[i] ) { + if( i == declarations.length - 1 ) + declarations[i] = null; + else + System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i ); + return; + } + } } - - declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java index 265e3082bac..9f8ffd1b766 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java @@ -232,6 +232,9 @@ public class CPPDeferredClassInstance /*extends CPPInstance*/ implements } + public void removeDeclaration(IASTNode node) { + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getOriginalBinding() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java index 2d8ca741a61..1d56732a469 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java @@ -244,6 +244,10 @@ public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements // TODO Auto-generated method stub } + + public void removeDeclaration(IASTNode node) { + + } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDelegate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDelegate.java index 848a303410b..ab6640b7647 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDelegate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDelegate.java @@ -149,5 +149,9 @@ public class CPPDelegate implements ICPPDelegate, ICPPInternalBinding { // TODO Auto-generated method stub } + + public void removeDeclaration(IASTNode node) { + + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java index 0c5f019cc78..0fbde65f07e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java @@ -169,6 +169,10 @@ public class CPPEnumeration implements IEnumeration, ICPPInternalBinding, ICPPBi // TODO Auto-generated method stub } + + public void removeDeclaration(IASTNode node) { + + } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java index 012ca3c2bcf..3bbf6b8f9e6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java @@ -62,7 +62,8 @@ public class CPPEnumerator implements IEnumerator, ICPPInternalBinding, ICPPBind public IASTNode getDefinition() { return enumName; } - + public void removeDeclaration(IASTNode node) { + } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 114f30305a0..ddf7488e269 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -225,12 +225,31 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction { //keep the lowest offset declaration in [0] if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){ - ICPPASTFunctionDeclarator temp = declarations[0]; - declarations[0] = dtor; - dtor = temp; + declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.prepend( ICPPASTFunctionDeclarator.class, declarations, dtor ); + } else { + declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.append( ICPPASTFunctionDeclarator.class, declarations, dtor ); + } + } + + public void removeDeclaration(IASTNode node) { + while( node instanceof IASTName ){ + node = node.getParent(); + } + if( definition == node ){ + definition = null; + return; + } + if( declarations != null ) { + for (int i = 0; i < declarations.length; i++) { + if( node == declarations[i] ) { + if( i == declarations.length - 1 ) + declarations[i] = null; + else + System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i ); + return; + } + } } - - declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.append( ICPPASTFunctionDeclarator.class, declarations, dtor ); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPInstance.java index 0d7a06fbfb4..f3908e4947f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPInstance.java @@ -94,6 +94,10 @@ public class CPPInstance implements ICPPTemplateInstance { // TODO Auto-generated method stub } + + public void removeDeclaration(IASTNode node) { + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArguments() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java index 815f116436b..30aae14890c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java @@ -139,6 +139,9 @@ public class CPPLabel implements ILabel, ICPPInternalBinding, ICPPBinding { // TODO Auto-generated method stub } + public void removeDeclaration(IASTNode node) { + + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java index 02e82e3930e..86f5b99f2e2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java @@ -134,6 +134,14 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { public IScope getScope() { IASTNode node = (declarations != null && declarations.length > 0) ? declarations[0] : definition; + if( node instanceof IASTDeclarator ){ + IASTName name = ((IASTDeclarator)node).getName(); + if( name instanceof ICPPASTQualifiedName ){ + IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ ns.length - 1 ]; + } + return CPPVisitor.getContainingScope( name ); + } return CPPVisitor.getContainingScope( node ); } @@ -174,8 +182,22 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual() */ - public boolean isVirtual() throws DOMException { - // TODO Auto-generated method stub + public boolean isVirtual() { + if( definition != null ){ + IASTNode node = definition.getParent(); + while( node instanceof IASTDeclarator ) + node = node.getParent(); + + ICPPASTDeclSpecifier declSpec = null; + if( node instanceof IASTSimpleDeclaration ) + declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)node).getDeclSpecifier(); + else if( node instanceof IASTFunctionDefinition ) + declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)node).getDeclSpecifier(); + + if( declSpec != null ){ + return declSpec.isVirtual(); + } + } return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java index c1b92e2f1ea..58089481b52 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java @@ -232,12 +232,10 @@ public class CPPNamespace implements ICPPNamespace, ICPPInternalBinding { } if( namespaceDefinitions.length > 0 && ((ASTNode)name).getOffset() < ((ASTNode)namespaceDefinitions[0]).getOffset() ){ - IASTName temp = namespaceDefinitions[0]; - namespaceDefinitions[0] = name; - name = temp; + namespaceDefinitions = (IASTName[]) ArrayUtil.prepend( IASTName.class, namespaceDefinitions, name ); + } else { + namespaceDefinitions = (IASTName[]) ArrayUtil.append( IASTName.class, namespaceDefinitions, name ); } - - namespaceDefinitions = (IASTName[]) ArrayUtil.append( IASTName.class, namespaceDefinitions, name ); } /* (non-Javadoc) @@ -246,5 +244,18 @@ public class CPPNamespace implements ICPPNamespace, ICPPInternalBinding { public void addDeclaration(IASTNode node) { addDefinition( node ); } + public void removeDeclaration(IASTNode node) { + if( namespaceDefinitions != null ) { + for (int i = 0; i < namespaceDefinitions.length; i++) { + if( node == namespaceDefinitions[i] ) { + if( i == namespaceDefinitions.length - 1 ) + namespaceDefinitions[i] = null; + else + System.arraycopy( namespaceDefinitions, i + 1, namespaceDefinitions, i, namespaceDefinitions.length - 1 - i ); + return; + } + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java index 997c9ec50c6..3891247e2b0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java @@ -143,4 +143,7 @@ public class CPPNamespaceAlias implements ICPPNamespaceAlias, ICPPInternalBindin */ public void addDeclaration(IASTNode node) { } + public void removeDeclaration(IASTNode node) { + + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index f01e7976727..6433ecbcd55 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -28,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTNode; /** * @author aniefer @@ -90,14 +91,30 @@ public class CPPParameter implements ICPPParameter, ICPPInternalBinding { if( !(node instanceof IASTName ) ) return; IASTName name = (IASTName) node; - if( declarations == null ){ - declarations = new IASTName [] { name }; - return; - } - - declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); + if( declarations == null ) + declarations = new IASTName[] { name }; + else { + //keep the lowest offset declaration in [0] + if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){ + declarations = (IASTName[]) ArrayUtil.prepend( IASTName.class, declarations, name ); + } else { + declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); + } + } } + public void removeDeclaration(IASTNode node) { + if( declarations != null ) { + for (int i = 0; i < declarations.length; i++) { + if( node == declarations[i] ) { + if( i == declarations.length - 1 ) + declarations[i] = null; + else + System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i ); + } + } + } + } private IASTName getPrimaryDeclaration(){ if( declarations != null ){ for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java index 012f1380824..9d012f56164 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java @@ -41,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ObjectMap; +import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** @@ -365,13 +366,35 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I return; IASTName declName = (IASTName) node; updateTemplateParameterBindings( declName ); - if( declarations == null ){ - declarations = new IASTName [] { declName }; - return; - } - declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, declName ); + if( declarations == null ) + declarations = new IASTName[] { declName }; + else { + //keep the lowest offset declaration in [0] + if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){ + declarations = (IASTName[]) ArrayUtil.prepend( IASTName.class, declarations, declName ); + } else { + declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, declName ); + } + } } + public void removeDeclaration(IASTNode node) { + if( definition == node ){ + definition = null; + return; + } + if( declarations != null ) { + for (int i = 0; i < declarations.length; i++) { + if( node == declarations[i] ) { + if( i == declarations.length - 1 ) + declarations[i] = null; + else + System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i ); + return; + } + } + } + } protected void updateTemplateParameterBindings( IASTName name ){ IASTName orig = definition != null ? definition : declarations[0]; ICPPASTTemplateDeclaration origTemplate = CPPTemplates.getTemplateDeclaration( orig ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java index 3f8b1067f68..4c4309c5a85 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java @@ -17,9 +17,10 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTNode; /** * @author aniefer @@ -65,20 +66,6 @@ public class CPPTemplateParameter implements ICPPTemplateParameter, ICPPInternal return CPPVisitor.getContainingScope( getPrimaryDeclaration () ); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isTemplateInstance() - */ - public boolean isTemplateInstance() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getTemplatedBinding() - */ - public ICPPBinding getTemplatedBinding() { - return null; - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName() */ @@ -114,6 +101,8 @@ public class CPPTemplateParameter implements ICPPTemplateParameter, ICPPInternal * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition() */ public IASTNode getDefinition() { + if( declarations != null && declarations.length > 0 ) + return declarations[0]; return null; } @@ -129,15 +118,39 @@ public class CPPTemplateParameter implements ICPPTemplateParameter, ICPPInternal * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode) */ public void addDefinition(IASTNode node) { - // TODO Auto-generated method stub - + addDeclaration( node ); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode) */ public void addDeclaration(IASTNode node) { - // TODO Auto-generated method stub - + if( !(node instanceof IASTName) ) + return; + IASTName name = (IASTName) node; + if( declarations == null ) + declarations = new IASTName[] { name }; + else { + //keep the lowest offset declaration in [0] + if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){ + IASTName temp = declarations[0]; + declarations[0] = name; + name = temp; + } + declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); + } + } + public void removeDeclaration(IASTNode node) { + if( declarations != null ) { + for (int i = 0; i < declarations.length; i++) { + if( node == declarations[i] ) { + if( i == declarations.length - 1 ) + declarations[i] = null; + else + System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i ); + return; + } + } + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java index 3d2be62b6f9..3227346c045 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java @@ -557,8 +557,12 @@ public class CPPTemplates { this.bindings = bindings; } public int visit(IASTName name) { - if( name.getBinding() != null && bindings.containsKey( name.getBinding() ) ) + if( name.getBinding() != null && bindings.containsKey( name.getBinding() ) ){ + IBinding binding = name.getBinding(); + if( binding instanceof ICPPInternalBinding ) + ((ICPPInternalBinding)binding).removeDeclaration( name ); name.setBinding( null ); + } return PROCESS_CONTINUE; } public int visit(IASTStatement statement) { @@ -590,6 +594,7 @@ public class CPPTemplates { if( bindingsToClear == null ) bindingsToClear = new ObjectSet( templateParams.length ); tn.setBinding( defParams[i] ); + ((ICPPInternalBinding)defParams[i]).addDeclaration( tn ); bindingsToClear.put( defParams[i] ); } @@ -641,7 +646,7 @@ public class CPPTemplates { } } - if( bindingsToClear != null ){ + if( bindingsToClear != null && !result ){ ClearBindingAction action = new ClearBindingAction( bindingsToClear ); templateDecl.accept( action ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java index b31f336e4df..1ae12f31026 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java @@ -191,11 +191,24 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPInternalBinding else { //keep the lowest offset declaration in [0] if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){ - IASTName temp = declarations[0]; - declarations[0] = name; - name = temp; + declarations = (IASTName[]) ArrayUtil.prepend( IASTName.class, declarations, name ); + } else { + declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); } - declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); } } + + public void removeDeclaration(IASTNode node) { + if( declarations != null ) { + for (int i = 0; i < declarations.length; i++) { + if( node == declarations[i] ) { + if( i == declarations.length - 1 ) + declarations[i] = null; + else + System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i ); + return; + } + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java index b28e00ce2a4..17b2be332dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java @@ -150,13 +150,30 @@ public class CPPVariable implements ICPPVariable, ICPPInternalBinding { else { //keep the lowest offset declaration in [0] if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){ - IASTName temp = declarations[0]; - declarations[0] = name; - name = temp; + declarations = (IASTName[]) ArrayUtil.prepend( IASTName.class, declarations, name ); + } else { + declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); } - declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name ); } } + + public void removeDeclaration(IASTNode node) { + if( node == definition ){ + definition = null; + return; + } + if( declarations != null ) { + for (int i = 0; i < declarations.length; i++) { + if( node == declarations[i] ) { + if( i == declarations.length - 1 ) + declarations[i] = null; + else + System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i ); + } + } + } + } + /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations() */ @@ -339,5 +356,4 @@ public class CPPVariable implements ICPPVariable, ICPPInternalBinding { public boolean isRegister() { return hasStorageClass( IASTDeclSpecifier.sc_register ); } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalBinding.java index 72d35689c7b..4655c5fe670 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalBinding.java @@ -36,4 +36,5 @@ public interface ICPPInternalBinding extends IBinding { */ void addDefinition( IASTNode node ); void addDeclaration( IASTNode node ); + void removeDeclaration(IASTNode node); }