From bfa93d84d0072c7b392689962d3510a0659a85c6 Mon Sep 17 00:00:00 2001
From: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Date: Mon, 14 Jul 2008 01:28:03 +0000
Subject: [PATCH] Different definitions of __null for C and C++ (bug 240567).

---
 .../cdt/core/parser/tests/ast2/AST2CPPTests.java  | 15 +++++++--------
 .../cdt/core/parser/tests/ast2/AST2Tests.java     | 15 +++++++--------
 .../parser/GNUScannerExtensionConfiguration.java  |  2 +-
 .../c/GCCScannerExtensionConfiguration.java       |  2 ++
 .../cpp/GPPScannerExtensionConfiguration.java     |  2 ++
 5 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index 266d5bf331f..6125af78517 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -4872,18 +4872,17 @@ public class AST2CPPTests extends AST2BaseTest {
 	}
 	
 	public void testBug99262() throws Exception {
-		parse("void foo() {void *f; f=__null;}", ParserLanguage.CPP, true, true ); //$NON-NLS-1$
+		parse("void foo() {void *f; f=__null;}", ParserLanguage.CPP, true, true); //$NON-NLS-1$
 	}
 	
-	// int foo2(void *) {
-	// return 0;
+	// void f1(int*) {
 	// }
-	// int foo3() {
-	// return foo2(__null);
+	// void f2() {
+	//   f1(__null);
 	// }
-	public void testBug99262B() throws Exception {
-		IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true ); 
-		assertTrue(((IASTIdExpression)((IASTFunctionCallExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[1]).getBody()).getStatements()[0]).getReturnValue()).getFunctionNameExpression()).getName().resolveBinding() instanceof IFunction);
+	public void testBug240567() throws Exception {    	  
+    	BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true);
+		bh.assertNonProblem("f1(__null", 2, ICPPFunction.class);
 	}
 	
 	public void testBug100408() throws Exception {
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 b88fd51a592..4bdc144e3f5 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
@@ -3146,18 +3146,17 @@ public class AST2Tests extends AST2BaseTest {
 	}
 	
 	public void testBug99262() throws Exception {
-		parse("void foo() {void *f; f=__null;}", ParserLanguage.C, true, true ); //$NON-NLS-1$
+		parse("void foo() {void *f; f=__null;}", ParserLanguage.C, true, true); //$NON-NLS-1$
 	}
 	
-	// int foo2(void *) {
-	// return 0;
+	// void f1(int*) {
 	// }
-	// int foo3() {
-	// return foo2(__null);
+	// void f2() {
+	//   f1(__null);
 	// }
-	public void testBug99262B() throws Exception {    	  
-		IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true, true );
-		assertTrue(((IASTIdExpression)((IASTFunctionCallExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[1]).getBody()).getStatements()[0]).getReturnValue()).getFunctionNameExpression()).getName().resolveBinding() instanceof IFunction);
+	public void testBug240567() throws Exception {    	  
+    	BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), false);
+		bh.assertNonProblem("f1(__null", 2, IFunction.class);
 	}
 	
 	// void f() {                    
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 0c0973acafc..8166319eabb 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
@@ -9,6 +9,7 @@
  *    IBM - Initial API and implementation
  *    Anton Leherbauer (Wind River Systems)
  *    Markus Schorn (Wind River Systems)
+ *    Sergey Prigogin (Google)
  *******************************************************************************/
 package org.eclipse.cdt.core.dom.parser;
 
@@ -32,7 +33,6 @@ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerEx
 		addMacro("__complex__", "_Complex");
 		addMacro("__extension__", ""); 
 		addMacro("__imag__", "(int)"); 
-		addMacro("__null", "(void *)0");
 		addMacro("__real__", "(int)");
 		addMacro("__stdcall", "");
 
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 57de27534cd..02612b6c5e3 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
@@ -9,6 +9,7 @@
  *    IBM - Initial API and implementation
  *    Ed Swartz (Nokia)
  *    Markus Schorn (Wind River Systems)
+ *    Sergey Prigogin (Google)
  *******************************************************************************/
 package org.eclipse.cdt.core.dom.parser.c;
 
@@ -28,6 +29,7 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu
 	}
 
 	public GCCScannerExtensionConfiguration() {
+		addMacro("__null", "(void *)0");  //$NON-NLS-1$//$NON-NLS-2$
 		addMacro("_Pragma(arg)", "");  //$NON-NLS-1$//$NON-NLS-2$
 	}
 
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 7fed446553f..20b1f4412d1 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
@@ -10,6 +10,7 @@
  *    Ed Swartz (Nokia)
  *    Anton Leherbauer (Wind River Systems)
  *    Markus Schorn (Wind River Systems)
+ *    Sergey Prigogin (Google)
  *******************************************************************************/
 package org.eclipse.cdt.core.dom.parser.cpp;
 
@@ -31,6 +32,7 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
 	}
 	
 	public GPPScannerExtensionConfiguration() {
+		addMacro("__null", "0");  //$NON-NLS-1$//$NON-NLS-2$
 		addKeyword(Keywords.cRESTRICT, IToken.t_restrict);
 		addKeyword(Keywords.c_COMPLEX, IToken.t__Complex);
 		addKeyword(Keywords.c_IMAGINARY, IToken.t__Imaginary);