1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-15 20:25:46 +02:00

Static variables/functions declared in headers, bug 180305.

This commit is contained in:
Markus Schorn 2007-11-22 13:10:49 +00:00
parent a6d8d84032
commit 01e130423b
30 changed files with 464 additions and 158 deletions

View file

@ -1090,4 +1090,89 @@ public class IndexBugsTests extends BaseTestCase {
IFunctionType ft= ((IFunction) bindings[0]).getType(); IFunctionType ft= ((IFunction) bindings[0]).getType();
assertEquals("void (long long)", ASTTypeUtil.getType(ft)); assertEquals("void (long long)", ASTTypeUtil.getType(ft));
} }
// static inline void staticInHeader() {};
// #include "header.h"
// void f1() {
// staticInHeader();
// }
public void testStaticFunctionsInHeader_Bug180305() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "source1.cpp", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "source2.cpp", contents[1].toString());
indexManager.reindex(fCProject);
waitForIndexer();
IIndexBinding[] bindings= fIndex.findBindings("staticInHeader".toCharArray(), IndexFilter.ALL, NPM);
IFunction func= (IFunction) bindings[0];
assertTrue(func.isStatic());
IIndexName[] refs= fIndex.findReferences(func);
assertEquals(2, refs.length);
}
// static const int staticConstInHeader= 12;
// #include "header.h"
// void f1() {
// int a= staticConstInHeader;
// }
public void testStaticVariableInHeader_Bug180305() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "source1.cpp", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "source2.cpp", contents[1].toString());
indexManager.reindex(fCProject);
waitForIndexer();
IIndexBinding[] bindings= fIndex.findBindings("staticConstInHeader".toCharArray(), IndexFilter.ALL, NPM);
IVariable var= (IVariable) bindings[0];
assertTrue(var.isStatic());
IIndexName[] refs= fIndex.findReferences(var);
assertEquals(2, refs.length);
}
// static inline void staticInHeader() {};
// #include "header.h"
// void f1() {
// staticInHeader();
// }
public void testStaticFunctionsInHeaderC_Bug180305() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "source1.c", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "source2.c", contents[1].toString());
indexManager.reindex(fCProject);
waitForIndexer();
IIndexBinding[] bindings= fIndex.findBindings("staticInHeader".toCharArray(), IndexFilter.ALL, NPM);
IFunction func= (IFunction) bindings[0];
assertTrue(func.isStatic());
IIndexName[] refs= fIndex.findReferences(func);
assertEquals(2, refs.length);
}
// static const int staticConstInHeader= 12;
// #include "header.h"
// void f1() {
// int a= staticConstInHeader;
// }
public void testStaticVariableInHeaderC_Bug180305() throws Exception {
StringBuffer[] contents= getContentsForTest(2);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
TestSourceReader.createFile(fCProject.getProject(), "header.h", contents[0].toString());
TestSourceReader.createFile(fCProject.getProject(), "source1.c", contents[1].toString());
TestSourceReader.createFile(fCProject.getProject(), "source2.c", contents[1].toString());
indexManager.reindex(fCProject);
waitForIndexer();
IIndexBinding[] bindings= fIndex.findBindings("staticConstInHeader".toCharArray(), IndexFilter.ALL, NPM);
IVariable var= (IVariable) bindings[0];
assertTrue(var.isStatic());
IIndexName[] refs= fIndex.findReferences(var);
assertEquals(2, refs.length);
}
} }

View file

@ -766,6 +766,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
ILanguage language= configureWith.getLanguage(); ILanguage language= configureWith.getLanguage();
fLanguageOfContext= language; fLanguageOfContext= language;
if (language != null) { if (language != null) {
IASTTranslationUnit ast= null;
if (language instanceof AbstractLanguage) { if (language instanceof AbstractLanguage) {
int options= 0; int options= 0;
if ((style & AST_SKIP_FUNCTION_BODIES) != 0) { if ((style & AST_SKIP_FUNCTION_BODIES) != 0) {
@ -774,9 +775,15 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
if ((style & AST_CREATE_COMMENT_NODES) != 0) { if ((style & AST_CREATE_COMMENT_NODES) != 0) {
options |= AbstractLanguage.OPTION_ADD_COMMENTS; options |= AbstractLanguage.OPTION_ADD_COMMENTS;
} }
return ((AbstractLanguage)language).getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, options, ParserUtil.getParserLogService()); ast= ((AbstractLanguage)language).getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, options, ParserUtil.getParserLogService());
} }
return language.getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, ParserUtil.getParserLogService()); else {
ast= language.getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, ParserUtil.getParserLogService());
}
if (ast != null) {
ast.setIsHeaderUnit(isHeaderUnit());
}
return ast;
} }
} }
return null; return null;

View file

@ -1,13 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2006 IBM Corporation and others. * Copyright (c) 2004, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
@ -32,7 +32,7 @@ public interface IASTNode {
/** /**
* Get the location of this node. In cases not involving macro expansions, * Get the location of this node. In cases not involving macro expansions,
* the IASTNodeLocation [] result will only have one element in it, and it * the IASTNodeLocation [] result will only have one element in it, and it
* will be an IASTFileLocation or subinterface. * will be an IASTFileLocation or sub-interface.
* *
* Where the node is completely generated within a macro expansion, * Where the node is completely generated within a macro expansion,
* IASTNodeLocation [] result will have one element in it, and it will be an * IASTNodeLocation [] result will have one element in it, and it will be an
@ -65,6 +65,12 @@ public interface IASTNode {
*/ */
public String getContainingFilename(); public String getContainingFilename();
/**
* Lightweight check to see whether this node is part of the root file.
* @since 5.0
*/
public boolean isPartOfTranslationUnitFile();
/** /**
* Get the parent node of this node in the tree. * Get the parent node of this node in the tree.
* *
@ -96,7 +102,7 @@ public interface IASTNode {
public void setPropertyInParent(ASTNodeProperty property); public void setPropertyInParent(ASTNodeProperty property);
/** /**
* Abstract method to be overriden by all subclasses. Necessary for * Abstract method to be overridden by all subclasses. Necessary for
* visitation of the tree using an <code>ASTVisitor</code>. * visitation of the tree using an <code>ASTVisitor</code>.
* *
* @param visitor * @param visitor
@ -116,7 +122,7 @@ public interface IASTNode {
/** /**
* Returns whether this node contains the given one. The decision is made * Returns whether this node contains the given one. The decision is made
* purly on location information and therefore the method is fast. * purely on location information and therefore the method is fast.
* @param node the node to check * @param node the node to check
* @return whether this node contains the given one. * @return whether this node contains the given one.
* @since 4.0 * @since 4.0

View file

@ -11,6 +11,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -261,5 +262,20 @@ public interface IASTTranslationUnit extends IASTNode, IAdaptable {
* @since 4.0 * @since 4.0
*/ */
public IASTComment[] getComments(); public IASTComment[] getComments();
/**
* Returns the linkage this ast was parsed in
*/
public ILinkage getLinkage();
/**
* Returns whether this ast represents a header file.
*/
public boolean isHeaderUnit();
/**
* Sets whether this ast represents a header file.
*/
public void setIsHeaderUnit(boolean headerUnit);
} }

View file

@ -17,8 +17,12 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalFunction;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalVariable;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalVariable;
/** /**
* Access to methods on scopes and bindings internal to the parser. * Access to methods on scopes and bindings internal to the parser.
@ -78,10 +82,23 @@ public class ASTInternal {
} }
} }
public static boolean isStatic(IFunction func, boolean resolveAll) throws DOMException { public static boolean isStatic(IFunction func, boolean resolveAll, boolean checkHeaders) throws DOMException {
if (func instanceof ICPPInternalFunction) { if (func instanceof ICPPInternalFunction) {
return ((ICPPInternalFunction)func).isStatic(resolveAll); return ((ICPPInternalFunction)func).isStatic(resolveAll, checkHeaders);
}
if (func instanceof ICInternalFunction) {
return ((ICInternalFunction) func).isStatic(resolveAll, checkHeaders);
} }
return func.isStatic(); return func.isStatic();
} }
public static boolean isStatic(IVariable var, boolean checkHeaders) throws DOMException {
if (var instanceof ICPPInternalVariable) {
return ((ICPPInternalVariable)var).isStatic(checkHeaders);
}
if (var instanceof ICInternalVariable) {
return ((ICInternalVariable)var).isStatic(checkHeaders);
}
return var.isStatic();
}
} }

View file

@ -159,6 +159,17 @@ public abstract class ASTNode implements IASTNode {
return fileLocation; return fileLocation;
} }
public boolean isPartOfTranslationUnitFile() {
IASTTranslationUnit ast = getTranslationUnit();
if (ast != null) {
ILocationResolver lr= (ILocationResolver) ast.getAdapter(ILocationResolver.class);
if (lr != null) {
return lr.isPartOfTranslationUnitFile(offset);
}
}
return false;
}
public IASTTranslationUnit getTranslationUnit() { public IASTTranslationUnit getTranslationUnit() {
return parent != null ? parent.getTranslationUnit() : null; return parent != null ? parent.getTranslationUnit() : null;
} }

View file

@ -13,6 +13,7 @@
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
@ -45,6 +46,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTComment; import org.eclipse.cdt.internal.core.dom.parser.ASTComment;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult; import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
@ -83,7 +85,8 @@ public class CASTTranslationUnit extends CASTNode implements
private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0]; private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
private IASTComment[] comments = new ASTComment[0]; private IASTComment[] comments = new ASTComment[0];
private boolean fIsHeader;
public IASTTranslationUnit getTranslationUnit() { public IASTTranslationUnit getTranslationUnit() {
return this; return this;
@ -614,4 +617,16 @@ public class CASTTranslationUnit extends CASTNode implements
} }
return null; return null;
} }
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
public boolean isHeaderUnit() {
return fIsHeader;
}
public void setIsHeaderUnit(boolean headerUnit) {
fIsHeader= headerUnit;
}
} }

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -335,18 +335,31 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic() * @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/ */
public boolean isStatic() { public boolean isStatic() {
return hasStorageClass( IASTDeclSpecifier.sc_static ); return isStatic(true, true);
} }
public boolean hasStorageClass( int storage ){ public boolean isStatic(boolean resolveAll, boolean checkHeaders) {
if( (bits & FULLY_RESOLVED) == 0 ){ if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations(); resolveAllDeclarations();
} }
return hasStorageClass( IASTDeclSpecifier.sc_static, checkHeaders );
}
public boolean hasStorageClass( int storage, boolean checkHeaders){
IASTDeclarator dtor = definition; IASTDeclarator dtor = definition;
IASTDeclarator[] ds = declarators; IASTDeclarator[] ds = declarators;
boolean useDeclsInRoot= checkHeaders;
int i = -1; int i = -1;
do{ do{
if( dtor != null ){ if( dtor != null ){
if (!useDeclsInRoot) {
if (dtor.getTranslationUnit().isHeaderUnit()) {
return false;
}
useDeclsInRoot= true;
}
IASTNode parent = dtor.getParent(); IASTNode parent = dtor.getParent();
while( !(parent instanceof IASTDeclaration) ) while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent(); parent = parent.getParent();
@ -357,8 +370,11 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
} else if( parent instanceof IASTFunctionDefinition ) } else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage ) if( declSpec.getStorageClass() == storage ) {
return true; if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
return true;
}
}
} }
if( ds != null && ++i < ds.length ) if( ds != null && ++i < ds.length )
@ -373,21 +389,34 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
*/ */
public boolean isExtern() { public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern ); return isExtern(true);
}
public boolean isExtern(boolean resolveAll) {
if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto() * @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
*/ */
public boolean isAuto() { public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto ); if( (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
return hasStorageClass( IASTDeclSpecifier.sc_auto, true);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister() * @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
*/ */
public boolean isRegister() { public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register ); if( (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
return hasStorageClass( IASTDeclSpecifier.sc_register, true);
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1,13 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2006 IBM Corporation and others. * Copyright (c) 2005, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -32,7 +32,7 @@ import org.eclipse.core.runtime.PlatformObject;
* Created on Nov 5, 2004 * Created on Nov 5, 2004
* @author aniefer * @author aniefer
*/ */
public class CVariable extends PlatformObject implements IVariable, ICInternalBinding { public class CVariable extends PlatformObject implements IVariable, ICInternalVariable {
public static class CVariableProblem extends ProblemBinding implements IVariable { public static class CVariableProblem extends ProblemBinding implements IVariable {
public CVariableProblem( IASTNode node, int id, char[] arg ) { public CVariableProblem( IASTNode node, int id, char[] arg ) {
super( node, id, arg ); super( node, id, arg );
@ -93,25 +93,40 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalBi
IASTDeclarator declarator = (IASTDeclarator) declarations[0].getParent(); IASTDeclarator declarator = (IASTDeclarator) declarations[0].getParent();
return CVisitor.getContainingScope( declarator.getParent() ); return CVisitor.getContainingScope( declarator.getParent() );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic() public boolean isStatic(boolean checkHeaders) {
*/ return hasStorageClass(IASTDeclSpecifier.sc_static, checkHeaders);
public boolean isStatic() { }
return hasStorageClass( IASTDeclSpecifier.sc_static );
} public boolean isStatic() {
return isStatic(true);
public boolean hasStorageClass( int storage ){ }
public boolean hasStorageClass( int storage, boolean checkHeaders){
if( declarations == null ) if( declarations == null )
return false; return false;
boolean useDeclsInRoot= checkHeaders;
for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){ for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){
IASTNode parent = declarations[i].getParent(); final IASTName name = declarations[i];
if (!useDeclsInRoot) {
if (name.getTranslationUnit().isHeaderUnit()) {
return false;
}
useDeclsInRoot= true;
}
IASTNode parent = name.getParent();
while( !(parent instanceof IASTDeclaration) ) while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent(); parent = parent.getParent();
if( parent instanceof IASTSimpleDeclaration ){ if( parent instanceof IASTSimpleDeclaration ){
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage ) if( declSpec.getStorageClass() == storage ) {
return true; if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
return true;
}
}
} }
} }
return false; return false;
@ -120,19 +135,19 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalBi
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern() * @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/ */
public boolean isExtern() { public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern ); return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto() * @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/ */
public boolean isAuto() { public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto ); return hasStorageClass( IASTDeclSpecifier.sc_auto, true);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister() * @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/ */
public boolean isRegister() { public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register ); return hasStorageClass( IASTDeclSpecifier.sc_register, true);
} }
public ILinkage getLinkage() { public ILinkage getLinkage() {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,21 +7,26 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Jun 6, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
/** /**
* @author aniefer * Interface for ast-internal implementations of function bindings.
*
*/ */
public interface ICInternalFunction extends ICInternalBinding { public interface ICInternalFunction extends ICInternalBinding {
public void setFullyResolved( boolean resolved ); public void setFullyResolved( boolean resolved );
public void addDeclarator( IASTFunctionDeclarator fnDeclarator ); public void addDeclarator( IASTFunctionDeclarator fnDeclarator );
/**
* Returns whether there is a static declaration for this function.
* @param resolveAll checks for names that are not yet resolved to this binding.
* @param checkHeaders if <code>false</code> declarations within header files are not
* considered.
*/
public boolean isStatic(boolean resolveAll, boolean checkHeaders);
} }

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.DOMException;
/**
* Interface for ast-internal implementations of variable bindings.
* @since 5.0
*/
public interface ICInternalVariable extends ICInternalBinding {
/**
* Returns whether there is a static declaration for this variable.
* @param checkHeaders if <code>false</code> declarations within header files are not
* considered.
*/
public boolean isStatic(boolean checkHeaders) throws DOMException;
}

View file

@ -98,6 +98,8 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0]; private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
private IASTComment[] comments = new ASTComment[0]; private IASTComment[] comments = new ASTComment[0];
private boolean fIsHeader;
public IASTTranslationUnit getTranslationUnit() { public IASTTranslationUnit getTranslationUnit() {
return this; return this;
@ -578,4 +580,12 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
} }
return null; return null;
} }
public boolean isHeaderUnit() {
return fIsHeader;
}
public void setIsHeaderUnit(boolean headerUnit) {
fIsHeader= headerUnit;
}
} }

View file

@ -9,9 +9,6 @@
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Apr 14, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
@ -175,9 +172,9 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/ */
public boolean isStatic( boolean resolveAll ) { public boolean isStatic( boolean resolveAll, boolean checkHeaders) {
try { try {
return ASTInternal.isStatic((IFunction) getTemplateDefinition(), resolveAll); return ASTInternal.isStatic((IFunction) getTemplateDefinition(), resolveAll, checkHeaders);
} catch (DOMException e) { } catch (DOMException e) {
return false; return false;
} }

View file

@ -9,9 +9,6 @@
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Nov 29, 2004
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
@ -161,7 +158,7 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBind
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable()
*/ */
public boolean isMutable() { public boolean isMutable() {
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable ); return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable, true);
} }
public boolean isExtern() { public boolean isExtern() {

View file

@ -9,9 +9,6 @@
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Dec 1, 2004
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ILinkage;
@ -86,9 +83,9 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
public boolean takesVarArgs() throws DOMException { public boolean takesVarArgs() throws DOMException {
return ((ICPPFunction)getBinding()).takesVarArgs(); return ((ICPPFunction)getBinding()).takesVarArgs();
} }
public boolean isStatic( boolean resolveAll ) { public boolean isStatic( boolean resolveAll, boolean checkHeaders) {
try { try {
return ASTInternal.isStatic((IFunction) getBinding(), resolveAll); return ASTInternal.isStatic((IFunction) getBinding(), resolveAll, checkHeaders);
} catch (DOMException e) { } catch (DOMException e) {
return false; return false;
} }
@ -429,16 +426,16 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic() * @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/ */
public boolean isStatic( ) { public boolean isStatic( ) {
return isStatic( true ); return isStatic( true, true );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/ */
public boolean isStatic( boolean resolveAll ) { public boolean isStatic( boolean resolveAll, boolean checkHeaders ) {
if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){ if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations(); resolveAllDeclarations();
} }
return hasStorageClass( this, IASTDeclSpecifier.sc_static ); return hasStorageClass( this, IASTDeclSpecifier.sc_static, checkHeaders );
} }
// } // }
// static public boolean isStatic // static public boolean isStatic
@ -507,12 +504,23 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
} }
static public boolean hasStorageClass( ICPPInternalFunction function, int storage ){ static public boolean hasStorageClass( ICPPInternalFunction function, int storage ){
return hasStorageClass(function, storage, true);
}
static public boolean hasStorageClass( ICPPInternalFunction function, int storage, boolean checkHeaders){
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) function.getDefinition(); ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) function.getDefinition();
IASTNode[] ds = function.getDeclarations(); IASTNode[] ds = function.getDeclarations();
boolean useDeclsInRoot= checkHeaders;
int i = -1; int i = -1;
do{ do{
if( dtor != null ){ if( dtor != null ){
if (!useDeclsInRoot) {
if (dtor.getTranslationUnit().isHeaderUnit()) {
return false;
}
useDeclsInRoot= true;
}
IASTNode parent = dtor.getParent(); IASTNode parent = dtor.getParent();
while( !(parent instanceof IASTDeclaration) ) while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent(); parent = parent.getParent();
@ -522,8 +530,11 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
else if( parent instanceof IASTFunctionDefinition ) else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage ) if( declSpec.getStorageClass() == storage ) {
return true; if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
return true;
}
}
} }
if( ds != null && ++i < ds.length ) { if( ds != null && ++i < ds.length ) {
dtor = (ICPPASTFunctionDeclarator) ds[i]; dtor = (ICPPASTFunctionDeclarator) ds[i];

View file

@ -6,12 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Mar 29, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -140,10 +137,10 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/ */
public boolean isStatic( boolean resolveAll ) { public boolean isStatic( boolean resolveAll, boolean checkHeaders ) {
ICPPFunction func = (ICPPFunction) getTemplateDefinition(); ICPPFunction func = (ICPPFunction) getTemplateDefinition();
try { try {
return ASTInternal.isStatic(func, resolveAll); return ASTInternal.isStatic(func, resolveAll, checkHeaders);
} catch (DOMException e) { } catch (DOMException e) {
return false; return false;
} }

View file

@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Bryan Wilkinson (QNX) * Bryan Wilkinson (QNX)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Apr 22, 2005 * Created on Apr 22, 2005
@ -95,19 +96,19 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
return getFunction().isInline(); return getFunction().isInline();
} }
public boolean isStatic() { public boolean isStatic() {
return isStatic( true ); return isStatic(true, true);
} }
public boolean isStatic(boolean resolveAll) { public boolean isStatic(boolean resolveAll, boolean checkHeaders) {
//TODO resolveAll //TODO resolveAll
IBinding f = getSpecializedBinding(); IBinding f = getSpecializedBinding();
if( f instanceof ICPPInternalFunction) if( f instanceof ICPPInternalFunction)
return ((ICPPInternalFunction)f).isStatic( resolveAll ); return ((ICPPInternalFunction)f).isStatic( resolveAll, checkHeaders);
if( f instanceof IIndexBinding && f instanceof ICPPFunction ) { if( f instanceof IIndexBinding && f instanceof ICPPFunction ) {
try { try {
return ((ICPPFunction) f).isStatic(); return ((ICPPFunction) f).isStatic();
} catch(DOMException de) { /* cannot occur as we query the index */} } catch(DOMException de) { /* cannot occur as we query the index */}
} }
return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_static ); return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_static, checkHeaders);
} }
public boolean isExtern() throws DOMException { public boolean isExtern() throws DOMException {

View file

@ -6,12 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Mar 31, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
@ -221,12 +218,20 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
return type; return type;
} }
public boolean hasStorageClass( int storage ){ public boolean hasStorageClass( int storage, boolean checkHeaders){
IASTName name = (IASTName) getDefinition(); IASTName name = (IASTName) getDefinition();
IASTNode[] ns = getDeclarations(); IASTNode[] ns = getDeclarations();
int i = -1; int i = -1;
boolean useDeclsInRoot= checkHeaders;
do{ do{
if( name != null ){ if( name != null ){
if (!useDeclsInRoot) {
if (name.getTranslationUnit().isHeaderUnit()) {
return false;
}
useDeclsInRoot= true;
}
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
while( !(parent instanceof IASTDeclaration) ) while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent(); parent = parent.getParent();
@ -236,8 +241,11 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
else if( parent instanceof IASTFunctionDefinition ) else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier(); declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage ) if( declSpec.getStorageClass() == storage ) {
return true; if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
return true;
}
}
} }
if( ns != null && ++i < ns.length ) if( ns != null && ++i < ns.length )
name = (IASTName) ns[i]; name = (IASTName) ns[i];
@ -310,13 +318,13 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic() * @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/ */
public boolean isStatic() { public boolean isStatic() {
return hasStorageClass( IASTDeclSpecifier.sc_static ); return hasStorageClass( IASTDeclSpecifier.sc_static, true);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
*/ */
public boolean isMutable() { public boolean isMutable() {
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable ); return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable, true);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -353,21 +361,21 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
*/ */
public boolean isExtern() { public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern ); return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto() * @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
*/ */
public boolean isAuto() { public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto ); return hasStorageClass( IASTDeclSpecifier.sc_auto, true );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister() * @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
*/ */
public boolean isRegister() { public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register); return hasStorageClass( IASTDeclSpecifier.sc_register, true);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -404,8 +412,8 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/ */
public boolean isStatic( boolean resolveAll ) { public boolean isStatic( boolean resolveAll, boolean checkHeaders ) {
return hasStorageClass( IASTDeclSpecifier.sc_static ); return hasStorageClass( IASTDeclSpecifier.sc_static, checkHeaders);
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -6,14 +6,11 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Bryan Wilkinson (QNX) * Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Dec 8, 2004
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
@ -1355,7 +1352,7 @@ public class CPPSemantics {
} }
//it is not ambiguous if they are the same thing and it is static or an enumerator //it is not ambiguous if they are the same thing and it is static or an enumerator
if( binding instanceof IEnumerator || if( binding instanceof IEnumerator ||
(binding instanceof IFunction && ASTInternal.isStatic((IFunction) binding, false)) || (binding instanceof IFunction && ASTInternal.isStatic((IFunction) binding, false, true)) ||
(binding instanceof IVariable && ((IVariable)binding).isStatic()) ) (binding instanceof IVariable && ((IVariable)binding).isStatic()) )
{ {
ok = true; ok = true;
@ -2396,7 +2393,7 @@ public class CPPSemantics {
} else } else
varArgs = true; varArgs = true;
if( useImplicitObj && j == 0 && ASTInternal.isStatic(currFn, false)) { if( useImplicitObj && j == 0 && ASTInternal.isStatic(currFn, false, true)) {
//13.3.1-4 for static member functions, the implicit object parameter is considered to match any object //13.3.1-4 for static member functions, the implicit object parameter is considered to match any object
cost = new Cost( source, target ); cost = new Cost( source, target );
cost.rank = Cost.IDENTITY_RANK; //exact match, no cost cost.rank = Cost.IDENTITY_RANK; //exact match, no cost

View file

@ -10,9 +10,6 @@
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Ed Swartz (Nokia) * Ed Swartz (Nokia)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Nov 29, 2004
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ILinkage;
@ -39,7 +36,7 @@ import org.eclipse.core.runtime.PlatformObject;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInternalBinding { public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInternalVariable {
public static class CPPVariableDelegate extends CPPDelegate implements ICPPVariable { public static class CPPVariableDelegate extends CPPDelegate implements ICPPVariable {
public CPPVariableDelegate( IASTName name, ICPPVariable binding ) { public CPPVariableDelegate( IASTName name, ICPPVariable binding ) {
super( name, binding ); super( name, binding );
@ -254,30 +251,6 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
return CPPVisitor.getContainingScope( definition != null ? definition : declarations[0] ); return CPPVisitor.getContainingScope( definition != null ? definition : declarations[0] );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#isStatic()
*/
public boolean isStatic() {
IASTDeclarator dtor = null;
if( declarations != null ) {
dtor= findDeclarator(declarations[0]);
}
else {
dtor= findDeclarator(definition);
}
if (dtor == null) {
return false;
}
IASTNode node = dtor.getParent();
if( node instanceof IASTSimpleDeclaration ){
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)node).getDeclSpecifier();
return (declSpec.getStorageClass() == IASTDeclSpecifier.sc_static );
}
return false;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName() * @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName()
*/ */
@ -319,20 +292,32 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
addDeclaration( node ); addDeclaration( node );
} }
public boolean hasStorageClass( int storage ){ public boolean hasStorageClass(int storage, boolean checkHeaders) {
IASTName name = (IASTName) getDefinition(); IASTName name = (IASTName) getDefinition();
IASTNode[] ns = getDeclarations(); IASTNode[] ns = getDeclarations();
boolean useDeclsInRoot= checkHeaders;
int i = -1; int i = -1;
do{ do{
if( name != null ){ if( name != null ){
if (!useDeclsInRoot) {
if (name.getTranslationUnit().isHeaderUnit()) {
return false;
}
useDeclsInRoot= true;
}
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
while( !(parent instanceof IASTDeclaration) ) while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent(); parent = parent.getParent();
if( parent instanceof IASTSimpleDeclaration ){ if( parent instanceof IASTSimpleDeclaration ){
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier(); IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage ) if (declSpec.getStorageClass() == storage) {
return true; if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
return true;
}
}
} }
} }
if( ns != null && ++i < ns.length ) if( ns != null && ++i < ns.length )
@ -351,28 +336,37 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
return false; return false;
} }
/* (non-Javadoc)
public boolean isStatic(boolean checkHeaders) {
return hasStorageClass(IASTDeclSpecifier.sc_static, checkHeaders);
}
public boolean isStatic() {
return isStatic(true);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern() * @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/ */
public boolean isExtern() { public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern ); return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto() * @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/ */
public boolean isAuto() { public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto ); return hasStorageClass( IASTDeclSpecifier.sc_auto, true);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister() * @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/ */
public boolean isRegister() { public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register ); return hasStorageClass( IASTDeclSpecifier.sc_register, true);
} }
public ILinkage getLinkage() { public ILinkage getLinkage() {
return Linkage.CPP_LINKAGE; return Linkage.CPP_LINKAGE;
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,22 +7,26 @@
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Apr 26, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
/** /**
* @author aniefer * Interface for ast-internal implementations of function bindings.
*/ */
public interface ICPPInternalFunction extends ICPPInternalBinding { public interface ICPPInternalFunction extends ICPPInternalBinding {
public IBinding resolveParameter( IASTParameterDeclaration param ); public IBinding resolveParameter( IASTParameterDeclaration param );
public boolean isStatic( boolean resolveAll ); /**
* Returns whether there is a static declaration for this function.
* @param resolveAll checks for names that are not yet resolved to this binding.
* @param checkHeaders if <code>false</code> declarations within header files are not
* considered.
*/
public boolean isStatic(boolean resolveAll, boolean checkHeaders);
} }

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
/**
* Interface for ast-internal implementations of variable bindings.
* @since 5.0
*/
public interface ICPPInternalVariable extends ICPPInternalBinding {
/**
* Returns whether there is a static declaration for this variable.
* @param checkHeaders if <code>false</code> declarations within header files are not
* considered.
*/
public boolean isStatic(boolean checkHeaders) throws DOMException;
}

View file

@ -133,4 +133,11 @@ public interface ILocationResolver extends org.eclipse.cdt.internal.core.parser.
* a macro expansion ({@link IASTName}). * a macro expansion ({@link IASTName}).
*/ */
IASTNode findSurroundingPreprocessorNode(int sequenceNumber, int length); IASTNode findSurroundingPreprocessorNode(int sequenceNumber, int length);
/**
* Returns whether the specified sequence number points into the root file of the
* translation unit, or not.
* @param offset
*/
boolean isPartOfTranslationUnitFile(int sequenceNumber);
} }

View file

@ -90,4 +90,12 @@ class LocationCtxFile extends LocationCtxContainer {
ASTFileLocation createFileLocation(int start, int length) { ASTFileLocation createFileLocation(int start, int length) {
return new ASTFileLocation(this, start, length); return new ASTFileLocation(this, start, length);
} }
public boolean isThisFile(int sequenceNumber) {
LocationCtx child= findChildLessOrEqualThan(sequenceNumber, false);
if (!(child instanceof LocationCtxFile)) {
return true;
}
return sequenceNumber >= child.fSequenceNumber + child.getSequenceLength();
}
} }

View file

@ -49,7 +49,7 @@ public class LocationMap implements ILocationResolver {
private ArrayList fBuiltinMacros= new ArrayList(); private ArrayList fBuiltinMacros= new ArrayList();
private IdentityHashMap fMacroReferences= new IdentityHashMap(); private IdentityHashMap fMacroReferences= new IdentityHashMap();
private LocationCtx fRootContext= null; private LocationCtxFile fRootContext= null;
private LocationCtx fCurrentContext= null; private LocationCtx fCurrentContext= null;
private int fLastChildInsertionOffset; private int fLastChildInsertionOffset;
@ -84,7 +84,7 @@ public class LocationMap implements ILocationResolver {
public ILocationCtx pushTranslationUnit(String filename, char[] buffer) { public ILocationCtx pushTranslationUnit(String filename, char[] buffer) {
assert fCurrentContext == null; assert fCurrentContext == null;
fTranslationUnitPath= filename; fTranslationUnitPath= filename;
fRootContext= fCurrentContext= new LocationCtxFile(null, filename, buffer, 0, 0, 0, null); fCurrentContext= fRootContext= new LocationCtxFile(null, filename, buffer, 0, 0, 0, null);
fLastChildInsertionOffset= 0; fLastChildInsertionOffset= 0;
return fCurrentContext; return fCurrentContext;
} }
@ -367,6 +367,11 @@ public class LocationMap implements ILocationResolver {
return (IASTNodeLocation[]) result.toArray(new IASTNodeLocation[result.size()]); return (IASTNodeLocation[]) result.toArray(new IASTNodeLocation[result.size()]);
} }
public boolean isPartOfTranslationUnitFile(int sequenceNumber) {
return fRootContext.isThisFile(sequenceNumber);
}
public IASTImageLocation getImageLocation(int sequenceNumber, int length) { public IASTImageLocation getImageLocation(int sequenceNumber, int length) {
ArrayList result= new ArrayList(); ArrayList result= new ArrayList();
fRootContext.collectLocations(sequenceNumber, length, result); fRootContext.collectLocations(sequenceNumber, length, result);

View file

@ -84,7 +84,7 @@ public class PDOMASTAdapter {
} }
public String getContainingFilename() { public String getContainingFilename() {
return fDelegate.getContainingFilename(); return fLocation.getFileName();
} }
public IASTFileLocation getFileLocation() { public IASTFileLocation getFileLocation() {
@ -154,6 +154,10 @@ public class PDOMASTAdapter {
public IASTImageLocation getImageLocation() { public IASTImageLocation getImageLocation() {
return null; return null;
} }
public boolean isPartOfTranslationUnitFile() {
return fLocation.getFileName().equals(fDelegate.getTranslationUnit().getFilePath());
}
} }
private static class AnonymousEnumeration implements IEnumeration { private static class AnonymousEnumeration implements IEnumeration {

View file

@ -60,7 +60,7 @@ public class PDOMCAnnotation {
modifiers |= (function.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET; modifiers |= (function.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET;
modifiers |= (function.isExtern() ? 1 : 0) << PDOMCAnnotation.EXTERN_OFFSET; modifiers |= (function.isExtern() ? 1 : 0) << PDOMCAnnotation.EXTERN_OFFSET;
modifiers |= (function.isRegister() ? 1 : 0) << PDOMCAnnotation.REGISTER_OFFSET; modifiers |= (function.isRegister() ? 1 : 0) << PDOMCAnnotation.REGISTER_OFFSET;
modifiers |= (ASTInternal.isStatic(function, false) ? 1 : 0) << PDOMCAnnotation.STATIC_OFFSET; modifiers |= (ASTInternal.isStatic(function, false, true) ? 1 : 0) << PDOMCAnnotation.STATIC_OFFSET;
modifiers |= (function.isInline() ? 1 : 0) << PDOMCAnnotation.INLINE_OFFSET; modifiers |= (function.isInline() ? 1 : 0) << PDOMCAnnotation.INLINE_OFFSET;
modifiers |= (function.takesVarArgs() ? 1 : 0) << PDOMCAnnotation.VARARGS_OFFSET; modifiers |= (function.takesVarArgs() ? 1 : 0) << PDOMCAnnotation.VARARGS_OFFSET;
} }

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType; import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
@ -258,11 +259,11 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
} }
if (binding instanceof IVariable) { if (binding instanceof IVariable) {
IVariable var= (IVariable) binding; IVariable var= (IVariable) binding;
return var.isStatic(); return ASTInternal.isStatic(var, false);
} }
if (binding instanceof IFunction) { if (binding instanceof IFunction) {
IFunction f= (IFunction) binding; IFunction f= (IFunction) binding;
return f.isStatic(); return ASTInternal.isStatic(f, false, false);
} }
return false; return false;
} }

View file

@ -58,9 +58,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
@ -801,17 +801,15 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
} }
if (binding instanceof ICPPVariable) { if (binding instanceof ICPPVariable) {
if (!(binding.getScope() instanceof CPPBlockScope)) { if (!(binding.getScope() instanceof CPPBlockScope)) {
ICPPVariable var= (ICPPVariable) binding; return ASTInternal.isStatic((ICPPVariable) binding, false);
return var.isStatic();
} }
return false; return false;
} }
if (binding instanceof ICPPMethod) { if (binding instanceof ICPPMethod) {
return false; return false;
} }
if (binding instanceof ICPPInternalFunction) { if (binding instanceof ICPPFunction) {
ICPPInternalFunction func = (ICPPInternalFunction)binding; return ASTInternal.isStatic((ICPPFunction) binding, false, false);
return func.isStatic(false);
} }
return false; return false;
} }

View file

@ -165,7 +165,11 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
return null; return null;
} }
return createAST((AbstractLanguage) language, codeReader, scannerInfo, options, pm); IASTTranslationUnit ast= createAST((AbstractLanguage) language, codeReader, scannerInfo, options, pm);
if (ast != null) {
ast.setIsHeaderUnit(tu.isHeaderUnit());
}
return ast;
} }
/** /**