mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Bug 294730: Predefined identifier __func__
This commit is contained in:
parent
648f5c9331
commit
e065c23034
7 changed files with 21 additions and 84 deletions
|
@ -5663,6 +5663,7 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
// }
|
// }
|
||||||
public void testPredefinedFunctionName_Bug247747() throws Exception {
|
public void testPredefinedFunctionName_Bug247747() throws Exception {
|
||||||
parseAndCheckBindings(getAboveComment(), ParserLanguage.C, false);
|
parseAndCheckBindings(getAboveComment(), ParserLanguage.C, false);
|
||||||
|
parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void alloc(const char * id) {}
|
// void alloc(const char * id) {}
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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.dom.parser.IBuiltinBindingsProvider;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
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;
|
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()
|
* @see org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration#getBuiltinSymbolProvider()
|
||||||
*/
|
*/
|
||||||
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
|
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
|
||||||
if (supportGCCOtherBuiltinSymbols()) {
|
return new GCCBuiltinSymbolProvider(ParserLanguage.C, supportGCCOtherBuiltinSymbols());
|
||||||
return new GCCBuiltinSymbolProvider(ParserLanguage.C);
|
|
||||||
}
|
|
||||||
return new CBuiltinSymbolProvider();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -89,6 +89,6 @@ public class GCCParserExtensionConfiguration extends AbstractCParserExtensionCon
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
|
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
|
||||||
return new GCCBuiltinSymbolProvider(ParserLanguage.C);
|
return new GCCBuiltinSymbolProvider(ParserLanguage.C, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -9,7 +9,6 @@
|
||||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.core.dom.parser.cpp;
|
package org.eclipse.cdt.core.dom.parser.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
|
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()
|
* @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#getBuiltinBindingsProvider()
|
||||||
*/
|
*/
|
||||||
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
|
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
|
||||||
if (supportGCCOtherBuiltinSymbols()) {
|
return new GCCBuiltinSymbolProvider(ParserLanguage.CPP, supportGCCOtherBuiltinSymbols());
|
||||||
return new GCCBuiltinSymbolProvider(ParserLanguage.CPP);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -129,6 +129,6 @@ public class GPPParserExtensionConfiguration extends AbstractCPPParserExtensionC
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
|
public IBuiltinBindingsProvider getBuiltinBindingsProvider() {
|
||||||
return new GCCBuiltinSymbolProvider(ParserLanguage.CPP);
|
return new GCCBuiltinSymbolProvider(ParserLanguage.CPP, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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 IBinding[] bindings= new IBinding[NUM_OTHER_GCC_BUILTINS];
|
||||||
private IScope scope= null;
|
private IScope scope= null;
|
||||||
private ParserLanguage lang= null;
|
private final ParserLanguage lang;
|
||||||
public GCCBuiltinSymbolProvider(ParserLanguage lang) {
|
private final boolean supportGnuSymbols;
|
||||||
|
public GCCBuiltinSymbolProvider(ParserLanguage lang, boolean supportGnuSymbols) {
|
||||||
this.lang = lang;
|
this.lang = lang;
|
||||||
|
this.supportGnuSymbols= supportGnuSymbols;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
|
// Symbols for all parsers
|
||||||
|
__func__();
|
||||||
|
|
||||||
|
// Gnu only
|
||||||
|
if (!supportGnuSymbols)
|
||||||
|
return;
|
||||||
|
|
||||||
__builtin_va_list();
|
__builtin_va_list();
|
||||||
__builtin_va_start();
|
__builtin_va_start();
|
||||||
__builtin_va_end();
|
__builtin_va_end();
|
||||||
|
@ -392,7 +401,6 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
|
||||||
__builtin_mem();
|
__builtin_mem();
|
||||||
__builtin_str_strn();
|
__builtin_str_strn();
|
||||||
__builtin_less_greater();
|
__builtin_less_greater();
|
||||||
__func__();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void __func__() {
|
private void __func__() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue