mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 13:55:39 +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[1], col.getName(2).resolveBinding() );
|
||||||
assertSame( bindings[2], col.getName(3).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
|
* @author aniefer
|
||||||
*/
|
*/
|
||||||
public class ProblemBinding implements IProblemBinding, IType, IScope {
|
public class ProblemBinding implements IProblemBinding, IType, IScope {
|
||||||
private final int id;
|
protected final int id;
|
||||||
private final char [] arg;
|
protected final char [] arg;
|
||||||
private IASTNode node;
|
protected IASTNode node;
|
||||||
private String message = null;
|
private String message = null;
|
||||||
|
|
||||||
public ProblemBinding( IASTNode node, int id, char [] arg ){
|
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 {
|
public class CPPBaseClause implements ICPPBase {
|
||||||
static public class CPPBaseProblem extends ProblemBinding implements ICPPBase {
|
static public class CPPBaseProblem extends ProblemBinding implements ICPPBase {
|
||||||
|
private ICPPClassType classProblem = null;
|
||||||
public CPPBaseProblem( IASTNode node, int id, char[] arg ) {
|
public CPPBaseProblem( IASTNode node, int id, char[] arg ) {
|
||||||
super( node, id, arg );
|
super( node, id, arg );
|
||||||
}
|
}
|
||||||
public ICPPClassType getBaseClass() throws DOMException {
|
public ICPPClassType getBaseClass() {
|
||||||
throw new DOMException( this );
|
if( classProblem == null ){
|
||||||
|
classProblem = new CPPClassType.CPPClassTypeProblem( node, id, arg );
|
||||||
|
}
|
||||||
|
return classProblem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVisibility() throws DOMException {
|
public int getVisibility() throws DOMException {
|
||||||
|
|
|
@ -155,13 +155,15 @@ public class CPPClassInstance extends CPPInstance implements ICPPClassType, ICPP
|
||||||
return true;
|
return true;
|
||||||
if( type instanceof ITypedef )
|
if( type instanceof ITypedef )
|
||||||
return ((ITypedef)type).isSameType( this );
|
return ((ITypedef)type).isSameType( this );
|
||||||
|
if( type instanceof CPPDeferredClassInstance )
|
||||||
|
return type.isSameType( this ); //the CPPDeferredClassInstance has some fuzziness
|
||||||
|
|
||||||
if( type instanceof ICPPTemplateInstance ){
|
if( type instanceof ICPPTemplateInstance ){
|
||||||
if( getSpecializedBinding() != ((ICPPTemplateInstance)type).getTemplateDefinition() )
|
if( getSpecializedBinding() != ((ICPPTemplateInstance)type).getTemplateDefinition() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ObjectMap m1 = getArgumentMap(), m2 = ((ICPPTemplateInstance)type).getArgumentMap();
|
ObjectMap m1 = getArgumentMap(), m2 = ((ICPPTemplateInstance)type).getArgumentMap();
|
||||||
if( m1.size() != m2.size() )
|
if( m1 == null || m2 == null || m1.size() != m2.size())
|
||||||
return false;
|
return false;
|
||||||
for( int i = 0; i < m1.size(); i++ ){
|
for( int i = 0; i < m1.size(); i++ ){
|
||||||
IType t1 = (IType) m1.getAt( i );
|
IType t1 = (IType) m1.getAt( i );
|
||||||
|
|
|
@ -914,7 +914,7 @@ public class CPPSemantics {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( !data.usingDirectivesOnly && scope instanceof ICPPClassScope ){
|
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()) )
|
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();
|
IASTNode node = lookIn.getPhysicalNode();
|
||||||
if( node == null || !(node instanceof ICPPASTCompositeTypeSpecifier) )
|
if( node == null || !(node instanceof ICPPASTCompositeTypeSpecifier) )
|
||||||
return null;
|
return null;
|
||||||
|
@ -983,9 +983,9 @@ public class CPPSemantics {
|
||||||
cls = (ICPPClassType) binding;
|
cls = (ICPPClassType) binding;
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
ICPPClassScope parent = (ICPPClassScope) cls.getCompositeScope();
|
ICPPScope parent = (ICPPScope) cls.getCompositeScope();
|
||||||
|
|
||||||
if( parent == null )
|
if( parent == null || parent instanceof CPPUnknownScope )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( !bases[i].isVirtual() || !data.visited.containsKey( parent ) ){
|
if( !bases[i].isVirtual() || !data.visited.containsKey( parent ) ){
|
||||||
|
|
|
@ -1215,12 +1215,16 @@ public class CPPTemplates {
|
||||||
IType [] args = createArgsForFunctionTemplateOrdering( f1 );
|
IType [] args = createArgsForFunctionTemplateOrdering( f1 );
|
||||||
ICPPFunction function = (ICPPFunction) ((ICPPInternalTemplate)f1).instantiate( args );
|
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 );
|
args = createArgsForFunctionTemplateOrdering( f2 );
|
||||||
function = (ICPPFunction) ((ICPPInternalTemplate)f2).instantiate( args );
|
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
|
//The transformed template is at least as specialized as the other iff the deduction
|
||||||
//succeeds and the deduced parameter types are an exact match
|
//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
|
* @author aniefer
|
||||||
*/
|
*/
|
||||||
public class CPPTypedef implements ITypedef, ITypeContainer, ICPPInternalBinding {
|
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 ) {
|
public CPPTypedefDelegate( IASTName name, ITypedef binding ) {
|
||||||
super( name, binding );
|
super( name, binding );
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,9 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPInternalBinding
|
||||||
public boolean isSameType( IType type ) {
|
public boolean isSameType( IType type ) {
|
||||||
return ((ITypedef)getBinding()).isSameType( type );
|
return ((ITypedef)getBinding()).isSameType( type );
|
||||||
}
|
}
|
||||||
|
public void setType(IType type) {
|
||||||
|
((ITypeContainer)getBinding()).setType( type );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private IASTName [] declarations = null;
|
private IASTName [] declarations = null;
|
||||||
private IType type = 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.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
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.ICPPASTTemplateId;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||||
|
@ -33,6 +34,10 @@ public class CPPUsingDeclaration implements ICPPUsingDeclaration, ICPPInternalBi
|
||||||
private ICPPDelegate [] delegates;
|
private ICPPDelegate [] delegates;
|
||||||
|
|
||||||
public CPPUsingDeclaration( IASTName name, IBinding [] bindings ) {
|
public CPPUsingDeclaration( IASTName name, IBinding [] bindings ) {
|
||||||
|
if( name instanceof ICPPASTQualifiedName ){
|
||||||
|
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||||
|
name = ns[ ns.length - 1 ];
|
||||||
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.delegates = createDelegates( bindings );
|
this.delegates = createDelegates( bindings );
|
||||||
}
|
}
|
||||||
|
@ -58,15 +63,15 @@ public class CPPUsingDeclaration implements ICPPUsingDeclaration, ICPPInternalBi
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
|
||||||
*/
|
*/
|
||||||
public String[] getQualifiedName() throws DOMException {
|
public String[] getQualifiedName() {
|
||||||
return delegates[0].getQualifiedName();
|
return CPPVisitor.getQualifiedName( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
|
||||||
*/
|
*/
|
||||||
public char[][] getQualifiedNameCharArray() throws DOMException {
|
public char[][] getQualifiedNameCharArray() {
|
||||||
return delegates[0].getQualifiedNameCharArray();
|
return CPPVisitor.getQualifiedNameCharArray( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -86,14 +91,15 @@ public class CPPUsingDeclaration implements ICPPUsingDeclaration, ICPPInternalBi
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return delegates[0].getName();
|
return name.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
|
||||||
*/
|
*/
|
||||||
public char[] getNameCharArray() {
|
public char[] getNameCharArray() {
|
||||||
return delegates[0].getNameCharArray(); }
|
return name.toCharArray();
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
* @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 );
|
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev != null ? prev : startOfSegment, newArgs );
|
||||||
r.add( d );
|
r.add( d );
|
||||||
startOfSegment = token.getNext();
|
startOfSegment = (token != last ) ? token.getNext() : last;
|
||||||
++count;
|
++count;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List newArgs = null;
|
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 = new ArrayList( 1 );
|
||||||
newArgs.add( argLists[count]);
|
newArgs.add( argLists[count]);
|
||||||
|
|
|
@ -173,9 +173,8 @@ public class TokenFactory {
|
||||||
|
|
||||||
public int removeValue()
|
public int removeValue()
|
||||||
{
|
{
|
||||||
int result = array[currentIndex];
|
int result = array[--currentIndex];
|
||||||
array[currentIndex] = -1;
|
array[currentIndex] = -1;
|
||||||
--currentIndex;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue