From 0f4ee61b1d04b4b53753a586c9537c352607c38d Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 20 Jan 2013 21:29:43 -0800 Subject: [PATCH 01/42] Cosmetics. --- .../ui/editor/AbstractCModelOutlinePage.java | 12 ++++---- .../ui/viewsupport/CUILabelProvider.java | 28 ------------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java index 95cf35fb74f..e514bee2bb9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java @@ -207,7 +207,7 @@ public abstract class AbstractCModelOutlinePage extends Page PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_INCLUDES, isChecked()); } - public boolean isIncludesGroupingEnabled () { + public boolean isIncludesGroupingEnabled() { return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES); } } @@ -240,7 +240,7 @@ public abstract class AbstractCModelOutlinePage extends Page PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_MACROS, isChecked()); } - public boolean isMacroGroupingEnabled () { + public boolean isMacroGroupingEnabled() { return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_GROUP_MACROS); } } @@ -374,8 +374,8 @@ public abstract class AbstractCModelOutlinePage extends Page } else if (fInput != null) { try { element= fInput.getElementAtOffset(offset); - } catch (CModelException exc) { - CUIPlugin.log(exc); + } catch (CModelException e) { + CUIPlugin.log(e); } } if (element != null) { @@ -526,7 +526,7 @@ public abstract class AbstractCModelOutlinePage extends Page fTreeViewer.setInput(fInput); PlatformUI.getWorkbench().getHelpSystem().setHelp(control, ICHelpContextIds.COUTLINE_VIEW); - IHandlerService handlerService= (IHandlerService)site.getService(IHandlerService.class); + IHandlerService handlerService= (IHandlerService) site.getService(IHandlerService.class); handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, new ActionHandler(fCollapseAllAction)); } @@ -761,7 +761,7 @@ public abstract class AbstractCModelOutlinePage extends Page public void setInput(ITranslationUnit unit) { fInput = unit; if (fTreeViewer != null) { - fTreeViewer.setInput (fInput); + fTreeViewer.setInput(fInput); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java index 73ba44c79ae..432971e4673 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java @@ -32,7 +32,6 @@ import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.ui.CUIPlugin; public class CUILabelProvider extends LabelProvider implements IColorProvider, IStyledLabelProvider { - protected CElementImageProvider fImageLabelProvider; protected StorageLabelProvider fStorageLabelProvider; @@ -136,9 +135,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I return image; } - /* (non-Javadoc) - * @see ILabelProvider#getImage - */ @Override public Image getImage(Object element) { Image result= fImageLabelProvider.getImageLabel(element, evaluateImageFlags(element)); @@ -159,10 +155,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I return text; } - - /* (non-Javadoc) - * @see ILabelProvider#getText - */ @Override public String getText(Object element) { String result= CElementLabels.getTextLabel(element, evaluateTextFlags(element)); @@ -186,10 +178,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I return string; } - - /* (non-Javadoc) - * @see IBaseLabelProvider#dispose - */ @Override public void dispose() { if (fLabelDecorators != null) { @@ -203,9 +191,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I fImageLabelProvider.dispose(); } - /* (non-Javadoc) - * @see IBaseLabelProvider#addListener(ILabelProviderListener) - */ @Override public void addListener(ILabelProviderListener listener) { if (fLabelDecorators != null) { @@ -217,17 +202,11 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I super.addListener(listener); } - /* (non-Javadoc) - * @see IBaseLabelProvider#isLabelProperty(Object, String) - */ @Override public boolean isLabelProperty(Object element, String property) { return true; } - /* (non-Javadoc) - * @see IBaseLabelProvider#removeListener(ILabelProviderListener) - */ @Override public void removeListener(ILabelProviderListener listener) { if (fLabelDecorators != null) { @@ -252,9 +231,6 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I return null; } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) - */ @Override public Color getForeground(Object element) { if (element instanceof ISourceReference) { @@ -270,12 +246,8 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider, I return fDefaultColor; } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object) - */ @Override public Color getBackground(Object element) { return null; } - } From 7be456a5de031550bbd482f38f7d3fb923fabab2 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 20 Jan 2013 21:33:55 -0800 Subject: [PATCH 02/42] Cosmetics. --- .../ui/viewsupport/ProblemsLabelDecorator.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java index 9e9bb99d4e3..3785db6d355 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java @@ -41,7 +41,7 @@ import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry; /** * LabelDecorator that decorates an element's image with error and warning overlays that * represent the severity of markers attached to the element's underlying resource. To see - * a problem decoration for a marker, the marker needs to be a subtype of IMarker.PROBLEM. + * a problem decoration for a marker, the marker needs to be a subtype of {@code IMarker.PROBLEM}. *

* Note: Only images for elements in Java projects are currently updated on marker changes. *

@@ -49,23 +49,22 @@ import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry; * @since 2.0 */ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabelDecorator { - /** - * This is a special LabelProviderChangedEvent carring additional - * information whether the event orgins from a maker change. + * This is a special LabelProviderChangedEvent carrying additional + * information whether the event origins from a maker change. *

* ProblemsLabelChangedEvents are only generated by * ProblemsLabelDecorators. *

*/ public static class ProblemsLabelChangedEvent extends LabelProviderChangedEvent { - private boolean fMarkerChange; /** * Note: This constructor is for internal use only. Clients should not call this constructor. */ - public ProblemsLabelChangedEvent(IBaseLabelProvider source, IResource[] changedResource, boolean isMarkerChange) { + public ProblemsLabelChangedEvent(IBaseLabelProvider source, IResource[] changedResource, + boolean isMarkerChange) { super(source, changedResource); fMarkerChange= isMarkerChange; } @@ -80,14 +79,13 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe public boolean isMarkerChange() { return fMarkerChange; } - } private static final int ERRORTICK_WARNING= CElementImageDescriptor.WARNING; private static final int ERRORTICK_ERROR= CElementImageDescriptor.ERROR; private ImageDescriptorRegistry fRegistry; - private boolean fUseNewRegistry= false; + private boolean fUseNewRegistry; private IProblemChangedListener fProblemChangedListener; private ListenerList fListeners; @@ -119,7 +117,6 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe return fRegistry; } - @Override public String decorateText(String text, Object element) { return text; @@ -175,7 +172,8 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe return 0; } - private int getErrorTicksFromMarkers(IResource res, int depth, ISourceReference sourceElement) throws CoreException { + private int getErrorTicksFromMarkers(IResource res, int depth, ISourceReference sourceElement) + throws CoreException { if (res == null || !res.isAccessible()) { return 0; } From 1cfda1b6e4ee373221c6e8ec700a897df7bd99cf Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 20 Jan 2013 21:57:33 -0800 Subject: [PATCH 03/42] Bug 398611. Avoid calling IResource.findMarkers multiple times for the same resource. --- .../viewsupport/ProblemsLabelDecorator.java | 63 +++++++++++++++---- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java index 3785db6d355..9167db36c20 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java @@ -7,9 +7,13 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.ui.viewsupport; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceStatus; @@ -81,14 +85,43 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe } } + private static class MarkersCacheKey { + private IResource res; + private int depth; + + public MarkersCacheKey(IResource res, int depth) { + this.res = res; + this.depth = depth; + } + + @Override + public int hashCode() { + return res.hashCode() + 31 * depth; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MarkersCacheKey other = (MarkersCacheKey) obj; + return depth == other.depth && res.equals(other.res); + } + } + private static final int ERRORTICK_WARNING= CElementImageDescriptor.WARNING; private static final int ERRORTICK_ERROR= CElementImageDescriptor.ERROR; + private static final IMarker[] EMPTY_MARKER_ARRAY = {}; private ImageDescriptorRegistry fRegistry; private boolean fUseNewRegistry; private IProblemChangedListener fProblemChangedListener; private ListenerList fListeners; + private Map fMarkersCache = new HashMap(); /** * Creates a new ProblemsLabelDecorator. @@ -179,17 +212,22 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe } int info= 0; - IMarker[] markers= res.findMarkers(IMarker.PROBLEM, true, depth); - if (markers != null) { - for (int i= 0; i < markers.length && (info != ERRORTICK_ERROR); i++) { - IMarker curr= markers[i]; - if (sourceElement == null || isMarkerInRange(curr, sourceElement)) { - int priority= curr.getAttribute(IMarker.SEVERITY, -1); - if (priority == IMarker.SEVERITY_WARNING) { - info= ERRORTICK_WARNING; - } else if (priority == IMarker.SEVERITY_ERROR) { - info= ERRORTICK_ERROR; - } + MarkersCacheKey cacheKey = new MarkersCacheKey(res, depth); + IMarker[] markers = fMarkersCache .get(cacheKey); + if (markers == null) { + markers= res.findMarkers(IMarker.PROBLEM, true, depth); + if (markers == null) + markers = EMPTY_MARKER_ARRAY; + fMarkersCache.put(cacheKey, markers); + } + for (int i= 0; i < markers.length && (info != ERRORTICK_ERROR); i++) { + IMarker curr= markers[i]; + if (sourceElement == null || isMarkerInRange(curr, sourceElement)) { + int priority= curr.getAttribute(IMarker.SEVERITY, -1); + if (priority == IMarker.SEVERITY_WARNING) { + info= ERRORTICK_WARNING; + } else if (priority == IMarker.SEVERITY_ERROR) { + info= ERRORTICK_ERROR; } } } @@ -226,7 +264,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe protected boolean isInside(int offSet, int line, ISourceReference sourceElement) throws CoreException { ISourceRange range= sourceElement.getSourceRange(); if (range != null) { - if (offSet ==-1) { + if (offSet == -1) { return (line >= range.getStartLine() && line <= range.getEndLine()); } int rangeOffset= range.getStartPos(); @@ -280,6 +318,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe } protected void fireProblemsChanged(IResource[] changedResources, boolean isMarkerChange) { + fMarkersCache.clear(); if (fListeners != null && !fListeners.isEmpty()) { LabelProviderChangedEvent event= new ProblemsLabelChangedEvent(this, changedResources, isMarkerChange); Object[] listeners= fListeners.getListeners(); From dee62ceaa7fb153ace823c62b340f60666f32c3e Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 20 Jan 2013 22:06:18 -0800 Subject: [PATCH 04/42] Adjusted Javadoc. --- .../internal/ui/viewsupport/ProblemsLabelDecorator.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java index 9167db36c20..d7d6f46f710 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/ProblemsLabelDecorator.java @@ -54,12 +54,10 @@ import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry; */ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabelDecorator { /** - * This is a special LabelProviderChangedEvent carrying additional - * information whether the event origins from a maker change. + * This is a special {@code LabelProviderChangedEvent} carrying additional + * information whether the event originates from a maker change. *

- * ProblemsLabelChangedEvents are only generated by - * ProblemsLabelDecorators. - *

+ * {@code ProblemsLabelChangedEvent}s are only generated by {@code ProblemsLabelDecorator}s. */ public static class ProblemsLabelChangedEvent extends LabelProviderChangedEvent { private boolean fMarkerChange; From ea3ca7e18afb2380e3e9882a646bfd589533377f Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 21 Jan 2013 17:14:07 -0800 Subject: [PATCH 05/42] Cosmetics. --- .../cdt/internal/core/dom/parser/ASTEnumerator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java index 32335283083..de5891334db 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java @@ -127,21 +127,21 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I private void createEnumValues(IASTEnumerationSpecifier parent) { IASTEnumerator[] etors= parent.getEnumerators(); long cv= -1; - boolean isknown= true; + boolean isKnown= true; for (IASTEnumerator etor : etors) { cv++; IASTExpression expr= etor.getValue(); if (expr != null) { IValue val= Value.create(expr, Value.MAX_RECURSION_DEPTH); Long nv= val.numericalValue(); - isknown= false; + isKnown= false; if (nv != null) { - isknown= true; + isKnown= true; cv= nv.longValue(); } } if (etor instanceof ASTEnumerator) { - ((ASTEnumerator) etor).integralValue= isknown ? Value.create(cv) : Value.UNKNOWN; + ((ASTEnumerator) etor).integralValue= isKnown ? Value.create(cv) : Value.UNKNOWN; } } } From 424d913ba96f864f56e9ca26acfccdefb103753d Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 21 Jan 2013 19:32:41 -0800 Subject: [PATCH 06/42] Do not treat sizeof(bool) as unknown when __SIZEOF_BOOL__ macro is not defined. --- .../cdt/internal/core/dom/parser/SizeofCalculator.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index a084775601e..92ebd31459a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -129,7 +129,11 @@ public class SizeofCalculator { sizeof_long_long = getSize(sizeofMacros, "__SIZEOF_LONG_LONG__", maxAlignment); //$NON-NLS-1$ sizeof_int128 = getSize(sizeofMacros, "__SIZEOF_INT128__", maxAlignment); //$NON-NLS-1$ sizeof_short = getSize(sizeofMacros, "__SIZEOF_SHORT__", maxAlignment); //$NON-NLS-1$ - sizeof_bool = getSize(sizeofMacros, "__SIZEOF_BOOL__", maxAlignment); //$NON-NLS-1$ + SizeAndAlignment size = getSize(sizeofMacros, "__SIZEOF_BOOL__", maxAlignment); //$NON-NLS-1$ + // __SIZEOF_BOOL__ is not defined by GCC but sizeof(bool) is needed for template resolution. + if (size == null) + size = SIZE_1; + sizeof_bool = size; sizeof_wchar_t = getSize(sizeofMacros, "__SIZEOF_WCHAR_T__", maxAlignment); //$NON-NLS-1$ sizeof_float = getSize(sizeofMacros, "__SIZEOF_FLOAT__", maxAlignment); //$NON-NLS-1$ sizeof_complex_float = getSizeOfPair(sizeof_float); @@ -152,7 +156,7 @@ public class SizeofCalculator { sizeof_long_long = null; sizeof_int128 = size_16; sizeof_short = null; - sizeof_bool = null; + sizeof_bool = SIZE_1; sizeof_wchar_t = null; sizeof_float = null; sizeof_complex_float = null; From 9a0842acd568f77315835fc7d823233f1266f74d Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 21 Jan 2013 19:33:31 -0800 Subject: [PATCH 07/42] Bug 398696 - Name resolution problem with a conditional enum value. --- .../parser/tests/ast2/AST2TemplateTests.java | 31 ++++++++++++++++++ .../core/dom/parser/ASTEnumerator.java | 32 +++++++++++-------- .../cdt/internal/core/dom/parser/Value.java | 16 ++++++++++ .../core/dom/parser/c/CASTEnumerator.java | 11 ++----- .../core/dom/parser/cpp/CPPASTEnumerator.java | 13 +++----- 5 files changed, 72 insertions(+), 31 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 19350ee7d27..59c74e79b3e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -7004,4 +7004,35 @@ public class AST2TemplateTests extends AST2BaseTest { public void testDependentExpressions_395243d() throws Exception { parseAndCheckBindings(); } + + // template struct A {}; + // + // template + // struct A { + // static void m(); + // }; + // + // template + // struct B { + // enum { value = 1 }; + // }; + // + // template + // struct C { + // enum { id = B::value ? 0 : -1 }; + // }; + // + // template + // struct D { + // typedef A::id> E; + // }; + // + // void test() { + // D::E::m(); + // } + public void testDependentEnum_398696() throws Exception { + BindingAssertionHelper ah = getAssertionHelper(); + ah.assertNonProblem("D::E::m()", "m"); +// parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java index de5891334db..ff3726895e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEnumerator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2013 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -33,11 +34,11 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I setName(name); setValue(value); } - - protected void copyAbstractEnumerator(ASTEnumerator copy, CopyStyle style) { + + protected T copy(T copy, CopyStyle style) { copy.setName(name == null ? null : name.copy(style)); copy.setValue(value == null ? null : value.copy(style)); - copy.setOffsetAndLength(this); + return super.copy(copy, style); } @Override @@ -125,23 +126,26 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I } private void createEnumValues(IASTEnumerationSpecifier parent) { + IValue previousExplicitValue = null; + int delta = 0; IASTEnumerator[] etors= parent.getEnumerators(); - long cv= -1; - boolean isKnown= true; for (IASTEnumerator etor : etors) { - cv++; + IValue val; IASTExpression expr= etor.getValue(); if (expr != null) { - IValue val= Value.create(expr, Value.MAX_RECURSION_DEPTH); - Long nv= val.numericalValue(); - isKnown= false; - if (nv != null) { - isKnown= true; - cv= nv.longValue(); + val= Value.create(expr, Value.MAX_RECURSION_DEPTH); + previousExplicitValue = val; + delta = 1; + } else { + if (previousExplicitValue != null) { + val = Value.incrementedValue(previousExplicitValue, delta); + } else { + val = Value.create(delta); } + delta++; } if (etor instanceof ASTEnumerator) { - ((ASTEnumerator) etor).integralValue= isKnown ? Value.create(cv) : Value.UNKNOWN; + ((ASTEnumerator) etor).integralValue= val; } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java index 4e5a941bc05..8c074ef9932 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/Value.java @@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; @@ -53,16 +54,20 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTInitializerClause; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator.SizeAndAlignment; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinary; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFixed; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TypeTraits; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator; import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException; @@ -77,6 +82,7 @@ public class Value implements IValue { public static final int MAX_RECURSION_DEPTH = 25; public static final Value UNKNOWN= new Value("".toCharArray(), null); //$NON-NLS-1$ public static final Value NOT_INITIALIZED= new Value("<__>".toCharArray(), null); //$NON-NLS-1$ + private static final IType INT_TYPE= new CPPBasicType(ICPPBasicType.Kind.eInt, 0); private static final Number VALUE_CANNOT_BE_DETERMINED = new Number() { @Override @@ -271,6 +277,16 @@ public class Value implements IValue { return UNKNOWN; } + public static IValue incrementedValue(IValue value, int increment) { + Long val = value.numericalValue(); + if (val != null) { + return create(val.longValue() + increment); + } + ICPPEvaluation arg1 = value.getEvaluation(); + EvalFixed arg2 = new EvalFixed(INT_TYPE, ValueCategory.PRVALUE, create(increment)); + return create(new EvalBinary(IASTBinaryExpression.op_plus, arg1, arg2)); + } + private static Number applyUnaryTypeIdOperator(int operator, IType type, IASTNode point) { switch (operator) { case op_sizeof: diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java index b5706d94dac..1b596216df0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTEnumerator.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2013 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: - * John Camelon (IBM Rational Software) - Initial API and implementation + * John Camelon (IBM Rational Software) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -34,11 +34,6 @@ public class CASTEnumerator extends ASTEnumerator { @Override public CASTEnumerator copy(CopyStyle style) { - CASTEnumerator copy = new CASTEnumerator(); - copyAbstractEnumerator(copy, style); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(new CASTEnumerator(), style); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java index fdd9fef35d6..0eee0c53ec3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerator.java @@ -1,13 +1,13 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2013 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: - * John Camelon (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * John Camelon (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -35,11 +35,6 @@ public class CPPASTEnumerator extends ASTEnumerator { @Override public CPPASTEnumerator copy(CopyStyle style) { - CPPASTEnumerator copy = new CPPASTEnumerator(); - copyAbstractEnumerator(copy, style); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(new CPPASTEnumerator(), style); } } From 2d3cc44232260e84aa8a08615f6960386a77627b Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 21 Jan 2013 20:11:25 -0800 Subject: [PATCH 08/42] Bug 398696 - Name resolution problem with a conditional enum value --- .../eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 59c74e79b3e..6c40e6998cb 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -7031,8 +7031,6 @@ public class AST2TemplateTests extends AST2BaseTest { // D::E::m(); // } public void testDependentEnum_398696() throws Exception { - BindingAssertionHelper ah = getAssertionHelper(); - ah.assertNonProblem("D::E::m()", "m"); -// parseAndCheckBindings(); + parseAndCheckBindings(); } } From f94c6909ac2da1edf581f334f39f401ad15b3baf Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 21 Jan 2013 21:42:01 -0800 Subject: [PATCH 09/42] Bug 398696. Failing test case. --- .../parser/tests/ast2/AST2TemplateTests.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 6c40e6998cb..b8d2a21ffb2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -44,6 +44,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunctionType; @@ -55,6 +56,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; @@ -7005,13 +7007,6 @@ public class AST2TemplateTests extends AST2BaseTest { parseAndCheckBindings(); } - // template struct A {}; - // - // template - // struct A { - // static void m(); - // }; - // // template // struct B { // enum { value = 1 }; @@ -7022,15 +7017,16 @@ public class AST2TemplateTests extends AST2BaseTest { // enum { id = B::value ? 0 : -1 }; // }; // - // template - // struct D { - // typedef A::id> E; - // }; - // // void test() { - // D::E::m(); + // int x = C::id; // } - public void testDependentEnum_398696() throws Exception { - parseAndCheckBindings(); + public void _testDependentEnum_398696() throws Exception { + BindingAssertionHelper ah = getAssertionHelper(); + IEnumerator binding = ah.assertNonProblem("C::id", "id"); + IBinding owner = binding.getOwner(); + IValue value = binding.getValue(); + Long num = value.numericalValue(); + assertNotNull(num); + assertEquals(0, num.longValue()); } } From ca712e679a7ee7790a2ed0cac13139f71c8f059e Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 22 Jan 2013 14:20:15 -0800 Subject: [PATCH 10/42] Test simplification. --- .../cdt/core/parser/tests/ast2/AST2TemplateTests.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index b8d2a21ffb2..42468a11cb8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -7014,19 +7014,18 @@ public class AST2TemplateTests extends AST2BaseTest { // // template // struct C { - // enum { id = B::value ? 0 : -1 }; + // enum { id = B::value }; // }; // // void test() { // int x = C::id; // } - public void _testDependentEnum_398696() throws Exception { + public void _testDependentEnumValue_389009() throws Exception { BindingAssertionHelper ah = getAssertionHelper(); IEnumerator binding = ah.assertNonProblem("C::id", "id"); - IBinding owner = binding.getOwner(); IValue value = binding.getValue(); Long num = value.numericalValue(); assertNotNull(num); - assertEquals(0, num.longValue()); + assertEquals(1, num.longValue()); } } From 8fcd01b3c757412ff9ff361fa4337995c0114ace Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 22 Jan 2013 04:19:40 -0500 Subject: [PATCH 11/42] Bug 398706 - 'T' in 'new T' gets resolved to CPPConstructor instead of CPPClassType Change-Id: I7fecc996736cfacb40ad4ee7af8619bd3b6d2a2a Reviewed-on: https://git.eclipse.org/r/9824 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../core/parser/tests/ast2/AST2BaseTest.java | 12 ++- .../tests/ast2/AST2CPPImplicitNameTests.java | 7 +- .../core/parser/tests/ast2/AST2CPPTests.java | 42 ++++++----- .../tests/ast2/AST2SelectionParseTest.java | 18 +++-- .../parser/tests/ast2/AST2TemplateTests.java | 12 +-- .../tests/ast2/CompleteParser2Tests.java | 43 ++++++----- .../tests/ast2/DOMSelectionParseTest.java | 20 +++-- .../cdt/core/parser/tests/ast2/TestUtil.java | 36 +++++++++ .../tests/IndexBindingResolutionTestBase.java | 72 ++++++++++++++++-- .../tests/IndexCPPBindingResolutionTest.java | 7 +- .../tests/IndexCPPTemplateResolutionTest.java | 6 +- .../parser/cpp/semantics/CPPSemantics.java | 75 +++++++++---------- 12 files changed, 233 insertions(+), 117 deletions(-) create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index dff0c031a63..374a5014c03 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 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 @@ -329,9 +329,15 @@ public class AST2BaseTest extends BaseTestCase { } static protected class CPPNameCollector extends ASTVisitor { - { - shouldVisitNames = true; + public CPPNameCollector() { + this(false); // don't visit implicit names by default } + + public CPPNameCollector(boolean shouldVisitImplicitNames) { + this.shouldVisitNames = true; + this.shouldVisitImplicitNames = shouldVisitImplicitNames; + } + public List nameList = new ArrayList(); @Override diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java index 002916af926..2095a9e4b25 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation and others. + * Copyright (c) 2009, 2013 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 @@ -9,6 +9,7 @@ * Mike Kucera (IBM) * Sergey Prigogin (Google) * Markus Schorn (Wind River Systems) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -445,11 +446,11 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { IBinding f= bh.assertNonProblem("operator new(size_t b)", 12); IASTImplicitName[] names = bh.getImplicitNames("new A;", 3); - assertEquals(1, names.length); + assertEquals(2, names.length); assertSame(m, names[0].resolveBinding()); names = bh.getImplicitNames("new B;", 3); - assertEquals(1, names.length); + assertEquals(2, names.length); assertSame(f, names[0].resolveBinding()); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 5908699d91c..6b0c3082484 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 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 @@ -1201,10 +1201,10 @@ public class AST2CPPTests extends AST2BaseTest { // } public void testVirtualParentLookup() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); - CPPNameCollector collector = new CPPNameCollector(); + CPPNameCollector collector = new CPPNameCollector(true); tu.accept(collector); - assertEquals(collector.size(), 15); + assertEquals(collector.size(), 16); ICPPClassType D = (ICPPClassType) collector.getName(0).resolveBinding(); ICPPField x = (ICPPField) collector.getName(1).resolveBinding(); @@ -1215,7 +1215,7 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(collector, D, 3); assertInstances(collector, C, 2); assertInstances(collector, B, 2); - assertInstances(collector, A, 2); + assertInstances(collector, A, 3); assertInstances(collector, ctor, 1); assertInstances(collector, x, 2); } @@ -1230,10 +1230,10 @@ public class AST2CPPTests extends AST2BaseTest { // } public void testAmbiguousVirtualParentLookup() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); - CPPNameCollector collector = new CPPNameCollector(); + CPPNameCollector collector = new CPPNameCollector(true); tu.accept(collector); - assertEquals(collector.size(), 15); + assertEquals(collector.size(), 16); ICPPClassType D = (ICPPClassType) collector.getName(0).resolveBinding(); ICPPField x1 = (ICPPField) collector.getName(1).resolveBinding(); @@ -1241,13 +1241,13 @@ public class AST2CPPTests extends AST2BaseTest { ICPPClassType B = (ICPPClassType) collector.getName(4).resolveBinding(); ICPPClassType A = (ICPPClassType) collector.getName(6).resolveBinding(); ICPPConstructor ctor = A.getConstructors()[0]; - IProblemBinding x2 = (IProblemBinding) collector.getName(14).resolveBinding(); + IProblemBinding x2 = (IProblemBinding) collector.getName(15).resolveBinding(); assertEquals(x2.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP); assertInstances(collector, D, 3); assertInstances(collector, C, 2); assertInstances(collector, B, 2); - assertInstances(collector, A, 2); + assertInstances(collector, A, 3); assertInstances(collector, ctor, 1); assertInstances(collector, x1, 1); } @@ -1843,7 +1843,7 @@ public class AST2CPPTests extends AST2BaseTest { ICPPMethod dtor = (ICPPMethod) col.getName(13).resolveBinding(); assertNotNull(dtor); assertEquals(dtor.getName(), "~C"); //$NON-NLS-1$ - assertInstances(col, C, 6); + assertInstances(col, C, 7); assertInstances(col, op, 3); assertInstances(col, other, 4); @@ -1993,7 +1993,7 @@ public class AST2CPPTests extends AST2BaseTest { assertInstances(col, pb, 2); assertInstances(col, mutate, 2); - assertInstances(col, B, 2); + assertInstances(col, B, 3); } // struct S { int i; }; @@ -2511,7 +2511,7 @@ public class AST2CPPTests extends AST2BaseTest { // } public void testBug86267() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); ICPPClassType D1 = (ICPPClassType) col.getName(2).resolveBinding(); @@ -2549,7 +2549,7 @@ public class AST2CPPTests extends AST2BaseTest { ICPPMethod op = (ICPPMethod) col.getName(3).resolveBinding(); IParameter other = (IParameter) col.getName(5).resolveBinding(); - assertInstances(col, C, 6); + assertInstances(col, C, 7); assertInstances(col, f, 2); assertInstances(col, op, 3); assertInstances(col, other, 4); @@ -4052,11 +4052,11 @@ public class AST2CPPTests extends AST2BaseTest { // X x = new X(y); public void testBug90654_1() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); ICPPConstructor ctor1 = (ICPPConstructor) col.getName(1).resolveBinding(); - ICPPConstructor ctor = (ICPPConstructor) col.getName(11).resolveBinding(); + ICPPConstructor ctor = (ICPPConstructor) col.getName(12).resolveBinding(); assertSame(ctor, ctor1); } @@ -8382,20 +8382,24 @@ public class AST2CPPTests extends AST2BaseTest { // fH({1}); // H(G(1)) // } public void testListInitialization_302412f() throws Exception { - ICPPConstructor ctor; IProblemBinding problem; String code= getAboveComment(); BindingAssertionHelper bh= new BindingAssertionHelper(code, true); bh.assertProblem("f({1,1})", 1); - ctor= bh.assertNonProblem("F({1,1})", 1); + bh.assertImplicitName("F({1,1})", 1, ICPPConstructor.class); bh.assertNonProblem("fF({1,1})", 2); bh.assertNonProblem("fG(1)", 2); bh.assertNonProblem("fG({1})", 2); - ctor= bh.assertNonProblem("H(1)", 1); - problem= bh.assertProblem("H({1})", 1); - assertEquals(IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, problem.getID()); + bh.assertImplicitName("H(1)", 1, ICPPConstructor.class); + bh.assertNoImplicitName("H({1})", 1); + // TODO(nathanridge): Perhaps we should store implicit names even if they + // resolve to ProblemBindings. Then we can do the stronger check in the + // 3 commented lines below. + //IASTImplicitName n= bh.assertImplicitName("H({1})", 1, IProblemBinding.class); + //problem= (IProblemBinding) n.resolveBinding(); + //assertEquals(IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, problem.getID()); bh.assertProblem("fH(1)", 2); bh.assertNonProblem("fH({1})", 2); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java index 9ec90bf1263..d729230bdc5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2013 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -26,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IField; @@ -352,9 +354,10 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest { assertTrue(node instanceof IASTTypeId); assertEquals(((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName().toString(), "Gonzo"); //$NON-NLS-1$ name = ((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName(); - assertNotNull(name.resolveBinding()); - assertTrue(name.resolveBinding() instanceof ICPPConstructor); - assertEquals(((ICPPConstructor)name.resolveBinding()).getName(), "Gonzo"); //$NON-NLS-1$ + name = TestUtil.findImplicitName(name); + IBinding binding = name.resolveBinding(); + assertTrue(binding instanceof ICPPConstructor); + assertEquals(((ICPPConstructor)binding).getName(), "Gonzo"); //$NON-NLS-1$ break; default: assertTrue(node instanceof IASTName); @@ -736,9 +739,10 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest { assertTrue(node instanceof IASTTypeId); assertEquals(((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName().toString(), "B"); //$NON-NLS-1$ IASTName name = ((IASTNamedTypeSpecifier)((IASTTypeId)node).getDeclSpecifier()).getName(); - assertNotNull(name.resolveBinding()); - assertTrue(name.resolveBinding() instanceof ICPPConstructor); - assertEquals(((ICPPConstructor)name.resolveBinding()).getName(), "B"); //$NON-NLS-1$ + name = TestUtil.findImplicitName(name); + IBinding binding = name.resolveBinding(); + assertTrue(binding instanceof ICPPConstructor); + assertEquals(((ICPPConstructor)binding).getName(), "B"); //$NON-NLS-1$ } public void testBug72712_2() throws Exception{ diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 42468a11cb8..cb6cd028342 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2013 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 @@ -2373,11 +2373,11 @@ public class AST2TemplateTests extends AST2BaseTest { public void testCPPConstructorTemplateSpecialization() throws Exception { IASTTranslationUnit tu = parse(getAboveComment(), CPP, true, true); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); - ICPPASTTemplateId tid= (ICPPASTTemplateId) col.getName(20); - IASTName cn= col.getName(21); + IASTImplicitName tid= (IASTImplicitName) col.getName(20); + IASTName cn= col.getName(22); assertInstance(cn.resolveBinding(), ICPPClassTemplate.class); // *D*(5, 6) assertInstance(cn.resolveBinding(), ICPPClassType.class); // *D*(5, 6) assertInstance(tid.resolveBinding(), ICPPTemplateInstance.class); // *D*(5, 6) @@ -3842,7 +3842,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; public void testNestedTemplates_259872_1() throws Exception { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); - bh.assertNonProblem("A", 9, ICPPConstructor.class); + bh.assertNonProblem("A", 9, ICPPClassType.class); } // template @@ -3867,7 +3867,7 @@ public class AST2TemplateTests extends AST2BaseTest { // }; public void testNestedTemplates_259872_2() throws Exception { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), CPP); - bh.assertNonProblem("A", 9, ICPPConstructor.class); + bh.assertNonProblem("A", 9, ICPPClassType.class); } // template diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index d2c052b0c22..e8474a74621 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2013 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 @@ -8,6 +8,7 @@ * Contributors: * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -102,9 +103,13 @@ public class CompleteParser2Tests extends BaseTestCase { } static private class CPPNameCollector extends ASTVisitor { - { - shouldVisitNames = true; + public CPPNameCollector() { + this(false); // don't visit implicit names by default } + public CPPNameCollector(boolean shouldVisitImplicitNames) { + this.shouldVisitNames = true; + this.shouldVisitImplicitNames = shouldVisitImplicitNames; + } public List nameList = new ArrayList(); @Override public int visit(IASTName name){ @@ -141,7 +146,7 @@ public class CompleteParser2Tests extends BaseTestCase { if (nameCollector.getName(i).resolveBinding() == binding) count++; - assertEquals(count, num); + assertEquals(num, count); } protected void assertInstances(CNameCollector nameCollector, IBinding binding, int num) throws Exception { int count = 0; @@ -149,7 +154,7 @@ public class CompleteParser2Tests extends BaseTestCase { if (nameCollector.getName(i).resolveBinding() == binding) count++; - assertEquals(count, num); + assertEquals(num, count); } protected IASTTranslationUnit parse(String code, boolean expectedToPass, ParserLanguage lang) throws Exception { @@ -1112,14 +1117,14 @@ public class CompleteParser2Tests extends BaseTestCase { public void testBug43503A() throws Exception { IASTTranslationUnit tu = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } "); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); - assertEquals(col.size(), 8); + assertEquals(col.size(), 9); ICPPClassType SD_01 = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f_SD_01 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPConstructor ctor = SD_01.getConstructors()[0]; - assertInstances(col, SD_01, 2); + assertInstances(col, SD_01, 3); assertInstances(col, ctor, 1); assertInstances(col, f_SD_01, 2); } @@ -1204,10 +1209,10 @@ public class CompleteParser2Tests extends BaseTestCase { buff.append("} \n"); IASTTranslationUnit tu = parse(buff.toString()); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); - assertEquals(col.size(), 17); + assertEquals(col.size(), 18); ICompositeType SD_02 = (ICompositeType) col.getName(0).resolveBinding(); ICPPMethod f_SD_02 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPClassType SD_01 = (ICPPClassType) col.getName(2).resolveBinding(); @@ -1217,7 +1222,7 @@ public class CompleteParser2Tests extends BaseTestCase { assertInstances(col, SD_02, 2); assertInstances(col, f_SD_02, 2); - assertInstances(col, SD_01, 3); + assertInstances(col, SD_01, 4); assertInstances(col, ctor, 1); assertInstances(col, next, 2); assertInstances(col, f_SD_01, 4); @@ -1268,10 +1273,10 @@ public class CompleteParser2Tests extends BaseTestCase { public void testBug44342() throws Exception { IASTTranslationUnit tu = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); - assertEquals(col.size(), 10); + assertEquals(col.size(), 11); ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding(); ICPPMethod f1 = (ICPPMethod) col.getName(1).resolveBinding(); ICPPMethod f2 = (ICPPMethod) col.getName(2).resolveBinding(); @@ -1279,7 +1284,7 @@ public class CompleteParser2Tests extends BaseTestCase { ICPPConstructor ctor = A.getConstructors()[0]; IVariable a = (IVariable) col.getName(6).resolveBinding(); - assertInstances(col, A, 2); + assertInstances(col, A, 3); assertInstances(col, f1, 2); assertInstances(col, f2, 1); assertInstances(col, ctor, 1); @@ -1420,23 +1425,23 @@ public class CompleteParser2Tests extends BaseTestCase { buffer.append("void main() { N::A * a = new N::A(); a->f(); } "); IASTTranslationUnit tu = parse(buffer.toString()); - CPPNameCollector col = new CPPNameCollector(); + CPPNameCollector col = new CPPNameCollector(true); tu.accept(col); - assertEquals(col.size(), 13); + assertEquals(col.size(), 14); ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding(); IFunction f = (IFunction) col.getName(1).resolveBinding(); ICPPClassType A = (ICPPClassType) col.getName(2).resolveBinding(); ICPPConstructor ctor = A.getConstructors()[0]; - IProblemBinding fp = (IProblemBinding) col.getName(12).resolveBinding(); + IProblemBinding fp = (IProblemBinding) col.getName(13).resolveBinding(); assertEquals(fp.getID(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND); assertInstances(col, N, 3); assertInstances(col, f, 1); - assertInstances(col, A, 3); - assertInstances(col, ctor, 2); + assertInstances(col, A, 5); + assertInstances(col, ctor, 1); } public void testBug43110() throws Exception { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java index 9d59cf1c8b2..ac21a5487f7 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2010 IBM Corporation and others. + * Copyright (c) 2002, 2013 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 @@ -8,6 +8,7 @@ * Contributors: * IBM Rational Software - Initial API and implementation * Markus Schorn (Wind River Systems) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -37,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.model.CProject; import org.eclipse.core.resources.IFile; @@ -296,8 +298,12 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { } IASTNode node = parse( code, startOffset, endOffset ); assertTrue( node instanceof IASTName ); - assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); IBinding binding = ((IASTName)node).resolveBinding(); + if (binding instanceof ICPPClassType) { + node = TestUtil.findImplicitName(node); + binding = ((IASTName)node).resolveBinding(); + } + assertTrue( binding instanceof ICPPMethod ); IName[] decls = null; switch( i ) { @@ -599,14 +605,15 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { int startIndex = code.indexOf( "new B" ) + 4; //$NON-NLS-1$ IASTNode node = parse( code, startIndex, startIndex + 1 ); + node = TestUtil.findImplicitName(node); assertTrue( node instanceof IASTName ); - assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPConstructor ); + assertTrue( ((IASTName) node).resolveBinding() instanceof ICPPConstructor ); assertEquals( ((IASTName)node).toString(), "B" ); //$NON-NLS-1$ IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "B" ); //$NON-NLS-1$ - assertEquals( ((ASTNode)decls[0]).getOffset(), 17); - assertEquals( ((ASTNode)decls[0]).getLength(), 1); + assertEquals( 17, ((ASTNode)decls[0]).getOffset() ); + assertEquals( 1, ((ASTNode)decls[0]).getLength() ); } public void testBug72712_2() throws Exception{ @@ -1111,8 +1118,9 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { int index = code.indexOf("Point(10)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 5, true ); + node = TestUtil.findImplicitName(node); assertTrue( node instanceof IASTName ); - assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPConstructor ); + assertTrue( ((IASTName) node).resolveBinding() instanceof ICPPConstructor ); assertEquals( ((IASTName)node).toString(), "Point" ); //$NON-NLS-1$ IName[] decls = getDeclarationOffTU((IASTName)node); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java new file mode 100644 index 00000000000..89ddc566e2f --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2013 Nathan Ridge. + * 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: + * Nathan Ridge - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.parser.tests.ast2; + +import org.eclipse.cdt.core.dom.ast.IASTImplicitName; +import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; + +public class TestUtil { + /** + * Searches the AST upward from the given starting node to find the + * nearest IASTImplicitNameOwner and returns its first implicit name, + * or null if it has no implicit names. + */ + public static IASTName findImplicitName(IASTNode node) { + while (node != null) { + if (node instanceof IASTImplicitNameOwner) { + IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) node).getImplicitNames(); + if (implicitNames != null && implicitNames.length > 0) { + return implicitNames[0]; + } + } + node = node.getParent(); + } + return null; + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index 978a6f18bd0..4490da93a26 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 Symbian Software Systems and others. + * Copyright (c) 2006, 2013 Symbian Software Systems 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 @@ -10,6 +10,7 @@ * IBM Corporation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -83,7 +84,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { super.tearDown(); } - protected IASTName findName(String section, int len) { + protected IASTName findName(String section, int len, boolean preferImplicitName) { if (len == 0) len= section.length(); for (int i = 0; i < strategy.getAstCount(); i++) { @@ -91,15 +92,27 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { final IASTNodeSelector nodeSelector = ast.getNodeSelector(null); final int offset = strategy.getAstSource(i).indexOf(section); if (offset >= 0) { - IASTName name= nodeSelector.findName(offset, len); - if (name == null) - name= nodeSelector.findImplicitName(offset, len); - return name; + if (preferImplicitName) { + return nodeSelector.findImplicitName(offset, len); + } else { + IASTName name= nodeSelector.findName(offset, len); + if (name == null) + name= nodeSelector.findImplicitName(offset, len); + return name; + } } } return null; } + + protected IASTName findName(String section, int len) { + return findName(section, len, false); + } + + protected IASTName findImplicitName(String section, int len) { + return findName(section, len, true); + } /** * Attempts to get an IBinding from the initial specified number of characters @@ -129,9 +142,37 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { assertInstance(binding, clazz, cs); return clazz.cast(binding); } + + /** + * Attempts to get an IBinding attached to an implicit name from the initial specified + * number of characters from the specified code fragment. Fails the test if + *
    + *
  • There is not a unique implicit name with the specified criteria + *
  • The binding associated with the implicit name is null or a problem binding + *
  • The binding is not an instance of the specified class + *
+ * @param section the code fragment to search for in the AST. The first occurrence of an identical section is used. + * @param len the length of the specified section to use as a name + * @param clazz an expected class type or interface that the binding should extend/implement + * @return the associated implicit name's binding + */ + protected T getBindingFromImplicitASTName(String section, int len, Class clazz, Class ... cs) { + if (len < 1) { + len= section.length()+len; + } + IASTName name= findImplicitName(section, len); + assertNotNull("Name not found for \"" + section + "\"", name); + assertEquals(section.substring(0, len), name.getRawSignature()); + + IBinding binding = name.resolveBinding(); + assertNotNull("No binding for " + name.getRawSignature(), binding); + assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); + assertInstance(binding, clazz, cs); + return clazz.cast(binding); + } /* - * @see IndexBindingResolutionTestBase#getBindingFromASTName(Class, String, int) + * @see IndexBindingResolutionTestBase#getBindingFromASTName(String, int, Class, Class ...) */ protected T getBindingFromASTName(String section, int len) { if (len <= 0) @@ -146,6 +187,23 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); return (T) binding; } + + /* + * @see IndexBindingResolutionTestBase#getBindingFromImplicitASTName(String, int, Class, Class ...) + */ + protected T getBindingFromImplicitASTName(String section, int len) { + if (len <= 0) + len += section.length(); + + IASTName name= findImplicitName(section, len); + assertNotNull("Name not found for \"" + section + "\"", name); + assertEquals(section.substring(0, len), name.getRawSignature()); + + IBinding binding = name.resolveBinding(); + assertNotNull("No binding for " + name.getRawSignature(), binding); + assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); + return (T) binding; + } /** * Attempts to verify that the resolved binding for a name is a problem binding. diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java index 2925bf8ffa3..082c99311a4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Symbian Software Systems and others. + * Copyright (c) 2007, 2013 Symbian Software Systems 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 @@ -9,6 +9,7 @@ * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -1490,9 +1491,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti assertFalse(b0 instanceof IIndexBinding); ICPPConstructor b1 = getBindingFromASTName("B(int x)", 1, ICPPConstructor.class); assertFalse(b1 instanceof IIndexBinding); - ICPPConstructor b2 = getBindingFromASTName("B(0)", 1, ICPPConstructor.class); - assertFalse(b2 instanceof IIndexBinding); - assertEquals(b1, b2); + ICPPClassType b2 = getBindingFromASTName("B(0)", 1, ICPPClassType.class); ICPPMethod b3 = getBindingFromASTName("m(0)", 1, ICPPMethod.class); assertFalse(b3 instanceof IIndexBinding); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index 57ffaefda0b..2c1033ffc30 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Symbian Software Systems and others. + * Copyright (c) 2007, 2013 Symbian Software Systems 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 @@ -300,7 +300,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // X xa= new X(); // } public void testUnindexedConstructorInstance() { - IBinding b0= getBindingFromASTName("X()", 4); + IBinding b0= getBindingFromImplicitASTName("X()", 4); assertInstance(b0, ICPPConstructor.class); } @@ -409,7 +409,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // assertEquals(3, _ctcs.length); // two implicit plus the constructor template IBinding b2= getBindingFromASTName("D(", 1); - IBinding b3= getBindingFromASTName("D(", 6); + IBinding b3= getBindingFromImplicitASTName("D(", 6); assertInstance(b2, ICPPClassTemplate.class); // *D*(5, 6) assertInstance(b2, ICPPClassType.class); // *D*(5, 6) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index a447998e76e..70ca109fd0e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 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 @@ -550,14 +550,6 @@ public class CPPSemantics { if (parent instanceof ICPPASTConstructorChainInitializer) { return true; } - if (parent instanceof ICPPASTNamedTypeSpecifier) { - parent= parent.getParent(); - if (parent instanceof IASTTypeId && parent.getParent() instanceof ICPPASTNewExpression) { - IASTDeclarator dtor = ((IASTTypeId) parent).getAbstractDeclarator(); - if (dtor != null && dtor.getPointerOperators().length == 0) - return true; - } - } return false; } @@ -3103,27 +3095,43 @@ public class CPPSemantics { return null; IType type = ((ICPPVariable) binding).getType(); - try { - type = SemanticUtil.getNestedType(type, TDEF | CVTYPE); - if (!(type instanceof ICPPClassType)) - return null; - if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownType || type instanceof ISemanticProblem) - return null; + type = SemanticUtil.getNestedType(type, TDEF | CVTYPE); + if (!(type instanceof ICPPClassType)) + return null; + if (type instanceof ICPPClassTemplate || type instanceof ICPPUnknownType || type instanceof ISemanticProblem) + return null; - final ICPPClassType classType = (ICPPClassType) type; + return findImplicitlyCalledConstructor((ICPPClassType) type, initializer, name); + } + + public static ICPPConstructor findImplicitlyCalledConstructor(ICPPASTNewExpression expr) { + IType type = getNestedType(expr.getExpressionType(), TDEF | REF | CVTYPE); + if (!(type instanceof IPointerType)) + return null; + type = ((IPointerType) type).getType(); + if (type instanceof ICPPClassType) { + return findImplicitlyCalledConstructor((ICPPClassType) type, + expr.getInitializer(), expr.getTypeId()); + } + return null; + } + + private static ICPPConstructor findImplicitlyCalledConstructor(ICPPClassType type, IASTInitializer initializer, + IASTNode typeId) { + try { if (initializer instanceof IASTEqualsInitializer) { // Copy initialization. IASTEqualsInitializer eqInit= (IASTEqualsInitializer) initializer; ICPPASTInitializerClause initClause = (ICPPASTInitializerClause) eqInit.getInitializerClause(); final ICPPEvaluation evaluation = initClause.getEvaluation(); - IType sourceType= evaluation.getTypeOrFunctionSet(name); - ValueCategory isLValue= evaluation.getValueCategory(name); + IType sourceType= evaluation.getTypeOrFunctionSet(typeId); + ValueCategory isLValue= evaluation.getValueCategory(typeId); if (sourceType != null) { Cost c; - if (calculateInheritanceDepth(sourceType, classType, name) >= 0) { - c = Conversions.copyInitializationOfClass(isLValue, sourceType, classType, false, name); + if (calculateInheritanceDepth(sourceType, type, typeId) >= 0) { + c = Conversions.copyInitializationOfClass(isLValue, sourceType, type, false, typeId); } else { - c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY, name); + c = Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY, typeId); } if (c.converts()) { ICPPFunction f = c.getUserDefinedConversion(); @@ -3136,7 +3144,7 @@ public class CPPSemantics { // List initialization. ICPPEvaluation eval= ((ICPPASTInitializerList) initializer).getEvaluation(); if (eval instanceof EvalInitList) { - Cost c= Conversions.listInitializationSequence((EvalInitList) eval, type, UDCMode.ALLOWED, true, name); + Cost c= Conversions.listInitializationSequence((EvalInitList) eval, type, UDCMode.ALLOWED, true, typeId); if (c.converts()) { ICPPFunction f = c.getUserDefinedConversion(); if (f instanceof ICPPConstructor) @@ -3145,35 +3153,22 @@ public class CPPSemantics { } } else if (initializer instanceof ICPPASTConstructorInitializer) { // Direct initialization. - return findImplicitlyCalledConstructor(classType, - (ICPPASTConstructorInitializer) initializer, name); + return findImplicitlyCalledConstructor(type, + (ICPPASTConstructorInitializer) initializer, typeId); } else if (initializer == null) { // Default initialization. - ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(classType, name); + ICPPConstructor[] ctors = ClassTypeHelper.getConstructors(type, typeId); for (ICPPConstructor ctor : ctors) { if (ctor.getRequiredArgumentCount() == 0) return ctor; } return null; } - } catch (DOMException e) { + } catch (DOMException e) { } - return null; + return null; } - public static ICPPConstructor findImplicitlyCalledConstructor(ICPPASTNewExpression expr) { - IType type = getNestedType(expr.getExpressionType(), TDEF | REF | CVTYPE); - if (!(type instanceof IPointerType)) - return null; - type = ((IPointerType) type).getType(); - IASTInitializer initializer = expr.getInitializer(); - if (type instanceof ICPPClassType && initializer instanceof ICPPASTConstructorInitializer) { - return findImplicitlyCalledConstructor((ICPPClassType) type, - (ICPPASTConstructorInitializer) initializer, expr.getTypeId()); - } - return null; - } - private static ICPPConstructor findImplicitlyCalledConstructor(ICPPClassType classType, ICPPASTConstructorInitializer initializer, IASTNode typeId) { final IASTInitializerClause[] arguments = initializer.getArguments(); From 7a5d9818fc4ebb77b60e543bfbe9178c7b5be23a Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 23 Jan 2013 09:09:03 -0800 Subject: [PATCH 12/42] Cosmetics. --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 419 +++++++++--------- .../tests/IndexCBindingResolutionBugs.java | 56 +-- 2 files changed, 238 insertions(+), 237 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 0a8e2de6c42..be0185273d1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; +import static org.eclipse.cdt.core.parser.ParserLanguage.C; import static org.eclipse.cdt.core.parser.ParserLanguage.CPP; import java.io.IOException; @@ -144,21 +145,21 @@ public class AST2Tests extends AST2BaseTest { private void parseAndCheckBindings() throws Exception { String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } protected IASTTranslationUnit parseAndCheckBindings(String code) throws Exception { - return parseAndCheckBindings(code, ParserLanguage.C); + return parseAndCheckBindings(code, C); } public void testBug75189() throws Exception { parseAndCheckBindings("struct A{};\n typedef int (*F) (struct A*);"); //$NON-NLS-1$ - parseAndCheckBindings("struct A{};\n typedef int (*F) (A*);", ParserLanguage.CPP); //$NON-NLS-1$ + parseAndCheckBindings("struct A{};\n typedef int (*F) (A*);", CPP); //$NON-NLS-1$ } public void testBug75340() throws Exception { - IASTTranslationUnit tu = parseAndCheckBindings("void f(int i = 0, int * p = 0);", ParserLanguage.CPP); //$NON-NLS-1$ + IASTTranslationUnit tu = parseAndCheckBindings("void f(int i = 0, int * p = 0);", CPP); //$NON-NLS-1$ IASTSimpleDeclaration sd = (IASTSimpleDeclaration) tu.getDeclarations()[0]; isParameterSignatureEqual(sd.getDeclarators()[0], "(int=0, int*=0)"); //$NON-NLS-1$ } @@ -190,7 +191,7 @@ public class AST2Tests extends AST2BaseTest { // int ((*zzz3)) (char); // int (*(zzz4)) (char); public void testBug40768() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); @@ -201,7 +202,7 @@ public class AST2Tests extends AST2BaseTest { // int z = x + y; // } public void testBasicFunction() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IScope globalScope = tu.getScope(); @@ -344,7 +345,7 @@ public class AST2Tests extends AST2BaseTest { // myS.x = 5; // } public void testSimpleStruct() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu @@ -530,7 +531,7 @@ public class AST2Tests extends AST2BaseTest { } public void testMultipleDeclarators() throws Exception { - IASTTranslationUnit tu = parse("int r, s;", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("int r, s;", C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -568,7 +569,7 @@ public class AST2Tests extends AST2BaseTest { buffer.append(" struct A * a; \n"); //$NON-NLS-1$ buffer.append("} \n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); + IASTTranslationUnit tu = parse(buffer.toString(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -647,7 +648,7 @@ public class AST2Tests extends AST2BaseTest { buffer.append(" struct A * a; \n"); //$NON-NLS-1$ buffer.append("} \r\n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); + IASTTranslationUnit tu = parse(buffer.toString(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -712,7 +713,7 @@ public class AST2Tests extends AST2BaseTest { buffer.append(" a->i; \n"); //$NON-NLS-1$ buffer.append("} \n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); + IASTTranslationUnit tu = parse(buffer.toString(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -818,7 +819,7 @@ public class AST2Tests extends AST2BaseTest { // struct x i; // } public void testStructureNamespace() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -906,7 +907,7 @@ public class AST2Tests extends AST2BaseTest { // } public void testFunctionParameters() throws Exception { final String code = getAboveComment(); - IASTTranslationUnit tu = parse(code, ParserLanguage.C); + IASTTranslationUnit tu = parse(code, C); assertTrue(tu.isFrozen()); // void f( @@ -947,7 +948,7 @@ public class AST2Tests extends AST2BaseTest { assertSame(param_2, param_3); assertSame(f_1, f_2); - tu = parse(code, ParserLanguage.C); + tu = parse(code, C); assertTrue(tu.isFrozen()); // void f( f_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1011,7 +1012,7 @@ public class AST2Tests extends AST2BaseTest { // void f(int a, int b) { } public void testSimpleFunction() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTFunctionDefinition fDef = (IASTFunctionDefinition) tu.getDeclarations()[0]; @@ -1061,7 +1062,7 @@ public class AST2Tests extends AST2BaseTest { // } // void f() { } public void testSimpleFunctionCall() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -1130,7 +1131,7 @@ public class AST2Tests extends AST2BaseTest { // } // } public void testForLoop() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { // void f() { @@ -1204,7 +1205,7 @@ public class AST2Tests extends AST2BaseTest { // ((struct A *) 1)->x; // } public void testExpressionFieldReference() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1259,7 +1260,7 @@ public class AST2Tests extends AST2BaseTest { // end: ; // } public void testLabels() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector collector = new CNameCollector(); @@ -1294,7 +1295,7 @@ public class AST2Tests extends AST2BaseTest { // typedef struct { } X; // int f(X x); public void testAnonStruct() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { // test tu.getDeclarationsInAST(IBinding) @@ -1329,7 +1330,7 @@ public class AST2Tests extends AST2BaseTest { } public void testLongLong() throws ParserException { - IASTTranslationUnit tu = parse("long long x;\n", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("long long x;\n", C); //$NON-NLS-1$ // test tu.getDeclarationsInAST(IBinding) IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu @@ -1350,7 +1351,7 @@ public class AST2Tests extends AST2BaseTest { // return; // } public void testEnumerations() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1489,7 +1490,7 @@ public class AST2Tests extends AST2BaseTest { } public void testPointerToFunction() throws Exception { - IASTTranslationUnit tu = parse("int (*pfi)();", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("int (*pfi)();", C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { assertEquals(tu.getDeclarations().length, 1); @@ -1520,7 +1521,7 @@ public class AST2Tests extends AST2BaseTest { // const char ** e; // const char * const * const volatile ** const * f; public void testBasicTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu @@ -1623,7 +1624,7 @@ public class AST2Tests extends AST2BaseTest { // unsigned int unsignedInt = 99; // noSpec= 12; public void testBug270275_int_is_equivalent_to_signed_int() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); IASTDeclaration[] declarations = tu.getDeclarations(); IType plainInt = ((IVariable)((IASTSimpleDeclaration) declarations[0]).getDeclarators()[0].getName().resolveBinding()).getType(); IType signedInt = ((IVariable)((IASTSimpleDeclaration) declarations[1]).getDeclarators()[0].getName().resolveBinding()).getType(); @@ -1640,7 +1641,7 @@ public class AST2Tests extends AST2BaseTest { // struct A * const a2; // AP a3; public void testCompositeTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1717,7 +1718,7 @@ public class AST2Tests extends AST2BaseTest { // const char * const c[][][]; // char* d[const][]; public void testArrayTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1798,7 +1799,7 @@ public class AST2Tests extends AST2BaseTest { // void (*g) (struct A *); // void (* (*h)(struct A**)) (int d); public void testFunctionTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -1935,7 +1936,7 @@ public class AST2Tests extends AST2BaseTest { // Point point = {.width = 100, .pos = &xy}; // } public void testDesignatedInitializers() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { assertNotNull(tu); @@ -2041,7 +2042,7 @@ public class AST2Tests extends AST2BaseTest { // struct S s = {.a=1,.b=2}; // } public void testMoregetDeclarationsInAST1() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2081,7 +2082,7 @@ public class AST2Tests extends AST2BaseTest { // int b; // } s = {.a=1,.b=2}; public void testMoregetDeclarationsInAST2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2122,7 +2123,7 @@ public class AST2Tests extends AST2BaseTest { // typedef t y; // y x = {.a=1,.b=2}; public void testMoregetDeclarationsInAST3() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration S_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2158,7 +2159,7 @@ public class AST2Tests extends AST2BaseTest { public void testFnReturningPtrToFn() throws Exception { IASTTranslationUnit tu = parse( - "void (* f(int))() {}", ParserLanguage.C); //$NON-NLS-1$ + "void (* f(int))() {}", C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0]; @@ -2186,7 +2187,7 @@ public class AST2Tests extends AST2BaseTest { // array type derivation. public void testArrayTypeToQualifiedPointerTypeParm() throws Exception { IASTTranslationUnit tu = parse( - "void f(int parm[const 3]);", ParserLanguage.C); //$NON-NLS-1$ + "void f(int parm[const 3]);", C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration def = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2225,7 +2226,7 @@ public class AST2Tests extends AST2BaseTest { // int *f2() {} // int (* f3())() {} public void testFunctionDefTypes() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -2268,7 +2269,7 @@ public class AST2Tests extends AST2BaseTest { // any parameter to type function returning T is adjusted to be pointer to // function returning T public void testParmToFunction() throws Exception { - IASTTranslationUnit tu = parse("int f(int g(void)) { return g();}", ParserLanguage.C); + IASTTranslationUnit tu = parse("int f(int g(void)) { return g();}", C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0]; @@ -2304,7 +2305,7 @@ public class AST2Tests extends AST2BaseTest { } public void testArrayPointerFunction() throws Exception { - IASTTranslationUnit tu = parse("int (*v[])(int *x, int *y);", ParserLanguage.C); + IASTTranslationUnit tu = parse("int (*v[])(int *x, int *y);", C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -2349,7 +2350,7 @@ public class AST2Tests extends AST2BaseTest { // typedef DWORD v; // v signal(int); public void testTypedefExample4a() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -2404,7 +2405,7 @@ public class AST2Tests extends AST2BaseTest { // typedef DWORD (*pfv)(int); // pfv signal(int, pfv); public void testTypedefExample4b() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations()[0]; @@ -2486,7 +2487,7 @@ public class AST2Tests extends AST2BaseTest { // fv *signal2(int, fv *); // pfv signal3(int, pfv); public void testTypedefExample4c() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { @@ -2575,7 +2576,7 @@ public class AST2Tests extends AST2BaseTest { // int y [ const static x ]; public void testBug80992() throws Exception { ICASTArrayModifier mod = (ICASTArrayModifier) ((IASTArrayDeclarator) ((IASTSimpleDeclaration) parse( - getAboveComment(), ParserLanguage.C).getDeclarations()[1]) + getAboveComment(), C).getDeclarations()[1]) .getDeclarators()[0]).getArrayModifiers()[0]; assertTrue(mod.isConst()); assertTrue(mod.isStatic()); @@ -2588,7 +2589,7 @@ public class AST2Tests extends AST2BaseTest { // int y (int [ const *]); public void testBug80978() throws Exception { ICASTArrayModifier mod = (ICASTArrayModifier) ((IASTArrayDeclarator) ((IASTStandardFunctionDeclarator) ((IASTSimpleDeclaration) parse( - getAboveComment(), ParserLanguage.C).getDeclarations()[0]) + getAboveComment(), C).getDeclarations()[0]) .getDeclarators()[0]).getParameters()[0].getDeclarator()) .getArrayModifiers()[0]; assertTrue(mod.isConst()); @@ -2598,13 +2599,13 @@ public class AST2Tests extends AST2BaseTest { assertFalse(mod.isVolatile()); } - //AJN: bug 77383 don't do external variables + //AJN: bug 77383 don't do external variables // // void f() { // // if (a == 0) // // a = a + 3; // // } // public void testExternalVariable() throws Exception { - // IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + // IASTTranslationUnit tu = parse(getAboveComment(), C); // CNameCollector col = new CNameCollector(); // tu.accept(col); // @@ -2624,7 +2625,7 @@ public class AST2Tests extends AST2BaseTest { // g(*(&a + 2)); // } public void testExternalDefs() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -2649,7 +2650,7 @@ public class AST2Tests extends AST2BaseTest { // Coord xy = { .x = 10, .y = 11 }; // } public void testFieldDesignators() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -2674,7 +2675,7 @@ public class AST2Tests extends AST2BaseTest { // [member_two] = "two" // }; public void testArrayDesignator() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -2700,7 +2701,7 @@ public class AST2Tests extends AST2BaseTest { // g(*(&a + 2)); // } public void testBug83737() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { IASTIfStatement if_statement = (IASTIfStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) tu @@ -2730,7 +2731,7 @@ public class AST2Tests extends AST2BaseTest { // end: ; // } public void testBug84090_LabelReferences() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -2750,7 +2751,7 @@ public class AST2Tests extends AST2BaseTest { // enum col { red, blue }; // enum col c; public void testBug84092_EnumReferences() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector collector = new CNameCollector(); @@ -2769,7 +2770,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug84096_FieldDesignatorRef() throws Exception { IASTTranslationUnit tu = parse( - "struct s { int a; } ss = { .a = 1 }; \n", ParserLanguage.C); //$NON-NLS-1$ + "struct s { int a; } ss = { .a = 1 }; \n", C); //$NON-NLS-1$ assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector collector = new CNameCollector(); @@ -2789,7 +2790,7 @@ public class AST2Tests extends AST2BaseTest { public void testProblems() throws Exception { IASTTranslationUnit tu = parse( - " a += ;", ParserLanguage.C, true, false); //$NON-NLS-1$ + " a += ;", C, true, false); //$NON-NLS-1$ IASTProblem[] ps = CVisitor.getProblems(tu); assertEquals(ps.length, 1); ps[0].getMessage(); @@ -2798,7 +2799,7 @@ public class AST2Tests extends AST2BaseTest { // enum e; // enum e{ one }; public void testEnumerationForwards() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -2821,7 +2822,7 @@ public class AST2Tests extends AST2BaseTest { // (&p)[0] = 1; // } public void testBug84185() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -2840,7 +2841,7 @@ public class AST2Tests extends AST2BaseTest { // (&p)[0] = 1; // } public void testBug84185_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -2862,14 +2863,14 @@ public class AST2Tests extends AST2BaseTest { // p = &((struct s) { j++ }); // } public void testBug84176() throws Exception { - parse(getAboveComment(), ParserLanguage.C, false, true); + parse(getAboveComment(), C, false, true); } // struct s { double i; } f(void); // struct s f(void) {} public void testBug84266() throws Exception { final String code = getAboveComment(); - IASTTranslationUnit tu = parse(code, ParserLanguage.C); + IASTTranslationUnit tu = parse(code, C); CNameCollector col = new CNameCollector(); tu.accept(col); assertEquals(col.size(), 7); @@ -2878,7 +2879,7 @@ public class AST2Tests extends AST2BaseTest { ICompositeType s_decl = (ICompositeType) col.getName(0).resolveBinding(); assertSame(s_ref, s_decl); - tu = parse(code, ParserLanguage.C); + tu = parse(code, C); col = new CNameCollector(); tu.accept(col); assertEquals(col.size(), 7); @@ -2889,7 +2890,7 @@ public class AST2Tests extends AST2BaseTest { } public void testBug84266_2() throws Exception { - IASTTranslationUnit tu = parse("struct s f(void);", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("struct s f(void);", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); @@ -2898,7 +2899,7 @@ public class AST2Tests extends AST2BaseTest { ICompositeType s = (ICompositeType) col.getName(0).resolveBinding(); assertNotNull(s); - tu = parse("struct s f(void) {}", ParserLanguage.C); //$NON-NLS-1$ + tu = parse("struct s f(void) {}", C); //$NON-NLS-1$ col = new CNameCollector(); tu.accept(col); @@ -2910,7 +2911,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug84250() throws Exception { assertTrue(((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) parse( - "void f() { int (*p) [2]; }", ParserLanguage.C).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration); //$NON-NLS-1$ + "void f() { int (*p) [2]; }", C).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration); //$NON-NLS-1$ } // struct s1 { struct s2 *s2p; /* ... */ }; // D1 @@ -2945,7 +2946,7 @@ public class AST2Tests extends AST2BaseTest { // funcp()->a; // } public void testBug84267() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -2972,7 +2973,7 @@ public class AST2Tests extends AST2BaseTest { // { int x = x; } // } public void testBug84228() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -2998,7 +2999,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug84236() throws Exception { String code = "double maximum(double a[ ][*]);"; //$NON-NLS-1$ IASTSimpleDeclaration d = (IASTSimpleDeclaration) parse(code, - ParserLanguage.C).getDeclarations()[0]; + C).getDeclarations()[0]; IASTStandardFunctionDeclarator fd = (IASTStandardFunctionDeclarator) d .getDeclarators()[0]; IASTParameterDeclaration p = fd.getParameters()[0]; @@ -3013,7 +3014,7 @@ public class AST2Tests extends AST2BaseTest { // B * bp; //1 // } public void testBug85049() throws Exception { - IASTTranslationUnit t = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit t = parse(getAboveComment(), C); IASTFunctionDefinition g = (IASTFunctionDefinition) t.getDeclarations()[1]; IASTCompoundStatement body = (IASTCompoundStatement) g.getBody(); final IASTStatement statement = body.getStatements()[0]; @@ -3026,7 +3027,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug86766() throws Exception { IASTTranslationUnit tu = parse( - "char foo; void foo() {}", ParserLanguage.C); //$NON-NLS-1$ + "char foo; void foo() {}", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3039,7 +3040,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug88338_C() throws Exception { IASTTranslationUnit tu = parse( - "struct A; struct A* a;", ParserLanguage.C); //$NON-NLS-1$ + "struct A; struct A* a;", C); //$NON-NLS-1$ CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -3048,7 +3049,7 @@ public class AST2Tests extends AST2BaseTest { assertTrue(col.getName(1).isReference()); assertFalse(col.getName(1).isDeclaration()); - tu = parse("struct A* a; struct A;", ParserLanguage.C); //$NON-NLS-1$ + tu = parse("struct A* a; struct A;", C); //$NON-NLS-1$ col = new CPPNameCollector(); tu.accept(col); @@ -3062,7 +3063,7 @@ public class AST2Tests extends AST2BaseTest { } public void test88460() throws Exception { - IASTTranslationUnit tu = parse("void f();", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("void f();", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3072,7 +3073,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug90253() throws Exception { IASTTranslationUnit tu = parse( - "void f(int par) { int v1; };", ParserLanguage.C); //$NON-NLS-1$ + "void f(int par) { int v1; };", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3101,7 +3102,7 @@ public class AST2Tests extends AST2BaseTest { // } // } public void testFind() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3125,14 +3126,14 @@ public class AST2Tests extends AST2BaseTest { public void test92791() throws Exception { IASTTranslationUnit tu = parse( - "void f() { int x, y; x * y; }", ParserLanguage.C); //$NON-NLS-1$ + "void f() { int x, y; x * y; }", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); for (int i = 0; i < col.size(); ++i) assertFalse(col.getName(i).resolveBinding() instanceof IProblemBinding); tu = parse( - "int y; void f() { typedef int x; x * y; }", ParserLanguage.C); //$NON-NLS-1$ + "int y; void f() { typedef int x; x * y; }", C); //$NON-NLS-1$ col = new CNameCollector(); tu.accept(col); for (int i = 0; i < col.size(); ++i) @@ -3141,7 +3142,7 @@ public class AST2Tests extends AST2BaseTest { public void testBug85786() throws Exception { IASTTranslationUnit tu = parse( - "void f(int); void foo () { void * p = &f; ((void (*) (int)) p) (1); }", ParserLanguage.C); //$NON-NLS-1$ + "void f(int); void foo () { void * p = &f; ((void (*) (int)) p) (1); }", C); //$NON-NLS-1$ CNameCollector nameResolver = new CNameCollector(); tu.accept(nameResolver); assertNoProblemBindings(nameResolver); @@ -3153,7 +3154,7 @@ public class AST2Tests extends AST2BaseTest { // i= (i)&0x00ff; // } public void testBug95720() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); CNameCollector nameResolver = new CNameCollector(); tu.accept(nameResolver); assertNoProblemBindings(nameResolver); @@ -3168,7 +3169,7 @@ public class AST2Tests extends AST2BaseTest { // return 0; // } public void testBug94365() throws Exception { - parse(getAboveComment(), ParserLanguage.C); + parse(getAboveComment(), C); } // #define MACRO(a) @@ -3176,7 +3177,7 @@ public class AST2Tests extends AST2BaseTest { // MACRO('"'); // } public void testBug95119_a() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); IASTDeclaration[] declarations = tu.getDeclarations(); assertEquals(declarations.length, 1); assertNotNull(declarations[0]); @@ -3192,7 +3193,7 @@ public class AST2Tests extends AST2BaseTest { // MACRO('X'); // } public void testBug95119_b() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parse(getAboveComment(), C); IASTDeclaration[] declarations = tu.getDeclarations(); assertEquals(declarations.length, 1); assertNotNull(declarations[0]); @@ -3207,13 +3208,13 @@ public class AST2Tests extends AST2BaseTest { // typedef _TYPE TYPE; // int function(TYPE (* pfv)(int parm)); public void testBug81739() throws Exception { - parse(getAboveComment(), ParserLanguage.C); + parse(getAboveComment(), C); } // float _Complex x; // double _Complex y; public void testBug95757() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true, true); IASTDeclaration[] decls = tu.getDeclarations(); assertTrue(((ICASTSimpleDeclSpecifier)((IASTSimpleDeclaration) decls[0]).getDeclSpecifier()).isComplex()); @@ -3226,7 +3227,7 @@ public class AST2Tests extends AST2BaseTest { // typeof({ int x = foo(); // x; }) zoot; public void testBug93980() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3240,14 +3241,14 @@ public class AST2Tests extends AST2BaseTest { } public void testBug95866() throws Exception { - IASTTranslationUnit tu = parse("int test[10] = { [0 ... 9] = 2 };", ParserLanguage.C, true, true); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("int test[10] = { [0 ... 9] = 2 };", C, true, true); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); } public void testBug98502() throws Exception { - IASTTranslationUnit tu = parse("typedef enum { ONE } e;", ParserLanguage.C, true, true); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("typedef enum { ONE } e;", C, true, true); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3263,7 +3264,7 @@ public class AST2Tests extends AST2BaseTest { // PIPERR; // } public void testBug98365() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3272,7 +3273,7 @@ public class AST2Tests extends AST2BaseTest { } public void testBug99262() throws Exception { - parse("void foo() {void *f; f=__null;}", ParserLanguage.C, true, true); //$NON-NLS-1$ + parse("void foo() {void *f; f=__null;}", C, true, true); //$NON-NLS-1$ } // void f1(int*) { @@ -3280,7 +3281,7 @@ public class AST2Tests extends AST2BaseTest { // void f2() { // f1(__null); // } - public void testBug240567() throws Exception { + public void testBug240567() throws Exception { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), false); bh.assertNonProblem("f1(__null", 2, IFunction.class); } @@ -3290,7 +3291,7 @@ public class AST2Tests extends AST2BaseTest { // { a; int a; } // } public void testBug98960() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3303,7 +3304,7 @@ public class AST2Tests extends AST2BaseTest { } public void testBug100408() throws Exception { - IASTTranslationUnit tu = parse("int foo() { int x=1; (x)*3; }", ParserLanguage.C); //$NON-NLS-1$ + IASTTranslationUnit tu = parse("int foo() { int x=1; (x)*3; }", C); //$NON-NLS-1$ CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); @@ -3319,7 +3320,7 @@ public class AST2Tests extends AST2BaseTest { // { // } public void testBug98760() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3396,7 +3397,7 @@ public class AST2Tests extends AST2BaseTest { // blah: x; // } public void testBug104390_2() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, true); + IASTTranslationUnit tu = parse(getAboveComment(), C, true); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -3429,9 +3430,9 @@ public class AST2Tests extends AST2BaseTest { buffer.append("((int arg1)) {\r\n"); //$NON-NLS-1$ buffer.append("return 0;\r\n"); //$NON-NLS-1$ buffer.append("}\r\n"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C); + IASTTranslationUnit tu = parse(buffer.toString(), C); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - tu = parse(buffer.toString(), ParserLanguage.CPP); + tu = parse(buffer.toString(), CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); buffer = new StringBuffer(); @@ -3443,9 +3444,9 @@ public class AST2Tests extends AST2BaseTest { buffer.append("((int arg1)) {\n"); //$NON-NLS-1$ buffer.append("return 0;\n"); //$NON-NLS-1$ buffer.append("}\n"); //$NON-NLS-1$ - tu= parse(buffer.toString(), ParserLanguage.C); + tu= parse(buffer.toString(), C); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - tu= parse(buffer.toString(), ParserLanguage.CPP); + tu= parse(buffer.toString(), CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); } @@ -3459,10 +3460,10 @@ public class AST2Tests extends AST2BaseTest { buffer.append("((int arg1)) {\r\n"); //$NON-NLS-1$ buffer.append("return 0;\r\n"); //$NON-NLS-1$ buffer.append("}\r\n"); //$NON-NLS-1$ - IASTTranslationUnit tu= parse(buffer.toString(), ParserLanguage.C); + IASTTranslationUnit tu= parse(buffer.toString(), C); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - tu = parse(buffer.toString(), ParserLanguage.CPP); + tu = parse(buffer.toString(), CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); buffer = new StringBuffer(); @@ -3474,9 +3475,9 @@ public class AST2Tests extends AST2BaseTest { buffer.append("((int arg1)) {\n"); //$NON-NLS-1$ buffer.append("return 0;\n"); //$NON-NLS-1$ buffer.append("}\n"); //$NON-NLS-1$ - tu = parse(buffer.toString(), ParserLanguage.C); + tu = parse(buffer.toString(), C); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); - tu = parse(buffer.toString(), ParserLanguage.CPP); + tu = parse(buffer.toString(), CPP); assertFalse(tu.getDeclarations()[1] instanceof IASTProblemDeclaration); } @@ -3522,7 +3523,7 @@ public class AST2Tests extends AST2BaseTest { // return newWindow; // } public void testBug143502() throws Exception { - parse(getAboveComment(), ParserLanguage.C, true, false); + parse(getAboveComment(), C, true, false); } // void func(int a) { @@ -3537,13 +3538,13 @@ public class AST2Tests extends AST2BaseTest { // } public void testBracketAroundIdentifier_168924() throws IOException, ParserException { String content= getAboveComment(); - IASTTranslationUnit tu= parse(content, ParserLanguage.C, true, true); + IASTTranslationUnit tu= parse(content, C, true, true); IASTFunctionDefinition func= (IASTFunctionDefinition) tu.getDeclarations()[0]; IASTParameterDeclaration[] params= ((IASTStandardFunctionDeclarator) func.getDeclarator()).getParameters(); IBinding binding= params[0].getDeclarator().getName().resolveBinding(); assertEquals(7, tu.getReferences(binding).length); - tu= parse(content, ParserLanguage.CPP, true, true); + tu= parse(content, CPP, true, true); func= (IASTFunctionDefinition) tu.getDeclarations()[0]; params= ((IASTStandardFunctionDeclarator) func.getDeclarator()).getParameters(); binding= params[0].getDeclarator().getName().resolveBinding(); @@ -3555,7 +3556,7 @@ public class AST2Tests extends AST2BaseTest { // MAC("); // } public void testBug179383() throws ParserException, IOException { - parse(getAboveComment(), ParserLanguage.C, false, false); + parse(getAboveComment(), C, false, false); } /** @@ -3572,7 +3573,7 @@ public class AST2Tests extends AST2BaseTest { " return func(LIT); // fails to parse\r\n" + "}\r\n"; - IASTTranslationUnit tu = parse(simple, ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(simple, CPP, true, true); // actual reduced test case, plus extra cases String text = @@ -3594,7 +3595,7 @@ public class AST2Tests extends AST2BaseTest { ; // essential test: this code should be parseable - tu = parse(text, ParserLanguage.CPP, true, true); + tu = parse(text, CPP, true, true); // verify macros IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions(); @@ -3692,11 +3693,11 @@ public class AST2Tests extends AST2BaseTest { // this should work String textNoComment = noCommentMacro + textTail; - IASTTranslationUnit tu = parse(textNoComment, ParserLanguage.CPP, true, true); + IASTTranslationUnit tu = parse(textNoComment, CPP, true, true); // this fails String textComment = commentMacro + textTail; - tu = parse(textComment, ParserLanguage.CPP, true, true); + tu = parse(textComment, CPP, true, true); } @@ -3716,7 +3717,7 @@ public class AST2Tests extends AST2BaseTest { " } \n" + "}\n"; - parseAndCheckBindings(code, ParserLanguage.C); + parseAndCheckBindings(code, C); } // template @@ -3744,7 +3745,7 @@ public class AST2Tests extends AST2BaseTest { // } // }; public void test186736() throws Exception { - IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), CPP); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -3796,7 +3797,7 @@ public class AST2Tests extends AST2BaseTest { // } // }; public void test186736_variant1() throws Exception { - IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), CPP); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -3834,7 +3835,7 @@ public class AST2Tests extends AST2BaseTest { // (&a)->foo(); // } public void test186736_variant2() throws Exception { - IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), CPP); validateCopy(tu); } @@ -3843,8 +3844,8 @@ public class AST2Tests extends AST2BaseTest { // return *p; // } public void test167833() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); - parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + parseAndCheckBindings(getAboveComment(), CPP); + parseAndCheckBindings(getAboveComment(), C); } // // this is a \ @@ -3885,7 +3886,7 @@ public class AST2Tests extends AST2BaseTest { final IBinding typedef = col.getName(12).resolveBinding(); final IBinding secondJ = col.getName(13).resolveBinding(); assertInstance(typedef, ITypedef.class); - if (lang == ParserLanguage.CPP) { + if (lang == CPP) { assertInstance(secondJ, IProblemBinding.class); } else { // for plain C this is actually not a problem, the second J has to be interpreted as a (useless) @@ -3901,8 +3902,8 @@ public class AST2Tests extends AST2BaseTest { // INVALID(1, 2) // public void test192639() throws Exception { - parse(getAboveComment(), ParserLanguage.CPP, false, false); - parse(getAboveComment(), ParserLanguage.C, false, false); + parse(getAboveComment(), CPP, false, false); + parse(getAboveComment(), C, false, false); } public void test195943() throws Exception { @@ -3914,19 +3915,19 @@ public class AST2Tests extends AST2BaseTest { } buffer.append("int a= M" + (depth-1) + ";\n"); long time= System.currentTimeMillis(); - parse(buffer.toString(), ParserLanguage.CPP); - parse(buffer.toString(), ParserLanguage.C); + parse(buffer.toString(), CPP); + parse(buffer.toString(), C); assertTrue(System.currentTimeMillis()-time < 2000); } // int array[12]= {}; public void testBug196468_emptyArrayInitializer() throws Exception { final String content = getAboveComment(); - parse(content, ParserLanguage.CPP, false); - parse(content, ParserLanguage.CPP, true); - parse(content, ParserLanguage.C, true); + parse(content, CPP, false); + parse(content, CPP, true); + parse(content, C, true); try { - parse(content, ParserLanguage.C, false); + parse(content, C, false); fail("C89 does not allow empty braces in array initializer"); } catch (ParserException e) { @@ -3945,16 +3946,16 @@ public class AST2Tests extends AST2BaseTest { // } public void testBug197633_parenthesisInVarargMacros() throws Exception { final String content = getAboveComment(); - parse(content, ParserLanguage.CPP); - parse(content, ParserLanguage.C); + parse(content, CPP); + parse(content, C); } // void (__attribute__((__stdcall__))* foo1) (int); // void (* __attribute__((__stdcall__)) foo2) (int); // void (* __attribute__((__stdcall__))* foo3) (int); public void testBug191450_attributesInBetweenPointers() throws Exception { - parse(getAboveComment(), ParserLanguage.CPP, true, true); - parse(getAboveComment(), ParserLanguage.C, true, true); + parse(getAboveComment(), CPP, true, true); + parse(getAboveComment(), C, true, true); } // class NameClash {}; @@ -3962,7 +3963,7 @@ public class AST2Tests extends AST2BaseTest { // namespace NameClash2 {}; // class NameClash2 {}; public void testBug202271_nameClash() throws Exception { - IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); + IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment(), CPP, true); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -3982,7 +3983,7 @@ public class AST2Tests extends AST2BaseTest { // int b= WRAP(MACRO); public void testBug94673_refsForMacrosAsArguments() throws Exception { String content= getAboveComment(); - IASTTranslationUnit tu= parseAndCheckBindings(content, ParserLanguage.CPP, true); + IASTTranslationUnit tu= parseAndCheckBindings(content, CPP, true); IASTPreprocessorMacroDefinition[] defs= tu.getMacroDefinitions(); assertEquals(2, defs.length); IASTPreprocessorMacroDefinition md= defs[1]; @@ -4041,10 +4042,10 @@ public class AST2Tests extends AST2BaseTest { CharSequence[] buffer = getContents(2); final String content1 = buffer[0].toString(); final String content2 = buffer[1].toString(); - parse(content1, ParserLanguage.CPP); - parse(content1, ParserLanguage.C); - parse(content2, ParserLanguage.CPP); - parse(content2, ParserLanguage.C); + parse(content1, CPP); + parse(content1, C); + parse(content2, CPP); + parse(content2, C); } @@ -4065,14 +4066,14 @@ public class AST2Tests extends AST2BaseTest { // // int foo() { // Point p1 = {.x = 1, .y = 2}; - // + // // Line l1 = {.p1 = {.x = 1, .y = 2}, {.x = 1, .y = 2}, {.tag = 5}}; // Line l2 = {.t.tag = 9, .p1.x = 1, .p2.x = 3, .p1.y = 4, .p2.y = 9}; // // Point points[] = {{.x=1, .y=1}, {.x=2, .y=2}}; // } public void _testBug210019_nestedDesignatedInitializers() throws Exception { - IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), C); CNameCollector col = new CNameCollector(); tu.accept(col); @@ -4150,7 +4151,7 @@ public class AST2Tests extends AST2BaseTest { // 3, 4 // }; public void testBug210019_designatedInitializers() throws Exception { - IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), C); assertTrue(tu.isFrozen()); for (int i = 0; i < NUM_TESTS; i++) { CNameCollector col = new CNameCollector(); @@ -4189,7 +4190,7 @@ public class AST2Tests extends AST2BaseTest { // externFunc(); // } public void testBug183126_nestedLinkageSpecs() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP); + parseAndCheckBindings(getAboveComment(), CPP); } // int* i= 0; @@ -4203,7 +4204,7 @@ public class AST2Tests extends AST2BaseTest { // f3(&i); // ok // } public void testBug213029_cvConversion() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, false); + IASTTranslationUnit tu = parse(getAboveComment(), CPP, false); CNameCollector col = new CNameCollector(); tu.accept(col); for (Object o : col.nameList) { @@ -4694,8 +4695,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testOmittedPositiveExpression_212905() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // #define __inline__ __inline__ __attribute__((always_inline)) @@ -4705,16 +4706,16 @@ public class AST2Tests extends AST2BaseTest { // } public void testRedefinedGCCKeywords_226112() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // int foo asm ("myfoo") __attribute__((__used__)), ff asm("ss") = 2; // extern void func () asm ("FUNC") __attribute__((__used__)); public void testASMLabels_226121() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test() { @@ -4722,8 +4723,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testCompoundStatementExpression_226274() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test(int count) { @@ -4732,8 +4733,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testTypeofUnaryExpression_226492() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test(int count) { @@ -4741,8 +4742,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testTypeofExpression_226492() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void func() { @@ -4750,8 +4751,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testTypeofExpressionWithAttribute_226492() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test(int count) { @@ -4762,7 +4763,7 @@ public class AST2Tests extends AST2BaseTest { public void testCaseRange_211882() throws Exception { final String code = getAboveComment(); { - IASTTranslationUnit tu = parseAndCheckBindings(code, ParserLanguage.C, true); + IASTTranslationUnit tu = parseAndCheckBindings(code, C, true); IASTCompoundStatement body = (IASTCompoundStatement)((IASTFunctionDefinition) tu.getDeclarations()[0]).getBody(); IASTSwitchStatement switchStmt = (IASTSwitchStatement) body.getStatements()[0]; IASTCaseStatement caseStmt = (IASTCaseStatement)((IASTCompoundStatement) switchStmt.getBody()).getStatements()[0]; @@ -4772,7 +4773,7 @@ public class AST2Tests extends AST2BaseTest { assertTrue(binExpr.getOperand2() instanceof IASTLiteralExpression); } { - IASTTranslationUnit tu = parseAndCheckBindings(code, ParserLanguage.CPP, true); + IASTTranslationUnit tu = parseAndCheckBindings(code, CPP, true); IASTCompoundStatement body = (IASTCompoundStatement)((IASTFunctionDefinition) tu.getDeclarations()[0]).getBody(); IASTSwitchStatement switchStmt = (IASTSwitchStatement) body.getStatements()[0]; IASTCaseStatement caseStmt = (IASTCaseStatement)((IASTCompoundStatement) switchStmt.getBody()).getStatements()[0]; @@ -4788,8 +4789,8 @@ public class AST2Tests extends AST2BaseTest { // int x(int(TIntPtr)); public void testInfiniteRecursion_269052() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // template class X { @@ -4799,29 +4800,29 @@ public class AST2Tests extends AST2BaseTest { // }; public void testTypenameInExpression() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, CPP); } // struct __attribute__((declspec)) bla; public void testAttributeInElaboratedTypeSpecifier_227085() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // struct X; // void test(struct X* __restrict result); public void testRestrictReference_227110() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, CPP, true); } // char buf[256]; // int x= sizeof(buf)[0]; public void testSizeofUnaryWithParenthesis_227122() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // class X { @@ -4835,7 +4836,7 @@ public class AST2Tests extends AST2BaseTest { // } public void testPlacementNewInConditionalExpression_227104() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, CPP); } // int f(x) { @@ -4843,7 +4844,7 @@ public class AST2Tests extends AST2BaseTest { // } public void testBug228422_noKnrParam() throws Exception { CharSequence buffer = getContents(1)[0]; - parse(buffer.toString(), ParserLanguage.C, false); + parse(buffer.toString(), C, false); } // struct { @@ -4896,8 +4897,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testTypeOfPointerOperations() throws Exception { String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // int globalArray[4] = {1,2,3,4}; @@ -4960,8 +4961,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testReturnTypeOfBuiltin_234309() throws Exception { String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // typedef void VOID; @@ -5490,7 +5491,7 @@ public class AST2Tests extends AST2BaseTest { // spinlock_t _lock = (spinlock_t) { }; public void testCompoundInitializer_145387() throws Exception { // valid in C99, not in C++. - parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); + parseAndCheckBindings(getAboveComment(), C, true); } // enum __declspec(uuid("uuid")) bla { a, b}; @@ -5534,8 +5535,8 @@ public class AST2Tests extends AST2BaseTest { // alloc(__func__); // } public void testPredefinedFunctionName_247747() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.C, false); - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, false); + parseAndCheckBindings(getAboveComment(), C, false); + parseAndCheckBindings(getAboveComment(), CPP, false); } // void alloc(const char * id) {} @@ -5545,16 +5546,16 @@ public class AST2Tests extends AST2BaseTest { // alloc(__PRETTY_FUNCTION__); // } public void testPredefinedFunctionNameGcc_247747() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); + parseAndCheckBindings(getAboveComment(), C, true); + parseAndCheckBindings(getAboveComment(), CPP, true); } // int foo = 42; // typedef char StupidType; // StupidType const *bar = (StupidType const*)&foo; public void testUnusualDeclSpecOrdering_251514() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); - parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); + parseAndCheckBindings(getAboveComment(), C, true); + parseAndCheckBindings(getAboveComment(), CPP, true); } // #define IF if @@ -5872,7 +5873,7 @@ public class AST2Tests extends AST2BaseTest { // {1,2,3}, // 1.2, // { - + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // } @@ -5978,8 +5979,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testNestedDeclarator_257540() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // typedef struct { @@ -5992,8 +5993,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testCompoundLiterals_258496() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // __thread int i; @@ -6001,8 +6002,8 @@ public class AST2Tests extends AST2BaseTest { // extern __thread int k; public void testThreadLocalVariables_260387() throws Exception { final String code= getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test() { @@ -6027,7 +6028,7 @@ public class AST2Tests extends AST2BaseTest { // }; public void testAmbiguousDeclaration_259373() throws Exception { final String code= getAboveComment(); - IASTTranslationUnit tu= parseAndCheckBindings(code, ParserLanguage.C, true); + IASTTranslationUnit tu= parseAndCheckBindings(code, C, true); BindingAssertionHelper bh= new BindingAssertionHelper(code, false); ITypedef td= bh.assertNonProblem("TInt; //", 4); IField f= bh.assertNonProblem("a;", 1); @@ -6062,7 +6063,7 @@ public class AST2Tests extends AST2BaseTest { for (ParserLanguage lang : ParserLanguage.values()) { IASTTranslationUnit tu= parseAndCheckBindings(code, lang, true); - BindingAssertionHelper ba= new BindingAssertionHelper(code, lang == ParserLanguage.CPP); + BindingAssertionHelper ba= new BindingAssertionHelper(code, lang == CPP); ITypedef t= ba.assertNonProblem("A;", 1); ICompositeType s1= ba.assertNonProblem("A; // struct", 1); ICompositeType s2= ba.assertNonProblem("A*", 1); @@ -6072,7 +6073,7 @@ public class AST2Tests extends AST2BaseTest { } // typedef long unsigned int size_t; - // + // // size_t a = 0; // size_t x = a + 5; // size_t y = 2 + a; @@ -6095,7 +6096,7 @@ public class AST2Tests extends AST2BaseTest { // typedef void* VoidPtr; // typedef VoidPtr (*Func)(); - // + // // void test(Func f) { // f(); // } @@ -6127,7 +6128,7 @@ public class AST2Tests extends AST2BaseTest { public void testSizeofFunctionType_252243() throws Exception { final String code= getAboveComment(); for (ParserLanguage lang : ParserLanguage.values()) { - BindingAssertionHelper ba= new BindingAssertionHelper(code, lang == ParserLanguage.CPP); + BindingAssertionHelper ba= new BindingAssertionHelper(code, lang == CPP); ba.assertProblem("y));", 1); IVariable v= ba.assertNonProblem("y);", 1); } @@ -6341,7 +6342,7 @@ public class AST2Tests extends AST2BaseTest { // __TIME__; // } public void testPredefinedMacroNamesC() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + parseAndCheckBindings(getAboveComment(), C); } // long double longDouble = 1.0; @@ -6872,7 +6873,7 @@ public class AST2Tests extends AST2BaseTest { // int MyGlobal[10]; // public void testBug273797() throws Exception { - IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), C); IASTName n = ((IASTSimpleDeclaration) tu.getDeclarations()[0]).getDeclarators()[0].getName(); IVariable v = (IVariable) n.resolveBinding(); @@ -6894,7 +6895,7 @@ public class AST2Tests extends AST2BaseTest { // (int) value1; // } public void testBug278797() throws Exception { - IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.C); + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), C); IASTFunctionDefinition func = (IASTFunctionDefinition) tu.getDeclarations()[1]; IASTExpressionStatement stmt = ((IASTExpressionStatement)((IASTCompoundStatement) func.getBody()).getStatements()[0]); IType t = ((IASTCastExpression) stmt.getExpression()).getOperand().getExpressionType(); @@ -6994,7 +6995,7 @@ public class AST2Tests extends AST2BaseTest { // structure.ptr = goo; // } public void testBindingsOnFields() throws Exception { - IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, false); + IASTTranslationUnit tu = parse(getAboveComment(), C, false); IASTCompoundStatement bodyStmt = (IASTCompoundStatement)((IASTFunctionDefinition) tu.getDeclarations()[2]).getBody(); // Get the IFields bindings from the type used in the declaration of structure @@ -7006,7 +7007,7 @@ public class AST2Tests extends AST2BaseTest { // Get the IField for the first assignment IASTFieldReference ref1 = (IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement) bodyStmt.getStatements()[1]).getExpression()).getOperand1(); IBinding field1 = ref1.getFieldName().resolveBinding(); - + // Get the IField for the second assignment IASTFieldReference ref2 = (IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement) bodyStmt.getStatements()[2]).getExpression()).getOperand1(); IBinding field2 = ref2.getFieldName().resolveBinding(); @@ -7014,7 +7015,7 @@ public class AST2Tests extends AST2BaseTest { // Compare the IField from the type and the assignments assertEquals(fields[0], field1); assertEquals(fields[1], field2); // fails - + assertEquals(1, ((ICInternalBinding) field1).getDeclarations().length); assertEquals(1, ((ICInternalBinding) field2).getDeclarations().length); } @@ -7092,8 +7093,8 @@ public class AST2Tests extends AST2BaseTest { // int a[1]; public void testIncompleteArrays_269926() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C); - parseAndCheckBindings(code, ParserLanguage.CPP); + parseAndCheckBindings(code, C); + parseAndCheckBindings(code, CPP); } // void f1(const int* p); @@ -7146,7 +7147,7 @@ public class AST2Tests extends AST2BaseTest { // static a[2]= {0,0}; public void testSkipAggregateInitializer_297550() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, false, true); + parseAndCheckBindings(code, C, false, true); } // typeof(b(1)) b(int); @@ -7187,8 +7188,8 @@ public class AST2Tests extends AST2BaseTest { // void f () __attribute__ ((int)); public void testAttributeSyntax_298841() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void func(int* obj) { @@ -7211,7 +7212,7 @@ public class AST2Tests extends AST2BaseTest { // ONCE() public void testPragmaOperator_294730() throws Exception { final String code = getAboveComment(); - IASTTranslationUnit tu= parseAndCheckBindings(code, ParserLanguage.C); + IASTTranslationUnit tu= parseAndCheckBindings(code, C); IASTPreprocessorStatement[] stmts = tu.getAllPreprocessorStatements(); assertEquals(5, stmts.length); for (int i = 2; i < stmts.length; i++) { @@ -7219,7 +7220,7 @@ public class AST2Tests extends AST2BaseTest { assertInstance(stmt, IASTPreprocessorPragmaStatement.class); assertEquals(i>2, ((IASTPreprocessorPragmaStatement) stmt).isPragmaOperator()); } - tu= parseAndCheckBindings(code, ParserLanguage.CPP); + tu= parseAndCheckBindings(code, CPP); assertEquals(5, stmts.length); for (int i = 2; i < stmts.length; i++) { IASTPreprocessorStatement stmt = stmts[i]; @@ -7234,8 +7235,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testFunctionNameExpression() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // #define MACRO @@ -7264,8 +7265,8 @@ public class AST2Tests extends AST2BaseTest { // } public void testVaArgWithFunctionPtr_311030() throws Exception { final String code = getAboveComment(); - parseAndCheckBindings(code, ParserLanguage.C, true); - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, C, true); + parseAndCheckBindings(code, CPP, true); } // void test() { @@ -7308,7 +7309,7 @@ public class AST2Tests extends AST2BaseTest { public void testPtrDiffRecursion_317004() throws Exception { final String comment = getAboveComment(); String code= comment; - parseAndCheckBindings(code, ParserLanguage.C, true); + parseAndCheckBindings(code, C, true); BindingAssertionHelper bh= new BindingAssertionHelper(code, false); ITypedef td= bh.assertNonProblem("ptrdiff_t", 0); assertEquals("int", ASTTypeUtil.getType(td.getType())); @@ -7316,7 +7317,7 @@ public class AST2Tests extends AST2BaseTest { assertEquals("unsigned long int", ASTTypeUtil.getType(td.getType())); code= "namespace std {" + comment + "}"; - parseAndCheckBindings(code, ParserLanguage.CPP, true); + parseAndCheckBindings(code, CPP, true); bh= new BindingAssertionHelper(code, true); td= bh.assertNonProblem("ptrdiff_t", 0); assertEquals("int", ASTTypeUtil.getType(td.getType())); @@ -7365,14 +7366,14 @@ public class AST2Tests extends AST2BaseTest { // } public void testTypeOfSizeof_355052() throws Exception { final String code = getAboveComment(); - IASTTranslationUnit tu= parseAndCheckBindings(code, ParserLanguage.CPP); + IASTTranslationUnit tu= parseAndCheckBindings(code, CPP); IASTFunctionDefinition a= getDeclaration(tu, 0); IASTExpressionStatement es= getStatement(a, 1); assertEquals("unsigned long int", ASTTypeUtil.getType(es.getExpression().getExpressionType())); es= getStatement(a, 2); assertEquals("unsigned long int", ASTTypeUtil.getType(es.getExpression().getExpressionType())); - tu= parseAndCheckBindings(code, ParserLanguage.C); + tu= parseAndCheckBindings(code, C); a= getDeclaration(tu, 0); es= getStatement(a, 1); assertEquals("unsigned long int", ASTTypeUtil.getType(es.getExpression().getExpressionType())); @@ -7420,9 +7421,9 @@ public class AST2Tests extends AST2BaseTest { public void testGCCDecltype_397227() throws Exception { parseAndCheckBindings(getAboveComment(), CPP, true); } - + // #define macro(R) #R"" public void testNoRawStringInPlainC_397127() throws Exception { - parseAndCheckBindings(getAboveComment(), ParserLanguage.C, true); + parseAndCheckBindings(getAboveComment(), C, true); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java index c2210a5712e..1f4f785bdde 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java @@ -42,20 +42,20 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase public ProjectWithDepProj() { setStrategy(new ReferencedProject(false)); } public static TestSuite suite() { return suite(ProjectWithDepProj.class); } } - - public static void addTests(TestSuite suite) { + + public static void addTests(TestSuite suite) { suite.addTest(SingleProject.suite()); suite.addTest(ProjectWithDepProj.suite()); } - // #include + // #include // void func1(void) { // int i = 0; // for (i=0; i<10;i++) { // printf("%i", i); // } // } - + // #include "header.h" // // int main(void) { @@ -77,7 +77,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase } // void func1(void); - + // #include "header.h" // // int main(void) { @@ -87,7 +87,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase IBinding b0 = getBindingFromASTName("func1;", 5); assertTrue(b0 instanceof IFunction); } - + // typedef struct { // int utm; // } usertype; @@ -132,7 +132,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertInstance(type, IEnumeration.class); assertTrue(type instanceof IEnumeration); } - + // int globalVar; // // don't include header @@ -268,10 +268,10 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase e= (IEnumeration) b1; ei= e.getEnumerators(); assertEquals(1, ei.length); - } + } // // no header needed - + // typedef struct { // int member; // } t_struct; @@ -289,7 +289,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + IType tAST= ((ITypedef) tdAST).getType(); IType tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof ICompositeType); @@ -304,7 +304,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + tAST= ((ITypedef) tdAST).getType(); tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof ICompositeType); @@ -319,7 +319,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(tdIndex instanceof IIndexBinding); assertTrue(tdAST instanceof ITypedef); assertTrue(tdIndex instanceof ITypedef); - + tAST= ((ITypedef) tdAST).getType(); tIndex= ((ITypedef) tdIndex).getType(); assertTrue(tAST instanceof IEnumeration); @@ -327,13 +327,13 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(tAST.isSameType(tIndex)); assertTrue(tIndex.isSameType(tAST)); } - + // struct outer { // union { // int var1; // }; // }; - + // #include "header.h" // void test() { // struct outer x; @@ -354,7 +354,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase // int var1; // }; // }; - + // #include "header.h" // void test() { // union outer x; @@ -369,14 +369,14 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(outer instanceof ICCompositeTypeScope); assertEquals("outer", outer.getScopeName().toString()); } - + // int myFunc(); - + // int myFunc(var) - // int var; - // { - // return var; - // } + // int var; + // { + // return var; + // } // int main(void) { // return myFunc(0); // } @@ -390,7 +390,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(params[0].getType() instanceof IBasicType); assertEquals(IBasicType.Kind.eInt, ((IBasicType) params[0].getType()).getKind()); } - + // typedef struct S S; // void setValue(S *pSelf, int value); @@ -404,7 +404,7 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase IBinding b = getBindingFromASTName("value =", 5); assertTrue(b instanceof IField); } - + // void f255( // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, @@ -439,8 +439,8 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, // int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int); - - // void test() { + + // void test() { // f255( // 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -463,8 +463,8 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase public void testFunctionsWithManyParameters_Bug319186() throws Exception { getBindingFromASTName("f255", 0); getBindingFromASTName("f256", 0); - } - + } + // struct B { // float f; // }; @@ -474,5 +474,5 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase // }; public void testDesignatedInitializer_Bug210019() throws Exception { IField f= getBindingFromASTName("f", 0); - } + } } From 2820e4b9fb6719c10b0dc0e8fef1568a231adf28 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 23 Jan 2013 09:26:08 -0800 Subject: [PATCH 13/42] Bug 394151 - Regression: ClassCastException evaluating read/write flags --- .../index/tests/IndexCBindingResolutionBugs.java | 15 ++++++++++++++- .../core/dom/parser/VariableReadWriteFlags.java | 5 +++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java index 1f4f785bdde..ea7a3a80dd6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2013 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 @@ -8,6 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -475,4 +476,16 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase public void testDesignatedInitializer_Bug210019() throws Exception { IField f= getBindingFromASTName("f", 0); } + + // struct S { + // int data; + // }; + + // void test(void (*f)(void*)) { + // struct S *i; + // f(&i->data); + // } + public void testBug394151() throws Exception { + IParameter f= getBindingFromASTName("f(", 1); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java index a800794bc05..b32d1f97e6a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2013 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -191,7 +192,7 @@ public abstract class VariableReadWriteFlags { final IType type= functionNameExpression.getExpressionType(); if (type instanceof IFunctionType) { return rwArgumentForFunctionCall((IFunctionType) type, i, indirection); - } else { + } else if (funcCall instanceof IASTImplicitNameOwner) { IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) funcCall).getImplicitNames(); if (implicitNames.length == 1) { IASTImplicitName name = implicitNames[0]; From 815d32990ce4c76d76bf7170b0fdcdafd9687a3c Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Wed, 23 Jan 2013 12:41:02 -0500 Subject: [PATCH 14/42] Bug 344890 - [remote] Cannot start a new process on a remote target with extended-remote Change-Id: Iae6f29a8a549cc57577911bdc84cc95f6ba983df Reviewed-on: https://git.eclipse.org/r/7438 Reviewed-by: Marc Khouzam IP-Clean: Marc Khouzam Reviewed-by: Mikhail Khodjaiants IP-Clean: Mikhail Khodjaiants Tested-by: Mikhail Khodjaiants --- .../model/IDebugNewExecutableHandler.java | 22 ++ .../icons/obj16/new_exec.gif | Bin 0 -> 949 bytes .../plugin.properties | 6 + debug/org.eclipse.cdt.debug.ui/plugin.xml | 33 ++- .../commands/DebugNewExecutableHandler.java | 23 ++ .../gdb/internal/ui/GdbAdapterFactory.java | 9 +- .../ui/commands/GdbConnectCommand.java | 48 ++-- .../GdbDebugNewExecutableCommand.java | 213 ++++++++++++++++++ .../gdb/internal/ui/commands/Messages.java | 58 +++++ .../internal/ui/commands/Messages.properties | 28 +++ .../ui/launching/NewExecutableDialog.java | 169 ++++++++++++++ .../ui/launching/NewExecutableInfo.java | 51 +++++ .../ui/launching/ProcessPrompter.java | 13 +- .../ui/launching/ProcessPrompterDialog.java | 27 ++- .../gdb/IGDBLaunchConfigurationConstants.java | 7 + .../cdt/dsf/gdb/launching/GdbLaunch.java | 6 +- .../gdb/service/DebugNewProcessSequence.java | 8 +- .../service/DebugNewProcessSequence_7_2.java | 57 ++++- .../cdt/dsf/gdb/service/GDBProcesses_7_2.java | 12 +- .../StartOrRestartProcessSequence_7_0.java | 15 +- 20 files changed, 753 insertions(+), 52 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDebugNewExecutableHandler.java create mode 100755 debug/org.eclipse.cdt.debug.ui/icons/obj16/new_exec.gif create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/DebugNewExecutableHandler.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableDialog.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableInfo.java diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDebugNewExecutableHandler.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDebugNewExecutableHandler.java new file mode 100644 index 00000000000..ecde45f0427 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDebugNewExecutableHandler.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2012 Mentor Graphics 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: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.debug.core.model; + +import org.eclipse.debug.core.commands.IDebugCommandHandler; + +/** + * Command handler for the "Debug New Executable" command. + * + * @since 7.3 + */ +public interface IDebugNewExecutableHandler extends IDebugCommandHandler { +} diff --git a/debug/org.eclipse.cdt.debug.ui/icons/obj16/new_exec.gif b/debug/org.eclipse.cdt.debug.ui/icons/obj16/new_exec.gif new file mode 100755 index 0000000000000000000000000000000000000000..78ca91c6dab7edd4ab90789a10e3b9f7306eb2a8 GIT binary patch literal 949 zcmYk5F^C>S5QX2tY3^cTPAo*QxkO^I7Re3d6w&I?C>A2wGI(hol0vZ(NwXve3UUNv zicF;j1l=ZLnTVkEs{&hD3dtp%L=H@l=l)iiZW!2o^Sw83z5V7Zubx}O8ty*A{}lj% z1OylbD1kzhL=lQnff}epO;n*84QPQzv_un{(SaW5L{D^~8v_`DL5#!@hUeRGz=RVP zJR1Zez(58xXHgI(qA*HEQ4~i-)QHNc8C6jo4bdVRqh&Njb96+H=!~Ax72PoqBVsT{ z#!w805som!8CH1em}>_?A_+}dEMN&1vLuUG%nH_EC2O*Z)ofr3HnJs~*vt<0U?+RB zi`^XH2o7>2hd4}w4w`h*q9=k$JQ7S~LX$`qWQi=yl3A3+S&=oeGHYg4R%b)D$i{4$ zP1&3s*&{o%XLeYN%2* zRi$b*sD&EUQcY@BhkB?}J=LXd4QPZ0HBv(wmLZ2sIc3RS1Yx={kxX54IHOSD5-xN} z7rEFKuHj18bd{^!;1+IlOEy_jH%LJ>U@@^hghREIyk-n{H3!bMM(dUhDrX zFD=Bpyf}o#OWZT);y%U`eP T^3(og>(7%nKG<1W!fXElGQ-Y4 literal 0 HcmV?d00001 diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.properties b/debug/org.eclipse.cdt.debug.ui/plugin.properties index 34cbb7d2d35..2266d66e86e 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.properties +++ b/debug/org.eclipse.cdt.debug.ui/plugin.properties @@ -242,3 +242,9 @@ OpenNewView.name = Open New View # Disassembly Ruler Column extension point extPoint.disassemblyRulerColumn=Disassembly Ruler Column + +# Debug New Executable Command +DebugNewExecutable.name=Debug New Executable +DebugNewExecutable.description=Debug a new executable +DebugNewExecutable.label=Debug New Executable... +DebugNewExecutable.tooltip=Debug a new executable diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index 0188aa81f49..d2b3fc1b6f1 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -2012,7 +2012,12 @@ id="org.eclipse.cdt.debug.ui.command.connect" name="%Connect.name"> - + + @@ -2079,6 +2084,10 @@ class="org.eclipse.cdt.debug.internal.ui.commands.ConnectCommandHandler" commandId="org.eclipse.cdt.debug.ui.command.connect"> + + @@ -2520,6 +2529,28 @@ + + + + + getCommandType() { + return IDebugNewExecutableHandler.class; + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java index a35c0913306..51d5f2ea88b 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java @@ -19,6 +19,7 @@ import java.util.WeakHashMap; import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.cdt.debug.core.model.IConnectHandler; +import org.eclipse.cdt.debug.core.model.IDebugNewExecutableHandler; import org.eclipse.cdt.debug.core.model.IResumeWithoutSignalHandler; import org.eclipse.cdt.debug.core.model.IReverseResumeHandler; import org.eclipse.cdt.debug.core.model.IReverseStepIntoHandler; @@ -49,6 +50,7 @@ import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbDisconnectCommand; import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbRestartCommand; import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbSteppingModeTarget; import org.eclipse.cdt.dsf.gdb.internal.ui.commands.GdbConnectCommand; +import org.eclipse.cdt.dsf.gdb.internal.ui.commands.GdbDebugNewExecutableCommand; import org.eclipse.cdt.dsf.gdb.internal.ui.commands.GdbResumeWithoutSignalCommand; import org.eclipse.cdt.dsf.gdb.internal.ui.commands.GdbReverseResumeCommand; import org.eclipse.cdt.dsf.gdb.internal.ui.commands.GdbReverseStepIntoCommand; @@ -114,6 +116,7 @@ public class GdbAdapterFactory final GdbResumeWithoutSignalCommand fResumeWithoutSignalCommand; final GdbRestartCommand fRestartCommand; final DsfTerminateCommand fTerminateCommand; + final GdbDebugNewExecutableCommand fDebugNewExecutableCommand; final GdbConnectCommand fConnectCommand; final GdbDisconnectCommand fDisconnectCommand; final IDebugModelProvider fDebugModelProvider; @@ -162,7 +165,8 @@ public class GdbAdapterFactory fResumeWithoutSignalCommand = new GdbResumeWithoutSignalCommand(session); fRestartCommand = new GdbRestartCommand(session, fLaunch); fTerminateCommand = new DsfTerminateCommand(session); - fConnectCommand = new GdbConnectCommand(session); + fDebugNewExecutableCommand = new GdbDebugNewExecutableCommand(session, fLaunch); + fConnectCommand = new GdbConnectCommand(session, fLaunch); fDisconnectCommand = new GdbDisconnectCommand(session); fSuspendTrigger = new GdbSuspendTrigger(session, fLaunch); fModelSelectionPolicyFactory = new DefaultDsfModelSelectionPolicyFactory(); @@ -189,6 +193,7 @@ public class GdbAdapterFactory session.registerModelAdapter(IRestartHandler.class, fRestartCommand); session.registerModelAdapter(ITerminateHandler.class, fTerminateCommand); session.registerModelAdapter(IConnectHandler.class, fConnectCommand); + session.registerModelAdapter(IDebugNewExecutableHandler.class, fDebugNewExecutableCommand); session.registerModelAdapter(IDisconnectHandler.class, fDisconnectCommand); session.registerModelAdapter(IModelSelectionPolicyFactory.class, fModelSelectionPolicyFactory); session.registerModelAdapter(IRefreshAllTarget.class, fRefreshAllTarget); @@ -249,6 +254,7 @@ public class GdbAdapterFactory session.unregisterModelAdapter(IRestartHandler.class); session.unregisterModelAdapter(ITerminateHandler.class); session.unregisterModelAdapter(IConnectHandler.class); + session.unregisterModelAdapter(IDebugNewExecutableHandler.class); session.unregisterModelAdapter(IDisconnectHandler.class); session.unregisterModelAdapter(IModelSelectionPolicyFactory.class); session.unregisterModelAdapter(IRefreshAllTarget.class); @@ -279,6 +285,7 @@ public class GdbAdapterFactory fRestartCommand.dispose(); fTerminateCommand.dispose(); fConnectCommand.dispose(); + fDebugNewExecutableCommand.dispose(); fDisconnectCommand.dispose(); fSuspendTrigger.dispose(); fReverseToggleTarget.dispose(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java index d797a6e48ae..5a50b774632 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java @@ -20,6 +20,7 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.RejectedExecutionException; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.model.IConnectHandler; import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; @@ -35,9 +36,11 @@ import org.eclipse.cdt.dsf.debug.service.IProcesses.IProcessDMContext; import org.eclipse.cdt.dsf.debug.service.IProcesses.IThreadDMData; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; +import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; import org.eclipse.cdt.dsf.gdb.actions.IConnect; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; import org.eclipse.cdt.dsf.gdb.internal.ui.actions.ProcessInfo; +import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableInfo; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.LaunchUIMessages; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.ProcessPrompter; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.ProcessPrompter.PrompterInfo; @@ -68,7 +71,8 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.progress.UIJob; public class GdbConnectCommand extends AbstractDebugCommand implements IConnectHandler, IConnect { - + + private final GdbLaunch fLaunch; private final DsfExecutor fExecutor; private final DsfServicesTracker fTracker; @@ -82,7 +86,8 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH // the binary location for a local attach session. private Map fProcessNameToBinaryMap = new HashMap(); - public GdbConnectCommand(DsfSession session) { + public GdbConnectCommand(DsfSession session, GdbLaunch launch) { + fLaunch = launch; fExecutor = session.getExecutor(); fTracker = new DsfServicesTracker(GdbUIPlugin.getBundleContext(), session.getId()); } @@ -143,10 +148,12 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH IProcessExtendedInfo[] fProcessList = null; DataRequestMonitor fRequestMonitor; boolean fNewProcessSupported; + boolean fRemote; - public PromptForPidJob(String name, boolean newProcessSupported, IProcessExtendedInfo[] procs, DataRequestMonitor rm) { + public PromptForPidJob(String name, boolean newProcessSupported, boolean remote, IProcessExtendedInfo[] procs, DataRequestMonitor rm) { super(name); fNewProcessSupported = newProcessSupported; + fRemote = remote; fProcessList = procs; fRequestMonitor = rm; } @@ -158,11 +165,11 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH null); try { - PrompterInfo info = new PrompterInfo(fNewProcessSupported, fProcessList); + PrompterInfo info = new PrompterInfo(fNewProcessSupported, fRemote, fProcessList); Object result = new ProcessPrompter().handleStatus(null, info); if (result == null) { fRequestMonitor.cancel(); - } else if (result instanceof IProcessExtendedInfo[] || result instanceof String) { + } else if (result instanceof IProcessExtendedInfo[] || result instanceof NewExecutableInfo) { fRequestMonitor.setData(result); } else if (result instanceof Integer) { // This is the case where the user typed in a pid number directly @@ -288,9 +295,11 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH public void run() { final IProcesses procService = fTracker.getService(IProcesses.class); ICommandControlService commandControl = fTracker.getService(ICommandControlService.class); + IGDBBackend backend = fTracker.getService(IGDBBackend.class); - if (procService != null && commandControl != null) { + if (procService != null && commandControl != null && backend != null) { final ICommandControlDMContext controlCtx = commandControl.getContext(); + final boolean remote = backend.getSessionType() == SessionType.REMOTE; // First check if the "New..." button should be enabled. procService.isDebugNewProcessSupported(controlCtx, new DataRequestMonitor(fExecutor, rm) { @@ -314,7 +323,8 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH // Prompt the user to choose one or more processes, or to start a new one new PromptForPidJob( LaunchUIMessages.getString("ProcessPrompter.PromptJob"), //$NON-NLS-1$ - newProcessSupported, + newProcessSupported, + remote, procInfoList.toArray(new IProcessExtendedInfo[procInfoList.size()]), new DataRequestMonitor(fExecutor, rm) { @Override @@ -325,9 +335,9 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH @Override protected void handleSuccess() { Object data = getData(); - if (data instanceof String) { + if (data instanceof NewExecutableInfo) { // User wants to start a new process - startNewProcess(controlCtx, (String)data, rm); + startNewProcess(controlCtx, (NewExecutableInfo)data, rm); } else if (data instanceof IProcessExtendedInfo[]) { attachToProcesses(controlCtx, (IProcessExtendedInfo[])data, rm); } else { @@ -412,11 +422,23 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH }); } - private void startNewProcess(ICommandControlDMContext controlDmc, String binaryPath, RequestMonitor rm) { + private void startNewProcess(ICommandControlDMContext controlDmc, NewExecutableInfo info, RequestMonitor rm) { IGDBProcesses procService = fTracker.getService(IGDBProcesses.class); - procService.debugNewProcess( - controlDmc, binaryPath, - new HashMap(), new DataRequestMonitor(fExecutor, rm)); + try { + @SuppressWarnings("unchecked") + Map attributes = fLaunch.getLaunchConfiguration().getAttributes(); + attributes.put(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_REMOTE_BINARY, info.getTargetPath()); + attributes.put(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, info.getArguments()); + procService.debugNewProcess( + controlDmc, + info.getHostPath(), + attributes, + new DataRequestMonitor(fExecutor, rm)); + } + catch(CoreException e) { + rm.setStatus(e.getStatus()); + rm.done(); + } } private void attachToProcesses(final ICommandControlDMContext controlDmc, IProcessExtendedInfo[] processes, final RequestMonitor rm) { diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java new file mode 100644 index 00000000000..4631445ea5c --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2012 Mentor Graphics 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: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.internal.ui.commands; + +import java.util.Map; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.RejectedExecutionException; + +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.debug.core.model.IDebugNewExecutableHandler; +import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.DsfExecutor; +import org.eclipse.cdt.dsf.concurrent.DsfRunnable; +import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.Query; +import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.datamodel.IDMContext; +import org.eclipse.cdt.dsf.debug.service.IProcesses; +import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; +import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; +import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; +import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableInfo; +import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableDialog; +import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch; +import org.eclipse.cdt.dsf.gdb.service.IGDBBackend; +import org.eclipse.cdt.dsf.gdb.service.SessionType; +import org.eclipse.cdt.dsf.service.DsfServicesTracker; +import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.IRequest; +import org.eclipse.debug.core.commands.AbstractDebugCommand; +import org.eclipse.debug.core.commands.IEnabledStateRequest; +import org.eclipse.jface.window.Window; +import org.eclipse.ui.progress.UIJob; + +public class GdbDebugNewExecutableCommand extends AbstractDebugCommand implements IDebugNewExecutableHandler { + + private class PromptJob extends UIJob { + + private DataRequestMonitor fRequestMonitor; + private boolean fRemote = false; + + private PromptJob( boolean remote, DataRequestMonitor rm ) { + super( Messages.GdbDebugNewExecutableCommand_New_Executable_Prompt_Job ); + fRemote = remote; + fRequestMonitor = rm; + } + + @Override + public IStatus runInUIThread( IProgressMonitor monitor ) { + int flags = ( fRemote ) ? NewExecutableDialog.REMOTE : 0; + NewExecutableDialog dialog = new NewExecutableDialog( GdbUIPlugin.getShell(), flags ); + final boolean canceled = dialog.open() == Window.CANCEL; + final NewExecutableInfo info = dialog.getExecutableInfo(); + fExecutor.execute( new DsfRunnable() { + + @Override + public void run() { + if ( canceled ) + fRequestMonitor.cancel(); + else + fRequestMonitor.setData( info ); + fRequestMonitor.done(); + } + } ); + return Status.OK_STATUS; + } + } + + private final GdbLaunch fLaunch; + private final DsfExecutor fExecutor; + private final DsfServicesTracker fTracker; + + public GdbDebugNewExecutableCommand( DsfSession session, GdbLaunch launch ) { + super(); + fLaunch = launch; + fExecutor = session.getExecutor(); + fTracker = new DsfServicesTracker( GdbUIPlugin.getBundleContext(), session.getId() ); + } + + public boolean canDebugNewExecutable() { + + Query canDebugQuery = new Query() { + @Override + public void execute( DataRequestMonitor rm ) { + IProcesses procService = fTracker.getService( IProcesses.class ); + ICommandControlService commandControl = fTracker.getService( ICommandControlService.class ); + + if ( procService == null || commandControl == null ) { + rm.setData( false ); + rm.done(); + return; + } + procService.isDebugNewProcessSupported( commandControl.getContext(), rm ); + } + }; + try { + fExecutor.execute( canDebugQuery ); + return canDebugQuery.get(); + } + catch( InterruptedException e ) { + } + catch( ExecutionException e ) { + } + catch( RejectedExecutionException e ) { + // Can be thrown if the session is shutdown + } + return false; + } + + public void debugNewExecutable( final RequestMonitor rm ) { + IGDBBackend backend = fTracker.getService( IGDBBackend.class ); + final IProcesses procService = fTracker.getService( IProcesses.class ); + final ICommandControlService commandControl = fTracker.getService( ICommandControlService.class ); + if ( backend == null || procService == null || commandControl == null ) { + rm.setStatus( new Status( IStatus.ERROR, GdbUIPlugin.PLUGIN_ID, "Service is not available" ) ); //$NON-NLS-1$ + rm.done(); + return; + } + + PromptJob job = new PromptJob( + backend.getSessionType() == SessionType.REMOTE, + new DataRequestMonitor( fExecutor, rm ){ + + @Override + protected void handleCancel() { + rm.cancel(); + rm.done(); + }; + + @Override + protected void handleSuccess() { + try { + @SuppressWarnings( "unchecked" ) + Map attributes = getLaunchConfiguration().getAttributes(); + attributes.put( IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_REMOTE_BINARY, getData().getTargetPath() ); + attributes.put( ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, getData().getArguments() ); + procService.debugNewProcess( + commandControl.getContext(), + getData().getHostPath(), + attributes, + new ImmediateDataRequestMonitor( rm ) ); + } + catch( CoreException e ) { + rm.setStatus( e.getStatus() ); + rm.done(); + } + }; + } ); + job.schedule(); + } + + @Override + protected void doExecute( Object[] targets, IProgressMonitor monitor, IRequest request ) throws CoreException { + Query query = new Query() { + + @Override + protected void execute( DataRequestMonitor rm ) { + debugNewExecutable( rm ); + } + }; + try { + fExecutor.execute( query ); + query.get(); + } + catch( InterruptedException e ) { + } + catch( ExecutionException e ) { + } + catch( CancellationException e ) { + // Nothing to do, just ignore the command since the user + // cancelled it. + } + catch( RejectedExecutionException e ) { + // Can be thrown if the session is shutdown + } + } + + @Override + protected boolean isExecutable( Object[] targets, IProgressMonitor monitor, IEnabledStateRequest request ) throws CoreException { + return canDebugNewExecutable(); + } + + @Override + protected Object getTarget( Object element ) { + if ( element instanceof GdbLaunch || element instanceof IDMVMContext ) + return element; + return null; + } + + public void dispose() { + fTracker.dispose(); + } + + private ILaunchConfiguration getLaunchConfiguration() { + return fLaunch.getLaunchConfiguration(); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java new file mode 100644 index 00000000000..a8d5629cd7f --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2012 Mentor Graphics 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: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.internal.ui.commands; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + + public static String GdbDebugNewExecutableCommand_Arguments; + + public static String GdbDebugNewExecutableCommand_Binary; + + public static String GdbDebugNewExecutableCommand_Binary_file_does_not_exist; + + public static String GdbDebugNewExecutableCommand_Binary_must_be_specified; + + public static String GdbDebugNewExecutableCommand_Binary_on_host; + + public static String GdbDebugNewExecutableCommand_Binary_on_target; + + public static String GdbDebugNewExecutableCommand_Binary_on_target_must_be_specified; + + public static String GdbDebugNewExecutableCommand_Browse; + + public static String GdbDebugNewExecutableCommand_Debug_New_Executable; + + public static String GdbDebugNewExecutableCommand_Host_binary_file_does_not_exist; + + public static String GdbDebugNewExecutableCommand_Host_binary_must_be_specified; + + public static String GdbDebugNewExecutableCommand_Invalid_binary; + + public static String GdbDebugNewExecutableCommand_Invalid_host_binary; + + public static String GdbDebugNewExecutableCommand_New_Executable_Prompt_Job; + + public static String GdbDebugNewExecutableCommand_Select_binaries_on_host_and_target; + + public static String GdbDebugNewExecutableCommand_Select_Binary; + + public static String GdbDebugNewExecutableCommand_Select_binary_and_specify_arguments; + static { + // initialize resource bundle + NLS.initializeMessages( Messages.class.getName(), Messages.class ); + } + + private Messages() { + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties new file mode 100644 index 00000000000..d601bc6d839 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/Messages.properties @@ -0,0 +1,28 @@ +############################################################################### +# Copyright (c) 2012 Mentor Graphics 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: +# Mentor Graphics - Initial API and implementation +############################################################################### + +GdbDebugNewExecutableCommand_Arguments=Arguments: +GdbDebugNewExecutableCommand_Binary=Binary: +GdbDebugNewExecutableCommand_Binary_file_does_not_exist=Binary file does not exist +GdbDebugNewExecutableCommand_Binary_must_be_specified=Binary must be specified +GdbDebugNewExecutableCommand_Binary_on_host=Binary on host: +GdbDebugNewExecutableCommand_Binary_on_target=Binary on target: +GdbDebugNewExecutableCommand_Binary_on_target_must_be_specified=Binary on target must be specified +GdbDebugNewExecutableCommand_Browse=Browse... +GdbDebugNewExecutableCommand_Debug_New_Executable=Debug New Executable +GdbDebugNewExecutableCommand_Host_binary_file_does_not_exist=Host binary file does not exist +GdbDebugNewExecutableCommand_Host_binary_must_be_specified=Host binary must be specified +GdbDebugNewExecutableCommand_Invalid_binary=Invalid binary +GdbDebugNewExecutableCommand_Invalid_host_binary=Invalid host binary +GdbDebugNewExecutableCommand_New_Executable_Prompt_Job=New Executable Prompt Job +GdbDebugNewExecutableCommand_Select_binaries_on_host_and_target=Select binaries on the host and the target and specify the arguments +GdbDebugNewExecutableCommand_Select_Binary=Select Binary +GdbDebugNewExecutableCommand_Select_binary_and_specify_arguments=Select a binary and specify the arguments diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableDialog.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableDialog.java new file mode 100644 index 00000000000..7c65e7be5eb --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableDialog.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2013 Mentor Graphics 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: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.internal.ui.launching; + +import java.io.File; + +import org.eclipse.cdt.dsf.gdb.internal.ui.commands.Messages; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class NewExecutableDialog extends TitleAreaDialog { + + public static final int REMOTE = 0x1; + + private int fFlags = 0; + private NewExecutableInfo fInfo = null; + + private Text fHostBinaryText; + private Text fTargetBinaryText; + private Text fArgumentsText; + + public NewExecutableDialog( Shell parentShell, int flags ) { + super( parentShell ); + setShellStyle( getShellStyle() | SWT.RESIZE ); + fFlags = flags; + } + + @Override + protected Control createContents( Composite parent ) { + Control control = super.createContents( parent ); + validate(); + return control; + } + + @Override + protected Control createDialogArea( Composite parent ) { + boolean remote = (fFlags & REMOTE) > 0; + + getShell().setText( Messages.GdbDebugNewExecutableCommand_Debug_New_Executable ); + setTitle( Messages.GdbDebugNewExecutableCommand_Select_Binary ); + String message = ( remote ) ? + Messages.GdbDebugNewExecutableCommand_Select_binaries_on_host_and_target : + Messages.GdbDebugNewExecutableCommand_Select_binary_and_specify_arguments; + setMessage( message ); + + Composite control = (Composite)super.createDialogArea( parent ); + Composite comp = new Composite( control, SWT.NONE ); + GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true ); + GridLayout layout = new GridLayout( 3, false ); + comp.setLayout( layout ); + comp.setLayoutData( gd ); + + new Label( comp, SWT.None ).setText( remote ? Messages.GdbDebugNewExecutableCommand_Binary_on_host : Messages.GdbDebugNewExecutableCommand_Binary ); + fHostBinaryText = new Text( comp, SWT.BORDER ); + fHostBinaryText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) ); + fHostBinaryText.addModifyListener( new ModifyListener() { + + @Override + public void modifyText( ModifyEvent e ) { + validate(); + } + } ); + Button browseButton = new Button( comp, SWT.PUSH ); + browseButton.setText( Messages.GdbDebugNewExecutableCommand_Browse ); + browseButton.setFont( JFaceResources.getDialogFont() ); + setButtonLayoutData( browseButton ); + browseButton.addSelectionListener( new SelectionAdapter() { + + @Override + public void widgetSelected( SelectionEvent e ) { + FileDialog dialog = new FileDialog( getShell() ); + dialog.setFileName( fHostBinaryText.getText() ); + String result = dialog.open(); + if ( result != null ) { + fHostBinaryText.setText( result ); + } + } + } ); + + if ( remote ) { + new Label( comp, SWT.None ).setText( Messages.GdbDebugNewExecutableCommand_Binary_on_target ); + fTargetBinaryText = new Text( comp, SWT.BORDER ); + fTargetBinaryText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) ); + fTargetBinaryText.addModifyListener( new ModifyListener() { + + @Override + public void modifyText( ModifyEvent e ) { + validate(); + } + } ); + } + + new Label( comp, SWT.None ).setText( Messages.GdbDebugNewExecutableCommand_Arguments ); + fArgumentsText = new Text( comp, SWT.BORDER ); + fArgumentsText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) ); + + return control; + } + + @Override + protected void okPressed() { + String targetPath = ( fTargetBinaryText != null ) ? fTargetBinaryText.getText().trim() : null; + String args = fArgumentsText.getText().trim(); + fInfo = new NewExecutableInfo( fHostBinaryText.getText().trim(), targetPath, args ); + super.okPressed(); + } + + public NewExecutableInfo getExecutableInfo() { + return fInfo; + } + + private void validate() { + boolean remote = (fFlags & REMOTE) > 0; + StringBuilder sb = new StringBuilder(); + String hostBinary = fHostBinaryText.getText().trim(); + if ( hostBinary.isEmpty() ) { + sb.append( ( remote ) ? + Messages.GdbDebugNewExecutableCommand_Host_binary_must_be_specified : + Messages.GdbDebugNewExecutableCommand_Binary_must_be_specified ); + } + else { + File file = new File( hostBinary ); + if ( !file.exists() ) { + sb.append( ( remote ) ? + Messages.GdbDebugNewExecutableCommand_Host_binary_file_does_not_exist : + Messages.GdbDebugNewExecutableCommand_Binary_file_does_not_exist ); + } + else if ( file.isDirectory() ) { + sb.append( ( remote ) ? + Messages.GdbDebugNewExecutableCommand_Invalid_host_binary : + Messages.GdbDebugNewExecutableCommand_Invalid_binary ); + } + } + if ( fTargetBinaryText != null ) { + if ( fTargetBinaryText.getText().trim().length() == 0 ) { + if ( sb.length() != 0 ) { + sb.append( "\n " ); //$NON-NLS-1$ + } + sb.append( Messages.GdbDebugNewExecutableCommand_Binary_on_target_must_be_specified ); + } + } + setErrorMessage( ( sb.length() != 0 ) ? sb.toString() : null ); + getButton( IDialogConstants.OK_ID ).setEnabled( getErrorMessage() == null ); + } +} \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableInfo.java new file mode 100644 index 00000000000..1f88a279bde --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/NewExecutableInfo.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 Mentor Graphics 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: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.internal.ui.launching; + +/** + * This class provides information required to start + * debugging an executable. + */ +public class NewExecutableInfo { + private String fHostPath; + private String fTargetPath; + private String fArguments; + + public NewExecutableInfo(String hostPath, String targetPath, String args) { + super(); + fHostPath = hostPath; + fTargetPath = targetPath; + fArguments = args; + } + + /** + * Returns the path of the executable on the host + */ + public String getHostPath() { + return fHostPath; + } + + /** + * For remote sessions returns the path of the executable + * on the target. Otherwise returns null. + */ + public String getTargetPath() { + return fTargetPath; + } + + /** + * Returns the arguments to pass to the executable, or null + */ + public String getArguments() { + return fArguments; + } +} \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java index 8df673aa10c..b50e0ce4a68 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompter.java @@ -34,10 +34,12 @@ public class ProcessPrompter implements IStatusHandler { public static class PrompterInfo { public boolean supportsNewProcess; + public boolean remote; public IProcessExtendedInfo[] processList; - public PrompterInfo(boolean supportsNew, IProcessExtendedInfo[] list) { + public PrompterInfo(boolean supportsNew, boolean remote, IProcessExtendedInfo[] list) { supportsNewProcess = supportsNew; + this.remote = remote; processList = list; } } @@ -162,7 +164,8 @@ public class ProcessPrompter implements IStatusHandler { }; // Display the list of processes and have the user choose - ProcessPrompterDialog dialog = new ProcessPrompterDialog(shell, provider, qprovider, prompterInfo.supportsNewProcess); + ProcessPrompterDialog dialog = + new ProcessPrompterDialog(shell, provider, qprovider, prompterInfo.supportsNewProcess, prompterInfo.remote); dialog.setTitle(LaunchUIMessages.getString("LocalAttachLaunchDelegate.Select_Process")); //$NON-NLS-1$ dialog.setMessage(LaunchUIMessages.getString("LocalAttachLaunchDelegate.Select_Process_to_attach_debugger_to")); //$NON-NLS-1$ @@ -172,9 +175,9 @@ public class ProcessPrompter implements IStatusHandler { dialog.setElements(plist); if (dialog.open() == Window.OK) { // First check if the user pressed the New button - String binaryPath = dialog.getBinaryPath(); - if (binaryPath != null) { - return binaryPath; + NewExecutableInfo execInfo = dialog.getExecutableInfo(); + if (execInfo != null) { + return execInfo; } Object[] results = dialog.getResult(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompterDialog.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompterDialog.java index 92f6ee216bd..623c148e386 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompterDialog.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/ProcessPrompterDialog.java @@ -13,12 +13,12 @@ package org.eclipse.cdt.dsf.gdb.internal.ui.launching; import java.util.Arrays; +import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; @@ -42,13 +42,15 @@ import org.eclipse.ui.dialogs.TwoPaneElementSelector; */ public class ProcessPrompterDialog extends TwoPaneElementSelector { private static final int NEW_BUTTON_ID = 9876; - private String fBinaryPath; + private NewExecutableInfo fExecInfo; private boolean fSupportsNewProcess; + private boolean fRemote; public ProcessPrompterDialog(Shell parent, ILabelProvider elementRenderer, - ILabelProvider qualifierRenderer, boolean supportsNewProcess) { + ILabelProvider qualifierRenderer, boolean supportsNewProcess, boolean remote) { super(parent, elementRenderer, qualifierRenderer); fSupportsNewProcess = supportsNewProcess; + fRemote = remote; } @Override @@ -62,19 +64,16 @@ public class ProcessPrompterDialog extends TwoPaneElementSelector { @Override protected void buttonPressed(int buttonId) { if (buttonId == NEW_BUTTON_ID) { - FileDialog fd = new FileDialog(getShell(), SWT.NONE); - fBinaryPath = fd.open(); - - setReturnCode(OK); - close(); + NewExecutableDialog dialog = new NewExecutableDialog(getShell(), (fRemote) ? NewExecutableDialog.REMOTE : 0); + if (dialog.open() == IDialogConstants.OK_ID) { + fExecInfo = dialog.getExecutableInfo(); + setReturnCode(OK); + close(); + } } super.buttonPressed(buttonId); } - public String getBinaryPath() { - return fBinaryPath; - } - /* * The result should be every selected element. */ @@ -116,4 +115,8 @@ public class ProcessPrompterDialog extends TwoPaneElementSelector { }); return list; } + + public NewExecutableInfo getExecutableInfo() { + return fExecInfo; + } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java index 0f1cf56d63b..74bdabda65e 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java @@ -114,6 +114,13 @@ public class IGDBLaunchConfigurationConstants { */ public static final String ATTR_DEBUGGER_TRACEPOINT_MODE = GdbPlugin.PLUGIN_ID + ".TRACEPOINT_MODE"; //$NON-NLS-1$ + /** + * Launch configuration attribute key. The value is a String specifying the path of the executable + * on the target. + * @since 4.2 + */ + public static final String ATTR_DEBUGGER_REMOTE_BINARY = GdbPlugin.PLUGIN_ID + ".REMOTE_BINARY"; //$NON-NLS-1$ + /** * Launch configuration attribute value. The key is ATTR_DEBUG_NAME. */ diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java index 87c79a79e94..efaa5bdb475 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunch.java @@ -19,6 +19,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.RejectedExecutionException; import org.eclipse.cdt.debug.core.model.IConnectHandler; +import org.eclipse.cdt.debug.core.model.IDebugNewExecutableHandler; import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor; import org.eclipse.cdt.dsf.concurrent.DefaultDsfExecutor; import org.eclipse.cdt.dsf.concurrent.DsfExecutor; @@ -295,7 +296,10 @@ public class GdbLaunch extends DsfLaunch if (adapter.equals(IConnectHandler.class)) return getSession().getModelAdapter(adapter); - // Must force adapters to be loaded. + if (adapter.equals(IDebugNewExecutableHandler.class)) + return getSession().getModelAdapter(adapter); + + // Must force adapters to be loaded. Platform.getAdapterManager().loadAdapter(this, adapter.getName()); return super.getAdapter(adapter); } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java index ba0797d0f3b..acd2c10c2cc 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence.java @@ -200,9 +200,13 @@ public class DebugNewProcessSequence extends ReflectionSequence { @Execute public void stepSetArguments(RequestMonitor rm) { try { - String args = fBackend.getProgramArguments(); + String args = CDebugUtils.getAttribute( + fAttributes, + ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, + ""); //$NON-NLS-1$ - if (args != null) { + if (args.length() != 0) { + args = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(args); String[] argArray = CommandLineUtil.argumentsToArray(args); fCommandControl.queueCommand( fCommandFactory.createMIGDBSetArgs(getContainerContext(), argArray), diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java index c7238712b59..40685bb3d89 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/DebugNewProcessSequence_7_2.java @@ -15,15 +15,19 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DsfExecutor; import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants; import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.dsf.datamodel.IDMContext; +import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; +import org.eclipse.cdt.dsf.mi.service.command.CommandFactory; import org.eclipse.cdt.dsf.mi.service.command.output.MIAddInferiorInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -40,14 +44,23 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence { private IGDBControl fGdbControl; private IGDBProcesses fProcService; + private IGDBBackend fBackend; + private CommandFactory fCommandFactory; private String fSessionId; private final boolean fInitialProcess; + private final Map fAttributes; - public DebugNewProcessSequence_7_2(DsfExecutor executor, boolean isInitial, IDMContext dmc, String file, - Map attributes, DataRequestMonitor rm) { + public DebugNewProcessSequence_7_2( + DsfExecutor executor, + boolean isInitial, + IDMContext dmc, + String file, + Map attributes, + DataRequestMonitor rm) { super(executor, isInitial, dmc, file, attributes, rm); fSessionId = dmc.getSessionId(); fInitialProcess = isInitial; + fAttributes = attributes; } @Override @@ -60,13 +73,14 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence { // Now insert our steps right after the initialization of the base class. orderList.add(orderList.indexOf("stepInitializeBaseSequence") + 1, "stepInitializeSequence_7_2"); //$NON-NLS-1$ //$NON-NLS-2$ orderList.add(orderList.indexOf("stepInitializeSequence_7_2") + 1, "stepAddInferior"); //$NON-NLS-1$ //$NON-NLS-2$ + orderList.add(orderList.indexOf("stepSetExecutable") + 1, "stepSetRemoteExecutable"); //$NON-NLS-1$ //$NON-NLS-2$ return orderList.toArray(new String[orderList.size()]); } return null; } - + /** * Initialize the members of the DebugNewProcessSequence_7_2 class. * This step is mandatory for the rest of the sequence to complete. @@ -76,14 +90,17 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence { DsfServicesTracker tracker = new DsfServicesTracker(GdbPlugin.getBundleContext(), fSessionId); fGdbControl = tracker.getService(IGDBControl.class); fProcService = tracker.getService(IGDBProcesses.class); + fBackend = tracker.getService(IGDBBackend.class); tracker.dispose(); - if (fGdbControl == null || fProcService == null) { + if (fGdbControl == null || fProcService == null || fBackend == null) { rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Cannot obtain service", null)); //$NON-NLS-1$ rm.done(); return; } + fCommandFactory = fGdbControl.getCommandFactory(); + rm.done(); } @@ -119,5 +136,37 @@ public class DebugNewProcessSequence_7_2 extends DebugNewProcessSequence { rm.done(); } }); + } + + /** + * Set remote executable. + * @since 4.2 + */ + @Execute + public void stepSetRemoteExecutable(final RequestMonitor rm) { + if (fBackend.getSessionType() == SessionType.REMOTE && fBackend.getIsAttachSession()) { + String remoteBinary = CDebugUtils.getAttribute( + fAttributes, + IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_REMOTE_BINARY, + ""); //$NON-NLS-1$ + if (remoteBinary.length() == 0) { + rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, "Binary on host is not specified")); //$NON-NLS-1$ + rm.done(); + return; + } + + fGdbControl.queueCommand( + fCommandFactory.createMIGDBSet( + getContainerContext(), + new String[] { + "remote", //$NON-NLS-1$ + "exec-file", //$NON-NLS-1$ + remoteBinary, + }), + new ImmediateDataRequestMonitor(rm)); + } + else { + rm.done(); } } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java index d9ab8bc5851..4a313fc1d95 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_2.java @@ -469,10 +469,14 @@ public class GDBProcesses_7_2 extends GDBProcesses_7_1 { return false; } - // We don't yet support starting a new process on a remote target - // Bug 344890 - if (type == SessionType.REMOTE && fBackend.getIsAttachSession()) { - return false; + // Multi-process does not work for all-stop right now + IMIRunControl runControl = getServicesTracker().getService(IMIRunControl.class); + if (runControl != null && runControl.getRunMode() == MIRunMode.ALL_STOP) { + // Only one process is allowed in all-stop (for now) + return getNumConnected() == 0; + // NOTE: when we support multi-process in all-stop mode, + // we will need to interrupt the target to when starting + // the new process. } return true; diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java index 6f8a2fd69fd..e88e9b6b3ca 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java @@ -260,10 +260,9 @@ public class StartOrRestartProcessSequence_7_0 extends ReflectionSequence { */ @Execute public void stepInitializeInputOutput(final RequestMonitor rm) { - if (fBackend.getSessionType() == SessionType.REMOTE && !fBackend.getIsAttachSession()) { - // Remote non-attach sessions don't support multi-process and therefore will not - // start new processes. Those sessions will only start the one process, which should - // not have a console, because it's output is handled by GDB server. + if (fBackend.getSessionType() == SessionType.REMOTE) { + // The program input and output for a remote session is handled by gdbserver. + // Therefore, no need to create a pty. fPty = null; rm.done(); } else { @@ -296,11 +295,9 @@ public class StartOrRestartProcessSequence_7_0 extends ReflectionSequence { */ @Execute public void stepCreateConsole(final RequestMonitor rm) { - if (fBackend.getSessionType() == SessionType.REMOTE && !fBackend.getIsAttachSession()) { - // Remote non-attach sessions don't support multi-process and therefore will not - // start new processes. Those sessions will only start the one process, which should - // not have a console, because it's output is handled by GDB server. Therefore, - // no need to create an inferior process and add it to the launch + if (fBackend.getSessionType() == SessionType.REMOTE) { + // The program output for a remote session is handled by gdbserver. Therefore, + // no need to create an inferior process and add it to the launch. rm.done(); return; } From 6878112781dcc8c1459480f4429072c92178cd14 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 23 Jan 2013 10:05:51 -0800 Subject: [PATCH 15/42] Cosmetics. --- .../core/parser/tests/FileBasePluginTest.java | 105 ++--- .../core/parser/tests/ast2/AST2BaseTest.java | 106 ++--- .../tests/ast2/AST2CPPImplicitNameTests.java | 86 ++-- .../core/parser/tests/ast2/AST2CPPTests.java | 14 +- .../tests/ast2/AST2FileBasePluginTest.java | 96 ++-- .../parser/tests/ast2/AST2TemplateTests.java | 67 +-- .../tests/ast2/CompleteParser2Tests.java | 28 +- .../tests/ast2/DOMSelectionParseTest.java | 434 ++++++++---------- .../cdt/core/parser/tests/ast2/TestUtil.java | 2 +- 9 files changed, 443 insertions(+), 495 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java index 57601678d90..81389f8057c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java @@ -8,10 +8,6 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ - -/* - * Created on Sept 28, 2004 - */ package org.eclipse.cdt.core.parser.tests; import java.io.ByteArrayInputStream; @@ -41,7 +37,7 @@ public class FileBasePluginTest extends TestCase { static IWorkspace workspace; static IProject project; static FileManager fileManager; - static int numProjects = 0; + static int numProjects; static Class className; static ICProject cPrj; @@ -52,111 +48,94 @@ public class FileBasePluginTest extends TestCase { super(name); } - private void initialize(Class aClassName){ - if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){ + private void initialize(Class aClassName) { + if (CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null) { //(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset(); monitor = new NullProgressMonitor(); - + workspace = ResourcesPlugin.getWorkspace(); - + try { cPrj = CProjectHelper.createCCProject("ParserTestProject", "bin", IPDOMManager.ID_NO_INDEXER); //$NON-NLS-1$ //$NON-NLS-2$ project = cPrj.getProject(); - + // ugly if (className == null || !className.equals(aClassName)) { className = aClassName; numProjects++; } - } catch ( CoreException e ) { - /*boo*/ + } catch (CoreException e) { + // Ignore } if (project == null) throw new NullPointerException("Unable to create project"); //$NON-NLS-1$ - + //Create file manager fileManager = new FileManager(); } } - public FileBasePluginTest(String name, Class className) - { + public FileBasePluginTest(String name, Class className) { super(name); initialize(className); } - + public void cleanupProject() throws Exception { numProjects--; - - try{ + + try { if (numProjects == 0) { - project.delete( true, false, monitor ); + project.delete(true, false, monitor); project = null; } - } catch( Throwable e ){ - /*boo*/ + } catch (Throwable e) { + // Ignore } } @Override protected void tearDown() throws Exception { - if( project == null || !project.exists() ) + if (project == null || !project.exists()) return; - + IResource [] members = project.members(); - for( int i = 0; i < members.length; i++ ){ - if( members[i].getName().equals( ".project" ) || members[i].getName().equals( ".cproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$ + for (int i = 0; i < members.length; i++) { + if (members[i].getName().equals(".project") || members[i].getName().equals(".cproject")) //$NON-NLS-1$ //$NON-NLS-2$ continue; if (members[i].getName().equals(".settings")) continue; - try{ - members[i].delete( false, monitor ); - } catch( Throwable e ){ - /*boo*/ + try { + members[i].delete(false, monitor); + } catch (Throwable e) { + // Ignore } } } - // below can be used to work with large files (too large for memory) -// protected IFile importFile(String fileName) throws Exception { -// IFile file = cPrj.getProject().getFile(fileName); -// if (!file.exists()) { -// try{ -// FileInputStream fileIn = new FileInputStream( -// CTestPlugin.getDefault().getFileInPlugin(new Path("resources/parser/" + fileName))); -// file.create(fileIn,false, monitor); -// } catch (CoreException e) { -// e.printStackTrace(); -// } catch (FileNotFoundException e) { -// e.printStackTrace(); -// } -// } -// -// return file; -// } - protected IFolder importFolder(String folderName) throws Exception { IFolder folder = project.getProject().getFolder(folderName); - - //Create file input stream - if( !folder.exists() ) - folder.create( false, false, monitor ); - + + // Create file input stream + if (!folder.exists()) + folder.create(false, false, monitor); + return folder; } - public IFile importFile(String fileName, String contents ) throws Exception{ - //Obtain file handle + + public IFile importFile(String fileName, String contents) throws Exception { + // Obtain file handle IFile file = project.getProject().getFile(fileName); - - InputStream stream = new ByteArrayInputStream( contents.getBytes() ); - //Create file input stream - if( file.exists() ) - file.setContents( stream, false, false, monitor ); - else - file.create( stream, false, monitor ); - + + InputStream stream = new ByteArrayInputStream(contents.getBytes()); + // Create file input stream + if (file.exists()) { + file.setContents(stream, false, false, monitor); + } else { + file.create(stream, false, monitor); + } + fileManager.addFile(file); - + return file; } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index 374a5014c03..f7e532c46b9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -124,11 +124,11 @@ public class AST2BaseTest extends BaseTestCase { public AST2BaseTest() { super(); } - + public AST2BaseTest(String name) { super(name); } - + @Override protected void setUp() throws Exception { sValidateCopy= true; @@ -138,7 +138,7 @@ public class AST2BaseTest extends BaseTestCase { protected IASTTranslationUnit parse(String code, ParserLanguage lang) throws ParserException { return parse(code, lang, false, true); } - + protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException { return parse(code, lang, useGNUExtensions, true); } @@ -147,10 +147,10 @@ public class AST2BaseTest extends BaseTestCase { boolean expectNoProblems) throws ParserException { return parse(code, lang, useGNUExtensions, expectNoProblems, false); } - + protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException { - IScanner scanner = createScanner(FileContent.create(TEST_CODE, code.toCharArray()), lang, ParserMode.COMPLETE_PARSE, + IScanner scanner = createScanner(FileContent.create(TEST_CODE, code.toCharArray()), lang, ParserMode.COMPLETE_PARSE, createScannerInfo(useGNUExtensions)); configureScanner(scanner); AbstractGNUSourceCodeParser parser = null; @@ -170,12 +170,12 @@ public class AST2BaseTest extends BaseTestCase { } else { config = new ANSICParserExtensionConfiguration(); } - + parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config, null); } if (skipTrivialInitializers) parser.setSkipTrivialExpressionsInAggregateInitializers(true); - + IASTTranslationUnit tu = parser.parse(); assertTrue(tu.isFrozen()); if (sValidateCopy) @@ -183,7 +183,7 @@ public class AST2BaseTest extends BaseTestCase { if (parser.encounteredError() && expectNoProblems) throw new ParserException("FAILURE"); //$NON-NLS-1$ - + if (lang == ParserLanguage.C && expectNoProblems) { assertEquals(CVisitor.getProblems(tu).length, 0); assertEquals(tu.getPreprocessorProblems().length, 0); @@ -193,7 +193,7 @@ public class AST2BaseTest extends BaseTestCase { } if (expectNoProblems) assertEquals(0, tu.getPreprocessorProblems().length); - + return tu; } @@ -215,7 +215,7 @@ public class AST2BaseTest extends BaseTestCase { configuration= GPPScannerExtensionConfiguration.getInstance(scannerInfo); } IScanner scanner; - scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration, + scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration, IncludeFileContentProvider.getSavedFilesProvider()); return scanner; } @@ -263,7 +263,7 @@ public class AST2BaseTest extends BaseTestCase { } protected void validateSimpleBinaryExpressionC(String code, int operand) throws ParserException { - IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); + IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); assertNotNull(e); assertEquals(e.getOperator(), operand); IASTIdExpression x = (IASTIdExpression) e.getOperand1(); @@ -290,8 +290,8 @@ public class AST2BaseTest extends BaseTestCase { ASTComparer.assertCopy(tu, copy); return (T) copy; } - - + + static protected class CNameCollector extends ASTVisitor { { shouldVisitNames = true; @@ -309,22 +309,22 @@ public class AST2BaseTest extends BaseTestCase { return null; return nameList.get(idx); } - + public int size() { return nameList.size(); - } + } } protected void assertInstances(CNameCollector collector, IBinding binding, int num) throws Exception { int count = 0; - + assertNotNull(binding); - + for (int i = 0; i < collector.size(); i++) { if (collector.getName(i).resolveBinding() == binding) count++; } - + assertEquals(count, num); } @@ -332,12 +332,12 @@ public class AST2BaseTest extends BaseTestCase { public CPPNameCollector() { this(false); // don't visit implicit names by default } - + public CPPNameCollector(boolean shouldVisitImplicitNames) { this.shouldVisitNames = true; this.shouldVisitImplicitNames = shouldVisitImplicitNames; } - + public List nameList = new ArrayList(); @Override @@ -355,7 +355,7 @@ public class AST2BaseTest extends BaseTestCase { public int size() { return nameList.size(); } - + public void dump() { for (int i= 0; i < size(); i++) { IASTName name= getName(i); @@ -371,7 +371,7 @@ public class AST2BaseTest extends BaseTestCase { if (collector.getName(i).resolveBinding() == binding) count++; } - + assertEquals(num, count); } @@ -392,42 +392,42 @@ public class AST2BaseTest extends BaseTestCase { String expressionString = ASTStringUtil.getExpressionString(exp); assertEquals(str, expressionString); } - + protected void isParameterSignatureEqual(IASTDeclarator decltor, String str) { assertTrue(decltor instanceof IASTFunctionDeclarator); final String[] sigArray = ASTStringUtil.getParameterSignatureArray((IASTFunctionDeclarator) decltor); assertEquals(str, "(" + ASTStringUtil.join(sigArray, ", ") + ")"); } - + protected void isSignatureEqual(IASTDeclarator declarator, String expected) { String signature= ASTStringUtil.getSignatureString(declarator); assertEquals(expected, signature); } - + protected void isSignatureEqual(IASTDeclSpecifier declSpec, String str) { assertEquals(str, ASTStringUtil.getSignatureString(declSpec, null)); } - + protected void isSignatureEqual(IASTTypeId typeId, String str) { assertEquals(str, ASTStringUtil.getSignatureString(typeId.getDeclSpecifier(), typeId.getAbstractDeclarator())); } - + protected void isTypeEqual(IASTDeclarator decltor, String str) { assertEquals(str, ASTTypeUtil.getType(decltor)); } - + protected void isTypeEqual(IASTTypeId typeId, String str) { assertEquals(str, ASTTypeUtil.getType(typeId)); } - + protected void isTypeEqual(IType type, String str) { assertEquals(str, ASTTypeUtil.getType(type)); } - + protected void isParameterTypeEqual(IFunctionType fType, String str) { assertEquals(str, ASTTypeUtil.getParameterTypeString(fType)); } - + static protected class CNameResolver extends ASTVisitor { { shouldVisitNames = true; @@ -455,9 +455,9 @@ public class AST2BaseTest extends BaseTestCase { public int size() { return nameList.size(); - } + } } - + static protected class CPPNameResolver extends ASTVisitor { { shouldVisitNames = true; @@ -485,13 +485,13 @@ public class AST2BaseTest extends BaseTestCase { public int size() { return nameList.size(); - } + } } - + protected String getAboveComment() throws IOException { return getContents(1)[0].toString(); } - + protected CharSequence[] getContents(int sections) throws IOException { CTestPlugin plugin = CTestPlugin.getDefault(); if (plugin == null) @@ -508,14 +508,14 @@ public class AST2BaseTest extends BaseTestCase { } return clazz.cast(o); } - + protected static void assertField(IBinding binding, String fieldName, String ownerName) { assertInstance(binding, IField.class); assertEquals(fieldName, binding.getName()); ICompositeType struct = ((IField) binding).getCompositeTypeOwner(); assertEquals(ownerName, struct.getName()); } - + protected class BindingAssertionHelper { protected IASTTranslationUnit tu; protected String contents; @@ -568,7 +568,7 @@ public class AST2BaseTest extends BaseTestCase { IBinding binding= binding(section, len); if (binding instanceof IProblemBinding) { IProblemBinding problem= (IProblemBinding) binding; - fail("ProblemBinding for name: " + section.substring(0, len) + " (" + renderProblemID(problem.getID()) + ")"); + fail("ProblemBinding for name: " + section.substring(0, len) + " (" + renderProblemID(problem.getID()) + ")"); } if (binding == null) { fail("Null binding resolved for name: " + section.substring(0, len)); @@ -617,12 +617,12 @@ public class AST2BaseTest extends BaseTestCase { IASTName name = findImplicitName(section, len); final String selection = section.substring(0, len); assertNotNull("did not find \"" + selection + "\"", name); - + assertInstance(name, IASTImplicitName.class); IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent(); IASTImplicitName[] implicits = owner.getImplicitNames(); assertNotNull(implicits); - + if (implicits.length > 1) { boolean found = false; for (IASTImplicitName n : implicits) { @@ -633,34 +633,34 @@ public class AST2BaseTest extends BaseTestCase { } assertTrue(found); } - + assertEquals(selection, name.getRawSignature()); IBinding binding = name.resolveBinding(); assertNotNull(binding); assertInstance(binding, bindingClass); return (IASTImplicitName) name; } - + public void assertNoImplicitName(String section, int len) { IASTName name = findImplicitName(section, len); final String selection = section.substring(0, len); assertNull("found name \"" + selection + "\"", name); } - + public IASTImplicitName[] getImplicitNames(String section, int len) { IASTName name = findImplicitName(section, len); IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent(); IASTImplicitName[] implicits = owner.getImplicitNames(); return implicits; } - + public IASTName findName(String section, int len) { final int offset = contents.indexOf(section); assertTrue("Section \"" + section + "\" not found", offset >= 0); IASTNodeSelector selector = tu.getNodeSelector(null); return selector.findName(offset, len); } - + public IASTName findName(String context, String name) { if (context == null) { context = contents; @@ -718,7 +718,7 @@ public class AST2BaseTest extends BaseTestCase { } return "Unknown problem ID"; } - + public T assertNonProblem(String section, int len, Class... cs) { if (len <= 0) len += section.length(); @@ -750,10 +750,10 @@ public class AST2BaseTest extends BaseTestCase { final String selection = section.substring(0, len); assertNotNull("No AST name for \"" + selection + "\"", astName); assertEquals(selection, astName.getRawSignature()); - + IBinding binding = astName.resolveBinding(); assertNotNull("No binding for " + astName.getRawSignature(), binding); - + return astName.resolveBinding(); } @@ -761,10 +761,10 @@ public class AST2BaseTest extends BaseTestCase { IASTName astName = findName(context, name); assertNotNull("No AST name for \"" + name + "\"", astName); assertEquals(name, astName.getRawSignature()); - + IBinding binding = astName.resolveBinding(); assertNotNull("No binding for " + astName.getRawSignature(), binding); - + return astName.resolveBinding(); } } @@ -776,10 +776,10 @@ public class AST2BaseTest extends BaseTestCase { final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions) throws Exception { return parseAndCheckBindings(code, lang, useGnuExtensions, false); } - + final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions, boolean skipTrivialInitializers) throws Exception { - IASTTranslationUnit tu = parse(code, lang, useGnuExtensions, true, skipTrivialInitializers); + IASTTranslationUnit tu = parse(code, lang, useGnuExtensions, true, skipTrivialInitializers); CNameCollector col = new CNameCollector(); tu.accept(col); assertNoProblemBindings(col); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java index 2095a9e4b25..d73040b5422 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java @@ -33,15 +33,15 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { public AST2CPPImplicitNameTests() { } - + public AST2CPPImplicitNameTests(String name) { super(name); } - + public static TestSuite suite() { return suite(AST2CPPImplicitNameTests.class); } - + public IASTImplicitName[] getImplicitNames(IASTTranslationUnit tu, String contents, String section, int len) { final int offset = contents.indexOf(section); assertTrue(offset >= 0); @@ -76,25 +76,25 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { CPPNameCollector col = new CPPNameCollector(); tu.accept(col); IASTImplicitName n; - + n = ba.assertImplicitName("+= 5", 2, ICPPMethod.class); assertSame(n.resolveBinding(), col.getName(14).resolveBinding()); - + n = ba.assertImplicitName("+ p", 1, ICPPMethod.class); assertSame(n.resolveBinding(), col.getName(4).resolveBinding()); - + n = ba.assertImplicitName("- p", 1, ICPPMethod.class); assertSame(n.resolveBinding(), col.getName(8).resolveBinding()); - + n = ba.assertImplicitName("* p", 1, ICPPFunction.class); assertSame(n.resolveBinding(), col.getName(17).resolveBinding()); - + n = ba.assertImplicitName("/ p", 1, ICPPFunction.class); assertSame(n.resolveBinding(), col.getName(23).resolveBinding()); - + n = ba.assertImplicitName("-p;", 1, ICPPMethod.class); assertSame(n.resolveBinding(), col.getName(12).resolveBinding()); - + ba.assertNoImplicitName("<< 6", 2); ba.assertNoImplicitName("+p;", 1); } @@ -137,9 +137,9 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + ba.assertNoImplicitName("&Y::x;", 1); - + IASTImplicitName n = ba.assertImplicitName("&y;", 1, ICPPFunction.class); assertSame(n.resolveBinding(), col.getName(9).resolveBinding()); } @@ -166,20 +166,20 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { // p2->doA(); // } public void testArrowOperator() throws Exception { - String contents = getAboveComment(); + String contents = getAboveComment(); IASTTranslationUnit tu = parse(contents, ParserLanguage.CPP); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + IASTImplicitName[] implicits = getImplicitNames(tu, contents, "->doA();", 2); - + assertNotNull(implicits); assertEquals(2, implicits.length); - + assertSame(implicits[1].getBinding(), col.getName(4).resolveBinding()); assertSame(implicits[0].getBinding(), col.getName(12).resolveBinding()); } - + // struct A { // int x; // }; @@ -225,15 +225,15 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { ba.assertNoImplicitName(", b, c, d); // func", 1); ba.assertNoImplicitName(", c, d); // func", 1); ba.assertNoImplicitName(", d); // func", 1); - + IASTImplicitName opAB = ba.assertImplicitName(", b, c, d; // expr", 1, ICPPFunction.class); IASTImplicitName opCC = ba.assertImplicitName(", c, d; // expr", 1, ICPPFunction.class); ba.assertNoImplicitName(", d; // expr", 1); - + IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + assertSame(opAB.resolveBinding(), col.getName(5).resolveBinding()); assertSame(opCC.resolveBinding(), col.getName(11).resolveBinding()); } @@ -256,20 +256,20 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { // } public void testCommaOperator2() throws Exception { BindingAssertionHelper ba = new BindingAssertionHelper(getAboveComment(), true); - + IASTImplicitName opAB = ba.assertImplicitName(", b, c, d", 1, ICPPMethod.class); IASTImplicitName opCC = ba.assertImplicitName(", c, d", 1, ICPPFunction.class); IASTImplicitName opDD = ba.assertImplicitName(", d", 1, ICPPMethod.class); - + IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + // 6, 11, 15 assertSame(opAB.resolveBinding(), col.getName(6).resolveBinding()); assertSame(opCC.resolveBinding(), col.getName(15).resolveBinding()); assertSame(opDD.resolveBinding(), col.getName(11).resolveBinding()); - + ba.assertNonProblem("ee;", 2); } @@ -290,7 +290,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + IASTImplicitName n1 = ba.assertImplicitName("(b); // 1", 1, ICPPMethod.class); IASTImplicitName n2 = ba.assertImplicitName("); // 1", 1, ICPPMethod.class); assertSame(n1.resolveBinding(), n2.resolveBinding()); @@ -299,14 +299,14 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { // there should be no overlap ba.assertNoImplicitName("b); // 1", 1); assertSame(col.getName(1).resolveBinding(), n1.resolveBinding()); - + n1 = ba.assertImplicitName("(); // 2", 1, ICPPMethod.class); n2 = ba.assertImplicitName("); // 2", 1, ICPPMethod.class); assertSame(n1.resolveBinding(), n2.resolveBinding()); assertFalse(n1.isAlternate()); assertTrue(n2.isAlternate()); assertSame(col.getName(3).resolveBinding(), n1.resolveBinding()); - + n1 = ba.assertImplicitName("(1, 2); // 3", 1, ICPPMethod.class); n2 = ba.assertImplicitName("); // 3", 1, ICPPMethod.class); assertSame(n1.resolveBinding(), n2.resolveBinding()); @@ -349,7 +349,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + IASTImplicitName n1 = ba.assertImplicitName("[0]); //1", 1, ICPPMethod.class); ba.assertNoImplicitName("0]); //1", 1); IASTImplicitName n2 = ba.assertImplicitName("]); //1", 1, ICPPMethod.class); @@ -357,7 +357,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { assertFalse(n1.isAlternate()); assertTrue(n2.isAlternate()); assertSame(col.getName(1).resolveBinding(), n1.resolveBinding()); - + n1 = ba.assertImplicitName("[q]); //2", 1, ICPPMethod.class); ba.assertNoImplicitName("q]); //2", 1); n2 = ba.assertImplicitName("]); //2", 1, ICPPMethod.class); @@ -385,21 +385,21 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { assertEquals(2, names.length); IASTImplicitName destructor = names[0]; IASTImplicitName delete = names[1]; - + IASTTranslationUnit tu = ba.getTranslationUnit(); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); - + assertSame(col.getName(1).resolveBinding(), destructor.resolveBinding()); assertSame(col.getName(2).resolveBinding(), delete.resolveBinding()); - + names = ba.getImplicitNames("delete[] x;", 6); assertEquals(1, names.length); assertSame(col.getName(4).resolveBinding(), names[0].resolveBinding()); - + ba.assertNoImplicitName("delete 1;", 6); } - + // struct A { // void operator delete(void * a); // }; @@ -417,15 +417,15 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); IBinding m= bh.assertNonProblem("operator delete(void * a)", 15); IBinding f= bh.assertNonProblem("operator delete(void * b)", 15); - + IASTImplicitName[] names = bh.getImplicitNames("delete a;", 6); - assertEquals(2, names.length); + assertEquals(2, names.length); assertTrue(((ICPPMethod) names[0].resolveBinding()).isDestructor()); assertSame(m, names[1].resolveBinding()); names = bh.getImplicitNames("delete b;", 6); assertTrue(((ICPPMethod) names[0].resolveBinding()).isDestructor()); - assertEquals(2, names.length); + assertEquals(2, names.length); assertSame(f, names[1].resolveBinding()); } @@ -444,7 +444,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); IBinding m= bh.assertNonProblem("operator new(size_t a)", 12); IBinding f= bh.assertNonProblem("operator new(size_t b)", 12); - + IASTImplicitName[] names = bh.getImplicitNames("new A;", 3); assertEquals(2, names.length); assertSame(m, names[0].resolveBinding()); @@ -462,9 +462,9 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { public void testImplicitNewAndDelete() throws Exception { BindingAssertionHelper ba = new BindingAssertionHelper(getAboveComment(), true); ba.assertNoImplicitName("new X", 3); - ba.assertNoImplicitName("delete[]", 6); + ba.assertNoImplicitName("delete[]", 6); } - + // typedef long unsigned int size_t // struct nothrow_t {}; // extern const nothrow_t nothrow; @@ -492,7 +492,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { assertSame(col.getName(9).resolveBinding(), n2.resolveBinding()); assertSame(col.getName(14).resolveBinding(), n3.resolveBinding()); } - + // int test() { // throw; // } @@ -552,7 +552,7 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { IASTImplicitName v = ba.assertImplicitName("v(p)", 1, ICPPConstructor.class); assertSame(ctor1, v.resolveBinding()); } - + // enum A {aa}; // struct B{ operator A();}; // bool operator==(A, A); // overrides the built-in operator. @@ -568,5 +568,5 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { ICPPFunction op = ba.assertNonProblem("operator==", 0); IASTImplicitName a = ba.assertImplicitName("==b", 2, ICPPFunction.class); assertSame(op, a.resolveBinding()); - } + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 6b0c3082484..a369089ea8e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -260,7 +260,7 @@ public class AST2CPPTests extends AST2BaseTest { assertEquals(declNames.length, i); assertEquals(defNames.length, j); } - + @Override protected void assertSameType(IType first, IType second){ assertNotNull(first); @@ -8397,7 +8397,7 @@ public class AST2CPPTests extends AST2BaseTest { // TODO(nathanridge): Perhaps we should store implicit names even if they // resolve to ProblemBindings. Then we can do the stronger check in the // 3 commented lines below. - //IASTImplicitName n= bh.assertImplicitName("H({1})", 1, IProblemBinding.class); + //IASTImplicitName n= bh.assertImplicitName("H({1})", 1, IProblemBinding.class); //problem= (IProblemBinding) n.resolveBinding(); //assertEquals(IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, problem.getID()); bh.assertProblem("fH(1)", 2); @@ -9827,7 +9827,7 @@ public class AST2CPPTests extends AST2BaseTest { } // struct Base { - // virtual void mFuncDecl(); + // virtual void mFuncDecl(); // virtual void mFuncDef(){} // }; // struct S : public Base { @@ -9855,9 +9855,9 @@ public class AST2CPPTests extends AST2BaseTest { assertInstance(declarator, ICPPASTFunctionDeclarator.class); assertVirtualSpecifiers((ICPPASTFunctionDeclarator)declarator, true, false); } - + // struct Base { - // virtual void mFuncDecl(); + // virtual void mFuncDecl(); // virtual void mFuncDef(){} // }; // struct S : public Base { @@ -10029,7 +10029,7 @@ public class AST2CPPTests extends AST2BaseTest { // double vdouble; // long double vlongdouble; // UnscopedEnum vue; - // + // // // Narrowing conversions // fint({vdouble}); // ffloat({vlongdouble}); @@ -10087,7 +10087,7 @@ public class AST2CPPTests extends AST2BaseTest { helper.assertNonProblemOnFirstIdentifier("fint({vbool"); helper.assertNonProblemOnFirstIdentifier("fint({vchar"); } - + // namespace std { // struct string {}; // struct exception {}; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java index 8aa20c65a32..83486231a38 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java @@ -8,10 +8,6 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ - -/* - * Created on Sept 28, 2004 - */ package org.eclipse.cdt.core.parser.tests.ast2; import java.io.ByteArrayInputStream; @@ -44,7 +40,7 @@ public class AST2FileBasePluginTest extends TestCase { static IWorkspace workspace; static IProject project; static FileManager fileManager; - static int numProjects = 0; + static int numProjects; static Class className; static ICProject cPrj; @@ -55,100 +51,100 @@ public class AST2FileBasePluginTest extends TestCase { super(name); } - private void initialize(Class aClassName){ - if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){ + private void initialize(Class aClassName) { + if (CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null) { //(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset(); monitor = new NullProgressMonitor(); - + workspace = ResourcesPlugin.getWorkspace(); - + try { cPrj = CProjectHelper.createCCProject("AST2BasedProjectMofo", "bin", IPDOMManager.ID_NO_INDEXER); //$NON-NLS-1$ //$NON-NLS-2$ - + project = cPrj.getProject(); - + // ugly if (className == null || !className.equals(aClassName)) { className = aClassName; numProjects++; } - } catch ( CoreException e ) { - /*boo*/ + } catch (CoreException e) { + // Ignore } if (project == null) throw new NullPointerException("Unable to create project"); //$NON-NLS-1$ - - //Create file manager + + // Create file manager fileManager = new FileManager(); } } - public AST2FileBasePluginTest(String name, Class className) - { + public AST2FileBasePluginTest(String name, Class className) { super(name); initialize(className); } - + public void cleanupProject() throws Exception { numProjects--; - - try{ + + try { if (numProjects == 0) { - project.delete( true, false, monitor ); + project.delete(true, false, monitor); project = null; } - } catch( Throwable e ){ - /*boo*/ + } catch (Throwable e) { + // Ignore } } @Override protected void tearDown() throws Exception { - if( project == null || !project.exists() ) + if (project == null || !project.exists()) return; - - IResource [] members = project.members(); - for( int i = 0; i < members.length; i++ ){ - if( members[i].getName().equals( ".project" ) || members[i].getName().equals( ".cproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$ + + IResource[] members = project.members(); + for (int i = 0; i < members.length; i++) { + if (members[i].getName().equals(".project") || members[i].getName().equals(".cproject")) //$NON-NLS-1$ //$NON-NLS-2$ continue; if (members[i].getName().equals(".settings")) continue; - try{ - members[i].delete( false, monitor ); - } catch( Throwable e ){ - /*boo*/ + try { + members[i].delete(false, monitor); + } catch (Throwable e) { + // Ignore } } } protected IFolder importFolder(String folderName) throws Exception { IFolder folder = project.getProject().getFolder(folderName); - - //Create file input stream - if( !folder.exists() ) - folder.create( false, false, monitor ); - + + // Create file input stream + if (!folder.exists()) + folder.create(false, false, monitor); + return folder; } - public IFile importFile(String fileName, String contents ) throws Exception{ - //Obtain file handle + + public IFile importFile(String fileName, String contents) throws Exception { + // Obtain file handle IFile file = project.getProject().getFile(fileName); - - InputStream stream = new ByteArrayInputStream( contents.getBytes() ); - //Create file input stream - if( file.exists() ) - file.setContents( stream, false, false, monitor ); - else - file.create( stream, false, monitor ); - + + InputStream stream = new ByteArrayInputStream(contents.getBytes()); + // Create file input stream + if (file.exists()) { + file.setContents(stream, false, false, monitor); + } else { + file.create(stream, false, monitor); + } + fileManager.addFile(file); - + return file; } - + protected StringBuilder[] getContents(int sections) throws IOException { return TestSourceReader.getContentsForTest( CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), sections); } - } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index cb6cd028342..64c80b39a55 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -6221,24 +6221,24 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testSimpleAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); - + ICPPClassType S = assertionHelper.assertNonProblem("struct S {", "S", ICPPClassType.class); ICPPField x = assertionHelper.assertNonProblem("int x", "x", ICPPField.class); ITypedef Alias = assertionHelper.assertNonProblem("using Alias = S", "Alias", ITypedef.class); IFunction foo = assertionHelper.assertNonProblem("void foo() {", "foo", IFunction.class); IVariable myA = assertionHelper.assertNonProblem("Alias myA", "myA", IVariable.class); - - + + assertInstances(collector, S, 2); assertInstances(collector, x, 2); assertInstances(collector, Alias, 2); assertInstances(collector, foo, 1); assertInstances(collector, myA, 2); } - + // template // struct S { // T x; @@ -6250,7 +6250,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testSpecifiedTemplateAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); @@ -6259,7 +6259,7 @@ public class AST2TemplateTests extends AST2BaseTest { ITypedef Alias = assertionHelper.assertNonProblem("using Alias = S;", "Alias", ITypedef.class); IVariable myA = assertionHelper.assertNonProblem("Alias myA;", "myA", IVariable.class); ICPPSpecialization xRef = assertionHelper.assertNonProblem("myA.x = 42;", "x", ICPPSpecialization.class); - + assertInstances(collector, S, 2); assertInstances(collector, Alias, 2); @@ -6275,13 +6275,13 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasBasicType() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); - + ICPPAliasTemplate Alias = assertionHelper.assertNonProblem("using Alias = int;", "Alias", ICPPAliasTemplate.class); ICPPAliasTemplateInstance aliasFloatInstance = assertionHelper.assertNonProblem("Alias myA;", "Alias", ICPPAliasTemplateInstance.class); - + assertInstances(collector, Alias, 2); assertSameType(aliasFloatInstance, new CPPBasicType(IBasicType.Kind.eInt, 0)); } @@ -6298,7 +6298,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); @@ -6336,9 +6336,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasDeclarationMultipleParameters() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField t1 = assertionHelper.assertNonProblem("T1 t1;", "t1", ICPPField.class); ICPPField t2 = assertionHelper.assertNonProblem("T2 t2;", "t2", ICPPField.class); ICPPField t3 = assertionHelper.assertNonProblem("T3 t3;", "t3", ICPPField.class); @@ -6379,9 +6379,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasDeclarationTemplateArgument() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class); ICPPAliasTemplateInstance TAliasSInt = assertionHelper.assertNonProblem("TAlias> myA;", "TAlias>", ICPPAliasTemplateInstance.class); ICPPSpecialization tRef = assertionHelper.assertNonProblem("myA.t = S()", "t", ICPPSpecialization.class); @@ -6402,9 +6402,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasAsTemplateArgument() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class); ICPPTemplateInstance STAliasInt = assertionHelper.assertNonProblem("S> myA;", "S>", ICPPTemplateInstance.class); ICPPSpecialization tRef = assertionHelper.assertNonProblem("myA.t = S();", "t", ICPPSpecialization.class); @@ -6425,9 +6425,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasDeclarationValueArgument() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField buff = assertionHelper.assertNonProblem("int buff [Size];", "buff", ICPPField.class); ICPPSpecialization buffRef = assertionHelper.assertNonProblem("myA.buff[0] = 1;", "buff", ICPPSpecialization.class); @@ -6448,9 +6448,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasDefaultArguments() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField buff = assertionHelper.assertNonProblem("T buff [Size];", "buff", ICPPField.class); ICPPAliasTemplateInstance myA = assertionHelper.assertNonProblem("TAlias<> myA;", "TAlias<>", ICPPAliasTemplateInstance.class); ICPPSpecialization buffRef = assertionHelper.assertNonProblem("myA.buff[0] = 1;", "buff", ICPPSpecialization.class); @@ -6472,9 +6472,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasTemplateArgument() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class); ICPPSpecialization tRef = assertionHelper.assertNonProblem(" myA.t = S();", "t", ICPPSpecialization.class); ICPPClassSpecialization Sint = assertionHelper.assertNonProblem("myA.t = S();", "S", ICPPClassSpecialization.class); @@ -6499,9 +6499,9 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasAsFunctionParameter() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - + ICPPFunction bar = assertionHelper.assertNonProblem("void bar(TAlias arg){", "bar", ICPPFunction.class); ICPPFunction barRefAlias = assertionHelper.assertNonProblem("bar(myA);", "bar", ICPPFunction.class); ICPPFunction barRefSInt = assertionHelper.assertNonProblem("bar(myS);", "bar", ICPPFunction.class); @@ -6524,7 +6524,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasAsFunctionArgument() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); ICPPFunction bar = assertionHelper.assertNonProblem("void bar(S arg){", "bar", ICPPFunction.class); @@ -6573,7 +6573,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testSimpleFunctionAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); @@ -6598,7 +6598,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasForTemplateReference() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); ICPPClassSpecialization SInt = assertionHelper.assertNonProblem("S myS;", "S", ICPPClassSpecialization.class); @@ -6614,7 +6614,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testSimpleFunctionTemplateAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); @@ -6634,7 +6634,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testSimpleFunctionReferenceTemplateAliasDeclaration() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); CPPNameCollector collector = getCPPNameCollector(assertionHelper.getTranslationUnit()); @@ -6659,7 +6659,7 @@ public class AST2TemplateTests extends AST2BaseTest { // } public void testTemplatedAliasTemplateParameter() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); ICPPField t = assertionHelper.assertNonProblem("T t;", "t", ICPPField.class); @@ -6682,10 +6682,11 @@ public class AST2TemplateTests extends AST2BaseTest { // Alias intAlias; public void testAliasDeclarationContext() throws Exception { parseAndCheckBindings(); - + BindingAssertionHelper assertionHelper = getAssertionHelper(); - ICPPAliasTemplateInstance AliasInt = assertionHelper.assertNonProblem("Alias intAlias;", "Alias", ICPPAliasTemplateInstance.class); + ICPPAliasTemplateInstance AliasInt = + assertionHelper.assertNonProblem("Alias intAlias;", "Alias", ICPPAliasTemplateInstance.class); assertEquals("Alias", AliasInt.getName()); assertEquals("NS", AliasInt.getQualifiedName()[0]); assertEquals("Alias", AliasInt.getQualifiedName()[1]); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index e8474a74621..8ed4bb367a9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Nathan Ridge + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -755,7 +755,7 @@ public class CompleteParser2Tests extends BaseTestCase { } public void testConstructorChain() throws Exception { - IASTTranslationUnit tu = parse("int x = 5;\n class A \n{ public : \n int a; \n A() : a(x) { } };"); + IASTTranslationUnit tu = parse("int x = 5;\n class A \n{ public : \n int a; \n A() : a(x) { } };"); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1058,7 +1058,7 @@ public class CompleteParser2Tests extends BaseTestCase { } public void testScoping() throws Exception { - IASTTranslationUnit tu = parse("void foo() { int x = 3; if (x == 1) { int x = 4; } else int x = 2; }"); + IASTTranslationUnit tu = parse("void foo() { int x = 3; if (x == 1) { int x = 4; } else int x = 2; }"); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1103,7 +1103,7 @@ public class CompleteParser2Tests extends BaseTestCase { } public void testBug42872() throws Exception { - IASTTranslationUnit tu = parse("struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast(dp); }"); + IASTTranslationUnit tu = parse("struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast(dp); }"); CPPNameCollector col = new CPPNameCollector(); tu.accept(col); @@ -1293,7 +1293,7 @@ public class CompleteParser2Tests extends BaseTestCase { public void testCDesignatedInitializers() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append("struct Inner { int a,b,c; };"); + buffer.append("struct Inner { int a,b,c; };"); buffer.append("struct A { int x; int y[]; struct Inner innerArray[]; int z[]; };"); buffer.append("struct A myA = { .x = 4, .y[3] = 4, .y[4] = 3, .innerArray[0].a = 3, .innerArray[1].b = 5, .innerArray[2].c=6, .z = { 1,4,5} };"); parse(buffer.toString(), true, ParserLanguage.C); @@ -1319,7 +1319,7 @@ public class CompleteParser2Tests extends BaseTestCase { " _Bool b; " + " f(b);" + " f(g((_Bool) 1) );" + - "}", + "}", true, ParserLanguage.C); } @@ -1342,7 +1342,7 @@ public class CompleteParser2Tests extends BaseTestCase { public void testBug44925() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append("class MyClass { };"); + buffer.append("class MyClass { };"); buffer.append("class MyClass myObj1;"); buffer.append("enum MyEnum { Item1 };"); buffer.append("enum MyEnum myObj2;"); @@ -1999,7 +1999,7 @@ public class CompleteParser2Tests extends BaseTestCase { writer.write("int main(int argc, char **argv) {\n"); writer.write("FILE * file = 0;\n"); writer.write("static_function(file);\n"); - writer.write("return 0;\n"); + writer.write("return 0;\n"); writer.write("}\n"); parse(writer.toString()); } @@ -2051,8 +2051,8 @@ public class CompleteParser2Tests extends BaseTestCase { writer.write("};\n"); writer.write("\n"); writer.write("template\n"); - writer.write("inline T526026< T >\n"); - writer.write("operator+(typename T526026::diff d, const T526026 & x)\n"); + writer.write("inline T526026< T >\n"); + writer.write("operator+(typename T526026::diff d, const T526026 & x)\n"); writer.write("{ return T526026< T >(); }\n"); writer.write("}\n"); parse(writer.toString(), false); @@ -2060,7 +2060,7 @@ public class CompleteParser2Tests extends BaseTestCase { public void testBug71094() throws Exception { Writer writer = new StringWriter(); - writer.write("using namespace DOESNOTEXIST;\n"); + writer.write("using namespace DOESNOTEXIST;\n"); writer.write("class A { int x; };\n"); parse(writer.toString(), false); } @@ -2228,7 +2228,7 @@ public class CompleteParser2Tests extends BaseTestCase { public void testBug74328() throws Exception { Writer writer = new StringWriter(); - writer.write("int\n"); + writer.write("int\n"); writer.write("main(int argc, char **argv) {\n"); writer.write(" char *sign;\n"); writer.write("sign = \"\"; // IProblem generated here, syntax error\n"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java index ac21a5487f7..a3bb7c210ef 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Nathan Ridge + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -38,7 +38,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.model.CProject; import org.eclipse.core.resources.IFile; @@ -58,8 +57,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { super(name, DOMSelectionParseTest.class); } - public void testBaseCase_VariableReference() throws Exception - { + public void testBaseCase_VariableReference() throws Exception { String code = "void f() { int x; x=3; }"; //$NON-NLS-1$ int offset1 = code.indexOf( "x=" ); //$NON-NLS-1$ int offset2 = code.indexOf( '='); @@ -74,8 +72,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - public void testBaseCase_FunctionReference() throws Exception - { + public void testBaseCase_FunctionReference() throws Exception { String code = "int x(){x( );}"; //$NON-NLS-1$ int offset1 = code.indexOf( "x( " ); //$NON-NLS-1$ int offset2 = code.indexOf( "( )"); //$NON-NLS-1$ @@ -89,17 +86,15 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - - public void testBaseCase_Error() throws Exception - { + + public void testBaseCase_Error() throws Exception { String code = "int x() { y( ) }"; //$NON-NLS-1$ int offset1 = code.indexOf( "y( " ); //$NON-NLS-1$ int offset2 = code.indexOf( "( )"); //$NON-NLS-1$ assertNull( parse( code, offset1, offset2, false )); } - - public void testBaseCase_FunctionDeclaration() throws Exception - { + + public void testBaseCase_FunctionDeclaration() throws Exception { String code = "int x(); void test() {x( );}"; //$NON-NLS-1$ int offset1 = code.indexOf( "x( )" ); //$NON-NLS-1$ int offset2 = code.indexOf( "( )"); //$NON-NLS-1$ @@ -113,9 +108,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - - public void testBaseCase_FunctionDeclaration2() throws Exception - { + + public void testBaseCase_FunctionDeclaration2() throws Exception { String code = "int printf( const char *, ... ); "; //$NON-NLS-1$ int offset1 = code.indexOf( "printf" ); //$NON-NLS-1$ int offset2 = code.indexOf( "( const"); //$NON-NLS-1$ @@ -125,8 +119,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((IASTName)node).toString(), "printf" ); //$NON-NLS-1$ } - public void testBaseCase_VariableDeclaration() throws Exception - { + public void testBaseCase_VariableDeclaration() throws Exception { String code = "int x = 3;"; //$NON-NLS-1$ int offset1 = code.indexOf( "x" ); //$NON-NLS-1$ int offset2 = code.indexOf( " ="); //$NON-NLS-1$ @@ -136,9 +129,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "x" ); //$NON-NLS-1$ } - - public void testBaseCase_Parameter() throws Exception - { + + public void testBaseCase_Parameter() throws Exception { String code = "int main( int argc ) { int x = argc; }"; //$NON-NLS-1$ int offset1 = code.indexOf( "argc;" ); //$NON-NLS-1$ int offset2 = code.indexOf( ";" ); //$NON-NLS-1$ @@ -153,9 +145,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 14); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - - public void testBug57898() throws Exception - { + + public void testBug57898() throws Exception { Writer writer = new StringWriter(); writer.write( "class Gonzo { public: void playHorn(); };\n" ); //$NON-NLS-1$ writer.write( "void Gonzo::playHorn() { return; }\n" ); //$NON-NLS-1$ @@ -189,9 +180,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getLength(), 8); } } - - public void testConstructorDestructorDeclaration() throws Exception - { + + public void testConstructorDestructorDeclaration() throws Exception { Writer writer = new StringWriter(); writer.write( "class Gonzo { Gonzo(); ~Gonzo(); };"); //$NON-NLS-1$ String code = writer.toString(); @@ -201,16 +191,15 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPConstructor ); assertEquals( ((IASTName)node).toString(), "Gonzo" ); //$NON-NLS-1$ - + offset = code.indexOf( "~Gonzo"); //$NON-NLS-1$ node = parse( code, offset, offset + 6 ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "~Gonzo" ); //$NON-NLS-1$ - } - - public void testBug60264() throws Exception - { + } + + public void testBug60264() throws Exception { Writer writer = new StringWriter(); writer.write( "namespace Muppets { int i; }\n" ); //$NON-NLS-1$ writer.write( "int main(int argc, char **argv) { Muppets::i = 1; }\n" ); //$NON-NLS-1$ @@ -238,9 +227,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 10); assertEquals( ((ASTNode)decls[0]).getLength(), 7); } - - public void testBug61613() throws Exception - { + + public void testBug61613() throws Exception { Writer writer = new StringWriter(); writer.write( "class Foo { // ** (A) **\n" ); //$NON-NLS-1$ writer.write( " public:\n" ); //$NON-NLS-1$ @@ -262,9 +250,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 6); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - - public void testBug60038() throws Exception - { + + public void testBug60038() throws Exception { Writer writer = new StringWriter(); writer.write( "class Gonzo {\n"); //$NON-NLS-1$ writer.write( "public:\n"); //$NON-NLS-1$ @@ -315,7 +302,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 53); assertEquals( ((ASTNode)decls[0]).getLength(), 5); break; - case 1: + case 1: assertTrue( binding instanceof ICPPConstructor ); decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); @@ -323,7 +310,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 22); assertEquals( ((ASTNode)decls[0]).getLength(), 5); break; - default: + default: assertFalse( binding instanceof ICPPConstructor ); String name = ((IASTName)node).toString(); assertEquals( name.indexOf("~"), 0); //$NON-NLS-1$ @@ -334,13 +321,12 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 64); assertEquals( ((ASTNode)decls[0]).getLength(), 6); break; - + } } } - - public void testMethodReference() throws Exception - { + + public void testMethodReference() throws Exception { Writer writer = new StringWriter(); writer.write( "class Sample { public:\n"); //$NON-NLS-1$ writer.write( " int getAnswer() const;\n"); //$NON-NLS-1$ @@ -361,9 +347,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 29); assertEquals( ((ASTNode)decls[0]).getLength(), 9); } - - public void testConstructorDefinition() throws Exception - { + + public void testConstructorDefinition() throws Exception { String code = "class ABC { public: ABC(); }; ABC::ABC(){}"; //$NON-NLS-1$ int startIndex = code.indexOf( "::ABC") + 2; //$NON-NLS-1$ IASTNode node = parse( code, startIndex, startIndex + 3 ); @@ -376,9 +361,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 20); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - - public void testBug63966() throws Exception - { + + public void testBug63966() throws Exception { Writer writer = new StringWriter(); writer.write( "void foo(int a) {}\n" ); //$NON-NLS-1$ writer.write( "void foo(long a) {}\n" ); //$NON-NLS-1$ @@ -388,22 +372,20 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { int startIndex = code.indexOf( "foo(1)"); //$NON-NLS-1$ parse( code, startIndex, startIndex + 3 ); } - - public void testBug66744() throws Exception - { + + public void testBug66744() throws Exception { Writer writer = new StringWriter(); writer.write( "enum EColours { RED, GREEN, BLUE }; \n" ); //$NON-NLS-1$ writer.write( "void foo() { EColours color = GREEN; } \n" ); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "EColours color"); //$NON-NLS-1$ parse( code, startIndex, startIndex + 8 ); } - - - public void testBug68527() throws Exception - { + + + public void testBug68527() throws Exception { Writer writer = new StringWriter(); writer.write("struct X;\n"); //$NON-NLS-1$ writer.write("struct X anA;"); //$NON-NLS-1$ @@ -412,8 +394,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { parse( code, startIndex, startIndex + 1 ); } - public void testBug60407() throws Exception - { + public void testBug60407() throws Exception { Writer writer = new StringWriter(); writer.write( "struct ZZZ { int x, y, z; };\n" ); //$NON-NLS-1$ writer.write( "typedef struct ZZZ _FILE;\n" ); //$NON-NLS-1$ @@ -428,9 +409,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { int startIndex = code.indexOf( "static_function( file )"); //$NON-NLS-1$ parse( code, startIndex, startIndex + "static_function".length() ); //$NON-NLS-1$ } - - public void testBug61800() throws Exception - { + + public void testBug61800() throws Exception { Writer writer = new StringWriter(); writer.write( "class B {};\n"); //$NON-NLS-1$ writer.write( "class ABCDEF {\n"); //$NON-NLS-1$ @@ -449,27 +429,25 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 37); assertEquals( ((ASTNode)decls[0]).getLength(), 5); } - - public void testBug68739() throws Exception - { + + public void testBug68739() throws Exception { Writer writer = new StringWriter(); writer.write( "int fprintf( int *, const char *, ... ); \n" ); //$NON-NLS-1$ writer.write( "void boo( int * lcd ) { \n" ); //$NON-NLS-1$ writer.write( " /**/fprintf( lcd, \"%c%s 0x%x\", ' ', \"bbb\", 2 ); \n" ); //$NON-NLS-1$ writer.write( "} \n" ); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "/**/fprintf") + 4; //$NON-NLS-1$ IASTNode node = parse( code, startIndex, startIndex+ 7 ); - + assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IFunction ); assertEquals( ((IASTName)node).toString(), "fprintf" ); //$NON-NLS-1$ } - - public void testBug72818() throws Exception - { + + public void testBug72818() throws Exception { Writer writer = new StringWriter(); writer.write( "union Squaw { int x; double u; };\n" ); //$NON-NLS-1$ writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ @@ -488,9 +466,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 6); assertEquals( ((ASTNode)decls[0]).getLength(), 5); } - - public void test72220() throws Exception - { + + public void test72220() throws Exception { Writer writer = new StringWriter(); writer.write( "const int FOUND_ME = 1;\n" ); //$NON-NLS-1$ writer.write( "class Test{\n" ); //$NON-NLS-1$ @@ -512,7 +489,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 10); assertEquals( ((ASTNode)decls[0]).getLength(), 8); } - + public void testBug72721() throws Exception{ Writer writer = new StringWriter(); writer.write(" class ABC { public: ABC(int); }; \n"); //$NON-NLS-1$ @@ -520,7 +497,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write(" int j = 1; \n"); //$NON-NLS-1$ writer.write(" new ABC( j + 1 ); \n"); //$NON-NLS-1$ writer.write("} \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "ABC(" ); //$NON-NLS-1$ IASTNode node = parse( code, startIndex, startIndex + 3 ); @@ -533,7 +510,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 21); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - + public void testBug72372() throws Exception{ Writer writer = new StringWriter(); writer.write("namespace B { \n"); //$NON-NLS-1$ @@ -541,7 +518,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("} \n"); //$NON-NLS-1$ writer.write("using namespace B; \n"); //$NON-NLS-1$ writer.write("void SD_02::f_SD(){} \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( ":f_SD" ); //$NON-NLS-1$ IASTNode node = parse( code, startIndex + 1, startIndex + 5 ); @@ -565,7 +542,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write(" using namespace A; \n"); //$NON-NLS-1$ writer.write("} \n"); //$NON-NLS-1$ writer.write("void C::B::f_SD(){} \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( ":f_SD" ); //$NON-NLS-1$ IASTNode node = parse( code, startIndex + 1, startIndex + 5 ); @@ -578,12 +555,12 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 109); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - + public void testBug72713() throws Exception{ Writer writer = new StringWriter(); writer.write( "class Deck{ void initialize(); }; \n"); //$NON-NLS-1$ writer.write( "void Deck::initialize(){} \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( ":initialize" ); //$NON-NLS-1$ IASTNode node = parse( code, startIndex + 1, startIndex + 11 ); @@ -596,14 +573,14 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 17); assertEquals( ((ASTNode)decls[0]).getLength(), 10); } - + public void testBug72712() throws Exception{ Writer writer = new StringWriter(); writer.write( "class B{ public: B(); }; void f(){ B* b; b = new B(); }" ); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "new B" ) + 4; //$NON-NLS-1$ - + IASTNode node = parse( code, startIndex, startIndex + 1 ); node = TestUtil.findImplicitName(node); assertTrue( node instanceof IASTName ); @@ -615,16 +592,16 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( 17, ((ASTNode)decls[0]).getOffset() ); assertEquals( 1, ((ASTNode)decls[0]).getLength() ); } - + public void testBug72712_2() throws Exception{ Writer writer = new StringWriter(); writer.write( "class A {}; \n"); //$NON-NLS-1$ writer.write( "class B{ public: B( A* ); }; \n"); //$NON-NLS-1$ writer.write( "void f(){ B* b; b = new B( (A*)0 ); } \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "(A*)" ) + 1; //$NON-NLS-1$ - + IASTNode node = parse( code, startIndex, startIndex + 1 ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPClassType ); @@ -635,7 +612,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 6); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - + public void testBug72814() throws Exception{ CPPASTNameBase.sAllowNameComputation= true; @@ -644,11 +621,11 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write( " template < class T > class AAA { T _t; };\n"); //$NON-NLS-1$ writer.write( "} \n"); //$NON-NLS-1$ writer.write( "N::AAA a; \n"); //$NON-NLS-1$ - + String code = writer.toString(); int startIndex = code.indexOf( "AAA" ); //$NON-NLS-1$ IASTNode node = parse( code, startIndex, startIndex + 3 ); - + assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPClassType ); assertEquals( ((IASTName)node).toString(), "AAA" ); //$NON-NLS-1$ @@ -657,9 +634,9 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "AAA" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 75); assertEquals( ((ASTNode)decls[0]).getLength(), 3); - + node = parse( code, startIndex, startIndex + 8 ); - + assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPClassType ); assertEquals( ((IASTName)node).toString(), "AAA" ); //$NON-NLS-1$ @@ -670,9 +647,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { // assertEquals( ((ASTNode)decls[0]).getOffset(), 15); // assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - - public void testBug72710() throws Exception - { + + public void testBug72710() throws Exception { Writer writer = new StringWriter(); writer.write( "class Card{\n" ); //$NON-NLS-1$ writer.write( " Card( int rank );\n" ); //$NON-NLS-1$ @@ -693,9 +669,9 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 36); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - - - public void testBug75731() throws Exception + + + public void testBug75731() throws Exception { Writer writer = new StringWriter(); writer.write("int rank() {\n"); //$NON-NLS-1$ @@ -712,7 +688,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("this->rank = rank;\n"); //$NON-NLS-1$ writer.write("this->rank = Card::rank;\n"); //$NON-NLS-1$ writer.write("this->rank = getRank();\n}\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf( "int rank() {") + 4; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 4 ); @@ -725,7 +701,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "class Card{") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -737,7 +713,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "Card" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 31); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "Card( int rank );"); //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -749,7 +725,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "Card" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 46); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "Card( int rank );") + 10; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -773,7 +749,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "int getRank();") + 4; //$NON-NLS-1$ node = parse( code, index, index + 7 ); assertTrue( node instanceof IASTName ); @@ -785,7 +761,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "getRank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 86); assertEquals( ((ASTNode)decls[0]).getLength(), 7); - + index = code.indexOf( "Card::Card( int rank )"); //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -797,7 +773,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "Card" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 31); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "Card::Card( int rank )") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -809,7 +785,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "Card" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 46); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "Card::Card( int rank )") + 16; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -821,7 +797,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 56); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = ::rank();") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -833,7 +809,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = ::rank();") + 15; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -845,7 +821,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = this->rank;") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -857,7 +833,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = this->rank;") + 19; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -869,7 +845,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = rank;") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -881,7 +857,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = rank;") + 13; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -893,7 +869,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 56); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = Card::rank;") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -905,7 +881,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = Card::rank;") + 19; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -917,7 +893,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = getRank();") + 6; //$NON-NLS-1$ node = parse( code, index, index + 4 ); assertTrue( node instanceof IASTName ); @@ -929,7 +905,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( decls[0].toString(), "rank" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 68); assertEquals( ((ASTNode)decls[0]).getLength(), 4); - + index = code.indexOf( "this->rank = getRank();") + 13; //$NON-NLS-1$ node = parse( code, index, index + 7 ); assertTrue( node instanceof IASTName ); @@ -949,7 +925,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("class C{};\n}\n"); //$NON-NLS-1$ writer.write("using namespace N; /* B */\n"); //$NON-NLS-1$ writer.write("N::C c; /* C */\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf( "using namespace N;") + 16; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1 ); @@ -966,9 +942,9 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { public void testBug78435() throws Exception { Writer writer = new StringWriter(); - writer.write("int itself; //A\n"); //$NON-NLS-1$ + writer.write("int itself; //A\n"); //$NON-NLS-1$ writer.write("void f(int itself){} //B\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf( "void f(int itself){}") + 11; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 6 ); @@ -988,7 +964,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("struct Base {\n"); //$NON-NLS-1$ writer.write("int Data; // 1\n"); //$NON-NLS-1$ writer.write("struct Data; // 2\n};\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf("struct Data;") + 7; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 4 ); @@ -1002,14 +978,14 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 36); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - + public void testBug78231B() throws Exception { Writer writer = new StringWriter(); writer.write("int Data;\n"); //$NON-NLS-1$ writer.write("struct Base {\n"); //$NON-NLS-1$ writer.write("int Data; // 1\n"); //$NON-NLS-1$ writer.write("struct Data; // 2\n};\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf("struct Data;") + 7; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 4 ); @@ -1018,7 +994,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((IASTName)node).toString(), "Data" ); //$NON-NLS-1$ assertEquals( ((ASTNode)node).getOffset(), index); } - + public void testBug64326() throws Exception { Writer writer = new StringWriter(); writer.write("class foo {\n"); //$NON-NLS-1$ @@ -1031,7 +1007,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("foo* f;\n"); //$NON-NLS-1$ writer.write("f->bar = 1; // ** (A) **\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); int index = code.indexOf("f->bar") + 3; //$NON-NLS-1$ IASTNode node = parse( code, index, index + 3 ); @@ -1044,7 +1020,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getOffset(), 33); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - + public void testBug92605() throws Exception { Writer writer = new StringWriter(); writer.write("#define UINT32 unsigned int\n"); //$NON-NLS-1$ @@ -1062,14 +1038,14 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IMacroBinding ); assertEquals( ((IASTName)node).toString(), "UINT32" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "UINT32" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 8); assertEquals( ((ASTNode)decls[0]).getLength(), 6); } - + public void testBug79877() throws Exception { Writer writer = new StringWriter(); writer.write("int Func2() {\n"); //$NON-NLS-1$ @@ -1079,27 +1055,27 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("}\n"); //$NON-NLS-1$ String code = writer.toString(); IFile test1 = importFile("test1.c", code); //$NON-NLS-1$ - + writer.write("int Func1(void) {\n"); //$NON-NLS-1$ writer.write("return(10);\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ importFile("test2.c", writer.toString()); //$NON-NLS-1$ - + int index = code.indexOf("Func1"); //$NON-NLS-1$ IASTNode node = parse( test1, index, index + 5, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICExternalBinding ); assertEquals( ((IASTName)node).toString(), "Func1" ); //$NON-NLS-1$ - + ICElement[] scope = new ICElement[1]; scope[0] = new CProject(null, project); // // TODO need to register to an index and wait for it to finish before this test will work -// +// // Set matches = SearchEngine.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), (IASTName)node, CSearchPattern.DECLARATIONS); // assertEquals(matches.size(), 1); } - + public void testBug78114() throws Exception { Writer writer = new StringWriter(); writer.write("class Point{ //line C\n"); //$NON-NLS-1$ @@ -1113,23 +1089,23 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("Point &p2 = *(new Point(10)); // line A\n"); //$NON-NLS-1$ writer.write("return (0);\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("Point(10)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 5, true ); node = TestUtil.findImplicitName(node); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName) node).resolveBinding() instanceof ICPPConstructor ); assertEquals( ((IASTName)node).toString(), "Point" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "Point" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 53); assertEquals( ((ASTNode)decls[0]).getLength(), 5); } - + public void testBug73398() throws Exception { Writer writer = new StringWriter(); writer.write("int joo=4;\n"); //$NON-NLS-1$ @@ -1137,22 +1113,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("int main(int argc, char **argv) {\n"); //$NON-NLS-1$ writer.write("return (koo);\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("koo);"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 3, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IMacroBinding ); assertEquals( ((IASTName)node).toString(), "koo" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "koo" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 19); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - + public void testBug() throws Exception { Writer writer = new StringWriter(); writer.write("class Point{ \n"); //$NON-NLS-1$ @@ -1168,22 +1144,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("p2->operator=(zero); // line B\n"); //$NON-NLS-1$ writer.write("return (0); \n"); //$NON-NLS-1$ writer.write(" }\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("operator=(zero)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 9, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "operator =" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "operator =" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 51); assertEquals( ((ASTNode)decls[0]).getLength(), 9); } - + public void testBug80826() throws Exception { Writer writer = new StringWriter(); writer.write("void swapImpl(int& a, int& b) {/*...*/} // line C\n"); //$NON-NLS-1$ @@ -1194,22 +1170,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("swap(x,y); // line A\n"); //$NON-NLS-1$ writer.write(" //...\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("swap(x,y);"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 4, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IMacroBinding ); assertEquals( ((IASTName)node).toString(), "swap" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "swap" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 58); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - + public void testBug78389() throws Exception { Writer writer = new StringWriter(); writer.write("class A{\n"); //$NON-NLS-1$ @@ -1220,22 +1196,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("A a; \n"); //$NON-NLS-1$ writer.write("a.method1(3); // F3 on method1 in this line should highlight method1 on line B\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("method1(3)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 7, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "method1" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "method1" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 41); assertEquals( ((ASTNode)decls[0]).getLength(), 7); } - + public void testBug78625() throws Exception { Writer writer = new StringWriter(); writer.write("class A{ \n"); //$NON-NLS-1$ @@ -1244,22 +1220,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("class B: A{\n"); //$NON-NLS-1$ writer.write("B():A(2) {} //line 5\n"); //$NON-NLS-1$ writer.write("};\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("A(2)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPConstructor ); assertEquals( ((IASTName)node).toString(), "A" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "A" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 29); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - + public void testBug78656() throws Exception { Writer writer = new StringWriter(); writer.write("class A{\n"); //$NON-NLS-1$ @@ -1269,41 +1245,41 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("A a;\n"); //$NON-NLS-1$ writer.write("int i=a.method1(); //line 6\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("method1();"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 7, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "method1" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "method1" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 21); assertEquals( ((ASTNode)decls[0]).getLength(), 7); } - + public void testBug79965() throws Exception { Writer writer = new StringWriter(); writer.write("int i = 2, half_i = i / 2;\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("i / 2"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "i" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "i" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - + public void testBug64326A() throws Exception { Writer writer = new StringWriter(); writer.write("class foo {\n"); //$NON-NLS-1$ @@ -1316,22 +1292,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("foo* f;\n"); //$NON-NLS-1$ writer.write("f->bar(); // ** (A) **\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("bar();"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 3, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "bar" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "bar" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 34); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - + public void testBug64326B() throws Exception { Writer writer = new StringWriter(); writer.write("class foo {\n"); //$NON-NLS-1$ @@ -1344,22 +1320,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("foo* f;\n"); //$NON-NLS-1$ writer.write("f->bar = 1; // ** (A) **\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("bar = "); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 3, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPField ); assertEquals( ((IASTName)node).toString(), "bar" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "bar" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 33); assertEquals( ((ASTNode)decls[0]).getLength(), 3); } - + public void testBug43128A() throws Exception { Writer writer = new StringWriter(); writer.write("void foo()\n"); //$NON-NLS-1$ @@ -1368,44 +1344,44 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write(" // ...\n"); //$NON-NLS-1$ writer.write("x++;\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("x++"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "x" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "x" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 17); assertEquals( ((ASTNode)decls[0]).getLength(), 1); } - + public void testBug43128B() throws Exception { Writer writer = new StringWriter(); writer.write("int\n"); //$NON-NLS-1$ writer.write("main(int argc, char **argv) {\n"); //$NON-NLS-1$ writer.write("int x = argc;\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("argc;"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 4, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IParameter ); assertEquals( ((IASTName)node).toString(), "argc" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "argc" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 13); assertEquals( ((ASTNode)decls[0]).getLength(), 4); } - + public void testBug43128C() throws Exception { Writer writer = new StringWriter(); writer.write("int j;\n"); //$NON-NLS-1$ @@ -1418,44 +1394,44 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("}\n"); //$NON-NLS-1$ String code = writer.toString(); - + int index = code.indexOf("x ="); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "x" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "x" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 19); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - + index = code.indexOf("j ="); //$NON-NLS-1$ node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "j" ); //$NON-NLS-1$ - + decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "j" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 4); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - + index = code.indexOf("y ="); //$NON-NLS-1$ node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "y" ); //$NON-NLS-1$ - + decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "y" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 30); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - } - + } + public void testBug86504() throws Exception { Writer writer = new StringWriter(); writer.write("class C { };\n"); //$NON-NLS-1$ @@ -1465,21 +1441,21 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("void foo() {\n"); //$NON-NLS-1$ writer.write("f(g); // openDeclarations on g causes StackOverflowError\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("g); "); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPFunction ); assertEquals( ((IASTName)node).toString(), "g" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "g" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 89); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - } + } public void testBug79811() throws Exception { Writer writer = new StringWriter(); @@ -1489,21 +1465,21 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("E e; //this one is incorrectly found\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ writer.write("E f; //ok\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("E{E0}"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IEnumeration ); assertEquals( ((IASTName)node).toString(), "E" ); //$NON-NLS-1$ - + IName[] decls = getReferencesOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "E" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 76); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - } + } public void testBugLabelWithMacro() throws Exception { Writer writer = new StringWriter(); @@ -1519,32 +1495,32 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("goto test;\n"); //$NON-NLS-1$ writer.write("return foo();\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("HANDLE h"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 6, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IMacroBinding ); assertEquals( ((IASTName)node).toString(), "HANDLE" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "HANDLE" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 36); assertEquals( ((ASTNode)decls[0]).getLength(), 6); - + index = code.indexOf("test;"); //$NON-NLS-1$ node = parse( code, index, index + 4, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ILabel ); assertEquals( ((IASTName)node).toString(), "test" ); //$NON-NLS-1$ - + decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "test" ); //$NON-NLS-1$ assertLocation(code, "test:", 4, decls[0]); - } + } public void testBugMethodDef() throws Exception { Writer writer = new StringWriter(); @@ -1560,28 +1536,28 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("void tetrahedron::set() {\n"); //$NON-NLS-1$ writer.write("int color;\n"); //$NON-NLS-1$ writer.write("setColor(color);\n"); //$NON-NLS-1$ - writer.write("}\n"); //$NON-NLS-1$ - + writer.write("}\n"); //$NON-NLS-1$ + String code = writer.toString(); - + int index = code.indexOf("setColor(color)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 8, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPMethod ); assertEquals( ((IASTName)node).toString(), "setColor" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "setColor" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 67); assertEquals( ((ASTNode)decls[0]).getLength(), 8); - + IName[] refs = getReferencesOffTU((IASTName)node); assertEquals(refs.length, 1); assertEquals( refs[0].toString(), "setColor" ); //$NON-NLS-1$ assertEquals( ((ASTNode)refs[0]).getOffset(), 162); assertEquals( ((ASTNode)refs[0]).getLength(), 8); - } + } public void testBug86698A() throws Exception { Writer writer = new StringWriter(); @@ -1591,22 +1567,22 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("int c;\n"); //$NON-NLS-1$ writer.write("C() : c(0) { no_opt(this); }\n"); //$NON-NLS-1$ writer.write("};\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("c(0)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof IVariable ); assertEquals( ((IASTName)node).toString(), "c" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "c" ); //$NON-NLS-1$ assertEquals( ((ASTNode)decls[0]).getOffset(), 42); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - } - + } + public void testBug86698B() throws Exception { Writer writer = new StringWriter(); writer.write("int f(int);\n"); //$NON-NLS-1$ @@ -1627,24 +1603,23 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { writer.write("// handles exceptions thrown from the ctorinitializer\n"); //$NON-NLS-1$ writer.write("// and from the constructor function body\n"); //$NON-NLS-1$ writer.write("}\n"); //$NON-NLS-1$ - + String code = writer.toString(); - + int index = code.indexOf("i(f(ii)), d(id)"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 1, true ); assertTrue( node instanceof IASTName ); assertTrue( ((IASTName)node).resolveBinding() instanceof ICPPField ); assertEquals( ((IASTName)node).toString(), "i" ); //$NON-NLS-1$ - + IName[] decls = getDeclarationOffTU((IASTName)node); assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "i" ); //$NON-NLS-1$ assertEquals( code.indexOf("int i") + 4, ((ASTNode)decls[0]).getOffset()); assertEquals( ((ASTNode)decls[0]).getLength(), 1); - } + } - public void testBug64181() throws Exception - { + public void testBug64181() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("namespace Foo { // ** (A) **\n"); //$NON-NLS-1$ buffer.append("int bar;\n"); //$NON-NLS-1$ @@ -1656,7 +1631,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { buffer.append("main(int argc, char **argv) {\n"); //$NON-NLS-1$ buffer.append("Foo::bar; // ** (C) **\n"); //$NON-NLS-1$ buffer.append("}\n"); //$NON-NLS-1$ - + String code = buffer.toString(); int index = code.indexOf("Foo::bar;"); //$NON-NLS-1$ IASTNode node = parse( code, index, index + 3, true ); @@ -1672,9 +1647,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[1]).getOffset(), 50); assertEquals( ((ASTNode)decls[1]).getLength(), 3); } - - public void testBug80823() throws Exception - { + + public void testBug80823() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("class MyEggImpl {}; // line A\n"); //$NON-NLS-1$ buffer.append("#define MyChicken MyEggImpl\n"); //$NON-NLS-1$ @@ -1694,8 +1668,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( ((ASTNode)decls[0]).getLength(), 9); } - public void testBug86993() throws Exception - { + public void testBug86993() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("#define _BEGIN_STD_C extern \"C\" {\n"); //$NON-NLS-1$ buffer.append("#define _END_STD_C }\n"); //$NON-NLS-1$ @@ -1704,8 +1677,8 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { buffer.append("_END_STD_C\n"); //$NON-NLS-1$ buffer.append("char foo() {\n"); //$NON-NLS-1$ buffer.append("return c; // ref \n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - + buffer.append("}\n"); //$NON-NLS-1$ + String code = buffer.toString(); int index = code.indexOf("return c;"); //$NON-NLS-1$ IASTNode node = parse( code, index + 7, index + 8, true ); @@ -1717,7 +1690,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals(decls.length, 1); assertEquals( decls[0].toString(), "c" ); //$NON-NLS-1$ assertLocation(code, "c;", 1, decls[0]); - + index = code.indexOf("char c"); //$NON-NLS-1$ node = parse( code, index + 5, index + 6, true ); assertNotNull( node ); @@ -1728,7 +1701,7 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals( refs[0].toString(), "c" ); //$NON-NLS-1$ assertLocation(code, "c; // ref", 1, refs[0]); } - + private void assertLocation(String code, String occur, int length, IName name) { int offset= code.indexOf(occur); final IASTFileLocation loc= name.getFileLocation(); @@ -1736,4 +1709,3 @@ public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { assertEquals(length, loc.getNodeLength()); } } - diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java index 89ddc566e2f..5a292b6bd77 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TestUtil.java @@ -18,7 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; public class TestUtil { /** * Searches the AST upward from the given starting node to find the - * nearest IASTImplicitNameOwner and returns its first implicit name, + * nearest IASTImplicitNameOwner and returns its first implicit name, * or null if it has no implicit names. */ public static IASTName findImplicitName(IASTNode node) { From 4346a7377f58d8e3623477144aaecffe79dfed29 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 23 Jan 2013 10:55:42 -0800 Subject: [PATCH 16/42] Renamed few classes to distinguish tests from their base classes. --- .../cdt/codan/core/test/CodanFastCxxAstTestCase.java | 4 ++-- ...sePluginTest.java => FileBasePluginTestCase.java} | 8 ++++---- .../parser/tests/ast2/AST2CPPImplicitNameTests.java | 2 +- .../cdt/core/parser/tests/ast2/AST2CPPSpecTest.java | 2 +- .../cdt/core/parser/tests/ast2/AST2CPPTests.java | 2 +- .../cdt/core/parser/tests/ast2/AST2CSpecTest.java | 2 +- ...uginTest.java => AST2FileBasePluginTestCase.java} | 8 ++++---- .../cdt/core/parser/tests/ast2/AST2KnRTests.java | 2 +- .../parser/tests/ast2/AST2SelectionParseTest.java | 2 +- ...BaseTest.java => AST2SelectionParseTestBase.java} | 12 ++++++------ .../{AST2SpecBaseTest.java => AST2SpecTestBase.java} | 8 ++++---- .../core/parser/tests/ast2/AST2TemplateTests.java | 2 +- .../ast2/{AST2BaseTest.java => AST2TestBase.java} | 6 +++--- .../cdt/core/parser/tests/ast2/AST2Tests.java | 2 +- .../cdt/core/parser/tests/ast2/AST2UtilOldTests.java | 2 +- .../cdt/core/parser/tests/ast2/AST2UtilTests.java | 2 +- .../parser/tests/ast2/ASTCPPSpecDefectTests.java | 2 +- .../core/parser/tests/ast2/ASTInactiveCodeTests.java | 2 +- .../core/parser/tests/ast2/ASTNodeSelectorTest.java | 4 ++-- .../core/parser/tests/ast2/AccessControlTests.java | 2 +- .../ast2/{CDOMBaseTest.java => CDOMTestBase.java} | 10 +++++----- .../core/parser/tests/ast2/CodeReaderCacheTest.java | 2 +- .../cdt/core/parser/tests/ast2/CommentTests.java | 2 +- .../core/parser/tests/ast2/CompleteParser2Tests.java | 2 +- .../ast2/DOMGCCSelectionParseExtensionsTest.java | 2 +- .../parser/tests/ast2/DOMLocationInclusionTests.java | 2 +- .../parser/tests/ast2/DOMLocationMacroTests.java | 2 +- .../cdt/core/parser/tests/ast2/DOMLocationTests.java | 2 +- .../tests/ast2/DOMPreprocessorInformationTest.java | 2 +- .../parser/tests/ast2/DOMSelectionParseTest.java | 2 +- ...eBaseTest.java => DOMSelectionParseTestBase.java} | 8 ++++---- .../core/parser/tests/ast2/FaultToleranceTests.java | 2 +- .../tests/ast2/GCCCompleteParseExtensionsTest.java | 2 +- .../eclipse/cdt/core/parser/tests/ast2/GCCTests.java | 2 +- .../core/parser/tests/ast2/ImageLocationTests.java | 2 +- .../parser/tests/ast2/LanguageExtensionsTest.java | 2 +- .../core/parser/tests/ast2/QuickParser2Tests.java | 2 +- .../cdt/core/parser/tests/ast2/SemanticsTests.java | 2 +- .../cdt/core/parser/tests/ast2/TaskParserTest.java | 2 +- .../cdt/core/parser/tests/ast2/TypeTraitsTests.java | 2 +- .../tests/ast2/VariableReadWriteFlagsTest.java | 2 +- .../core/parser/tests/prefix/CompletionTestBase.java | 4 ++-- .../tests/rewrite/astwriter/ASTWriterTest.java | 4 ++-- .../cdt/ui/tests/search/LinkedNamesFinderTest.java | 4 ++-- .../eclipse/cdt/core/lrparser/tests/ParseHelper.java | 8 ++++---- 45 files changed, 76 insertions(+), 76 deletions(-) rename core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/{FileBasePluginTest.java => FileBasePluginTestCase.java} (95%) rename core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/{AST2FileBasePluginTest.java => AST2FileBasePluginTestCase.java} (95%) rename core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/{AST2SelectionParseBaseTest.java => AST2SelectionParseTestBase.java} (94%) rename core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/{AST2SpecBaseTest.java => AST2SpecTestBase.java} (97%) rename core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/{AST2BaseTest.java => AST2TestBase.java} (99%) rename core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/{CDOMBaseTest.java => CDOMTestBase.java} (86%) rename core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/{DOMSelectionParseBaseTest.java => DOMSelectionParseTestBase.java} (90%) diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanFastCxxAstTestCase.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanFastCxxAstTestCase.java index fda1349b053..6175ae8d035 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanFastCxxAstTestCase.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/test/CodanFastCxxAstTestCase.java @@ -35,7 +35,7 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest; +import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; @@ -83,7 +83,7 @@ public abstract class CodanFastCxxAstTestCase extends TestCase { protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean gcc) { FileContent codeReader = FileContent.create("code.c", code.toCharArray()); IScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner = AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner = AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTestCase.java similarity index 95% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTestCase.java index 81389f8057c..12a869f2466 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTestCase.java @@ -32,7 +32,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; /** * @author dsteffle */ -public class FileBasePluginTest extends TestCase { +public class FileBasePluginTestCase extends TestCase { static NullProgressMonitor monitor; static IWorkspace workspace; static IProject project; @@ -41,10 +41,10 @@ public class FileBasePluginTest extends TestCase { static Class className; static ICProject cPrj; - public FileBasePluginTest() { + public FileBasePluginTestCase() { } - public FileBasePluginTest(String name) { + public FileBasePluginTestCase(String name) { super(name); } @@ -75,7 +75,7 @@ public class FileBasePluginTest extends TestCase { } } - public FileBasePluginTest(String name, Class className) { + public FileBasePluginTestCase(String name, Class className) { super(name); initialize(className); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java index d73040b5422..3d4d2c70d0f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java @@ -29,7 +29,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * Tests for classes implementing IASTImplicitNameOwner interface. */ -public class AST2CPPImplicitNameTests extends AST2BaseTest { +public class AST2CPPImplicitNameTests extends AST2TestBase { public AST2CPPImplicitNameTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index ef4f48076d4..5f28ad59cf6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -46,7 +46,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * Examples taken from the c++-specification. */ -public class AST2CPPSpecTest extends AST2SpecBaseTest { +public class AST2CPPSpecTest extends AST2SpecTestBase { public AST2CPPSpecTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index a369089ea8e..b7f7c8bee72 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -139,7 +139,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil; import org.eclipse.cdt.internal.core.parser.ParserException; -public class AST2CPPTests extends AST2BaseTest { +public class AST2CPPTests extends AST2TestBase { public AST2CPPTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java index 974728e23da..9ad87f0b996 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java @@ -15,7 +15,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * @author dsteffle */ -public class AST2CSpecTest extends AST2SpecBaseTest { +public class AST2CSpecTest extends AST2SpecTestBase { public AST2CSpecTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTestCase.java similarity index 95% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTestCase.java index 83486231a38..deb5f8f4b80 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTestCase.java @@ -35,7 +35,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; /** * @author dsteffle */ -public class AST2FileBasePluginTest extends TestCase { +public class AST2FileBasePluginTestCase extends TestCase { static NullProgressMonitor monitor; static IWorkspace workspace; static IProject project; @@ -44,10 +44,10 @@ public class AST2FileBasePluginTest extends TestCase { static Class className; static ICProject cPrj; - public AST2FileBasePluginTest() { + public AST2FileBasePluginTestCase() { } - public AST2FileBasePluginTest(String name) { + public AST2FileBasePluginTestCase(String name) { super(name); } @@ -79,7 +79,7 @@ public class AST2FileBasePluginTest extends TestCase { } } - public AST2FileBasePluginTest(String name, Class className) { + public AST2FileBasePluginTestCase(String name, Class className) { super(name); initialize(className); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java index b0717f0aa51..80ee143f853 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java @@ -59,7 +59,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding; /** * @author dsteffle */ -public class AST2KnRTests extends AST2BaseTest { +public class AST2KnRTests extends AST2TestBase { public AST2KnRTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java index d729230bdc5..71ec93a7c7f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java @@ -48,7 +48,7 @@ import org.eclipse.core.resources.IFile; /** * @author dsteffle */ -public class AST2SelectionParseTest extends AST2SelectionParseBaseTest { +public class AST2SelectionParseTest extends AST2SelectionParseTestBase { public AST2SelectionParseTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTestBase.java similarity index 94% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTestBase.java index 8aca7558fa4..851a990f72b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTestBase.java @@ -29,7 +29,7 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.FileBasePluginTest; +import org.eclipse.cdt.core.parser.tests.FileBasePluginTestCase; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; @@ -40,18 +40,18 @@ import org.eclipse.core.resources.IFile; /** * @author dsteffle */ -public class AST2SelectionParseBaseTest extends FileBasePluginTest { +public class AST2SelectionParseTestBase extends FileBasePluginTestCase { - public AST2SelectionParseBaseTest() { + public AST2SelectionParseTestBase() { } - public AST2SelectionParseBaseTest(String name) { + public AST2SelectionParseTestBase(String name) { super(name); } private static final IParserLogService NULL_LOG = new NullLogService(); - public AST2SelectionParseBaseTest(String name, Class className) { + public AST2SelectionParseTestBase(String name, Class className) { super(name, className); } @@ -76,7 +76,7 @@ public class AST2SelectionParseBaseTest extends FileBasePluginTest { protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems) throws ParserException { FileContent codeReader = FileContent.create("", code.toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; if (lang == ParserLanguage.CPP) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecTestBase.java similarity index 97% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecTestBase.java index 5d9942bcf81..9dd536cb736 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SpecTestBase.java @@ -41,12 +41,12 @@ import org.eclipse.cdt.internal.core.parser.ParserException; /** * @author dsteffle */ -public class AST2SpecBaseTest extends AST2BaseTest { - public AST2SpecBaseTest() { +public class AST2SpecTestBase extends AST2TestBase { + public AST2SpecTestBase() { super(); } - public AST2SpecBaseTest(String name) { + public AST2SpecTestBase(String name) { super(name); } @@ -101,7 +101,7 @@ public class AST2SpecBaseTest extends AST2BaseTest { boolean useGNUExtensions, boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings, String[] problems) throws ParserException { ScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; if (lang == ParserLanguage.CPP) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 64c80b39a55..c06be8560cc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -103,7 +103,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.parser.ParserException; -public class AST2TemplateTests extends AST2BaseTest { +public class AST2TemplateTests extends AST2TestBase { public AST2TemplateTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java similarity index 99% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java index f7e532c46b9..afb76a90c9d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java @@ -95,7 +95,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor; /** * @author aniefer */ -public class AST2BaseTest extends BaseTestCase { +public class AST2TestBase extends BaseTestCase { public final static String TEST_CODE = ""; protected static final IParserLogService NULL_LOG = new NullLogService(); protected static boolean sValidateCopy; @@ -121,11 +121,11 @@ public class AST2BaseTest extends BaseTestCase { return map; } - public AST2BaseTest() { + public AST2TestBase() { super(); } - public AST2BaseTest(String name) { + public AST2TestBase(String name) { super(name); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index be0185273d1..a0863b741a4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -128,7 +128,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException; /** * Test cases on the AST. */ -public class AST2Tests extends AST2BaseTest { +public class AST2Tests extends AST2TestBase { private static final int NUM_TESTS = 3; public static TestSuite suite() { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilOldTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilOldTests.java index 1bf32ed357a..f98a9a69e3a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilOldTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilOldTests.java @@ -17,7 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.parser.ParserLanguage; -public class AST2UtilOldTests extends AST2BaseTest { +public class AST2UtilOldTests extends AST2TestBase { public AST2UtilOldTests() { } public AST2UtilOldTests(String name) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilTests.java index 12f3c43ecc4..d4a7c5802ac 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2UtilTests.java @@ -27,7 +27,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator; /** * @author dsteffle */ -public class AST2UtilTests extends AST2BaseTest { +public class AST2UtilTests extends AST2TestBase { public AST2UtilTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTCPPSpecDefectTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTCPPSpecDefectTests.java index 3a67049702c..0c7433d461f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTCPPSpecDefectTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTCPPSpecDefectTests.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.parser.ParserLanguage; -public class ASTCPPSpecDefectTests extends AST2BaseTest { +public class ASTCPPSpecDefectTests extends AST2TestBase { public ASTCPPSpecDefectTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTInactiveCodeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTInactiveCodeTests.java index e1ef4945dbb..873b1bda0a8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTInactiveCodeTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTInactiveCodeTests.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * Testcases for inactive code in ast. */ -public class ASTInactiveCodeTests extends AST2BaseTest { +public class ASTInactiveCodeTests extends AST2TestBase { public static TestSuite suite() { return suite(ASTInactiveCodeTests.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTNodeSelectorTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTNodeSelectorTest.java index 29ff910dbfb..4bb56ea205e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTNodeSelectorTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ASTNodeSelectorTest.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -public class ASTNodeSelectorTest extends AST2BaseTest { +public class ASTNodeSelectorTest extends AST2TestBase { static public TestSuite suite() { return suite(ASTNodeSelectorTest.class); @@ -55,7 +55,7 @@ public class ASTNodeSelectorTest extends AST2BaseTest { fCode= getContents(1)[0].toString(); FileContent codeReader = FileContent.create("", fCode.toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner= AST2BaseTest.createScanner(codeReader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, ParserLanguage.CPP, ParserMode.COMPLETE_PARSE, scannerInfo); GNUCPPSourceParser parser= new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, new NullLogService(), new GPPParserExtensionConfiguration()); fTu= parser.parse(); fSelector= fTu.getNodeSelector(null); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AccessControlTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AccessControlTests.java index 11bbfd143b2..922026b0dce 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AccessControlTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AccessControlTests.java @@ -18,7 +18,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.AccessContext; import org.eclipse.cdt.internal.core.parser.ParserException; -public class AccessControlTests extends AST2BaseTest { +public class AccessControlTests extends AST2TestBase { protected class AccessAssertionHelper extends BindingAssertionHelper { AccessAssertionHelper(String contents) throws ParserException { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMTestBase.java similarity index 86% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMBaseTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMTestBase.java index c59ded324af..9059c090e2c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CDOMTestBase.java @@ -13,22 +13,22 @@ package org.eclipse.cdt.core.parser.tests.ast2; import org.eclipse.cdt.core.dom.CDOM; import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.parser.tests.FileBasePluginTest; +import org.eclipse.cdt.core.parser.tests.FileBasePluginTestCase; import org.eclipse.core.resources.IFile; /** * @author dsteffle */ -public class CDOMBaseTest extends FileBasePluginTest { +public class CDOMTestBase extends FileBasePluginTestCase { - public CDOMBaseTest() { + public CDOMTestBase() { } - public CDOMBaseTest(String name) { + public CDOMTestBase(String name) { super(name); } - public CDOMBaseTest(String name, Class className) { + public CDOMTestBase(String name, Class className) { super(name, className); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CodeReaderCacheTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CodeReaderCacheTest.java index e17d7fd1e6a..e557b30625e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CodeReaderCacheTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CodeReaderCacheTest.java @@ -26,7 +26,7 @@ import org.eclipse.core.runtime.jobs.Job; /** * @author dsteffle */ -public class CodeReaderCacheTest extends CDOMBaseTest { +public class CodeReaderCacheTest extends CDOMTestBase { public CodeReaderCacheTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java index b60b13cb03c..ca8d20b7f90 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException; * @author Guido Zgraggen * */ -public class CommentTests extends AST2BaseTest { +public class CommentTests extends AST2TestBase { public static TestSuite suite() { return suite(CommentTests.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java index 8ed4bb367a9..b6afaf309c4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CompleteParser2Tests.java @@ -177,7 +177,7 @@ public class CompleteParser2Tests extends BaseTestCase { FileContent codeReader = FileContent.create("", code.toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); ISourceCodeParser parser2 = null; - IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; if (gcc) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMGCCSelectionParseExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMGCCSelectionParseExtensionsTest.java index f1256dd05a4..f6daa2ad12d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMGCCSelectionParseExtensionsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMGCCSelectionParseExtensionsTest.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; * @author jcamelon * */ -public class DOMGCCSelectionParseExtensionsTest extends DOMSelectionParseBaseTest { +public class DOMGCCSelectionParseExtensionsTest extends DOMSelectionParseTestBase { public DOMGCCSelectionParseExtensionsTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java index 7c7b93a3234..ddc30d2f5c1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java @@ -44,7 +44,7 @@ import org.eclipse.core.runtime.content.IContentType; /** * @author jcamelon */ -public class DOMLocationInclusionTests extends AST2FileBasePluginTest { +public class DOMLocationInclusionTests extends AST2FileBasePluginTestCase { public DOMLocationInclusionTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java index 27c22c01543..c4a25dba2b9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java @@ -35,7 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.parser.ParserException; -public class DOMLocationMacroTests extends AST2BaseTest { +public class DOMLocationMacroTests extends AST2TestBase { final ParserLanguage[] languages = new ParserLanguage[] { ParserLanguage.C, ParserLanguage.CPP }; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java index 80ec78f9b37..df72e0c9215 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java @@ -73,7 +73,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException; /** * @author jcamelon */ -public class DOMLocationTests extends AST2BaseTest { +public class DOMLocationTests extends AST2TestBase { public DOMLocationTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java index 325fc03f6dd..716098f44d3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java @@ -32,7 +32,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; * @author Emanuel Graf * */ -public class DOMPreprocessorInformationTest extends AST2BaseTest { +public class DOMPreprocessorInformationTest extends AST2TestBase { public void testPragma() throws Exception { String msg = "GCC poison printf sprintf fprintf"; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java index a3bb7c210ef..923bdf95206 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTest.java @@ -44,7 +44,7 @@ import org.eclipse.core.resources.IFile; /** * @author dsteffle */ -public class DOMSelectionParseTest extends DOMSelectionParseBaseTest { +public class DOMSelectionParseTest extends DOMSelectionParseTestBase { public DOMSelectionParseTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTestBase.java similarity index 90% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseBaseTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTestBase.java index a54b623bec7..80d7a29a63f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMSelectionParseTestBase.java @@ -23,16 +23,16 @@ import org.eclipse.core.resources.IFile; * @author johnc * */ -public class DOMSelectionParseBaseTest extends DOMFileBasePluginTest { +public class DOMSelectionParseTestBase extends DOMFileBasePluginTest { - public DOMSelectionParseBaseTest() { + public DOMSelectionParseTestBase() { } - public DOMSelectionParseBaseTest(String name) { + public DOMSelectionParseTestBase(String name) { super(name); } - public DOMSelectionParseBaseTest(String name, Class className) { + public DOMSelectionParseTestBase(String name, Class className) { super(name, className); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java index 46beb30698f..9493190bb1b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java @@ -30,7 +30,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * Testcases related to recovery from invalid syntax. */ -public class FaultToleranceTests extends AST2BaseTest { +public class FaultToleranceTests extends AST2TestBase { public static TestSuite suite() { return suite(FaultToleranceTests.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java index 54ee449ebb2..803f458c1db 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCCompleteParseExtensionsTest.java @@ -31,7 +31,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CFunction; import org.eclipse.cdt.internal.core.model.ASTStringUtil; import org.eclipse.cdt.internal.core.parser.ParserException; -public class GCCCompleteParseExtensionsTest extends AST2BaseTest { +public class GCCCompleteParseExtensionsTest extends AST2TestBase { public GCCCompleteParseExtensionsTest() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java index 51515f83f85..4d284afb934 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java @@ -29,7 +29,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * @author aniefer */ -public class GCCTests extends AST2BaseTest { +public class GCCTests extends AST2TestBase { public GCCTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ImageLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ImageLocationTests.java index 3781b3dcf99..a9b2425d18b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ImageLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ImageLocationTests.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; /** * @author jcamelon */ -public class ImageLocationTests extends AST2BaseTest { +public class ImageLocationTests extends AST2TestBase { private static final int CODE = IASTImageLocation.REGULAR_CODE; private static final int MACRO = IASTImageLocation.MACRO_DEFINITION; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/LanguageExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/LanguageExtensionsTest.java index 5ccbc2afdea..80fa8691192 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/LanguageExtensionsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/LanguageExtensionsTest.java @@ -44,7 +44,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor; /** * Testcases for non-gnu language extensions. */ -public class LanguageExtensionsTest extends AST2BaseTest { +public class LanguageExtensionsTest extends AST2TestBase { protected static final int SIZEOF_EXTENSION = 0x1; protected static final int FUNCTION_STYLE_ASM = 0x2; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java index 33cc1a0d043..9f33234002f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/QuickParser2Tests.java @@ -1335,7 +1335,7 @@ public class QuickParser2Tests extends TestCase { ParserLanguage lang, boolean gcc) throws Exception { FileContent codeReader = FileContent.create("", code.toCharArray()); IScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser2 = null; if (lang == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java index e4d259c68bc..d669ebbea30 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java @@ -20,7 +20,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** * Directly tests parts of the semantics package */ -public class SemanticsTests extends AST2BaseTest { +public class SemanticsTests extends AST2TestBase { public SemanticsTests() {} public SemanticsTests(String name) { super(name); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java index 381b6965450..bdd5255f575 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TaskParserTest.java @@ -18,7 +18,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.pdom.indexer.TodoTaskParser; import org.eclipse.cdt.internal.core.pdom.indexer.TodoTaskParser.Task; -public class TaskParserTest extends AST2BaseTest { +public class TaskParserTest extends AST2TestBase { public static TestSuite suite() { return suite(TaskParserTest.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java index 7fff28bb67d..bb536e69847 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/TypeTraitsTests.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException; /** * Tests for ClassTypeHelper class. */ -public class TypeTraitsTests extends AST2BaseTest { +public class TypeTraitsTests extends AST2TestBase { public TypeTraitsTests() { } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java index 494d56817d3..3fdf112e2fc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java @@ -23,7 +23,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; /** * Unit tests for CPPVariableReadWriteFlags and CVariableReadWriteFlags classes. */ -public class VariableReadWriteFlagsTest extends AST2BaseTest { +public class VariableReadWriteFlagsTest extends AST2TestBase { private static final int READ = PDOMName.READ_ACCESS; private static final int WRITE = PDOMName.WRITE_ACCESS; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java index be9e1b6f112..f6d44ea67ff 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/prefix/CompletionTestBase.java @@ -38,7 +38,7 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest; +import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; @@ -53,7 +53,7 @@ public class CompletionTestBase extends BaseTestCase { protected IASTCompletionNode getCompletionNode(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException { FileContent codeReader = FileContent.create("", code.trim().toCharArray()); ScannerInfo scannerInfo = new ScannerInfo(); - IScanner scanner= AST2BaseTest.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner= AST2TestBase.createScanner(codeReader, lang, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser = null; if( lang == ParserLanguage.CPP ) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java index 8eea3e22ddf..6576a1f3eb2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.core.parser.NullLogService; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest; +import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase; import org.eclipse.cdt.core.parser.tests.rewrite.RewriteBaseTest; import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper; import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile; @@ -95,7 +95,7 @@ public class ASTWriterTest extends RewriteBaseTest { ParserLanguage language = getLanguage(testFile); boolean useGNUExtensions = getGNUExtension(testFile); - IScanner scanner = AST2BaseTest.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo); + IScanner scanner = AST2TestBase.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo); ISourceCodeParser parser = null; if (language == ParserLanguage.CPP) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/LinkedNamesFinderTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/LinkedNamesFinderTest.java index 4de0f8a1942..8fe56f6fe83 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/LinkedNamesFinderTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/LinkedNamesFinderTest.java @@ -20,7 +20,7 @@ import junit.framework.TestSuite; import org.eclipse.jface.text.IRegion; import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest; +import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.ui.testplugin.CTestPlugin; @@ -31,7 +31,7 @@ import org.eclipse.cdt.internal.ui.search.LinkedNamesFinder; /** * Tests for LinkedNamesFinder class. */ -public class LinkedNamesFinderTest extends AST2BaseTest { +public class LinkedNamesFinderTest extends AST2TestBase { private static class RegionComparator implements Comparator { @Override public int compare(IRegion r1, IRegion r2) { diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java index c3e4caf2b12..c4d8134cda3 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java @@ -29,7 +29,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IncludeFileContentProvider; import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest; +import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; import org.eclipse.core.runtime.CoreException; @@ -136,7 +136,7 @@ public class ParseHelper { public static IASTTranslationUnit parse(char[] code, ILanguage lang, Options options) { - return parse(FileContent.create(AST2BaseTest.TEST_CODE, code), lang, new ScannerInfo(), null, options); + return parse(FileContent.create(AST2TestBase.TEST_CODE, code), lang, new ScannerInfo(), null, options); } @@ -254,7 +254,7 @@ public class ParseHelper { IASTTranslationUnit tu; try { - tu = language.getASTTranslationUnit(FileContent.create(AST2BaseTest.TEST_CODE, code.toCharArray()), new ScannerInfo(), null, null, ILanguage.OPTION_ADD_COMMENTS, ParserUtil.getParserLogService()); + tu = language.getASTTranslationUnit(FileContent.create(AST2TestBase.TEST_CODE, code.toCharArray()), new ScannerInfo(), null, null, ILanguage.OPTION_ADD_COMMENTS, ParserUtil.getParserLogService()); } catch (CoreException e) { throw new AssertionFailedError(e.toString()); } @@ -273,7 +273,7 @@ public class ParseHelper { public static IASTCompletionNode getCompletionNode(String code, ILanguage language, int offset) { try { - return language.getCompletionNode(FileContent.create(AST2BaseTest.TEST_CODE, code.toCharArray()), new ScannerInfo(), null, null, ParserUtil.getParserLogService(), offset); + return language.getCompletionNode(FileContent.create(AST2TestBase.TEST_CODE, code.toCharArray()), new ScannerInfo(), null, null, ParserUtil.getParserLogService(), offset); } catch (CoreException e) { throw new RuntimeException(e); } From ea08a27209d09a31277714c29102ce75bb7aa78a Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 23 Jan 2013 11:35:35 -0800 Subject: [PATCH 17/42] Bug 398706. Adjusted two tests. --- .../tests/text/SemanticHighlightingTest.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java index a44a925f671..c70d7b77511 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/SemanticHighlightingTest.java @@ -1,11 +1,11 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 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 + * Copyright (c) 2000, 2013 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: + * Contributors: * IBM Corporation - initial API and implementation * Anton Leherbauer (Wind River Systems) - Adapted for CDT *******************************************************************************/ @@ -20,13 +20,12 @@ import org.eclipse.cdt.internal.ui.editor.SemanticHighlightings; /** * Semantic highlighting tests. - * + * *

Derived from JDT.

* * @since 4.0 */ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { - private static final boolean PRINT_POSITIONS= false; private static final Class THIS= SemanticHighlightingTest.class; @@ -101,7 +100,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { createPosition(108, 4, 26), createPosition(112, 4, 25), createPosition(117, 4, 32), - }; + }; if (PRINT_POSITIONS) System.out.println(toString(actual)); assertEqualPositions(expected, actual); } @@ -121,10 +120,9 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { createPosition(108, 4, 26), createPosition(112, 4, 25), createPosition(117, 4, 32), - createPosition(118, 23, 9), createPosition(122, 4, 15), createPosition(130, 13, 9), - }; + }; Position[] actual= getSemanticHighlightingPositions(); if (PRINT_POSITIONS) System.out.println(toString(actual)); assertEqualPositions(expected, actual); @@ -134,7 +132,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { setUpSemanticHighlighting(SemanticHighlightings.STATIC_METHOD_INVOCATION); Position[] expected= new Position[] { createPosition(122, 4, 15), - }; + }; Position[] actual= getSemanticHighlightingPositions(); if (PRINT_POSITIONS) System.out.println(toString(actual)); assertEqualPositions(expected, actual); @@ -256,6 +254,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { createPosition(112, 4, 14), createPosition(117, 4, 14), createPosition(118, 4, 9), + createPosition(118, 23, 9), createPosition(120, 4, 8), createPosition(129, 4, 8), createPosition(147, 42, 7), @@ -297,7 +296,6 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { assertEqualPositions(expected, actual); } - public void testGlobalVariableHighlighting() throws Exception { setUpSemanticHighlighting(SemanticHighlightings.GLOBAL_VARIABLE); Position[] actual= getSemanticHighlightingPositions(); @@ -421,5 +419,4 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest { if (PRINT_POSITIONS) System.out.println(toString(actual)); assertEqualPositions(expected, actual); } - } From f1ca02367b75b871988819ebd7ca58faa9209dc5 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 24 Jan 2013 10:57:33 -0500 Subject: [PATCH 18/42] Temporarily disable CommandTimeoutTests as they may be the ones that cause a dialog to pop-up and hang the build. Change-Id: I2e1cabad2024e2b6b1df52f7a3346823f5b2765c --- .../eclipse/cdt/tests/dsf/gdb/tests/tests_7_5/Suite_7_5.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_5/Suite_7_5.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_5/Suite_7_5.java index ad053dda7f4..058f7757b64 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_5/Suite_7_5.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_5/Suite_7_5.java @@ -45,7 +45,7 @@ import org.junit.runners.Suite; OperationsWhileTargetIsRunningTest_7_5.class, OperationsWhileTargetIsRunningNonStopTest_7_5.class, PostMortemCoreTest_7_5.class, - CommandTimeoutTest_7_5.class, +// CommandTimeoutTest_7_5.class, Suite_Sessionless_Tests.class, GDBConsoleBreakpointsTest_7_5.class, /* Add your test class here */ From a861f63691f72b3ed54b634d551717780d6ec326 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 24 Jan 2013 12:27:02 -0800 Subject: [PATCH 19/42] Bug 399014 - "Enclosing namespace does not exist" error is too harsh --- .../classwizard/NewClassWizardMessages.java | 3 +- .../NewClassWizardMessages.properties | 5 ++- .../wizards/NewClassCreationWizardPage.java | 33 ++++++++++--------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java index b2cd29b36cf..c4d0357ad3d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 QNX Software Systems and others. + * Copyright (c) 2004, 2013 QNX Software Systems 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 @@ -29,7 +29,6 @@ public final class NewClassWizardMessages extends NLS { public static String NewClassCreationWizardPage_namespace_label; public static String NewClassCreationWizardPage_namespace_button; public static String NewClassCreationWizardPage_error_EnterNamespace; - public static String NewClassCreationWizardPage_error_EnclosingNamespaceNotExists; public static String NewClassCreationWizardPage_error_NamespaceExistsDifferentCase; public static String NewClassCreationWizardPage_error_TypeMatchingNamespaceExists; public static String NewClassCreationWizardPage_error_TypeMatchingNamespaceExistsDifferentCase; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties index ff35ba93539..34b3bdbb72e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2004, 2011 QNX Software Systems and others. +# Copyright (c) 2004, 2013 QNX Software Systems 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 @@ -34,11 +34,10 @@ NewClassCreationWizardPage_namespace_label=&Namespace: NewClassCreationWizardPage_namespace_button=Bro&wse... NewClassCreationWizardPage_error_EnterNamespace=Namespace is empty. -NewClassCreationWizardPage_error_EnclosingNamespaceNotExists=Enclosing namespace does not exist. NewClassCreationWizardPage_error_NamespaceExistsDifferentCase=Namespace with the same name exists in a different scope. NewClassCreationWizardPage_error_TypeMatchingNamespaceExists=Another type with the same name as specified namespace exists. NewClassCreationWizardPage_error_TypeMatchingNamespaceExistsDifferentCase=Another type with the same name as specified namespace exists in a different scope. -NewClassCreationWizardPage_warning_NamespaceNotExists=Namespace does not exist. A new namespace will be created. +NewClassCreationWizardPage_warning_NamespaceNotExists=Namespace ''{0}'' does not exist. A new namespace will be created. NewClassCreationWizardPage_error_InvalidNamespace=Namespace is not valid. {0}. NewClassCreationWizardPage_warning_NamespaceDiscouraged=Namespace is discouraged. {0}. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java index 4ce3ebc734d..58b995452c2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassCreationWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 QNX Software Systems and others. + * Copyright (c) 2004, 2013 QNX Software Systems 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 @@ -1591,17 +1591,8 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { ICProject project = getCurrentProject(); if (project != null) { - /* search for parent name space first */ - int searchResult; - if (typeName.isQualified()) { - searchResult = NewClassWizardUtil.searchForCppType(typeName.getEnclosingTypeName(),project, ICPPNamespace.class); - if (searchResult != NewClassWizardUtil.SEARCH_MATCH_FOUND_EXACT) { - status.setError(NewClassWizardMessages.NewClassCreationWizardPage_error_EnclosingNamespaceNotExists); - return status; - } - } - searchResult = NewClassWizardUtil.searchForCppType(typeName, project, ICPPNamespace.class); - switch(searchResult) { + int searchResult = NewClassWizardUtil.searchForCppType(typeName, project, ICPPNamespace.class); + switch (searchResult) { case NewClassWizardUtil.SEARCH_MATCH_FOUND_EXACT: status.setOK(); return status; @@ -1615,7 +1606,17 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { status.setWarning(NewClassWizardMessages.NewClassCreationWizardPage_error_TypeMatchingNamespaceExistsDifferentCase); return status; case NewClassWizardUtil.SEARCH_MATCH_NOTFOUND: - status.setWarning(NewClassWizardMessages.NewClassCreationWizardPage_warning_NamespaceNotExists); + // Find the highest ancestor namespace that does not exist. + IQualifiedTypeName ns = typeName; + while (ns.isQualified()) { + IQualifiedTypeName ns1 = ns.getEnclosingTypeName(); + if (NewClassWizardUtil.searchForCppType(ns1, project, ICPPNamespace.class) == NewClassWizardUtil.SEARCH_MATCH_FOUND_EXACT) { + break; + } + ns = ns1; + } + status.setWarning(NLS.bind(NewClassWizardMessages.NewClassCreationWizardPage_warning_NamespaceNotExists, + ns.getFullyQualifiedName())); break; } } @@ -1638,7 +1639,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { StatusInfo status = new StatusInfo(); String className = getClassName(); - // must not be empty + // Must not be empty. if (className == null || className.length() == 0) { status.setError(NewClassWizardMessages.NewClassCreationWizardPage_error_EnterClassName); return status; @@ -1669,7 +1670,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { } } int searchResult = NewClassWizardUtil.searchForCppType(fullyQualifiedName, project, ICPPClassType.class); - switch(searchResult) { + switch (searchResult) { case NewClassWizardUtil.SEARCH_MATCH_FOUND_EXACT: status.setError(NewClassWizardMessages.NewClassCreationWizardPage_error_ClassNameExists); return status; @@ -1729,7 +1730,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage { MultiStatus status = new MultiStatus(CUIPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$ IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project.getProject()); if (provider != null) { - //TODO get the scanner info for the actual source folder + // TODO Get the scanner info for the actual source folder. IScannerInfo info = provider.getScannerInformation(project.getProject()); if (info != null) { String[] includePaths = info.getIncludePaths(); From f072ce9223f834cae38a7b70d49e4e122735c4bf Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Thu, 24 Jan 2013 20:11:14 -0800 Subject: [PATCH 20/42] Bug 399036 - Add C/C++ Code Style category to preference export --- core/org.eclipse.cdt.ui/plugin.properties | 6 ++++-- core/org.eclipse.cdt.ui/plugin.xml | 24 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 51c079b50e5..82a725516ba 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -629,9 +629,11 @@ LanguageSettingsProviderAssociationExtensionPoint=Language Settings Provider UI overrideAnnotation.label = C/C++ Override indicators transfer.EditorAppearance.name = C/C++ Editor Appearance -transfer.EditorAppearance.description = Preference related to how the editor presents the edited code to the user (including colors, fonts, hovers, foldings, etc...) +transfer.EditorAppearance.description = Preferences related to how the editor presents the edited code to the user (including colors, fonts, hovers, foldings, etc...) transfer.EditorBehavior.name = C/C++ Editor Behavior -transfer.EditorBehavior.description = Preference related to how the editor process the edited code (typing, save action, etc...) +transfer.EditorBehavior.description = Preferences related to how the editor deals with the edited code (typing, save action, etc...) +transfer.CodeStyle.name = C/C++ Code Style +transfer.CodeStyle.description = C/C++ > Code Style preferences # Refresh Exclusion Contributors RefreshExclusionContributor.name = Resources diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 7b23e99066c..e86fecfc6d4 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -4497,6 +4497,7 @@ @@ -4555,6 +4556,7 @@ @@ -4588,15 +4590,31 @@ - - + %transfer.EditorBehavior.description + + + + + + + + + + + + + %transfer.CodeStyle.description + + Date: Thu, 10 Jan 2013 14:41:10 -0800 Subject: [PATCH 21/42] Cosmetics --- .../ui/preferences/NameStyleBlock.java | 1 - .../utils/ui/controls/TabFolderLayout.java | 28 +++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java index 6ef9c311a3a..08e0eee044b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java @@ -648,7 +648,6 @@ public class NameStyleBlock extends OptionsConfigurationBlock { private class NameStyleAdapter extends ViewerComparator implements ITreeListAdapter, IDialogFieldListener { - @Override public void selectionChanged(TreeListDialogField field) { updateConfigurationBlock(field.getSelectedElements()); diff --git a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/TabFolderLayout.java b/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/TabFolderLayout.java index a9516535121..2cf7e37db34 100644 --- a/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/TabFolderLayout.java +++ b/core/org.eclipse.cdt.ui/utils.ui/org/eclipse/cdt/utils/ui/controls/TabFolderLayout.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.utils.ui.controls; - import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; @@ -22,34 +21,33 @@ import org.eclipse.swt.widgets.Layout; * @noextend This class is not intended to be subclassed by clients. */ public class TabFolderLayout extends Layout { - @Override - protected Point computeSize (Composite composite, int wHint, int hHint, boolean flushCache) { + protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) return new Point(wHint, hHint); - - Control [] children = composite.getChildren (); + + Control[] children = composite.getChildren(); int count = children.length; int maxWidth = 0, maxHeight = 0; - for (int i=0; i Date: Wed, 23 Jan 2013 19:54:38 -0800 Subject: [PATCH 22/42] Code streamlining. --- .../internal/ui/preferences/NameStyleBlock.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java index 08e0eee044b..d3cd571eee6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java @@ -39,7 +39,6 @@ import org.eclipse.cdt.internal.corext.codemanipulation.StubUtility; import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; import org.eclipse.cdt.internal.ui.util.NameComposer; -import org.eclipse.cdt.internal.ui.viewsupport.ProjectTemplateStore; import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; @@ -254,17 +253,6 @@ public class NameStyleBlock extends OptionsConfigurationBlock { categoryTree.postSetSelection(new StructuredSelection(element)); } - @Override - public boolean hasProjectSpecificOptions(IProject project) { - if (super.hasProjectSpecificOptions(project)) - return true; - - if (project != null) { - return ProjectTemplateStore.hasProjectSpecificTempates(project); - } - return false; - } - @Override protected Control createContents(Composite parent) { pixelConverter = new PixelConverter(parent); @@ -416,11 +404,6 @@ public class NameStyleBlock extends OptionsConfigurationBlock { updateConfigurationBlock(categoryTree.getSelectedElements()); } - @Override - public boolean performOk() { - return super.performOk(); - } - @Override protected void validateSettings(Key changedKey, String oldValue, String newValue) { StatusInfo status = new StatusInfo(); From 0248aa4474165d5e39624971be5307212f9e5e2f Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 10 Jan 2013 14:34:14 -0500 Subject: [PATCH 23/42] Bug 397715 - [memory][expressions] Make use of GDB 7.6 new =memory-changed MI event Change-Id: I98c3cd273e185dfb1782527d7abd553351a163d9 Reviewed-on: https://git.eclipse.org/r/9662 Reviewed-by: Marc Khouzam IP-Clean: Marc Khouzam Tested-by: Marc Khouzam --- .../cdt/dsf/gdb/service/GDBMemory_7_6.java | 165 +++++++++ .../gdb/service/GdbDebugServicesFactory.java | 9 +- .../eclipse/cdt/dsf/mi/service/MIMemory.java | 49 ++- .../data/launch/src/ConsoleSyncTestApp.cc | 15 + .../GDBConsoleSynchronizingTest_7_6.java | 330 ++++++++++++++++++ .../dsf/gdb/tests/tests_7_6/Suite_7_6.java | 1 + .../gdb/tests/tests_7_6/Suite_Remote_7_6.java | 1 + 7 files changed, 551 insertions(+), 19 deletions(-) create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory_7_6.java create mode 100644 dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ConsoleSyncTestApp.cc create mode 100644 dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory_7_6.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory_7_6.java new file mode 100644 index 00000000000..3c4dd5475e2 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory_7_6.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson 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: + * Marc Khouzam (Ericsson) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.dsf.gdb.service; + +import java.util.Hashtable; + +import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.datamodel.DMContexts; +import org.eclipse.cdt.dsf.debug.service.IMemory; +import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext; +import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; +import org.eclipse.cdt.dsf.debug.service.command.IEventListener; +import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; +import org.eclipse.cdt.dsf.mi.service.IMIProcesses; +import org.eclipse.cdt.dsf.mi.service.MIMemory; +import org.eclipse.cdt.dsf.mi.service.command.output.MIConst; +import org.eclipse.cdt.dsf.mi.service.command.output.MINotifyAsyncOutput; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOOBRecord; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput; +import org.eclipse.cdt.dsf.mi.service.command.output.MIResult; +import org.eclipse.cdt.dsf.mi.service.command.output.MIValue; +import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.cdt.utils.Addr64; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +/** + * Memory service that uses the enhancements from GDB 7.6: + * =memory-changed MI event + * + * @since 4.2 + */ +public class GDBMemory_7_6 extends GDBMemory_7_0 implements IEventListener { + + private ICommandControlService fConnection; + + public GDBMemory_7_6(DsfSession session) { + super(session); + } + + @Override + public void initialize(final RequestMonitor requestMonitor) { + super.initialize( + new ImmediateRequestMonitor(requestMonitor) { + @Override + public void handleSuccess() { + doInitialize(requestMonitor); + }}); + } + + private void doInitialize(final RequestMonitor requestMonitor) { + register(new String[] { MIMemory.class.getName(), + IMemory.class.getName(), + GDBMemory_7_0.class.getName(), + GDBMemory_7_6.class.getName()}, + new Hashtable()); + + fConnection = getServicesTracker().getService(ICommandControlService.class); + if (fConnection == null) { + requestMonitor.done(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, "CommandControl Service is not available")); //$NON-NLS-1$ + return; + } + fConnection.addEventListener(this); + + requestMonitor.done(); + } + + @Override + public void shutdown(final RequestMonitor requestMonitor) { + fConnection.removeEventListener(this); + unregister(); + super.shutdown(requestMonitor); + } + + @Override + public void eventReceived(Object output) { + if (output instanceof MIOutput) { + MIOOBRecord[] records = ((MIOutput)output).getMIOOBRecords(); + for (MIOOBRecord r : records) { + if (r instanceof MINotifyAsyncOutput) { + MINotifyAsyncOutput notifyOutput = (MINotifyAsyncOutput)r; + String asyncClass = notifyOutput.getAsyncClass(); + // These events have been added with GDB 7.6 + if ("memory-changed".equals(asyncClass)) { //$NON-NLS-1$ + String groupId = null; + String addr = null; + int length = 0; + + MIResult[] results = notifyOutput.getMIResults(); + for (int i = 0; i < results.length; i++) { + String var = results[i].getVariable(); + MIValue val = results[i].getMIValue(); + if (var.equals("thread-group")) { //$NON-NLS-1$ + if (val instanceof MIConst) { + groupId = ((MIConst)val).getString(); + } + } else if (var.equals("addr")) { //$NON-NLS-1$ + if (val instanceof MIConst) { + addr = ((MIConst)val).getString(); + } + } else if (var.equals("len")) { //$NON-NLS-1$ + if (val instanceof MIConst) { + try { + String lenStr = ((MIConst)val).getString().trim(); + if (lenStr.startsWith("0x")) { //$NON-NLS-1$ + length = Integer.parseInt(lenStr.substring(2), 16); + } else { + length = Integer.parseInt(lenStr); + } + } catch (NumberFormatException e) { + assert false; + } + } + } else if (var.equals("type")) { //$NON-NLS-1$ + if (val instanceof MIConst) { + if ("code".equals(((MIConst)val).getString())) { //$NON-NLS-1$ + } + } + } + } + + IMIProcesses procService = getServicesTracker().getService(IMIProcesses.class); + if (procService != null && groupId != null && addr != null && length > 0) { + IContainerDMContext containerDmc = + procService.createContainerContextFromGroupId(fConnection.getContext(), groupId); + + // Now refresh our memory cache, it case it contained this address. Don't have + // it send the potential IMemoryChangedEvent as we will send it ourselves (see below). + final IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(containerDmc, IMemoryDMContext.class); + final IAddress address = new Addr64(addr); + // The length returned by GDB is in bytes, while the memory cache expects + // a count of number of addresses of 8 bytes. + int count = length/8 + 1; + getMemoryCache(memoryDMC).refreshMemory(memoryDMC, address, 0, 1, count, false, + new RequestMonitor(getExecutor(), null) { + @Override + protected void handleCompleted() { + // Only once the memory cache is updated, we send the IMemoryChangedEvent. If we were to do it + // earlier, the memory view may not show the updated value. + // + // We must always send this event when GDB reports a memory change because it can mean that + // an expression or register has changed, and therefore we must notify the different views + // and services of it. We cannot rely on this event to be sent by the memory cache after being + // refreshed, because if the memory cache does not contain this address, it will not send + // the event. + getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, new IAddress[] { address }), getProperties()); + } + }); + } + } + } + } + } + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java index c1a2647d4c0..0a62d53fb65 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Ericsson and others. + * Copyright (c) 2008, 2013 Ericsson 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 @@ -12,6 +12,7 @@ * Marc Khouzam (Ericsson) - Support for GDB 7.4 (Bug 367788) * Marc Khouzam (Ericsson) - Include IGDBHardware service for the multicore visualizer (Bug 335027) * Vladimir Prus (Mentor Graphics) - Support for OS resources. + * Marc Khouzam (Ericsson) - Support for GDB 7.6 memory service *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service; @@ -67,6 +68,8 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory { public static final String GDB_7_4_VERSION = "7.4"; //$NON-NLS-1$ /** @since 4.2*/ public static final String GDB_7_5_VERSION = "7.5"; //$NON-NLS-1$ + /** @since 4.2*/ + public static final String GDB_7_6_VERSION = "7.5.50"; //$NON-NLS-1$ private final String fVersion; @@ -172,6 +175,10 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory { @Override protected IMemory createMemoryService(DsfSession session) { + if (GDB_7_6_VERSION.compareTo(fVersion) <= 0) { + return new GDBMemory_7_6(session); + } + if (GDB_7_0_VERSION.compareTo(fVersion) <= 0) { return new GDBMemory_7_0(session); } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIMemory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIMemory.java index f75beaa1628..67cc4f3da5f 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIMemory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIMemory.java @@ -34,6 +34,7 @@ import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.debug.service.ICachingService; import org.eclipse.cdt.dsf.debug.service.IExpressions; +import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionChangedDMEvent; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMAddress; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; import org.eclipse.cdt.dsf.debug.service.IMemory; @@ -92,7 +93,8 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer // Map of memory caches private Map fMemoryCaches; - private MIMemoryCache getMemoryCache(IMemoryDMContext memoryDMC) { + /** @since 4.2 */ + protected MIMemoryCache getMemoryCache(IMemoryDMContext memoryDMC) { MIMemoryCache cache = fMemoryCaches.get(memoryDMC); if (cache == null) { cache = new MIMemoryCache(); @@ -490,12 +492,19 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer } } - /** - * @nooverride This method is not intended to be re-implemented or extended by clients. - * @noreference This method is not intended to be referenced by clients. - */ - @DsfServiceEventHandler + /** + * @deprecated Replaced by the generic {@link #eventDispatched(IExpressionChangedDMEvent)} + */ + @Deprecated public void eventDispatched(ExpressionChangedEvent e) { + } + + /** + * @noreference This method is not intended to be referenced by clients. + * @since 4.2 + */ + @DsfServiceEventHandler + public void eventDispatched(IExpressionChangedDMEvent e) { // Get the context and expression service handle final IExpressionDMContext context = e.getDMContext(); @@ -518,7 +527,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer address = new Addr64(expAddress.getValue()); final IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(context, IMemoryDMContext.class); - getMemoryCache(memoryDMC).refreshMemory(memoryDMC, address, 0, 1, count, + getMemoryCache(memoryDMC).refreshMemory(memoryDMC, address, 0, 1, count, true, new RequestMonitor(getExecutor(), null)); } }); @@ -629,7 +638,8 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer // MIMemoryCache /////////////////////////////////////////////////////////////////////////// - private class MIMemoryCache { + /** @since 4.2 */ + protected class MIMemoryCache { // The memory cache data structure private SortedMemoryBlockList fMemoryBlockList; @@ -965,10 +975,12 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer * @param offset * @param word_size * @param count + * @param sendMemoryEvent Indicates if a IMemoryChangedEvent should be sent if the memory cache has changed. * @param rm */ public void refreshMemory(final IMemoryDMContext memoryDMC, final IAddress address, - final long offset, final int word_size, final int count, final RequestMonitor rm) + final long offset, final int word_size, final int count, final boolean sendMemoryEvent, + final RequestMonitor rm) { // Check if we already cache part of this memory area (which means it // is used by a memory service client that will have to be updated) @@ -983,16 +995,10 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer rm.done(); return; } - - // Prepare the data for the MemoryChangedEvent - final IAddress[] addresses = new IAddress[count]; - for (int i = 0; i < count; i++) { - addresses[i] = address.add(i); - } // Read the corresponding memory block fCommandCache.reset(); - readMemoryBlock(memoryDMC, address, 0, 1, count, + readMemoryBlock(memoryDMC, address, offset, word_size, count, new DataRequestMonitor(getExecutor(), rm) { @Override protected void handleSuccess() { @@ -1006,8 +1012,15 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer } } if (blocksDiffer) { - updateMemoryCache(address, count, newBlock); - getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, addresses), getProperties()); + updateMemoryCache(address.add(offset), count, newBlock); + if (sendMemoryEvent) { + // Send the MemoryChangedEvent + final IAddress[] addresses = new IAddress[count]; + for (int i = 0; i < count; i++) { + addresses[i] = address.add(offset + i); + } + getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, addresses), getProperties()); + } } rm.done(); } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ConsoleSyncTestApp.cc b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ConsoleSyncTestApp.cc new file mode 100644 index 00000000000..2e858e5dd12 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ConsoleSyncTestApp.cc @@ -0,0 +1,15 @@ +#include + +int testMemoryChanges() { + int i = 8; + + return i; +} + +int main() { + printf("Running ConsoleSyncTestApp\n"); + + testMemoryChanges(); + + return 0; +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java new file mode 100644 index 00000000000..c8299d57783 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java @@ -0,0 +1,330 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson 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: + * Marc Khouzam (Ericsson) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_6; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.Query; +import org.eclipse.cdt.dsf.datamodel.DMContexts; +import org.eclipse.cdt.dsf.datamodel.IDMContext; +import org.eclipse.cdt.dsf.datamodel.IDMEvent; +import org.eclipse.cdt.dsf.debug.service.IExpressions; +import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMAddress; +import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; +import org.eclipse.cdt.dsf.debug.service.IMemory; +import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryChangedEvent; +import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryDMContext; +import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext; +import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; +import org.eclipse.cdt.dsf.mi.service.command.events.MIStoppedEvent; +import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; +import org.eclipse.cdt.dsf.service.DsfServiceEventHandler; +import org.eclipse.cdt.dsf.service.DsfServicesTracker; +import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner; +import org.eclipse.cdt.tests.dsf.gdb.framework.BaseTestCase; +import org.eclipse.cdt.tests.dsf.gdb.framework.SyncUtil; +import org.eclipse.cdt.tests.dsf.gdb.launching.TestsPlugin; +import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants; +import org.eclipse.debug.core.model.MemoryByte; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * This test case verifies that different commands issued from the + * GDB console cause proper updating within the CDT views. + */ +@RunWith(BackgroundRunner.class) +public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { + + final static private int DEFAULT_TIMEOUT = 1000; + final static private TimeUnit DEFAULT_TIME_UNIT = TimeUnit.MILLISECONDS; + + private DsfSession fSession; + private DsfServicesTracker fServicesTracker; + private IGDBControl fCommandControl; + private IMemory fMemoryService; + private IExpressions fExprService; + + private List> fEventsReceived = new ArrayList>(); + + @Override + protected void setGdbVersion() { + setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_6); + } + + @Override + protected void setLaunchAttributes() { + super.setLaunchAttributes(); + + setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "data/launch/bin/ConsoleSyncTestApp.exe"); + } + + @Override + public void doBeforeTest() throws Exception { + super.doBeforeTest(); + + fSession = getGDBLaunch().getSession(); + Runnable runnable = new Runnable() { + @Override + public void run() { + fServicesTracker = new DsfServicesTracker(TestsPlugin.getBundleContext(), fSession.getId()); + Assert.assertTrue(fServicesTracker != null); + + fCommandControl = fServicesTracker.getService(IGDBControl.class); + Assert.assertTrue(fCommandControl != null); + + fMemoryService = fServicesTracker.getService(IMemory.class); + Assert.assertTrue(fMemoryService != null); + + fExprService = fServicesTracker.getService(IExpressions.class); + Assert.assertTrue(fExprService != null); + + // Register to breakpoint events + fSession.addServiceEventListener(GDBConsoleSynchronizingTest_7_6.this, null); + } + }; + fSession.getExecutor().submit(runnable).get(); + } + + @Override + public void doAfterTest() throws Exception { + Runnable runnable = new Runnable() { + @Override + public void run() { + fSession.removeServiceEventListener(GDBConsoleSynchronizingTest_7_6.this); + } + }; + fSession.getExecutor().submit(runnable).get(); + fEventsReceived.clear(); + fServicesTracker.dispose(); + super.doAfterTest(); + } + + ////////////////////////////////////////////////////////////////////////////////////// + // Start of tests + ////////////////////////////////////////////////////////////////////////////////////// + + /** + * This test verifies that setting a variable from the console + * using the set command will properly trigger a DSF event to + * indicate the change. This test makes sure the value that + * changes is in the memory cache also. + */ + @Test + public void testSettingVariableWithSetWithMemory() throws Throwable { + MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("testMemoryChanges"); + + final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); + final IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "i"); + + // Read the memory that will change first, or else there will be no event for it + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + fExprService.getExpressionAddressData(exprDmc, rm); + } + }; + + fSession.getExecutor().execute(query); + IExpressionDMAddress data = query.get(); + + IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); + readMemory(memoryDmc, data.getAddress(), data.getSize()); + + fEventsReceived.clear(); + queueConsoleCommand("set variable i=100"); + + IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); + assertEquals(1, memoryEvent.getAddresses().length); + assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + } + + /** + * This test verifies that setting a variable from the console + * using the set command will properly trigger a DSF event to + * indicate the change, when the address is not in the memory cache. + */ + @Test + public void testSettingVariableWithSet() throws Throwable { + MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("testMemoryChanges"); + + final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); + final IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "i"); + + // Read the memory that will change first, or else there will be no event for it + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + fExprService.getExpressionAddressData(exprDmc, rm); + } + }; + + fSession.getExecutor().execute(query); + IExpressionDMAddress data = query.get(); + + fEventsReceived.clear(); + queueConsoleCommand("set variable i=100"); + + IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); + assertEquals(1, memoryEvent.getAddresses().length); + assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + } + + /** + * This test verifies that setting a variable from the console + * using the print command will properly trigger a DSF event + * to indicate the change. + */ + @Test + public void testSettingVariableWithPrint() throws Throwable { + MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("testMemoryChanges"); + + final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); + final IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "i"); + + // Read the memory that will change first, or else there will be no event for it + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + fExprService.getExpressionAddressData(exprDmc, rm); + } + }; + + fSession.getExecutor().execute(query); + IExpressionDMAddress data = query.get(); + + fEventsReceived.clear(); + queueConsoleCommand("print i=100"); + + IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); + assertEquals(1, memoryEvent.getAddresses().length); + assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + } + + /** + * This test verifies that setting a memory location from the + * console will properly trigger a DSF event to indicate the change. + */ + @Test + public void testSettingMemory() throws Throwable { + MIStoppedEvent stoppedEvent = SyncUtil.runToLocation("testMemoryChanges"); + + final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); + final IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "i"); + + // Read the memory that will change first, or else there will be no event for it + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + fExprService.getExpressionAddressData(exprDmc, rm); + } + }; + + fSession.getExecutor().execute(query); + IExpressionDMAddress data = query.get(); + + fEventsReceived.clear(); + queueConsoleCommand("set {int}&i=100"); + + IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); + assertEquals(1, memoryEvent.getAddresses().length); + assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + } + + ////////////////////////////////////////////////////////////////////////////////////// + // End of tests + ////////////////////////////////////////////////////////////////////////////////////// + + @DsfServiceEventHandler + public void eventDispatched(IDMEvent e) { + synchronized(this) { + fEventsReceived.add(e); + notifyAll(); + } + } + + private MemoryByte[] readMemory(final IMemoryDMContext dmc, final IAddress address, final int count) + throws Throwable + { + Query query = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + fMemoryService.getMemory(dmc, address, 0, 1, count, rm); + } + }; + fSession.getExecutor().execute(query); + return query.get(DEFAULT_TIMEOUT, DEFAULT_TIME_UNIT); + } + + private void queueConsoleCommand(String command) throws Throwable { + queueConsoleCommand(command, DEFAULT_TIMEOUT, DEFAULT_TIME_UNIT); + } + + private void queueConsoleCommand(final String command, int timeout, TimeUnit unit) throws Throwable { + Query query = new Query() { + @Override + protected void execute(DataRequestMonitor rm) { + fCommandControl.queueCommand( + fCommandControl.getCommandFactory().createMIInterpreterExecConsole( + fCommandControl.getContext(), + command), + rm); + } + }; + fSession.getExecutor().execute(query); + query.get(timeout, unit); + } + + private > V waitForEvent(Class eventType) throws Exception { + return waitForEvent(eventType, DEFAULT_TIMEOUT); + } + + @SuppressWarnings("unchecked") + private > V waitForEvent(Class eventType, int timeout) throws Exception { + IDMEvent event = getEvent(eventType); + if (event == null) { + synchronized(this) { + try { + wait(timeout); + } + catch (InterruptedException ex) { + } + } + event = getEvent(eventType); + if (event == null) { + throw new Exception(String.format("Timed out waiting for '%s' to occur.", eventType.getName())); + } + } + return (V)event; + } + + @SuppressWarnings("unchecked") + private synchronized > V getEvent(Class eventType) { + for (IDMEvent e : fEventsReceived) { + if (eventType.isAssignableFrom(e.getClass())) { + fEventsReceived.remove(e); + return (V)e; + } + } + return null; + } + +} diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_7_6.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_7_6.java index 983dc915d30..0e364d79885 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_7_6.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_7_6.java @@ -48,6 +48,7 @@ import org.junit.runners.Suite; GDBMultiNonStopRunControlTest_7_6.class, Suite_Sessionless_Tests.class, GDBConsoleBreakpointsTest_7_6.class, + GDBConsoleSynchronizingTest_7_6.class, /* Add your test class here */ }) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_Remote_7_6.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_Remote_7_6.java index aa3edd8421e..fc54dbfa84f 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_Remote_7_6.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/Suite_Remote_7_6.java @@ -49,6 +49,7 @@ import org.junit.runners.Suite; Suite_Sessionless_Tests.class, GDBConsoleBreakpointsTest_7_6.class, TraceFileTest_7_6.class, + GDBConsoleSynchronizingTest_7_6.class, /* Add your test class here */ }) From 3b431d7bcff8c7a87251093eaf42af60ffb33d47 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Fri, 25 Jan 2013 14:37:01 -0500 Subject: [PATCH 24/42] Bug 399123 - [reverse] Uncall does not work with instruction stepping Change-Id: I9d749dcda1d1cab8001e0dae6e4d12321cda42ae Reviewed-on: https://git.eclipse.org/r/9933 Reviewed-by: Anton Leherbauer Reviewed-by: Marc Khouzam IP-Clean: Marc Khouzam Tested-by: Marc Khouzam --- .../cdt/dsf/gdb/internal/ui/commands/GdbUncallCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbUncallCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbUncallCommand.java index 6087a96b686..c0c89fd2251 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbUncallCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbUncallCommand.java @@ -7,6 +7,7 @@ * * Contributors: * Ericsson - initial API and implementation + * Marc Khouzam (Ericsson) - Instruction-level step-return does not make sense (bug 399123) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.internal.ui.commands; @@ -26,7 +27,6 @@ public class GdbUncallCommand extends GdbAbstractReverseStepCommand implements I @Override protected final StepType getStepType() { - boolean instructionSteppingEnabled = getSteppingMode() != null && getSteppingMode().isInstructionSteppingEnabled(); - return instructionSteppingEnabled ? StepType.INSTRUCTION_STEP_RETURN : StepType.STEP_RETURN; + return StepType.STEP_RETURN; } } From f0b7098f0098427e5ce2e42ecd8f8d54173328aa Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Mon, 28 Jan 2013 12:55:12 -0500 Subject: [PATCH 25/42] Bug 397715 - Update JUnit tests to verify value of change memory and expression. Change-Id: I75a9dc166ae3287973d8b32e20cc121ea842cd27 Reviewed-on: https://git.eclipse.org/r/9964 Reviewed-by: Marc Khouzam IP-Clean: Marc Khouzam Tested-by: Marc Khouzam --- .../cdt/tests/dsf/gdb/framework/SyncUtil.java | 21 +++++++ .../GDBConsoleSynchronizingTest_7_6.java | 56 +++++++++++++++++-- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java index fb078685198..c6b5f0c0e84 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java @@ -30,6 +30,7 @@ import org.eclipse.cdt.dsf.debug.service.IExpressions; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; import org.eclipse.cdt.dsf.debug.service.IFormattedValues; import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext; +import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData; import org.eclipse.cdt.dsf.debug.service.IFormattedValues.IFormattedDataDMContext; import org.eclipse.cdt.dsf.debug.service.IProcesses.IProcessDMContext; import org.eclipse.cdt.dsf.debug.service.IProcesses.IThreadDMContext; @@ -432,6 +433,26 @@ public class SyncUtil { return fSession.getExecutor().submit(callable).get(); } + public static String getExpressionValue(final IExpressionDMContext exprDmc, final String format) + throws Throwable { + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + FormattedValueDMContext valueDmc = fExpressions.getFormattedValueContext(exprDmc, format); + fExpressions.getFormattedExpressionValue(valueDmc, + new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + rm.done(getData().getFormattedValue()); + } + }); + } + }; + + fSession.getExecutor().execute(query); + return query.get(); + } + public static FormattedValueDMContext getFormattedValue( final IFormattedValues service, final IFormattedDataDMContext dmc, final String formatId) throws Throwable { diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java index c8299d57783..015ebae46bb 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.dsf.datamodel.IDMEvent; import org.eclipse.cdt.dsf.debug.service.IExpressions; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMAddress; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; +import org.eclipse.cdt.dsf.debug.service.IFormattedValues; import org.eclipse.cdt.dsf.debug.service.IMemory; import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryChangedEvent; import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryDMContext; @@ -147,14 +148,24 @@ public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { IExpressionDMAddress data = query.get(); IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); - readMemory(memoryDmc, data.getAddress(), data.getSize()); + readMemory(memoryDmc, data.getAddress(), 1); fEventsReceived.clear(); - queueConsoleCommand("set variable i=100"); + + final String newValue = "100"; + queueConsoleCommand("set variable i=" + newValue); IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); assertEquals(1, memoryEvent.getAddresses().length); assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + + // Now verify the memory service knows the new memory value + MemoryByte[] memory = readMemory(memoryDmc, data.getAddress(), 1); + assertEquals(newValue, Byte.toString(memory[0].getValue())); + + // Now verify the expressions service knows the new value + String exprValue = SyncUtil.getExpressionValue(exprDmc, IFormattedValues.DECIMAL_FORMAT); + assertEquals(newValue, exprValue); } /** @@ -181,11 +192,22 @@ public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { IExpressionDMAddress data = query.get(); fEventsReceived.clear(); - queueConsoleCommand("set variable i=100"); + + final String newValue = "100"; + queueConsoleCommand("set variable i=" + newValue); IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); assertEquals(1, memoryEvent.getAddresses().length); assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + + // Now verify the memory service knows the new memory value + IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); + MemoryByte[] memory = readMemory(memoryDmc, data.getAddress(), 1); + assertEquals(newValue, Byte.toString(memory[0].getValue())); + + // Now verify the expressions service knows the new value + String exprValue = SyncUtil.getExpressionValue(exprDmc, IFormattedValues.DECIMAL_FORMAT); + assertEquals(newValue, exprValue); } /** @@ -212,11 +234,22 @@ public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { IExpressionDMAddress data = query.get(); fEventsReceived.clear(); - queueConsoleCommand("print i=100"); + + final String newValue = "100"; + queueConsoleCommand("print i=" + newValue); IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); assertEquals(1, memoryEvent.getAddresses().length); assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + + // Now verify the memory service knows the new memory value + IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); + MemoryByte[] memory = readMemory(memoryDmc, data.getAddress(), 1); + assertEquals(newValue, Byte.toString(memory[0].getValue())); + + // Now verify the expressions service knows the new value + String exprValue = SyncUtil.getExpressionValue(exprDmc, IFormattedValues.DECIMAL_FORMAT); + assertEquals(newValue, exprValue); } /** @@ -242,11 +275,22 @@ public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { IExpressionDMAddress data = query.get(); fEventsReceived.clear(); - queueConsoleCommand("set {int}&i=100"); - + + final String newValue = "100"; + queueConsoleCommand("set {int}&i=" + newValue); + IMemoryChangedEvent memoryEvent = waitForEvent(IMemoryChangedEvent.class); assertEquals(1, memoryEvent.getAddresses().length); assertEquals(data.getAddress(), memoryEvent.getAddresses()[0]); + + // Now verify the memory service knows the new memory value + IMemoryDMContext memoryDmc = DMContexts.getAncestorOfType(frameDmc, IMemoryDMContext.class); + MemoryByte[] memory = readMemory(memoryDmc, data.getAddress(), 1); + assertEquals(newValue, Byte.toString(memory[0].getValue())); + + // Now verify the expressions service knows the new value + String exprValue = SyncUtil.getExpressionValue(exprDmc, IFormattedValues.DECIMAL_FORMAT); + assertEquals(newValue, exprValue); } ////////////////////////////////////////////////////////////////////////////////////// From 1c88eba5239c31cdc5ae94a3f11e894227bf0689 Mon Sep 17 00:00:00 2001 From: Randy Rohrbach Date: Fri, 25 Jan 2013 14:25:26 -0500 Subject: [PATCH 26/42] Bug 399119 - The CDT Model presentation does not support editor and color customization for breakpoints. --- .../internal/ui/CDebugModelPresentation.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java index e75c80e840c..b9904b6cd32 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java @@ -89,10 +89,13 @@ import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugModelPresentation; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.debug.ui.ISourcePresentation; import org.eclipse.debug.ui.IValueDetailListener; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.IEditorDescriptor; import org.eclipse.ui.IEditorInput; @@ -105,7 +108,7 @@ import com.ibm.icu.text.MessageFormat; /** * @see IDebugModelPresentation */ -public class CDebugModelPresentation extends LabelProvider implements IDebugModelPresentation { +public class CDebugModelPresentation extends LabelProvider implements IDebugModelPresentation, IColorProvider { public final static String DISPLAY_FULL_PATHS = "DISPLAY_FULL_PATHS"; //$NON-NLS-1$ @@ -194,6 +197,14 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode } if ( file != null ) return new FileEditorInput( file ); + // There is no file associated with this breakpoint. See if another editor is available from an adapter + ISourcePresentation srcPres = (ISourcePresentation) Platform.getAdapterManager().getAdapter(b, ISourcePresentation.class); + if ( srcPres != null ) { + IEditorInput editor = srcPres.getEditorInput(b); + if ( editor != null ) { + return editor; + } + } } if ( element instanceof FileStorage || element instanceof LocalFileStorage ) { return new ExternalEditorInput( ((IStorage) element).getFullPath() ); @@ -220,7 +231,20 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode if ( input != null ) { IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); IEditorDescriptor descriptor = registry.getDefaultEditor( input.getName() ); - id = (descriptor != null) ? descriptor.getId() : CUIPlugin.EDITOR_ID; + id = CUIPlugin.EDITOR_ID; + if ( descriptor != null ) { + id = descriptor.getId(); + } + else if ( element instanceof ICBreakpoint ) { + // There is no associated editor ID for this breakpoint, see if an alternative can be supplied from an adapter. + ISourcePresentation sourcePres = (ISourcePresentation) Platform.getAdapterManager().getAdapter(element, ISourcePresentation.class); + if ( sourcePres != null ) { + String lid = sourcePres.getEditorId(input, element); + if ( lid != null ) { + id = lid; + } + } + } } return id; } @@ -797,4 +821,21 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode return MessageFormat.format( string, (Object[]) args ); } + @Override + public Color getForeground(Object element) { + IColorProvider colorProv = (IColorProvider) Platform.getAdapterManager().getAdapter(element, IColorProvider.class); + if ( colorProv != null ) { + return colorProv.getForeground(element); + } + return null; + } + + @Override + public Color getBackground(Object element) { + IColorProvider colorProv = (IColorProvider) Platform.getAdapterManager().getAdapter(element, IColorProvider.class); + if ( colorProv != null ) { + return colorProv.getBackground(element); + } + return null; + } } From 0cca070d73e448b31c259cc35edc47931835a00a Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Wed, 16 Jan 2013 05:00:37 -0500 Subject: [PATCH 27/42] Reuse CPPTemplates.isValidArgument() is TemplateArgumentDeduction Change-Id: I85abc02f4fe36719c16fcb52b4c675b9ab46d449 Reviewed-on: https://git.eclipse.org/r/9697 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../cpp/semantics/TemplateArgumentDeduction.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index 4233824ebbd..6319e0c3516 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -636,16 +636,8 @@ public class TemplateArgumentDeduction { deducedArg= tpar.getDefaultValue(); if (deducedArg != null) { deducedArg= CPPTemplates.instantiateArgument(deducedArg, tpMap, -1, null, point); - if (deducedArg != null) { - if (deducedArg instanceof CPPTemplateTypeArgument) { - CPPTemplateTypeArgument deducedTypeArg = (CPPTemplateTypeArgument) deducedArg; - if (!(deducedTypeArg.getTypeValue() instanceof ISemanticProblem)) { - tpMap.put(tpar, deducedArg); - } - } else { - // TODO: Check for problems in non-type or template template parameters? - tpMap.put(tpar, deducedArg); - } + if (CPPTemplates.isValidArgument(deducedArg)) { + tpMap.put(tpar, deducedArg); } } } From 7112819c9b584acef60c6fb3c6e639fa03fdb04c Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 29 Jan 2013 02:48:19 -0500 Subject: [PATCH 28/42] Bug 399353 - Error involving __is_base_of Change-Id: I93270040e75819c41705f0413d831ceaaf007131 Reviewed-on: https://git.eclipse.org/r/9989 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../cdt/core/parser/tests/ast2/AST2CPPTests.java | 13 +++++++++++++ .../parser/cpp/CPPASTBinaryTypeIdExpression.java | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index b7f7c8bee72..7d2815987cc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -10125,4 +10125,17 @@ public class AST2CPPTests extends AST2TestBase { parseAndCheckBindings(getAboveComment(), CPP, true); } + // template + // struct enable_if { + // }; + // template <> + // struct enable_if { + // typedef void type; + // }; + // struct base {}; + // struct derived : base {}; + // typedef enable_if<__is_base_of(base, derived)>::type T; + public void testIsBaseOf_399353() throws Exception { + parseAndCheckBindings(getAboveComment(), CPP, true); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java index 7953101446d..a0a508069fc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBinaryTypeIdExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2013 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 @@ -124,7 +124,7 @@ public class CPPASTBinaryTypeIdExpression extends ASTNode implements ICPPASTExpr fEvaluation= EvalFixed.INCOMPLETE; } else { IType t1= CPPVisitor.createType(fOperand1); - IType t2= CPPVisitor.createType(fOperand1); + IType t2= CPPVisitor.createType(fOperand2); if (t1 == null || t2 == null) { fEvaluation= EvalFixed.INCOMPLETE; } else { From 047a6f8f298e30b56aaa210eef600c69acb7713d Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 29 Jan 2013 14:54:20 -0800 Subject: [PATCH 29/42] Bug 382074 - [C++11] Error involving variadic non-type template parameters Change-Id: I6f4e3672b4aca8e8ca878bccdec9c19a1838c74d Reviewed-on: https://git.eclipse.org/r/9581 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../parser/tests/ast2/AST2TemplateTests.java | 9 ++++++++ .../cpp/CPPASTAmbiguousTemplateArgument.java | 21 ++++++++++++------- .../cpp/CPPASTPackExpansionExpression.java | 8 ++++--- .../parser/cpp/semantics/CPPTemplates.java | 3 +++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index c06be8560cc..da6898aa9ba 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -7029,4 +7029,13 @@ public class AST2TemplateTests extends AST2TestBase { assertNotNull(num); assertEquals(1, num.longValue()); } + + // template struct A {}; + // template void foo(A); + // int main() { + // foo(A<0>()); + // } + public void testVariadicNonTypeTemplateParameter_382074() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java index 7b702c2bcf5..e6b02b0356c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousTemplateArgument.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Symbian Software Systems and others. + * Copyright (c) 2008, 2013 Symbian Software Systems 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 @@ -9,6 +9,7 @@ * Andrew Ferguson (Symbian) - Initial Implementation * Markus Schorn (Wind River Systems) * IBM Corporation + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -68,12 +69,18 @@ public class CPPASTAmbiguousTemplateArgument extends ASTAmbiguousNode implements name.setBinding(null); namedTypeSpec.setName(name); } - } else if (node instanceof IASTIdExpression) { - IASTIdExpression id= (IASTIdExpression) node; - final IASTName name = id.getName(); - name.setBinding(null); - id.setName(name); - } + } else { + // Unwrap variadic pack expansion if necessary. + if (node instanceof ICPPASTPackExpansionExpression) + node= ((ICPPASTPackExpansionExpression) node).getPattern(); + + if (node instanceof IASTIdExpression) { + IASTIdExpression id= (IASTIdExpression) node; + final IASTName name = id.getName(); + name.setBinding(null); + id.setName(name); + } + } } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java index 9b115f02e50..56695296b2a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPackExpansionExpression.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2013 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 + * Markus Schorn - initial API and implementation + * Natan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -16,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; @@ -74,7 +76,7 @@ public class CPPASTPackExpansionExpression extends ASTNode implements ICPPASTPac } else { type= new CPPParameterPackType(type); } - fEvaluation= new EvalFixed(type, PRVALUE, Value.UNKNOWN); + fEvaluation= new EvalFixed(type, PRVALUE, Value.create(((ICPPASTExpression) fPattern).getEvaluation())); } return fEvaluation; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 61f55dfe0fe..9a3a3244d2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -2226,6 +2226,9 @@ public class CPPTemplates { pType= instantiateType(pType, map, -1, null, point); } + if (argType instanceof ICPPParameterPackType) { + argType = ((ICPPParameterPackType) argType).getType(); + } if (argType instanceof ICPPUnknownType) { return new CPPTemplateNonTypeArgument(arg.getNonTypeValue(), pType); } From 0ef8976a2a4ae73d7f2009cf4fcaec6d8891c8be Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 29 Jan 2013 15:09:59 -0800 Subject: [PATCH 30/42] Bug 397494 - Error evaluating decltype of constant lambda Change-Id: Ib9f5b09d331db9b7686c7d1c3a0c124cb235131f Reviewed-on: https://git.eclipse.org/r/9478 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../cdt/core/parser/tests/ast2/AST2CPPTests.java | 15 +++++++++++++++ .../core/dom/parser/cpp/CPPClosureType.java | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 7d2815987cc..eb4b961ae3b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -10125,6 +10125,21 @@ public class AST2CPPTests extends AST2TestBase { parseAndCheckBindings(getAboveComment(), CPP, true); } + // template + // T bar(); + // struct S { + // void waldo(); + // }; + // int main() { + // auto L = [](S s) { return s; }; + // typedef decltype(L) lambda_type; + // decltype(bar()(S())) v; + // v.waldo(); + // } + public void testDecltypeWithConstantLambda_397494() throws Exception { + parseAndCheckBindings(); + } + // template // struct enable_if { // }; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java index 14e1902fd42..979cc8fd7b3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java @@ -103,7 +103,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP // Function call operator final IType returnType= getReturnType(); final IType[] parameterTypes= getParameterTypes(); - ft= new CPPFunctionType(returnType, parameterTypes, isMutable(), false, false); + ft= new CPPFunctionType(returnType, parameterTypes, !isMutable(), false, false); ICPPParameter[] params = new ICPPParameter[parameterTypes.length]; for (int i = 0; i < params.length; i++) { From 69c73ec432fde23f438e83fa93a4940fb30034bf Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Sun, 13 Jan 2013 20:01:12 -0500 Subject: [PATCH 31/42] Bug 388805 - False ambiguity in overload resolution with variadic templates Change-Id: I4d8b73ab5238f98de7b53849b265ebbc6158d62e Reviewed-on: https://git.eclipse.org/r/9643 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../parser/tests/ast2/AST2TemplateTests.java | 11 ++++++++ .../parser/cpp/semantics/CPPTemplates.java | 26 +++++++++++++++++-- .../semantics/TemplateArgumentDeduction.java | 5 ++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index da6898aa9ba..fb687f073fc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -4405,6 +4405,17 @@ public class AST2TemplateTests extends AST2TestBase { parseAndCheckBindings(); } + // template + // void foo(A); + // template + // void foo(A, B...); + // int main() { + // foo(0); + // } + public void testFunctionTemplatePartialOrdering_388805() throws Exception { + parseAndCheckBindings(); + } + // template class CT {}; // template class CTI {}; // diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 9a3a3244d2b..73dcc32b4b2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2013 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 @@ -81,6 +81,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; 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.ICPPParameter; 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.ICPPScope; @@ -1958,13 +1959,34 @@ public class CPPTemplates { return arg; } + private static ICPPFunctionType getFunctionTypeIgnoringParametersWithDefaults(ICPPFunction function) { + ICPPParameter[] parameters = function.getParameters(); + IType[] parameterTypes = new IType[parameters.length]; + int i; + for (i = 0; i < parameters.length; ++i) { + ICPPParameter parameter = parameters[i]; + if (!parameter.hasDefaultValue()) { + parameterTypes[i] = parameter.getType(); + } else { + break; + } + } + ICPPFunctionType originalType = function.getType(); + if (i == parameters.length) // no parameters with default arguments + return originalType; + return new CPPFunctionType(originalType.getReturnType(), ArrayUtil.trim(parameterTypes), + originalType.isConst(), originalType.isVolatile(), originalType.takesVarArgs()); + } + private static int compareSpecialization(ICPPFunctionTemplate f1, ICPPFunctionTemplate f2, TypeSelection mode, IASTNode point) throws DOMException { ICPPFunction transF1 = transferFunctionTemplate(f1, point); if (transF1 == null) return -1; final ICPPFunctionType ft2 = f2.getType(); - final ICPPFunctionType transFt1 = transF1.getType(); + // Ignore parameters with default arguments in the transformed function template + // as per [temp.func.order] p5. + final ICPPFunctionType transFt1 = getFunctionTypeIgnoringParametersWithDefaults(transF1); IType[] pars; IType[] args; switch(mode) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index 6319e0c3516..8f8328cffa2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2013 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 @@ -8,6 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -431,7 +432,7 @@ public class TemplateArgumentDeduction { deduct.incPackOffset(); } else { if (j >= fnParCount) - return result; + return -1; par= fnPars[j]; if (par instanceof ICPPParameterPackType) { From 524777cfa8cc8e0456727b85d0bcfb71e152ba35 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 29 Jan 2013 15:48:16 -0800 Subject: [PATCH 32/42] Bug 397828 - Error involving recursive variadic template Change-Id: I68d1ed4c303fcaf7dd1b74438dc0673444f5fedc Reviewed-on: https://git.eclipse.org/r/9644 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../parser/tests/ast2/AST2TemplateTests.java | 19 +++++++++++ .../semantics/TemplateArgumentDeduction.java | 32 +++++++++++++++---- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index fb687f073fc..789af2f3408 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -4841,6 +4841,25 @@ public class AST2TemplateTests extends AST2TestBase { ub= bh.assertNonProblem("f(h(args...) + args...)", 1); } + // template + // struct contains_waldo; + // template <> + // struct contains_waldo<> { + // static const bool value = false; + // }; + // template + // struct contains_waldo { + // static const bool value = contains_waldo::value; + // }; + // int main() { + // bool b1 = contains_waldo::value; + // bool b2 = contains_waldo::value; + // bool b2 = contains_waldo::value; + // } + public void testRecursiveVariadicTemplate_397828() throws Exception { + parseAndCheckBindings(); + } + // struct Test { // void Update() {} // }; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index 8f8328cffa2..eeafbef7f77 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -37,7 +37,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IQualifierType; -import org.eclipse.cdt.core.dom.ast.ISemanticProblem; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IValue; @@ -607,15 +606,36 @@ public class TemplateArgumentDeduction { final ICPPTemplateArgument[] p, final ICPPTemplateArgument[] a, CPPTemplateParameterMap map, IASTNode point) throws DOMException { TemplateArgumentDeduction deduct= new TemplateArgumentDeduction(pars, null, map, 0); - final int len= a.length; - if (p == null || p.length != len) { + if (p == null) { return false; } - for (int j= 0; j < len; j++) { - if (!deduct.fromTemplateArgument(p[j], a[j], point)) { - return false; + boolean containsPackExpansion= false; + for (int j= 0; j < p.length; j++) { + if (p[j].isPackExpansion()) { + deduct = new TemplateArgumentDeduction(deduct, a.length - j); + containsPackExpansion= true; + if (j != p.length - 1) { + return false; // A pack expansion must be the last argument to the specialization. + } + ICPPTemplateArgument pattern = p[j].getExpansionPattern(); + for (int i= j; i < a.length; i++) { + if (!deduct.fromTemplateArgument(pattern, a[i], point)) { + return false; + } + deduct.incPackOffset(); + } + break; + } else { + if (j >= a.length) { + return false; // Not enough arguments. + } + if (!deduct.fromTemplateArgument(p[j], a[j], point)) { + return false; + } } } + if (!containsPackExpansion && p.length < a.length) + return false; // Too many arguments. return verifyDeduction(pars, map, false, point); } From d4cf62a7853199a723b45d6454586e67ae3332c4 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 29 Jan 2013 15:59:34 -0800 Subject: [PATCH 33/42] Bug 398044 - Error involving partial ordering of class template specializations Change-Id: Ia4a2d8760c6122e5aeec81524a20a3fa14a5a3ac Reviewed-on: https://git.eclipse.org/r/9645 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../parser/tests/ast2/AST2TemplateTests.java | 30 +++++++++++++ .../parser/cpp/semantics/CPPTemplates.java | 19 +++----- .../parser/cpp/semantics/SemanticUtil.java | 45 ++----------------- .../semantics/TemplateArgumentDeduction.java | 2 +- 4 files changed, 40 insertions(+), 56 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 789af2f3408..f1ef857a7a3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -7068,4 +7068,34 @@ public class AST2TemplateTests extends AST2TestBase { public void testVariadicNonTypeTemplateParameter_382074() throws Exception { parseAndCheckBindings(); } + + // template + // struct common_type; + // template + // struct common_type { + // typedef int type; + // }; + // template + // struct common_type { + // typedef int type; + // }; + // typedef common_type::type type; + public void testClassTemplateSpecializationPartialOrdering_398044a() throws Exception { + parseAndCheckBindings(); + } + + // template + // class A; + // template + // class A { + // }; + // template + // class A { + // }; + // int main() { + // A mf; + // } + public void testClassTemplateSpecializationPartialOrdering_398044b() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 73dcc32b4b2..8d4f25cf045 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -2140,8 +2140,6 @@ public class CPPTemplates { final ICPPTemplateParameter[] tpars2 = f2.getTemplateParameters(); final ICPPTemplateArgument[] targs1 = f1.getTemplateArguments(); final ICPPTemplateArgument[] targs2 = f2.getTemplateArguments(); - if (targs1.length != targs2.length) - return false; // Transfer arguments of specialization 1 final int tpars1Len = tpars1.length; @@ -2151,22 +2149,17 @@ public class CPPTemplates { final ICPPTemplateParameter param = tpars1[i]; final ICPPTemplateArgument arg = uniqueArg(param); args[i]= arg; - transferMap.put(param, arg); + if (param.isParameterPack()) { + transferMap.put(param, new ICPPTemplateArgument[] { arg }); + } else { + transferMap.put(param, arg); + } } final ICPPTemplateArgument[] transferredArgs1 = instantiateArguments(targs1, transferMap, -1, null, point, false); // Deduce arguments for specialization 2 final CPPTemplateParameterMap deductionMap= new CPPTemplateParameterMap(2); - if (!TemplateArgumentDeduction.fromTemplateArguments(tpars2, targs2, transferredArgs1, deductionMap, point)) - return false; - - // Compare - for (int i = 0; i < targs2.length; i++) { - ICPPTemplateArgument transferredArg2= instantiateArgument(targs2[i], deductionMap, -1, null, point); - if (!transferredArg2.isSameValue(transferredArgs1[i])) - return false; - } - return true; + return TemplateArgumentDeduction.fromTemplateArguments(tpars2, targs2, transferredArgs1, deductionMap, point); } static boolean isValidType(IType t) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java index 5431c752d7c..5e86257e167 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 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 @@ -11,6 +11,7 @@ * Bryan Wilkinson (QNX) * Andrew Ferguson (Symbian) * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; @@ -49,7 +50,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; 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.ICPPTemplateInstance; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -663,46 +663,7 @@ public class SemanticUtil { return -1; } - public static boolean containsUniqueTypeForParameterPack(IType type) { - if (type instanceof ICPPFunctionType) { - final ICPPFunctionType ft = (ICPPFunctionType) type; - if (containsUniqueTypeForParameterPack(ft.getReturnType())) - return true; - - for (IType pt : ft.getParameterTypes()) { - if (containsUniqueTypeForParameterPack(pt)) - return true; - } - return false; - } - - if (type instanceof ICPPPointerToMemberType) { - if (containsUniqueTypeForParameterPack(((ICPPPointerToMemberType) type).getMemberOfClass())) - return true; - } - - if (type instanceof IBinding) { - IBinding owner = ((IBinding) type).getOwner(); - if (owner instanceof IType) { - if (containsUniqueTypeForParameterPack((IType) owner)) - return true; - } - } - - if (type instanceof ICPPTemplateInstance) { - ICPPTemplateArgument[] args = ((ICPPTemplateInstance) type).getTemplateArguments(); - for (ICPPTemplateArgument arg : args) { - if (containsUniqueTypeForParameterPack(arg.getTypeValue())) - return true; - } - } - - if (type instanceof ITypeContainer) { - final ITypeContainer tc = (ITypeContainer) type; - final IType nestedType= tc.getType(); - return containsUniqueTypeForParameterPack(nestedType); - } - + public static boolean isUniqueTypeForParameterPack(IType type) { if (type instanceof UniqueType) { return ((UniqueType) type).isForParameterPack(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index eeafbef7f77..555f1ec9e77 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -970,7 +970,7 @@ public class TemplateArgumentDeduction { return false; return fDeducedArgs.putPackElement(parID, fPackOffset, arg, fPackSize); } - if (SemanticUtil.containsUniqueTypeForParameterPack(arg.getTypeValue())) + if (SemanticUtil.isUniqueTypeForParameterPack(arg.getTypeValue())) return false; fDeducedArgs.put(parID, arg); return true; From 95c12313366888fea38f77449ef4ba840f52ac1b Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 29 Jan 2013 16:22:40 -0800 Subject: [PATCH 34/42] Bug 399039 - Error involving variadic non-type template parameter Change-Id: I61b19e1fc5aac9372ad756c1e33e412f4bee86e2 Reviewed-on: https://git.eclipse.org/r/9943 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../parser/tests/ast2/AST2TemplateTests.java | 27 +++++++++++++++++++ .../core/dom/parser/cpp/ICPPEvaluation.java | 13 +++++++-- .../parser/cpp/semantics/CPPTemplates.java | 14 ++++++++++ .../core/dom/parser/cpp/semantics/EvalID.java | 9 +++++-- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index f1ef857a7a3..f6f66498610 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -7069,6 +7069,33 @@ public class AST2TemplateTests extends AST2TestBase { parseAndCheckBindings(); } + // template + // struct ice_or { + // static const bool value = false; + // }; + // template + // struct is_foo { + // static const bool value = false; + // }; + // template + // struct contains_foo { + // static const bool value = ice_or::value...>::value; + // }; + // template + // struct meta; + // struct S { void bar(); }; + // template <> + // struct meta { + // typedef S type; + // }; + // int main() { + // meta::value>::type t; + // t.bar(); + // } + public void testVariadicNonTypeTemplateParameter_399039() throws Exception { + parseAndCheckBindings(); + } + // template // struct common_type; // template diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java index 0ed1f673f48..4bff763279a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPEvaluation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2012, 2013 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 @@ -8,6 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Sergey Prigogin (Google) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -84,8 +85,16 @@ public interface ICPPEvaluation extends ISerializableEvaluation { IASTNode point); /** - * Determines size of the template parameter pack. + * Searches the evaluation for a usage of a template parameter which is a parameter pack, + * and returns the number of arguments bound to that parameter pack in the given + * template parameter map. * + * Can also return one of the special values CPPTemplates.PACK_SIZE_DEFER, + * CPPTemplates.PACK_SIZE_FAIL, and CPPTemplates.PACK_SIZE_NOT_FOUND. See their + * declarations for their meanings. + * + * See also CPPTemplates.determinePackSize(). + * * @noreference This method is not intended to be referenced by clients. */ int determinePackSize(ICPPTemplateParameterMap tpMap); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 8d4f25cf045..9e4a6d0a356 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -162,9 +162,23 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMod * type instantiation. */ public class CPPTemplates { + // The three constants below are used as special return values for the various overloads + // of CPPTemplates.determinePackSize() and for ICPPEvaluation.determinePackSize(), which + // search a type, template argument, or value for a usage of a template parameter pack + // and return the number of arguments bound to that parameter pack in an + // ICPPTemplateParameterMap. + + // Used to indicate that the parameter pack is not bound to any arguments in the + // template parameter map. Computation of the pack size needs to be deferred until + // arguments for it become available. static final int PACK_SIZE_DEFER = -1; + + // Used to indicate that two different packs with different sizes were found. static final int PACK_SIZE_FAIL = -2; + + // Used to indicate that no template parameter packs were found. static final int PACK_SIZE_NOT_FOUND = Integer.MAX_VALUE; + static enum TypeSelection { PARAMETERS, RETURN_TYPE, PARAMETERS_AND_RETURN_TYPE } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java index 74760703536..61c5c7883af 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalID.java @@ -360,8 +360,13 @@ public class EvalID extends CPPEvaluation { @Override public int determinePackSize(ICPPTemplateParameterMap tpMap) { int r = fFieldOwner != null ? fFieldOwner.determinePackSize(tpMap) : CPPTemplates.PACK_SIZE_NOT_FOUND; - for (ICPPTemplateArgument arg : fTemplateArgs) { - r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap)); + if (fNameOwner instanceof ICPPUnknownBinding) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize((ICPPUnknownBinding) fNameOwner, tpMap)); + } + if (fTemplateArgs != null) { + for (ICPPTemplateArgument arg : fTemplateArgs) { + r = CPPTemplates.combinePackSize(r, CPPTemplates.determinePackSize(arg, tpMap)); + } } return r; } From 90bdc3c39c53086d9fb09d2800eea724efac14b8 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 29 Jan 2013 04:22:24 -0500 Subject: [PATCH 35/42] Bug 399363 - ClassCastException in CPPBaseClause.getBaseClassType() Change-Id: Ia7f168648b739334982b7e0728250fbb663bd1c5 Reviewed-on: https://git.eclipse.org/r/9994 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../internal/core/dom/parser/cpp/CPPBaseClause.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java index 5d45beba891..21c80c020a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java @@ -1,14 +1,15 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2013 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: - * Andrew Niefer (IBM Corporation) - initial API and implementation - * Bryan Wilkinson (QNX) - * Markus Schorn (Wind River Systems) + * Andrew Niefer (IBM Corporation) - initial API and implementation + * Bryan Wilkinson (QNX) + * Markus Schorn (Wind River Systems) + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -47,8 +48,10 @@ public class CPPBaseClause implements ICPPBase, ICPPInternalBase { public IType getBaseClassType() { if (baseClass == null) { IBinding b = base.getName().resolveBinding(); - if (b instanceof IProblemBinding || ! (b instanceof IType)) { + if (b instanceof IProblemBinding) { baseClass = new CPPClassType.CPPClassTypeProblem(base.getName(), ((IProblemBinding) b).getID()); + } else if (!(b instanceof IType)) { + baseClass = new CPPClassType.CPPClassTypeProblem(base.getName(), ISemanticProblem.BINDING_NO_CLASS); } else { baseClass= (IType) b; IType check= getNestedType(baseClass, TDEF); From 9e8c662a737d697067444b8699adc36a5bb08c94 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Wed, 30 Jan 2013 10:39:29 -0800 Subject: [PATCH 36/42] Bug 397342 - Error calculating size of reference type Change-Id: I1274da6ebd14f0c1f97dce2699d62018cff57b05 Reviewed-on: https://git.eclipse.org/r/9426 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../core/parser/tests/ast2/AST2BaseTest.java | 848 ++++++++++++++++++ .../core/parser/tests/ast2/AST2CPPTests.java | 33 + .../core/dom/parser/SizeofCalculator.java | 24 +- 3 files changed, 901 insertions(+), 4 deletions(-) create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java new file mode 100644 index 00000000000..dbcaed9b143 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -0,0 +1,848 @@ +/******************************************************************************* + * Copyright (c) 2004, 2013 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) + * Mike Kucera (IBM) + * Sergey Prigogin (Google) + * Nathan Ridge + *******************************************************************************/ +package org.eclipse.cdt.core.parser.tests.ast2; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import junit.framework.AssertionFailedError; + +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTCastExpression; +import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTImplicitName; +import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; +import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IField; +import org.eclipse.cdt.core.dom.ast.IFunctionType; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; +import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; +import org.eclipse.cdt.core.parser.FileContent; +import org.eclipse.cdt.core.parser.IParserLogService; +import org.eclipse.cdt.core.parser.IScanner; +import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.cdt.core.parser.IncludeFileContentProvider; +import org.eclipse.cdt.core.parser.NullLogService; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.ScannerInfo; +import org.eclipse.cdt.core.parser.tests.ASTComparer; +import org.eclipse.cdt.core.testplugin.CTestPlugin; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.core.testplugin.util.TestSourceReader; +import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; +import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; +import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; +import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; +import org.eclipse.cdt.internal.core.model.ASTStringUtil; +import org.eclipse.cdt.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor; + +/** + * @author aniefer + */ +public class AST2BaseTest extends BaseTestCase { + public final static String TEST_CODE = ""; + protected static final IParserLogService NULL_LOG = new NullLogService(); + protected static boolean sValidateCopy; + + private static final ScannerInfo GNU_SCANNER_INFO = new ScannerInfo(getGnuMap()); + private static final ScannerInfo SCANNER_INFO = new ScannerInfo(getStdMap()); + + private static Map getGnuMap() { + Map map= new HashMap(); + map.put("__GNUC__", "4"); + map.put("__GNUC_MINOR__", "7"); + map.put("__SIZEOF_SHORT__", "2"); + map.put("__SIZEOF_INT__", "4"); + map.put("__SIZEOF_LONG__", "8"); + map.put("__SIZEOF_POINTER__", "8"); + return map; + } + + private static Map getStdMap() { + Map map= new HashMap(); + map.put("__SIZEOF_SHORT__", "2"); + map.put("__SIZEOF_INT__", "4"); + map.put("__SIZEOF_LONG__", "8"); + map.put("__SIZEOF_POINTER__", "8"); + return map; + } + + public AST2BaseTest() { + super(); + } + + public AST2BaseTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + sValidateCopy= true; + super.setUp(); + } + + protected IASTTranslationUnit parse(String code, ParserLanguage lang) throws ParserException { + return parse(code, lang, false, true); + } + + protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException { + return parse(code, lang, useGNUExtensions, true); + } + + protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, + boolean expectNoProblems) throws ParserException { + return parse(code, lang, useGNUExtensions, expectNoProblems, false); + } + + protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, + boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException { + IScanner scanner = createScanner(FileContent.create(TEST_CODE, code.toCharArray()), lang, ParserMode.COMPLETE_PARSE, + createScannerInfo(useGNUExtensions)); + configureScanner(scanner); + AbstractGNUSourceCodeParser parser = null; + if (lang == ParserLanguage.CPP) { + ICPPParserExtensionConfiguration config = null; + if (useGNUExtensions) { + config = new GPPParserExtensionConfiguration(); + } else { + config = new ANSICPPParserExtensionConfiguration(); + } + parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG,config, null); + } else { + ICParserExtensionConfiguration config = null; + + if (useGNUExtensions) { + config = new GCCParserExtensionConfiguration(); + } else { + config = new ANSICParserExtensionConfiguration(); + } + + parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config, null); + } + if (skipTrivialInitializers) + parser.setSkipTrivialExpressionsInAggregateInitializers(true); + + IASTTranslationUnit tu = parser.parse(); + assertTrue(tu.isFrozen()); + if (sValidateCopy) + validateCopy(tu); + + if (parser.encounteredError() && expectNoProblems) + throw new ParserException("FAILURE"); //$NON-NLS-1$ + + if (lang == ParserLanguage.C && expectNoProblems) { + assertEquals(CVisitor.getProblems(tu).length, 0); + assertEquals(tu.getPreprocessorProblems().length, 0); + } else if (lang == ParserLanguage.CPP && expectNoProblems) { + assertEquals(CPPVisitor.getProblems(tu).length, 0); + assertEquals(0, tu.getPreprocessorProblems().length); + } + if (expectNoProblems) + assertEquals(0, tu.getPreprocessorProblems().length); + + return tu; + } + + public ScannerInfo createScannerInfo(boolean useGnu) { + if (useGnu) + return GNU_SCANNER_INFO; + return SCANNER_INFO; + } + + protected void configureScanner(IScanner scanner) { + } + + public static IScanner createScanner(FileContent codeReader, ParserLanguage lang, ParserMode mode, + IScannerInfo scannerInfo) { + IScannerExtensionConfiguration configuration = null; + if (lang == ParserLanguage.C) { + configuration= GCCScannerExtensionConfiguration.getInstance(scannerInfo); + } else { + configuration= GPPScannerExtensionConfiguration.getInstance(scannerInfo); + } + IScanner scanner; + scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration, + IncludeFileContentProvider.getSavedFilesProvider()); + return scanner; + } + + protected void validateSimplePostfixInitializerExpressionC(String code) throws ParserException { + ICASTTypeIdInitializerExpression e = (ICASTTypeIdInitializerExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); + assertNotNull(e); + assertNotNull(e.getTypeId()); + assertNotNull(e.getInitializer()); + } + + protected void validateSimpleUnaryTypeIdExpression(String code, int op) throws ParserException { + IASTCastExpression e = (IASTCastExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); + assertNotNull(e); + assertEquals(e.getOperator(), op); + assertNotNull(e.getTypeId()); + IASTIdExpression x = (IASTIdExpression) e.getOperand(); + assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$ + } + + protected void validateSimpleTypeIdExpressionC(String code, int op) throws ParserException { + IASTTypeIdExpression e = (IASTTypeIdExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); + assertNotNull(e); + assertEquals(e.getOperator(), op); + assertNotNull(e.getTypeId()); + } + + protected void validateSimpleUnaryExpressionC(String code, int operator) throws ParserException { + IASTUnaryExpression e = (IASTUnaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); + assertNotNull(e); + assertEquals(e.getOperator(), operator); + IASTIdExpression x = (IASTIdExpression) e.getOperand(); + assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$ + } + + protected void validateConditionalExpressionC(String code) throws ParserException { + IASTConditionalExpression e = (IASTConditionalExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); + assertNotNull(e); + IASTIdExpression x = (IASTIdExpression) e.getLogicalConditionExpression(); + assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$ + IASTIdExpression y = (IASTIdExpression) e.getPositiveResultExpression(); + assertEquals(y.getName().toString(), "y"); //$NON-NLS-1$ + IASTIdExpression x2 = (IASTIdExpression) e.getNegativeResultExpression(); + assertEquals(x.getName().toString(), x2.getName().toString()); + } + + protected void validateSimpleBinaryExpressionC(String code, int operand) throws ParserException { + IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); + assertNotNull(e); + assertEquals(e.getOperator(), operand); + IASTIdExpression x = (IASTIdExpression) e.getOperand1(); + assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$ + IASTIdExpression y = (IASTIdExpression) e.getOperand2(); + assertEquals(y.getName().toString(), "y"); //$NON-NLS-1$ + } + + protected IASTExpression getExpressionFromStatementInCode(String code, ParserLanguage language) throws ParserException { + StringBuffer buffer = new StringBuffer("void f() { "); //$NON-NLS-1$ + buffer.append("int x, y;\n"); //$NON-NLS-1$ + buffer.append(code); + buffer.append(";\n}"); //$NON-NLS-1$ + IASTTranslationUnit tu = parse(buffer.toString(), language); + IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0]; + IASTCompoundStatement cs = (IASTCompoundStatement) f.getBody(); + IASTExpressionStatement s = (IASTExpressionStatement) cs.getStatements()[1]; + return s.getExpression(); + } + + protected T validateCopy(T tu) { + IASTNode copy = tu.copy(); + assertFalse(copy.isFrozen()); + ASTComparer.assertCopy(tu, copy); + return (T) copy; + } + + + static protected class CNameCollector extends ASTVisitor { + { + shouldVisitNames = true; + } + public List nameList = new ArrayList(); + + @Override + public int visit(IASTName name) { + nameList.add(name); + return PROCESS_CONTINUE; + } + + public IASTName getName(int idx) { + if (idx < 0 || idx >= nameList.size()) + return null; + return nameList.get(idx); + } + + public int size() { + return nameList.size(); + } + } + + protected void assertInstances(CNameCollector collector, IBinding binding, int num) throws Exception { + int count = 0; + + assertNotNull(binding); + + for (int i = 0; i < collector.size(); i++) { + if (collector.getName(i).resolveBinding() == binding) + count++; + } + + assertEquals(count, num); + } + + static protected class CPPNameCollector extends ASTVisitor { + { + shouldVisitNames = true; + } + public List nameList = new ArrayList(); + + @Override + public int visit(IASTName name) { + nameList.add(name); + return PROCESS_CONTINUE; + } + + public IASTName getName(int idx) { + if (idx < 0 || idx >= nameList.size()) + return null; + return nameList.get(idx); + } + + public int size() { + return nameList.size(); + } + + public void dump() { + for (int i= 0; i < size(); i++) { + IASTName name= getName(i); + String parent= name.getParent() != null ? name.getParent().getRawSignature() : ""; + System.out.println(i + ": #" + name.getRawSignature() + "# " + parent); + } + } + } + + protected void assertInstances(CPPNameCollector collector, IBinding binding, int num) throws Exception { + int count = 0; + for (int i = 0; i < collector.size(); i++) { + if (collector.getName(i).resolveBinding() == binding) + count++; + } + + assertEquals(num, count); + } + + protected void assertSameType(IType expected, IType actual) { + assertNotNull(expected); + assertNotNull(actual); + assertTrue("Expected same types, but the types were: '" + + ASTTypeUtil.getType(expected, false) + "' and '" + ASTTypeUtil.getType(actual, false) + "'", + expected.isSameType(actual)); + } + + protected void isExpressionStringEqual(IASTInitializerClause exp, String str) { + String expressionString = ASTStringUtil.getExpressionString((IASTExpression) exp); + assertEquals(str, expressionString); + } + + protected void isExpressionStringEqual(IASTExpression exp, String str) { + String expressionString = ASTStringUtil.getExpressionString(exp); + assertEquals(str, expressionString); + } + + protected void isParameterSignatureEqual(IASTDeclarator decltor, String str) { + assertTrue(decltor instanceof IASTFunctionDeclarator); + final String[] sigArray = ASTStringUtil.getParameterSignatureArray((IASTFunctionDeclarator) decltor); + assertEquals(str, "(" + ASTStringUtil.join(sigArray, ", ") + ")"); + } + + protected void isSignatureEqual(IASTDeclarator declarator, String expected) { + String signature= ASTStringUtil.getSignatureString(declarator); + assertEquals(expected, signature); + } + + protected void isSignatureEqual(IASTDeclSpecifier declSpec, String str) { + assertEquals(str, ASTStringUtil.getSignatureString(declSpec, null)); + } + + protected void isSignatureEqual(IASTTypeId typeId, String str) { + assertEquals(str, ASTStringUtil.getSignatureString(typeId.getDeclSpecifier(), typeId.getAbstractDeclarator())); + } + + protected void isTypeEqual(IASTDeclarator decltor, String str) { + assertEquals(str, ASTTypeUtil.getType(decltor)); + } + + protected void isTypeEqual(IASTTypeId typeId, String str) { + assertEquals(str, ASTTypeUtil.getType(typeId)); + } + + protected void isTypeEqual(IType type, String str) { + assertEquals(str, ASTTypeUtil.getType(type)); + } + + protected void isParameterTypeEqual(IFunctionType fType, String str) { + assertEquals(str, ASTTypeUtil.getParameterTypeString(fType)); + } + + static protected class CNameResolver extends ASTVisitor { + { + shouldVisitNames = true; + } + public int numProblemBindings; + public int numNullBindings; + public List nameList = new ArrayList(); + + @Override + public int visit(IASTName name) { + nameList.add(name); + IBinding binding = name.resolveBinding(); + if (binding instanceof IProblemBinding) + numProblemBindings++; + if (binding == null) + numNullBindings++; + return PROCESS_CONTINUE; + } + + public IASTName getName(int idx) { + if (idx < 0 || idx >= nameList.size()) + return null; + return nameList.get(idx); + } + + public int size() { + return nameList.size(); + } + } + + static protected class CPPNameResolver extends ASTVisitor { + { + shouldVisitNames = true; + } + public int numProblemBindings; + public int numNullBindings; + public List nameList = new ArrayList(); + + @Override + public int visit(IASTName name) { + nameList.add(name); + IBinding binding = name.resolveBinding(); + if (binding instanceof IProblemBinding) + numProblemBindings++; + if (binding == null) + numNullBindings++; + return PROCESS_CONTINUE; + } + + public IASTName getName(int idx) { + if (idx < 0 || idx >= nameList.size()) + return null; + return nameList.get(idx); + } + + public int size() { + return nameList.size(); + } + } + + protected String getAboveComment() throws IOException { + return getContents(1)[0].toString(); + } + + protected CharSequence[] getContents(int sections) throws IOException { + CTestPlugin plugin = CTestPlugin.getDefault(); + if (plugin == null) + throw new AssertionFailedError("This test must be run as a JUnit plugin test"); + return TestSourceReader.getContentsForTest(plugin.getBundle(), "parser", getClass(), getName(), sections); + } + + protected static T assertInstance(Object o, Class clazz, Class... cs) { + assertNotNull("Expected object of " + clazz.getName() + " but got a null value", o); + assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o)); + for (Class c : cs) { + assertNotNull("Expected object of " + c.getName() + " but got a null value", o); + assertTrue("Expected " + c.getName() + " but got " + o.getClass().getName(), c.isInstance(o)); + } + return clazz.cast(o); + } + + protected static void assertField(IBinding binding, String fieldName, String ownerName) { + assertInstance(binding, IField.class); + assertEquals(fieldName, binding.getName()); + ICompositeType struct = ((IField) binding).getCompositeTypeOwner(); + assertEquals(ownerName, struct.getName()); + } + + protected class BindingAssertionHelper { + protected IASTTranslationUnit tu; + protected String contents; + protected boolean isCPP; + + public BindingAssertionHelper(String contents, boolean isCPP) throws ParserException { + this(contents, isCPP ? ParserLanguage.CPP : ParserLanguage.C); + } + + public BindingAssertionHelper(String contents, ParserLanguage lang) throws ParserException { + this.contents= contents; + this.isCPP= lang.isCPP(); + this.tu= parse(contents, lang, true, false); + } + + public IASTTranslationUnit getTranslationUnit() { + return tu; + } + + public IProblemBinding assertProblem(String section, int len) { + if (len <= 0) + len= section.length() + len; + IBinding binding= binding(section, len); + assertTrue("Non-ProblemBinding for name: " + section.substring(0, len), + binding instanceof IProblemBinding); + return (IProblemBinding) binding; + } + + public IProblemBinding assertProblem(String context, int len, int problemId) { + IProblemBinding problemBinding = assertProblem(context, len); + assertEquals(problemId, problemBinding.getID()); + return problemBinding; + } + + public IProblemBinding assertProblem(String context, String name) { + IBinding binding= binding(context, name); + assertTrue("Non-ProblemBinding for name: " + name, binding instanceof IProblemBinding); + return (IProblemBinding) binding; + } + + public IProblemBinding assertProblem(String context, String name, int problemId) { + IProblemBinding problemBinding = assertProblem(context, name); + assertEquals(problemId, problemBinding.getID()); + return problemBinding; + } + + public T assertNonProblem(String section, int len) { + if (len <= 0) + len= section.length() + len; + IBinding binding= binding(section, len); + if (binding instanceof IProblemBinding) { + IProblemBinding problem= (IProblemBinding) binding; + fail("ProblemBinding for name: " + section.substring(0, len) + " (" + renderProblemID(problem.getID()) + ")"); + } + if (binding == null) { + fail("Null binding resolved for name: " + section.substring(0, len)); + } + return (T) binding; + } + + private int getIdentifierLength(String str) { + int i; + for (i = 0; i < str.length() && Character.isJavaIdentifierPart(str.charAt(i)); ++i) { + } + return i; + } + + public IProblemBinding assertProblemOnFirstIdentifier(String section) { + return assertProblem(section, getIdentifierLength(section)); + } + + public IProblemBinding assertProblemOnFirstIdentifier(String section, int problemId) { + IProblemBinding problemBinding = assertProblemOnFirstIdentifier(section); + assertEquals(problemId, problemBinding.getID()); + return problemBinding; + } + + public T assertNonProblemOnFirstIdentifier(String section, Class... cs) { + return assertNonProblem(section, getIdentifierLength(section), cs); + } + + public IBinding assertNonProblemOnFirstIdentifier(String section) { + return assertNonProblem(section, getIdentifierLength(section), IBinding.class); + } + + public void assertNoName(String section, int len) { + IASTName name= findName(section, len); + if (name != null) { + String selection = section.substring(0, len); + fail("Found unexpected \"" + selection + "\": " + name.resolveBinding()); + } + } + + /** + * Asserts that there is exactly one name at the given location and that + * it resolves to the given type of binding. + */ + public IASTImplicitName assertImplicitName(String section, int len, Class bindingClass) { + IASTName name = findImplicitName(section, len); + final String selection = section.substring(0, len); + assertNotNull("did not find \"" + selection + "\"", name); + + assertInstance(name, IASTImplicitName.class); + IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent(); + IASTImplicitName[] implicits = owner.getImplicitNames(); + assertNotNull(implicits); + + if (implicits.length > 1) { + boolean found = false; + for (IASTImplicitName n : implicits) { + if (((ASTNode) n).getOffset() == ((ASTNode) name).getOffset()) { + assertFalse(found); + found = true; + } + } + assertTrue(found); + } + + assertEquals(selection, name.getRawSignature()); + IBinding binding = name.resolveBinding(); + assertNotNull(binding); + assertInstance(binding, bindingClass); + return (IASTImplicitName) name; + } + + public void assertNoImplicitName(String section, int len) { + IASTName name = findImplicitName(section, len); + final String selection = section.substring(0, len); + assertNull("found name \"" + selection + "\"", name); + } + + public IASTImplicitName[] getImplicitNames(String section, int len) { + IASTName name = findImplicitName(section, len); + IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent(); + IASTImplicitName[] implicits = owner.getImplicitNames(); + return implicits; + } + + public IASTName findName(String section, int len) { + final int offset = contents.indexOf(section); + assertTrue("Section \"" + section + "\" not found", offset >= 0); + IASTNodeSelector selector = tu.getNodeSelector(null); + return selector.findName(offset, len); + } + + public IASTName findName(String context, String name) { + if (context == null) { + context = contents; + } + int offset = contents.indexOf(context); + assertTrue("Context \"" + context + "\" not found", offset >= 0); + int nameOffset = context.indexOf(name); + assertTrue("Name \"" + name + "\" not found", nameOffset >= 0); + IASTNodeSelector selector = tu.getNodeSelector(null); + return selector.findName(offset + nameOffset, name.length()); + } + + public IASTName findName(String name) { + return findName(contents, name); + } + + public IASTName findImplicitName(String section, int len) { + final int offset = contents.indexOf(section); + assertTrue(offset >= 0); + IASTNodeSelector selector = tu.getNodeSelector(null); + return selector.findImplicitName(offset, len); + } + + public T assertNode(String context, String nodeText, Class... cs) { + if (context == null) { + context = contents; + } + int offset = contents.indexOf(context); + assertTrue("Context \"" + context + "\" not found", offset >= 0); + int nodeOffset = context.indexOf(nodeText); + assertTrue("Node \"" + nodeText + "\" not found", nodeOffset >= 0); + IASTNodeSelector selector = tu.getNodeSelector(null); + IASTNode node = selector.findNode(offset + nodeOffset, nodeText.length()); + return assertType(node, cs); + } + + public T assertNode(String nodeText, Class... cs) { + return assertNode(contents, nodeText, cs); + } + + private String renderProblemID(int i) { + try { + for (Field field : IProblemBinding.class.getDeclaredFields()) { + if (field.getName().startsWith("SEMANTIC_")) { + if (field.getType() == int.class) { + Integer ci= (Integer) field.get(null); + if (ci.intValue() == i) { + return field.getName(); + } + } + } + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + return "Unknown problem ID"; + } + + public T assertNonProblem(String section, int len, Class... cs) { + if (len <= 0) + len += section.length(); + IBinding binding= binding(section, len); + assertTrue("ProblemBinding for name: " + section.substring(0, len), + !(binding instanceof IProblemBinding)); + return assertType(binding, cs); + } + + public T assertNonProblem(String section, Class... cs) { + return assertNonProblem(section, section.length(), cs); + } + + public T assertNonProblem(String context, String name, Class... cs) { + IBinding binding= binding(context, name); + assertTrue("ProblemBinding for name: " + name, !(binding instanceof IProblemBinding)); + return assertType(binding, cs); + } + + public U assertType(T obj, Class... cs) { + for (Class c : cs) { + assertInstance(obj, c); + } + return (U) obj; + } + + private IBinding binding(String section, int len) { + IASTName astName = findName(section, len); + final String selection = section.substring(0, len); + assertNotNull("No AST name for \"" + selection + "\"", astName); + assertEquals(selection, astName.getRawSignature()); + + IBinding binding = astName.resolveBinding(); + assertNotNull("No binding for " + astName.getRawSignature(), binding); + + return astName.resolveBinding(); + } + + private IBinding binding(String context, String name) { + IASTName astName = findName(context, name); + assertNotNull("No AST name for \"" + name + "\"", astName); + assertEquals(name, astName.getRawSignature()); + + IBinding binding = astName.resolveBinding(); + assertNotNull("No binding for " + astName.getRawSignature(), binding); + + return astName.resolveBinding(); + } + } + + final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang) throws Exception { + return parseAndCheckBindings(code, lang, false); + } + + final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions) throws Exception { + return parseAndCheckBindings(code, lang, useGnuExtensions, false); + } + + final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions, + boolean skipTrivialInitializers) throws Exception { + IASTTranslationUnit tu = parse(code, lang, useGnuExtensions, true, skipTrivialInitializers); + CNameCollector col = new CNameCollector(); + tu.accept(col); + assertNoProblemBindings(col); + return tu; + } + + final protected void assertNoProblemBindings(CNameCollector col) { + for (IASTName n : col.nameList) { + assertFalse("ProblemBinding for " + n.getRawSignature(), n.resolveBinding() instanceof IProblemBinding); + } + } + + final protected void assertProblemBindings(CNameCollector col, int count) { + int sum = 0; + for (IASTName n : col.nameList) { + if (n.getBinding() instanceof IProblemBinding) + ++sum; + } + assertEquals(count, sum); + } + + final protected T getDeclaration(IASTTranslationUnit tu, int i_decl) { + Class tclass; + IASTDeclaration[] decls= tu.getDeclarations(); + assertTrue(decls.length > i_decl); + return (T) decls[i_decl]; + } + + final protected T getDeclaration(ICPPASTNamespaceDefinition ns, int i_decl) { + Class tclass; + IASTDeclaration[] decls= ns.getDeclarations(); + assertTrue(decls.length > i_decl); + return (T) decls[i_decl]; + } + + final protected T getDeclaration(ICPPASTLinkageSpecification ls, int i_decl) { + Class tclass; + IASTDeclaration[] decls= ls.getDeclarations(); + assertTrue(decls.length > i_decl); + return (T) decls[i_decl]; + } + + final protected T getDeclaration(IASTCompositeTypeSpecifier ct, int i_decl) { + Class tclass; + IASTDeclaration[] decls= ct.getMembers(); + assertTrue(decls.length > i_decl); + return (T) decls[i_decl]; + } + + final protected T getCompositeType(IASTTranslationUnit tu, int i_decl) { + IASTSimpleDeclaration sdecl= getDeclaration(tu, i_decl); + return (T) sdecl.getDeclSpecifier(); + } + + final protected T getStatement(IASTFunctionDefinition fdef, int i_stmt) { + return getStatement((IASTCompoundStatement) fdef.getBody(), i_stmt); + } + + final protected T getStatement(IASTCompoundStatement compound, int i_stmt) { + IASTStatement[] stmts= compound.getStatements(); + assertTrue(stmts.length > i_stmt); + return (T) stmts[i_stmt]; + } + + final protected T getExpressionOfStatement(IASTFunctionDefinition fdef, int i) { + IASTStatement stmt= getStatement(fdef, i); + assertInstance(stmt, IASTExpressionStatement.class); + return (T) ((IASTExpressionStatement) stmt).getExpression(); + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index eb4b961ae3b..ff1f4eef230 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -128,6 +128,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod; @@ -10153,4 +10154,36 @@ public class AST2CPPTests extends AST2TestBase { public void testIsBaseOf_399353() throws Exception { parseAndCheckBindings(getAboveComment(), CPP, true); } + + // template struct B{}; + // template <> + // struct B { + // void waldo(); + // }; + // typedef char& one; + // int main() { + // B b; + // b.waldo(); + // } + public void testSizeofReference_397342() throws Exception { + parseAndCheckBindings(); + } + + // struct A { + // char a[100]; + // }; + // struct B { + // A& b; + // }; + // A* p; + public void testSizeofStructWithReferenceField_397342() throws Exception { + BindingAssertionHelper bh = getAssertionHelper(); + IASTName nameB = bh.findName("B"); + IASTName namep = bh.findName("p"); + ICPPClassType B = (ICPPClassType) nameB.resolveBinding(); + IPointerType ptrToA = (IPointerType) ((ICPPVariable) namep.resolveBinding()).getType(); + long pointerSize = SizeofCalculator.getSizeAndAlignment(ptrToA, namep).size; + long BSize = SizeofCalculator.getSizeAndAlignment(B, nameB).size; + assertEquals(pointerSize, BSize); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index 92ebd31459a..387da41ee83 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Google, Inc and others. + * Copyright (c) 2011, 2013 Google, 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 @@ -7,6 +7,7 @@ * * Contributors: * Sergey Prigogin (Google) - initial API and implementation + * Nathan Ridge *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -182,7 +183,12 @@ public class SizeofCalculator { if (type instanceof IBasicType) { return sizeAndAlignment((IBasicType) type); } - if (type instanceof IPointerType || type instanceof ICPPReferenceType) { + // [expr.sizeof]/2: "When applied to a reference or a reference type, the + // result is the size of the referenced type." + if (type instanceof ICPPReferenceType) { + return sizeAndAlignment(((ICPPReferenceType) type).getType()); + } + if (type instanceof IPointerType) { if (type instanceof ICPPPointerToMemberType) return null; return sizeof_pointer; @@ -314,14 +320,24 @@ public class SizeofCalculator { if (field.isStatic()) continue; IType fieldType = field.getType(); - SizeAndAlignment info = sizeAndAlignment(fieldType); + SizeAndAlignment info; + // sizeof() on a reference type returns the size of the referenced type. + // However, a reference field in a structure only occupies as much space + // as a pointer. + if (fieldType instanceof ICPPReferenceType) { + info = sizeof_pointer; + } else { + info = sizeAndAlignment(fieldType); + } if (info == null) return null; if (union) { if (size < info.size) size = info.size; } else { - size += info.alignment - (size - 1) % info.alignment - 1 + info.size; + if (size > 0) + size += info.alignment - (size - 1) % info.alignment - 1; + size += info.size; } if (maxAlignment < info.alignment) maxAlignment = info.alignment; From 9c151f6127c6b0c8555e1b78fc9db48a0723306f Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 30 Jan 2013 11:54:44 -0800 Subject: [PATCH 37/42] Fixed an NPE. --- .../org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java index afb76a90c9d..54928023f80 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TestBase.java @@ -110,6 +110,7 @@ public class AST2TestBase extends BaseTestCase { map.put("__SIZEOF_SHORT__", "2"); map.put("__SIZEOF_INT__", "4"); map.put("__SIZEOF_LONG__", "8"); + map.put("__SIZEOF_POINTER__", "8"); return map; } @@ -118,6 +119,7 @@ public class AST2TestBase extends BaseTestCase { map.put("__SIZEOF_SHORT__", "2"); map.put("__SIZEOF_INT__", "4"); map.put("__SIZEOF_LONG__", "8"); + map.put("__SIZEOF_POINTER__", "8"); return map; } From 4caa97f8d6c42776a5a5cb15c4afe8cf13286f5d Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 30 Jan 2013 11:56:20 -0800 Subject: [PATCH 38/42] Bug 399142. Proper signatures for types of dependent expressions. --- .../eclipse/cdt/core/dom/ast/ASTTypeUtil.java | 7 +- .../parser/cpp/semantics/CPPEvaluation.java | 191 +--------------- .../cpp/semantics/SignatureBuilder.java | 204 ++++++++++++++++++ .../semantics/TypeOfDependentExpression.java | 15 +- 4 files changed, 224 insertions(+), 193 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java index 42ec1b40b31..f2097edf8d8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2013 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 @@ -45,6 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownMemberClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.TypeOfDependentExpression; /** * This is a utility class to help convert AST elements to Strings corresponding to @@ -408,6 +409,8 @@ public class ASTTypeUtil { IQualifierType qt= (IQualifierType) type; needSpace= appendCVQ(result, needSpace, qt.isConst(), qt.isVolatile(), false); + } else if (type instanceof TypeOfDependentExpression) { + result.append(((TypeOfDependentExpression) type).getSignature()); } else if (type instanceof ISemanticProblem) { result.append('?'); } else if (type != null) { @@ -584,7 +587,7 @@ public class ASTTypeUtil { if (parenthesis == null) { parenthesis= new BitSet(); } - parenthesis.set(postfix.size()-1); + parenthesis.set(postfix.size() - 1); } appendTypeString(tj, normalize, result); needParenthesis= false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java index d1d279b2628..81a51e64dd1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPEvaluation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Google, Inc and others. + * Copyright (c) 2012, 2013 Google, 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 @@ -11,207 +11,18 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.IValue; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; -import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; -import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; -import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.core.runtime.CoreException; public abstract class CPPEvaluation implements ICPPEvaluation { - private static class SignatureBuilder implements ITypeMarshalBuffer { - private static final byte NULL_TYPE= 0; - private static final byte UNSTORABLE_TYPE= (byte) -1; - - private final StringBuilder fBuffer; - - /** - * Constructor for input buffer. - */ - public SignatureBuilder() { - fBuffer= new StringBuilder(); - } - - @Override - public String toString() { - return fBuffer.toString(); - } - - public char[] getSignature() { - return CharArrayUtils.extractChars(fBuffer); - } - - @Override - public void marshalBinding(IBinding binding) throws CoreException { - if (binding instanceof ISerializableType) { - ((ISerializableType) binding).marshal(this); - } else if (binding == null) { - putByte(NULL_TYPE); - } else { - appendSeparator(); - if (binding instanceof ICPPBinding) { - if (binding instanceof ICPPTemplateParameter) { - ICPPTemplateParameter param = (ICPPTemplateParameter) binding; - fBuffer.append(param.isParameterPack() ? '*' : '#'); - fBuffer.append(param.getParameterID()); - } else { - fBuffer.append(ASTTypeUtil.getQualifiedName((ICPPBinding) binding)); - } - } else { - fBuffer.append(binding.getNameCharArray()); - } - } - } - - @Override - public void marshalType(IType type) throws CoreException { - if (type instanceof ISerializableType) { - ((ISerializableType) type).marshal(this); - } else if (type == null) { - putByte(NULL_TYPE); - } else if (type instanceof IBinding) { - marshalBinding((IBinding) type); - } else { - assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + " (" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ - putByte(UNSTORABLE_TYPE); - } - } - - @Override - public void marshalEvaluation(ISerializableEvaluation eval, boolean includeValues) throws CoreException { - if (eval == null) { - putByte(NULL_TYPE); - } else { - eval.marshal(this, includeValues); - } - } - - @Override - public void marshalValue(IValue value) throws CoreException { - if (value instanceof Value) { - ((Value) value).marshall(this); - } else { - putByte(NULL_TYPE); - } - } - - @Override - public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException { - if (arg.isNonTypeValue()) { - putByte(VALUE); - arg.getNonTypeEvaluation().marshal(this, true); - } else { - marshalType(arg.getTypeValue()); - } - } - - @Override - public void putByte(byte value) { - appendSeparator(); - fBuffer.append(value); - } - - @Override - public void putFixedInt(int value) { - appendSeparator(); - fBuffer.append(value); - } - - @Override - public void putInt(int value) { - appendSeparator(); - fBuffer.append(value); - } - - @Override - public void putLong(long value) { - appendSeparator(); - fBuffer.append(value); - } - - @Override - public void putCharArray(char[] chars) { - appendSeparator(); - for (char c : chars) { - fBuffer.append(c); - } - } - - private void appendSeparator() { - if (fBuffer.length() != 0) - fBuffer.append(' '); - } - - @Override - public IBinding unmarshalBinding() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public IType unmarshalType() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public ISerializableEvaluation unmarshalEvaluation() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public IValue unmarshalValue() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public int getByte() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public CoreException unmarshallingError() { - throw new UnsupportedOperationException(); - } - - @Override - public int getFixedInt() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public int getInt() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public long getLong() throws CoreException { - throw new UnsupportedOperationException(); - } - - @Override - public char[] getCharArray() throws CoreException { - throw new UnsupportedOperationException(); - } - } - CPPEvaluation() { } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java new file mode 100644 index 00000000000..7ec523e7b46 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SignatureBuilder.java @@ -0,0 +1,204 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 Google, 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: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; + +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IValue; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; +import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; +import org.eclipse.cdt.internal.core.dom.parser.Value; +import org.eclipse.core.runtime.CoreException; + +class SignatureBuilder implements ITypeMarshalBuffer { + private static final byte NULL_TYPE= 0; + private static final byte UNSTORABLE_TYPE= (byte) -1; + + private final StringBuilder fBuffer; + + /** + * Constructor for input buffer. + */ + public SignatureBuilder() { + fBuffer= new StringBuilder(); + } + + @Override + public String toString() { + return fBuffer.toString(); + } + + public char[] getSignature() { + return CharArrayUtils.extractChars(fBuffer); + } + + @Override + public void marshalBinding(IBinding binding) throws CoreException { + if (binding instanceof ISerializableType) { + ((ISerializableType) binding).marshal(this); + } else if (binding == null) { + putByte(NULL_TYPE); + } else { + appendSeparator(); + if (binding instanceof ICPPBinding) { + if (binding instanceof ICPPTemplateParameter) { + ICPPTemplateParameter param = (ICPPTemplateParameter) binding; + fBuffer.append(param.isParameterPack() ? '*' : '#'); + fBuffer.append(param.getParameterID()); + } else { + fBuffer.append(ASTTypeUtil.getQualifiedName((ICPPBinding) binding)); + } + } else { + fBuffer.append(binding.getNameCharArray()); + } + } + } + + @Override + public void marshalType(IType type) throws CoreException { + if (type instanceof ISerializableType) { + ((ISerializableType) type).marshal(this); + } else if (type == null) { + putByte(NULL_TYPE); + } else if (type instanceof IBinding) { + marshalBinding((IBinding) type); + } else { + assert false : "Cannot serialize " + ASTTypeUtil.getType(type) + " (" + type.getClass().getName() + ")"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + putByte(UNSTORABLE_TYPE); + } + } + + @Override + public void marshalEvaluation(ISerializableEvaluation eval, boolean includeValues) throws CoreException { + if (eval == null) { + putByte(NULL_TYPE); + } else { + eval.marshal(this, includeValues); + } + } + + @Override + public void marshalValue(IValue value) throws CoreException { + if (value instanceof Value) { + ((Value) value).marshall(this); + } else { + putByte(NULL_TYPE); + } + } + + @Override + public void marshalTemplateArgument(ICPPTemplateArgument arg) throws CoreException { + if (arg.isNonTypeValue()) { + putByte(VALUE); + arg.getNonTypeEvaluation().marshal(this, true); + } else { + marshalType(arg.getTypeValue()); + } + } + + @Override + public void putByte(byte value) { + appendSeparator(); + fBuffer.append(value); + } + + @Override + public void putFixedInt(int value) { + appendSeparator(); + fBuffer.append(value); + } + + @Override + public void putInt(int value) { + appendSeparator(); + fBuffer.append(value); + } + + @Override + public void putLong(long value) { + appendSeparator(); + fBuffer.append(value); + } + + @Override + public void putCharArray(char[] chars) { + appendSeparator(); + for (char c : chars) { + fBuffer.append(c); + } + } + + private void appendSeparator() { + if (fBuffer.length() != 0) + fBuffer.append(' '); + } + + @Override + public IBinding unmarshalBinding() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public IType unmarshalType() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public ISerializableEvaluation unmarshalEvaluation() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public IValue unmarshalValue() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public ICPPTemplateArgument unmarshalTemplateArgument() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public int getByte() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public CoreException unmarshallingError() { + throw new UnsupportedOperationException(); + } + + @Override + public int getFixedInt() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public int getInt() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public long getLong() throws CoreException { + throw new UnsupportedOperationException(); + } + + @Override + public char[] getCharArray() throws CoreException { + throw new UnsupportedOperationException(); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java index 6fdd5259adc..d77e3e96595 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TypeOfDependentExpression.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2012, 2013 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 @@ -7,9 +7,11 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ISerializableType; @@ -48,6 +50,17 @@ public class TypeOfDependentExpression implements ICPPUnknownType, ISerializable } } + public char[] getSignature() { + SignatureBuilder buf = new SignatureBuilder(); + try { + marshal(buf); + } catch (CoreException e) { + CCorePlugin.log(e); + return new char[] { '?' }; + } + return buf.getSignature(); + } + @Override public void marshal(ITypeMarshalBuffer buffer) throws CoreException { buffer.putByte(ITypeMarshalBuffer.DEPENDENT_EXPRESSION_TYPE); From 47373b66448440510f6dc3586022b8041c420061 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 30 Jan 2013 13:22:42 -0800 Subject: [PATCH 39/42] Deleted an obsolete file. --- .../core/parser/tests/ast2/AST2BaseTest.java | 848 ------------------ 1 file changed, 848 deletions(-) delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java deleted file mode 100644 index dbcaed9b143..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ /dev/null @@ -1,848 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2013 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Markus Schorn (Wind River Systems) - * Andrew Ferguson (Symbian) - * Mike Kucera (IBM) - * Sergey Prigogin (Google) - * Nathan Ridge - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests.ast2; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import junit.framework.AssertionFailedError; - -import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; -import org.eclipse.cdt.core.dom.ast.IASTCastExpression; -import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; -import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; -import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; -import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; -import org.eclipse.cdt.core.dom.ast.IASTDeclaration; -import org.eclipse.cdt.core.dom.ast.IASTDeclarator; -import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; -import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; -import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; -import org.eclipse.cdt.core.dom.ast.IASTIdExpression; -import org.eclipse.cdt.core.dom.ast.IASTImplicitName; -import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; -import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; -import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; -import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; -import org.eclipse.cdt.core.dom.ast.IASTStatement; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.dom.ast.IASTTypeId; -import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; -import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; -import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.ICompositeType; -import org.eclipse.cdt.core.dom.ast.IField; -import org.eclipse.cdt.core.dom.ast.IFunctionType; -import org.eclipse.cdt.core.dom.ast.IProblemBinding; -import org.eclipse.cdt.core.dom.ast.IType; -import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; -import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; -import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration; -import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration; -import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration; -import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration; -import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration; -import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; -import org.eclipse.cdt.core.parser.FileContent; -import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IScanner; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.IncludeFileContentProvider; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.ASTComparer; -import org.eclipse.cdt.core.testplugin.CTestPlugin; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; -import org.eclipse.cdt.core.testplugin.util.TestSourceReader; -import org.eclipse.cdt.internal.core.dom.parser.ASTNode; -import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; -import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; -import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; -import org.eclipse.cdt.internal.core.model.ASTStringUtil; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor; - -/** - * @author aniefer - */ -public class AST2BaseTest extends BaseTestCase { - public final static String TEST_CODE = ""; - protected static final IParserLogService NULL_LOG = new NullLogService(); - protected static boolean sValidateCopy; - - private static final ScannerInfo GNU_SCANNER_INFO = new ScannerInfo(getGnuMap()); - private static final ScannerInfo SCANNER_INFO = new ScannerInfo(getStdMap()); - - private static Map getGnuMap() { - Map map= new HashMap(); - map.put("__GNUC__", "4"); - map.put("__GNUC_MINOR__", "7"); - map.put("__SIZEOF_SHORT__", "2"); - map.put("__SIZEOF_INT__", "4"); - map.put("__SIZEOF_LONG__", "8"); - map.put("__SIZEOF_POINTER__", "8"); - return map; - } - - private static Map getStdMap() { - Map map= new HashMap(); - map.put("__SIZEOF_SHORT__", "2"); - map.put("__SIZEOF_INT__", "4"); - map.put("__SIZEOF_LONG__", "8"); - map.put("__SIZEOF_POINTER__", "8"); - return map; - } - - public AST2BaseTest() { - super(); - } - - public AST2BaseTest(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - sValidateCopy= true; - super.setUp(); - } - - protected IASTTranslationUnit parse(String code, ParserLanguage lang) throws ParserException { - return parse(code, lang, false, true); - } - - protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions) throws ParserException { - return parse(code, lang, useGNUExtensions, true); - } - - protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, - boolean expectNoProblems) throws ParserException { - return parse(code, lang, useGNUExtensions, expectNoProblems, false); - } - - protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions, - boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException { - IScanner scanner = createScanner(FileContent.create(TEST_CODE, code.toCharArray()), lang, ParserMode.COMPLETE_PARSE, - createScannerInfo(useGNUExtensions)); - configureScanner(scanner); - AbstractGNUSourceCodeParser parser = null; - if (lang == ParserLanguage.CPP) { - ICPPParserExtensionConfiguration config = null; - if (useGNUExtensions) { - config = new GPPParserExtensionConfiguration(); - } else { - config = new ANSICPPParserExtensionConfiguration(); - } - parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG,config, null); - } else { - ICParserExtensionConfiguration config = null; - - if (useGNUExtensions) { - config = new GCCParserExtensionConfiguration(); - } else { - config = new ANSICParserExtensionConfiguration(); - } - - parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config, null); - } - if (skipTrivialInitializers) - parser.setSkipTrivialExpressionsInAggregateInitializers(true); - - IASTTranslationUnit tu = parser.parse(); - assertTrue(tu.isFrozen()); - if (sValidateCopy) - validateCopy(tu); - - if (parser.encounteredError() && expectNoProblems) - throw new ParserException("FAILURE"); //$NON-NLS-1$ - - if (lang == ParserLanguage.C && expectNoProblems) { - assertEquals(CVisitor.getProblems(tu).length, 0); - assertEquals(tu.getPreprocessorProblems().length, 0); - } else if (lang == ParserLanguage.CPP && expectNoProblems) { - assertEquals(CPPVisitor.getProblems(tu).length, 0); - assertEquals(0, tu.getPreprocessorProblems().length); - } - if (expectNoProblems) - assertEquals(0, tu.getPreprocessorProblems().length); - - return tu; - } - - public ScannerInfo createScannerInfo(boolean useGnu) { - if (useGnu) - return GNU_SCANNER_INFO; - return SCANNER_INFO; - } - - protected void configureScanner(IScanner scanner) { - } - - public static IScanner createScanner(FileContent codeReader, ParserLanguage lang, ParserMode mode, - IScannerInfo scannerInfo) { - IScannerExtensionConfiguration configuration = null; - if (lang == ParserLanguage.C) { - configuration= GCCScannerExtensionConfiguration.getInstance(scannerInfo); - } else { - configuration= GPPScannerExtensionConfiguration.getInstance(scannerInfo); - } - IScanner scanner; - scanner= new CPreprocessor(codeReader, scannerInfo, lang, NULL_LOG, configuration, - IncludeFileContentProvider.getSavedFilesProvider()); - return scanner; - } - - protected void validateSimplePostfixInitializerExpressionC(String code) throws ParserException { - ICASTTypeIdInitializerExpression e = (ICASTTypeIdInitializerExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); - assertNotNull(e); - assertNotNull(e.getTypeId()); - assertNotNull(e.getInitializer()); - } - - protected void validateSimpleUnaryTypeIdExpression(String code, int op) throws ParserException { - IASTCastExpression e = (IASTCastExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); - assertNotNull(e); - assertEquals(e.getOperator(), op); - assertNotNull(e.getTypeId()); - IASTIdExpression x = (IASTIdExpression) e.getOperand(); - assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$ - } - - protected void validateSimpleTypeIdExpressionC(String code, int op) throws ParserException { - IASTTypeIdExpression e = (IASTTypeIdExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); - assertNotNull(e); - assertEquals(e.getOperator(), op); - assertNotNull(e.getTypeId()); - } - - protected void validateSimpleUnaryExpressionC(String code, int operator) throws ParserException { - IASTUnaryExpression e = (IASTUnaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); - assertNotNull(e); - assertEquals(e.getOperator(), operator); - IASTIdExpression x = (IASTIdExpression) e.getOperand(); - assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$ - } - - protected void validateConditionalExpressionC(String code) throws ParserException { - IASTConditionalExpression e = (IASTConditionalExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); - assertNotNull(e); - IASTIdExpression x = (IASTIdExpression) e.getLogicalConditionExpression(); - assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$ - IASTIdExpression y = (IASTIdExpression) e.getPositiveResultExpression(); - assertEquals(y.getName().toString(), "y"); //$NON-NLS-1$ - IASTIdExpression x2 = (IASTIdExpression) e.getNegativeResultExpression(); - assertEquals(x.getName().toString(), x2.getName().toString()); - } - - protected void validateSimpleBinaryExpressionC(String code, int operand) throws ParserException { - IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C); - assertNotNull(e); - assertEquals(e.getOperator(), operand); - IASTIdExpression x = (IASTIdExpression) e.getOperand1(); - assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$ - IASTIdExpression y = (IASTIdExpression) e.getOperand2(); - assertEquals(y.getName().toString(), "y"); //$NON-NLS-1$ - } - - protected IASTExpression getExpressionFromStatementInCode(String code, ParserLanguage language) throws ParserException { - StringBuffer buffer = new StringBuffer("void f() { "); //$NON-NLS-1$ - buffer.append("int x, y;\n"); //$NON-NLS-1$ - buffer.append(code); - buffer.append(";\n}"); //$NON-NLS-1$ - IASTTranslationUnit tu = parse(buffer.toString(), language); - IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0]; - IASTCompoundStatement cs = (IASTCompoundStatement) f.getBody(); - IASTExpressionStatement s = (IASTExpressionStatement) cs.getStatements()[1]; - return s.getExpression(); - } - - protected T validateCopy(T tu) { - IASTNode copy = tu.copy(); - assertFalse(copy.isFrozen()); - ASTComparer.assertCopy(tu, copy); - return (T) copy; - } - - - static protected class CNameCollector extends ASTVisitor { - { - shouldVisitNames = true; - } - public List nameList = new ArrayList(); - - @Override - public int visit(IASTName name) { - nameList.add(name); - return PROCESS_CONTINUE; - } - - public IASTName getName(int idx) { - if (idx < 0 || idx >= nameList.size()) - return null; - return nameList.get(idx); - } - - public int size() { - return nameList.size(); - } - } - - protected void assertInstances(CNameCollector collector, IBinding binding, int num) throws Exception { - int count = 0; - - assertNotNull(binding); - - for (int i = 0; i < collector.size(); i++) { - if (collector.getName(i).resolveBinding() == binding) - count++; - } - - assertEquals(count, num); - } - - static protected class CPPNameCollector extends ASTVisitor { - { - shouldVisitNames = true; - } - public List nameList = new ArrayList(); - - @Override - public int visit(IASTName name) { - nameList.add(name); - return PROCESS_CONTINUE; - } - - public IASTName getName(int idx) { - if (idx < 0 || idx >= nameList.size()) - return null; - return nameList.get(idx); - } - - public int size() { - return nameList.size(); - } - - public void dump() { - for (int i= 0; i < size(); i++) { - IASTName name= getName(i); - String parent= name.getParent() != null ? name.getParent().getRawSignature() : ""; - System.out.println(i + ": #" + name.getRawSignature() + "# " + parent); - } - } - } - - protected void assertInstances(CPPNameCollector collector, IBinding binding, int num) throws Exception { - int count = 0; - for (int i = 0; i < collector.size(); i++) { - if (collector.getName(i).resolveBinding() == binding) - count++; - } - - assertEquals(num, count); - } - - protected void assertSameType(IType expected, IType actual) { - assertNotNull(expected); - assertNotNull(actual); - assertTrue("Expected same types, but the types were: '" + - ASTTypeUtil.getType(expected, false) + "' and '" + ASTTypeUtil.getType(actual, false) + "'", - expected.isSameType(actual)); - } - - protected void isExpressionStringEqual(IASTInitializerClause exp, String str) { - String expressionString = ASTStringUtil.getExpressionString((IASTExpression) exp); - assertEquals(str, expressionString); - } - - protected void isExpressionStringEqual(IASTExpression exp, String str) { - String expressionString = ASTStringUtil.getExpressionString(exp); - assertEquals(str, expressionString); - } - - protected void isParameterSignatureEqual(IASTDeclarator decltor, String str) { - assertTrue(decltor instanceof IASTFunctionDeclarator); - final String[] sigArray = ASTStringUtil.getParameterSignatureArray((IASTFunctionDeclarator) decltor); - assertEquals(str, "(" + ASTStringUtil.join(sigArray, ", ") + ")"); - } - - protected void isSignatureEqual(IASTDeclarator declarator, String expected) { - String signature= ASTStringUtil.getSignatureString(declarator); - assertEquals(expected, signature); - } - - protected void isSignatureEqual(IASTDeclSpecifier declSpec, String str) { - assertEquals(str, ASTStringUtil.getSignatureString(declSpec, null)); - } - - protected void isSignatureEqual(IASTTypeId typeId, String str) { - assertEquals(str, ASTStringUtil.getSignatureString(typeId.getDeclSpecifier(), typeId.getAbstractDeclarator())); - } - - protected void isTypeEqual(IASTDeclarator decltor, String str) { - assertEquals(str, ASTTypeUtil.getType(decltor)); - } - - protected void isTypeEqual(IASTTypeId typeId, String str) { - assertEquals(str, ASTTypeUtil.getType(typeId)); - } - - protected void isTypeEqual(IType type, String str) { - assertEquals(str, ASTTypeUtil.getType(type)); - } - - protected void isParameterTypeEqual(IFunctionType fType, String str) { - assertEquals(str, ASTTypeUtil.getParameterTypeString(fType)); - } - - static protected class CNameResolver extends ASTVisitor { - { - shouldVisitNames = true; - } - public int numProblemBindings; - public int numNullBindings; - public List nameList = new ArrayList(); - - @Override - public int visit(IASTName name) { - nameList.add(name); - IBinding binding = name.resolveBinding(); - if (binding instanceof IProblemBinding) - numProblemBindings++; - if (binding == null) - numNullBindings++; - return PROCESS_CONTINUE; - } - - public IASTName getName(int idx) { - if (idx < 0 || idx >= nameList.size()) - return null; - return nameList.get(idx); - } - - public int size() { - return nameList.size(); - } - } - - static protected class CPPNameResolver extends ASTVisitor { - { - shouldVisitNames = true; - } - public int numProblemBindings; - public int numNullBindings; - public List nameList = new ArrayList(); - - @Override - public int visit(IASTName name) { - nameList.add(name); - IBinding binding = name.resolveBinding(); - if (binding instanceof IProblemBinding) - numProblemBindings++; - if (binding == null) - numNullBindings++; - return PROCESS_CONTINUE; - } - - public IASTName getName(int idx) { - if (idx < 0 || idx >= nameList.size()) - return null; - return nameList.get(idx); - } - - public int size() { - return nameList.size(); - } - } - - protected String getAboveComment() throws IOException { - return getContents(1)[0].toString(); - } - - protected CharSequence[] getContents(int sections) throws IOException { - CTestPlugin plugin = CTestPlugin.getDefault(); - if (plugin == null) - throw new AssertionFailedError("This test must be run as a JUnit plugin test"); - return TestSourceReader.getContentsForTest(plugin.getBundle(), "parser", getClass(), getName(), sections); - } - - protected static T assertInstance(Object o, Class clazz, Class... cs) { - assertNotNull("Expected object of " + clazz.getName() + " but got a null value", o); - assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o)); - for (Class c : cs) { - assertNotNull("Expected object of " + c.getName() + " but got a null value", o); - assertTrue("Expected " + c.getName() + " but got " + o.getClass().getName(), c.isInstance(o)); - } - return clazz.cast(o); - } - - protected static void assertField(IBinding binding, String fieldName, String ownerName) { - assertInstance(binding, IField.class); - assertEquals(fieldName, binding.getName()); - ICompositeType struct = ((IField) binding).getCompositeTypeOwner(); - assertEquals(ownerName, struct.getName()); - } - - protected class BindingAssertionHelper { - protected IASTTranslationUnit tu; - protected String contents; - protected boolean isCPP; - - public BindingAssertionHelper(String contents, boolean isCPP) throws ParserException { - this(contents, isCPP ? ParserLanguage.CPP : ParserLanguage.C); - } - - public BindingAssertionHelper(String contents, ParserLanguage lang) throws ParserException { - this.contents= contents; - this.isCPP= lang.isCPP(); - this.tu= parse(contents, lang, true, false); - } - - public IASTTranslationUnit getTranslationUnit() { - return tu; - } - - public IProblemBinding assertProblem(String section, int len) { - if (len <= 0) - len= section.length() + len; - IBinding binding= binding(section, len); - assertTrue("Non-ProblemBinding for name: " + section.substring(0, len), - binding instanceof IProblemBinding); - return (IProblemBinding) binding; - } - - public IProblemBinding assertProblem(String context, int len, int problemId) { - IProblemBinding problemBinding = assertProblem(context, len); - assertEquals(problemId, problemBinding.getID()); - return problemBinding; - } - - public IProblemBinding assertProblem(String context, String name) { - IBinding binding= binding(context, name); - assertTrue("Non-ProblemBinding for name: " + name, binding instanceof IProblemBinding); - return (IProblemBinding) binding; - } - - public IProblemBinding assertProblem(String context, String name, int problemId) { - IProblemBinding problemBinding = assertProblem(context, name); - assertEquals(problemId, problemBinding.getID()); - return problemBinding; - } - - public T assertNonProblem(String section, int len) { - if (len <= 0) - len= section.length() + len; - IBinding binding= binding(section, len); - if (binding instanceof IProblemBinding) { - IProblemBinding problem= (IProblemBinding) binding; - fail("ProblemBinding for name: " + section.substring(0, len) + " (" + renderProblemID(problem.getID()) + ")"); - } - if (binding == null) { - fail("Null binding resolved for name: " + section.substring(0, len)); - } - return (T) binding; - } - - private int getIdentifierLength(String str) { - int i; - for (i = 0; i < str.length() && Character.isJavaIdentifierPart(str.charAt(i)); ++i) { - } - return i; - } - - public IProblemBinding assertProblemOnFirstIdentifier(String section) { - return assertProblem(section, getIdentifierLength(section)); - } - - public IProblemBinding assertProblemOnFirstIdentifier(String section, int problemId) { - IProblemBinding problemBinding = assertProblemOnFirstIdentifier(section); - assertEquals(problemId, problemBinding.getID()); - return problemBinding; - } - - public T assertNonProblemOnFirstIdentifier(String section, Class... cs) { - return assertNonProblem(section, getIdentifierLength(section), cs); - } - - public IBinding assertNonProblemOnFirstIdentifier(String section) { - return assertNonProblem(section, getIdentifierLength(section), IBinding.class); - } - - public void assertNoName(String section, int len) { - IASTName name= findName(section, len); - if (name != null) { - String selection = section.substring(0, len); - fail("Found unexpected \"" + selection + "\": " + name.resolveBinding()); - } - } - - /** - * Asserts that there is exactly one name at the given location and that - * it resolves to the given type of binding. - */ - public IASTImplicitName assertImplicitName(String section, int len, Class bindingClass) { - IASTName name = findImplicitName(section, len); - final String selection = section.substring(0, len); - assertNotNull("did not find \"" + selection + "\"", name); - - assertInstance(name, IASTImplicitName.class); - IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent(); - IASTImplicitName[] implicits = owner.getImplicitNames(); - assertNotNull(implicits); - - if (implicits.length > 1) { - boolean found = false; - for (IASTImplicitName n : implicits) { - if (((ASTNode) n).getOffset() == ((ASTNode) name).getOffset()) { - assertFalse(found); - found = true; - } - } - assertTrue(found); - } - - assertEquals(selection, name.getRawSignature()); - IBinding binding = name.resolveBinding(); - assertNotNull(binding); - assertInstance(binding, bindingClass); - return (IASTImplicitName) name; - } - - public void assertNoImplicitName(String section, int len) { - IASTName name = findImplicitName(section, len); - final String selection = section.substring(0, len); - assertNull("found name \"" + selection + "\"", name); - } - - public IASTImplicitName[] getImplicitNames(String section, int len) { - IASTName name = findImplicitName(section, len); - IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent(); - IASTImplicitName[] implicits = owner.getImplicitNames(); - return implicits; - } - - public IASTName findName(String section, int len) { - final int offset = contents.indexOf(section); - assertTrue("Section \"" + section + "\" not found", offset >= 0); - IASTNodeSelector selector = tu.getNodeSelector(null); - return selector.findName(offset, len); - } - - public IASTName findName(String context, String name) { - if (context == null) { - context = contents; - } - int offset = contents.indexOf(context); - assertTrue("Context \"" + context + "\" not found", offset >= 0); - int nameOffset = context.indexOf(name); - assertTrue("Name \"" + name + "\" not found", nameOffset >= 0); - IASTNodeSelector selector = tu.getNodeSelector(null); - return selector.findName(offset + nameOffset, name.length()); - } - - public IASTName findName(String name) { - return findName(contents, name); - } - - public IASTName findImplicitName(String section, int len) { - final int offset = contents.indexOf(section); - assertTrue(offset >= 0); - IASTNodeSelector selector = tu.getNodeSelector(null); - return selector.findImplicitName(offset, len); - } - - public T assertNode(String context, String nodeText, Class... cs) { - if (context == null) { - context = contents; - } - int offset = contents.indexOf(context); - assertTrue("Context \"" + context + "\" not found", offset >= 0); - int nodeOffset = context.indexOf(nodeText); - assertTrue("Node \"" + nodeText + "\" not found", nodeOffset >= 0); - IASTNodeSelector selector = tu.getNodeSelector(null); - IASTNode node = selector.findNode(offset + nodeOffset, nodeText.length()); - return assertType(node, cs); - } - - public T assertNode(String nodeText, Class... cs) { - return assertNode(contents, nodeText, cs); - } - - private String renderProblemID(int i) { - try { - for (Field field : IProblemBinding.class.getDeclaredFields()) { - if (field.getName().startsWith("SEMANTIC_")) { - if (field.getType() == int.class) { - Integer ci= (Integer) field.get(null); - if (ci.intValue() == i) { - return field.getName(); - } - } - } - } - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - return "Unknown problem ID"; - } - - public T assertNonProblem(String section, int len, Class... cs) { - if (len <= 0) - len += section.length(); - IBinding binding= binding(section, len); - assertTrue("ProblemBinding for name: " + section.substring(0, len), - !(binding instanceof IProblemBinding)); - return assertType(binding, cs); - } - - public T assertNonProblem(String section, Class... cs) { - return assertNonProblem(section, section.length(), cs); - } - - public T assertNonProblem(String context, String name, Class... cs) { - IBinding binding= binding(context, name); - assertTrue("ProblemBinding for name: " + name, !(binding instanceof IProblemBinding)); - return assertType(binding, cs); - } - - public U assertType(T obj, Class... cs) { - for (Class c : cs) { - assertInstance(obj, c); - } - return (U) obj; - } - - private IBinding binding(String section, int len) { - IASTName astName = findName(section, len); - final String selection = section.substring(0, len); - assertNotNull("No AST name for \"" + selection + "\"", astName); - assertEquals(selection, astName.getRawSignature()); - - IBinding binding = astName.resolveBinding(); - assertNotNull("No binding for " + astName.getRawSignature(), binding); - - return astName.resolveBinding(); - } - - private IBinding binding(String context, String name) { - IASTName astName = findName(context, name); - assertNotNull("No AST name for \"" + name + "\"", astName); - assertEquals(name, astName.getRawSignature()); - - IBinding binding = astName.resolveBinding(); - assertNotNull("No binding for " + astName.getRawSignature(), binding); - - return astName.resolveBinding(); - } - } - - final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang) throws Exception { - return parseAndCheckBindings(code, lang, false); - } - - final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions) throws Exception { - return parseAndCheckBindings(code, lang, useGnuExtensions, false); - } - - final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang, boolean useGnuExtensions, - boolean skipTrivialInitializers) throws Exception { - IASTTranslationUnit tu = parse(code, lang, useGnuExtensions, true, skipTrivialInitializers); - CNameCollector col = new CNameCollector(); - tu.accept(col); - assertNoProblemBindings(col); - return tu; - } - - final protected void assertNoProblemBindings(CNameCollector col) { - for (IASTName n : col.nameList) { - assertFalse("ProblemBinding for " + n.getRawSignature(), n.resolveBinding() instanceof IProblemBinding); - } - } - - final protected void assertProblemBindings(CNameCollector col, int count) { - int sum = 0; - for (IASTName n : col.nameList) { - if (n.getBinding() instanceof IProblemBinding) - ++sum; - } - assertEquals(count, sum); - } - - final protected T getDeclaration(IASTTranslationUnit tu, int i_decl) { - Class tclass; - IASTDeclaration[] decls= tu.getDeclarations(); - assertTrue(decls.length > i_decl); - return (T) decls[i_decl]; - } - - final protected T getDeclaration(ICPPASTNamespaceDefinition ns, int i_decl) { - Class tclass; - IASTDeclaration[] decls= ns.getDeclarations(); - assertTrue(decls.length > i_decl); - return (T) decls[i_decl]; - } - - final protected T getDeclaration(ICPPASTLinkageSpecification ls, int i_decl) { - Class tclass; - IASTDeclaration[] decls= ls.getDeclarations(); - assertTrue(decls.length > i_decl); - return (T) decls[i_decl]; - } - - final protected T getDeclaration(IASTCompositeTypeSpecifier ct, int i_decl) { - Class tclass; - IASTDeclaration[] decls= ct.getMembers(); - assertTrue(decls.length > i_decl); - return (T) decls[i_decl]; - } - - final protected T getCompositeType(IASTTranslationUnit tu, int i_decl) { - IASTSimpleDeclaration sdecl= getDeclaration(tu, i_decl); - return (T) sdecl.getDeclSpecifier(); - } - - final protected T getStatement(IASTFunctionDefinition fdef, int i_stmt) { - return getStatement((IASTCompoundStatement) fdef.getBody(), i_stmt); - } - - final protected T getStatement(IASTCompoundStatement compound, int i_stmt) { - IASTStatement[] stmts= compound.getStatements(); - assertTrue(stmts.length > i_stmt); - return (T) stmts[i_stmt]; - } - - final protected T getExpressionOfStatement(IASTFunctionDefinition fdef, int i) { - IASTStatement stmt= getStatement(fdef, i); - assertInstance(stmt, IASTExpressionStatement.class); - return (T) ((IASTExpressionStatement) stmt).getExpression(); - } -} From b4401b6198c5671e43d794e6dea7890e77f6e857 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 31 Jan 2013 10:35:40 +0100 Subject: [PATCH 40/42] Bug 399394: Include macro expansions yielding the empty token in IASTNode.getNodeLocations() --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 27 +++++++++++++ .../core/parser/scanner/LocationCtx.java | 2 +- .../parser/scanner/LocationCtxContainer.java | 40 +++++++++++-------- .../scanner/LocationCtxMacroExpansion.java | 10 ++--- 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index a0863b741a4..096032fb9ab 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -57,9 +57,11 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializerList; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; +import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation; 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.IASTNullStatement; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; @@ -7426,4 +7428,29 @@ public class AST2Tests extends AST2TestBase { public void testNoRawStringInPlainC_397127() throws Exception { parseAndCheckBindings(getAboveComment(), C, true); } + + // #define X + // int a=X-1;X + public void testMacroReferences_399394() throws Exception { + IASTTranslationUnit tu= parseAndCheckBindings(getAboveComment()); + assertEquals(2, countMacroRefs(tu)); + + IASTSimpleDeclaration decl= getDeclaration(tu, 0); + assertEquals(1, countMacroRefs(decl)); + + IASTEqualsInitializer init= (IASTEqualsInitializer) decl.getDeclarators()[0].getInitializer(); + assertEquals(1, countMacroRefs(init)); + + IASTUnaryExpression expr= (IASTUnaryExpression) init.getInitializerClause(); + assertEquals(0, countMacroRefs(expr)); + } + + private int countMacroRefs(IASTNode node) { + int count = 0; + for (IASTNodeLocation loc : node.getNodeLocations()) { + if (loc instanceof IASTMacroExpansionLocation) + count++; + } + return count; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtx.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtx.java index fee6a0479b0..3c62af24107 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtx.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtx.java @@ -130,7 +130,7 @@ abstract class LocationCtx implements ILocationCtx { * Returns the sequence of file locations spanning the given range. * Assumes that the range starts within this context. */ - public abstract boolean collectLocations(int sequenceNumber, int length, ArrayList sofar); + public abstract void collectLocations(int sequenceNumber, int length, ArrayList sofar); /** * Support for the dependency tree, add inclusion statements found in this context. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java index 6323e537149..4e11a04c5fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxContainer.java @@ -32,7 +32,7 @@ class LocationCtxContainer extends LocationCtx { private int fChildSequenceLength; private ArrayList fChildren; - private AbstractCharArray fSource; + private final AbstractCharArray fSource; private int[] fLineOffsets; public LocationCtxContainer(LocationCtxContainer parent, AbstractCharArray source, @@ -138,47 +138,55 @@ class LocationCtxContainer extends LocationCtx { } @Override - public boolean collectLocations(int sequenceNumber, final int length, ArrayList locations) { + public void collectLocations(int sequenceNumber, final int length, ArrayList locations) { + if (length < 1) + return; + final int endSequenceNumber= sequenceNumber + length; if (fChildren != null) { int childIdx= Math.max(0, findChildIdxLessOrEqualThan(sequenceNumber, false)); for (; childIdx < fChildren.size(); childIdx++) { final LocationCtx child= fChildren.get(childIdx); - // create the location between start and the child + // Create the location between start and the child if (sequenceNumber < child.fSequenceNumber) { - // compute offset backwards from the child's offset + // Compute offset backwards from the child's offset in this location final int offset= child.fEndOffsetInParent - (child.fSequenceNumber - sequenceNumber); - // it the child is not affected, we are done. + + // Requested range ends before the child. if (endSequenceNumber <= child.fSequenceNumber) { addFileLocation(offset, endSequenceNumber - sequenceNumber, locations); - return true; + return; } - if (offset < child.fOffsetInParent) + + final int gapLen = child.fOffsetInParent - offset; + if (gapLen > 0) addFileLocation(offset, child.fOffsetInParent - offset, locations); + sequenceNumber= child.fSequenceNumber; + assert sequenceNumber < endSequenceNumber; } - // let the child create locations + // Let the child create locations final int childEndSequenceNumber= child.fSequenceNumber + child.getSequenceLength(); - if (sequenceNumber < childEndSequenceNumber) { - if (child.collectLocations(sequenceNumber, endSequenceNumber - sequenceNumber, locations)) { - return true; - } + if (sequenceNumber < childEndSequenceNumber + || (sequenceNumber == childEndSequenceNumber && !locations.isEmpty())) { + child.collectLocations(sequenceNumber, endSequenceNumber - sequenceNumber, locations); sequenceNumber= childEndSequenceNumber; + if (sequenceNumber >= endSequenceNumber) + return; } } } - // create the location after the last child. + // Create the location after the last child. final int myEndNumber = fSequenceNumber + getSequenceLength(); final int offset= fSource.getLength() - (myEndNumber - sequenceNumber); if (endSequenceNumber <= myEndNumber) { addFileLocation(offset, endSequenceNumber - sequenceNumber, locations); - return true; + } else { + addFileLocation(offset, fSource.getLength() - offset, locations); } - addFileLocation(offset, fSource.getLength() - offset, locations); - return false; } private ArrayList addFileLocation(int offset, int length, ArrayList sofar) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java index d94e229e8fb..90bba002862 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationCtxMacroExpansion.java @@ -25,7 +25,7 @@ class LocationCtxMacroExpansion extends LocationCtx { private final LocationMap fLocationMap; private final int fLength; private final ImageLocationInfo[] fLocationInfos; - private ASTMacroReferenceName fExpansionName; + private final ASTMacroReferenceName fExpansionName; public LocationCtxMacroExpansion(LocationMap map, LocationCtxContainer parent, int parentOffset, int parentEndOffset, int sequenceNumber, int length, ImageLocationInfo[] imageLocations, ASTMacroReferenceName expansionName) { @@ -45,17 +45,15 @@ class LocationCtxMacroExpansion extends LocationCtx { } @Override - public boolean collectLocations(int start, int length, ArrayList locations) { + public void collectLocations(int start, int length, ArrayList locations) { final int offset= start - fSequenceNumber; assert offset >= 0 && length >= 0; if (offset + length <= fLength) { locations.add(new ASTMacroExpansionLocation(this, offset, length)); - return true; + } else { + locations.add(new ASTMacroExpansionLocation(this, offset, fLength-offset)); } - - locations.add(new ASTMacroExpansionLocation(this, offset, fLength-offset)); - return false; } public ASTMacroExpansion getExpansion() { From 35a1eb1832871fcb3488380c6fef588e5a342629 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Sat, 26 Jan 2013 22:53:54 -0500 Subject: [PATCH 41/42] Bug 399163 - [reverse] Make use of GDB's new =record-started/stopped MI events Change-Id: I168b4734a2971bd71ebd34532bb118aa72ccc70b Reviewed-on: https://git.eclipse.org/r/9957 Reviewed-by: Marc Khouzam IP-Clean: Marc Khouzam Tested-by: Marc Khouzam --- .../commands/ReverseToggleCommandHandler.java | 6 + .../ui/commands/GdbReverseToggleCommand.java | 58 +++++++++- .../dsf/gdb/service/GDBRunControl_7_0.java | 30 ++++- .../dsf/gdb/service/GDBRunControl_7_6.java | 104 +++++++++++++++++ .../gdb/service/GdbDebugServicesFactory.java | 3 + .../dsf/gdb/service/IReverseRunControl.java | 69 ++++++++++- .../GDBConsoleSynchronizingTest_7_6.java | 108 ++++++++++++++++++ 7 files changed, 373 insertions(+), 5 deletions(-) create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_6.java diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ReverseToggleCommandHandler.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ReverseToggleCommandHandler.java index dd917d98ddc..64f1a4e5cc3 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ReverseToggleCommandHandler.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ReverseToggleCommandHandler.java @@ -124,6 +124,12 @@ public class ReverseToggleCommandHandler extends DebugCommandHandler implements return adapter; } + /* + * (non-Javadoc) + * @see org.eclipse.debug.ui.actions.DebugCommandHandler#postExecute(org.eclipse.debug.core.IRequest, java.lang.Object[]) + * + * We keep this logic for users that may not do the refresh themselves. + */ @Override protected void postExecute(IRequest request, Object[] targets) { super.postExecute(request, targets); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java index dd236ed83d0..d02a5008215 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson and others. + * Copyright (c) 2009, 2013 Ericsson 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 @@ -7,6 +7,7 @@ * * Contributors: * Ericsson - initial API and implementation + * Marc Khouzam (Ericsson) - Listen for IReverseModeChangedDMEvent (Bug 399163) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.internal.ui.commands; @@ -16,6 +17,7 @@ import java.util.concurrent.RejectedExecutionException; import org.eclipse.cdt.debug.core.model.IReverseToggleHandler; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DsfExecutor; +import org.eclipse.cdt.dsf.concurrent.DsfRunnable; import org.eclipse.cdt.dsf.concurrent.Query; import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.IDMContext; @@ -24,15 +26,23 @@ import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; import org.eclipse.cdt.dsf.gdb.service.IReverseRunControl; +import org.eclipse.cdt.dsf.gdb.service.IReverseRunControl.IReverseModeChangedDMEvent; +import org.eclipse.cdt.dsf.service.DsfServiceEventHandler; import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.dsf.service.DsfSession; import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.IRequest; import org.eclipse.debug.core.commands.AbstractDebugCommand; import org.eclipse.debug.core.commands.IDebugCommandRequest; import org.eclipse.debug.core.commands.IEnabledStateRequest; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.progress.WorkbenchJob; +import org.eclipse.ui.services.IEvaluationService; /** * Command that toggles the Reverse Debugging feature @@ -42,13 +52,33 @@ import org.eclipse.debug.core.commands.IEnabledStateRequest; public class GdbReverseToggleCommand extends AbstractDebugCommand implements IReverseToggleHandler { private final DsfExecutor fExecutor; private final DsfServicesTracker fTracker; + private final DsfSession fSession; public GdbReverseToggleCommand(DsfSession session) { fExecutor = session.getExecutor(); fTracker = new DsfServicesTracker(GdbUIPlugin.getBundleContext(), session.getId()); + fSession = session; + try { + fExecutor.execute(new DsfRunnable() { + @Override + public void run() { + fSession.addServiceEventListener(GdbReverseToggleCommand.this, null); + } + }); + } catch(RejectedExecutionException e) {} } public void dispose() { + try { + fExecutor.execute(new DsfRunnable() { + @Override + public void run() { + fSession.removeServiceEventListener(GdbReverseToggleCommand.this); + } + }); + } catch (RejectedExecutionException e) { + // Session already gone. + } fTracker.dispose(); } @@ -195,4 +225,30 @@ public class GdbReverseToggleCommand extends AbstractDebugCommand implements IRe return false; } + + /** + * @noreference This method is not intended to be referenced by clients. + */ + @DsfServiceEventHandler + public void eventDispatched(IReverseModeChangedDMEvent e) { + new WorkbenchJob("") { //$NON-NLS-1$ + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + // Request re-evaluation of property "org.eclipse.cdt.debug.ui.isReverseDebuggingEnabled" to update + // visibility of reverse stepping commands. + IEvaluationService exprService = (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class); + if (exprService != null) { + exprService.requestEvaluation("org.eclipse.cdt.debug.ui.isReverseDebuggingEnabled"); //$NON-NLS-1$ + } + // Refresh reverse toggle commands with the new state of reverse enabled. + // This is in order to keep multiple toggle actions in UI in sync. + ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + if (commandService != null) { + commandService.refreshElements("org.eclipse.cdt.debug.ui.command.reverseToggle", null); //$NON-NLS-1$ + } + + return Status.OK_STATUS; + } + }.schedule(); + } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java index eb6abfb6adf..f5f8f1b8055 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Wind River Systems and others. + * Copyright (c) 2008, 2013 Wind River Systems 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 @@ -11,6 +11,7 @@ * Ericsson - Version 7.0 * Nokia - create and use backend service. * Ericsson - Added IReverseControl support + * Marc Khouzam (Ericsson) - Added IReverseModeChangedDMEvent (Bug 399163) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service; @@ -21,6 +22,7 @@ import java.util.Hashtable; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.datamodel.AbstractDMEvent; import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext; @@ -52,6 +54,22 @@ import org.eclipse.core.runtime.Status; public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunControl { + /** @since 4.2 */ + protected static class GdbReverseModeChangedDMEvent extends AbstractDMEvent + implements IReverseModeChangedDMEvent { + private boolean fIsEnabled; + + public GdbReverseModeChangedDMEvent(ICommandControlDMContext context, boolean enabled) { + super(context); + fIsEnabled = enabled; + } + + @Override + public boolean isReverseModeEnabled() { + return fIsEnabled; + } + } + private static class RunToLineActiveOperation { private IMIExecutionDMContext fThreadContext; private int fBpId; @@ -75,6 +93,7 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro public boolean shouldSkipBreakpoints() { return fSkipBreakpoints; } } + private IMICommandControl fCommandControl; private IGDBBackend fGdb; private IMIProcesses fProcService; private CommandFactory fCommandFactory; @@ -111,7 +130,8 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro fGdb = getServicesTracker().getService(IGDBBackend.class); fProcService = getServicesTracker().getService(IMIProcesses.class); - fCommandFactory = getServicesTracker().getService(IMICommandControl.class).getCommandFactory(); + fCommandControl = getServicesTracker().getService(IMICommandControl.class); + fCommandFactory = fCommandControl.getCommandFactory(); if (fGdb.getSessionType() == SessionType.CORE) { // No execution for core files, so no support for reverse @@ -628,6 +648,10 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro /** @since 2.0 */ public void setReverseModeEnabled(boolean enabled) { - fReverseModeEnabled = enabled; + if (fReverseModeEnabled != enabled) { + fReverseModeEnabled = enabled; + getSession().dispatchEvent(new GdbReverseModeChangedDMEvent(fCommandControl.getContext(), fReverseModeEnabled), + getProperties()); + } } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_6.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_6.java new file mode 100644 index 00000000000..0e5a3cc3c7a --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_6.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson 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: + * Marc Khouzam (Ericsson) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.service; + + +import java.util.Hashtable; + +import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.debug.service.IRunControl; +import org.eclipse.cdt.dsf.debug.service.IRunControl2; +import org.eclipse.cdt.dsf.debug.service.command.ICommandControl; +import org.eclipse.cdt.dsf.debug.service.command.IEventListener; +import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; +import org.eclipse.cdt.dsf.mi.service.IMIRunControl; +import org.eclipse.cdt.dsf.mi.service.MIRunControl; +import org.eclipse.cdt.dsf.mi.service.command.output.MINotifyAsyncOutput; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOOBRecord; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput; +import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +/** + * @since 4.2 + */ +public class GDBRunControl_7_6 extends GDBRunControl_7_0 implements IEventListener { + + private ICommandControl fCommandControl; + + public GDBRunControl_7_6(DsfSession session) { + super(session); + } + + @Override + public void initialize(final RequestMonitor requestMonitor) { + super.initialize( + new ImmediateRequestMonitor(requestMonitor) { + @Override + public void handleSuccess() { + doInitialize(requestMonitor); + }}); + } + + private void doInitialize(final RequestMonitor requestMonitor) { + + fCommandControl = getServicesTracker().getService(ICommandControl.class); + + if (fCommandControl == null) { + requestMonitor.done(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, "Service is not available")); //$NON-NLS-1$ + return; + } + + fCommandControl.addEventListener(this); + + register(new String[]{IRunControl.class.getName(), + IRunControl2.class.getName(), + IMIRunControl.class.getName(), + MIRunControl.class.getName(), + GDBRunControl_7_0.class.getName(), + GDBRunControl_7_6.class.getName(), + IReverseRunControl.class.getName()}, + new Hashtable()); + requestMonitor.done(); + } + + @Override + public void shutdown(final RequestMonitor requestMonitor) { + if (fCommandControl != null) { + fCommandControl.removeEventListener(this); + } + unregister(); + super.shutdown(requestMonitor); + } + + @Override + public void eventReceived(Object output) { + if (output instanceof MIOutput) { + MIOOBRecord[] records = ((MIOutput)output).getMIOOBRecords(); + for (MIOOBRecord r : records) { + if (r instanceof MINotifyAsyncOutput) { + MINotifyAsyncOutput notifyOutput = (MINotifyAsyncOutput)r; + String asyncClass = notifyOutput.getAsyncClass(); + // These events have been added with GDB 7.6 + if ("record-started".equals(asyncClass) || //$NON-NLS-1$ + "record-stopped".equals(asyncClass)) { //$NON-NLS-1$ + + boolean enable = "record-started".equals(asyncClass); //$NON-NLS-1$ + setReverseModeEnabled(enable); + } + } + } + } + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java index 0a62d53fb65..d01fcd6e7de 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GdbDebugServicesFactory.java @@ -215,6 +215,9 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory { @Override protected IRunControl createRunControlService(DsfSession session) { + if (GDB_7_6_VERSION.compareTo(fVersion) <= 0) { + return new GDBRunControl_7_6(session); + } if (GDB_7_0_VERSION.compareTo(fVersion) <= 0) { return new GDBRunControl_7_0(session); } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IReverseRunControl.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IReverseRunControl.java index 6751d3f4ee3..3d03793bc9c 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IReverseRunControl.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IReverseRunControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson and others. + * Copyright (c) 2009, 2013 Ericsson 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 @@ -7,27 +7,94 @@ * * Contributors: * Ericsson - Initial API and implementation + * Marc Khouzam (Ericsson) - Added IReverseModeChangedDMEvent (Bug 399163) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; +import org.eclipse.cdt.dsf.datamodel.IDMEvent; import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext; import org.eclipse.cdt.dsf.debug.service.IRunControl.StepType; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext; /** + * This interface provides access to controlling and monitoring the reverse execution + * state of a process being debugged. + * * @since 2.0 */ public interface IReverseRunControl { + /** + * Indicates that the enablement of reverse debugging has changed. + * + * @since 4.2 + */ + interface IReverseModeChangedDMEvent extends IDMEvent { + /** + * @return the new state of reverse mode. + */ + boolean isReverseModeEnabled(); + }; + + /** + * Establish if a reverse-resume operation is allowed on the specified context. + * + * @param context The thread or process on which the reverse operation will apply + * @param rm Will contain the result of the operation, true or false, not null. + */ void canReverseResume(IExecutionDMContext context, DataRequestMonitor rm); + + /** + * Perform a reverse-resume operation on the specified context. + * + * @param context The thread or process on which the reverse operation will apply + */ void reverseResume(IExecutionDMContext context, RequestMonitor requestMonitor); + + /** + * Returns whether a reverse-step operation is on-going for the specified context. + * + * @param context The thread or process on which the reverse operation will apply + * @return True if a reverse-steop operation is on-going, false otherwise. + */ boolean isReverseStepping(IExecutionDMContext context); + + /** + * Establish if a reverse-step operation is allowed on the specified context. + * + * @param context The thread or process on which the reverse operation will apply + * @param rm Will contain the result of the operation, true or false, not null. + */ void canReverseStep(IExecutionDMContext context, StepType stepType, DataRequestMonitor rm); + + /** + * Perform a reverse-step operation on the specified context with the specified step type. + * + * @param context The thread or process on which the reverse operation will apply + * @param stepType The step type to be used for the operation + */ void reverseStep(IExecutionDMContext context, StepType stepType, RequestMonitor requestMonitor); + /** + * Establish if it is possible to enable reverse debugging. + * + * @param rm Will contain the result of the operation, true or false, not null. + */ void canEnableReverseMode(ICommandControlDMContext context, DataRequestMonitor rm); + + /** + * Establish if reverse debugging is enabled. + * + * @param rm Will contain the result of the operation, true or false, not null. + */ void isReverseModeEnabled(ICommandControlDMContext context, DataRequestMonitor rm); + + /** + * Enable or disable reverse debugging based on the enable parameter. + * + * @param enable True if reverse debugging should enabled, false for disabled. + */ void enableReverseMode(ICommandControlDMContext context, boolean enable, RequestMonitor rm); } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java index 015ebae46bb..14eeaa21486 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/tests_7_6/GDBConsoleSynchronizingTest_7_6.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_6; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; @@ -20,6 +21,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.cdt.core.IAddress; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor; import org.eclipse.cdt.dsf.concurrent.Query; import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.IDMContext; @@ -31,7 +33,10 @@ import org.eclipse.cdt.dsf.debug.service.IFormattedValues; import org.eclipse.cdt.dsf.debug.service.IMemory; import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryChangedEvent; import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryDMContext; +import org.eclipse.cdt.dsf.debug.service.IRunControl; import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext; +import org.eclipse.cdt.dsf.gdb.service.IReverseRunControl; +import org.eclipse.cdt.dsf.gdb.service.IReverseRunControl.IReverseModeChangedDMEvent; import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; import org.eclipse.cdt.dsf.mi.service.command.events.MIStoppedEvent; import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; @@ -63,6 +68,7 @@ public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { private IGDBControl fCommandControl; private IMemory fMemoryService; private IExpressions fExprService; + private IRunControl fRunControl; private List> fEventsReceived = new ArrayList>(); @@ -98,6 +104,9 @@ public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { fExprService = fServicesTracker.getService(IExpressions.class); Assert.assertTrue(fExprService != null); + fRunControl = fServicesTracker.getService(IRunControl.class); + Assert.assertTrue(fRunControl != null); + // Register to breakpoint events fSession.addServiceEventListener(GDBConsoleSynchronizingTest_7_6.this, null); } @@ -293,6 +302,105 @@ public class GDBConsoleSynchronizingTest_7_6 extends BaseTestCase { assertEquals(newValue, exprValue); } + /** + * This test verifies that enabling reverse debugging from the + * console will properly trigger a DSF event to indicate the change and + * will be processed by the service. + */ + @Test + public void testEnableRecord() throws Throwable { + assertTrue("Reverse debugging is not supported", fRunControl instanceof IReverseRunControl); + final IReverseRunControl reverseService = (IReverseRunControl)fRunControl; + + SyncUtil.runToLocation("testMemoryChanges"); + + // check starting state + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + reverseService.isReverseModeEnabled(fCommandControl.getContext(), rm); + } + }; + + fSession.getExecutor().execute(query); + Boolean enabled = query.get(); + assertTrue("Reverse debugging should not be enabled", !enabled); + + fEventsReceived.clear(); + + queueConsoleCommand("record"); + + // Wait for the event + IReverseModeChangedDMEvent event = waitForEvent(IReverseModeChangedDMEvent.class); + assertEquals(true, event.isReverseModeEnabled()); + + // Check the service + query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + reverseService.isReverseModeEnabled(fCommandControl.getContext(), rm); + } + }; + fSession.getExecutor().execute(query); + enabled = query.get(); + assertTrue("Reverse debugging should be enabled", enabled); + } + + /** + * This test verifies that disabling reverse debugging from the + * console will properly trigger a DSF event to indicate the change and + * will be processed by the service. + */ + @Test + public void testDisableRecord() throws Throwable { + assertTrue("Reverse debugging is not supported", fRunControl instanceof IReverseRunControl); + final IReverseRunControl reverseService = (IReverseRunControl)fRunControl; + + SyncUtil.runToLocation("testMemoryChanges"); + + fEventsReceived.clear(); + + // check starting state + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + reverseService.enableReverseMode(fCommandControl.getContext(), true, + new ImmediateRequestMonitor(rm) { + @Override + protected void handleSuccess() { + reverseService.isReverseModeEnabled(fCommandControl.getContext(), rm); + } + }); + } + }; + + fSession.getExecutor().execute(query); + Boolean enabled = query.get(); + assertTrue("Reverse debugging should be enabled", enabled); + + // Wait for the event to avoid confusing it with the next one + IReverseModeChangedDMEvent event = waitForEvent(IReverseModeChangedDMEvent.class); + assertEquals(true, event.isReverseModeEnabled()); + fEventsReceived.clear(); + + queueConsoleCommand("record stop"); + + // Wait for the event + event = waitForEvent(IReverseModeChangedDMEvent.class); + assertEquals(false, event.isReverseModeEnabled()); + + // Check the service + query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + reverseService.isReverseModeEnabled(fCommandControl.getContext(), rm); + } + }; + fSession.getExecutor().execute(query); + enabled = query.get(); + assertTrue("Reverse debugging should not be enabled", !enabled); + } + ////////////////////////////////////////////////////////////////////////////////////// // End of tests ////////////////////////////////////////////////////////////////////////////////////// From b5807e9b299039e1370185c9e2444957c093039d Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sun, 27 Jan 2013 21:23:56 -0500 Subject: [PATCH 42/42] Refined a pattern for GNU Make Error Parser --- core/org.eclipse.cdt.core/plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index 7cd1e698f09..e395e8fdc7d 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -268,7 +268,7 @@ - +