From e065c23034b7b551dba6ee70c7890bca24c86e19 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 8 Feb 2010 14:39:19 +0000 Subject: [PATCH] Bug 294730: Predefined identifier __func__ --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 1 + ...AbstractCParserExtensionConfiguration.java | 8 +-- .../c/GCCParserExtensionConfiguration.java | 4 +- ...stractCPPParserExtensionConfiguration.java | 8 +-- .../cpp/GPPParserExtensionConfiguration.java | 4 +- .../dom/parser/CBuiltinSymbolProvider.java | 64 ------------------- .../dom/parser/GCCBuiltinSymbolProvider.java | 16 +++-- 7 files changed, 21 insertions(+), 84 deletions(-) delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CBuiltinSymbolProvider.java 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 0ac4d60d070..2ff3003969e 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 @@ -5663,6 +5663,7 @@ public class AST2Tests extends AST2BaseTest { // } public void testPredefinedFunctionName_Bug247747() throws Exception { parseAndCheckBindings(getAboveComment(), ParserLanguage.C, false); + parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, false); } // void alloc(const char * id) {} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java index 30f1c73d984..2589220e106 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCParserExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2010 Wind River Systems, Inc. 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 @@ -13,7 +13,6 @@ package org.eclipse.cdt.core.dom.parser.c; import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.internal.core.dom.parser.CBuiltinSymbolProvider; import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; @@ -83,10 +82,7 @@ public abstract class AbstractCParserExtensionConfiguration implements ICParserE * @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#getBuiltinSymbolProvider() */ public IBuiltinBindingsProvider getBuiltinBindingsProvider() { - if (supportGCCOtherBuiltinSymbols()) { - return new GCCBuiltinSymbolProvider(ParserLanguage.C); - } - return new CBuiltinSymbolProvider(); + return new GCCBuiltinSymbolProvider(ParserLanguage.C, supportGCCOtherBuiltinSymbols()); } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java index 5df338d2a0b..74ff3989434 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCParserExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2010 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 @@ -89,6 +89,6 @@ public class GCCParserExtensionConfiguration extends AbstractCParserExtensionCon */ @Override public IBuiltinBindingsProvider getBuiltinBindingsProvider() { - return new GCCBuiltinSymbolProvider(ParserLanguage.C); + return new GCCBuiltinSymbolProvider(ParserLanguage.C, true); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java index 236b5d658c2..20b8b98a1d9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2010 Wind River Systems, Inc. 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 @@ -9,7 +9,6 @@ * Anton Leherbauer (Wind River Systems) - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; @@ -143,9 +142,6 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#getBuiltinBindingsProvider() */ public IBuiltinBindingsProvider getBuiltinBindingsProvider() { - if (supportGCCOtherBuiltinSymbols()) { - return new GCCBuiltinSymbolProvider(ParserLanguage.CPP); - } - return null; + return new GCCBuiltinSymbolProvider(ParserLanguage.CPP, supportGCCOtherBuiltinSymbols()); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java index 80441e92c9b..23258d5da2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPParserExtensionConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2008 IBM Corporation and others. + * Copyright (c) 2002, 2010 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 @@ -129,6 +129,6 @@ public class GPPParserExtensionConfiguration extends AbstractCPPParserExtensionC */ @Override public IBuiltinBindingsProvider getBuiltinBindingsProvider() { - return new GCCBuiltinSymbolProvider(ParserLanguage.CPP); + return new GCCBuiltinSymbolProvider(ParserLanguage.CPP, true); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CBuiltinSymbolProvider.java deleted file mode 100644 index df3e49afd4d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/CBuiltinSymbolProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2009 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 - * Markus Schorn (Wind River Systems) - * Anton Leherbauer (Wind River Systems) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.dom.parser; - -import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; -import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.IScope; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; -import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; -import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType; -import org.eclipse.cdt.internal.core.dom.parser.c.CBuiltinVariable; -import org.eclipse.cdt.internal.core.dom.parser.c.CPointerType; -import org.eclipse.cdt.internal.core.dom.parser.c.CQualifierType; - -/** - * This is the IBuiltinBindingsProvider used to implement the standard builtin bindings: - */ -public class CBuiltinSymbolProvider implements IBuiltinBindingsProvider { - public static final ASTNodeProperty BUILTIN_SYMBOL = new ASTNodeProperty( - "GCCBuiltinSymbolProvider.BUILTIN_SYMBOL - built-in symbol"); //$NON-NLS-1$ - - private static final char[] __FUNC__ = "__func__".toCharArray(); //$NON-NLS-1$ - private static final int NUM_BUILTINS = 1; // the total number of builtin functions listed above - - static final private IType c_char; - static final private IType c_const_char_p; - static { - c_char = new CBasicType(Kind.eChar, 0); - c_const_char_p = new CPointerType(new CQualifierType(c_char, true, false, false), 0); - } - - private IBinding[] bindings=new IBinding[NUM_BUILTINS]; - private IScope scope=null; - public CBuiltinSymbolProvider() { - } - - public IBinding[] getBuiltinBindings(IScope scope) { - this.scope= scope; - initialize(); - return (IBinding[])ArrayUtil.trim(IBinding.class, bindings); - } - - private void initialize() { - __func__(); - } - - private void __func__() { - // const char * __func__; - IBinding temp= new CBuiltinVariable(c_const_char_p, __FUNC__, scope); - bindings = (IBinding[])ArrayUtil.append(IBinding.class, bindings, temp); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java index 0760dce0ec6..a13012b0b62 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 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 @@ -359,12 +359,21 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { private IBinding[] bindings= new IBinding[NUM_OTHER_GCC_BUILTINS]; private IScope scope= null; - private ParserLanguage lang= null; - public GCCBuiltinSymbolProvider(ParserLanguage lang) { + private final ParserLanguage lang; + private final boolean supportGnuSymbols; + public GCCBuiltinSymbolProvider(ParserLanguage lang, boolean supportGnuSymbols) { this.lang = lang; + this.supportGnuSymbols= supportGnuSymbols; } private void initialize() { + // Symbols for all parsers + __func__(); + + // Gnu only + if (!supportGnuSymbols) + return; + __builtin_va_list(); __builtin_va_start(); __builtin_va_end(); @@ -392,7 +401,6 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { __builtin_mem(); __builtin_str_strn(); __builtin_less_greater(); - __func__(); } private void __func__() {