Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2005-03-11 16:15:05 +0000
committerAndrew Niefer2005-03-11 16:15:05 +0000
commit9e60f451708666e38349593a21f5a71b72147ee5 (patch)
tree2a78886d34c786f00118495045390935e4272bc7
parentf4f320853448aeabd8fd6dac326cb4a38ac48a68 (diff)
downloadorg.eclipse.cdt-9e60f451708666e38349593a21f5a71b72147ee5.tar.gz
org.eclipse.cdt-9e60f451708666e38349593a21f5a71b72147ee5.tar.xz
org.eclipse.cdt-9e60f451708666e38349593a21f5a71b72147ee5.zip
Implement IGPPPointerType and IGPPPointerToMemberType (bug 87424)
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java20
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java52
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java63
6 files changed, 163 insertions, 12 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index c4148b80f2c..c12c0f5d2c6 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -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() );
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java
index 4b31f15ce8e..173f538fca6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerToMemberType.java
@@ -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();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java
index 81f460327e4..5ff3e944d4f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPPointerType.java
@@ -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(){
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java
index 0afffc295eb..d6e4b4f9098 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java
@@ -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 )
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java
new file mode 100644
index 00000000000..1c5f4c5367e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerToMemberType.java
@@ -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);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java
new file mode 100644
index 00000000000..f0e09883b86
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPPointerType.java
@@ -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);
+ }
+}

Back to the top