mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 352309: Builtin type-traits conflict with old system headers
This commit is contained in:
parent
e40f225222
commit
df4c17ffdc
6 changed files with 107 additions and 34 deletions
|
@ -16,8 +16,10 @@ package org.eclipse.cdt.core.parser.tests.ast2;
|
|||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
|
@ -95,13 +97,23 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
|
|||
public class AST2BaseTest extends BaseTestCase {
|
||||
public final static String TEST_CODE = "<testcode>";
|
||||
protected static final IParserLogService NULL_LOG = new NullLogService();
|
||||
protected static boolean sValidateCopy;
|
||||
protected static boolean sValidateCopy;
|
||||
|
||||
private static final ScannerInfo GNU_SCANNER_INFO = new ScannerInfo(getGnuMap());
|
||||
private static final ScannerInfo SCANNER_INFO = new ScannerInfo();
|
||||
|
||||
private static Map<String, String> getGnuMap() {
|
||||
Map<String, String> map= new HashMap<String, String>();
|
||||
map.put("__GNUC__", "4");
|
||||
map.put("__GNUC_MINOR__", "5");
|
||||
return map;
|
||||
}
|
||||
|
||||
public AST2BaseTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AST2BaseTest(String name) {
|
||||
public AST2BaseTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
@ -133,7 +145,7 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
|
||||
boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
|
||||
IScanner scanner = createScanner(FileContent.create(TEST_CODE, code.toCharArray()), lang, ParserMode.COMPLETE_PARSE,
|
||||
new ScannerInfo());
|
||||
createScannerInfo(useGNUExtensions));
|
||||
configureScanner(scanner);
|
||||
AbstractGNUSourceCodeParser parser = null;
|
||||
if (lang == ParserLanguage.CPP) {
|
||||
|
@ -177,6 +189,12 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
return tu;
|
||||
}
|
||||
|
||||
public ScannerInfo createScannerInfo(boolean useGnu) {
|
||||
if (useGnu)
|
||||
return GNU_SCANNER_INFO;
|
||||
return SCANNER_INFO;
|
||||
}
|
||||
|
||||
protected void configureScanner(IScanner scanner) {
|
||||
}
|
||||
|
||||
|
@ -186,7 +204,7 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
if (lang == ParserLanguage.C)
|
||||
configuration= GCCScannerExtensionConfiguration.getInstance();
|
||||
else
|
||||
configuration= GPPScannerExtensionConfiguration.getInstance();
|
||||
configuration= GPPScannerExtensionConfiguration.getInstance(scannerInfo);
|
||||
IScanner scanner;
|
||||
scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration,
|
||||
IncludeFileContentProvider.getSavedFilesProvider());
|
||||
|
|
|
@ -19,8 +19,8 @@ import java.util.Map;
|
|||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
|
@ -82,7 +82,7 @@ public class PreprocessorSpeedTest {
|
|||
scannerConfig= GCCScannerExtensionConfiguration.getInstance();
|
||||
}
|
||||
else {
|
||||
scannerConfig= GPPScannerExtensionConfiguration.getInstance();
|
||||
scannerConfig= GPPScannerExtensionConfiguration.getInstance(info);
|
||||
}
|
||||
ParserMode mode = ParserMode.COMPLETE_PARSE;
|
||||
CPreprocessor cpp= new CPreprocessor(reader, info, lang, new NullLogService(), scannerConfig, readerFactory);
|
||||
|
|
|
@ -19,12 +19,12 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
|||
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.FileContent;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
|
@ -83,7 +83,7 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
|
|||
scannerConfig= GCCScannerExtensionConfiguration.getInstance();
|
||||
}
|
||||
else {
|
||||
scannerConfig= GPPScannerExtensionConfiguration.getInstance();
|
||||
scannerConfig= GPPScannerExtensionConfiguration.getInstance(scannerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
|||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||
|
@ -67,6 +68,11 @@ public class GPPLanguage extends AbstractCLikeLanguage {
|
|||
return CPP_GNU_SCANNER_EXTENSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IScannerExtensionConfiguration getScannerExtensionConfiguration(IScannerInfo info) {
|
||||
return GPPScannerExtensionConfiguration.getInstance(info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the extension configuration used for creating the parser.
|
||||
* @since 5.1
|
||||
|
|
|
@ -84,7 +84,17 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
|
|||
* return <code>null</code>
|
||||
*/
|
||||
protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration();
|
||||
|
||||
|
||||
/**
|
||||
* @return the scanner extension configuration for this language, may not
|
||||
* return <code>null</code>
|
||||
* @noreference
|
||||
* Will be available in next version of CDT.
|
||||
*/
|
||||
protected IScannerExtensionConfiguration getScannerExtensionConfiguration(IScannerInfo info) {
|
||||
return getScannerExtensionConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns the actual parser object.
|
||||
*/
|
||||
|
@ -212,7 +222,7 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
|
|||
* @since 5.2
|
||||
*/
|
||||
protected final IScanner createScanner(FileContent content, IScannerInfo scanInfo, IncludeFileContentProvider fcp, IParserLogService log) {
|
||||
return new CPreprocessor(content, scanInfo, getParserLanguage(), log, getScannerExtensionConfiguration(), fcp);
|
||||
return new CPreprocessor(content, scanInfo, getParserLanguage(), log, getScannerExtensionConfiguration(scanInfo), fcp);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
|
|
@ -14,9 +14,12 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.parser.cpp;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
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.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
|
||||
|
@ -25,38 +28,74 @@ import org.eclipse.cdt.core.parser.Keywords;
|
|||
*/
|
||||
public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfiguration {
|
||||
|
||||
private static GPPScannerExtensionConfiguration sInstance= new GPPScannerExtensionConfiguration();
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
private static final int VERSION_4_3 = version(4,3);
|
||||
private static GPPScannerExtensionConfiguration CONFIG= new GPPScannerExtensionConfiguration();
|
||||
private static GPPScannerExtensionConfiguration CONFIG_4_3= new GPPScannerExtensionConfiguration(VERSION_4_3);
|
||||
|
||||
private static int version(int major, int minor) {
|
||||
return (major << 16) + minor;
|
||||
}
|
||||
|
||||
|
||||
public static GPPScannerExtensionConfiguration getInstance() {
|
||||
return sInstance;
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
/**
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
* Will be available in next version of CDT.
|
||||
*/
|
||||
public static GPPScannerExtensionConfiguration getInstance(IScannerInfo info) {
|
||||
if (info != null) {
|
||||
try {
|
||||
final Map<String, String> definedSymbols = info.getDefinedSymbols();
|
||||
int major= Integer.valueOf(definedSymbols.get("__GNUC__")); //$NON-NLS-1$
|
||||
int minor= Integer.valueOf(definedSymbols.get("__GNUC_MINOR__")); //$NON-NLS-1$
|
||||
int version= version(major, minor);
|
||||
if (version >= VERSION_4_3) {
|
||||
return CONFIG_4_3;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Fall-back to the default configuration.
|
||||
}
|
||||
}
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
public GPPScannerExtensionConfiguration() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @noreference This constructor is not intended to be referenced by clients.
|
||||
* Will be available in next version of CDT.
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
public GPPScannerExtensionConfiguration() {
|
||||
public GPPScannerExtensionConfiguration(int version) {
|
||||
addMacro("__null", "0");
|
||||
addMacro("__builtin_offsetof(T,m)", "(reinterpret_cast <size_t>(&reinterpret_cast <const volatile char &>(static_cast<T*> (0)->m)))");
|
||||
addKeyword(Keywords.c_COMPLEX, IToken.t__Complex);
|
||||
addKeyword(Keywords.c_IMAGINARY, IToken.t__Imaginary);
|
||||
|
||||
// Type-traits
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_assign, IGCCToken.tTT_has_nothrow_assign);
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_constructor, IGCCToken.tTT_has_nothrow_constructor);
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_copy, IGCCToken.tTT_has_nothrow_copy);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_assign, IGCCToken.tTT_has_trivial_assign);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_constructor, IGCCToken.tTT_has_trivial_constructor);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_copy, IGCCToken.tTT_has_trivial_copy);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_destructor, IGCCToken.tTT_has_trivial_destructor);
|
||||
addKeyword(GCCKeywords.cp__has_virtual_destructor, IGCCToken.tTT_has_virtual_destructor);
|
||||
addKeyword(GCCKeywords.cp__is_abstract, IGCCToken.tTT_is_abstract);
|
||||
addKeyword(GCCKeywords.cp__is_base_of, IGCCToken.tTT_is_base_of);
|
||||
addKeyword(GCCKeywords.cp__is_class, IGCCToken.tTT_is_class);
|
||||
addKeyword(GCCKeywords.cp__is_empty, IGCCToken.tTT_is_empty);
|
||||
addKeyword(GCCKeywords.cp__is_enum, IGCCToken.tTT_is_enum);
|
||||
addKeyword(GCCKeywords.cp__is_pod, IGCCToken.tTT_is_pod);
|
||||
addKeyword(GCCKeywords.cp__is_polymorphic, IGCCToken.tTT_is_polymorphic);
|
||||
addKeyword(GCCKeywords.cp__is_union, IGCCToken.tTT_is_union);
|
||||
// Type-traits supported by gcc 4.3
|
||||
if (version >= VERSION_4_3) {
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_assign, IGCCToken.tTT_has_nothrow_assign);
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_constructor, IGCCToken.tTT_has_nothrow_constructor);
|
||||
addKeyword(GCCKeywords.cp__has_nothrow_copy, IGCCToken.tTT_has_nothrow_copy);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_assign, IGCCToken.tTT_has_trivial_assign);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_constructor, IGCCToken.tTT_has_trivial_constructor);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_copy, IGCCToken.tTT_has_trivial_copy);
|
||||
addKeyword(GCCKeywords.cp__has_trivial_destructor, IGCCToken.tTT_has_trivial_destructor);
|
||||
addKeyword(GCCKeywords.cp__has_virtual_destructor, IGCCToken.tTT_has_virtual_destructor);
|
||||
addKeyword(GCCKeywords.cp__is_abstract, IGCCToken.tTT_is_abstract);
|
||||
addKeyword(GCCKeywords.cp__is_base_of, IGCCToken.tTT_is_base_of);
|
||||
addKeyword(GCCKeywords.cp__is_class, IGCCToken.tTT_is_class);
|
||||
addKeyword(GCCKeywords.cp__is_empty, IGCCToken.tTT_is_empty);
|
||||
addKeyword(GCCKeywords.cp__is_enum, IGCCToken.tTT_is_enum);
|
||||
addKeyword(GCCKeywords.cp__is_pod, IGCCToken.tTT_is_pod);
|
||||
addKeyword(GCCKeywords.cp__is_polymorphic, IGCCToken.tTT_is_polymorphic);
|
||||
addKeyword(GCCKeywords.cp__is_union, IGCCToken.tTT_is_union);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
Loading…
Add table
Reference in a new issue