diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java index 30fbea48661..c0c79fa3b4f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateTests.java @@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; 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.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias; @@ -756,4 +757,47 @@ public class IndexUpdateTests extends IndexTestBase { fIndex.releaseReadLock(); } } + + + // int globalVar; + // void func(); + + // extern "C" { + // int globalVar; + // void func(); + // } + + // int globalVar; + // void func(); + + // extern "C" int globalVar; + // extern "C" void func(); + + // int globalVar; + // void func(); + public void testExternC() throws Exception { + setupFile(5, true); + checkExternC(false); + updateFile(); + checkExternC(true); + updateFile(); + checkExternC(false); + updateFile(); + checkExternC(true); + updateFile(); + checkExternC(false); + } + + private void checkExternC(boolean value) throws Exception { + fIndex.acquireReadLock(); + try { + ICPPVariable var = (ICPPVariable) findBinding("globalVar"); + assertEquals(value, var.isExternC()); + ICPPFunction func = (ICPPFunction) findBinding("func"); + assertEquals(value, func.isExternC()); + } finally { + fIndex.releaseReadLock(); + } + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java index 7b600dc6390..5cd2fcefeee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,15 +7,15 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Mar 15, 2005 */ -package org.eclipse.cdt.core.dom.ast.cpp; - -import org.eclipse.cdt.core.dom.ast.DOMException; +package org.import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IFunction; +pse.cdt.core.dom.ast.IFunction; /** * @author aniefer @@ -33,4 +33,9 @@ public interface ICPPFunction extends IFunction, ICPPBinding { * is this an inline function */ public boolean isInline() throws DOMException; + + /** + * Returns whether this function is declared as extern "C". + */ + public boolean isExternC() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPVariable.java index e928a8ec7e1..704defb2b64 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPVariable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2007 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* @@ -27,4 +28,9 @@ public interface ICPPVariable extends IVariable, ICPPBinding { * @throws DOMException */ public boolean isMutable() throws DOMException; + + /** + * Returns whether this variable is declared as extern "C". + */ + public boolean isExternC() throws DOMException; } 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 5aae6261acd..13394247d4c 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 @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Anton Leherbauer (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -2409,6 +2409,10 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { return false; } + public boolean isExternC() { + return false; + } + /** * returns false */ 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 d1d2f8cf312..fbc369bba29 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 @@ -133,6 +133,13 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc return ((ICPPFunction)getTemplateDefinition()).isInline(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline() + */ + public boolean isExternC() throws DOMException { + return ((ICPPFunction)getTemplateDefinition()).isExternC(); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java index 93f28d329e4..a1a03f7c4c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Mar 29, 2005 @@ -78,6 +79,10 @@ public class CPPFieldSpecialization extends CPPSpecialization implements ICPPFie return getField().isMutable(); } + public boolean isExternC() { + return false; + } + public ICPPDelegate createDelegate(IASTName name) { return new CPPFieldDelegate( name, this ); } 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 6e07a06379b..2ec56613347 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 @@ -71,6 +71,9 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt public boolean isInline() throws DOMException { return ((ICPPFunction)getBinding()).isInline(); } + public boolean isExternC() throws DOMException { + return ((ICPPFunction)getBinding()).isExternC(); + } public boolean isExtern() throws DOMException { return ((ICPPFunction)getBinding()).isExtern(); } @@ -128,6 +131,9 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt public boolean isInline() throws DOMException { throw new DOMException( this ); } + public boolean isExternC() throws DOMException { + throw new DOMException( this ); + } public boolean isExtern() throws DOMException { throw new DOMException( this ); } @@ -582,6 +588,24 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt return false; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline() + */ + public boolean isExternC() throws DOMException { + if (CPPVisitor.isExternC(getDefinition())) { + return true; + } + IASTNode[] ds= getDeclarations(); + if (ds != null) { + for (int i = 0; i < ds.length; i++) { + if (CPPVisitor.isExternC(ds[i])) { + return true; + } + } + } + return false; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java index dd1c433bf91..079c6a0aa18 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java @@ -106,6 +106,13 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC return ((ICPPFunction)getTemplateDefinition()).isInline(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline() + */ + public boolean isExternC() throws DOMException { + return ((ICPPFunction)getTemplateDefinition()).isExternC(); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java index 9ddea55d0b9..589a276d244 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java @@ -95,6 +95,14 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP } return getFunction().isInline(); } + + public boolean isExternC() throws DOMException { + if (CPPVisitor.isExternC(getDefinition())) { + return true; + } + return getFunction().isExternC(); + } + public boolean isStatic() { return isStatic(true, true); } 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 b328c5d56a9..19fb3ad0652 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 @@ -65,6 +65,9 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu public boolean isInline() throws DOMException { throw new DOMException( this ); } + public boolean isExternC() throws DOMException { + throw new DOMException( this ); + } public IParameter[] getParameters() throws DOMException { throw new DOMException( this ); } @@ -357,6 +360,21 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu return false; } + public boolean isExternC() throws DOMException { + if (CPPVisitor.isExternC(getDefinition())) { + return true; + } + IASTNode[] ds= getDeclarations(); + if (ds != null) { + for (int i = 0; i < ds.length; i++) { + if (CPPVisitor.isExternC(ds[i])) { + return true; + } + } + } + return false; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() */ 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 42f9e7b2451..efebd2ccd73 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 @@ -64,6 +64,9 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI public boolean hasDefaultValue() { return ((ICPPParameter)getBinding()).hasDefaultValue(); } + public boolean isExternC() { + return false; + } } public static class CPPParameterProblem extends ProblemBinding implements ICPPParameter { @@ -100,6 +103,9 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI public boolean isGloballyQualified() throws DOMException { throw new DOMException( this ); } + public boolean isExternC() { + return false; + } } private IType type = null; @@ -320,4 +326,8 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } + + public boolean isExternC() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java index 305dafe27e5..2d1857ce83b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java @@ -1,13 +1,13 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2007 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 - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ /* * Created on Mar 29, 2005 @@ -94,4 +94,8 @@ public class CPPParameterSpecialization extends CPPSpecialization implements ICP public ICPPDelegate createDelegate(IASTName name) { return new CPPParameterDelegate( name, this ); } + + public boolean isExternC() { + return false; + } } 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 a61fcab27b1..cd1bb036290 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 @@ -53,6 +53,9 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt public boolean isExtern() throws DOMException { return ((ICPPVariable)getBinding()).isExtern(); } + public boolean isExternC() throws DOMException { + return ((ICPPVariable)getBinding()).isExternC(); + } public boolean isAuto() throws DOMException { return ((ICPPVariable)getBinding()).isAuto(); } @@ -87,6 +90,9 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt public boolean isExtern() throws DOMException { throw new DOMException( this ); } + public boolean isExternC() throws DOMException { + throw new DOMException( this ); + } public boolean isAuto() throws DOMException { throw new DOMException( this ); } @@ -352,6 +358,24 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt return hasStorageClass( IASTDeclSpecifier.sc_extern, true); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern() + */ + public boolean isExternC() { + if (CPPVisitor.isExternC(getDefinition())) { + return true; + } + IASTNode[] ds= getDeclarations(); + if (ds != null) { + for (int i = 0; i < ds.length; i++) { + if (CPPVisitor.isExternC(ds[i])) { + return true; + } + } + } + return false; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 410d6976dd8..28ca0c9ce63 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -90,6 +90,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; @@ -2133,4 +2134,16 @@ public class CPPVisitor { } return parentScope; } + + public static boolean isExternC(IASTNode node) { + while (node != null) { + node= node.getParent(); + if (node instanceof ICPPASTLinkageSpecification) { + if ("\"C\"".equals(((ICPPASTLinkageSpecification) node).getLiteral())) { //$NON-NLS-1$ + return true; + } + } + } + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunction.java index 17a6de27db2..a8030892042 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunction.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation + * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -31,6 +32,10 @@ class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction, super(cf, rbinding); } + public boolean isExternC() throws DOMException { + return ((ICPPFunction)rbinding).isExternC(); + } + public boolean isInline() throws DOMException { return ((ICPPFunction)rbinding).isInline(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPVariable.java index 60afba0bd87..c75d5cc16ee 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPVariable.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation + * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -30,6 +31,10 @@ class CompositeCPPVariable extends CompositeCPPBinding implements ICPPVariable, return ((ICPPVariable)rbinding).isMutable(); } + public boolean isExternC() throws DOMException { + return ((ICPPVariable)rbinding).isExternC(); + } + public IType getType() throws DOMException { IType rtype = ((ICPPVariable)rbinding).getType(); return cf.getCompositeType((IIndexType)rtype); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 79c9a753488..d11849b7b8c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -82,7 +82,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { */ public static final String FRAGMENT_PROPERTY_VALUE_FORMAT_ID= "org.eclipse.cdt.internal.core.pdom.PDOM"; //$NON-NLS-1$ - public static final int CURRENT_VERSION = 50; + public static final int CURRENT_VERSION = 51; public static final int MIN_SUPPORTED_VERSION= CURRENT_VERSION; /** @@ -140,7 +140,9 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { * #37#- added index for nested bindings (189811), compatible with version 36 - <> * 38 - added b-tree for macros (193056), compatible with version 36 and 37 * #39#- added flag for function-style macros (208558), compatible with version 36,37,38 - <> - * 40 - string optimizations, removed compatibility with prior versions. + * + * 50 - support for complex, imaginary and long long (bug 209049). + * 51 - modeling extern "C" (bug 191989) */ public static final int LINKAGES = Database.DATA_AREA; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAnnotation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAnnotation.java index b8117a36e74..08c5a3beb08 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAnnotation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPAnnotation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation. + * Copyright (c) 2006, 2007 IBM Corporation. * 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -15,16 +16,20 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; 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.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCAnnotation; class PDOMCPPAnnotation { // "Mutable" shares the same offset as "inline" because // only fields can be mutable and only functions can be inline. - public static final int MUTABLE_OFFSET = 2; - + public static final int MUTABLE_OFFSET = PDOMCAnnotation.INLINE_OFFSET; + // extern C shares the same offset as visibility because + // only members have visibility and cannot be extern C. + public static final int EXTERN_C_OFFSET= 6; public static final int VISIBILITY_OFFSET = 6; private static final int VISIBILITY_MASK = 0x03; @@ -46,15 +51,28 @@ class PDOMCPPAnnotation { */ public static byte encodeAnnotation(IBinding binding) throws DOMException { byte modifiers = PDOMCAnnotation.encodeAnnotation(binding); - if (binding instanceof ICPPField) { - ICPPField variable = (ICPPField) binding; - modifiers |= (variable.isMutable() ? 1 : 0) << MUTABLE_OFFSET; - } if (binding instanceof ICPPMember) { ICPPMember member = (ICPPMember) binding; int mask = ~(VISIBILITY_MASK << VISIBILITY_OFFSET); modifiers &= mask; modifiers |= (member.getVisibility() & VISIBILITY_MASK) << VISIBILITY_OFFSET; + + if (binding instanceof ICPPField) { + ICPPField variable = (ICPPField) binding; + modifiers |= (variable.isMutable() ? 1 : 0) << MUTABLE_OFFSET; + } + } + else { + if (binding instanceof ICPPFunction) { + if (((ICPPFunction) binding).isExternC()) { + modifiers |= 1 << EXTERN_C_OFFSET; + } + } + if (binding instanceof ICPPVariable) { + if (((ICPPVariable) binding).isExternC()) { + modifiers |= 1 << EXTERN_C_OFFSET; + } + } } return modifiers; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPField.java index 806f4e99562..86ea79ad3ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPField.java @@ -6,8 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * IBM Corporation + * QNX - Initial API and implementation + * IBM Corporation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -79,6 +80,11 @@ class PDOMCPPField extends PDOMCPPVariable implements ICPPField, ICPPDelegateCre return false; } + // @Override + public boolean isExternC() { + return false; + } + // @Override public boolean isRegister() { // ISO/IEC 14882:2003 9.2.6 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFieldSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFieldSpecialization.java index 92bd58b4228..5fc47a29c0e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFieldSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFieldSpecialization.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -93,6 +94,10 @@ class PDOMCPPFieldSpecialization extends PDOMCPPSpecialization implements return getField().isExtern(); } + public boolean isExternC() { + return false; + } + public boolean isRegister() throws DOMException { return getField().isRegister(); } 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 1a4b3c6fea6..010a7e07776 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 @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * IBM Corporation - * Markus Schorn (Wind River Systems) + * QNX - Initial API and implementation + * IBM Corporation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -181,6 +181,10 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl return getBit(getByte(record + ANNOTATION), PDOMCAnnotation.INLINE_OFFSET); } + public boolean isExternC() throws DOMException { + return getBit(getByte(record + ANNOTATION), PDOMCPPAnnotation.EXTERN_C_OFFSET); + } + public boolean isMutable() throws DOMException { throw new PDOMNotImplementedError(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java index d7b83e3430a..f2f3ba7aa2e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java @@ -6,8 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Andrew Ferguson (Symbian) + * QNX - Initial API and implementation + * Andrew Ferguson (Symbian) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -156,6 +157,10 @@ class PDOMCPPFunctionInstance extends PDOMCPPInstance implements ICPPFunction { return ((ICPPFunction)getTemplateDefinition()).isExtern(); } + public boolean isExternC() throws DOMException { + return ((ICPPFunction)getTemplateDefinition()).isExternC(); + } + public boolean isRegister() throws DOMException { return ((ICPPFunction)getTemplateDefinition()).isRegister(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java index d4ffc38335c..06d4c234c56 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -170,6 +171,10 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP return getBit(getByte(record + ANNOTATION), PDOMCAnnotation.EXTERN_OFFSET); } + public boolean isExternC() throws DOMException { + return getBit(getByte(record + ANNOTATION), PDOMCPPAnnotation.EXTERN_C_OFFSET); + } + public boolean isRegister() throws DOMException { // ISO/IEC 14882:2003 7.1.1.2 return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java index f2a391c9262..9fe02b3503a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethod.java @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * IBM Corporation - * Andrew Ferguson (Symbian) - * Markus Schorn (Wind River Systems) + * QNX - Initial API and implementation + * IBM Corporation + * Andrew Ferguson (Symbian) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -117,6 +117,10 @@ class PDOMCPPMethod extends PDOMCPPFunction implements ICPPMethod, ICPPDelegateC return false; } + public boolean isExternC() { + return false; + } + public boolean isAuto() throws DOMException { // ISO/IEC 14882:2003 9.2.6 return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodInstance.java index bfd372cc4f3..a8153c5951f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodInstance.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -51,6 +52,10 @@ class PDOMCPPMethodInstance extends PDOMCPPFunctionInstance implements return ((ICPPMethod)getTemplateDefinition()).isDestructor(); } + public boolean isExternC() { + return false; + } + public boolean isImplicit() { return ((ICPPMethod)getTemplateDefinition()).isImplicit(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java index bc2bc569fa7..bb8d62ef588 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodSpecialization.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -89,6 +90,10 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization return false; } + public boolean isExternC() { + return false; + } + public ICPPClassType getClassOwner() throws DOMException { ICPPMethod f = (ICPPMethod) getSpecializedBinding(); if( f != null ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplate.java index b546407d7a6..f8b0551a1a0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplate.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -112,6 +113,10 @@ class PDOMCPPMethodTemplate extends PDOMCPPFunctionTemplate implements // ISO/IEC 14882:2003 9.2.6 return false; } + + public boolean isExternC() { + return false; + } public boolean isAuto() throws DOMException { // ISO/IEC 14882:2003 9.2.6 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplateSpecialization.java index 9f2533e0e6d..dc4d2c7dce8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplateSpecialization.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -88,4 +89,8 @@ class PDOMCPPMethodTemplateSpecialization extends } return 0; } + + public boolean isExternC() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java index 2fcb1ccea5b..cd5b06915f6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java @@ -171,6 +171,10 @@ class PDOMCPPParameter extends PDOMNamedNode return false; } + public boolean isExternC() { + return false; + } + public boolean isRegister() throws DOMException { throw new PDOMNotImplementedError(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java index 127971dbb5b..cdd83b308d3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameterSpecialization.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -16,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.internal.core.Util; +import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -80,7 +82,7 @@ class PDOMCPPParameterSpecialization extends PDOMCPPSpecialization implements IC } public int getNodeType() { - return PDOMCPPLinkage.CPP_PARAMETER_SPECIALIZATION; + return IIndexCPPBindingConstants.CPP_PARAMETER_SPECIALIZATION; } public void setNextParameter(PDOMCPPParameterSpecialization nextParam) throws CoreException { @@ -122,7 +124,11 @@ class PDOMCPPParameterSpecialization extends PDOMCPPSpecialization implements IC public boolean isExtern() throws DOMException { return false; } - + + public boolean isExternC() { + return false; + } + public boolean isStatic() throws DOMException { return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java index 35fa2d69464..d983c7fd773 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPVariable.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) - * IBM Corporation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) + * IBM Corporation *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -130,6 +130,10 @@ class PDOMCPPVariable extends PDOMCPPBinding implements ICPPVariable, ICPPDelega return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.EXTERN_OFFSET); } + public boolean isExternC() throws DOMException { + return getBit(getByte(record + ANNOTATIONS), PDOMCPPAnnotation.EXTERN_C_OFFSET); + } + public boolean isRegister() throws DOMException { return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.REGISTER_OFFSET); }