diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IArrayType.java index c73ccf59f35..15a4d76ce25 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IArrayType.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java index 2a714a80409..9eaa3902053 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java index 84120544eb0..b91fc4a52a2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java index 5b303ac55b2..1608775e8f6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java index 9b901195928..40c3bf253c6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPVariable.java index bde0fef6872..6484b4de8a0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPVariable.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java index 665fdc5a370..3401aa5e328 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CArrayType.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java index f7297eff21e..42fcb448eac 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java index 225673774d2..796098ab12b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 50d3b367cb1..1436b49a4e9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -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(); } - - //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; - } - } - - 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; + 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(); + } + + if( definition != null ){ + if( definition instanceof IASTStandardFunctionDeclarator ) + return ((IASTStandardFunctionDeclarator)definition).takesVarArgs(); + return false; + } + + if( declarators != null && declarators.length > 0 ){ + return declarators[0].takesVarArgs(); } - bits |= 2 << 2; return false; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java index 5c9919bcf17..541afb15688 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java index 587b8f4af0f..37a37695e46 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java index 564f064a6a1..e7a1fe29c2f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java @@ -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(); - - IASTSimpleDeclaration simple = (IASTSimpleDeclaration) dtor.getParent(); - IASTDeclSpecifier declSpec = simple.getDeclSpecifier(); - return ( declSpec.getStorageClass() == IASTDeclSpecifier.sc_static ); + return hasStorageClass( 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 ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java index 5decad53230..93251721665 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPArrayType.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java index bbad721ff93..a4c72a402e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java @@ -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,14 +61,71 @@ 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) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName) */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldInstance.java index 1469f44aa63..02fb9e06759 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldInstance.java @@ -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(); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 736589525e8..57e92a7dcf1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -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; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java index e2c26c036a6..ba19fceda15 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java @@ -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(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java index bcea75b440a..c66672da902 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -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,12 +160,30 @@ 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 - return false; + 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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java index c59f768df60..02e82e3930e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java @@ -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 ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java index c1c99d6bd47..171cc070ef8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java @@ -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(); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java index 70783b08276..30a23b1d1b7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java @@ -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() { - // 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.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 ICPPASTTemplateDeclaration && ((ICPPASTTemplateDeclaration)decl).getDeclaration() instanceof IASTFunctionDefinition ) + return true; + + return super.isInline(); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index 46334f2fcc6..afcd4f1cee0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterInstance.java index 1b535fa9f38..0e014036916 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterInstance.java @@ -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; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java index 03b76063cf6..b1b81e7bdc8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java @@ -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 ); + } + } 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 ebf68ca7a32..58fe6474d5f 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 @@ -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; }