mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 06:45:43 +02:00
Configure gcc-extensions as keywords, rather than macros, bug 226112.
This commit is contained in:
parent
61cc1a811f
commit
52d3320503
7 changed files with 93 additions and 69 deletions
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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$
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue