From 29e5a631327f838c741e4dc24cf7b049d6fd71d8 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Tue, 3 Nov 2009 15:15:50 +0000 Subject: [PATCH] Function declared by use of a typedef, bug 86495. --- .../core/parser/tests/ast2/AST2CPPTests.java | 30 ++++ .../cdt/core/parser/tests/ast2/AST2Tests.java | 17 +- .../cdt/core/parser/util/ArrayUtil.java | 38 +++- .../dom/parser/GCCBuiltinSymbolProvider.java | 170 +----------------- .../core/dom/parser/c/CBuiltinParameter.java | 89 +++++++++ .../core/dom/parser/c/CExternalFunction.java | 36 ++-- .../internal/core/dom/parser/c/CFunction.java | 2 +- .../dom/parser/cpp/CPPASTTranslationUnit.java | 1 - .../dom/parser/cpp/CPPBuiltinParameter.java | 111 ++++++++++++ .../core/dom/parser/cpp/CPPFunction.java | 131 ++++++++------ .../core/dom/parser/cpp/CPPFunctionScope.java | 10 +- .../dom/parser/cpp/CPPFunctionTemplate.java | 96 +++++----- .../dom/parser/cpp/CPPImplicitMethod.java | 2 +- .../core/dom/parser/cpp/CPPMethod.java | 84 ++++----- .../dom/parser/cpp/CPPMethodTemplate.java | 11 +- .../parser/cpp/semantics/CPPSemantics.java | 2 +- .../dom/parser/cpp/semantics/CPPVisitor.java | 119 ++++++------ .../core/pdom/AbstractIndexerTask.java | 40 +++-- .../cdt/internal/core/pdom/PDOMWriter.java | 2 + .../core/pdom/dom/c/PDOMCFunction.java | 6 +- .../core/pdom/dom/cpp/PDOMCPPFunction.java | 14 +- .../DOMCompletionProposalComputer.java | 4 +- 22 files changed, 593 insertions(+), 422 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinParameter.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinParameter.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 2bf38190471..45f6a28419c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -100,6 +100,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; 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.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -7625,5 +7626,34 @@ public class AST2CPPTests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.CPP); } + // typedef int F(int); + // template F functionTemplate; + // class C { + // F method; + // friend F friendFunction; + // template F methodTemplate; + // }; + public void testFunctionDeclViaTypedef_86495() throws Exception { + final String code = getAboveComment(); + parseAndCheckBindings(code, ParserLanguage.CPP); + BindingAssertionHelper bh= new BindingAssertionHelper(code, true); + + ICPPFunctionTemplate template= bh.assertNonProblem("functionTemplate", 16); + assertNotNull(template.getType()); + assertEquals(1, template.getParameters().length); + + ICPPMethod method= bh.assertNonProblem("method", 6); + assertNotNull(method.getType()); + assertEquals(1, method.getParameters().length); + + ICPPFunction friendFunction= bh.assertNonProblem("friendFunction", 14); + assertNotNull(friendFunction.getType()); + assertEquals(1, friendFunction.getParameters().length); + + ICPPMethod methodTemplate= bh.assertNonProblem("methodTemplate", 14); + assertTrue(methodTemplate instanceof ICPPFunctionTemplate); + assertNotNull(methodTemplate.getType()); + assertEquals(1, methodTemplate.getParameters().length); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index c4137094d44..15189082ffc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -7029,19 +7029,16 @@ public class AST2Tests extends AST2BaseTest { assertEquals("const int *", ASTTypeUtil.getType(f.getParameters()[0].getType())); } - // typedef int f(); + // typedef int f(int); // f ff; - // int ff() { return 0;} public void testFunctionDeclViaTypedef_86495() throws Exception { final String code = getAboveComment(); -// for(ParserLanguage lang : ParserLanguage.values()) { -// IASTTranslationUnit tu = parseAndCheckBindings(code, lang); - IASTTranslationUnit tu = parseAndCheckBindings(code, ParserLanguage.C); + for(ParserLanguage lang : ParserLanguage.values()) { + IASTTranslationUnit tu = parseAndCheckBindings(code, lang); IASTSimpleDeclaration decl= getDeclaration(tu, 1); - IASTFunctionDefinition def= getDeclaration(tu, 2); - IBinding ffDecl= decl.getDeclarators()[0].getName().resolveBinding(); - IBinding ffDef= def.getDeclarator().getName().resolveBinding(); - assertSame(ffDecl, ffDef); -// } + IFunction ff= (IFunction) decl.getDeclarators()[0].getName().resolveBinding(); + assertNotNull(ff.getType()); + assertEquals(1, ff.getParameters().length); + } } } 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 9977fb6f5ac..83ba8d257dc 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 @@ -464,7 +464,43 @@ public abstract class ArrayUtil { return array; } - + + /** + * Inserts the obj at the beginning of the array, shifting the whole thing one index + * Assumes that array contains nulls at the end, only. + * array must not be null. + * @since 5.2 + */ + public static T[] prepend(T[] array, T obj) { + assert array != null; + + if (obj == null) + return array; + if (array.length == 0) { + array = newArray(array, DEFAULT_LENGTH); + array[0] = obj; + return array; + } + + int i = findFirstNull(array); + if (i >= 0) { + System.arraycopy(array, 0, array, 1, i); + array[0] = obj; + } else { + T[] temp = newArray(array, array.length*2); + System.arraycopy(array, 0, temp, 1, array.length); + temp[0] = obj; + array = temp; + } + + return array; + } + + @SuppressWarnings("unchecked") + private static T[] newArray(T[] array, int newLen) { + return (T[]) Array.newInstance(array.getClass().getComponentType(), newLen); + } + /** * Removes first occurrence of element in array and moves objects behind up front. * @since 4.0 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java index fea6c0468e2..d1629854c8f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java @@ -13,7 +13,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; -import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -21,15 +20,13 @@ import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType; +import org.eclipse.cdt.internal.core.dom.parser.c.CBuiltinParameter; import org.eclipse.cdt.internal.core.dom.parser.c.CBuiltinVariable; import org.eclipse.cdt.internal.core.dom.parser.c.CFunctionType; import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitFunction; @@ -37,6 +34,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitTypedef; import org.eclipse.cdt.internal.core.dom.parser.c.CPointerType; import org.eclipse.cdt.internal.core.dom.parser.c.CQualifierType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinVariable; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction; @@ -44,7 +42,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTypedef; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPPointerType; -import org.eclipse.core.runtime.PlatformObject; /** * This is the IBuiltinBindingsProvider used to implement the "Other" built-in GCC symbols defined: @@ -2972,167 +2969,4 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { initialize(); return (IBinding[]) ArrayUtil.trim(IBinding.class, bindings); } - - public static class CBuiltinParameter extends PlatformObject implements IParameter { - private static final String BLANK_STRING = ""; //$NON-NLS-1$ - private IType type= null; - - public CBuiltinParameter(IType type) { - this.type = type; - } - - public IType getType() { - return type; - } - - /** - * Returns false - */ - public boolean isStatic() { - return false; - } - - /** - * Returns false - */ - public boolean isExtern() { - return false; - } - - /** - * Returns false - */ - public boolean isAuto() { - return false; - } - - /** - * Returns false - */ - public boolean isRegister() { - return false; - } - - public String getName() { - return BLANK_STRING; - } - - public char[] getNameCharArray() { - return BLANK_STRING.toCharArray(); - } - - /** - * Returns false - */ - public IScope getScope() { - return null; - } - - public ILinkage getLinkage() { - return Linkage.C_LINKAGE; - } - - public IBinding getOwner() { - return null; - } - - public IValue getInitialValue() { - return null; - } - } - - static public class CPPBuiltinParameter extends PlatformObject implements ICPPParameter { - private static final String BLANK_STRING = ""; //$NON-NLS-1$ - private IType type= null; - - public CPPBuiltinParameter(IType type) { - this.type = type; - } - - public IType getType() { - return type; - } - - /** - * Returns false - */ - public boolean isStatic() { - return false; - } - - /** - * Returns false - */ - public boolean isExtern() { - return false; - } - - public boolean isExternC() { - return false; - } - - /** - * Returns false - */ - public boolean isAuto() { - return false; - } - - /** - * Returns false - */ - public boolean isRegister() { - return false; - } - - public String getName() { - return BLANK_STRING; - } - - public char[] getNameCharArray() { - return BLANK_STRING.toCharArray(); - } - - /** - * Returns false - */ - public IScope getScope() { - return null; - } - - public boolean hasDefaultValue() { - return false; - } - - /** - * Returns false - */ - public boolean isMutable() { - return false; - } - - public String[] getQualifiedName() { - return new String[0]; - } - - public char[][] getQualifiedNameCharArray() { - return new char[0][]; - } - - public boolean isGloballyQualified() { - return false; - } - - public ILinkage getLinkage() { - return Linkage.CPP_LINKAGE; - } - - public IBinding getOwner() { - return null; - } - - public IValue getInitialValue() { - return null; - } - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinParameter.java new file mode 100644 index 00000000000..94c5c7bc0c1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CBuiltinParameter.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2009 Wind River Systems, Inc. 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: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IFunctionType; +import org.eclipse.cdt.core.dom.ast.IParameter; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.Linkage; +import org.eclipse.core.runtime.PlatformObject; + +public class CBuiltinParameter extends PlatformObject implements IParameter { + + public static IParameter[] createParameterList(IFunctionType ft) { + if (ft == null) { + return IParameter.EMPTY_PARAMETER_ARRAY; + } + assert !(ft instanceof ICPPFunctionType); + IType[] ptypes= ft.getParameterTypes(); + IParameter[] result= new IParameter[ptypes.length]; + for (int i = 0; i < result.length; i++) { + result[i]= new CBuiltinParameter(ptypes[i]); + } + return result; + } + + private IType type= null; + + public CBuiltinParameter(IType type) { + this.type = type; + } + + public IType getType() { + return type; + } + + public boolean isStatic() { + return false; + } + + public boolean isExtern() { + return false; + } + + public boolean isAuto() { + return false; + } + + public boolean isRegister() { + return false; + } + + public String getName() { + return ""; //$NON-NLS-1$ + } + + public char[] getNameCharArray() { + return CharArrayUtils.EMPTY; + } + + public IScope getScope() { + return null; + } + + public ILinkage getLinkage() { + return Linkage.C_LINKAGE; + } + + public IBinding getOwner() { + return null; + } + + public IValue getInitialValue() { + return null; + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java index 297743684bb..e27efb2f5b8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java @@ -1,33 +1,32 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation 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: - * IBM Corporation - initial API and implementation + * Andrew Niefer (IBM Corporation) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ - -/* - * Created on Jan 26, 2005 - */ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IFunctionType; +import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; /** - * @author aniefer + * Models functions used without declarations. */ public class CExternalFunction extends CFunction implements ICExternalBinding { - private IASTName name = null; + private static final IType VOID_TYPE = new CBasicType(Kind.eVoid, 0); + + private IASTName name = null; private IASTTranslationUnit tu = null; public CExternalFunction( IASTTranslationUnit tu, IASTName name ) { @@ -39,14 +38,19 @@ public class CExternalFunction extends CFunction implements ICExternalBinding { @Override public IFunctionType getType() { - IFunctionType t = super.getType(); - if( t == null ) { - type = new CPPFunctionType( CPPSemantics.VOID_TYPE, IType.EMPTY_TYPE_ARRAY ); - } - return type; - } + IFunctionType t = super.getType(); + if (t == null) { + type = new CFunctionType(VOID_TYPE, IType.EMPTY_TYPE_ARRAY); + } + return type; + } @Override + public IParameter[] getParameters() { + return IParameter.EMPTY_PARAMETER_ARRAY; + } + + @Override protected IASTTranslationUnit getTranslationUnit() { return tu; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 2c6e4819084..4a4f452de27 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -157,7 +157,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu return getParameters(); } - return IParameter.EMPTY_PARAMETER_ARRAY; + return CBuiltinParameter.createParameterList(getType()); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 7e31c875917..f64d7a8cc06 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -30,7 +30,6 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; -import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinParameter.java new file mode 100644 index 00000000000..23ce606516a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBuiltinParameter.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2009 Wind River Systems, Inc. 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: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IParameter; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.Linkage; +import org.eclipse.core.runtime.PlatformObject; + +public class CPPBuiltinParameter extends PlatformObject implements ICPPParameter { + public static IParameter[] createParameterList(ICPPFunctionType ft) { + if (ft == null) { + return IParameter.EMPTY_PARAMETER_ARRAY; + } + IType[] ptypes= ft.getParameterTypes(); + IParameter[] result= new IParameter[ptypes.length]; + for (int i = 0; i < result.length; i++) { + result[i]= new CPPBuiltinParameter(ptypes[i]); + } + return result; + } + + private IType type= null; + + public CPPBuiltinParameter(IType type) { + this.type = type; + } + + public IType getType() { + return type; + } + + public boolean isStatic() { + return false; + } + + public boolean isExtern() { + return false; + } + + public boolean isExternC() { + return false; + } + + public boolean isAuto() { + return false; + } + + public boolean isRegister() { + return false; + } + + public String getName() { + return ""; //$NON-NLS-1$ + } + + public char[] getNameCharArray() { + return CharArrayUtils.EMPTY; + } + + public IScope getScope() { + return null; + } + + public boolean hasDefaultValue() { + return false; + } + + public boolean isMutable() { + return false; + } + + public String[] getQualifiedName() { + return new String[0]; + } + + public char[][] getQualifiedNameCharArray() { + return new char[0][]; + } + + public boolean isGloballyQualified() { + return false; + } + + public ILinkage getLinkage() { + return Linkage.CPP_LINKAGE; + } + + public IBinding getOwner() { + return null; + } + + public IValue getInitialValue() { + return null; + } +} \ No newline at end of file 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 a6e21efc89f..75e51c648d9 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 @@ -11,6 +11,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; + import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; @@ -106,7 +109,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } } - protected ICPPASTFunctionDeclarator[] declarations; + protected IASTDeclarator[] declarations; protected ICPPASTFunctionDeclarator definition; protected ICPPFunctionType type = null; @@ -114,13 +117,16 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt private static final int RESOLUTION_IN_PROGRESS = 1 << 1; private int bits = 0; - public CPPFunction(ICPPASTFunctionDeclarator declarator) { + public CPPFunction(IASTDeclarator declarator) { if (declarator != null) { IASTNode parent = ASTQueries.findOutermostDeclarator(declarator).getParent(); - if (parent instanceof IASTFunctionDefinition) - definition = declarator; - else - declarations = new ICPPASTFunctionDeclarator[] { declarator }; + if (parent instanceof IASTFunctionDefinition) { + if (declarator instanceof ICPPASTFunctionDeclarator) { + definition = (ICPPASTFunctionDeclarator) declarator; + } + } else { + declarations = new IASTDeclarator[] { declarator }; + } IASTName name= getASTName(); name.setBinding(this); @@ -149,64 +155,65 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt if (tu != null) { CPPVisitor.getDeclarations(tu, this); } - declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.trim(ICPPASTFunctionDeclarator.class, - declarations); + declarations = (IASTDeclarator[]) ArrayUtil.trim(IASTDeclarator.class, declarations); bits |= FULLY_RESOLVED; bits &= ~RESOLUTION_IN_PROGRESS; } } - public IASTNode[] getDeclarations() { + public IASTDeclarator[] getDeclarations() { return declarations; } - public IASTNode getDefinition() { + public ICPPASTFunctionDeclarator getDefinition() { return definition; } public final void addDefinition(IASTNode node) { - ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node); - if (dtor != null) { - updateFunctionParameterBindings(dtor); - definition = dtor; + IASTDeclarator dtor = extractRelevantDtor(node); + if (dtor instanceof ICPPASTFunctionDeclarator) { + ICPPASTFunctionDeclarator fdtor= (ICPPASTFunctionDeclarator) dtor; + updateFunctionParameterBindings(fdtor); + definition = fdtor; } } public final void addDeclaration(IASTNode node) { - ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node); - if (dtor != null) { - updateFunctionParameterBindings(dtor); - - if (declarations == null) { - declarations = new ICPPASTFunctionDeclarator[] { dtor }; - return; - } + IASTDeclarator dtor = extractRelevantDtor(node); + if (dtor == null) { + return; + } + + // function could be declared via a typedef + if (dtor instanceof ICPPASTFunctionDeclarator) { + updateFunctionParameterBindings((ICPPASTFunctionDeclarator) dtor); + } + if (declarations == null || declarations.length == 0) { + declarations = new IASTDeclarator[] { dtor }; + } else { // Keep the lowest offset declaration in [0] - if (declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset()) { - declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.prepend(ICPPASTFunctionDeclarator.class, - declarations, dtor); + if (((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset()) { + declarations = ArrayUtil.prepend(declarations, dtor); } else { - declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.append(ICPPASTFunctionDeclarator.class, - declarations, dtor); + declarations = ArrayUtil.append(declarations, dtor); } } } - private ICPPASTFunctionDeclarator extractFunctionDtor(IASTNode node) { + private IASTDeclarator extractRelevantDtor(IASTNode node) { while (node instanceof IASTName) node = node.getParent(); - if (node instanceof IASTDeclarator == false) + if (!(node instanceof IASTDeclarator)) return null; - node= ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) node); - if (node instanceof ICPPASTFunctionDeclarator == false) - return null; - - return (ICPPASTFunctionDeclarator) node; + return ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) node); } public IParameter[] getParameters() { IASTStandardFunctionDeclarator dtor = getPreferredDtor(); + if (dtor == null) { + return CPPBuiltinParameter.createParameterList(getType()); + } IASTParameterDeclaration[] params = dtor.getParameters(); int size = params.length; IParameter[] result = new IParameter[size]; @@ -232,7 +239,14 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt return definition.getFunctionScope(); } - return declarations[0].getFunctionScope(); + for (IASTDeclarator dtor : declarations) { + if (dtor instanceof ICPPASTFunctionDeclarator) { + return ((ICPPASTFunctionDeclarator) dtor).getFunctionScope(); + } + } + + // function declaration via typedef + return null; } public String getName() { @@ -281,8 +295,11 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } public ICPPFunctionType getType() { - if (type == null) - type = (ICPPFunctionType) CPPVisitor.createType((definition != null) ? definition : declarations[0]); + if (type == null) { + final IType t = getNestedType(CPPVisitor.createType((definition != null) ? definition : declarations[0]), TDEF); + if (t instanceof ICPPFunctionType) + type = (ICPPFunctionType) t; + } return type; } @@ -297,9 +314,14 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt if (tdecl == null) continue; } else { - tdecl= declarations[i]; - if (tdecl == null) - break; + final IASTDeclarator dtor= declarations[i]; + if (!(dtor instanceof ICPPASTFunctionDeclarator)) { + if (dtor == null) { + break; + } + continue; + } + tdecl= (ICPPASTFunctionDeclarator) dtor; } IASTParameterDeclaration[] params = tdecl.getParameters(); @@ -327,9 +349,14 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt if (tdecl == null) continue; } else { - tdecl= declarations[i]; - if (tdecl == null) - break; + final IASTDeclarator dtor= declarations[i]; + if (!(dtor instanceof ICPPASTFunctionDeclarator)) { + if (dtor == null) { + break; + } + continue; + } + tdecl= (ICPPASTFunctionDeclarator) dtor; } IASTParameterDeclaration[] params = tdecl.getParameters(); @@ -405,7 +432,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } static public boolean hasStorageClass(ICPPInternalFunction function, int storage) { - ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) function.getDefinition(); + IASTDeclarator dtor = (IASTDeclarator) function.getDefinition(); IASTNode[] ds = function.getDeclarations(); int i = -1; @@ -426,7 +453,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } } if (ds != null && ++i < ds.length) { - dtor = (ICPPASTFunctionDeclarator) ds[i]; + dtor = (IASTDeclarator) ds[i]; } else { break; } @@ -439,8 +466,8 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } public boolean isInline() throws DOMException { - ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) getDefinition(); - ICPPASTFunctionDeclarator[] ds = (ICPPASTFunctionDeclarator[]) getDeclarations(); + IASTDeclarator dtor = getDefinition(); + IASTDeclarator[] ds = getDeclarations(); int i = -1; do { if (dtor != null) { @@ -534,15 +561,15 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } protected ICPPASTFunctionDeclarator getPreferredDtor() { - ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) getDefinition(); + ICPPASTFunctionDeclarator dtor = getDefinition(); if (dtor != null) return dtor; - ICPPASTFunctionDeclarator[] dtors = (ICPPASTFunctionDeclarator[]) getDeclarations(); + IASTDeclarator[] dtors = getDeclarations(); if (dtors != null) { - for (ICPPASTFunctionDeclarator declarator : dtors) { - if (declarator != null) - return declarator; + for (IASTDeclarator declarator : dtors) { + if (declarator instanceof ICPPASTFunctionDeclarator) + return (ICPPASTFunctionDeclarator) declarator; } } return null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java index 82c88fb38ff..5c53881f64a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -27,7 +28,6 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.dom.ast.IScope; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -89,8 +89,8 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope { } IBinding[] additional = super.find(name); - for (int i = 0; i < additional.length; i++) { - bindings.add(additional[i]); + for (IBinding element : additional) { + bindings.add(element); } return bindings.toArray(new IBinding[bindings.size()]); @@ -125,8 +125,8 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope { @Override public IName getScopeName() { IASTNode node = getPhysicalNode(); - if (node instanceof ICPPASTFunctionDeclarator) { - return ((ICPPASTFunctionDeclarator)node).getName(); + if (node instanceof IASTDeclarator) { + return ((IASTDeclarator)node).getName(); } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java index 691478121f7..5525d8f354d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -11,6 +11,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType; + import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -113,29 +116,45 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition public void addDefinition(IASTNode node) { if (!(node instanceof IASTName)) return; - ICPPASTFunctionDeclarator fdecl= getDeclaratorByName(node); - if (fdecl == null) - return; - - updateFunctionParameterBindings(fdecl); - super.addDefinition(node); + IASTDeclarator fdecl= getDeclaratorByName(node); + if (fdecl instanceof ICPPASTFunctionDeclarator) { + updateFunctionParameterBindings((ICPPASTFunctionDeclarator) fdecl); + super.addDefinition(node); + } } - + @Override public void addDeclaration(IASTNode node) { if (!(node instanceof IASTName)) return; - ICPPASTFunctionDeclarator fdecl= getDeclaratorByName(node); + IASTDeclarator fdecl= getDeclaratorByName(node); if (fdecl == null) return; - updateFunctionParameterBindings(fdecl); + if (fdecl instanceof ICPPASTFunctionDeclarator) + updateFunctionParameterBindings((ICPPASTFunctionDeclarator) fdecl); + super.addDeclaration(node); } + private ICPPASTFunctionDeclarator getFirstFunctionDtor() { + IASTDeclarator dtor= getDeclaratorByName(getDefinition()); + if (dtor instanceof ICPPASTFunctionDeclarator) + return (ICPPASTFunctionDeclarator) dtor; + + IASTNode[] decls = getDeclarations(); + if (decls != null) { + for (IASTNode decl : decls) { + dtor= getDeclaratorByName(decl); + if (dtor instanceof ICPPASTFunctionDeclarator) + return (ICPPASTFunctionDeclarator) dtor; + } + } + return null; + } + public IParameter[] getParameters() { - IASTName name = getTemplateName(); - ICPPASTFunctionDeclarator fdecl= getDeclaratorByName(name); + ICPPASTFunctionDeclarator fdecl= getFirstFunctionDtor(); if (fdecl != null) { IASTParameterDeclaration[] params = fdecl.getParameters(); int size = params.length; @@ -155,7 +174,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition } return result; } - return null; + return CPPBuiltinParameter.createParameterList(getType()); } public IScope getFunctionScope() { @@ -169,7 +188,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition while(parent.getParent() instanceof IASTDeclarator) parent = parent.getParent(); - IType temp = CPPVisitor.createType((IASTDeclarator)parent); + IType temp = getNestedType(CPPVisitor.createType((IASTDeclarator)parent), TDEF); if (temp instanceof ICPPFunctionType) type = (ICPPFunctionType) temp; } @@ -210,7 +229,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition final IASTNode[] decls= getDeclarations(); int tdeclLen= decls == null ? 0 : decls.length; for (int i= -1; i < tdeclLen; i++) { - ICPPASTFunctionDeclarator tdecl; + IASTDeclarator tdecl; if (i == -1) { tdecl= getDeclaratorByName(getDefinition()); if (tdecl == null) @@ -223,10 +242,12 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition break; } - IASTParameterDeclaration[] params = tdecl.getParameters(); - if (pos < params.length) { - final IASTName oName = getParamName(params[pos]); - return oName.resolvePreBinding(); + if (tdecl instanceof ICPPASTFunctionDeclarator) { + IASTParameterDeclaration[] params = ((ICPPASTFunctionDeclarator) tdecl).getParameters(); + if (pos < params.length) { + final IASTName oName = getParamName(params[pos]); + return oName.resolvePreBinding(); + } } } return param; @@ -239,7 +260,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition final IASTNode[] decls= getDeclarations(); int tdeclLen= decls == null ? 0 : decls.length; for (int i= -1; i < tdeclLen && k < updateParams.length; i++) { - ICPPASTFunctionDeclarator tdecl; + IASTDeclarator tdecl; if (i == -1) { tdecl= getDeclaratorByName(getDefinition()); if (tdecl == null) @@ -252,14 +273,16 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition break; } - IASTParameterDeclaration[] params = tdecl.getParameters(); - int end= Math.min(params.length, updateParams.length); - for (; k < end; k++) { - final IASTName oName = getParamName(params[k]); - IBinding b= oName.resolvePreBinding(); - IASTName n = getParamName(updateParams[k]); - n.setBinding(b); - ASTInternal.addDeclaration(b, n); + if (tdecl instanceof ICPPASTFunctionDeclarator) { + IASTParameterDeclaration[] params = ((ICPPASTFunctionDeclarator) tdecl).getParameters(); + int end= Math.min(params.length, updateParams.length); + for (; k < end; k++) { + final IASTName oName = getParamName(params[k]); + IBinding b= oName.resolvePreBinding(); + IASTName n = getParamName(updateParams[k]); + n.setBinding(b); + ASTInternal.addDeclaration(b, n); + } } } } @@ -332,28 +355,19 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition } public boolean takesVarArgs() { - ICPPASTFunctionDeclarator fdecl= getDeclaratorByName(getDefinition()); - if (fdecl == null) { - IASTName[] ns = (IASTName[]) getDeclarations(); - if (ns != null && ns.length > 0) { - for (int i = 0; i < ns.length && fdecl == null; i++) { - IASTName name = ns[i]; - fdecl= getDeclaratorByName(name); - } - } - } + ICPPASTFunctionDeclarator fdecl= getFirstFunctionDtor(); if (fdecl != null) { return fdecl.takesVarArgs(); } return false; } - private ICPPASTFunctionDeclarator getDeclaratorByName(IASTNode node) { + private IASTDeclarator getDeclaratorByName(IASTNode node) { // skip qualified names and nested declarators. while (node != null) { node= node.getParent(); - if (node instanceof ICPPASTFunctionDeclarator) { - return ((ICPPASTFunctionDeclarator) node); + if (node instanceof IASTDeclarator) { + return ASTQueries.findTypeRelevantDeclarator((IASTDeclarator) node); } } return null; @@ -373,7 +387,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition } public IType[] getExceptionSpecification() throws DOMException { - ICPPASTFunctionDeclarator declarator = getDeclaratorByName(getDefinition()); + ICPPASTFunctionDeclarator declarator = getFirstFunctionDtor(); if (declarator != null) { IASTTypeId[] astTypeIds = declarator.getExceptionSpecification(); if (astTypeIds.equals(ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java index f32fc082741..bdabdcec046 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java @@ -86,7 +86,7 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod public IASTDeclaration getPrimaryDeclaration() throws DOMException { // first check if we already know it if (declarations != null) { - for (ICPPASTFunctionDeclarator dtor : declarations) { + for (IASTDeclarator dtor : declarations) { if (dtor == null) break; 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 0fc87cb350c..18fefacb7fa 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation 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 @@ -32,71 +32,65 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; +import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * The binding for a method. */ public class CPPMethod extends CPPFunction implements ICPPMethod { - public static class CPPMethodProblem extends CPPFunctionProblem implements ICPPMethod { - /** - * @param id - * @param arg - */ - public CPPMethodProblem( IASTNode node, int id, char[] arg ) { - super( node, id, arg ); - } + public static class CPPMethodProblem extends CPPFunctionProblem implements ICPPMethod { + public CPPMethodProblem(IASTNode node, int id, char[] arg) { + super(node, id, arg); + } - public int getVisibility() throws DOMException { - throw new DOMException( this ); - } - public ICPPClassType getClassOwner() throws DOMException { - throw new DOMException( this ); - } - @Override - public boolean isStatic() throws DOMException { - throw new DOMException( this ); - } - public boolean isVirtual() throws DOMException { - throw new DOMException( this ); - } - public boolean isPureVirtual() throws DOMException { - throw new DOMException( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor() - */ + public int getVisibility() throws DOMException { + throw new DOMException(this); + } + public ICPPClassType getClassOwner() throws DOMException { + throw new DOMException(this); + } + public boolean isVirtual() throws DOMException { + throw new DOMException(this); + } + public boolean isPureVirtual() throws DOMException { + throw new DOMException(this); + } public boolean isDestructor() { char[] name = getNameCharArray(); if (name.length > 1 && name[0] == '~') return true; - + return false; } - public boolean isImplicit() { return false; } - } + } - public CPPMethod( ICPPASTFunctionDeclarator declarator ){ - super( declarator ); + public CPPMethod(IASTDeclarator declarator) { + super(declarator); } public IASTDeclaration getPrimaryDeclaration() throws DOMException{ //first check if we already know it - if( declarations != null ){ + if (declarations != null) { for (IASTDeclarator dtor : declarations) { - if (dtor == null) { - break; - } - dtor= CPPVisitor.findOutermostDeclarator(dtor); + if (dtor == null) { + break; + } + dtor = ASTQueries.findOutermostDeclarator(dtor); IASTDeclaration decl = (IASTDeclaration) dtor.getParent(); - if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier ) + if (decl.getParent() instanceof ICPPASTCompositeTypeSpecifier) return decl; } } + if (definition != null) { + IASTDeclarator dtor = ASTQueries.findOutermostDeclarator(definition); + IASTDeclaration decl = (IASTDeclaration) dtor.getParent(); + if (decl.getParent() instanceof ICPPASTCompositeTypeSpecifier) + return decl; + } final char[] myName = getASTName().getLookupKey(); ICPPClassScope scope = (ICPPClassScope) getScope(); @@ -107,14 +101,14 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { if (member instanceof IASTSimpleDeclaration) { IASTDeclarator[] dtors = ((IASTSimpleDeclaration) member).getDeclarators(); for (IASTDeclarator dtor : dtors) { - IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName(); + IASTName name = ASTQueries.findInnermostDeclarator(dtor).getName(); if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) { return member; } } } else if (member instanceof IASTFunctionDefinition) { final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition) member).getDeclarator(); - IASTName name = CPPVisitor.findInnermostDeclarator(declarator).getName(); + IASTName name = ASTQueries.findInnermostDeclarator(declarator).getName(); if (CharArrayUtils.equals(name.getLookupKey(), myName) && name.resolveBinding() == this) { return member; } @@ -163,7 +157,7 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { @Override protected IASTName getASTName() { IASTDeclarator dtor= (declarations != null && declarations.length > 0) ? declarations[0] : definition; - dtor= CPPVisitor.findInnermostDeclarator(dtor); + dtor= ASTQueries.findInnermostDeclarator(dtor); IASTName name= dtor.getName(); if (name instanceof ICPPASTQualifiedName) { IASTName[] ns = ((ICPPASTQualifiedName)name).getNames(); @@ -247,10 +241,10 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { if (dtor == null) break; - dtor = CPPVisitor.findOutermostDeclarator(dtor); + dtor = ASTQueries.findOutermostDeclarator(dtor); IASTDeclaration decl = (IASTDeclaration) dtor.getParent(); if (decl.getParent() instanceof ICPPASTCompositeTypeSpecifier) { - dtor= CPPVisitor.findTypeRelevantDeclarator(dtor); + dtor= ASTQueries.findTypeRelevantDeclarator(dtor); if (dtor instanceof ICPPASTFunctionDeclarator) { return ((ICPPASTFunctionDeclarator) dtor).isPureVirtual(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java index b0e7aaebc4b..bccfd93b3f9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2009 IBM Corporation 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 @@ -53,6 +53,15 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements ICPPMethod return decl; } } + if (definition != null) { + IASTNode parent = definition.getParent(); + while (!(parent instanceof IASTDeclaration) && parent != null) + parent = parent.getParent(); + + IASTDeclaration decl = (IASTDeclaration) parent; + if (decl != null && decl.getParent() instanceof ICPPASTCompositeTypeSpecifier) + return decl; + } final char[] myName = getTemplateName().getLookupKey(); IScope scope = getScope(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index ecd95e47d52..59e4798ab62 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -153,7 +153,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclarator; import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; -import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFieldReference; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; @@ -163,6 +162,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTUnaryExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCompositeBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index a9b72d91a6f..c6f3ff72fe1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; +import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateType; import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateTypeUptoPointers; @@ -509,11 +510,7 @@ public class CPPVisitor extends ASTQueries { IASTNode parent = findOutermostDeclarator(declarator).getParent(); declarator= findInnermostDeclarator(declarator); - IASTFunctionDeclarator funcDeclarator= null; final IASTDeclarator typeRelevantDtor= findTypeRelevantDeclarator(declarator); - if (typeRelevantDtor instanceof IASTFunctionDeclarator) { - funcDeclarator= (IASTFunctionDeclarator) typeRelevantDtor; - } IASTName name= declarator.getName(); if (name instanceof ICPPASTQualifiedName) { @@ -606,29 +603,65 @@ public class CPPVisitor extends ASTQueries { return e.getProblem(); } - IASTSimpleDeclaration simpleDecl = (parent instanceof IASTSimpleDeclaration) ? - (IASTSimpleDeclaration) parent : null; - if (simpleDecl != null && - simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) { - if (binding instanceof ICPPInternalBinding && binding instanceof ITypedef && name.isActive()) { - IType t1 = ((ITypedef) binding).getType(); - IType t2 = createType(declarator); - if (t1 != null && t2 != null && t1.isSameType(t2)) { - ASTInternal.addDeclaration(binding, name); - return binding; - } - return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); - } - // if we don't resolve the target type first, we get a problem binding in case the typedef - // redeclares the target type, otherwise it is safer to defer the resolution of the target type. - IType targetType= createType(declarator); - CPPTypedef td= new CPPTypedef(name); - td.setType(targetType); - binding = td; - } else if (funcDeclarator != null) { + boolean isFunction= false; + if (parent instanceof ICPPASTFunctionDefinition) { + isFunction= true; + } else if (parent instanceof IASTSimpleDeclaration) { + IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) parent; + if (simpleDecl.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) { + // typedef declaration + if (binding instanceof ICPPInternalBinding && binding instanceof ITypedef && name.isActive()) { + IType t1 = ((ITypedef) binding).getType(); + IType t2 = createType(declarator); + if (t1 != null && t2 != null && t1.isSameType(t2)) { + ASTInternal.addDeclaration(binding, name); + return binding; + } + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); + } + // if we don't resolve the target type first, we get a problem binding in case the typedef + // redeclares the target type, otherwise it is safer to defer the resolution of the target type. + IType targetType= createType(declarator); + CPPTypedef td= new CPPTypedef(name); + td.setType(targetType); + binding = td; + } else if (typeRelevantDtor instanceof IASTFunctionDeclarator) { + // function declaration + isFunction= true; + } else { + // looks like a variable declaration + IType t1 = createType(declarator); + if (SemanticUtil.getNestedType(t1, TDEF) instanceof IFunctionType) { + // function declaration with typedef + isFunction= true; + } else { + // variable declaration + IType t2= null; + if (binding != null && binding instanceof IVariable && !(binding instanceof IIndexBinding)) { + try { + t2 = ((IVariable) binding).getType(); + } catch (DOMException e1) { + } + } + if (t1 != null && t2 != null) { + if (t1.isSameType(t2) || isCompatibleArray(t1, t2) != null) { + ASTInternal.addDeclaration(binding, name); + } else { + binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); + } + } else if (simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier) { + binding = new CPPField(name); + } else { + binding = new CPPVariable(name); + } + } + } + } + + if (isFunction) { if (binding instanceof ICPPInternalBinding && binding instanceof IFunction && name.isActive()) { IFunction function = (IFunction) binding; - if (CPPSemantics.isSameFunction(function, funcDeclarator)) { + if (CPPSemantics.isSameFunction(function, typeRelevantDtor)) { binding= CPPSemantics.checkDeclSpecifier(binding, name, parent); if (binding instanceof IProblemBinding) return binding; @@ -652,40 +685,20 @@ public class CPPVisitor extends ASTQueries { } if (scope instanceof ICPPClassScope) { - if (isConstructor(scope, funcDeclarator)) { + if (isConstructor(scope, typeRelevantDtor)) { binding = template ? (ICPPConstructor) new CPPConstructorTemplate(name) - : new CPPConstructor((ICPPASTFunctionDeclarator) funcDeclarator); + : new CPPConstructor((ICPPASTFunctionDeclarator) typeRelevantDtor); } else { binding = template ? (ICPPMethod) new CPPMethodTemplate(name) - : new CPPMethod((ICPPASTFunctionDeclarator) funcDeclarator); + : new CPPMethod(typeRelevantDtor); } } else { binding = template ? (ICPPFunction) new CPPFunctionTemplate(name) - : new CPPFunction((ICPPASTFunctionDeclarator) funcDeclarator); + : new CPPFunction(typeRelevantDtor); } binding= CPPSemantics.checkDeclSpecifier(binding, name, parent); - } else if (simpleDecl != null) { - IType t1 = null, t2 = null; - if (binding != null && binding instanceof IVariable && !(binding instanceof IIndexBinding)) { - t1 = createType(declarator); - try { - t2 = ((IVariable) binding).getType(); - } catch (DOMException e1) { - } - } - if (t1 != null && t2 != null) { - if (t1.isSameType(t2) || isCompatibleArray(t1, t2) != null) { - ASTInternal.addDeclaration(binding, name); - } else { - binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); - } - } else if (simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier) { - binding = new CPPField(name); - } else { - binding = new CPPVariable(name); - } - } - + } + return binding; } @@ -712,8 +725,8 @@ public class CPPVisitor extends ASTQueries { } public static boolean isConstructor(IASTName parentName, IASTDeclarator declarator) { - if (declarator == null || !(declarator instanceof IASTFunctionDeclarator)) - return false; + if (declarator == null || !(declarator instanceof IASTFunctionDeclarator)) + return false; IASTName name = findInnermostDeclarator(declarator).getName(); if (!CharArrayUtils.equals(name.getLookupKey(), parentName.getLookupKey())) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java index 37ba0ae8dfd..3894ab23e4b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java @@ -557,6 +557,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } } catch (Exception e) { swallowError(path, e); + } catch (Error e) { + swallowError(path, e); } } fFilesUpFront.clear(); @@ -701,12 +703,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter { th= e; } catch (StackOverflowError e) { th= e; - } catch (Error e) { - try { - swallowError(path, e); - } catch (Throwable ignore) { - } - throw e; + } catch (AssertionError e) { + th= e; } if (th != null) { swallowError(path, th); @@ -807,23 +805,25 @@ public abstract class AbstractIndexerTask extends PDOMWriter { */ if (e instanceof CoreException) { s=((CoreException)e).getStatus(); - if (s != null && s.getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE) { + if (s.getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE) { if (CCorePlugin.PLUGIN_ID.equals(s.getPlugin())) throw (CoreException) e; } - } - if (e instanceof CoreException) { - s= ((CoreException) e).getStatus(); + + // mask errors in order to avoid dialog from platform Throwable exception = s.getException(); - if (exception instanceof OutOfMemoryError || exception instanceof StackOverflowError) { - // mask errors in order to avoid dialog from platform - e= new InvocationTargetException(exception); - exception= null; - } + if (exception != null) { + Throwable masked= getMaskedException(exception); + if (masked != exception) { + e= exception; + exception= null; + } + } if (exception == null) { s= new Status(s.getSeverity(), s.getPlugin(), s.getCode(), s.getMessage(), e); } } else { + e= getMaskedException(e); s= createStatus(getMessage(MessageKind.errorWhileParsing, file), e); } logError(s); @@ -832,9 +832,13 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } } - /** - * @param s - */ + private Throwable getMaskedException(Throwable e) { + if (e instanceof OutOfMemoryError || e instanceof StackOverflowError || e instanceof AssertionError) { + return new InvocationTargetException(e); + } + return e; + } + protected void logError(IStatus s) { CCorePlugin.log(s); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java index 75b325cf1b6..a55864b4077 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java @@ -212,6 +212,8 @@ abstract public class PDOMWriter { th= e; } catch (StackOverflowError e) { th= e; + } catch (AssertionError e) { + th= e; } finally { index.releaseWriteLock(readlockCount, flushIndex); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java index 19adb6cbbe9..d3441878c8d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java @@ -101,7 +101,11 @@ class PDOMCFunction extends PDOMBinding implements IFunction { } IFunctionType oldType= getType(); - setType(linkage, newType); + if (oldType != null && oldType.isSameType(newType)) { + oldType= null; + } else { + setType(linkage, newType); + } PDOMCParameter oldParams= getFirstParameter(); setParameters(newParams); if (oldType != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java index 6b0df955c37..767de5aa014 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java @@ -122,11 +122,15 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl IFunctionType oldType= getType(); PDOMCPPParameter oldParams= getFirstParameter(); - PDOMCPPFunctionType pft= setType(newType); - setParameters(pft, newParams); - if (oldType != null) { - linkage.deleteType(oldType, record); - } + if (oldType instanceof PDOMCPPFunctionType && oldType.isSameType(newType)) { + setParameters((PDOMCPPFunctionType) oldType, newParams); + } else { + PDOMCPPFunctionType pft= setType(newType); + setParameters(pft, newParams); + if (oldType != null) { + linkage.deleteType(oldType, record); + } + } if (oldParams != null) { oldParams.delete(linkage); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java index 94dd7d64f33..943b1cc2dcd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java @@ -67,11 +67,11 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.text.ICPartitions; -import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CBuiltinParameter; -import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter; +import org.eclipse.cdt.internal.core.dom.parser.c.CBuiltinParameter; import org.eclipse.cdt.internal.core.dom.parser.c.CBuiltinVariable; import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitFunction; import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitTypedef; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinVariable; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod;