mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Static variables/functions declared in headers, bug 180305.
This commit is contained in:
parent
a6d8d84032
commit
01e130423b
30 changed files with 464 additions and 158 deletions
|
@ -1090,4 +1090,89 @@ public class IndexBugsTests extends BaseTestCase {
|
|||
IFunctionType ft= ((IFunction) bindings[0]).getType();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -766,6 +766,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
ILanguage language= configureWith.getLanguage();
|
||||
fLanguageOfContext= language;
|
||||
if (language != null) {
|
||||
IASTTranslationUnit ast= null;
|
||||
if (language instanceof AbstractLanguage) {
|
||||
int options= 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) {
|
||||
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;
|
||||
|
|
|
@ -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
|
||||
* 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:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
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,
|
||||
* 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,
|
||||
* IASTNodeLocation [] result will have one element in it, and it will be an
|
||||
|
@ -65,6 +65,12 @@ public interface IASTNode {
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -96,7 +102,7 @@ public interface IASTNode {
|
|||
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>.
|
||||
*
|
||||
* @param visitor
|
||||
|
@ -116,7 +122,7 @@ public interface IASTNode {
|
|||
|
||||
/**
|
||||
* 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
|
||||
* @return whether this node contains the given one.
|
||||
* @since 4.0
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
*******************************************************************************/
|
||||
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.index.IIndex;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
@ -261,5 +262,20 @@ public interface IASTTranslationUnit extends IASTNode, IAdaptable {
|
|||
* @since 4.0
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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.IFunction;
|
||||
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.ICPPInternalFunction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalVariable;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
return ((ICPPInternalFunction)func).isStatic(resolveAll);
|
||||
return ((ICPPInternalFunction)func).isStatic(resolveAll, checkHeaders);
|
||||
}
|
||||
if (func instanceof ICInternalFunction) {
|
||||
return ((ICInternalFunction) func).isStatic(resolveAll, checkHeaders);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,6 +159,17 @@ public abstract class ASTNode implements IASTNode {
|
|||
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() {
|
||||
return parent != null ? parent.getTranslationUnit() : null;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
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.ast.ASTVisitor;
|
||||
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.parser.ParserLanguage;
|
||||
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.ASTNode;
|
||||
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 IASTComment[] comments = new ASTComment[0];
|
||||
private IASTComment[] comments = new ASTComment[0];
|
||||
private boolean fIsHeader;
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit() {
|
||||
return this;
|
||||
|
@ -614,4 +617,16 @@ public class CASTTranslationUnit extends CASTNode implements
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ILinkage getLinkage() {
|
||||
return Linkage.C_LINKAGE;
|
||||
}
|
||||
|
||||
public boolean isHeaderUnit() {
|
||||
return fIsHeader;
|
||||
}
|
||||
|
||||
public void setIsHeaderUnit(boolean headerUnit) {
|
||||
fIsHeader= headerUnit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
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()
|
||||
*/
|
||||
public boolean isStatic() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_static );
|
||||
return isStatic(true, true);
|
||||
}
|
||||
|
||||
public boolean hasStorageClass( int storage ){
|
||||
if( (bits & FULLY_RESOLVED) == 0 ){
|
||||
|
||||
public boolean isStatic(boolean resolveAll, boolean checkHeaders) {
|
||||
if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){
|
||||
resolveAllDeclarations();
|
||||
}
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_static, checkHeaders );
|
||||
}
|
||||
|
||||
public boolean hasStorageClass( int storage, boolean checkHeaders){
|
||||
IASTDeclarator dtor = definition;
|
||||
IASTDeclarator[] ds = declarators;
|
||||
|
||||
boolean useDeclsInRoot= checkHeaders;
|
||||
int i = -1;
|
||||
do{
|
||||
if( dtor != null ){
|
||||
if (!useDeclsInRoot) {
|
||||
if (dtor.getTranslationUnit().isHeaderUnit()) {
|
||||
return false;
|
||||
}
|
||||
useDeclsInRoot= true;
|
||||
}
|
||||
|
||||
IASTNode parent = dtor.getParent();
|
||||
while( !(parent instanceof IASTDeclaration) )
|
||||
parent = parent.getParent();
|
||||
|
@ -357,8 +370,11 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
|
|||
} else if( parent instanceof IASTFunctionDefinition )
|
||||
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
|
||||
|
||||
if( declSpec.getStorageClass() == storage )
|
||||
return true;
|
||||
if( declSpec.getStorageClass() == storage ) {
|
||||
if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
*/
|
||||
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)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
|
||||
*/
|
||||
public boolean isAuto() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_auto );
|
||||
if( (bits & FULLY_RESOLVED) == 0 ){
|
||||
resolveAllDeclarations();
|
||||
}
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_auto, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
|
||||
*/
|
||||
public boolean isRegister() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_register );
|
||||
if( (bits & FULLY_RESOLVED) == 0 ){
|
||||
resolveAllDeclarations();
|
||||
}
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_register, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -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
|
||||
* 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:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
@ -32,7 +32,7 @@ import org.eclipse.core.runtime.PlatformObject;
|
|||
* Created on Nov 5, 2004
|
||||
* @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 CVariableProblem( IASTNode node, int id, char[] arg ) {
|
||||
super( node, id, arg );
|
||||
|
@ -93,25 +93,40 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalBi
|
|||
IASTDeclarator declarator = (IASTDeclarator) declarations[0].getParent();
|
||||
return CVisitor.getContainingScope( declarator.getParent() );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic()
|
||||
*/
|
||||
public boolean isStatic() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_static );
|
||||
}
|
||||
|
||||
public boolean hasStorageClass( int storage ){
|
||||
|
||||
public boolean isStatic(boolean checkHeaders) {
|
||||
return hasStorageClass(IASTDeclSpecifier.sc_static, checkHeaders);
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return isStatic(true);
|
||||
}
|
||||
|
||||
public boolean hasStorageClass( int storage, boolean checkHeaders){
|
||||
if( declarations == null )
|
||||
return false;
|
||||
|
||||
boolean useDeclsInRoot= checkHeaders;
|
||||
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) )
|
||||
parent = parent.getParent();
|
||||
|
||||
if( parent instanceof IASTSimpleDeclaration ){
|
||||
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
|
||||
if( declSpec.getStorageClass() == storage )
|
||||
return true;
|
||||
if( declSpec.getStorageClass() == storage ) {
|
||||
if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -120,19 +135,19 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalBi
|
|||
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
|
||||
*/
|
||||
public boolean isExtern() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_extern );
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
|
||||
*/
|
||||
public boolean isAuto() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_auto );
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_auto, true);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
|
||||
*/
|
||||
public boolean isRegister() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_register );
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_register, true);
|
||||
}
|
||||
|
||||
public ILinkage getLinkage() {
|
||||
|
|
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,21 +7,26 @@
|
|||
*
|
||||
* Contributors:
|
||||
* 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;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* Interface for ast-internal implementations of function bindings.
|
||||
*/
|
||||
public interface ICInternalFunction extends ICInternalBinding {
|
||||
public void setFullyResolved( boolean resolved );
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -98,6 +98,8 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
|
||||
|
||||
private IASTComment[] comments = new ASTComment[0];
|
||||
|
||||
private boolean fIsHeader;
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit() {
|
||||
return this;
|
||||
|
@ -578,4 +580,12 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isHeaderUnit() {
|
||||
return fIsHeader;
|
||||
}
|
||||
|
||||
public void setIsHeaderUnit(boolean headerUnit) {
|
||||
fIsHeader= headerUnit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Apr 14, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
|
@ -175,9 +172,9 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc
|
|||
/* (non-Javadoc)
|
||||
* @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 {
|
||||
return ASTInternal.isStatic((IFunction) getTemplateDefinition(), resolveAll);
|
||||
return ASTInternal.isStatic((IFunction) getTemplateDefinition(), resolveAll, checkHeaders);
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Nov 29, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
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()
|
||||
*/
|
||||
public boolean isMutable() {
|
||||
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable );
|
||||
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable, true);
|
||||
}
|
||||
|
||||
public boolean isExtern() {
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Dec 1, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
|
@ -86,9 +83,9 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
|||
public boolean takesVarArgs() throws DOMException {
|
||||
return ((ICPPFunction)getBinding()).takesVarArgs();
|
||||
}
|
||||
public boolean isStatic( boolean resolveAll ) {
|
||||
public boolean isStatic( boolean resolveAll, boolean checkHeaders) {
|
||||
try {
|
||||
return ASTInternal.isStatic((IFunction) getBinding(), resolveAll);
|
||||
return ASTInternal.isStatic((IFunction) getBinding(), resolveAll, checkHeaders);
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -429,16 +426,16 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
|||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
|
||||
*/
|
||||
public boolean isStatic( ) {
|
||||
return isStatic( true );
|
||||
return isStatic( true, true );
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @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 ){
|
||||
resolveAllDeclarations();
|
||||
}
|
||||
return hasStorageClass( this, IASTDeclSpecifier.sc_static );
|
||||
return hasStorageClass( this, IASTDeclSpecifier.sc_static, checkHeaders );
|
||||
}
|
||||
// }
|
||||
// static public boolean isStatic
|
||||
|
@ -507,12 +504,23 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
|||
}
|
||||
|
||||
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();
|
||||
IASTNode[] ds = function.getDeclarations();
|
||||
|
||||
boolean useDeclsInRoot= checkHeaders;
|
||||
int i = -1;
|
||||
do{
|
||||
if( dtor != null ){
|
||||
if (!useDeclsInRoot) {
|
||||
if (dtor.getTranslationUnit().isHeaderUnit()) {
|
||||
return false;
|
||||
}
|
||||
useDeclsInRoot= true;
|
||||
}
|
||||
IASTNode parent = dtor.getParent();
|
||||
while( !(parent instanceof IASTDeclaration) )
|
||||
parent = parent.getParent();
|
||||
|
@ -522,8 +530,11 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
|||
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
|
||||
else if( parent instanceof IASTFunctionDefinition )
|
||||
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
|
||||
if( declSpec.getStorageClass() == storage )
|
||||
return true;
|
||||
if( declSpec.getStorageClass() == storage ) {
|
||||
if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( ds != null && ++i < ds.length ) {
|
||||
dtor = (ICPPASTFunctionDeclarator) ds[i];
|
||||
|
|
|
@ -6,12 +6,9 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Mar 29, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
|
@ -140,10 +137,10 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
|
|||
/* (non-Javadoc)
|
||||
* @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();
|
||||
try {
|
||||
return ASTInternal.isStatic(func, resolveAll);
|
||||
return ASTInternal.isStatic(func, resolveAll, checkHeaders);
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Bryan Wilkinson (QNX)
|
||||
* IBM - Initial API and implementation
|
||||
* Bryan Wilkinson (QNX)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Apr 22, 2005
|
||||
|
@ -95,19 +96,19 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
|
|||
return getFunction().isInline();
|
||||
}
|
||||
public boolean isStatic() {
|
||||
return isStatic( true );
|
||||
return isStatic(true, true);
|
||||
}
|
||||
public boolean isStatic(boolean resolveAll) {
|
||||
public boolean isStatic(boolean resolveAll, boolean checkHeaders) {
|
||||
//TODO resolveAll
|
||||
IBinding f = getSpecializedBinding();
|
||||
if( f instanceof ICPPInternalFunction)
|
||||
return ((ICPPInternalFunction)f).isStatic( resolveAll );
|
||||
return ((ICPPInternalFunction)f).isStatic( resolveAll, checkHeaders);
|
||||
if( f instanceof IIndexBinding && f instanceof ICPPFunction ) {
|
||||
try {
|
||||
return ((ICPPFunction) f).isStatic();
|
||||
} 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 {
|
||||
|
|
|
@ -6,12 +6,9 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Mar 31, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
|
@ -221,12 +218,20 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
|
|||
return type;
|
||||
}
|
||||
|
||||
public boolean hasStorageClass( int storage ){
|
||||
public boolean hasStorageClass( int storage, boolean checkHeaders){
|
||||
IASTName name = (IASTName) getDefinition();
|
||||
IASTNode[] ns = getDeclarations();
|
||||
int i = -1;
|
||||
boolean useDeclsInRoot= checkHeaders;
|
||||
do{
|
||||
if( name != null ){
|
||||
if (!useDeclsInRoot) {
|
||||
if (name.getTranslationUnit().isHeaderUnit()) {
|
||||
return false;
|
||||
}
|
||||
useDeclsInRoot= true;
|
||||
}
|
||||
|
||||
IASTNode parent = name.getParent();
|
||||
while( !(parent instanceof IASTDeclaration) )
|
||||
parent = parent.getParent();
|
||||
|
@ -236,8 +241,11 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
|
|||
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
|
||||
else if( parent instanceof IASTFunctionDefinition )
|
||||
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
|
||||
if( declSpec.getStorageClass() == storage )
|
||||
return true;
|
||||
if( declSpec.getStorageClass() == storage ) {
|
||||
if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( ns != null && ++i < ns.length )
|
||||
name = (IASTName) ns[i];
|
||||
|
@ -310,13 +318,13 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
|
|||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
|
||||
*/
|
||||
public boolean isStatic() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_static );
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_static, true);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
|
||||
*/
|
||||
public boolean isMutable() {
|
||||
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable );
|
||||
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -353,21 +361,21 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
|
|||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
|
||||
*/
|
||||
public boolean isExtern() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_extern );
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
|
||||
*/
|
||||
public boolean isAuto() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_auto );
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_auto, true );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
|
||||
*/
|
||||
public boolean isRegister() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_register);
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_register, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -404,8 +412,8 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
|
||||
*/
|
||||
public boolean isStatic( boolean resolveAll ) {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_static );
|
||||
public boolean isStatic( boolean resolveAll, boolean checkHeaders ) {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_static, checkHeaders);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -6,14 +6,11 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
* Andrew Ferguson (Symbian)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Dec 8, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
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
|
||||
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()) )
|
||||
{
|
||||
ok = true;
|
||||
|
@ -2396,7 +2393,7 @@ public class CPPSemantics {
|
|||
} else
|
||||
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
|
||||
cost = new Cost( source, target );
|
||||
cost.rank = Cost.IDENTITY_RANK; //exact match, no cost
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
* Markus Schorn (Wind River Systems)
|
||||
* Ed Swartz (Nokia)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Nov 29, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
|
@ -39,7 +36,7 @@ import org.eclipse.core.runtime.PlatformObject;
|
|||
/**
|
||||
* @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 CPPVariableDelegate( IASTName name, ICPPVariable binding ) {
|
||||
super( name, binding );
|
||||
|
@ -254,30 +251,6 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
|
|||
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)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName()
|
||||
*/
|
||||
|
@ -319,20 +292,32 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
|
|||
addDeclaration( node );
|
||||
}
|
||||
|
||||
public boolean hasStorageClass( int storage ){
|
||||
public boolean hasStorageClass(int storage, boolean checkHeaders) {
|
||||
IASTName name = (IASTName) getDefinition();
|
||||
IASTNode[] ns = getDeclarations();
|
||||
|
||||
boolean useDeclsInRoot= checkHeaders;
|
||||
int i = -1;
|
||||
do{
|
||||
if( name != null ){
|
||||
if (!useDeclsInRoot) {
|
||||
if (name.getTranslationUnit().isHeaderUnit()) {
|
||||
return false;
|
||||
}
|
||||
useDeclsInRoot= true;
|
||||
}
|
||||
|
||||
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 (declSpec.getStorageClass() == storage) {
|
||||
if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if( ns != null && ++i < ns.length )
|
||||
|
@ -351,28 +336,37 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
|
|||
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()
|
||||
*/
|
||||
public boolean isExtern() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_extern );
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
|
||||
*/
|
||||
public boolean isAuto() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_auto );
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_auto, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
|
||||
*/
|
||||
public boolean isRegister() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_register );
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_register, true);
|
||||
}
|
||||
|
||||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,22 +7,26 @@
|
|||
*
|
||||
* Contributors:
|
||||
* 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;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
* Interface for ast-internal implementations of function bindings.
|
||||
*/
|
||||
public interface ICPPInternalFunction extends ICPPInternalBinding {
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -133,4 +133,11 @@ public interface ILocationResolver extends org.eclipse.cdt.internal.core.parser.
|
|||
* a macro expansion ({@link IASTName}).
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -90,4 +90,12 @@ class LocationCtxFile extends LocationCtxContainer {
|
|||
ASTFileLocation createFileLocation(int start, int 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();
|
||||
}
|
||||
}
|
|
@ -49,7 +49,7 @@ public class LocationMap implements ILocationResolver {
|
|||
private ArrayList fBuiltinMacros= new ArrayList();
|
||||
private IdentityHashMap fMacroReferences= new IdentityHashMap();
|
||||
|
||||
private LocationCtx fRootContext= null;
|
||||
private LocationCtxFile fRootContext= null;
|
||||
private LocationCtx fCurrentContext= null;
|
||||
private int fLastChildInsertionOffset;
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class LocationMap implements ILocationResolver {
|
|||
public ILocationCtx pushTranslationUnit(String filename, char[] buffer) {
|
||||
assert fCurrentContext == null;
|
||||
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;
|
||||
return fCurrentContext;
|
||||
}
|
||||
|
@ -367,6 +367,11 @@ public class LocationMap implements ILocationResolver {
|
|||
return (IASTNodeLocation[]) result.toArray(new IASTNodeLocation[result.size()]);
|
||||
}
|
||||
|
||||
|
||||
public boolean isPartOfTranslationUnitFile(int sequenceNumber) {
|
||||
return fRootContext.isThisFile(sequenceNumber);
|
||||
}
|
||||
|
||||
public IASTImageLocation getImageLocation(int sequenceNumber, int length) {
|
||||
ArrayList result= new ArrayList();
|
||||
fRootContext.collectLocations(sequenceNumber, length, result);
|
||||
|
|
|
@ -84,7 +84,7 @@ public class PDOMASTAdapter {
|
|||
}
|
||||
|
||||
public String getContainingFilename() {
|
||||
return fDelegate.getContainingFilename();
|
||||
return fLocation.getFileName();
|
||||
}
|
||||
|
||||
public IASTFileLocation getFileLocation() {
|
||||
|
@ -154,6 +154,10 @@ public class PDOMASTAdapter {
|
|||
public IASTImageLocation getImageLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPartOfTranslationUnitFile() {
|
||||
return fLocation.getFileName().equals(fDelegate.getTranslationUnit().getFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
private static class AnonymousEnumeration implements IEnumeration {
|
||||
|
|
|
@ -60,7 +60,7 @@ public class PDOMCAnnotation {
|
|||
modifiers |= (function.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET;
|
||||
modifiers |= (function.isExtern() ? 1 : 0) << PDOMCAnnotation.EXTERN_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.takesVarArgs() ? 1 : 0) << PDOMCAnnotation.VARARGS_OFFSET;
|
||||
}
|
||||
|
|
|
@ -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.c.ICBasicType;
|
||||
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.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
||||
|
@ -258,11 +259,11 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
|
|||
}
|
||||
if (binding instanceof IVariable) {
|
||||
IVariable var= (IVariable) binding;
|
||||
return var.isStatic();
|
||||
return ASTInternal.isStatic(var, false);
|
||||
}
|
||||
if (binding instanceof IFunction) {
|
||||
IFunction f= (IFunction) binding;
|
||||
return f.isStatic();
|
||||
return ASTInternal.isStatic(f, false, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -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.gnu.cpp.IGPPBasicType;
|
||||
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.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.pdom.PDOM;
|
||||
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.getScope() instanceof CPPBlockScope)) {
|
||||
ICPPVariable var= (ICPPVariable) binding;
|
||||
return var.isStatic();
|
||||
return ASTInternal.isStatic((ICPPVariable) binding, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (binding instanceof ICPPMethod) {
|
||||
return false;
|
||||
}
|
||||
if (binding instanceof ICPPInternalFunction) {
|
||||
ICPPInternalFunction func = (ICPPInternalFunction)binding;
|
||||
return func.isStatic(false);
|
||||
if (binding instanceof ICPPFunction) {
|
||||
return ASTInternal.isStatic((ICPPFunction) binding, false, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -165,7 +165,11 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue