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

Patch for Andrew Niefer.

This commit is contained in:
John Camelon 2003-12-10 00:07:32 +00:00
parent 0b91eeb637
commit bce674ac9a
8 changed files with 421 additions and 35 deletions

View file

@ -1,3 +1,7 @@
2003-12-09 Andrew Niefer
added ParserSymbolTableTests.testVisibilityDetermination()
added ParserSymbolTableTests.testPrefixFiltering
2003-12-09 Hoda Amer 2003-12-09 Hoda Amer
Modified the Completion Proposal test to include case sensitivity Modified the Completion Proposal test to include case sensitivity
in the order of proposals. in the order of proposals.

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -20,6 +21,16 @@ import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
import org.eclipse.cdt.core.parser.ast.IASTField;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTClassSpecifier;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTCompilationUnit;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTField;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol;
@ -29,6 +40,7 @@ import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
import org.eclipse.cdt.internal.core.parser.pst.TemplateInstance; import org.eclipse.cdt.internal.core.parser.pst.TemplateInstance;
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Mark; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Mark;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.OperatorExpression; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.OperatorExpression;
@ -3010,7 +3022,7 @@ public class ParserSymbolTableTest extends TestCase {
ISymbol anotherVar = table.newSymbol( "anotherVar", TypeInfo.t_int ); ISymbol anotherVar = table.newSymbol( "anotherVar", TypeInfo.t_int );
foo.addSymbol( anotherVar ); foo.addSymbol( anotherVar );
List results = foo.prefixLookup( TypeInfo.t_any, "a", false ); List results = foo.prefixLookup( null, "a", false );
assertTrue( results != null ); assertTrue( results != null );
assertEquals( results.size(), 2 ); assertEquals( results.size(), 2 );
@ -3044,7 +3056,7 @@ public class ParserSymbolTableTest extends TestCase {
D.addSymbol( aField ); D.addSymbol( aField );
D.addSymbol( aMethod ); D.addSymbol( aMethod );
List results = D.prefixLookup( TypeInfo.t_any, "a", true ); List results = D.prefixLookup( null, "a", true );
assertTrue( results != null ); assertTrue( results != null );
assertEquals( results.size(), 2 ); assertEquals( results.size(), 2 );
@ -3096,7 +3108,7 @@ public class ParserSymbolTableTest extends TestCase {
B.addSymbol( af2 ); B.addSymbol( af2 );
List results = B.prefixLookup( TypeInfo.t_any, "a", true ); List results = B.prefixLookup( null, "a", true );
assertTrue( results != null ); assertTrue( results != null );
assertEquals( results.size(), 3 ); assertEquals( results.size(), 3 );
@ -3161,7 +3173,7 @@ public class ParserSymbolTableTest extends TestCase {
f.addUsingDirective( V ); f.addUsingDirective( V );
f.addUsingDirective( W ); f.addUsingDirective( W );
List results = f.prefixLookup( TypeInfo.t_any, "a", false ); List results = f.prefixLookup( null, "a", false );
assertTrue( results != null ); assertTrue( results != null );
assertEquals( results.size(), 1 ); assertEquals( results.size(), 1 );
@ -3195,5 +3207,131 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( null, A.qualifiedLookup( "i" ) ); assertEquals( null, A.qualifiedLookup( "i" ) );
assertEquals( i, g.lookup( "i" ) ); assertEquals( i, g.lookup( "i" ) );
} }
/**
* class A { public: static int i; };
* class B : private A {};
* class C : public B, public A {};
*
* @throws Exception
*/
public void testVisibilityDetermination() throws Exception{
newTable();
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
ISymbol i = table.newSymbol( "i", TypeInfo.t_int );
table.getCompilationUnit().addSymbol( A );
A.addSymbol( i );
IASTCompilationUnit compUnit = new ASTCompilationUnit(table.getCompilationUnit() );
ISymbolASTExtension cuExtension = new StandardSymbolExtension( table.getCompilationUnit(), (ASTSymbol) compUnit );
table.getCompilationUnit().setASTExtension( cuExtension );
IASTClassSpecifier clsSpec = new ASTClassSpecifier( A, ASTClassKind.CLASS, ClassNameType.IDENTIFIER, ASTAccessVisibility.PUBLIC, 0, 0, 0, new ArrayList( ) );
ISymbolASTExtension clsExtension = new StandardSymbolExtension( A, (ASTSymbol) clsSpec );
A.setASTExtension( clsExtension );
IASTField field = new ASTField(i, null, null, null, 0, 0, 0, new ArrayList(), false, null, ASTAccessVisibility.PUBLIC );
ISymbolASTExtension extension = new StandardSymbolExtension( i, (ASTSymbol) field );
i.setASTExtension( extension );
IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", TypeInfo.t_class );
B.addParent( A, false, ASTAccessVisibility.PRIVATE, 0, null );
table.getCompilationUnit().addSymbol( B );
IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C", TypeInfo.t_class );
C.addParent( B );
C.addParent( A );
table.getCompilationUnit().addSymbol( C );
assertTrue( table.getCompilationUnit().isVisible( i, A ) );
assertFalse( table.getCompilationUnit().isVisible( i, B ) );
assertTrue( table.getCompilationUnit().isVisible(i, C ) );
}
/**
* struct a1{};
* void aFoo() {}
* int aa;
* class A2{
* struct a3 {};
* int a3;
* void aF();
* void f() {
* int aLocal;
* A(CTRL+SPACE)
* };
* };
* @throws Exception
*/
public void testPrefixFiltering() throws Exception{
newTable();
IDerivableContainerSymbol a1 = table.newDerivableContainerSymbol( "a1", TypeInfo.t_struct );
table.getCompilationUnit().addSymbol( a1 );
IParameterizedSymbol aFoo = table.newParameterizedSymbol( "aFoo", TypeInfo.t_function );
table.getCompilationUnit().addSymbol( aFoo );
ISymbol aa = table.newSymbol( "aa", TypeInfo.t_int );
table.getCompilationUnit().addSymbol( aa );
IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A2", TypeInfo.t_class );
table.getCompilationUnit().addSymbol( A2 );
IDerivableContainerSymbol a3 = table.newDerivableContainerSymbol( "a3", TypeInfo.t_struct );
A2.addSymbol( a3 );
ISymbol a3_int = table.newSymbol( "a3", TypeInfo.t_int );
A2.addSymbol( a3_int );
IParameterizedSymbol aF = table.newParameterizedSymbol( "aF", TypeInfo.t_function );
A2.addSymbol( aF );
IParameterizedSymbol f = table.newParameterizedSymbol( "f", TypeInfo.t_function );
A2.addSymbol( f );
ISymbol aLocal = table.newSymbol( "aLocal", TypeInfo.t_int );
f.addSymbol( aLocal );
List results = f.prefixLookup( new TypeFilter( LookupKind.STRUCTURES ), "A", false );
assertEquals( results.size(), 3 );
assertTrue( results.contains( a1 ) );
assertTrue( results.contains( A2 ) );
assertTrue( results.contains( a3 ) );
results = f.prefixLookup( null, "a", false );
assertEquals( results.size(), 7 );
assertTrue( results.contains( aF ) );
assertTrue( results.contains( A2 ) );
assertTrue( results.contains( a3_int ) );
assertTrue( results.contains( a1 ) );
assertTrue( results.contains( aFoo ) );
assertTrue( results.contains( aa ) );
assertTrue( results.contains( aLocal ) );
results = f.prefixLookup( new TypeFilter( LookupKind.FUNCTIONS ), "a", false );
assertEquals( results.size(), 1 );
assertTrue( results.contains( aFoo ) );
results = f.prefixLookup( new TypeFilter( LookupKind.METHODS ), "a", false );
assertEquals( results.size(), 1 );
assertTrue( results.contains( aF ) );
results = f.prefixLookup( new TypeFilter( LookupKind.LOCAL_VARIABLES ), "a", false );
assertEquals( results.size(), 1 );
assertTrue( results.contains( aLocal ) );
results = f.prefixLookup( new TypeFilter( LookupKind.VARIABLES ), "a", false );
assertEquals( results.size(), 1 );
assertTrue( results.contains( aa ) );
results = f.prefixLookup( new TypeFilter( LookupKind.FIELDS), "a", false );
assertEquals( results.size(), 1 );
assertTrue( results.contains( a3_int ) );
};
} }

View file

@ -1,3 +1,7 @@
2003-12-09 Andrew Niefer
-created TypeFilter to support support filtering of what kind of symbols to find (for prefix lookup 48306)
-added IContainerSymbol.isVisible for bug 48294
2003-12-09 Hoda Amer 2003-12-09 Hoda Amer
Modified IASTCompletionNode.CompletionKind Modified IASTCompletionNode.CompletionKind
modified IASTNode.LookupKind modified IASTNode.LookupKind

View file

@ -22,6 +22,9 @@ import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.IASTMember;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Command; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Command;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData;
@ -378,8 +381,10 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
ISymbol foundSymbol = null; ISymbol foundSymbol = null;
LookupData data = new LookupData( name, TypeInfo.t_namespace, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_namespace, getTemplateInstance() );
data.upperType = TypeInfo.t_union; data.filter.addFilteredType( TypeInfo.t_class );
data.filter.addFilteredType( TypeInfo.t_struct );
data.filter.addFilteredType( TypeInfo.t_union );
data.foundItems = ParserSymbolTable.lookupInContained( data, inSymbol ); data.foundItems = ParserSymbolTable.lookupInContained( data, inSymbol );
if( data.foundItems != null ){ if( data.foundItems != null ){
@ -571,8 +576,8 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
return null; return null;
} }
public List prefixLookup( TypeInfo.eType type, String prefix, boolean qualified ) throws ParserSymbolTableException{ public List prefixLookup( TypeFilter filter, String prefix, boolean qualified ) throws ParserSymbolTableException{
LookupData data = new LookupData( prefix, type, getTemplateInstance() ); LookupData data = new LookupData( prefix, filter, getTemplateInstance() );
data.qualified = qualified; data.qualified = qualified;
data.mode = ParserSymbolTable.LookupMode.PREFIX; data.mode = ParserSymbolTable.LookupMode.PREFIX;
@ -607,6 +612,45 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} }
} }
public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol ){
ISymbolASTExtension extension = symbol.getASTExtension();
IASTNode node = extension.getPrimaryDeclaration();
if( node instanceof IASTMember ){
ASTAccessVisibility visibility;
try {
visibility = ParserSymbolTable.getVisibility( symbol, qualifyingSymbol );
} catch (ParserSymbolTableException e) {
return false;
}
if( visibility == ASTAccessVisibility.PUBLIC ){
return true;
}
IContainerSymbol container = getContainingSymbol();
IContainerSymbol symbolContainer = ( qualifyingSymbol != null ) ? qualifyingSymbol : symbol.getContainingSymbol();
if( !symbolContainer.isType( TypeInfo.t_class, TypeInfo.t_union ) ||
symbolContainer.equals( container ) )
{
return true;
}
//TODO: friendship
if( visibility == ASTAccessVisibility.PROTECTED )
{
try {
return ( ParserSymbolTable.hasBaseClass( container, symbolContainer ) >= 0 );
} catch (ParserSymbolTableException e) {
return false;
}
} else { //PRIVATE
return false;
}
}
return true;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#instantiate(java.util.List) * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#instantiate(java.util.List)
*/ */

View file

@ -39,7 +39,7 @@ public interface IContainerSymbol extends ISymbol {
public Map getContainedSymbols(); public Map getContainedSymbols();
public List prefixLookup( TypeInfo.eType type, String prefix, boolean qualified ) throws ParserSymbolTableException; public List prefixLookup( TypeFilter filter, String prefix, boolean qualified ) throws ParserSymbolTableException;
public ISymbol elaboratedLookup( TypeInfo.eType type, String name ) throws ParserSymbolTableException; public ISymbol elaboratedLookup( TypeInfo.eType type, String name ) throws ParserSymbolTableException;
public ISymbol lookup( String name ) throws ParserSymbolTableException; public ISymbol lookup( String name ) throws ParserSymbolTableException;
@ -53,4 +53,6 @@ public interface IContainerSymbol extends ISymbol {
public IParameterizedSymbol qualifiedFunctionLookup( String name, List parameters ) throws ParserSymbolTableException; public IParameterizedSymbol qualifiedFunctionLookup( String name, List parameters ) throws ParserSymbolTableException;
public TemplateInstance templateLookup( String name, List arguments ) throws ParserSymbolTableException; public TemplateInstance templateLookup( String name, List arguments ) throws ParserSymbolTableException;
public TemplateInstance instantiate( List arguments ) throws ParserSymbolTableException; public TemplateInstance instantiate( List arguments ) throws ParserSymbolTableException;
public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol );
} }

View file

@ -25,6 +25,9 @@ import java.util.Set;
import org.eclipse.cdt.core.parser.Enum; import org.eclipse.cdt.core.parser.Enum;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.IASTMember;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
/** /**
@ -90,9 +93,9 @@ public class ParserSymbolTable {
*/ */
static protected void lookup( LookupData data, IContainerSymbol inSymbol ) throws ParserSymbolTableException static protected void lookup( LookupData data, IContainerSymbol inSymbol ) throws ParserSymbolTableException
{ {
if( data.type != TypeInfo.t_any && data.type.compareTo(TypeInfo.t_class) < 0 && data.upperType.compareTo(TypeInfo.t_union) > 0 ){ // if( data.type != TypeInfo.t_any && data.type.compareTo(TypeInfo.t_class) < 0 && data.upperType.compareTo(TypeInfo.t_union) > 0 ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); // throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
} // }
//handle namespace aliases //handle namespace aliases
if( inSymbol.isType( TypeInfo.t_namespace ) ){ if( inSymbol.isType( TypeInfo.t_namespace ) ){
@ -352,22 +355,26 @@ public class ParserSymbolTable {
private static boolean nameMatches( LookupData data, String name ){ private static boolean nameMatches( LookupData data, String name ){
if( data.mode == LookupMode.PREFIX ){ if( data.mode == LookupMode.PREFIX ){
return name.startsWith( data.name ); return name.regionMatches( true, 0, data.name, 0, data.name.length() );
} else { } else {
return name.equals( data.name ); return name.equals( data.name );
} }
} }
private static boolean checkType( LookupData data, ISymbol symbol, TypeInfo.eType type, TypeInfo.eType upperType ){ private static boolean checkType( LookupData data, ISymbol symbol ) { //, TypeInfo.eType type, TypeInfo.eType upperType ){
if( data.filter == null ){
return true;
}
if( data.templateInstance != null && symbol.isTemplateMember() ){ if( data.templateInstance != null && symbol.isTemplateMember() ){
if( symbol.isType( TypeInfo.t_type ) ){ if( symbol.isType( TypeInfo.t_type ) ){
symbol = symbol.getTypeSymbol(); symbol = symbol.getTypeSymbol();
} }
if( symbol.isType( TypeInfo.t_undef ) && symbol.getContainingSymbol().isType( TypeInfo.t_template ) ){ if( symbol.isType( TypeInfo.t_undef ) && symbol.getContainingSymbol().isType( TypeInfo.t_template ) ){
TypeInfo info = (TypeInfo) data.templateInstance.getArgumentMap().get( symbol ); TypeInfo info = (TypeInfo) data.templateInstance.getArgumentMap().get( symbol );
return info.isType( type, upperType ); return data.filter.shouldAccept( symbol, info );
} }
} }
return symbol.isType( type, upperType ); return data.filter.shouldAccept( symbol );
} }
private static Object collectSymbol(LookupData data, Object object ) throws ParserSymbolTableException { private static Object collectSymbol(LookupData data, Object object ) throws ParserSymbolTableException {
@ -385,7 +392,7 @@ public class ParserSymbolTable {
IContainerSymbol cls = null; IContainerSymbol cls = null;
while( symbol != null ){ while( symbol != null ){
if( checkType( data, symbol, data.type, data.upperType ) ){ if( checkType( data, symbol ) ){//, data.type, data.upperType ) ){
if( symbol.isTemplateMember() && data.templateInstance != null ) if( symbol.isTemplateMember() && data.templateInstance != null )
foundSymbol = new TemplateInstance( symbol.getSymbolTable(), symbol, data.templateInstance.getArgumentMap() ); foundSymbol = new TemplateInstance( symbol.getSymbolTable(), symbol, data.templateInstance.getArgumentMap() );
else else
@ -1110,7 +1117,7 @@ public class ParserSymbolTable {
* *
* TBD: Consider rewriting iteratively for performance. * TBD: Consider rewriting iteratively for performance.
*/ */
static private int hasBaseClass( ISymbol obj, ISymbol base ) throws ParserSymbolTableException { static protected int hasBaseClass( ISymbol obj, ISymbol base ) throws ParserSymbolTableException {
return hasBaseClass( obj, base, false ); return hasBaseClass( obj, base, false );
} }
@ -2242,9 +2249,8 @@ public class ParserSymbolTable {
public List parameters; //parameter info for resolving functions public List parameters; //parameter info for resolving functions
public HashSet associated; //associated namespaces for argument dependant lookup public HashSet associated; //associated namespaces for argument dependant lookup
public ISymbol stopAt; //stop looking along the stack once we hit this declaration public ISymbol stopAt; //stop looking along the stack once we hit this declaration
public TypeFilter filter = null;
public TypeInfo.eType type = TypeInfo.t_any;
public TypeInfo.eType upperType = TypeInfo.t_undef;
public boolean qualified = false; public boolean qualified = false;
public boolean ignoreUsingDirectives = false; public boolean ignoreUsingDirectives = false;
public boolean usingDirectivesOnly = false; public boolean usingDirectivesOnly = false;
@ -2257,7 +2263,12 @@ public class ParserSymbolTable {
public LookupData( String n, TypeInfo.eType t, ISymbol i ){ public LookupData( String n, TypeInfo.eType t, ISymbol i ){
name = n; name = n;
type = t; filter = new TypeFilter( t );
templateInstance = i;
}
public LookupData( String n, TypeFilter f, ISymbol i ){
name = n;
filter = ( f != null ) ? f : new TypeFilter( TypeInfo.t_any );
templateInstance = i; templateInstance = i;
} }
} }
@ -2372,4 +2383,69 @@ public class ParserSymbolTable {
} }
} }
/**
* The visibility of the symbol is modified by the visibility of the base classes
* @param symbol
* @param qualifyingSymbol
* @return
*/
public static ASTAccessVisibility getVisibility(ISymbol symbol, IContainerSymbol qualifyingSymbol) throws ParserSymbolTableException {
IContainerSymbol container = symbol.getContainingSymbol();
if( qualifyingSymbol == null || container.equals( qualifyingSymbol ) ){
ISymbolASTExtension extension = symbol.getASTExtension();
IASTNode node = extension != null ? extension.getPrimaryDeclaration() : null;
if( node != null && node instanceof IASTMember ){
return ((IASTMember)node).getVisiblity();
} else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_InternalError );
}
}
if( ! (qualifyingSymbol instanceof IDerivableContainerSymbol) ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_InternalError );
}
List parents = ((IDerivableContainerSymbol) qualifyingSymbol).getParents();
Iterator iter = parents.iterator();
IParentSymbol parent = null;
ASTAccessVisibility symbolAccess = null;
ASTAccessVisibility parentAccess = null;
while( iter.hasNext() ){
parent = (IParentSymbol) iter.next();
if( container == parent.getParent() ){
parentAccess = parent.getAccess();
symbolAccess = ((IASTMember)symbol.getASTExtension().getPrimaryDeclaration()).getVisiblity();
return ( parentAccess.getEnumValue() > symbolAccess.getEnumValue() ) ? parentAccess : symbolAccess;
}
}
iter = parents.iterator();
//if static or an enumerator, the symbol could be visible through more than one path through the heirarchy,
//so we need to check all paths
boolean checkAllPaths = ( symbol.isType( TypeInfo.t_enumerator ) || symbol.getTypeInfo().checkBit( TypeInfo.isStatic ) );
ASTAccessVisibility resultingAccess = null;
while( iter.hasNext() ){
parent = (IParentSymbol) iter.next();
parentAccess = parent.getAccess();
symbolAccess = getVisibility( symbol, (IContainerSymbol) parent.getParent() );
if( symbolAccess != null ){
symbolAccess = ( parentAccess.getEnumValue() > symbolAccess.getEnumValue() ) ? parentAccess : symbolAccess;
if( checkAllPaths ){
if( resultingAccess != null )
resultingAccess = ( resultingAccess.getEnumValue() > symbolAccess.getEnumValue() ) ? symbolAccess : resultingAccess;
else
resultingAccess = symbolAccess;
} else {
return symbolAccess;
}
}
}
return resultingAccess;
}
} }

View file

@ -0,0 +1,117 @@
/*******************************************************************************
* Copyright (c) 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.core.parser.pst;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
/**
* @author aniefer
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class TypeFilter {
public TypeFilter(){
acceptedTypes.add( TypeInfo.t_any );
}
public TypeFilter( Set types ){
acceptedTypes.addAll( types );
}
public TypeFilter( TypeInfo.eType type ){
acceptedTypes.add( type );
}
public TypeFilter( LookupKind kind ){
acceptedKinds.add( kind );
populatedFilteredTypes( kind );
}
public void addFilteredType( TypeInfo.eType type ){
acceptedTypes.add( type );
}
public void addFilteredType( LookupKind kind ) {
populatedFilteredTypes( kind );
acceptedKinds.add( kind );
}
public boolean shouldAccept( ISymbol symbol ){
return shouldAccept( symbol, symbol.getTypeInfo() );
}
public boolean shouldAccept( ISymbol symbol, TypeInfo typeInfo ){
if( acceptedTypes.contains( TypeInfo.t_any ) ){
return true;
}
if( acceptedKinds.isEmpty() ){
return acceptedTypes.contains( typeInfo.getType() );
}
IContainerSymbol container = symbol.getContainingSymbol();
boolean symbolIsMember = container.isType( TypeInfo.t_class, TypeInfo.t_union );
boolean symbolIsLocal = container.isType( TypeInfo.t_constructor, TypeInfo.t_function ) ||
container.isType( TypeInfo.t_block );
if( typeInfo.isType( TypeInfo.t_function ) )
{
if( ( acceptedKinds.contains( LookupKind.FUNCTIONS ) && !symbolIsMember ) ||
( acceptedKinds.contains( LookupKind.METHODS ) && symbolIsMember ) )
{
return true;
} else {
return false;
}
}
else if ( typeInfo.isType( TypeInfo.t_type ) || typeInfo.isType( TypeInfo.t_bool, TypeInfo.t_enumerator ) )
{
if( ( acceptedKinds.contains( LookupKind.VARIABLES ) && !symbolIsMember && !symbolIsLocal ) ||
( acceptedKinds.contains( LookupKind.LOCAL_VARIABLES ) && !symbolIsMember && symbolIsLocal ) ||
( acceptedKinds.contains( LookupKind.FIELDS ) && symbolIsMember ) )
{
return true;
} else {
return false;
}
}
else
{
return acceptedTypes.contains( typeInfo.getType() );
}
}
/**
* @param lookupKind
*/
private void populatedFilteredTypes(LookupKind kind) {
if ( kind == LookupKind.STRUCTURES ) { acceptedTypes.add( TypeInfo.t_class );
acceptedTypes.add( TypeInfo.t_struct );
acceptedTypes.add( TypeInfo.t_union ); }
else if ( kind == LookupKind.STRUCS ) { acceptedTypes.add( TypeInfo.t_struct ); }
else if ( kind == LookupKind.UNIONS ) { acceptedTypes.add( TypeInfo.t_union ); }
else if ( kind == LookupKind.CLASSES ) { acceptedTypes.add( TypeInfo.t_class ); }
else if ( kind == LookupKind.CONSTRUCTORS ){ acceptedTypes.add( TypeInfo.t_constructor ); }
else if ( kind == LookupKind.NAMESPACES ) { acceptedTypes.add( TypeInfo.t_namespace ); }
else if ( kind == LookupKind.ENUMERATIONS ){ acceptedTypes.add( TypeInfo.t_enumeration ); }
else if ( kind == LookupKind.ENUMERATORS ) { acceptedTypes.add( TypeInfo.t_enumerator ); }
}
private Set acceptedTypes = new HashSet();
private Set acceptedKinds = new HashSet();
}

View file

@ -102,19 +102,20 @@ public class TypeInfo {
public static final TypeInfo.eType t_enumeration = new TypeInfo.eType( 6 ); public static final TypeInfo.eType t_enumeration = new TypeInfo.eType( 6 );
public static final TypeInfo.eType t_constructor = new TypeInfo.eType( 7 ); public static final TypeInfo.eType t_constructor = new TypeInfo.eType( 7 );
public static final TypeInfo.eType t_function = new TypeInfo.eType( 8 ); public static final TypeInfo.eType t_function = new TypeInfo.eType( 8 );
public static final TypeInfo.eType t_bool = new TypeInfo.eType( 9 ); public static final TypeInfo.eType t__Bool = new TypeInfo.eType( 9 );
public static final TypeInfo.eType t_char = new TypeInfo.eType( 10 ); public static final TypeInfo.eType t_bool = new TypeInfo.eType( 10 );
public static final TypeInfo.eType t_wchar_t = new TypeInfo.eType( 11 ); public static final TypeInfo.eType t_char = new TypeInfo.eType( 11 );
public static final TypeInfo.eType t_int = new TypeInfo.eType( 12 ); public static final TypeInfo.eType t_wchar_t = new TypeInfo.eType( 12 );
public static final TypeInfo.eType t_float = new TypeInfo.eType( 13 ); public static final TypeInfo.eType t_int = new TypeInfo.eType( 13 );
public static final TypeInfo.eType t_double = new TypeInfo.eType( 14 ); public static final TypeInfo.eType t_float = new TypeInfo.eType( 14 );
public static final TypeInfo.eType t_void = new TypeInfo.eType( 15 ); public static final TypeInfo.eType t_double = new TypeInfo.eType( 15 );
public static final TypeInfo.eType t_enumerator = new TypeInfo.eType( 16 ); public static final TypeInfo.eType t_void = new TypeInfo.eType( 16 );
public static final TypeInfo.eType t_block = new TypeInfo.eType( 17 ); public static final TypeInfo.eType t_enumerator = new TypeInfo.eType( 17 );
public static final TypeInfo.eType t_template = new TypeInfo.eType( 18 ); public static final TypeInfo.eType t_block = new TypeInfo.eType( 18 );
public static final TypeInfo.eType t_asm = new TypeInfo.eType( 19 ); public static final TypeInfo.eType t_template = new TypeInfo.eType( 19 );
public static final TypeInfo.eType t_linkage = new TypeInfo.eType( 20 ); public static final TypeInfo.eType t_asm = new TypeInfo.eType( 20 );
public static final TypeInfo.eType t__Bool = new TypeInfo.eType( 21 ); public static final TypeInfo.eType t_linkage = new TypeInfo.eType( 21 );
//public static final eType t_templateParameter = new eType( 18 ); //public static final eType t_templateParameter = new eType( 18 );
public static class eType implements Comparable{ public static class eType implements Comparable{