mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
more C Types from Devin Steffler
This commit is contained in:
parent
57a32ca95d
commit
b0f2b85991
5 changed files with 137 additions and 187 deletions
|
@ -887,7 +887,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
buffer.append( "const int c; \n" ); //$NON-NLS-1$
|
||||
buffer.append( "const char * const d; \n" ); //$NON-NLS-1$
|
||||
buffer.append( "const char ** e; \n" ); //$NON-NLS-1$
|
||||
buffer.append( "const char ***** f; \n" ); //$NON-NLS-1$
|
||||
buffer.append( "const char * const * const volatile ** const * f; \n" ); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
|
||||
|
||||
|
@ -937,8 +937,10 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IType t_e_1 = e.getType();
|
||||
assertTrue( t_e_1 instanceof IPointerType );
|
||||
assertFalse( ((IPointerType)t_e_1).isConst() );
|
||||
IType t_e_2 = ((IPointerType)t_e_1).getType();
|
||||
assertTrue( t_e_2 instanceof IPointerType );
|
||||
assertFalse( ((IPointerType)t_e_2).isConst() );
|
||||
IType t_e_3 = ((IPointerType)t_e_2).getType();
|
||||
assertTrue( t_e_3 instanceof IQualifierType );
|
||||
assertTrue( ((IQualifierType)t_e_3).isConst() );
|
||||
|
@ -948,14 +950,24 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IType t_f_1 = f.getType();
|
||||
assertTrue( t_f_1 instanceof IPointerType );
|
||||
assertFalse( ((IPointerType)t_f_1).isConst() );
|
||||
assertFalse( ((IPointerType)t_f_1).isVolatile() );
|
||||
IType t_f_2 = ((IPointerType)t_f_1).getType();
|
||||
assertTrue( t_f_2 instanceof IPointerType );
|
||||
assertTrue( ((IPointerType)t_f_2).isConst() );
|
||||
assertFalse( ((IPointerType)t_f_2).isVolatile() );
|
||||
IType t_f_3 = ((IPointerType)t_f_2).getType();
|
||||
assertTrue( t_f_2 instanceof IPointerType );
|
||||
assertTrue( t_f_3 instanceof IPointerType );
|
||||
assertFalse( ((IPointerType)t_f_3).isConst() );
|
||||
assertFalse( ((IPointerType)t_f_3).isVolatile() );
|
||||
IType t_f_4 = ((IPointerType)t_f_3).getType();
|
||||
assertTrue( t_f_2 instanceof IPointerType );
|
||||
assertTrue( t_f_4 instanceof IPointerType );
|
||||
assertTrue( ((IPointerType)t_f_4).isConst() );
|
||||
assertTrue( ((IPointerType)t_f_4).isVolatile() );
|
||||
IType t_f_5 = ((IPointerType)t_f_4).getType();
|
||||
assertTrue( t_f_2 instanceof IPointerType );
|
||||
assertTrue( t_f_5 instanceof IPointerType );
|
||||
assertTrue( ((IPointerType)t_f_5).isConst() );
|
||||
assertFalse( ((IPointerType)t_f_5).isVolatile() );
|
||||
IType t_f_6 = ((IPointerType)t_f_5).getType();
|
||||
assertTrue( t_f_6 instanceof IQualifierType );
|
||||
assertTrue( ((IQualifierType)t_f_6).isConst() );
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
|
||||
|
@ -23,14 +24,15 @@ import org.eclipse.cdt.core.dom.ast.c.ICQualifierType;
|
|||
*/
|
||||
public class CQualifierType implements ICQualifierType {
|
||||
|
||||
ICASTDeclSpecifier declSpec = null;
|
||||
IASTDeclSpecifier declSpec = null;
|
||||
IType type = null;
|
||||
|
||||
/**
|
||||
* CQualifierType has an IBasicType to keep track of the basic type information.
|
||||
*
|
||||
* @param type the CQualifierType's IBasicType
|
||||
*/
|
||||
public CQualifierType(ICASTDeclSpecifier declSpec) {
|
||||
public CQualifierType(IASTDeclSpecifier declSpec) {
|
||||
this.declSpec = declSpec;
|
||||
}
|
||||
|
||||
|
@ -55,25 +57,28 @@ public class CQualifierType implements ICQualifierType {
|
|||
*/
|
||||
public boolean isRestrict() {
|
||||
if (declSpec == null) return false;
|
||||
|
||||
return declSpec.isRestrict();
|
||||
return (declSpec instanceof ICASTDeclSpecifier && ((ICASTDeclSpecifier)declSpec).isRestrict());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IQualifierType#getType()
|
||||
*/
|
||||
public IType getType() {
|
||||
if( declSpec instanceof ICASTTypedefNameSpecifier ){
|
||||
ICASTTypedefNameSpecifier nameSpec = (ICASTTypedefNameSpecifier) declSpec;
|
||||
return (IType) nameSpec.getName().resolveBinding();
|
||||
} else if( declSpec instanceof IASTElaboratedTypeSpecifier ){
|
||||
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) declSpec;
|
||||
return (IType) elabTypeSpec.getName().resolveBinding();
|
||||
} else if( declSpec instanceof IASTCompositeTypeSpecifier ){
|
||||
IASTCompositeTypeSpecifier compTypeSpec = (IASTCompositeTypeSpecifier) declSpec;
|
||||
return (IType) compTypeSpec.getName().resolveBinding();
|
||||
}
|
||||
if (type == null) {
|
||||
if( declSpec instanceof ICASTTypedefNameSpecifier ){
|
||||
ICASTTypedefNameSpecifier nameSpec = (ICASTTypedefNameSpecifier) declSpec;
|
||||
type = (IType) nameSpec.getName().resolveBinding();
|
||||
} else if( declSpec instanceof IASTElaboratedTypeSpecifier ){
|
||||
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) declSpec;
|
||||
type = (IType) elabTypeSpec.getName().resolveBinding();
|
||||
} else if( declSpec instanceof IASTCompositeTypeSpecifier ){
|
||||
IASTCompositeTypeSpecifier compTypeSpec = (IASTCompositeTypeSpecifier) declSpec;
|
||||
type = (IType) compTypeSpec.getName().resolveBinding();
|
||||
}
|
||||
|
||||
type = new CBasicType((ICASTSimpleDeclSpecifier)declSpec);
|
||||
}
|
||||
|
||||
return new CBasicType((ICASTSimpleDeclSpecifier)declSpec);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,22 +11,13 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
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.c.ICASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
||||
|
||||
/**
|
||||
* Created on Nov 8, 2004
|
||||
|
@ -34,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
|||
*/
|
||||
public class CTypeDef implements ITypedef {
|
||||
private final IASTName name;
|
||||
private IType type = null;
|
||||
|
||||
public CTypeDef( IASTName name ){
|
||||
this.name = name;
|
||||
|
@ -46,81 +38,9 @@ public class CTypeDef implements ITypedef {
|
|||
* @see org.eclipse.cdt.core.dom.ast.ITypedef#getType()
|
||||
*/
|
||||
public IType getType() {
|
||||
IASTDeclarator declarator = (IASTDeclarator) name.getParent();
|
||||
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) declarator.getParent();
|
||||
|
||||
IASTDeclSpecifier declSpec = declaration.getDeclSpecifier();
|
||||
if( declSpec instanceof ICASTTypedefNameSpecifier ){
|
||||
IType lastType = null;
|
||||
ICASTTypedefNameSpecifier nameSpec = (ICASTTypedefNameSpecifier) declSpec;
|
||||
lastType = (IType) nameSpec.getName().resolveBinding();
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
} else if( declSpec instanceof IASTElaboratedTypeSpecifier ){
|
||||
IType lastType = null;
|
||||
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) declSpec;
|
||||
lastType = (IType) elabTypeSpec.getName().resolveBinding();
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
} else if( declSpec instanceof IASTCompositeTypeSpecifier ){
|
||||
IType lastType = null;
|
||||
IASTCompositeTypeSpecifier compTypeSpec = (IASTCompositeTypeSpecifier) declSpec;
|
||||
lastType = (IType) compTypeSpec.getName().resolveBinding();
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
} else if (declSpec instanceof ICASTSimpleDeclSpecifier) {
|
||||
IType lastType = null;
|
||||
if (declSpec.isConst() || declSpec.isVolatile() || ((ICASTSimpleDeclSpecifier)declSpec).isRestrict())
|
||||
lastType = new CQualifierType((ICASTDeclSpecifier)declSpec);
|
||||
else
|
||||
lastType = new CBasicType((ICASTSimpleDeclSpecifier)declSpec);
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private IType setupPointerChain(IASTPointerOperator[] ptrs, IType lastType) {
|
||||
CPointerType pointerType = null;
|
||||
|
||||
if ( ptrs != null && ptrs.length > 0 ) {
|
||||
pointerType = new CPointerType();
|
||||
|
||||
if (ptrs.length == 1) {
|
||||
pointerType.setType(lastType);
|
||||
pointerType.setPointer((ICASTPointer)ptrs[0]);
|
||||
} else {
|
||||
CPointerType tempType = new CPointerType();
|
||||
pointerType.setType(tempType);
|
||||
pointerType.setPointer((ICASTPointer)ptrs[0]);
|
||||
for (int i=1; i<ptrs.length - 1; i++) {
|
||||
tempType.setType(new CPointerType());
|
||||
tempType.setPointer((ICASTPointer)ptrs[i]);
|
||||
tempType = (CPointerType)tempType.getType();
|
||||
}
|
||||
tempType.setType(lastType);
|
||||
}
|
||||
|
||||
return pointerType;
|
||||
}
|
||||
|
||||
return null;
|
||||
if (type == null)
|
||||
type = CVisitor.getType(name);
|
||||
return type;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -11,23 +11,13 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType;
|
||||
|
||||
/**
|
||||
* Created on Nov 5, 2004
|
||||
|
@ -35,6 +25,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CBasicType;
|
|||
*/
|
||||
public class CVariable implements IVariable {
|
||||
final IASTName name;
|
||||
private IType type = null;
|
||||
|
||||
public CVariable( IASTName name ){
|
||||
// name = checkForDefinition( name );
|
||||
|
@ -67,82 +58,11 @@ public class CVariable implements IVariable {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IVariable#getType()
|
||||
*/
|
||||
public IType getType() {
|
||||
IASTDeclarator declarator = (IASTDeclarator) name.getParent();
|
||||
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) declarator.getParent();
|
||||
IASTDeclSpecifier declSpec = declaration.getDeclSpecifier();
|
||||
if( declSpec instanceof ICASTTypedefNameSpecifier ){
|
||||
IType lastType = null;
|
||||
ICASTTypedefNameSpecifier nameSpec = (ICASTTypedefNameSpecifier) declSpec;
|
||||
lastType = (IType) nameSpec.getName().resolveBinding();
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
} else if( declSpec instanceof IASTElaboratedTypeSpecifier ){
|
||||
IType lastType = null;
|
||||
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) declSpec;
|
||||
lastType = (IType) elabTypeSpec.getName().resolveBinding();
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
} else if( declSpec instanceof IASTCompositeTypeSpecifier ){
|
||||
IType lastType = null;
|
||||
IASTCompositeTypeSpecifier compTypeSpec = (IASTCompositeTypeSpecifier) declSpec;
|
||||
lastType = (IType) compTypeSpec.getName().resolveBinding();
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
} else if (declSpec instanceof ICASTSimpleDeclSpecifier) {
|
||||
IType lastType = null;
|
||||
if (declSpec.isConst() || declSpec.isVolatile() || ((ICASTSimpleDeclSpecifier)declSpec).isRestrict())
|
||||
lastType = new CQualifierType((ICASTDeclSpecifier)declSpec);
|
||||
else
|
||||
lastType = new CBasicType((ICASTSimpleDeclSpecifier)declSpec);
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
}
|
||||
return null;
|
||||
if (type == null)
|
||||
type = CVisitor.getType(name);
|
||||
return type;
|
||||
}
|
||||
|
||||
private IType setupPointerChain(IASTPointerOperator[] ptrs, IType lastType) {
|
||||
CPointerType pointerType = null;
|
||||
|
||||
if ( ptrs != null && ptrs.length > 0 ) {
|
||||
pointerType = new CPointerType();
|
||||
|
||||
if (ptrs.length == 1) {
|
||||
pointerType.setType(lastType);
|
||||
pointerType.setPointer((ICASTPointer)ptrs[0]);
|
||||
} else {
|
||||
CPointerType tempType = new CPointerType();
|
||||
pointerType.setType(tempType);
|
||||
pointerType.setPointer((ICASTPointer)ptrs[0]);
|
||||
for (int i=1; i<ptrs.length - 1; i++) {
|
||||
tempType.setType(new CPointerType());
|
||||
tempType.setPointer((ICASTPointer)ptrs[i]);
|
||||
tempType = (CPointerType)tempType.getType();
|
||||
}
|
||||
tempType.setType(lastType);
|
||||
}
|
||||
|
||||
return pointerType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||
|
@ -44,6 +45,7 @@ import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
|
@ -65,8 +67,11 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
|
|||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
||||
|
@ -880,4 +885,92 @@ public class CVisitor {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static IType getType(IASTName name) {
|
||||
IASTDeclarator declarator = (IASTDeclarator) name.getParent();
|
||||
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) declarator.getParent();
|
||||
|
||||
IASTDeclSpecifier declSpec = declaration.getDeclSpecifier();
|
||||
if( declSpec instanceof ICASTTypedefNameSpecifier ){
|
||||
if (declSpec.isConst() || declSpec.isVolatile() || (declSpec instanceof ICASTDeclSpecifier && ((ICASTDeclSpecifier)declSpec).isRestrict()))
|
||||
return new CQualifierType(declSpec);
|
||||
|
||||
IType lastType = null;
|
||||
ICASTTypedefNameSpecifier nameSpec = (ICASTTypedefNameSpecifier) declSpec;
|
||||
lastType = (IType) nameSpec.getName().resolveBinding();
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
} else if( declSpec instanceof IASTElaboratedTypeSpecifier ){
|
||||
if (declSpec.isConst() || declSpec.isVolatile() || (declSpec instanceof ICASTDeclSpecifier && ((ICASTDeclSpecifier)declSpec).isRestrict()))
|
||||
return new CQualifierType(declSpec);
|
||||
|
||||
IType lastType = null;
|
||||
IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) declSpec;
|
||||
lastType = (IType) elabTypeSpec.getName().resolveBinding();
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
} else if( declSpec instanceof IASTCompositeTypeSpecifier ){
|
||||
if (declSpec.isConst() || declSpec.isVolatile() || (declSpec instanceof ICASTDeclSpecifier && ((ICASTDeclSpecifier)declSpec).isRestrict()))
|
||||
return new CQualifierType(declSpec);
|
||||
|
||||
IType lastType = null;
|
||||
IASTCompositeTypeSpecifier compTypeSpec = (IASTCompositeTypeSpecifier) declSpec;
|
||||
lastType = (IType) compTypeSpec.getName().resolveBinding();
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
} else if (declSpec instanceof ICASTSimpleDeclSpecifier) {
|
||||
IType lastType = null;
|
||||
if (declSpec.isConst() || declSpec.isVolatile() || (declSpec instanceof ICASTDeclSpecifier && ((ICASTDeclSpecifier)declSpec).isRestrict()))
|
||||
lastType = new CQualifierType(declSpec);
|
||||
else
|
||||
lastType = new CBasicType((ICASTSimpleDeclSpecifier)declSpec);
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
||||
if (pointerChain != null) return pointerChain;
|
||||
|
||||
return lastType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static IType setupPointerChain(IASTPointerOperator[] ptrs, IType lastType) {
|
||||
CPointerType pointerType = null;
|
||||
|
||||
if ( ptrs != null && ptrs.length > 0 ) {
|
||||
pointerType = new CPointerType();
|
||||
|
||||
if (ptrs.length == 1) {
|
||||
pointerType.setType(lastType);
|
||||
pointerType.setPointer((ICASTPointer)ptrs[0]);
|
||||
} else {
|
||||
CPointerType tempType = new CPointerType();
|
||||
pointerType.setType(tempType);
|
||||
pointerType.setPointer((ICASTPointer)ptrs[ptrs.length - 1]);
|
||||
int i = ptrs.length - 2;
|
||||
for (; i > 0; i--) {
|
||||
tempType.setType(new CPointerType());
|
||||
tempType.setPointer((ICASTPointer)ptrs[i]);
|
||||
tempType = (CPointerType)tempType.getType();
|
||||
}
|
||||
tempType.setType(lastType);
|
||||
tempType.setPointer((ICASTPointer)ptrs[i]);
|
||||
}
|
||||
|
||||
return pointerType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue