1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Correct status handling + index update issue, bug 293021.

This commit is contained in:
Markus Schorn 2009-10-22 14:34:20 +00:00
parent 5333c64790
commit 247c59316f
10 changed files with 83 additions and 42 deletions

View file

@ -50,8 +50,10 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; 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.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
@ -2152,4 +2154,27 @@ public class IndexBugsTests extends BaseTestCase {
index.releaseReadLock(); index.releaseReadLock();
} }
} }
// template<typename T> void f(T t) throw (T) {}
public void testFunctionTemplateWithThrowsException_293021() throws Exception {
waitForIndexer();
String testData = getContentsForTest(1)[0].toString();
IFile f= TestSourceReader.createFile(fCProject.getProject(), "testFunctionTemplateWithThrowsException_293021.cpp", testData);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
waitUntilFileIsIndexed(f, 4000);
IIndex index= indexManager.getIndex(fCProject);
index.acquireReadLock();
try {
IIndexFile file= index.getFile(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(f));
int idx= testData.indexOf("f(");
IIndexName[] names = file.findNames(idx, idx+1);
assertEquals(1, names.length);
ICPPFunctionTemplate ft= (ICPPFunctionTemplate) index.findBinding(names[0]);
final IType[] espec = ft.getExceptionSpecification();
ICPPTemplateParameter par= (ICPPTemplateParameter) espec[0];
assertEquals(ft, par.getOwner());
} finally {
index.releaseReadLock();
}
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2008 QNX Software Systems and others. * Copyright (c) 2000, 2009 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -746,7 +746,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
SafeRunner.run(new ISafeRunnable() { SafeRunner.run(new ISafeRunnable() {
public void handleException(Throwable exception) { public void handleException(Throwable exception) {
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID,
"Exception occurred in container initializer: " + initializer, exception); //$NON-NLS-1$ "Exception occurred in container initializer: " + initializer, exception); //$NON-NLS-1$
CCorePlugin.log(status); CCorePlugin.log(status);
} }

View file

@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URI; import java.net.URI;
import com.ibm.icu.text.MessageFormat; import com.ibm.icu.text.MessageFormat;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -190,7 +191,7 @@ public class Util implements ICLogConstants {
* Add a log entry * Add a log entry
*/ */
public static void log(Throwable e, String message, LogConst logType) { public static void log(Throwable e, String message, LogConst logType) {
IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, message,e); IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, message,e);
Util.log(status, logType); Util.log(status, logType);
} }

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom; package org.eclipse.cdt.internal.core.pdom;
import java.lang.reflect.InvocationTargetException;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -806,12 +807,19 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (e instanceof CoreException) { if (e instanceof CoreException) {
s=((CoreException)e).getStatus(); s=((CoreException)e).getStatus();
if (s != null && s.getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE) { if (s != null && s.getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE) {
if (CCorePlugin.PLUGIN_ID.equals(s.getPlugin()))
throw (CoreException) e; throw (CoreException) e;
} }
} }
if (e instanceof CoreException) { if (e instanceof CoreException) {
s= ((CoreException) e).getStatus(); s= ((CoreException) e).getStatus();
if (s.getException() == null) { Throwable exception = s.getException();
if (exception instanceof OutOfMemoryError || exception instanceof StackOverflowError) {
// mask errors in order to avoid dialog from platform
e= new InvocationTargetException(exception);
exception= null;
}
if (exception == null) {
s= new Status(s.getSeverity(), s.getPlugin(), s.getCode(), s.getMessage(), e); s= new Status(s.getSeverity(), s.getPlugin(), s.getCode(), s.getMessage(), e);
} }
} else { } else {

View file

@ -310,7 +310,9 @@ public class PDOMFile implements IIndexFragmentFile {
return result; return result;
} }
} catch (CoreException e) { } catch (CoreException e) {
if( e.getStatus() != null && e.getStatus().getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE ) { final IStatus status = e.getStatus();
if (status != null && status.getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE) {
if (CCorePlugin.PLUGIN_ID.equals(status.getPlugin()))
throw e; throw e;
} }
CCorePlugin.log(e); CCorePlugin.log(e);
@ -643,6 +645,6 @@ public class PDOMFile implements IIndexFragmentFile {
// required because we cannot reference CCorePlugin in order for StandaloneIndexer to work // required because we cannot reference CCorePlugin in order for StandaloneIndexer to work
private static IStatus createStatus(String msg) { private static IStatus createStatus(String msg) {
return new Status(IStatus.ERROR, "org.eclipse.cdt.core", IStatus.ERROR, msg, null); //$NON-NLS-1$ return new Status(IStatus.ERROR, "org.eclipse.cdt.core", msg, null); //$NON-NLS-1$
} }
} }

View file

@ -87,19 +87,19 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
Database db = getDB(); Database db = getDB();
Integer sigHash = IndexCPPSignatureUtil.getSignatureHash(function); Integer sigHash = IndexCPPSignatureUtil.getSignatureHash(function);
getDB().putInt(record + SIGNATURE_HASH, sigHash != null ? sigHash.intValue() : 0); getDB().putInt(record + SIGNATURE_HASH, sigHash != null ? sigHash.intValue() : 0);
db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(function));
if (setTypes) { if (setTypes) {
initData(function.getType(), function.getParameters()); initData(function.getType(), function.getParameters(), extractExceptionSpec(function));
} }
db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(function));
storeExceptionSpec(db, function);
} }
public void initData(ICPPFunctionType ftype, IParameter[] params) { public void initData(ICPPFunctionType ftype, IParameter[] params, IType[] exceptionSpec) {
PDOMCPPFunctionType pft; PDOMCPPFunctionType pft;
try { try {
pft = setType(ftype); pft = setType(ftype);
setParameters(pft, params); setParameters(pft, params);
storeExceptionSpec(exceptionSpec);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }
@ -135,25 +135,32 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl
annotation= newAnnotation; annotation= newAnnotation;
long oldRec = db.getRecPtr(record+EXCEPTION_SPEC); long oldRec = db.getRecPtr(record+EXCEPTION_SPEC);
storeExceptionSpec(db, func); storeExceptionSpec(extractExceptionSpec(func));
if (oldRec != 0) { if (oldRec != 0) {
PDOMCPPTypeList.clearTypes(this, oldRec); PDOMCPPTypeList.clearTypes(this, oldRec);
} }
} }
} }
private void storeExceptionSpec(final Database db, ICPPFunction binding) throws CoreException { private void storeExceptionSpec(IType[] exceptionSpec) throws CoreException {
long typelist= 0; long typelist= PDOMCPPTypeList.putTypes(this, exceptionSpec);
try { getDB().putRecPtr(record + EXCEPTION_SPEC, typelist);
if (binding instanceof ICPPMethod && ((ICPPMethod) binding).isImplicit()) {
// don't store the exception specification, computed it on demand.
} else {
typelist = PDOMCPPTypeList.putTypes(this, binding.getExceptionSpecification());
} }
IType[] extractExceptionSpec(ICPPFunction binding) {
IType[] exceptionSpec;
if (binding instanceof ICPPMethod && ((ICPPMethod) binding).isImplicit()) {
// don't store the exception specification, compute it on demand.
exceptionSpec= null;
} else {
try{
exceptionSpec= binding.getExceptionSpecification();
} catch (DOMException e) { } catch (DOMException e) {
// ignore problems in the exception specification. // ignore problems in the exception specification.
exceptionSpec= null;
} }
db.putRecPtr(record + EXCEPTION_SPEC, typelist); }
return exceptionSpec;
} }
private void setParameters(PDOMCPPFunctionType pft, IParameter[] params) throws CoreException { private void setParameters(PDOMCPPFunctionType pft, IParameter[] params) throws CoreException {

View file

@ -175,6 +175,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
private final ICPPTemplateParameter[] fOriginalTemplateParameters; private final ICPPTemplateParameter[] fOriginalTemplateParameters;
private final ICPPFunctionType fOriginalFunctionType; private final ICPPFunctionType fOriginalFunctionType;
private final IParameter[] fOriginalParameters; private final IParameter[] fOriginalParameters;
private final IType[] fOriginalExceptionSpec;
public ConfigureFunctionTemplate(ICPPFunctionTemplate original, PDOMCPPFunctionTemplate template) throws DOMException { public ConfigureFunctionTemplate(ICPPFunctionTemplate original, PDOMCPPFunctionTemplate template) throws DOMException {
fTemplate = template; fTemplate = template;
@ -182,6 +183,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
fOriginalTemplateParameters= original.getTemplateParameters(); fOriginalTemplateParameters= original.getTemplateParameters();
fOriginalFunctionType= original.getType(); fOriginalFunctionType= original.getType();
fOriginalParameters= original.getParameters(); fOriginalParameters= original.getParameters();
fOriginalExceptionSpec= template.extractExceptionSpec(original);
postProcesses.add(this); postProcesses.add(this);
} }
@ -191,8 +193,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
if (tp != null) if (tp != null)
tp.configure(fOriginalTemplateParameters[i]); tp.configure(fOriginalTemplateParameters[i]);
} }
fTemplate.initData(fOriginalFunctionType, fOriginalParameters, fOriginalExceptionSpec);
fTemplate.initData(fOriginalFunctionType, fOriginalParameters);
} }
} }

