1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

add binding interface methods to check storage class & function specifiers on bindings.

add IArrayType.getArraySizeExpression
This commit is contained in:
Andrew Niefer 2005-04-15 21:16:44 +00:00
parent 6fcccd4495
commit 1e45251b74
26 changed files with 1073 additions and 65 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* Copyright (c) 2004, 2005 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
@ -24,4 +24,11 @@ public interface IArrayType extends IType {
* @throws DOMException
*/
IType getType() throws DOMException;
/**
* get the expression that represents the size of this array
* @return
* @throws DOMException
*/
IASTExpression getArraySizeExpression() throws DOMException;
}

View file

@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* Copyright (c) 2004, 2005 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
@ -42,5 +42,28 @@ public interface IFunction extends IBinding {
*/
public IFunctionType getType() throws DOMException;
/**
* Does this function have the static storage-class specifier
* similarily for extern, auto, register
* @return
* @throws DOMException
*/
public boolean isStatic() throws DOMException;
public boolean isExtern() throws DOMException;
public boolean isAuto() throws DOMException;
public boolean isRegister() throws DOMException;
/**
* is this function inline
* @return
* @throws DOMException
*/
public boolean isInline() throws DOMException;
/**
* Whether or not this function takes variable arguments
* @return
* @throws DOMException
*/
public boolean takesVarArgs()throws DOMException;
}

View file

@ -22,9 +22,13 @@ public interface IVariable extends IBinding {
/**
* whether or not this is a static variable
* Does this function have the static storage-class specifier
* similarily for extern, auto, register
* @return
* @throws DOMException
*/
public boolean isStatic() throws DOMException;
public boolean isExtern() throws DOMException;
public boolean isAuto() throws DOMException;
public boolean isRegister() throws DOMException;
}

View file

@ -14,6 +14,7 @@
*/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IFunction;
/**
@ -21,4 +22,15 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
*/
public interface ICPPFunction extends IFunction, ICPPBinding {
/**
* does this function have the mutable storage class specifier
* @return
* @throws DOMException
*/
public boolean isMutable() throws DOMException;
/**
* is this an inline function
*/
public boolean isInline() throws DOMException;
}

View file

@ -10,10 +10,18 @@
**********************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
/**
* @author Doug Schaefer
*/
public interface ICPPMethod extends ICPPFunction, ICPPMember {
public static final ICPPMethod [] EMPTY_CPPMETHOD_ARRAY = new ICPPMethod[0];
/**
* is this a virtual method
* @return
* @throws DOMException
*/
public boolean isVirtual() throws DOMException;
}

View file

@ -14,11 +14,17 @@
*/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IVariable;
/**
* @author aniefer
*/
public interface ICPPVariable extends IVariable, ICPPBinding {
/**
* does this variable have the mutable storage class specifier
* @return
* @throws DOMException
*/
public boolean isMutable() throws DOMException;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* Copyright (c) 2004, 2005 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
@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
@ -97,8 +98,8 @@ public class CArrayType implements ICArrayType, ITypeContainer {
* @see org.eclipse.cdt.core.dom.ast.c.ICArrayType#isVariableLength()
*/
public boolean isVariableLength() {
// TODO Auto-generated method stub
return false;
if( mod == null ) return false;
return mod.isVariableSized();
}
public Object clone(){
@ -117,4 +118,13 @@ public class CArrayType implements ICArrayType, ITypeContainer {
public ICASTArrayModifier getModifier() {
return mod;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IArrayType#getArraySizeExpression()
*/
public IASTExpression getArraySizeExpression() {
if( mod != null )
return mod.getConstantExpression();
return null;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* Copyright (c) 2004, 2005 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
@ -87,4 +87,39 @@ public class CExternalFunction implements IFunction, ICExternalBinding {
public boolean isStatic() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
*/
public boolean isExtern() {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
*/
public boolean isAuto() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
*/
public boolean isRegister() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isInline()
*/
public boolean isInline() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs()
*/
public boolean takesVarArgs() {
return false;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* Copyright (c) 2004, 2005 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
@ -69,4 +69,25 @@ public class CExternalVariable implements ICExternalBinding, IVariable {
public boolean isStatic() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
public boolean isExtern() {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
public boolean isAuto() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
public boolean isRegister() {
return false;
}
}

View file

@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2002-2004 IBM Canada and others.
* Copyright (c) 2004, 2005 IBM Canada and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.dom.parser.c;
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.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
@ -42,7 +43,6 @@ public class CFunction implements IFunction, ICInternalBinding {
private static final int FULLY_RESOLVED = 1;
private static final int RESOLUTION_IN_PROGRESS = 1 << 1;
private static final int IS_STATIC = 3 << 2;
private int bits = 0;
IFunctionType type = null;
@ -301,35 +301,112 @@ public class CFunction implements IFunction, ICInternalBinding {
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/
public boolean isStatic() {
return hasStorageClass( IASTDeclSpecifier.sc_static );
}
public boolean hasStorageClass( int storage ){
if( (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
IASTDeclarator dtor = definition;
IASTDeclarator[] ds = declarators;
int i = -1;
do{
if( dtor != null ){
IASTNode parent = dtor.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
IASTDeclSpecifier declSpec = null;
if( parent instanceof IASTSimpleDeclaration ){
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
} else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage )
return true;
}
if( ds != null && ++i < ds.length )
dtor = ds[i];
else
break;
} while( dtor != null );
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
*/
public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
*/
public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
*/
public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isInline()
*/
public boolean isInline() {
if( (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
IASTDeclarator dtor = definition;
IASTDeclarator[] ds = declarators;
int i = -1;
do{
if( dtor != null ){
IASTNode parent = dtor.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
IASTDeclSpecifier declSpec = null;
if( parent instanceof IASTSimpleDeclaration ){
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
} else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.isInline() )
return true;
}
if( ds != null && ++i < ds.length )
dtor = ds[i];
else
break;
} while( dtor != null );
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs()
*/
public boolean takesVarArgs() {
if( (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
//2 state bits, most significant = whether or not we've figure this out yet
//least significant = whether or not we are static
int state = ( bits & IS_STATIC ) >> 2;
if( state > 1 ) return (state % 2 != 0);
IASTFunctionDeclarator dtor = definition;
IASTDeclSpecifier declSpec = null;
if( dtor != null ){
declSpec = ((IASTFunctionDefinition)dtor.getParent()).getDeclSpecifier();
if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_static ){
bits |= 3 << 2;
return true;
}
if( definition != null ){
if( definition instanceof IASTStandardFunctionDeclarator )
return ((IASTStandardFunctionDeclarator)definition).takesVarArgs();
return false;
}
for( int i = 0; i < declarators.length; i++ ){
IASTNode parent = declarators[i].getParent();
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_static ){
bits |= 3 << 2;
return true;
if( declarators != null && declarators.length > 0 ){
return declarators[0].takesVarArgs();
}
}
bits |= 2 << 2;
return false;
}
}

View file

@ -89,4 +89,28 @@ public class CKnRParameter implements IParameter {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
public boolean isExtern() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
public boolean isAuto() {
if( declaration instanceof IASTSimpleDeclaration )
return ((IASTSimpleDeclaration)declaration).getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_auto;
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
public boolean isRegister() {
if( declaration instanceof IASTSimpleDeclaration )
return ((IASTSimpleDeclaration)declaration).getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_register;
return false;
}
}

View file

@ -1,6 +1,6 @@
/**********************************************************************
* Copyright (c) 2002-2004 IBM Canada and others.
* Copyright (c) 2004, 2005 IBM Canada and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@ -13,11 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
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.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
@ -34,14 +37,21 @@ public class CParameter implements IParameter {
public CParameterProblem( IASTNode node, int id, char[] arg ) {
super( node, id, arg );
}
public IType getType() throws DOMException {
throw new DOMException( this );
}
public boolean isStatic() throws DOMException {
throw new DOMException( this );
}
public boolean isExtern() throws DOMException {
throw new DOMException( this );
}
public boolean isAuto() throws DOMException {
throw new DOMException( this );
}
public boolean isRegister() throws DOMException {
throw new DOMException( this );
}
}
private IASTName [] declarations;
@ -109,4 +119,41 @@ public class CParameter implements IParameter {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
public boolean isExtern() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register );
}
public boolean hasStorageClass( int storage ){
if( declarations == null )
return false;
for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){
IASTNode parent = declarations[i].getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
if( parent instanceof IASTSimpleDeclaration ){
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage )
return true;
}
}
return false;
}
}

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -39,7 +40,15 @@ public class CVariable implements IVariable, ICInternalBinding {
public boolean isStatic() throws DOMException {
throw new DOMException( this );
}
public boolean isExtern() throws DOMException {
throw new DOMException( this );
}
public boolean isAuto() throws DOMException {
throw new DOMException( this );
}
public boolean isRegister() throws DOMException {
throw new DOMException( this );
}
}
private IASTName [] declarations = null;
private IType type = null;
@ -84,12 +93,41 @@ public class CVariable implements IVariable, ICInternalBinding {
* @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic()
*/
public boolean isStatic() {
IASTDeclarator dtor = (IASTDeclarator) declarations[0].getParent();
while( dtor.getParent() instanceof IASTDeclarator )
dtor = (IASTDeclarator) dtor.getParent();
return hasStorageClass( IASTDeclSpecifier.sc_static );
}
IASTSimpleDeclaration simple = (IASTSimpleDeclaration) dtor.getParent();
IASTDeclSpecifier declSpec = simple.getDeclSpecifier();
return ( declSpec.getStorageClass() == IASTDeclSpecifier.sc_static );
public boolean hasStorageClass( int storage ){
if( declarations == null )
return false;
for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){
IASTNode parent = declarations[i].getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
if( parent instanceof IASTSimpleDeclaration ){
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage )
return true;
}
}
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register );
}
}

View file

@ -15,6 +15,7 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
@ -24,11 +25,17 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
*/
public class CPPArrayType implements IArrayType, ITypeContainer {
private IType type = null;
private IASTExpression sizeExpression = null;
public CPPArrayType( IType type ){
this.type = type;
}
public CPPArrayType( IType type, IASTExpression sizeExp ){
this.type = type;
this.sizeExpression = sizeExp;
}
public IType getType(){
return type;
}
@ -57,4 +64,11 @@ public class CPPArrayType implements IArrayType, ITypeContainer {
}
return t;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IArrayType#getArraySizeExpression()
*/
public IASTExpression getArraySizeExpression() {
return sizeExpression;
}
}

View file

@ -14,10 +14,19 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
/**
* @author aniefer
@ -52,12 +61,69 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBind
super( name );
}
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
//first check if we already know it
IASTName [] declarations = (IASTName[]) getDeclarations();
if( declarations != null ){
for( int i = 0; i < declarations.length; i++ ){
IASTDeclaration decl = (IASTDeclaration) declarations[i].getParent();
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
return decl;
}
}
char [] myName = getNameCharArray();
ICPPClassScope scope = (ICPPClassScope) getScope();
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) scope.getPhysicalNode();
IASTDeclaration [] members = compSpec.getMembers();
for( int i = 0; i < members.length; i++ ){
if( members[i] instanceof IASTSimpleDeclaration ){
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators();
for( int j = 0; j < dtors.length; j++ ){
IASTName name = dtors[j].getName();
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
return members[i];
}
}
}
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility()
*/
public int getVisibility() {
// TODO Auto-generated method stub
return 0;
public int getVisibility() throws DOMException {
IASTDeclaration decl = getPrimaryDeclaration();
IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent();
IASTDeclaration [] members = cls.getMembers();
ICPPASTVisiblityLabel vis = null;
for( int i = 0; i < members.length; i++ ){
if( members[i] instanceof ICPPASTVisiblityLabel )
vis = (ICPPASTVisiblityLabel) members[i];
else if( members[i] == decl )
break;
}
if( vis != null ){
return vis.getVisibility();
} else if( cls.getKey() == ICPPASTCompositeTypeSpecifier.k_class ){
return ICPPASTVisiblityLabel.v_private;
}
return ICPPASTVisiblityLabel.v_public;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable()
*/
public boolean isMutable() {
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable );
}
public boolean isExtern() {
//7.1.1-5 The extern specifier can not be used in the declaration of class members
return false;
}
/* (non-Javadoc)

View file

@ -90,4 +90,32 @@ public class CPPFieldInstance extends CPPInstance implements ICPPField {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
public boolean isExtern() throws DOMException {
return ((ICPPField)getOriginalBinding()).isExtern();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
public boolean isAuto() throws DOMException {
return ((ICPPField)getOriginalBinding()).isAuto();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
public boolean isRegister() throws DOMException {
return ((ICPPField)getOriginalBinding()).isRegister();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable()
*/
public boolean isMutable() throws DOMException {
return ((ICPPField)getOriginalBinding()).isMutable();
}
}

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
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.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
@ -61,6 +62,24 @@ public class CPPFunction implements ICPPFunction, ICPPInternalBinding {
public boolean isStatic() throws DOMException {
return ((ICPPFunction)getBinding()).isStatic();
}
public boolean isMutable() throws DOMException {
return ((ICPPFunction)getBinding()).isMutable();
}
public boolean isInline() throws DOMException {
return ((ICPPFunction)getBinding()).isInline();
}
public boolean isExtern() throws DOMException {
return ((ICPPFunction)getBinding()).isExtern();
}
public boolean isAuto() throws DOMException {
return ((ICPPFunction)getBinding()).isAuto();
}
public boolean isRegister() throws DOMException {
return ((ICPPFunction)getBinding()).isRegister();
}
public boolean takesVarArgs() throws DOMException {
return ((ICPPFunction)getBinding()).takesVarArgs();
}
}
public static class CPPFunctionProblem extends ProblemBinding implements ICPPFunction {
public CPPFunctionProblem( IASTNode node, int id, char[] arg ) {
@ -78,7 +97,6 @@ public class CPPFunction implements ICPPFunction, ICPPInternalBinding {
public IFunctionType getType() throws DOMException {
throw new DOMException( this );
}
public boolean isStatic() throws DOMException {
throw new DOMException( this );
}
@ -91,6 +109,24 @@ public class CPPFunction implements ICPPFunction, ICPPInternalBinding {
public boolean isGloballyQualified() throws DOMException {
throw new DOMException( this );
}
public boolean isMutable() throws DOMException {
throw new DOMException( this );
}
public boolean isInline() throws DOMException {
throw new DOMException( this );
}
public boolean isExtern() throws DOMException {
throw new DOMException( this );
}
public boolean isAuto() throws DOMException {
throw new DOMException( this );
}
public boolean isRegister() throws DOMException {
throw new DOMException( this );
}
public boolean takesVarArgs() throws DOMException {
throw new DOMException( this );
}
}
protected ICPPASTFunctionDeclarator [] declarations;
@ -417,4 +453,103 @@ public class CPPFunction implements ICPPFunction, ICPPInternalBinding {
return new CPPFunctionDelegate( name, this );
}
public boolean hasStorageClass( int storage ){
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) getDefinition();
ICPPASTFunctionDeclarator[] ds = (ICPPASTFunctionDeclarator[]) getDeclarations();
int i = -1;
do{
if( dtor != null ){
IASTNode parent = dtor.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
IASTDeclSpecifier declSpec = null;
if( parent instanceof IASTSimpleDeclaration )
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage )
return true;
}
if( ds != null && ++i < ds.length )
dtor = ds[i];
else
break;
} while( dtor != null );
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
*/
public boolean isMutable() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline()
*/
public boolean isInline() throws DOMException {
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) getDefinition();
ICPPASTFunctionDeclarator[] ds = (ICPPASTFunctionDeclarator[]) getDeclarations();
int i = -1;
do{
if( dtor != null ){
IASTNode parent = dtor.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
IASTDeclSpecifier declSpec = null;
if( parent instanceof IASTSimpleDeclaration )
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.isInline() )
return true;
}
if( ds != null && ++i < ds.length )
dtor = ds[i];
else
break;
} while( dtor != null );
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
*/
public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
*/
public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
*/
public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs()
*/
public boolean takesVarArgs() {
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) getDefinition();
if( dtor != null ){
return dtor.takesVarArgs();
}
ICPPASTFunctionDeclarator [] ds = (ICPPASTFunctionDeclarator[]) getDeclarations();
if( ds != null && ds.length > 0 ){
return ds[0].takesVarArgs();
}
return false;
}
}

View file

@ -100,9 +100,8 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/
public boolean isStatic() {
// TODO Auto-generated method stub
return false;
public boolean isStatic() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isStatic();
}
/* (non-Javadoc)
@ -128,4 +127,46 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
*/
public boolean isMutable() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isMutable();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline()
*/
public boolean isInline() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isInline();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
*/
public boolean isExtern() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isExtern();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
*/
public boolean isAuto() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isAuto();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
*/
public boolean isRegister() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isRegister();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs()
*/
public boolean takesVarArgs() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).takesVarArgs();
}
}

View file

@ -13,15 +13,21 @@
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
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.IASTFunctionDefinition;
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.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
@ -154,11 +160,29 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
return type;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/
public boolean isStatic() {
// TODO Auto-generated method stub
public boolean hasStorageClass( int storage ){
IASTName name = (IASTName) getDefinition();
IASTNode[] ns = getDeclarations();
int i = -1;
do{
if( name != null ){
IASTNode parent = name.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
IASTDeclSpecifier declSpec = null;
if( parent instanceof IASTSimpleDeclaration )
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage )
return true;
}
if( ns != null && ++i < ns.length )
name = (IASTName) ns[i];
else
break;
} while( name != null );
return false;
}
@ -205,6 +229,88 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
}
}
return binding; }
return binding;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/
public boolean isStatic() {
return hasStorageClass( IASTDeclSpecifier.sc_static );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
*/
public boolean isMutable() {
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline()
*/
public boolean isInline() throws DOMException {
IASTName name = (IASTName) getDefinition();
IASTNode[] ns = getDeclarations();
int i = -1;
do{
if( name != null ){
IASTNode parent = name.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
IASTDeclSpecifier declSpec = null;
if( parent instanceof IASTSimpleDeclaration )
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.isInline() )
return true;
}
if( ns != null && ++i < ns.length )
name = (IASTName) ns[i];
else
break;
} while( name != null );
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
*/
public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
*/
public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
*/
public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs()
*/
public boolean takesVarArgs() {
IASTName name = (IASTName) getDefinition();
if( name != null ){
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) name.getParent();
return dtor.takesVarArgs();
}
IASTName [] ns = (IASTName[]) getDeclarations();
if( ns != null && ns.length > 0 ){
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) ns[0].getParent();
return dtor.takesVarArgs();
}
return false;
}
}

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
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.IASTFunctionDefinition;
@ -23,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
@ -42,6 +44,9 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
public int getVisibility() throws DOMException {
return ((ICPPMethod)getBinding()).getVisibility();
}
public boolean isVirtual() throws DOMException {
return ((ICPPMethod)getBinding()).isVirtual();
}
}
public static class CPPMethodProblem extends CPPFunctionProblem implements ICPPMethod {
@ -59,6 +64,9 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
public boolean isStatic() throws DOMException {
throw new DOMException( this );
}
public boolean isVirtual() throws DOMException {
throw new DOMException( this );
}
}
public CPPMethod( ICPPASTFunctionDeclarator declarator ){
@ -163,4 +171,30 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
return new CPPMethodDelegate( name, this );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual()
*/
public boolean isVirtual() throws DOMException {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline()
*/
public boolean isInline() throws DOMException {
IASTDeclaration decl = getPrimaryDeclaration();
if( decl instanceof IASTFunctionDefinition )
return true;
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)decl).getDeclSpecifier();
return declSpec.isInline();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
*/
public boolean isMutable() {
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable );
}
}

View file

@ -13,6 +13,7 @@
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
@ -42,4 +43,11 @@ public class CPPMethodInstance extends CPPFunctionInstance implements
return 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual()
*/
public boolean isVirtual() throws DOMException {
return ((ICPPMethod)getOriginalBinding()).isVirtual();
}
}

View file

@ -13,8 +13,22 @@
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
/**
* @author aniefer
@ -27,15 +41,96 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
*/
public CPPMethodTemplate(IASTName name) {
super(name);
// TODO Auto-generated constructor stub
}
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
//first check if we already know it
if( declarations != null ){
for( int i = 0; i < declarations.length; i++ ){
IASTNode parent = declarations[i].getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
IASTDeclaration decl = (IASTDeclaration) parent.getParent();
if( decl instanceof ICPPASTCompositeTypeSpecifier )
return decl;
}
}
char [] myName = getNameCharArray();
IScope scope = getScope();
if( scope instanceof ICPPTemplateScope )
scope = scope.getParent();
ICPPClassScope clsScope = (ICPPClassScope) scope;
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) clsScope.getPhysicalNode();
IASTDeclaration [] members = compSpec.getMembers();
for( int i = 0; i < members.length; i++ ){
if( members[i] instanceof ICPPASTTemplateDeclaration ){
IASTDeclaration decl = ((ICPPASTTemplateDeclaration)members[i]).getDeclaration();
if( decl instanceof IASTSimpleDeclaration ){
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
for( int j = 0; j < dtors.length; j++ ){
IASTName name = CPPVisitor.getMostNestedDeclarator( dtors[j] ).getName();
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
return members[i];
}
}
} else if( decl instanceof IASTFunctionDefinition ){
IASTName name = CPPVisitor.getMostNestedDeclarator( ((IASTFunctionDefinition) decl).getDeclarator() ).getName();
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
return members[i];
}
}
}
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility()
*/
public int getVisibility() {
public int getVisibility() throws DOMException {
IASTDeclaration decl = getPrimaryDeclaration();
IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent();
IASTDeclaration [] members = cls.getMembers();
ICPPASTVisiblityLabel vis = null;
for( int i = 0; i < members.length; i++ ){
if( members[i] instanceof ICPPASTVisiblityLabel )
vis = (ICPPASTVisiblityLabel) members[i];
else if( members[i] == decl )
break;
}
if( vis != null ){
return vis.getVisibility();
} else if( cls.getKey() == ICPPASTCompositeTypeSpecifier.k_class ){
return ICPPASTVisiblityLabel.v_private;
}
return ICPPASTVisiblityLabel.v_public;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual()
*/
public boolean isVirtual() throws DOMException {
// TODO Auto-generated method stub
return 0;
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline()
*/
public boolean isInline() throws DOMException {
IASTDeclaration decl = getPrimaryDeclaration();
if( decl instanceof ICPPASTTemplateDeclaration && ((ICPPASTTemplateDeclaration)decl).getDeclaration() instanceof IASTFunctionDefinition )
return true;
return super.isInline();
}
}

View file

@ -14,11 +14,13 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
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.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
@ -40,6 +42,18 @@ public class CPPParameter implements IParameter, ICPPInternalBinding, ICPPVariab
public boolean isStatic() throws DOMException {
return ((IParameter)getBinding()).isStatic();
}
public boolean isExtern() {
return false;
}
public boolean isAuto() throws DOMException {
return ((IParameter)getBinding()).isAuto();
}
public boolean isRegister() throws DOMException {
return ((IParameter)getBinding()).isRegister();
}
public boolean isMutable() {
return false;
}
}
private IType type = null;
@ -181,4 +195,53 @@ public class CPPParameter implements IParameter, ICPPInternalBinding, ICPPVariab
public void addDefinition(IASTNode node) {
addDeclaration( node );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
public boolean isExtern() {
//7.1.1-5 extern can not be used in the declaration of a parameter
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable()
*/
public boolean isMutable() {
//7.1.1-8 mutable can only apply to class members
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register );
}
public boolean hasStorageClass( int storage ){
IASTNode[] ns = getDeclarations();
if( ns == null )
return false;
for( int i = 0; i < ns.length && ns[i] != null; i++ ){
IASTNode parent = ns[i].getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
if( parent instanceof IASTSimpleDeclaration ){
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage )
return true;
}
}
return false;
}
}

View file

@ -103,4 +103,32 @@ public class CPPParameterInstance extends CPPInstance implements IParameter,
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
public boolean isExtern() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
public boolean isAuto() throws DOMException {
return ((IParameter)getOriginalBinding()).isAuto();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
public boolean isRegister() throws DOMException {
return ((IParameter)getOriginalBinding()).isRegister();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable()
*/
public boolean isMutable() {
return false;
}
}

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -44,6 +45,18 @@ public class CPPVariable implements ICPPVariable, ICPPInternalBinding {
public boolean isStatic() throws DOMException {
return ((ICPPVariable)getBinding()).isStatic();
}
public boolean isMutable() throws DOMException {
return ((ICPPVariable)getBinding()).isMutable();
}
public boolean isExtern() throws DOMException {
return ((ICPPVariable)getBinding()).isExtern();
}
public boolean isAuto() throws DOMException {
return ((ICPPVariable)getBinding()).isAuto();
}
public boolean isRegister() throws DOMException {
return ((ICPPVariable)getBinding()).isRegister();
}
}
public static class CPPVariableProblem extends ProblemBinding implements ICPPVariable{
public CPPVariableProblem( IASTNode node, int id, char[] arg ) {
@ -66,6 +79,18 @@ public class CPPVariable implements ICPPVariable, ICPPInternalBinding {
public boolean isGloballyQualified() throws DOMException {
throw new DOMException( this );
}
public boolean isMutable() throws DOMException {
throw new DOMException( this );
}
public boolean isExtern() throws DOMException {
throw new DOMException( this );
}
public boolean isAuto() throws DOMException {
throw new DOMException( this );
}
public boolean isRegister() throws DOMException {
throw new DOMException( this );
}
}
private IASTName declarations[] = null;
private IASTName definition = null;
@ -262,4 +287,57 @@ public class CPPVariable implements ICPPVariable, ICPPInternalBinding {
addDeclaration( node );
}
public boolean hasStorageClass( int storage ){
IASTName name = (IASTName) getDefinition();
IASTNode[] ns = getDeclarations();
int i = -1;
do{
if( name != null ){
IASTNode parent = name.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
if( parent instanceof IASTSimpleDeclaration ){
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage )
return true;
}
}
if( ns != null && ++i < ns.length )
name = (IASTName) ns[i];
else
break;
} while( name != null );
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable()
*/
public boolean isMutable() {
//7.1.1-8 the mutable specifier can only be applied to names of class data members
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register );
}
}

View file

@ -1337,7 +1337,7 @@ public class CPPVisitor {
private static IType getArrayTypes( IType type, IASTArrayDeclarator declarator ){
IASTArrayModifier [] mods = declarator.getArrayModifiers();
for( int i = 0; i < mods.length; i++ ){
type = new CPPArrayType( type );
type = new CPPArrayType( type, mods[i].getConstantExpression() );
}
return type;
}