1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-19 06:55: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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -28,4 +28,10 @@ public interface IMacro extends ICElement, ISourceManipulation, ISourceReference
* @return String
*/
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.IASTNode;
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.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
@ -305,6 +306,9 @@ public class CModelBuilder2 implements IContributedModelBuilder {
// set positions
setIdentifierPosition(element, name);
setBodyPosition(element, macro);
if (macro instanceof IASTPreprocessorFunctionStyleMacroDefinition) {
element.setFunctionStyle(true);
}
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
* 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:
* Rational Software - Initial API and implementation
* Rational Software - Initial API and implementation
*******************************************************************************/
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 {
private boolean fFunctionStyle = false;
public void setFunctionStyle(boolean isFunctionStyle) {
this.fFunctionStyle = isFunctionStyle;
}
public Macro(ICElement parent, String name) {
super(parent, name, ICElement.C_MACRO);
}
@ -32,4 +38,8 @@ public class Macro extends SourceManipulation implements IMacro {
protected CElementInfo createElementInfo () {
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
* are made available under the terms of the Eclipse Public License v1.0
* 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 {
private final boolean fFunctionStyle;
public MacroHandle(ITranslationUnit tu, IIndexMacro macro) {
super(tu, ICElement.C_MACRO, new String(macro.getName()));
fFunctionStyle= macro.isFunctionStyle();
}
public String getIdentifierList() {
@ -28,4 +31,8 @@ public class MacroHandle extends CElementHandle implements IMacro {
public String getTokenSequence() {
return ""; //$NON-NLS-1$
}
public boolean isFunctionStyle() {
return fFunctionStyle;
}
}

View file

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

View file

@ -296,6 +296,12 @@ public class CElementLabelComposer {
*/
public void appendMacroLabel(IMacro macro, long flags) {
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)) {
IPath path= macro.getPath();
if (path != null) {