mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-15 20:25:46 +02:00
Fixes a CCE, bug 223020.
This commit is contained in:
parent
366bb49c07
commit
868da804e7
3 changed files with 47 additions and 10 deletions
|
@ -82,6 +82,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
|
@ -5826,4 +5827,15 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertEquals("Test", m1.getScope().getScopeName().toString());
|
||||
assertSame(b, b2);
|
||||
}
|
||||
|
||||
// namespace ns { typedef int ns::TINT; } // illegal, still no CCE is expected.
|
||||
public void testQualifiedTypedefs_Bug222093() throws Exception{
|
||||
final String code = getContents(1)[0].toString();
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
IBinding td= bh.assertNonProblem("TINT", 4);
|
||||
bh.assertProblem("ns::", 2);
|
||||
|
||||
assertTrue(td instanceof ITypedef);
|
||||
assertTrue(((ITypedef) td).getType() instanceof ICPPBasicType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
|
@ -34,10 +35,11 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
|
|||
private IASTName[] declarations = null;
|
||||
private IType type = null;
|
||||
|
||||
/**
|
||||
* @param declarator
|
||||
*/
|
||||
public CPPTypedef(IASTName name) {
|
||||
// bug 223020 even though qualified names are not legal, we need to deal with them.
|
||||
if (name != null && name.getParent() instanceof ICPPASTQualifiedName) {
|
||||
name= (IASTName) name.getParent();
|
||||
}
|
||||
this.declarations = new IASTName[] { name };
|
||||
if (name != null)
|
||||
name.setBinding(this);
|
||||
|
@ -95,14 +97,23 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
|
|||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return declarations[0].toString();
|
||||
return getSimpleName().toString();
|
||||
}
|
||||
|
||||
private IASTName getSimpleName() {
|
||||
IASTName name= declarations[0];
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] na= ((ICPPASTQualifiedName) name).getNames();
|
||||
name= na[na.length-1];
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
return declarations[0].toCharArray();
|
||||
return getSimpleName().toCharArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -160,9 +171,18 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
|
|||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDeclaration(IASTNode node) {
|
||||
if (!(node instanceof IASTName))
|
||||
IASTName name;
|
||||
if (node instanceof IASTName) {
|
||||
if (node.getParent() instanceof ICPPASTQualifiedName) {
|
||||
name= (IASTName) node.getParent();
|
||||
}
|
||||
else {
|
||||
name= (IASTName) node;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
IASTName name = (IASTName) node;
|
||||
}
|
||||
|
||||
if (declarations == null) {
|
||||
declarations = new IASTName[] { name };
|
||||
|
|
|
@ -51,6 +51,7 @@ import org.eclipse.core.runtime.IPath;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
/**
|
||||
* Task for the actual indexing. Various indexers need to implement the abstract methods.
|
||||
|
@ -697,14 +698,18 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
}
|
||||
|
||||
private void swallowError(IPath file, Throwable e) throws CoreException {
|
||||
IStatus s;
|
||||
if (e instanceof CoreException) {
|
||||
CCorePlugin.log(((CoreException) e).getStatus());
|
||||
s= ((CoreException) e).getStatus();
|
||||
if (s.getException() == null) {
|
||||
s= new Status(s.getSeverity(), s.getPlugin(), s.getCode(), s.getMessage(), e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
IStatus status= CCorePlugin.createStatus(
|
||||
s= CCorePlugin.createStatus(
|
||||
MessageFormat.format(Messages.AbstractIndexerTask_errorWhileParsing, new Object[]{file}), e);
|
||||
CCorePlugin.log(status);
|
||||
}
|
||||
CCorePlugin.log(s);
|
||||
if (++fStatistics.fErrorCount > MAX_ERRORS) {
|
||||
throw new CoreException(CCorePlugin.createStatus(Messages.AbstractIndexerTask_tooManyIndexProblems));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue