1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-20 07:25:23 +02:00

Bug 328259: Differentiate function-style and object-style macros, by Patrick Hofer.

This commit is contained in:
Markus Schorn 2010-10-21 10:38:51 +00:00
parent 7b99473f65
commit befb4d9e04
6 changed files with 40 additions and 5 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2009 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
@ -28,4 +28,10 @@ public interface IMacro extends ICElement, ISourceManipulation, ISourceReference
* @return String * @return String
*/ */
String getTokenSequence(); String getTokenSequence();
/**
* Returns true if this macro is of function style.
* @since 5.3
*/
boolean isFunctionStyle();
} }

View file

@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
@ -305,6 +306,9 @@ public class CModelBuilder2 implements IContributedModelBuilder {
// set positions // set positions
setIdentifierPosition(element, name); setIdentifierPosition(element, name);
setBodyPosition(element, macro); setBodyPosition(element, macro);
if (macro instanceof IASTPreprocessorFunctionStyleMacroDefinition) {
element.setFunctionStyle(true);
}
return element; return element;
} }

View file

@ -1,12 +1,12 @@
/******************************************************************************* /*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Rational Software - Initial API and implementation * Rational Software - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
@ -16,6 +16,12 @@ import org.eclipse.cdt.core.model.IMacro;
public class Macro extends SourceManipulation implements IMacro { public class Macro extends SourceManipulation implements IMacro {
private boolean fFunctionStyle = false;
public void setFunctionStyle(boolean isFunctionStyle) {
this.fFunctionStyle = isFunctionStyle;
}
public Macro(ICElement parent, String name) { public Macro(ICElement parent, String name) {
super(parent, name, ICElement.C_MACRO); super(parent, name, ICElement.C_MACRO);
} }
@ -32,4 +38,8 @@ public class Macro extends SourceManipulation implements IMacro {
protected CElementInfo createElementInfo () { protected CElementInfo createElementInfo () {
return new SourceManipulationInfo(this); return new SourceManipulationInfo(this);
} }
public boolean isFunctionStyle() {
return fFunctionStyle;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 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
@ -17,8 +17,11 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
public class MacroHandle extends CElementHandle implements IMacro { public class MacroHandle extends CElementHandle implements IMacro {
private final boolean fFunctionStyle;
public MacroHandle(ITranslationUnit tu, IIndexMacro macro) { public MacroHandle(ITranslationUnit tu, IIndexMacro macro) {
super(tu, ICElement.C_MACRO, new String(macro.getName())); super(tu, ICElement.C_MACRO, new String(macro.getName()));
fFunctionStyle= macro.isFunctionStyle();
} }
public String getIdentifierList() { public String getIdentifierList() {
@ -28,4 +31,8 @@ public class MacroHandle extends CElementHandle implements IMacro {
public String getTokenSequence() { public String getTokenSequence() {
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
public boolean isFunctionStyle() {
return fFunctionStyle;
}
} }

View file

@ -92,6 +92,7 @@ public class BasicOutlineTest extends BaseUITestCase {
//#include "user.h" //#include "user.h"
//#include <system.h> //#include <system.h>
//#define MACRO //#define MACRO
//#define MACRO2()
//int main(int argc, char** argv) {} //int main(int argc, char** argv) {}
public void testSimpleOutlineContent() throws Exception { public void testSimpleOutlineContent() throws Exception {
StringBuffer[] contents= getContentsForTest(1); StringBuffer[] contents= getContentsForTest(1);
@ -105,7 +106,8 @@ public class BasicOutlineTest extends BaseUITestCase {
Tree tree= checkTreeNode(outline, 0, "user.h").getParent(); Tree tree= checkTreeNode(outline, 0, "user.h").getParent();
checkTreeNode(tree, 1, "system.h"); checkTreeNode(tree, 1, "system.h");
checkTreeNode(tree, 2, "MACRO"); checkTreeNode(tree, 2, "MACRO");
checkTreeNode(tree, 3, "main(int, char**) : int"); checkTreeNode(tree, 3, "MACRO2()");
checkTreeNode(tree, 4, "main(int, char**) : int");
} }
//class Foo { //class Foo {

View file

@ -296,6 +296,12 @@ public class CElementLabelComposer {
*/ */
public void appendMacroLabel(IMacro macro, long flags) { public void appendMacroLabel(IMacro macro, long flags) {
fBuffer.append(macro.getElementName()); fBuffer.append(macro.getElementName());
if( getFlag( flags, CElementLabels.M_PARAMETER_TYPES ) ) {
if (macro.isFunctionStyle()) {
fBuffer.append("()"); //$NON-NLS-1$
}
}
if( getFlag(flags, CElementLabels.MF_POST_FILE_QUALIFIED)) { if( getFlag(flags, CElementLabels.MF_POST_FILE_QUALIFIED)) {
IPath path= macro.getPath(); IPath path= macro.getPath();
if (path != null) { if (path != null) {