From 60bb3058a1e7276bf7fcc578eec1d1b135e650e4 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Fri, 10 Jun 2005 18:46:10 +0000 Subject: [PATCH] fix bug 99256 - allow anonymous structures Patch from Devin Steffler for bug 99262 - __null builtin --- .../core/parser/tests/ast2/AST2CPPTests.java | 17 +++++++++++++++++ .../cdt/core/parser/tests/ast2/AST2Tests.java | 17 +++++++++++++++++ .../core/dom/parser/cpp/CPPSemantics.java | 4 ++-- .../GNUScannerExtensionConfiguration.java | 4 ++++ 4 files changed, 40 insertions(+), 2 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 dd2c9dfc555..a4256dd60de 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 @@ -4739,4 +4739,21 @@ public class AST2CPPTests extends AST2BaseTest { assertSame( i, col.getName(2).resolveBinding() ); assertSame( j, col.getName(5).resolveBinding() ); } + + public void testBug99262() throws Exception { + parse("void foo() {void *f; f=__null;}", ParserLanguage.CPP, true, true ); + } + + public void testBug99262B() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("int foo2(void *) {\n"); //$NON-NLS-1$ + buffer.append("return 0;\n"); //$NON-NLS-1$ + buffer.append("}\n"); //$NON-NLS-1$ + buffer.append("int foo3() {\n"); //$NON-NLS-1$ + buffer.append("return foo2(__null);\n"); //$NON-NLS-1$ + buffer.append("}\n"); //$NON-NLS-1$ + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP, true, true ); + assertTrue(((IASTIdExpression)((IASTFunctionCallExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[1]).getBody()).getStatements()[0]).getReturnValue()).getFunctionNameExpression()).getName().resolveBinding() instanceof IFunction); + } + } 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 f16d16bfe32..5e411f8a360 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 @@ -3160,4 +3160,21 @@ public class AST2Tests extends AST2BaseTest { IEnumerator etor = (IEnumerator) col.getName(2).resolveBinding(); assertSame( etor, col.getName(6).resolveBinding() ); } + + public void testBug99262() throws Exception { + parse("void foo() {void *f; f=__null;}", ParserLanguage.C, true, true ); + } + + public void testBug99262B() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("int foo2(void *) {\n"); //$NON-NLS-1$ + buffer.append("return 0;\n"); //$NON-NLS-1$ + buffer.append("}\n"); //$NON-NLS-1$ + buffer.append("int foo3() {\n"); //$NON-NLS-1$ + buffer.append("return foo2(__null);\n"); //$NON-NLS-1$ + buffer.append("}\n"); //$NON-NLS-1$ + IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, true ); + assertTrue(((IASTIdExpression)((IASTFunctionCallExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[1]).getBody()).getStatements()[0]).getReturnValue()).getFunctionNameExpression()).getName().resolveBinding() instanceof IFunction); + } + } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index ce019585df1..e7339dcb106 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -1464,8 +1464,8 @@ public class CPPSemantics { ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) declSpec; specName = compSpec.getName(); - //anonymous union? - if( declarators.length == 0 && compSpec.getKey() == IASTCompositeTypeSpecifier.k_union && + //anonymous union? //GCC supports anonymous structs too + if( declarators.length == 0 && /*compSpec.getKey() == IASTCompositeTypeSpecifier.k_union &&*/ specName.toCharArray().length == 0 ) { Object o = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerExtensionConfiguration.java index 3d62316a09e..f3e599e6353 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GNUScannerExtensionConfiguration.java @@ -71,6 +71,9 @@ public abstract class GNUScannerExtensionConfiguration implements IScannerExtens private static final ObjectStyleMacro __imag__ = new ObjectStyleMacro( "__imag__".toCharArray(), "(int)".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ + + private static final ObjectStyleMacro __null = new ObjectStyleMacro( + "__null".toCharArray(), "(void *)0".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ private static final FunctionStyleMacro __attribute__ = new FunctionStyleMacro( "__attribute__".toCharArray(), //$NON-NLS-1$ @@ -109,6 +112,7 @@ public abstract class GNUScannerExtensionConfiguration implements IScannerExtens realDefinitions.put(__signed__.name, __signed__); realDefinitions.put(__complex__.name, __complex__); realDefinitions.put(__imag__.name, __imag__); + realDefinitions.put( __null.name, __null ); realDefinitions.put(__real__.name, __real__); realDefinitions.put(__builtin_va_arg.name, __builtin_va_arg); realDefinitions.put(__builtin_constant_p.name, __builtin_constant_p);