View file

@ -1243,7 +1243,7 @@ public class CCorePlugin extends Plugin {
* @noreference This method is not intended to be referenced by clients. * @noreference This method is not intended to be referenced by clients.
*/ */
public static IStatus createStatus(String msg, Throwable e) { public static IStatus createStatus(String msg, Throwable e) {
return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, msg, e); return new Status(IStatus.ERROR, PLUGIN_ID, msg, e);
} }
/** /**

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others. * Copyright (c) 2000, 2009 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,18 +11,17 @@
package org.eclipse.cdt.core.resources; package org.eclipse.cdt.core.resources;
import java.io.InputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.InputStream;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
/** /**
* *
@ -38,7 +37,7 @@ public class FileStorage extends PlatformObject implements IStorage {
return new FileInputStream(path.toFile()); return new FileInputStream(path.toFile());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID,
IStatus.ERROR, e.toString(), e)); e.toString(), e));
} }
} }
return in; return in;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2005 QNX Software Systems and others. * Copyright (c) 2000, 2009 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,10 +8,8 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core; package org.eclipse.cdt.internal.core;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.resources.IPathEntryVariableManager; import org.eclipse.cdt.core.resources.IPathEntryVariableManager;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -30,7 +28,7 @@ public class PathEntryVariableResolver implements IDynamicVariableResolver {
public String resolveValue(IDynamicVariable variable, String argument) throws CoreException { public String resolveValue(IDynamicVariable variable, String argument) throws CoreException {
if (argument == null) { if (argument == null) {
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, CCorePlugin.getResourceString("PathEntryVariableResolver.0"), null)); //$NON-NLS-1$ throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.getResourceString("PathEntryVariableResolver.0"), null)); //$NON-NLS-1$
} }
IPathEntryVariableManager manager = CCorePlugin.getDefault().getPathEntryVariableManager(); IPathEntryVariableManager manager = CCorePlugin.getDefault().getPathEntryVariableManager();
IPath path = manager.getValue(argument); IPath path = manager.getValue(argument);