mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Fixing ClassCastExceptions, NPE's && ArrayIndexOutOfBounds, includes bug 98704
This commit is contained in:
parent
4d803ceaeb
commit
d3db562481
10 changed files with 49 additions and 23 deletions
|
@ -4636,4 +4636,11 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertSame( bindings[1], col.getName(2).resolveBinding() );
|
||||
assertSame( bindings[2], col.getName(3).resolveBinding() );
|
||||
}
|
||||
|
||||
public void testBug98704() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "A< B< C< D< E< F< G< H<int> > > > > > > > a; \n"); //$NON-NLS-1$
|
||||
buffer.append( "int A::B<int>::* b; \n"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ import org.eclipse.cdt.internal.core.parser.ParserMessages;
|
|||
* @author aniefer
|
||||
*/
|
||||
public class ProblemBinding implements IProblemBinding, IType, IScope {
|
||||
private final int id;
|
||||
private final char [] arg;
|
||||
private IASTNode node;
|
||||
protected final int id;
|
||||
protected final char [] arg;
|
||||
protected IASTNode node;
|
||||
private String message = null;
|
||||
|
||||
public ProblemBinding( IASTNode node, int id, char [] arg ){
|
||||
|
|
|
@ -29,11 +29,15 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
|||
*/
|
||||
public class CPPBaseClause implements ICPPBase {
|
||||
static public class CPPBaseProblem extends ProblemBinding implements ICPPBase {
|
||||
private ICPPClassType classProblem = null;
|
||||
public CPPBaseProblem( IASTNode node, int id, char[] arg ) {
|
||||
super( node, id, arg );
|
||||
}
|
||||
public ICPPClassType getBaseClass() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
public ICPPClassType getBaseClass() {
|
||||
if( classProblem == null ){
|
||||
classProblem = new CPPClassType.CPPClassTypeProblem( node, id, arg );
|
||||
}
|
||||
return classProblem;
|
||||
}
|
||||
|
||||
public int getVisibility() throws DOMException {
|
||||
|
|
|
@ -155,13 +155,15 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
|
|||
return true;
|
||||
if( type instanceof ITypedef )
|
||||
return ((ITypedef)type).isSameType( this );
|
||||
if( type instanceof CPPDeferredClassInstance )
|
||||
return type.isSameType( this ); //the CPPDeferredClassInstance has some fuzziness
|
||||
|
||||
if( type instanceof ICPPTemplateInstance ){
|
||||
if( getSpecializedBinding() != ((ICPPTemplateInstance)type).getTemplateDefinition() )
|
||||
return false;
|
||||
|
||||
ObjectMap m1 = getArgumentMap(), m2 = ((ICPPTemplateInstance)type).getArgumentMap();
|
||||
if( m1.size() != m2.size() )
|
||||
if( m1 == null || m2 == null || m1.size() != m2.size())
|
||||
return false;
|
||||
for( int i = 0; i < m1.size(); i++ ){
|
||||
IType t1 = (IType) m1.getAt( i );
|
||||
|
|
|
@ -914,7 +914,7 @@ public class CPPSemantics {
|
|||
return;
|
||||
|
||||
if( !data.usingDirectivesOnly && scope instanceof ICPPClassScope ){
|
||||
mergeResults( data, lookupInParents( data, (ICPPClassScope) scope ), true );
|
||||
mergeResults( data, lookupInParents( data, scope ), true );
|
||||
}
|
||||
|
||||
if( !data.prefixLookup && (data.problem != null || data.hasResults()) )
|
||||
|
@ -950,7 +950,7 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
private static Object lookupInParents( CPPSemantics.LookupData data, ICPPClassScope lookIn ) throws DOMException{
|
||||
private static Object lookupInParents( CPPSemantics.LookupData data, ICPPScope lookIn ) throws DOMException{
|
||||
IASTNode node = lookIn.getPhysicalNode();
|
||||
if( node == null || !(node instanceof ICPPASTCompositeTypeSpecifier) )
|
||||
return null;
|
||||
|
@ -983,9 +983,9 @@ public class CPPSemantics {
|
|||
cls = (ICPPClassType) binding;
|
||||
else
|
||||
continue;
|
||||
ICPPClassScope parent = (ICPPClassScope) cls.getCompositeScope();
|
||||
ICPPScope parent = (ICPPScope) cls.getCompositeScope();
|
||||
|
||||
if( parent == null )
|
||||
if( parent == null || parent instanceof CPPUnknownScope )
|
||||
continue;
|
||||
|
||||
if( !bases[i].isVirtual() || !data.visited.containsKey( parent ) ){
|
||||
|
|
|
@ -1215,12 +1215,16 @@ public class CPPTemplates {
|
|||
IType [] args = createArgsForFunctionTemplateOrdering( f1 );
|
||||
ICPPFunction function = (ICPPFunction) ((ICPPInternalTemplate)f1).instantiate( args );
|
||||
|
||||
ObjectMap m1 = deduceTemplateArguments( f2, function.getType().getParameterTypes() );
|
||||
ObjectMap m1 = null;
|
||||
if( function != null )
|
||||
m1 = deduceTemplateArguments( f2, function.getType().getParameterTypes() );
|
||||
|
||||
args = createArgsForFunctionTemplateOrdering( f2 );
|
||||
function = (ICPPFunction) ((ICPPInternalTemplate)f2).instantiate( args );
|
||||
|
||||
ObjectMap m2 = deduceTemplateArguments( f1, function.getType().getParameterTypes() );
|
||||
ObjectMap m2 = null;
|
||||
if( function != null )
|
||||
m2 = deduceTemplateArguments( f1, function.getType().getParameterTypes() );
|
||||
|
||||
//The transformed template is at least as specialized as the other iff the deduction
|
||||
//succeeds and the deduced parameter types are an exact match
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
|||
* @author aniefer
|
||||
*/
|
||||
public class CPPTypedef implements ITypedef, ITypeContainer, ICPPInternalBinding {
|
||||
public static class CPPTypedefDelegate extends CPPDelegate implements ITypedef {
|
||||
public static class CPPTypedefDelegate extends CPPDelegate implements ITypedef, ITypeContainer {
|
||||
public CPPTypedefDelegate( IASTName name, ITypedef binding ) {
|
||||
super( name, binding );
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPInternalBinding
|
|||
public boolean isSameType( IType type ) {
|
||||
return ((ITypedef)getBinding()).isSameType( type );
|
||||
}
|
||||
public void setType(IType type) {
|
||||
((ITypeContainer)getBinding()).setType( type );
|
||||
}
|
||||
}
|
||||
private IASTName [] declarations = null;
|
||||
private IType type = null;
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
|
@ -33,6 +34,10 @@ public class CPPUsingDeclaration implements ICPPUsingDeclaration, ICPPInternalBi
|
|||
private ICPPDelegate [] delegates;
|
||||
|
||||
public CPPUsingDeclaration( IASTName name, IBinding [] bindings ) {
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ ns.length - 1 ];
|
||||
}
|
||||
this.name = name;
|
||||
this.delegates = createDelegates( bindings );
|
||||
}
|
||||
|
@ -58,15 +63,15 @@ public class CPPUsingDeclaration implements ICPPUsingDeclaration, ICPPInternalBi
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
|
||||
*/
|
||||
public String[] getQualifiedName() throws DOMException {
|
||||
return delegates[0].getQualifiedName();
|
||||
public String[] getQualifiedName() {
|
||||
return CPPVisitor.getQualifiedName( this );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
|
||||
*/
|
||||
public char[][] getQualifiedNameCharArray() throws DOMException {
|
||||
return delegates[0].getQualifiedNameCharArray();
|
||||
public char[][] getQualifiedNameCharArray() {
|
||||
return CPPVisitor.getQualifiedNameCharArray( this );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -86,14 +91,15 @@ public class CPPUsingDeclaration implements ICPPUsingDeclaration, ICPPInternalBi
|
|||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return delegates[0].getName();
|
||||
return name.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||
*/
|
||||
public char[] getNameCharArray() {
|
||||
return delegates[0].getNameCharArray(); }
|
||||
return name.toCharArray();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
|
|
|
@ -157,13 +157,14 @@ public class TemplateTokenDuple extends BasicTokenDuple {
|
|||
}
|
||||
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev != null ? prev : startOfSegment, newArgs );
|
||||
r.add( d );
|
||||
startOfSegment = token.getNext();
|
||||
startOfSegment = (token != last ) ? token.getNext() : last;
|
||||
++count;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
List newArgs = null;
|
||||
if( argLists[count] != null )
|
||||
//pointer to members could have a A::B<int>::
|
||||
if( count < argLists.length && argLists[count] != null )
|
||||
{
|
||||
newArgs = new ArrayList( 1 );
|
||||
newArgs.add( argLists[count]);
|
||||
|
|
|
@ -173,9 +173,8 @@ public class TokenFactory {
|
|||
|
||||
public int removeValue()
|
||||
{
|
||||
int result = array[currentIndex];
|
||||
int result = array[--currentIndex];
|
||||
array[currentIndex] = -1;
|
||||
--currentIndex;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue