1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Merge remote branch 'cdt/master' into sd90

This commit is contained in:
Andrew Gvozdev 2011-09-15 17:25:39 -04:00
commit 8ba7dba9e9
36 changed files with 819 additions and 246 deletions

View file

@ -15,6 +15,14 @@
<artifactId>org.eclipse.cdt.managedbuilder.core.tests</artifactId> <artifactId>org.eclipse.cdt.managedbuilder.core.tests</artifactId>
<packaging>eclipse-test-plugin</packaging> <packaging>eclipse-test-plugin</packaging>
<repositories>
<repository>
<id>cdt.repo</id>
<url>file:/${basedir}/../../releng/org.eclipse.cdt.repo/target/repository</url>
<layout>p2</layout>
</repository>
</repositories>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -29,6 +37,18 @@
<include>**/AllManagedBuildTests.*</include> <include>**/AllManagedBuildTests.*</include>
</includes> </includes>
<testFailureIgnore>true</testFailureIgnore> <testFailureIgnore>true</testFailureIgnore>
<dependencies>
<dependency>
<artifactId>org.eclipse.platform.feature.group</artifactId>
<version>3.7.0</version>
<type>p2-installable-unit</type>
</dependency>
<dependency>
<artifactId>org.eclipse.cdt.feature.group</artifactId>
<version>8.0.0.${buildQualifier}</version>
<type>p2-installable-unit</type>
</dependency>
</dependencies>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View file

@ -9513,4 +9513,13 @@ public class AST2CPPTests extends AST2BaseTest {
assertNotSame(g1, g2); assertNotSame(g1, g2);
assertSame(g2, g3); assertSame(g2, g3);
} }
// class A : A {
// };
public void testRecursiveClassInheritance_Bug357256() throws Exception {
BindingAssertionHelper bh= getAssertionHelper();
ICPPClassType c= bh.assertNonProblem("A", 1);
assertEquals(0, ClassTypeHelper.getPureVirtualMethods(c).length);
}
} }

View file

@ -5481,4 +5481,36 @@ public class AST2TemplateTests extends AST2BaseTest {
public void testExplicitSpecializationOfForbiddenAsImplicit_356818() throws Exception { public void testExplicitSpecializationOfForbiddenAsImplicit_356818() throws Exception {
parseAndCheckBindings(); parseAndCheckBindings();
} }
// struct A {
// void f() { }
// };
// template <typename T> struct B : A {
// using A::f;
// void f(int) { }
// };
// template <typename T> struct C : B<T> {
// using B<T>::f;
// void f(int, int);
// };
//
// void test() {
// B<float> b;
// C<float> c;
// b.f();
// b.f(1);
// c.f();
// c.f(1);
// c.f(1,1);
// }
public void testSpecializationOfUsingDeclaration_357293() throws Exception {
parseAndCheckBindings();
}
// template<typename T> struct SS {};
// template<template<typename T, typename S = SS<T> > class Cont>
// Cont<int> f() {}
public void testReferenceToParameterOfTemplateTemplateParameter_357308() throws Exception {
parseAndCheckBindings();
}
} }

View file

@ -1866,4 +1866,35 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
IBinding[] friends = ct.getFriends(); IBinding[] friends = ct.getFriends();
assertEquals(0, friends.length); // not yet supported assertEquals(0, friends.length); // not yet supported
} }
// struct A {
// void f() { }
// };
// template <typename T> struct B : A {
// using A::f;
// void f(int) { }
// };
// template <typename T> struct C : B<T> {
// using B<T>::f;
// void f(int, int);
// };
// B<float> b;
// C<float> c;
// #include "header.h"
// void test() {
// b.f();
// b.f(1);
// c.f( );
// c.f(2);
// c.f(2,1);
// }
public void testSpecializationOfUsingDeclaration_357293() throws Exception {
getBindingFromASTName("f()", 1, ICPPMethod.class);
getBindingFromASTName("f(1)", 1, ICPPMethod.class);
getBindingFromASTName("f( )", 1, ICPPMethod.class);
getBindingFromASTName("f(2)", 1, ICPPMethod.class);
getBindingFromASTName("f(2,1)", 1, ICPPMethod.class);
}
} }

View file

@ -37,6 +37,11 @@
</includes> </includes>
<testFailureIgnore>true</testFailureIgnore> <testFailureIgnore>true</testFailureIgnore>
<dependencies> <dependencies>
<dependency>
<artifactId>org.eclipse.platform.feature.group</artifactId>
<version>3.7.0</version>
<type>p2-installable-unit</type>
</dependency>
<dependency> <dependency>
<artifactId>org.eclipse.cdt.feature.group</artifactId> <artifactId>org.eclipse.cdt.feature.group</artifactId>
<version>8.0.0.${buildQualifier}</version> <version>8.0.0.${buildQualifier}</version>

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2010 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2011 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
@ -159,7 +159,7 @@ public class BaseTestCase extends TestCase {
if (statusLog.size() != fExpectedLoggedNonOK) { if (statusLog.size() != fExpectedLoggedNonOK) {
StringBuffer msg= new StringBuffer("Expected number (" + fExpectedLoggedNonOK + ") of "); StringBuffer msg= new StringBuffer("Expected number (" + fExpectedLoggedNonOK + ") of ");
msg.append("non-OK status objects differs from actual (" + statusLog.size() + ").\n"); msg.append("non-OK status objects in log differs from actual (" + statusLog.size() + ").\n");
Throwable cause= null; Throwable cause= null;
if (!statusLog.isEmpty()) { if (!statusLog.isEmpty()) {
for (IStatus status : statusLog) { for (IStatus status : statusLog) {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Symbian Software Limited and others. * Copyright (c) 2007, 2011 Symbian Software Limited 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
@ -12,7 +12,6 @@ package org.eclipse.cdt.core.tests.templateengine;
import org.eclipse.cdt.core.templateengine.TemplateEngine; import org.eclipse.cdt.core.templateengine.TemplateEngine;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.ui.PlatformUI;
/** /**
* Test the functionality of TemplateEngine. * Test the functionality of TemplateEngine.
@ -50,20 +49,15 @@ public class TestTemplateEngine extends BaseTestCase {
* check for non null SharedDefaults * check for non null SharedDefaults
* *
*/ */
public void testSharedDefaults(){ public void testSharedDefaults() {
// when running the testcase in head-less mode, the TestExtraPagesProvider class cannot be loaded, assertNotNull(TemplateEngine.getSharedDefaults());
// which is logged.
if (!PlatformUI.isWorkbenchRunning()) {
setExpectedNumberOfLoggedNonOKStatusObjects(1);
}
assertNotNull(TemplateEngine.getSharedDefaults());
} }
/** /**
* check that the instace is created once(Singleton). * check that the instance is created once(Singleton).
*/ */
public void testSingleton(){ public void testSingleton() {
assertSame(templateEngine, TemplateEngine.getDefault()); assertSame(templateEngine, TemplateEngine.getDefault());
} }
} }

View file

@ -6,18 +6,17 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Doug Schaefer (IBM) - Initial API and implementation * Doug Schaefer (IBM) - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
/** /**
* The if statement including the optional else clause. * The 'if' statement including the optional else clause.
* *
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTIfStatement extends IASTStatement { public interface IASTIfStatement extends IASTStatement {
/** /**
* <code>CONDITION</code> represents the relationship between an * <code>CONDITION</code> represents the relationship between an
* <code>IASTIfStatement</code> and its nested <code>IASTExpression</code>. * <code>IASTIfStatement</code> and its nested <code>IASTExpression</code>.
@ -40,14 +39,16 @@ public interface IASTIfStatement extends IASTStatement {
public static final ASTNodeProperty ELSE = new ASTNodeProperty("IASTIfStatement.ELSE - IASTStatement (else) for IASTIfStatement"); //$NON-NLS-1$ public static final ASTNodeProperty ELSE = new ASTNodeProperty("IASTIfStatement.ELSE - IASTStatement (else) for IASTIfStatement"); //$NON-NLS-1$
/** /**
* Get the condition in the if statement. * Returns the condition in the if statement.
* *
* @return the condition <code>IASTExpression</code> * @return the condition <code>IASTExpression</code>. May return <code>null</code> if the 'if'
* statement has condition declaration instead of condition expression
* (see {@link org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement}).
*/ */
public IASTExpression getConditionExpression(); public IASTExpression getConditionExpression();
/** /**
* Set the condition in the if statement. * Sets the condition in the if statement.
* *
* @param condition * @param condition
* <code>IASTExpression</code> * <code>IASTExpression</code>
@ -55,14 +56,14 @@ public interface IASTIfStatement extends IASTStatement {
public void setConditionExpression(IASTExpression condition); public void setConditionExpression(IASTExpression condition);
/** /**
* Get the statement that is executed if the condition is true. * Returns the statement that is executed if the condition is true.
* *
* @return the then clause <code>IASTStatement</code> * @return the then clause <code>IASTStatement</code>
*/ */
public IASTStatement getThenClause(); public IASTStatement getThenClause();
/** /**
* Set the statement that is executed if the condition is true. * Sets the statement that is executed if the condition is true.
* *
* @param thenClause * @param thenClause
* <code>IASTStatement</code> * <code>IASTStatement</code>
@ -70,7 +71,7 @@ public interface IASTIfStatement extends IASTStatement {
public void setThenClause(IASTStatement thenClause); public void setThenClause(IASTStatement thenClause);
/** /**
* Get the statement that is executed if the condition is false. This clause * Returns the statement that is executed if the condition is false. This clause
* is optional and returns null if there is none. * is optional and returns null if there is none.
* *
* @return the else clause or null <code>IASTStatement</code> * @return the else clause or null <code>IASTStatement</code>
@ -78,7 +79,7 @@ public interface IASTIfStatement extends IASTStatement {
public IASTStatement getElseClause(); public IASTStatement getElseClause();
/** /**
* Set the else clause. * Sets the else clause.
* *
* @param elseClause * @param elseClause
* <code>IASTStatement</code> * <code>IASTStatement</code>

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
@ -15,17 +15,28 @@ import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
/** /**
* The 'if' statement including the optional else clause.
* *
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface ICPPASTIfStatement extends IASTIfStatement { public interface ICPPASTIfStatement extends IASTIfStatement {
/**
* Returns the condition declaration. The condition declaration and the condition expression are
* mutually exclusive.
*
* @return the condition declaration, or <code>null</code> if the 'if' statement doesn't
* have a condition declaration.
*/
public IASTDeclaration getConditionDeclaration(); public IASTDeclaration getConditionDeclaration();
public void setConditionDeclaration( IASTDeclaration d );
/**
* Sets the condition declaration.
*/
public void setConditionDeclaration(IASTDeclaration d);
/** /**
* Get the implicit <code>IScope</code> represented by this if statement * Returns the implicit <code>IScope</code> represented by this if statement
* *
* @return <code>IScope</code> * @return <code>IScope</code>
*/ */

View file

@ -92,6 +92,12 @@ public interface ICPPASTTemplatedTypeTemplateParameter extends ICPPASTTemplatePa
*/ */
public void setDefaultValue(IASTExpression expression); public void setDefaultValue(IASTExpression expression);
/**
* Returns the scope that contains the template parameters of this template-template parameter.
* @since 5.4
*/
public ICPPScope asScope();
/** /**
* @deprecated Use {@link #addTemplateParameter(ICPPASTTemplateParameter)}; * @deprecated Use {@link #addTemplateParameter(ICPPASTTemplateParameter)};
*/ */

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
@ -31,6 +32,7 @@ public class CPPASTTemplatedTypeTemplateParameter extends ASTNode implements
private boolean fIsParameterPack; private boolean fIsParameterPack;
private IASTName fName; private IASTName fName;
private IASTExpression fDefaultValue; private IASTExpression fDefaultValue;
private CPPTemplateTemplateParameterScope fScope;
public CPPASTTemplatedTypeTemplateParameter() { public CPPASTTemplatedTypeTemplateParameter() {
} }
@ -156,4 +158,11 @@ public class CPPASTTemplatedTypeTemplateParameter extends ASTNode implements
fDefaultValue = (IASTExpression) other; fDefaultValue = (IASTExpression) other;
} }
} }
public ICPPScope asScope() {
if (fScope == null) {
fScope= new CPPTemplateTemplateParameterScope(this);
}
return fScope;
}
} }

View file

@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2011 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.IName;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
/**
* Represents the scope of a template-template parameter.
*/
public class CPPTemplateTemplateParameterScope extends CPPScope {
public CPPTemplateTemplateParameterScope(ICPPASTTemplatedTypeTemplateParameter parameter) {
super(parameter);
}
public EScopeKind getKind() {
return EScopeKind.eLocal;
}
@Override
public IName getScopeName() {
return ((ICPPASTTemplatedTypeTemplateParameter) getPhysicalNode()).getName();
}
}

View file

@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2011 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 (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPFunctionSet;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
/**
* Specialization of a typedef in the context of a class-specialization.
*/
public class CPPUsingDeclarationSpecialization extends CPPSpecialization implements ICPPUsingDeclaration {
private IBinding[] fDelegates;
public CPPUsingDeclarationSpecialization(ICPPUsingDeclaration specialized, ICPPClassSpecialization owner,
ICPPTemplateParameterMap tpmap) {
super(specialized, owner, tpmap);
}
public IBinding[] getDelegates() {
if (fDelegates == null) {
fDelegates= specializeDelegates();
}
return fDelegates;
}
private IBinding[] specializeDelegates() {
IBinding[] origDelegates= ((ICPPUsingDeclaration) getSpecializedBinding()).getDelegates();
List<IBinding> result= new ArrayList<IBinding>();
ICPPClassSpecialization owner= (ICPPClassSpecialization) getOwner();
for (IBinding delegate : origDelegates) {
if (delegate instanceof ICPPUnknownBinding) {
try {
delegate= CPPTemplates.resolveUnknown((ICPPUnknownBinding) delegate,
owner.getTemplateParameterMap(), -1, null);
if (delegate instanceof CPPFunctionSet) {
for (IBinding b : ((CPPFunctionSet) delegate).getBindings()) {
result.add(b);
}
} else if (delegate != null) {
result.add(delegate);
}
} catch (DOMException e) {
}
} else {
result.add(delegate);
}
}
return result.toArray(new IBinding[result.size()]);
}
}

View file

@ -16,7 +16,6 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -819,22 +818,78 @@ public class ClassTypeHelper {
* template parameters. * template parameters.
*/ */
public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType) { public static ICPPMethod[] getPureVirtualMethods(ICPPClassType classType) {
Collection<Set<ICPPMethod>> result = collectPureVirtualMethods(classType).values(); Map<String, List<ICPPMethod>> result= collectPureVirtualMethods(classType,
new HashMap<ICPPClassType, Map<String, List<ICPPMethod>>>());
int resultArraySize = 0; int resultArraySize = 0;
for (Set<ICPPMethod> set : result) { for (List<ICPPMethod> methods : result.values()) {
resultArraySize += set.size(); resultArraySize += methods.size();
} }
ICPPMethod[] resultArray = new ICPPMethod[resultArraySize]; ICPPMethod[] resultArray = new ICPPMethod[resultArraySize];
int resultArrayIdx = 0; int resultArrayIdx = 0;
for (Set<ICPPMethod> methodsSet : result) { for (List<ICPPMethod> methods : result.values()) {
for (ICPPMethod method : methodsSet) { for (ICPPMethod method : methods) {
resultArray[resultArrayIdx] = method; resultArray[resultArrayIdx++] = method;
++resultArrayIdx;
} }
} }
return resultArray; return resultArray;
} }
private static Map<String, List<ICPPMethod>> collectPureVirtualMethods(ICPPClassType classType,
Map<ICPPClassType, Map<String, List<ICPPMethod>>> cache) {
Map<String, List<ICPPMethod>> result = cache.get(classType);
if (result != null)
return result;
result= new HashMap<String, List<ICPPMethod>>();
cache.put(classType, result);
// Look at the pure virtual methods of the base classes
Set<IBinding> handledBaseClasses= new HashSet<IBinding>();
for (ICPPBase base : classType.getBases()) {
final IBinding baseClass = base.getBaseClass();
if (baseClass instanceof ICPPClassType && handledBaseClasses.add(baseClass)) {
Map<String, List<ICPPMethod>> pureVirtuals = collectPureVirtualMethods((ICPPClassType) baseClass, cache);
// Merge derived pure virtual methods
for (String key : pureVirtuals.keySet()) {
List<ICPPMethod> list = result.get(key);
if (list == null) {
list= new ArrayList<ICPPMethod>();
result.put(key, list);
}
list.addAll(pureVirtuals.get(key));
}
}
}
// Remove overridden pure-virtual methods and add in new pure virutals.
final ObjectSet<ICPPMethod> methods = getOwnMethods(classType);
for (ICPPMethod method : methods) {
String key= getMethodNameForOverrideKey(method);
List<ICPPMethod> list = result.get(key);
if (list != null) {
final ICPPFunctionType methodType = method.getType();
for (Iterator<ICPPMethod> it= list.iterator(); it.hasNext(); ) {
ICPPMethod pureVirtual = it.next();
if (functionTypesAllowOverride(methodType, pureVirtual.getType())) {
it.remove();
}
}
}
if (method.isPureVirtual()) {
if (list == null) {
list= new ArrayList<ICPPMethod>();
result.put(key, list);
}
list.add(method);
} else if (list != null && list.isEmpty()) {
result.remove(key);
}
}
return result;
}
private static String getMethodNameForOverrideKey(ICPPMethod method) { private static String getMethodNameForOverrideKey(ICPPMethod method) {
if (method.isDestructor()) { if (method.isDestructor()) {
// Destructor's names may differ but they will override each other. // Destructor's names may differ but they will override each other.
@ -843,59 +898,4 @@ public class ClassTypeHelper {
return method.getName(); return method.getName();
} }
} }
/**
* Returns pure virtual methods of the given class grouped by their names.
*
* @param classType The class to obtain the pure virtual method for.
* @return pure virtual methods grouped by their names.
*/
private static Map<String, Set<ICPPMethod> > collectPureVirtualMethods(ICPPClassType classType) {
// Collect pure virtual functions from base classes
Map<String, Set<ICPPMethod>> pureVirtualMethods = new HashMap<String, Set<ICPPMethod>>();
for (ICPPBase base : classType.getBases()) {
if (base.getBaseClass() instanceof ICPPClassType) {
ICPPClassType baseClass = (ICPPClassType) base.getBaseClass();
Map<String, Set<ICPPMethod> > derivedPureVirtualMethods = collectPureVirtualMethods(baseClass);
// Merge derived pure virtual methods
for (Map.Entry<String, Set<ICPPMethod> > currMethodEntry : derivedPureVirtualMethods.entrySet()) {
Set<ICPPMethod> methodsSet = pureVirtualMethods.get(currMethodEntry.getKey());
if (methodsSet == null) {
pureVirtualMethods.put(currMethodEntry.getKey(), currMethodEntry.getValue());
} else {
methodsSet.addAll(currMethodEntry.getValue());
}
}
}
}
// Remove overridden methods (even if they are pure virtual)
for (ICPPMethod declaredMethod : getOwnMethods(classType)) {
Set<ICPPMethod> methodsSet = pureVirtualMethods.get(getMethodNameForOverrideKey(declaredMethod));
if (methodsSet != null) {
for (Iterator<ICPPMethod> methodIt = methodsSet.iterator(); methodIt.hasNext();) {
ICPPMethod method = methodIt.next();
if (functionTypesAllowOverride(declaredMethod.getType(), method.getType())) {
methodIt.remove();
}
}
if (methodsSet.isEmpty()) {
pureVirtualMethods.remove(getMethodNameForOverrideKey(declaredMethod));
}
}
}
// Add pure virtual methods of current class
for (ICPPMethod method : classType.getDeclaredMethods()) {
if (method.isPureVirtual()) {
Set<ICPPMethod> methodsSet = pureVirtualMethods.get(getMethodNameForOverrideKey(method));
if (methodsSet == null) {
methodsSet = new HashSet<ICPPMethod>();
pureVirtualMethods.put(getMethodNameForOverrideKey(method), methodsSet);
}
methodsSet.add(method);
}
}
return pureVirtualMethods;
}
} }

View file

@ -1426,6 +1426,15 @@ public class CPPSemantics {
ASTInternal.addName(scope, enumerator.getName()); ASTInternal.addName(scope, enumerator.getName());
} }
return; return;
} else if (parent instanceof ICPPASTTemplatedTypeTemplateParameter) {
// The template-template parameter scope contains the parameters
for (ICPPASTTemplateParameter par : ((ICPPASTTemplatedTypeTemplateParameter) parent).getTemplateParameters()) {
IASTName name= CPPTemplates.getTemplateParameterName(par);
if (name != null) {
ASTInternal.addName(scope, name);
}
}
return;
} }
int idx = -1; int idx = -1;
@ -2465,7 +2474,7 @@ public class CPPSemantics {
boolean haveASTResult= false; boolean haveASTResult= false;
for (ICPPFunction f : fns) { for (ICPPFunction f : fns) {
// Use the ast binding // Use the ast binding
final boolean fromIndex = f instanceof IIndexBinding; final boolean fromIndex = isFromIndex(f);
if (haveASTResult && fromIndex) if (haveASTResult && fromIndex)
break; break;

View file

@ -79,7 +79,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
@ -89,6 +88,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArraySet; import org.eclipse.cdt.core.parser.util.CharArraySet;
@ -134,6 +134,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClass; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClass;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclarationSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalTemplateDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalTemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
@ -597,20 +598,6 @@ public class CPPTemplates {
return new CPPTemplateNonTypeParameter(ASTQueries.findInnermostDeclarator(dtor).getName()); return new CPPTemplateNonTypeParameter(ASTQueries.findInnermostDeclarator(dtor).getName());
} }
static public ICPPScope getContainingScope(IASTNode node) {
while (node != null) {
if (node instanceof ICPPASTTemplateParameter) {
IASTNode parent = node.getParent();
if (parent instanceof ICPPASTTemplateDeclaration) {
return ((ICPPASTTemplateDeclaration) parent).getScope();
}
}
node = node.getParent();
}
return null;
}
public static IBinding createBinding(ICPPASTTemplateId id) { public static IBinding createBinding(ICPPASTTemplateId id) {
if (!isClassTemplate(id)) { if (!isClassTemplate(id)) {
//functions are instantiated as part of the resolution process //functions are instantiated as part of the resolution process
@ -794,6 +781,8 @@ public class CPPTemplates {
} else if (decl instanceof IEnumeration || decl instanceof IEnumerator) { } else if (decl instanceof IEnumeration || decl instanceof IEnumerator) {
// TODO(sprigogin): Deal with a case when an enumerator value depends on a template parameter. // TODO(sprigogin): Deal with a case when an enumerator value depends on a template parameter.
spec = decl; spec = decl;
} else if (decl instanceof ICPPUsingDeclaration) {
spec= new CPPUsingDeclarationSpecialization((ICPPUsingDeclaration) decl, owner, tpMap);
} }
return spec; return spec;
} }
@ -2294,7 +2283,7 @@ public class CPPTemplates {
/** /**
* Attempts to (partially) resolve an unknown binding with the given arguments. * Attempts to (partially) resolve an unknown binding with the given arguments.
*/ */
private static IBinding resolveUnknown(ICPPUnknownBinding unknown, ICPPTemplateParameterMap tpMap, public static IBinding resolveUnknown(ICPPUnknownBinding unknown, ICPPTemplateParameterMap tpMap,
int packOffset, ICPPClassSpecialization within) throws DOMException { int packOffset, ICPPClassSpecialization within) throws DOMException {
if (unknown instanceof ICPPDeferredClassInstance) { if (unknown instanceof ICPPDeferredClassInstance) {
return resolveDeferredClassInstance((ICPPDeferredClassInstance) unknown, tpMap, packOffset, within); return resolveDeferredClassInstance((ICPPDeferredClassInstance) unknown, tpMap, packOffset, within);

View file

@ -908,7 +908,7 @@ public class CPPVisitor extends ASTQueries {
if (result != null) if (result != null)
return result; return result;
} else if (parent instanceof ICPPASTTemplateDeclaration) { } else if (parent instanceof ICPPASTTemplateDeclaration) {
return CPPTemplates.getContainingScope(node); return ((ICPPASTTemplateDeclaration) parent).getScope();
} }
} else if (node instanceof IASTInitializer) { } else if (node instanceof IASTInitializer) {
if (node instanceof ICPPASTConstructorChainInitializer) { if (node instanceof ICPPASTConstructorChainInitializer) {
@ -979,7 +979,13 @@ public class CPPVisitor extends ASTQueries {
continue; continue;
} }
} else if (node instanceof ICPPASTTemplateParameter) { } else if (node instanceof ICPPASTTemplateParameter) {
return CPPTemplates.getContainingScope(node); if (node instanceof ICPPASTTemplatedTypeTemplateParameter && node != inputNode) {
return ((ICPPASTTemplatedTypeTemplateParameter) node).asScope();
}
IASTNode parent = node.getParent();
if (parent instanceof ICPPASTTemplateDeclaration) {
return ((ICPPASTTemplateDeclaration) parent).getScope();
}
} else if (node instanceof ICPPASTBaseSpecifier) { } else if (node instanceof ICPPASTBaseSpecifier) {
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) node.getParent(); ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) node.getParent();
IASTName n = compSpec.getName(); IASTName n = compSpec.getName();

View file

@ -58,4 +58,5 @@ public interface IIndexCPPBindingConstants {
int CPP_TEMPLATE_TEMPLATE_PARAMETER= IIndexBindingConstants.LAST_CONSTANT + 46; int CPP_TEMPLATE_TEMPLATE_PARAMETER= IIndexBindingConstants.LAST_CONSTANT + 46;
int CPP_CLASS_TEMPLATE_PARTIAL_SPEC_SPEC = IIndexBindingConstants.LAST_CONSTANT + 47; int CPP_CLASS_TEMPLATE_PARTIAL_SPEC_SPEC = IIndexBindingConstants.LAST_CONSTANT + 47;
int CPP_UNKNOWN_BINDING = IIndexBindingConstants.LAST_CONSTANT + 48; int CPP_UNKNOWN_BINDING = IIndexBindingConstants.LAST_CONSTANT + 48;
int CPP_USING_DECLARATION_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 49;
} }

View file

@ -293,6 +293,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
return new CompositeCPPParameterSpecialization(this, (ICPPParameter) binding); return new CompositeCPPParameterSpecialization(this, (ICPPParameter) binding);
} else if (binding instanceof ITypedef) { } else if (binding instanceof ITypedef) {
return new CompositeCPPTypedefSpecialization(this, (ICPPBinding) binding); return new CompositeCPPTypedefSpecialization(this, (ICPPBinding) binding);
} else if (binding instanceof ICPPUsingDeclaration) {
return new CompositeCPPUsingDeclarationSpecialization(this, (ICPPUsingDeclaration) binding);
} else { } else {
throw new CompositingNotImplementedError("composite binding unavailable for " + binding + " " + binding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$ throw new CompositingNotImplementedError("composite binding unavailable for " + binding + " " + binding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
} }

View file

@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2011 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 (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPUsingDeclarationSpecialization extends CompositeCPPUsingDeclaration implements ICPPSpecialization {
public CompositeCPPUsingDeclarationSpecialization(ICompositesFactory cf, ICPPUsingDeclaration delegate) {
super(cf, delegate);
}
public IBinding getSpecializedBinding() {
return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding);
}
public ICPPTemplateParameterMap getTemplateParameterMap() {
IBinding owner= getOwner();
if (owner instanceof ICPPSpecialization) {
return ((ICPPSpecialization) owner).getTemplateParameterMap();
}
return CPPTemplateParameterMap.EMPTY;
}
@Deprecated
public ObjectMap getArgumentMap() {
return TemplateInstanceUtil.getArgumentMap(cf, rbinding);
}
}

View file

@ -209,10 +209,11 @@ public class PDOM extends PlatformObject implements IPDOM {
* *
* CDT 8.1 development (versions not supported on teh 8.0.x branch) * CDT 8.1 development (versions not supported on teh 8.0.x branch)
* 120.0 - Enumerators in global index, bug 356235 * 120.0 - Enumerators in global index, bug 356235
* 120.1 - Specializations of using declarations, bug 357293.
*/ */
private static final int MIN_SUPPORTED_VERSION= version(120, 0); private static final int MIN_SUPPORTED_VERSION= version(120, 0);
private static final int MAX_SUPPORTED_VERSION= version(120, Short.MAX_VALUE); private static final int MAX_SUPPORTED_VERSION= version(120, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(120, 0); private static final int DEFAULT_VERSION = version(120, 1);
private static int version(int major, int minor) { private static int version(int major, int minor) {
return (major << 16) + minor; return (major << 16) + minor;

View file

@ -379,11 +379,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
} }
/** /**
* Usually bindings are added on behalf of a name, only. For unknown values we need to * Usually bindings are added on behalf of a name, only. For unknown values or using declarations
* add further bindings. * we need to add further bindings.
* @throws CoreException * @throws CoreException
*/ */
public PDOMBinding addUnknownValue(IBinding binding) throws CoreException { public PDOMBinding addPotentiallyUnknownBinding(IBinding binding) throws CoreException {
return null; return null;
} }

View file

@ -239,7 +239,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
} }
@Override @Override
public PDOMBinding addUnknownValue(IBinding binding) throws CoreException { public PDOMBinding addPotentiallyUnknownBinding(IBinding binding) throws CoreException {
return addBinding(binding, null); return addBinding(binding, null);
} }
@ -461,6 +461,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
result= new PDOMCPPClassSpecialization(this, parent, (ICPPClassType) special, orig); result= new PDOMCPPClassSpecialization(this, parent, (ICPPClassType) special, orig);
} else if (special instanceof ITypedef) { } else if (special instanceof ITypedef) {
result= new PDOMCPPTypedefSpecialization(this, parent, (ITypedef) special, orig); result= new PDOMCPPTypedefSpecialization(this, parent, (ITypedef) special, orig);
} else if (special instanceof ICPPUsingDeclaration) {
result= new PDOMCPPUsingDeclarationSpecialization(this, parent, (ICPPUsingDeclaration) special, orig);
} }
return result; return result;
@ -805,6 +807,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return new PDOMCPPClassTemplateSpecialization(this, record); return new PDOMCPPClassTemplateSpecialization(this, record);
case CPP_TYPEDEF_SPECIALIZATION: case CPP_TYPEDEF_SPECIALIZATION:
return new PDOMCPPTypedefSpecialization(this, record); return new PDOMCPPTypedefSpecialization(this, record);
case CPP_USING_DECLARATION_SPECIALIZATION:
return new PDOMCPPUsingDeclarationSpecialization(this, record);
} }
assert false : "nodeid= " + nodeType; //$NON-NLS-1$ assert false : "nodeid= " + nodeType; //$NON-NLS-1$
return null; return null;

View file

@ -54,7 +54,7 @@ class PDOMCPPUsingDeclaration extends PDOMCPPBinding implements ICPPUsingDeclara
Set<PDOMBinding> targets= new LinkedHashSet<PDOMBinding>(); Set<PDOMBinding> targets= new LinkedHashSet<PDOMBinding>();
PDOMCPPUsingDeclaration last= null; PDOMCPPUsingDeclaration last= null;
for (IBinding delegate : using.getDelegates()) { for (IBinding delegate : using.getDelegates()) {
PDOMBinding target = getLinkage().adaptBinding(delegate); PDOMBinding target = getLinkage().addPotentiallyUnknownBinding(delegate);
if (target != null && targets.add(target)) { if (target != null && targets.add(target)) {
if (last == null) { if (last == null) {
setTargetBinding(linkage, target); setTargetBinding(linkage, target);

View file

@ -0,0 +1,88 @@
/*******************************************************************************
* Copyright (c) 2011 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 (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
class PDOMCPPUsingDeclarationSpecialization extends PDOMCPPSpecialization implements ICPPUsingDeclaration {
private static final int TARGET_BINDINGS = PDOMCPPSpecialization.RECORD_SIZE;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = TARGET_BINDINGS + Database.PTR_SIZE;
private volatile IBinding[] delegates;
public PDOMCPPUsingDeclarationSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPUsingDeclaration using, PDOMBinding specialized)
throws CoreException {
super(linkage, parent, (ICPPSpecialization) using, specialized);
Set<PDOMBinding> targets= new LinkedHashSet<PDOMBinding>();
PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + TARGET_BINDINGS);
for (IBinding delegate : using.getDelegates()) {
PDOMBinding target = getLinkage().adaptBinding(delegate);
if (target != null && targets.add(target)) {
list.addMember(target);
}
}
}
public PDOMCPPUsingDeclarationSpecialization(PDOMLinkage linkage, long record) {
super(linkage, record);
}
@Override
protected int getRecordSize() {
return RECORD_SIZE;
}
@Override
public int getNodeType() {
return IIndexCPPBindingConstants.CPP_USING_DECLARATION;
}
public IBinding[] getDelegates() {
if (delegates == null) {
PDOMNodeLinkedList list= new PDOMNodeLinkedList(getLinkage(), record+TARGET_BINDINGS);
final List<IBinding> result= new ArrayList<IBinding>();
try {
list.accept(new IPDOMVisitor() {
public boolean visit(IPDOMNode node) {
if (node instanceof IBinding) {
result.add((IBinding) node);
}
return true;
}
public void leave(IPDOMNode node) {
}
});
} catch (CoreException e) {
}
delegates = result.toArray(new IBinding[result.size()]);
}
return delegates;
}
}

View file

@ -114,6 +114,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
@ -157,7 +158,7 @@ import org.eclipse.text.edits.TextEdit;
* Some heuristic is applied in case of syntax errors or other problems * Some heuristic is applied in case of syntax errors or other problems
* to skip those areas, but because of incomplete location information * to skip those areas, but because of incomplete location information
* the formatting may fail. The reason of the failure is logged. * the formatting may fail. The reason of the failure is logged.
* *
* @since 4.0 * @since 4.0
*/ */
public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, ICASTVisitor { public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, ICASTVisitor {
@ -827,7 +828,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
/** /**
* Determine whether the given declarator is the first in a list of declarators (if any). * Determine whether the given declarator is the first in a list of declarators (if any).
* *
* @param node the declarator node * @param node the declarator node
* @return <code>true</code> if this node is the first in a list * @return <code>true</code> if this node is the first in a list
*/ */
@ -1527,7 +1528,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
/** /**
* Returns the position of the last character of a node, or -1 if that character is part of * Returns the position of the last character of a node, or -1 if that character is part of
* a macro expansion. * a macro expansion.
* *
* @param node an AST node * @param node an AST node
* @return the position of the last character of a node, or -1 if that character is part of * @return the position of the last character of a node, or -1 if that character is part of
* a macro expansion. * a macro expansion.
@ -1658,12 +1659,16 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
Runnable tailFormatter = fExpectSemicolonAfterDeclaration ? Runnable tailFormatter = fExpectSemicolonAfterDeclaration ?
new TrailingSemicolonFormatter(node) : null; new TrailingSemicolonFormatter(node) : null;
if (declarators.size() == 1) { if (declarators.size() == 1) {
scribe.setTailFormatter(tailFormatter); if (tailFormatter != null) {
try { scribe.setTailFormatter(tailFormatter);
try {
visit(declarators.get(0));
scribe.runTailFormatter();
} finally {
scribe.setTailFormatter(null);
}
} else {
visit(declarators.get(0)); visit(declarators.get(0));
scribe.runTailFormatter();
} finally {
scribe.setTailFormatter(null);
} }
} else { } else {
final ListOptions options= new ListOptions(preferences.alignment_for_declarator_list); final ListOptions options= new ListOptions(preferences.alignment_for_declarator_list);
@ -2047,7 +2052,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
* @param encloseInParen indicates whether the list should be enclosed in parentheses * @param encloseInParen indicates whether the list should be enclosed in parentheses
* @param addEllipsis indicates whether ellipsis should be added after the last element * @param addEllipsis indicates whether ellipsis should be added after the last element
* @param tailFormatter formatter for the trailing text that should be kept together with * @param tailFormatter formatter for the trailing text that should be kept together with
* the last element of the list. * the last element of the list.
*/ */
private void formatList(List<? extends IASTNode> elements, ListOptions options, private void formatList(List<? extends IASTNode> elements, ListOptions options,
boolean encloseInParen, boolean addEllipsis, Runnable tailFormatter) { boolean encloseInParen, boolean addEllipsis, Runnable tailFormatter) {
@ -2153,12 +2158,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
final IASTDeclaration decl= node.getDeclaration(); final IASTDeclaration decl= node.getDeclaration();
if (decl != null) { if (decl != null) {
fExpectSemicolonAfterDeclaration= false; formatInlineDeclaration(decl);
try {
decl.accept(this);
} finally {
fExpectSemicolonAfterDeclaration= true;
}
} else if (node.isCatchAll()) { } else if (node.isCatchAll()) {
scribe.printNextToken(Token.tELIPSE, false /* preferences.insert_space_before_ellipsis */); scribe.printNextToken(Token.tELIPSE, false /* preferences.insert_space_before_ellipsis */);
// if (false /* preferences.insert_space_after_ellipsis */) { // if (false /* preferences.insert_space_after_ellipsis */) {
@ -2173,6 +2173,15 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private void formatInlineDeclaration(final IASTDeclaration decl) {
fExpectSemicolonAfterDeclaration= false;
try {
decl.accept(this);
} finally {
fExpectSemicolonAfterDeclaration= true;
}
}
private int visit(IASTCompoundStatement node) { private int visit(IASTCompoundStatement node) {
formatBlock(node, preferences.brace_position_for_block, preferences.insert_space_before_opening_brace_in_block, preferences.indent_statements_compare_to_block); formatBlock(node, preferences.brace_position_for_block, preferences.insert_space_before_opening_brace_in_block, preferences.indent_statements_compare_to_block);
return PROCESS_SKIP; return PROCESS_SKIP;
@ -2288,7 +2297,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
/** /**
* Formats given expressions as a function call, ie. enclosed in parenthesis. * Formats given expressions as a function call, ie. enclosed in parenthesis.
* *
* @param args the argument expressions, may be <code>null</code> * @param args the argument expressions, may be <code>null</code>
*/ */
private void formatFunctionCallArguments(IASTInitializerClause[] args) { private void formatFunctionCallArguments(IASTInitializerClause[] args) {
@ -2785,7 +2794,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
private boolean isOverloadedLeftShift(IASTBinaryExpression node) { private boolean isOverloadedLeftShift(IASTBinaryExpression node) {
return node.getOperator() == IASTBinaryExpression.op_shiftLeft && return node.getOperator() == IASTBinaryExpression.op_shiftLeft &&
node instanceof ICPPASTBinaryExpression && node instanceof ICPPASTBinaryExpression &&
((ICPPASTBinaryExpression) node).getOverload() != null; ((ICPPASTBinaryExpression) node).getOverload() != null;
} }
@ -3079,14 +3088,29 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
private int visit(IASTForStatement node) { private int visit(IASTForStatement node) {
scribe.printNextToken(Token.t_for); if (!startsWithMacroExpansion(node)) {
final int line = scribe.line; scribe.printNextToken(Token.t_for);
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_for);
fInsideFor= true;
if (preferences.insert_space_after_opening_paren_in_for) {
scribe.space();
} }
final int line = scribe.line;
IASTStatement initializerStmt= node.getInitializerStatement(); IASTStatement initializerStmt= node.getInitializerStatement();
IASTStatement body = node.getBody();
Runnable tailFormatter = null;
if (!doNodesHaveSameOffset(node, initializerStmt)) {
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_for);
fInsideFor= true;
if (preferences.insert_space_after_opening_paren_in_for) {
scribe.space();
}
if (DefaultCodeFormatterConstants.END_OF_LINE.equals(preferences.brace_position_for_block) &&
body instanceof IASTCompoundStatement && !startsWithMacroExpansion(body)) {
tailFormatter = new TrailingTokenFormatter(Token.tLBRACE,
body.getFileLocation().getNodeOffset(),
preferences.insert_space_before_opening_brace_in_block, false);
}
tailFormatter = new ClosingParensesisTailFormatter(
preferences.insert_space_before_closing_paren_in_for, tailFormatter);
}
initializerStmt.accept(this); initializerStmt.accept(this);
if (peekNextToken() == Token.tSEMI) { if (peekNextToken() == Token.tSEMI) {
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon_in_for); scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon_in_for);
@ -3124,6 +3148,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon_in_for); scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon_in_for);
} }
scribe.setTailFormatter(tailFormatter);
scribe.alignFragment(alignment, 1); scribe.alignFragment(alignment, 1);
IASTExpression iterationExpr= node.getIterationExpression(); IASTExpression iterationExpr= node.getIterationExpression();
if (iterationExpr != null) { if (iterationExpr != null) {
@ -3132,52 +3157,62 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
iterationExpr.accept(this); iterationExpr.accept(this);
} }
if (tailFormatter != null) {
scribe.runTailFormatter();
scribe.setTailFormatter(null);
}
} finally { } finally {
fInsideFor= false; fInsideFor= false;
} }
if (peekNextToken() == Token.tRPAREN) { ok = true;
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_for);
}
IASTStatement body = node.getBody();
if (body instanceof IASTCompoundStatement && !startsWithMacroExpansion(body)) {
formatLeftCurlyBrace(line, preferences.brace_position_for_block);
if (startNode(body)) {
try {
final boolean braceOnSameLine = DefaultCodeFormatterConstants.END_OF_LINE.equals(preferences.brace_position_for_block);
if (!braceOnSameLine) {
ok = true;
scribe.exitAlignment(alignment, true);
}
formatBlockOpening((IASTCompoundStatement) body,
preferences.brace_position_for_block,
preferences.insert_space_before_opening_brace_in_block);
if (braceOnSameLine) {
ok = true;
scribe.exitAlignment(alignment, true);
}
formatOpenedBlock((IASTCompoundStatement) body,
preferences.brace_position_for_block,
preferences.indent_statements_compare_to_block);
} finally {
endOfNode(body);
}
} else {
ok = true;
scribe.exitAlignment(alignment, true);
}
} else {
ok = true;
scribe.exitAlignment(alignment, true);
formatAction(line, body, preferences.brace_position_for_block);
}
} catch (AlignmentException e) { } catch (AlignmentException e) {
if (ok) {
throw e;
}
scribe.redoAlignment(e); scribe.redoAlignment(e);
} }
} while (!ok); } while (!ok);
scribe.exitAlignment(alignment, true);
if (body instanceof IASTCompoundStatement && !startsWithMacroExpansion(body)) {
// if (body instanceof IASTCompoundStatement && !startsWithMacroExpansion(body)) {
// formatLeftCurlyBrace(line, preferences.brace_position_for_block);
// if (startNode(body)) {
// try {
// final boolean braceOnSameLine = DefaultCodeFormatterConstants.END_OF_LINE.equals(preferences.brace_position_for_block);
// if (!braceOnSameLine) {
// ok = true;
// scribe.exitAlignment(alignment, true);
// }
// formatBlockOpening((IASTCompoundStatement) body,
// preferences.brace_position_for_block,
// preferences.insert_space_before_opening_brace_in_block);
// if (braceOnSameLine) {
// ok = true;
// scribe.exitAlignment(alignment, true);
// }
// formatOpenedBlock((IASTCompoundStatement) body,
// preferences.brace_position_for_block,
// preferences.indent_statements_compare_to_block);
// } finally {
// endOfNode(body);
// }
// }
// }
if (startNode(body)) {
try {
if (scribe.scanner.getCurrentPosition() <= body.getFileLocation().getNodeOffset()) {
formatLeftCurlyBrace(line, preferences.brace_position_for_block);
}
formatBlock((IASTCompoundStatement) body,
preferences.brace_position_for_block,
preferences.insert_space_before_opening_brace_in_block,
preferences.indent_statements_compare_to_block);
} finally {
endOfNode(body);
}
}
} else {
formatAction(line, body, preferences.brace_position_for_block);
}
scribe.printTrailingComment();
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -3210,36 +3245,53 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
private int visit(IASTIfStatement node) { private int visit(IASTIfStatement node) {
scribe.printNextToken(Token.t_if); if (!startsWithMacroExpansion(node)) {
final int line = scribe.line; scribe.printNextToken(Token.t_if);
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_if); }
if (preferences.insert_space_after_opening_paren_in_if) { final int line = scribe.line;
scribe.space(); IASTNode condition = node.getConditionExpression();
if (condition == null && node instanceof ICPPASTIfStatement) {
condition = ((ICPPASTIfStatement) node).getConditionDeclaration();
} }
IASTExpression condExpr= node.getConditionExpression();
final IASTStatement thenStatement = node.getThenClause(); final IASTStatement thenStatement = node.getThenClause();
final IASTStatement elseStatement = node.getElseClause(); final IASTStatement elseStatement = node.getElseClause();
Runnable tailFormatter = null;
if (DefaultCodeFormatterConstants.END_OF_LINE.equals(preferences.brace_position_for_block) && fExpectSemicolonAfterDeclaration= false;
thenStatement instanceof IASTCompoundStatement && !startsWithMacroExpansion(thenStatement)) { try {
tailFormatter = new TrailingTokenFormatter(Token.tLBRACE, if (condition == null || !doNodesHaveSameOffset(node, condition)) {
thenStatement.getFileLocation().getNodeOffset(), scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_if);
preferences.insert_space_before_opening_brace_in_block, false); if (preferences.insert_space_after_opening_paren_in_if) {
scribe.space();
}
Runnable tailFormatter = null;
if (DefaultCodeFormatterConstants.END_OF_LINE.equals(preferences.brace_position_for_block) &&
thenStatement instanceof IASTCompoundStatement && !startsWithMacroExpansion(thenStatement)) {
tailFormatter = new TrailingTokenFormatter(Token.tLBRACE,
thenStatement.getFileLocation().getNodeOffset(),
preferences.insert_space_before_opening_brace_in_block, false);
}
tailFormatter = new ClosingParensesisTailFormatter(
preferences.insert_space_before_closing_paren_in_if, tailFormatter);
scribe.setTailFormatter(tailFormatter);
if (condition == null || condition instanceof IASTProblemHolder) {
scribe.skipToToken(Token.tRPAREN);
} else {
condition.accept(this);
}
scribe.runTailFormatter();
scribe.setTailFormatter(null);
} else if (!(condition instanceof IASTProblemHolder)) {
condition.accept(this);
}
} finally {
fExpectSemicolonAfterDeclaration= true;
} }
tailFormatter = new ClosingParensesisTailFormatter(
preferences.insert_space_before_closing_paren_in_if, tailFormatter);
scribe.setTailFormatter(tailFormatter);
if (condExpr == null || condExpr instanceof IASTProblemExpression) {
scribe.skipToToken(Token.tRPAREN);
} else {
condExpr.accept(this);
}
scribe.runTailFormatter();
scribe.setTailFormatter(null);
boolean thenStatementIsBlock = false; boolean thenStatementIsBlock = false;
if (thenStatement != null) { if (thenStatement != null) {
if (thenStatement instanceof IASTCompoundStatement && !startsWithMacroExpansion(thenStatement)) { if (condition != null && doNodeLocationsOverlap(condition, thenStatement)) {
thenStatement.accept(this);
} else if (thenStatement instanceof IASTCompoundStatement && !startsWithMacroExpansion(thenStatement)) {
final IASTCompoundStatement block = (IASTCompoundStatement) thenStatement; final IASTCompoundStatement block = (IASTCompoundStatement) thenStatement;
thenStatementIsBlock = true; thenStatementIsBlock = true;
final List<IASTStatement> statements = Arrays.asList(block.getStatements()); final List<IASTStatement> statements = Arrays.asList(block.getStatements());
@ -3263,7 +3315,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
} }
} else { } else {
if (node.getFileLocation().getNodeOffset() == thenStatement.getFileLocation().getNodeOffset()) { if (doNodesHaveSameOffset(node, thenStatement)) {
startNode(thenStatement); startNode(thenStatement);
} }
if (elseStatement == null && preferences.keep_simple_if_on_one_line) { if (elseStatement == null && preferences.keep_simple_if_on_one_line) {
@ -3310,34 +3362,38 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
if (elseStatement != null) { if (elseStatement != null) {
if (peekNextToken() == Token.t_else) { if (condition != null && doNodeLocationsOverlap(condition, elseStatement)) {
if (thenStatementIsBlock) {
scribe.printNextToken(Token.t_else, preferences.insert_space_after_closing_brace_in_block);
} else {
scribe.printNextToken(Token.t_else, true);
}
}
if (elseStatement instanceof IASTCompoundStatement && !enclosedInMacroExpansion(elseStatement)) {
elseStatement.accept(this);
} else if (elseStatement instanceof IASTIfStatement) {
if (!preferences.compact_else_if) {
scribe.startNewLine();
scribe.indent();
}
scribe.space();
elseStatement.accept(this);
if (!preferences.compact_else_if) {
scribe.unIndent();
}
} else if (preferences.keep_else_statement_on_same_line) {
scribe.space();
elseStatement.accept(this); elseStatement.accept(this);
} else { } else {
scribe.startNewLine(); if (peekNextToken() == Token.t_else) {
scribe.indent(); if (thenStatementIsBlock) {
elseStatement.accept(this); scribe.printNextToken(Token.t_else, preferences.insert_space_after_closing_brace_in_block);
scribe.unIndent(); } else {
scribe.printNextToken(Token.t_else, true);
}
}
if (elseStatement instanceof IASTCompoundStatement && !enclosedInMacroExpansion(elseStatement)) {
elseStatement.accept(this);
} else if (elseStatement instanceof IASTIfStatement) {
if (!preferences.compact_else_if) {
scribe.startNewLine();
scribe.indent();
}
scribe.space();
elseStatement.accept(this);
if (!preferences.compact_else_if) {
scribe.unIndent();
}
} else if (preferences.keep_else_statement_on_same_line) {
scribe.space();
elseStatement.accept(this);
} else {
scribe.startNewLine();
scribe.indent();
elseStatement.accept(this);
scribe.unIndent();
}
} }
} }
return PROCESS_SKIP; return PROCESS_SKIP;
@ -3624,7 +3680,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.indent(); scribe.indent();
} }
scribe.startNewLine(); scribe.startNewLine();
formatClosingBrace(brace_position); formatClosingBrace(brace_position);
} }
} finally { } finally {
@ -3684,9 +3740,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
* Test whether the next node location is inside a macro expansion. If it is * Test whether the next node location is inside a macro expansion. If it is
* a macro expansion, formatting will be skipped until the next node outside * a macro expansion, formatting will be skipped until the next node outside
* the expansion is reached. * the expansion is reached.
* *
* @param node the AST node to be tested * @param node the AST node to be tested
* @return <code>false</code> if the node should be skipped * @return <code>false</code> if the node should be skipped
*/ */
private boolean startNode(IASTNode node) { private boolean startNode(IASTNode node) {
scribe.startNode(); scribe.startNode();
@ -3702,7 +3758,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
IASTFileLocation macroLocation = macroExpansion.getFileLocation(); IASTFileLocation macroLocation = macroExpansion.getFileLocation();
IASTFileLocation nodeLocation = node.getFileLocation(); IASTFileLocation nodeLocation = node.getFileLocation();
if (macroLocation.getNodeOffset() >= scribe.scanner.getCurrentPosition() && if (macroLocation.getNodeOffset() >= scribe.scanner.getCurrentPosition() &&
!scribe.shouldSkip(macroLocation.getNodeOffset()) && !scribe.shouldSkip(macroLocation.getNodeOffset()) &&
(nodeLocation.getNodeOffset() + nodeLocation.getNodeLength() == (nodeLocation.getNodeOffset() + nodeLocation.getNodeLength() ==
macroLocation.getNodeOffset() + macroLocation.getNodeLength() || macroLocation.getNodeOffset() + macroLocation.getNodeLength() ||
locations.length == 2 && isSemicolonLocation(locations[1])) && locations.length == 2 && isSemicolonLocation(locations[1])) &&
@ -3729,7 +3785,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
/** /**
* Formatting of node is complete. Undo skip region if any. * Formatting of node is complete. Undo skip region if any.
* *
* @param node * @param node
*/ */
private void endOfNode(IASTNode node) { private void endOfNode(IASTNode node) {
@ -3751,7 +3807,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
/** /**
* Formatting of node continues after completion of a child node. Establish next skip region. * Formatting of node continues after completion of a child node. Establish next skip region.
* *
* @param node * @param node
*/ */
private void continueNode(IASTNode node) { private void continueNode(IASTNode node) {
@ -3835,7 +3891,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
/** /**
* Format an expression nested in parenthesis. If the operand is * Format an expression nested in parenthesis. If the operand is
* <code>null</code>, empty parenthesis are expected. * <code>null</code>, empty parenthesis are expected.
* *
* @param operand * @param operand
*/ */
private void formatParenthesizedExpression(final IASTExpression operand) { private void formatParenthesizedExpression(final IASTExpression operand) {
@ -3944,11 +4000,25 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return true; return true;
} }
/**
* Returns true if the two given nodes have overlapping file locations. For nodes that are
* normally separated by other tokens this is an indication that they were produced by the same
* macro expansion.
*/
private static boolean doNodeLocationsOverlap(IASTNode node1, IASTNode node2) { private static boolean doNodeLocationsOverlap(IASTNode node1, IASTNode node2) {
IASTFileLocation loc1 = node1.getFileLocation(); IASTFileLocation loc1 = node1.getFileLocation();
IASTFileLocation loc2 = node2.getFileLocation(); IASTFileLocation loc2 = node2.getFileLocation();
return loc1.getNodeOffset() + loc1.getNodeLength() > loc2.getNodeOffset() && return loc1.getNodeOffset() + loc1.getNodeLength() > loc2.getNodeOffset() &&
loc1.getNodeOffset() < loc2.getNodeOffset() + loc2.getNodeLength(); loc1.getNodeOffset() < loc2.getNodeOffset() + loc2.getNodeLength();
}
/**
* Returns true if the two given nodes have the same offset. For nodes that are normally
* separated by other tokens this is an indication that they were produced by the same macro
* expansion.
*/
private static boolean doNodesHaveSameOffset(IASTNode node1, IASTNode node2) {
return node1.getFileLocation().getNodeOffset() == node2.getFileLocation().getNodeOffset();
} }
private void formatBlock(IASTCompoundStatement block, String block_brace_position, private void formatBlock(IASTCompoundStatement block, String block_brace_position,

View file

@ -15,6 +15,14 @@
<artifactId>org.eclipse.cdt.ui.tests</artifactId> <artifactId>org.eclipse.cdt.ui.tests</artifactId>
<packaging>eclipse-test-plugin</packaging> <packaging>eclipse-test-plugin</packaging>
<repositories>
<repository>
<id>cdt.repo</id>
<url>file:/${basedir}/../../releng/org.eclipse.cdt.repo/target/repository</url>
<layout>p2</layout>
</repository>
</repositories>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -28,6 +36,18 @@
<include>**/AutomatedSuite.*</include> <include>**/AutomatedSuite.*</include>
</includes> </includes>
<testFailureIgnore>true</testFailureIgnore> <testFailureIgnore>true</testFailureIgnore>
<dependencies>
<dependency>
<artifactId>org.eclipse.platform.feature.group</artifactId>
<version>3.7.0</version>
<type>p2-installable-unit</type>
</dependency>
<dependency>
<artifactId>org.eclipse.cdt.feature.group</artifactId>
<version>8.0.0.${buildQualifier}</version>
<type>p2-installable-unit</type>
</dependency>
</dependencies>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View file

@ -963,7 +963,7 @@ public class CodeFormatterTest extends BaseUITestCase {
//M* A::c(M* tm) { N::iterator it = myN.find(tm); if (!it) return NULL; else return *it; } //M* A::c(M* tm) { N::iterator it = myN.find(tm); if (!it) return NULL; else return *it; }
//void A::a(C e) { //void A::a(C e) {
// if (D::iterator it = m.find (e)) // if (D::iterator it = m.find(e))
// m.erase(it); // m.erase(it);
//} //}
//T* A::b(T* t) { //T* A::b(T* t) {
@ -1505,6 +1505,24 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult(); assertFormatterResult();
} }
//#define BLOCK { }
//#define ALWAYS if(true)
//
//void foo() {
//ALWAYS BLOCK
//}
//#define BLOCK { }
//#define ALWAYS if(true)
//
//void foo() {
// ALWAYS
// BLOCK
//}
public void testCompoundStatementAsMacro_Temp() throws Exception {
assertFormatterResult();
}
//#define BLOCK { } //#define BLOCK { }
//#define DOIT1() { } //#define DOIT1() { }
//#define DOIT2() do { } while(false) //#define DOIT2() do { } while(false)
@ -2400,6 +2418,37 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult(); assertFormatterResult();
} }
//struct Stream {
//Stream& operator <<(const char*);
//};
//Stream GetStream();
//
//#define MY_MACRO switch (0) case 0: default: if (bool x = false) ; else GetStream()
//
//void test() {
//MY_MACRO << "Loooooooooooooooooooong string literal" << " another literal.";
//MY_MACRO << "Looooooooooooooooooooong string literal" << " another literal.";
//}
//struct Stream {
// Stream& operator <<(const char*);
//};
//Stream GetStream();
//
//#define MY_MACRO switch (0) case 0: default: if (bool x = false) ; else GetStream()
//
//void test() {
// MY_MACRO << "Loooooooooooooooooooong string literal" << " another literal.";
// MY_MACRO << "Looooooooooooooooooooong string literal"
// << " another literal.";
//}
public void testOverloadedLeftShiftChain_6() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_OVERLOADED_LEFT_SHIFT_CHAIN,
Integer.toString(Alignment.M_COMPACT_SPLIT | Alignment.M_INDENT_ON_COLUMN));
assertFormatterResult();
}
//int main() { //int main() {
// std::vector<std::vector<int>> test; // std::vector<std::vector<int>> test;
// // some comment // // some comment

View file

@ -17,6 +17,7 @@
package org.eclipse.cdt.dsf.mi.service; package org.eclipse.cdt.dsf.mi.service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Hashtable; import java.util.Hashtable;
@ -845,9 +846,9 @@ public class MIBreakpointsManager extends AbstractDsfService implements IBreakpo
final Map<ICBreakpoint, Set<String>> threadsIDs = fBreakpointThreads.get(dmc); final Map<ICBreakpoint, Set<String>> threadsIDs = fBreakpointThreads.get(dmc);
assert threadsIDs != null; assert threadsIDs != null;
// Minimal validation boolean filtered = isBreakpointEntirelyFiltered(dmc, breakpoint);
if (!platformBPs.containsKey(breakpoint)) {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, UNKNOWN_BREAKPOINT, null)); if (filtered && !platformBPs.containsKey(breakpoint)) {
rm.done(); rm.done();
return; return;
} }
@ -860,7 +861,7 @@ public class MIBreakpointsManager extends AbstractDsfService implements IBreakpo
// Note that Tracepoints are not affected by "skip-all" // Note that Tracepoints are not affected by "skip-all"
boolean bpEnabled = attributes.get(ICBreakpoint.ENABLED).equals(true) && boolean bpEnabled = attributes.get(ICBreakpoint.ENABLED).equals(true) &&
(breakpoint instanceof ICTracepoint || fBreakpointManager.isEnabled()); (breakpoint instanceof ICTracepoint || fBreakpointManager.isEnabled());
if (bpEnabled) { if (!filtered && bpEnabled) {
attributes.put(ATTR_DEBUGGER_PATH, NULL_STRING); attributes.put(ATTR_DEBUGGER_PATH, NULL_STRING);
attributes.put(ATTR_THREAD_FILTER, extractThreads(dmc, breakpoint)); attributes.put(ATTR_THREAD_FILTER, extractThreads(dmc, breakpoint));
attributes.put(ATTR_THREAD_ID, NULL_STRING); attributes.put(ATTR_THREAD_ID, NULL_STRING);
@ -876,6 +877,11 @@ public class MIBreakpointsManager extends AbstractDsfService implements IBreakpo
} }
return; return;
} }
if (filtered) {
uninstallBreakpoint(dmc, breakpoint, rm );
return;
}
// Get the original breakpoint attributes // Get the original breakpoint attributes
final Map<String,Object> original_attributes = platformBPs.get(breakpoint); final Map<String,Object> original_attributes = platformBPs.get(breakpoint);
@ -975,8 +981,11 @@ public class MIBreakpointsManager extends AbstractDsfService implements IBreakpo
protected void handleSuccess() { protected void handleSuccess() {
// Get the list of new back-end breakpoints contexts // Get the list of new back-end breakpoints contexts
newTargetBPs.addAll(getData()); newTargetBPs.addAll(getData());
for (IBreakpointDMContext newRef : newTargetBPs)
targetBPs.put(newRef, breakpoint);
threadsIDs.put(breakpoint, newThreads); threadsIDs.put(breakpoint, newThreads);
for (final IBreakpointDMContext ref : oldTargetBPs) { for (final IBreakpointDMContext ref : oldTargetBPs) {
targetBPs.remove(ref);
decrementInstallCount(ref, breakpoint, // A tad early but it should work... decrementInstallCount(ref, breakpoint, // A tad early but it should work...
new RequestMonitor(getExecutor(), removeRM) { new RequestMonitor(getExecutor(), removeRM) {
@Override @Override
@ -1883,4 +1892,18 @@ public class MIBreakpointsManager extends AbstractDsfService implements IBreakpo
return !(breakpoint instanceof ICWatchpoint); return !(breakpoint instanceof ICWatchpoint);
} }
/**
* Returns whether the breakpoint is filtered for given target.
*/
private boolean isBreakpointEntirelyFiltered(IBreakpointsTargetDMContext dmc, ICBreakpoint breakpoint) {
IContainerDMContext currentDmc = DMContexts.getAncestorOfType(dmc, IContainerDMContext.class);
try {
IContainerDMContext[] targetDmcs = getFilterExtension(breakpoint).getTargetFilters();
if (Arrays.asList(targetDmcs).contains(currentDmc))
return false;
}
catch(CoreException e) {
}
return true;
}
} }

View file

@ -146,6 +146,9 @@ public class LRCPPTests extends AST2CPPTests {
@Override @Override
public void testStaticAssertions_294730() throws Exception {} public void testStaticAssertions_294730() throws Exception {}
//outer::foo x
@Override
public void testAttributeInUsingDirective_351228() throws Exception {}
@Override @Override

View file

@ -48,7 +48,8 @@ public class LRCompletionBasicTest extends BasicCompletionTest {
public void testCastExpression_Bug301933() throws Exception {} public void testCastExpression_Bug301933() throws Exception {}
@Override @Override
public void testConditionalOperator_Bug308611() throws Exception {} public void testConditionalOperator_Bug308611() throws Exception {}
@Override
public void testCompletionInDesignatedInitializor_353281() throws Exception {}
@Override @Override
@SuppressWarnings("unused") @SuppressWarnings("unused")

View file

@ -107,6 +107,12 @@ public class LRTemplateTests extends AST2TemplateTests {
//variadic template //variadic template
@Override @Override
public void testVariadicFunctionTemplate_Bug333389() throws Exception {} public void testVariadicFunctionTemplate_Bug333389() throws Exception {}
//auto
@Override
public void testRRefVsRef_351927() throws Exception {}
//Variadic template arguments
@Override
public void testTemplateTemplateParameterMatching_352859() throws Exception {}
@Override @Override
@SuppressWarnings("unused") @SuppressWarnings("unused")

View file

@ -42,8 +42,4 @@
id="org.eclipse.cdt.gnu.dsf" id="org.eclipse.cdt.gnu.dsf"
version="0.0.0"/> version="0.0.0"/>
<includes
id="org.eclipse.cdt.p2"
version="0.0.0"/>
</feature> </feature>

View file

@ -2,11 +2,13 @@
<site> <site>
<feature url="features/org.eclipse.cdt_0.0.0.qualifier.jar" id="org.eclipse.cdt" version="0.0.0"/> <feature url="features/org.eclipse.cdt_0.0.0.qualifier.jar" id="org.eclipse.cdt" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.sdk_0.0.0.qualifier.jar" id="org.eclipse.cdt.sdk" version="0.0.0"/> <feature url="features/org.eclipse.cdt.sdk_0.0.0.qualifier.jar" id="org.eclipse.cdt.sdk" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.core.lrparser.sdk_0.0.0.qualifier.jar" id="org.eclipse.cdt.core.lrparser.sdk" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.core.parser.upc.feature_0.0.0.qualifier.jar" id="org.eclipse.cdt.core.parser.upc.feature" version="0.0.0"/> <feature url="features/org.eclipse.cdt.core.parser.upc.feature_0.0.0.qualifier.jar" id="org.eclipse.cdt.core.parser.upc.feature" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.core.parser.upc.sdk.feature_0.0.0.qualifier.jar" id="org.eclipse.cdt.core.parser.upc.feature" version="0.0.0"/> <feature url="features/org.eclipse.cdt.core.parser.upc.sdk.feature_0.0.0.qualifier.jar" id="org.eclipse.cdt.core.parser.upc.sdk" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.bupc_0.0.0.qualifier.jar" id="org.eclipse.cdt.bupc" version="0.0.0"/> <feature url="features/org.eclipse.cdt.bupc_0.0.0.qualifier.jar" id="org.eclipse.cdt.bupc" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.debug.gdbjtag_0.0.0.qualifier.jar" id="org.eclipse.cdt.debug.gdbjtag" version="0.0.0"/> <feature url="features/org.eclipse.cdt.debug.gdbjtag_0.0.0.qualifier.jar" id="org.eclipse.cdt.debug.gdbjtag" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.xlc.feature_0.0.0.qualifier.jar" id="org.eclipse.cdt.xlc.feature" version="0.0.0"/> <feature url="features/org.eclipse.cdt.xlc.feature_0.0.0.qualifier.jar" id="org.eclipse.cdt.xlc.feature" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.xlc.sdk_0.0.0.qualifier.jar" id="org.eclipse.cdt.xlc.sdk" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.util_0.0.0.qualifier.jar" id="org.eclipse.cdt.util" version="0.0.0"/> <feature url="features/org.eclipse.cdt.util_0.0.0.qualifier.jar" id="org.eclipse.cdt.util" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.debug.ui.memory_0.0.0.qualifier.jar" id="org.eclipse.cdt.debug.ui.memory" version="0.0.0"/> <feature url="features/org.eclipse.cdt.debug.ui.memory_0.0.0.qualifier.jar" id="org.eclipse.cdt.debug.ui.memory" version="0.0.0"/>
<feature url="features/org.eclipse.cdt.debug.ui.memory.source_0.0.0.qualifier.jar" id="org.eclipse.cdt.debug.ui.memory.source" version="0.0.0"/> <feature url="features/org.eclipse.cdt.debug.ui.memory.source_0.0.0.qualifier.jar" id="org.eclipse.cdt.debug.ui.memory.source" version="0.0.0"/>

View file

@ -14,4 +14,45 @@
<version>8.0.0-SNAPSHOT</version> <version>8.0.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.repo</artifactId> <artifactId>org.eclipse.cdt.repo</artifactId>
<packaging>eclipse-repository</packaging> <packaging>eclipse-repository</packaging>
<profiles>
<profile>
<id>production</id>
<properties>
<cdt-install>/home/data/httpd/download.eclipse.org/tools/cdt/builds/hudson/cdt-nightly</cdt-install>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir dir="${cdt-install}"/>
<delete>
<fileset dir="${cdt-install}">
<include name="**" />
</fileset>
</delete>
<copy
file="target/org.eclipse.cdt.repo.zip"
tofile="${cdt-install}/org.eclipse.cdt.repo.${unqualifiedVersion}.${buildQualifier}.zip"/>
<unzip
src="target/org.eclipse.cdt.repo.zip"
dest="${cdt-install}"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View file

@ -477,6 +477,7 @@
valueType="boolean"/> valueType="boolean"/>
<inputType <inputType
id="org.eclipse.cdt.msvc.lib.inputType" id="org.eclipse.cdt.msvc.lib.inputType"
multipleOfType="true"
sources="obj,res"> sources="obj,res">
</inputType> </inputType>
<outputType <outputType