mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Support for __func__, bug 247747.
This commit is contained in:
parent
c7cf3b3790
commit
c47ff4d34f
7 changed files with 328 additions and 3 deletions
|
@ -5273,4 +5273,23 @@ public class AST2Tests extends AST2BaseTest {
|
|||
parseAndCheckBindings(getAboveComment(), lang, true);
|
||||
}
|
||||
}
|
||||
|
||||
// void alloc(const char * id) {}
|
||||
// void test() {
|
||||
// alloc(__func__);
|
||||
// }
|
||||
public void testPredefinedFunctionName_Bug247747() throws Exception {
|
||||
parseAndCheckBindings(getAboveComment(), ParserLanguage.C, false);
|
||||
}
|
||||
|
||||
// void alloc(const char * id) {}
|
||||
// void test() {
|
||||
// alloc(__func__);
|
||||
// alloc(__FUNCTION__);
|
||||
// alloc(__PRETTY_FUNCTION__);
|
||||
// }
|
||||
public void testPredefinedFunctionNameGcc_Bug247747() throws Exception {
|
||||
parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true);
|
||||
parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ 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;
|
||||
|
||||
|
||||
|
@ -85,7 +86,7 @@ public abstract class AbstractCParserExtensionConfiguration implements ICParserE
|
|||
if (supportGCCOtherBuiltinSymbols()) {
|
||||
return new GCCBuiltinSymbolProvider(ParserLanguage.C);
|
||||
}
|
||||
return null;
|
||||
return new CBuiltinSymbolProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 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.IBasicType;
|
||||
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.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 {
|
||||
new CBasicType(IBasicType.t_unspecified, 0);
|
||||
c_char = new CBasicType( IBasicType.t_char, 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);
|
||||
}
|
||||
}
|
|
@ -30,12 +30,14 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.c.CFunctionType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitFunction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CImplicitTypedef;
|
||||
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;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTypedef;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBuiltinVariable;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPBasicType;
|
||||
|
@ -161,8 +163,11 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
|
|||
private static final char[] __BUILTIN_ISLESSEQUAL = "__builtin_islessequal".toCharArray(); //$NON-NLS-1$
|
||||
private static final char[] __BUILTIN_ISLESSGREATER = "__builtin_islessgreater".toCharArray(); //$NON-NLS-1$
|
||||
private static final char[] __BUILTIN_ISUNORDERED = "__builtin_isunordered".toCharArray(); //$NON-NLS-1$
|
||||
private static final char[] __FUNC__ = "__func__".toCharArray(); //$NON-NLS-1$
|
||||
private static final char[] __FUNCTION__ = "__FUNCTION__".toCharArray(); //$NON-NLS-1$
|
||||
private static final char[] __PRETTY_FUNCTION__ = "__PRETTY_FUNCTION__".toCharArray(); //$NON-NLS-1$
|
||||
|
||||
private static final int NUM_OTHER_GCC_BUILTINS = 105; // the total number of builtin functions listed above
|
||||
private static final int NUM_OTHER_GCC_BUILTINS = 109; // the total number of builtin functions listed above
|
||||
|
||||
static final private IType c_unspecified;
|
||||
static final private IType c_char;
|
||||
|
@ -320,8 +325,26 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
|
|||
__builtin_mem();
|
||||
__builtin_str_strn();
|
||||
__builtin_less_greater();
|
||||
__func__();
|
||||
}
|
||||
|
||||
private void __func__() {
|
||||
// const char * __func__;
|
||||
IBinding temp1, temp2, temp3;
|
||||
if (lang == ParserLanguage.C) {
|
||||
temp1 = new CBuiltinVariable(c_const_char_p, __FUNC__, scope);
|
||||
temp2 = new CBuiltinVariable(c_const_char_p, __FUNCTION__, scope);
|
||||
temp3 = new CBuiltinVariable(c_const_char_p, __PRETTY_FUNCTION__, scope);
|
||||
} else {
|
||||
temp1 = new CPPBuiltinVariable(cpp_const_char_p, __FUNC__, scope);
|
||||
temp2 = new CPPBuiltinVariable(cpp_const_char_p, __FUNCTION__, scope);
|
||||
temp3 = new CPPBuiltinVariable(cpp_const_char_p, __PRETTY_FUNCTION__, scope);
|
||||
}
|
||||
bindings = (IBinding[])ArrayUtil.append(IBinding.class, bindings, temp1);
|
||||
bindings = (IBinding[])ArrayUtil.append(IBinding.class, bindings, temp2);
|
||||
bindings = (IBinding[])ArrayUtil.append(IBinding.class, bindings, temp3);
|
||||
}
|
||||
|
||||
private void __builtin_va_list() {
|
||||
// char * __builtin_va_list();
|
||||
IBinding temp = null;
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
||||
/**
|
||||
* Used to represent built-in variables that exist on the translation
|
||||
* unit but are not actually part of the physical AST created by CDT.
|
||||
*
|
||||
* An example is the built-in variable __func__.
|
||||
*/
|
||||
public class CBuiltinVariable extends CVariable {
|
||||
private IType type=null;
|
||||
private char[] name=null;
|
||||
private IScope scope=null;
|
||||
|
||||
public CBuiltinVariable(IType type, char[] name, IScope scope) {
|
||||
super(null);
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.valueOf(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getNameCharArray() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScope getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns null
|
||||
*/
|
||||
@Override
|
||||
public IASTNode[] getDeclarations() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns null
|
||||
*/
|
||||
@Override
|
||||
public IASTNode getDefinition() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
||||
/**
|
||||
* Used to represent built-in variables that exist on the translation
|
||||
* unit but are not actually part of the physical AST created by CDT.
|
||||
*
|
||||
* An example is the built-in variable __func__.
|
||||
*/
|
||||
public class CPPBuiltinVariable extends CPPVariable {
|
||||
private IType type=null;
|
||||
private char[] name=null;
|
||||
private IScope scope=null;
|
||||
|
||||
public CPPBuiltinVariable(IType type, char[] name, IScope scope) {
|
||||
super(null);
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return String.valueOf(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getNameCharArray() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScope getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns null
|
||||
*/
|
||||
@Override
|
||||
public IASTNode[] getDeclarations() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns null
|
||||
*/
|
||||
@Override
|
||||
public IASTNode getDefinition() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* does nothing
|
||||
*/
|
||||
@Override
|
||||
public void addDefinition(IASTNode node) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* does nothing
|
||||
*/
|
||||
@Override
|
||||
public void addDeclaration(IASTNode node) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* does nothing
|
||||
*/
|
||||
@Override
|
||||
public void removeDeclaration(IASTNode node) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getQualifiedName() {
|
||||
String[] temp = new String[1];
|
||||
temp[0] = String.valueOf(name);
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public char[][] getQualifiedNameCharArray() {
|
||||
char[][] temp = new char[1][];
|
||||
temp[0] = name;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true
|
||||
*/
|
||||
@Override
|
||||
public boolean isGloballyQualified() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDefinition(IASTName name) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -91,7 +91,13 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
|
|||
definition = name;
|
||||
else
|
||||
declarations = new IASTName[] { name };
|
||||
name.setBinding(this);
|
||||
|
||||
// built-in variables supply a null
|
||||
if (name != null) {
|
||||
name.setBinding(this);
|
||||
} else {
|
||||
assert this instanceof CPPBuiltinVariable;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isDefinition(IASTName name) {
|
||||
|
|
Loading…
Add table
Reference in a new issue