mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Implement IGPPPointerType and IGPPPointerToMemberType (bug 87424)
This commit is contained in:
parent
f4f3208534
commit
9e60f45170
6 changed files with 163 additions and 12 deletions
|
@ -63,6 +63,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
|||
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.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerToMemberType;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
|
||||
|
@ -1518,7 +1520,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
IType t = pm.getType();
|
||||
assertNotNull(t);
|
||||
assertTrue(t instanceof ICPPPointerToMemberType);
|
||||
ICPPClassType cls = (ICPPClassType) ((ICPPPointerToMemberType) t).getMemberOfClass();
|
||||
ICPPClassType cls = ((ICPPPointerToMemberType) t).getMemberOfClass();
|
||||
assertSame(S, cls);
|
||||
assertTrue(((ICPPPointerToMemberType) t).getType() instanceof IBasicType);
|
||||
}
|
||||
|
@ -1565,8 +1567,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertTrue(t instanceof ICPPPointerToMemberType);
|
||||
IFunctionType ft = (IFunctionType) ((ICPPPointerToMemberType) t)
|
||||
.getType();
|
||||
ICPPClassType ST = (ICPPClassType) ((ICPPPointerToMemberType) t)
|
||||
.getMemberOfClass();
|
||||
ICPPClassType ST = ((ICPPPointerToMemberType) t).getMemberOfClass();
|
||||
|
||||
assertTrue(ft.getReturnType() instanceof IPointerType);
|
||||
assertSame(ST, ((IPointerType) ft.getReturnType()).getType());
|
||||
|
@ -2850,5 +2851,25 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertSame( result[8], A_implicit[2] );
|
||||
assertSame( result[9], A_implicit[3] );
|
||||
}
|
||||
|
||||
public void testBug87424() throws Exception{
|
||||
IASTTranslationUnit tu = parse( "int * restrict x;", ParserLanguage.CPP, true ); //$NON-NLS-1$
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
IVariable x = (IVariable) col.getName(0).resolveBinding();
|
||||
IType t = x.getType();
|
||||
assertTrue( t instanceof IGPPPointerType );
|
||||
assertTrue( ((IGPPPointerType) t).isRestrict() );
|
||||
|
||||
tu = parse( "class A {}; int A::* restrict x;", ParserLanguage.CPP, true ); //$NON-NLS-1$
|
||||
col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
x = (IVariable) col.getName(3).resolveBinding();
|
||||
t = x.getType();
|
||||
assertTrue( t instanceof IGPPPointerToMemberType );
|
||||
assertTrue( ((IGPPPointerToMemberType) t).isRestrict() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
|||
*/
|
||||
public class CPPPointerToMemberType extends CPPPointerType implements
|
||||
ICPPPointerToMemberType {
|
||||
|
||||
private ICPPASTPointerToMember operator = null;
|
||||
private ICPPClassType clsType = null;
|
||||
/**
|
||||
* @param type
|
||||
|
@ -36,6 +36,7 @@ public class CPPPointerToMemberType extends CPPPointerType implements
|
|||
*/
|
||||
public CPPPointerToMemberType(IType type, ICPPASTPointerToMember operator) {
|
||||
super(type, operator);
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public boolean equals( Object o ){
|
||||
|
@ -62,7 +63,7 @@ public class CPPPointerToMemberType extends CPPPointerType implements
|
|||
*/
|
||||
public ICPPClassType getMemberOfClass() {
|
||||
if( clsType == null ){
|
||||
ICPPASTPointerToMember pm = (ICPPASTPointerToMember) operator;
|
||||
ICPPASTPointerToMember pm = operator;
|
||||
IASTName name = pm.getName();
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
|
|
|
@ -23,22 +23,30 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
|||
* @author aniefer
|
||||
*/
|
||||
public class CPPPointerType implements IPointerType, ITypeContainer {
|
||||
protected IASTPointer operator = null;
|
||||
protected IType type = null;
|
||||
private boolean isConst = false;
|
||||
private boolean isVolatile = false;
|
||||
/**
|
||||
* @param type
|
||||
* @param operator
|
||||
*/
|
||||
public CPPPointerType(IType type, IASTPointer operator) {
|
||||
this.type = type;
|
||||
this.operator = operator;
|
||||
this.isConst = operator.isConst();
|
||||
this.isVolatile = operator.isVolatile();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type2
|
||||
*/
|
||||
public CPPPointerType(IType type) {
|
||||
public CPPPointerType(IType type, boolean isConst, boolean isVolatile ) {
|
||||
this.type = type;
|
||||
this.isConst = isConst;
|
||||
this.isVolatile = isVolatile;
|
||||
}
|
||||
|
||||
public CPPPointerType( IType type ){
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean equals( Object o ){
|
||||
|
@ -51,7 +59,7 @@ public class CPPPointerType implements IPointerType, ITypeContainer {
|
|||
return false;
|
||||
|
||||
CPPPointerType pt = (CPPPointerType) o;
|
||||
if( isConst() == pt.isConst() && isVolatile() == pt.isVolatile() )
|
||||
if( isConst == pt.isConst && isVolatile == pt.isVolatile )
|
||||
return type.equals( pt.getType() );
|
||||
return false;
|
||||
}
|
||||
|
@ -71,14 +79,14 @@ public class CPPPointerType implements IPointerType, ITypeContainer {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IPointerType#isConst()
|
||||
*/
|
||||
public boolean isConst() {
|
||||
return ( operator != null ) ? operator.isConst() : false;
|
||||
return isConst;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IPointerType#isVolatile()
|
||||
*/
|
||||
public boolean isVolatile() {
|
||||
return ( operator != null ) ? operator.isVolatile() : false;
|
||||
return isVolatile;
|
||||
}
|
||||
|
||||
public Object clone(){
|
||||
|
|
|
@ -101,6 +101,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
@ -1175,8 +1177,12 @@ public class CPPVisitor {
|
|||
private static IType getPointerTypes( IType type, IASTDeclarator declarator ){
|
||||
IASTPointerOperator [] ptrOps = declarator.getPointerOperators();
|
||||
for( int i = 0; i < ptrOps.length; i++ ){
|
||||
if( ptrOps[i] instanceof ICPPASTPointerToMember )
|
||||
if( ptrOps[i] instanceof IGPPASTPointerToMember )
|
||||
type = new GPPPointerToMemberType( type, (IGPPASTPointerToMember) ptrOps[i] );
|
||||
else if( ptrOps[i] instanceof ICPPASTPointerToMember )
|
||||
type = new CPPPointerToMemberType( type, (ICPPASTPointerToMember) ptrOps[i] );
|
||||
else if( ptrOps[i] instanceof IGPPASTPointer )
|
||||
type = new GPPPointerType( type, (IGPPASTPointer) ptrOps[i] );
|
||||
else if( ptrOps[i] instanceof IASTPointer )
|
||||
type = new CPPPointerType( type, (IASTPointer) ptrOps[i] );
|
||||
else if( ptrOps[i] instanceof ICPPASTReferenceOperator )
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Created on Mar 11, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerToMemberType;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class GPPPointerToMemberType extends CPPPointerToMemberType implements
|
||||
IGPPPointerToMemberType {
|
||||
|
||||
private boolean isRestrict = false;
|
||||
/**
|
||||
* @param type
|
||||
* @param operator
|
||||
*/
|
||||
public GPPPointerToMemberType( IType type, IGPPASTPointerToMember operator ) {
|
||||
super( type, operator );
|
||||
this.isRestrict = operator.isRestrict();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType#isRestrict()
|
||||
*/
|
||||
public boolean isRestrict() {
|
||||
return isRestrict;
|
||||
}
|
||||
|
||||
public boolean equals( Object o ){
|
||||
if( !super.equals( o ) ) return false;
|
||||
|
||||
if( o instanceof IGPPPointerToMemberType ){
|
||||
return (isRestrict == ((IGPPPointerToMemberType) o).isRestrict());
|
||||
}
|
||||
return (isRestrict == false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Created on Mar 11, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPPointerType;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class GPPPointerType extends CPPPointerType implements IGPPPointerType {
|
||||
private boolean isRestrict = false;
|
||||
/**
|
||||
* @param type
|
||||
* @param operator
|
||||
*/
|
||||
public GPPPointerType( IType type, IGPPASTPointer operator ) {
|
||||
super( type, operator );
|
||||
isRestrict = operator.isRestrict();
|
||||
}
|
||||
|
||||
public GPPPointerType( IType type ){
|
||||
super( type );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type
|
||||
*/
|
||||
public GPPPointerType( IType type, boolean isConst, boolean isVolatile, boolean isRestrict ) {
|
||||
super( type, isConst, isVolatile );
|
||||
this.isRestrict = isRestrict;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer#isRestrict()
|
||||
*/
|
||||
public boolean isRestrict() {
|
||||
return isRestrict;
|
||||
|
||||
}
|
||||
|
||||
public boolean equals( Object o ){
|
||||
if( !super.equals( o ) ) return false;
|
||||
|
||||
if( o instanceof IGPPPointerType ){
|
||||
return (isRestrict == ((IGPPPointerType) o).isRestrict());
|
||||
}
|
||||
return (isRestrict == false);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue