Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarkus Schorn2011-07-27 08:56:42 -0400
committerMarkus Schorn2011-07-27 08:56:42 -0400
commit16da85ea6b2727782f9c936558cbb25ef9e7b702 (patch)
tree2a2f9c8ed728f004a3312515d80adcba274d9c44 /core
parenta8fb1e337610bb7dbfd1d70639770f7f07746bf3 (diff)
downloadorg.eclipse.cdt-16da85ea6b2727782f9c936558cbb25ef9e7b702.tar.gz
org.eclipse.cdt-16da85ea6b2727782f9c936558cbb25ef9e7b702.tar.xz
org.eclipse.cdt-16da85ea6b2727782f9c936558cbb25ef9e7b702.zip
Bug 352309: Builtin type-traits conflict with old system headers
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java26
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorSpeedTest.java4
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java81
6 files changed, 103 insertions, 33 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java
index bc1fedf307..8fe04b57bb 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java
@@ -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());
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorSpeedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorSpeedTest.java
index 0756ab1c65..0cec65e2ba 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorSpeedTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorSpeedTest.java
@@ -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);
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java
index b69afa240e..c688c1defd 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java
@@ -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);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java
index df18b86caf..b4350e2666 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java
@@ -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
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java
index 77e0e39fe5..952ca28671 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java
@@ -84,7 +84,16 @@ 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>
+ * @since 5.4
+ */
+ protected IScannerExtensionConfiguration getScannerExtensionConfiguration(IScannerInfo info) {
+ return getScannerExtensionConfiguration();
+ }
+
/**
* @returns the actual parser object.
*/
@@ -212,7 +221,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
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 9d20619807..451c0604a5 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
@@ -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,72 @@ import org.eclipse.cdt.core.parser.Keywords;
*/
public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfiguration {
- private static GPPScannerExtensionConfiguration sInstance= new GPPScannerExtensionConfiguration();
+ 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 CONFIG;
+ }
+
/**
- * @since 5.1
+ * @since 5.4
*/
- public static GPPScannerExtensionConfiguration getInstance() {
- return sInstance;
+ 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);
}
+ /**
+ * @since 5.4
+ */
@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)

Back to the top