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 94796701bf3..a0df7a24edf 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 @@ -4446,4 +4446,15 @@ public class AST2Tests extends AST2BaseTest { parseAndCheckBindings(code, ParserLanguage.C); parseAndCheckBindings(code, ParserLanguage.CPP); } + + // #define __inline__ __inline__ __attribute__((always_inline)) + // typedef int __u32; + // static __inline__ __u32 f(int x) { + // return x; + // } + public void testRedefinedGCCKeywords_Bug226112() throws Exception { + final String code = getAboveComment(); + parseAndCheckBindings(code, ParserLanguage.C, true); + parseAndCheckBindings(code, ParserLanguage.CPP, true); + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java index 2b0967e17c8..7f7e52349b4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java @@ -12,8 +12,11 @@ *******************************************************************************/ package org.eclipse.cdt.core.dom.parser; +import org.eclipse.cdt.core.parser.GCCKeywords; +import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IMacro; import org.eclipse.cdt.core.parser.IPreprocessorDirective; +import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; @@ -23,21 +26,12 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap; public abstract class GNUScannerExtensionConfiguration extends AbstractScannerExtensionConfiguration { private static IMacro[] sAdditionalMacros= new IMacro[] { - createMacro("__asm__", "asm"), //$NON-NLS-1$//$NON-NLS-2$ createMacro("__complex__", "_Complex"), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__const__", "const"), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__const", "const"), //$NON-NLS-1$ //$NON-NLS-2$ createMacro("__extension__", ""), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__inline__", "inline"), //$NON-NLS-1$ //$NON-NLS-2$ createMacro("__imag__", "(int)"), //$NON-NLS-1$ //$NON-NLS-2$ createMacro("__null", "(void *)0"), //$NON-NLS-1$ //$NON-NLS-2$ createMacro("__real__", "(int)"), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__restrict__", "restrict"), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__restrict", "restrict"), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__volatile__", "volatile"), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__signed__", "signed"), //$NON-NLS-1$ //$NON-NLS-2$ createMacro("__stdcall", ""), //$NON-NLS-1$ //$NON-NLS-2$ - createMacro("__typeof__", "typeof"), //$NON-NLS-1$ //$NON-NLS-2$ createMacro("__builtin_va_arg(ap,type)", "*(type *)ap"), //$NON-NLS-1$//$NON-NLS-2$ createMacro("__builtin_constant_p(exp)", "0") //$NON-NLS-1$//$NON-NLS-2$ @@ -46,23 +40,43 @@ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerEx public static IMacro[] getAdditionalGNUMacros() { return sAdditionalMacros; } - - public boolean support$InIdentifiers() { + + public static void addAdditionalGNUKeywords(CharArrayIntMap target) { + target.put(GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ ); + target.put(GCCKeywords.cp__ASM__, IToken.t_asm); + target.put(GCCKeywords.cp__ATTRIBUTE__, IGCCToken.t__attribute__ ); + target.put(GCCKeywords.cp__CONST, IToken.t_const); + target.put(GCCKeywords.cp__CONST__, IToken.t_const); + target.put(GCCKeywords.cp__DECLSPEC, IGCCToken.t__declspec ); + target.put(GCCKeywords.cp__INLINE__, IToken.t_inline); + target.put(GCCKeywords.cp__RESTRICT, IToken.t_restrict); + target.put(GCCKeywords.cp__RESTRICT__, IToken.t_restrict); + target.put(GCCKeywords.cp__VOLATILE__, IToken.t_volatile); + target.put(GCCKeywords.cp__SIGNED__, IToken.t_signed); + target.put(GCCKeywords.cp__TYPEOF__, IGCCToken.t_typeof); + target.put(GCCKeywords.cpTYPEOF, IGCCToken.t_typeof ); + } + + @Override + public boolean support$InIdentifiers() { return true; } - public char[] supportAdditionalNumericLiteralSuffixes() { + @Override + public char[] supportAdditionalNumericLiteralSuffixes() { return "ij".toCharArray(); //$NON-NLS-1$ } - public IMacro[] getAdditionalMacros() { + @Override + public IMacro[] getAdditionalMacros() { return sAdditionalMacros; } /* * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration#getAdditionalPreprocessorKeywords() */ - public CharArrayIntMap getAdditionalPreprocessorKeywords() { + @Override + public CharArrayIntMap getAdditionalPreprocessorKeywords() { CharArrayIntMap additionalPPKeywords= new CharArrayIntMap(8, IPreprocessorDirective.ppInvalid); additionalPPKeywords.put(Keywords.cINCLUDE_NEXT, IPreprocessorDirective.ppInclude_next); additionalPPKeywords.put(Keywords.cIMPORT, IPreprocessorDirective.ppImport); @@ -73,5 +87,4 @@ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerEx additionalPPKeywords.put(Keywords.cUNASSERT, IPreprocessorDirective.ppIgnore); return additionalPPKeywords; } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java index 72cdd51afeb..5fb3e258dbc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java @@ -1,19 +1,18 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 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 - * Ed Swartz (Nokia) + * IBM - Initial API and implementation + * Ed Swartz (Nokia) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.c; import org.eclipse.cdt.core.dom.parser.GNUScannerExtensionConfiguration; -import org.eclipse.cdt.core.parser.GCCKeywords; -import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IMacro; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; @@ -23,17 +22,22 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap; public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfiguration { private static IMacro[] sAdditionalMacros; + private static CharArrayIntMap sAdditionalKeywords; static { final IMacro[] macros = GNUScannerExtensionConfiguration.getAdditionalGNUMacros(); sAdditionalMacros= new IMacro[macros.length+1]; System.arraycopy(macros, 0, sAdditionalMacros, 0, macros.length); sAdditionalMacros[macros.length]= createMacro("_Pragma(arg)", ""); //$NON-NLS-1$//$NON-NLS-2$ + + sAdditionalKeywords= new CharArrayIntMap(10, -1); + GNUScannerExtensionConfiguration.addAdditionalGNUKeywords(sAdditionalKeywords); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#supportMinAndMaxOperators() */ - public boolean supportMinAndMaxOperators() { + @Override + public boolean supportMinAndMaxOperators() { return false; } @@ -41,20 +45,17 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros() */ - public IMacro[] getAdditionalMacros() { + @Override + public IMacro[] getAdditionalMacros() { return sAdditionalMacros; } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalKeywords() */ - public CharArrayIntMap getAdditionalKeywords() { - CharArrayIntMap result = new CharArrayIntMap( 4, -1 ); - result.put( GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ ); - result.put( GCCKeywords.cpTYPEOF, IGCCToken.t_typeof ); - result.put( GCCKeywords.cp__ATTRIBUTE__, IGCCToken.t__attribute__ ); - result.put( GCCKeywords.cp__DECLSPEC, IGCCToken.t__declspec ); - return result; + @Override + public CharArrayIntMap getAdditionalKeywords() { + return sAdditionalKeywords; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java index 23e9edeaa23..9eabc9da3c8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java @@ -1,20 +1,19 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 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 - * Ed Swartz (Nokia) - * Anton Leherbauer (Wind River Systems) + * IBM - Initial API and implementation + * Ed Swartz (Nokia) + * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.parser.GNUScannerExtensionConfiguration; -import org.eclipse.cdt.core.parser.GCCKeywords; -import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; @@ -24,26 +23,28 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap; */ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfiguration { + private static CharArrayIntMap sAdditionalKeywords; + static { + sAdditionalKeywords= new CharArrayIntMap(10, -1); + GNUScannerExtensionConfiguration.addAdditionalGNUKeywords(sAdditionalKeywords); + sAdditionalKeywords.put( Keywords.cRESTRICT, IToken.t_restrict ); + sAdditionalKeywords.put( Keywords.c_COMPLEX, IToken.t__Complex ); + sAdditionalKeywords.put( Keywords.c_IMAGINARY, IToken.t__Imaginary ); + } + /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#supportMinAndMaxOperators() */ - public boolean supportMinAndMaxOperators() { + @Override + public boolean supportMinAndMaxOperators() { return true; } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalKeywords() */ - public CharArrayIntMap getAdditionalKeywords() { - CharArrayIntMap additionalCPPKeywords = new CharArrayIntMap( 8, -1 ); - additionalCPPKeywords.put( GCCKeywords.cp__ALIGNOF__, IGCCToken.t___alignof__ ); - additionalCPPKeywords.put( GCCKeywords.cpTYPEOF, IGCCToken.t_typeof ); - additionalCPPKeywords.put( GCCKeywords.cp__ATTRIBUTE__, IGCCToken.t__attribute__ ); - additionalCPPKeywords.put( Keywords.cRESTRICT, IToken.t_restrict ); - additionalCPPKeywords.put( Keywords.c_COMPLEX, IToken.t__Complex ); - additionalCPPKeywords.put( Keywords.c_IMAGINARY, IToken.t__Imaginary ); - additionalCPPKeywords.put( GCCKeywords.cp__DECLSPEC, IGCCToken.t__declspec ); - return additionalCPPKeywords; + @Override + public CharArrayIntMap getAdditionalKeywords() { + return sAdditionalKeywords; } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/GCCKeywords.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/GCCKeywords.java index d11d57d633b..98a25406a80 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/GCCKeywords.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/GCCKeywords.java @@ -1,15 +1,14 @@ /******************************************************************************* - * Copyright (c) 2002, 2007 IBM Corporation and others. + * Copyright (c) 2002, 2008 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 Rational Software - Initial API and implementation - * Ed Swartz (Nokia) + * IBM Rational Software - Initial API and implementation + * Ed Swartz (Nokia) *******************************************************************************/ - package org.eclipse.cdt.core.parser; /** @@ -28,4 +27,13 @@ public class GCCKeywords { public static final char [] cp__ATTRIBUTE__ = __ATTRIBUTE__.toCharArray(); public static final char [] cp__DECLSPEC = __DECLSPEC.toCharArray(); + public static final char [] cp__ASM__= "__asm__".toCharArray(); //$NON-NLS-1$ + public static final char [] cp__CONST__= "__const__".toCharArray(); //$NON-NLS-1$ + public static final char [] cp__CONST= "__const".toCharArray(); //$NON-NLS-1$ + public static final char [] cp__INLINE__= "__inline__".toCharArray(); //$NON-NLS-1$ + public static final char [] cp__RESTRICT__= "__restrict__".toCharArray(); //$NON-NLS-1$ + public static final char [] cp__RESTRICT= "__restrict".toCharArray(); //$NON-NLS-1$ + public static final char [] cp__VOLATILE__= "__volatile__".toCharArray(); //$NON-NLS-1$ + public static final char [] cp__SIGNED__= "__signed__".toCharArray(); //$NON-NLS-1$ + public static final char [] cp__TYPEOF__= "__typeof__".toCharArray(); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_MacroRef_NoPrefix.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_MacroRef_NoPrefix.java index 707c9a16bcc..2115b9db281 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_MacroRef_NoPrefix.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTest_MacroRef_NoPrefix.java @@ -36,24 +36,15 @@ public class CompletionTest_MacroRef_NoPrefix extends CompletionProposalsBaseTe "__LINE__", "__STDC__", "__TIME__", - "__asm__", "__builtin_constant_p(exp)", "__builtin_va_arg(ap, type)", "__complex__", - "__const", - "__const__", "__cplusplus", "__extension__", "__imag__", - "__inline__", "__null", "__real__", - "__restrict", - "__restrict__", - "__signed__", "__stdcall", - "__volatile__", - "__typeof__" }; public CompletionTest_MacroRef_NoPrefix(String name) { @@ -69,6 +60,7 @@ public class CompletionTest_MacroRef_NoPrefix extends CompletionProposalsBaseTe /* (non-Javadoc) * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition() */ + @Override protected int getCompletionPosition() { return getBuffer().indexOf("#ifdef ") + 7; } @@ -76,6 +68,7 @@ public class CompletionTest_MacroRef_NoPrefix extends CompletionProposalsBaseTe /* (non-Javadoc) * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix() */ + @Override protected String getExpectedPrefix() { return expectedPrefix; } @@ -83,6 +76,7 @@ public class CompletionTest_MacroRef_NoPrefix extends CompletionProposalsBaseTe /* (non-Javadoc) * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues() */ + @Override protected String[] getExpectedResultsValues() { return expectedResults; } @@ -90,6 +84,7 @@ public class CompletionTest_MacroRef_NoPrefix extends CompletionProposalsBaseTe /* (non-Javadoc) * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName() */ + @Override protected String getFileName() { return fileName; } @@ -97,12 +92,14 @@ public class CompletionTest_MacroRef_NoPrefix extends CompletionProposalsBaseTe /* (non-Javadoc) * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath() */ + @Override protected String getFileFullPath() { return fileFullPath; } /* (non-Javadoc) * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath() */ + @Override protected String getHeaderFileFullPath() { return headerFileFullPath; } @@ -110,6 +107,7 @@ public class CompletionTest_MacroRef_NoPrefix extends CompletionProposalsBaseTe /* (non-Javadoc) * @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName() */ + @Override protected String getHeaderFileName() { return headerFileName; } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java index daeada3ec7a..b3487bc5f1d 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java @@ -158,6 +158,7 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest { /* * @see org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest#setUpProjectContent(org.eclipse.core.resources.IProject) */ + @Override protected IFile setUpProjectContent(IProject project) throws Exception { fProject= project; String headerContent= readTaggedComment(HEADER_FILE_NAME); @@ -356,23 +357,14 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest { "__STDC_VERSION_", "__STDC__", "__TIME__", - "__asm__", "__builtin_constant_p(exp)", "__builtin_va_arg(ap, type)", "__complex__", - "__const", - "__const__", "__extension__", "__imag__", - "__inline__", "__null", "__real__", - "__restrict", - "__restrict__", - "__signed__", "__stdcall", - "__volatile__", - "__typeof__" }; assertCompletionResults(expected); }