[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Fw: [cdt-dev] PST updates for 48306 & 48294
|
oops,
I accidently sent this to the wrong list yesterday.
-Andrew
----- Forwarded by Andrew Niefer/Ottawa/IBM on 12/10/2003 09:50 AM -----
Andrew Niefer/Ottawa/IBM@IBMCA
Sent by: cdt-dev-admin@xxxxxxxxxxx
12/09/2003 05:46 PM
Please respond to
cdt-dev
To
cdt-dev@xxxxxxxxxxx
cc
Subject
[cdt-dev] PST updates for 48306 & 48294
Core:
This patch creates a new class TypeFilter used by the symbol table to
allow code assist to specify what kinds of symbols it is looking for
(48306).
It also does a first pass at IContainerSymbol.isVisible (48294). If the
only requirement for having the ability to determine if a symbol is
visible or not due to access modifiers is so that content assist only
shows visibile results, then this would be more efficiently answered if
considered during the prefix lookup itself, so this code may mutate and
merge with the lookup code.
core.tests:
added ParserSymbolTableTests.testVisibilityDetermination()
added ParserSymbolTableTests.testPrefixFiltering
tested on windows
-Andrew
Index: ChangeLog
===================================================================
retrieving revision 1.150
diff -u -r1.150 ChangeLog
--- ChangeLog 9 Dec 2003 19:58:34 -0000 1.150
+++ ChangeLog 9 Dec 2003 22:21:11 -0000
@@ -1,3 +1,7 @@
+2003-12-09 Andrew Niefer
+ added ParserSymbolTableTests.testVisibilityDetermination()
+ added ParserSymbolTableTests.testPrefixFiltering
+
2003-12-09 Hoda Amer
Modified the Completion Proposal test to include case sensitivity
in the order of proposals.
Index: parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java
===================================================================
retrieving revision 1.26
diff -u -r1.26 ParserSymbolTableTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java 3 Dec 2003 21:48:12 -0000 1.26
+++ parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java 9 Dec 2003 22:21:14 -0000
@@ -11,6 +11,7 @@
package org.eclipse.cdt.core.parser.tests;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -20,6 +21,16 @@
import org.eclipse.cdt.core.parser.ParserLanguage;
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.IDerivableContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol;
@@ -29,6 +40,7 @@
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.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.ParserSymbolTable.Mark;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.OperatorExpression;
@@ -3010,7 +3022,7 @@
ISymbol anotherVar = table.newSymbol( "anotherVar", TypeInfo.t_int );
foo.addSymbol( anotherVar );
- List results = foo.prefixLookup( TypeInfo.t_any, "a", false );
+ List results = foo.prefixLookup( null, "a", false );
assertTrue( results != null );
assertEquals( results.size(), 2 );
@@ -3044,7 +3056,7 @@
D.addSymbol( aField );
D.addSymbol( aMethod );
- List results = D.prefixLookup( TypeInfo.t_any, "a", true );
+ List results = D.prefixLookup( null, "a", true );
assertTrue( results != null );
assertEquals( results.size(), 2 );
@@ -3096,7 +3108,7 @@
B.addSymbol( af2 );
- List results = B.prefixLookup( TypeInfo.t_any, "a", true );
+ List results = B.prefixLookup( null, "a", true );
assertTrue( results != null );
assertEquals( results.size(), 3 );
@@ -3161,7 +3173,7 @@
f.addUsingDirective( V );
f.addUsingDirective( W );
- List results = f.prefixLookup( TypeInfo.t_any, "a", false );
+ List results = f.prefixLookup( null, "a", false );
assertTrue( results != null );
assertEquals( results.size(), 1 );
@@ -3195,5 +3207,131 @@
assertEquals( null, A.qualifiedLookup( "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 ) );
+ };
+
}
Index: parser/ChangeLog-parser
===================================================================
retrieving revision 1.2
diff -u -r1.2 ChangeLog-parser
--- parser/ChangeLog-parser 9 Dec 2003 19:57:47 -0000 1.2
+++ parser/ChangeLog-parser 9 Dec 2003 22:45:05 -0000
@@ -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
Modified IASTCompletionNode.CompletionKind
modified IASTNode.LookupKind
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java
===================================================================
retrieving revision 1.3
diff -u -r1.3 ContainerSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java 3 Dec 2003 21:48:19 -0000 1.3
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java 9 Dec 2003 22:45:06 -0000
@@ -22,6 +22,9 @@
import java.util.ListIterator;
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.LookupData;
@@ -378,8 +381,10 @@
ISymbol foundSymbol = null;
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 );
if( data.foundItems != null ){
@@ -571,8 +576,8 @@
return null;
}
- public List prefixLookup( TypeInfo.eType type, String prefix, boolean qualified ) throws ParserSymbolTableException{
- LookupData data = new LookupData( prefix, type, getTemplateInstance() );
+ public List prefixLookup( TypeFilter filter, String prefix, boolean qualified ) throws ParserSymbolTableException{
+ LookupData data = new LookupData( prefix, filter, getTemplateInstance() );
data.qualified = qualified;
data.mode = ParserSymbolTable.LookupMode.PREFIX;
@@ -605,6 +610,45 @@
return list;
}
+ }
+
+ 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)
Index: parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java
===================================================================
retrieving revision 1.9
diff -u -r1.9 IContainerSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java 3 Dec 2003 21:48:19 -0000 1.9
+++ parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java 9 Dec 2003 22:45:07 -0000
@@ -39,7 +39,7 @@
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 lookup( String name ) throws ParserSymbolTableException;
@@ -53,4 +53,6 @@
public IParameterizedSymbol qualifiedFunctionLookup( String name, List parameters ) throws ParserSymbolTableException;
public TemplateInstance templateLookup( String name, List arguments ) throws ParserSymbolTableException;
public TemplateInstance instantiate( List arguments ) throws ParserSymbolTableException;
+
+ public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol );
}
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
===================================================================
retrieving revision 1.28
diff -u -r1.28 ParserSymbolTable.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java 3 Dec 2003 21:48:19 -0000 1.28
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java 9 Dec 2003 22:45:07 -0000
@@ -25,6 +25,9 @@
import org.eclipse.cdt.core.parser.Enum;
import org.eclipse.cdt.core.parser.ParserLanguage;
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;
/**
@@ -90,9 +93,9 @@
*/
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 ){
- throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
- }
+// 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 );
+// }
//handle namespace aliases
if( inSymbol.isType( TypeInfo.t_namespace ) ){
@@ -352,22 +355,26 @@
private static boolean nameMatches( LookupData data, String name ){
if( data.mode == LookupMode.PREFIX ){
- return name.startsWith( data.name );
+ return name.regionMatches( true, 0, data.name, 0, data.name.length() );
} else {
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( symbol.isType( TypeInfo.t_type ) ){
symbol = symbol.getTypeSymbol();
}
if( symbol.isType( TypeInfo.t_undef ) && symbol.getContainingSymbol().isType( TypeInfo.t_template ) ){
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 {
@@ -385,7 +392,7 @@
IContainerSymbol cls = 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 )
foundSymbol = new TemplateInstance( symbol.getSymbolTable(), symbol, data.templateInstance.getArgumentMap() );
else
@@ -1110,7 +1117,7 @@
*
* 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 );
}
@@ -2242,9 +2249,8 @@
public List parameters; //parameter info for resolving functions
public HashSet associated; //associated namespaces for argument dependant lookup
public ISymbol stopAt; //stop looking along the stack once we hit this declaration
-
- public TypeInfo.eType type = TypeInfo.t_any;
- public TypeInfo.eType upperType = TypeInfo.t_undef;
+ public TypeFilter filter = null;
+
public boolean qualified = false;
public boolean ignoreUsingDirectives = false;
public boolean usingDirectivesOnly = false;
@@ -2257,7 +2263,12 @@
public LookupData( String n, TypeInfo.eType t, ISymbol i ){
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;
}
}
@@ -2372,4 +2383,69 @@
}
}
+ /**
+ * 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;
+ }
}
Index: parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java
===================================================================
retrieving revision 1.7
diff -u -r1.7 TypeInfo.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java 20 Nov 2003 15:22:56 -0000 1.7
+++ parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java 9 Dec 2003 22:45:07 -0000
@@ -102,19 +102,20 @@
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_function = new TypeInfo.eType( 8 );
- 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_wchar_t = new TypeInfo.eType( 11 );
- public static final TypeInfo.eType t_int = new TypeInfo.eType( 12 );
- public static final TypeInfo.eType t_float = new TypeInfo.eType( 13 );
- public static final TypeInfo.eType t_double = new TypeInfo.eType( 14 );
- public static final TypeInfo.eType t_void = new TypeInfo.eType( 15 );
- public static final TypeInfo.eType t_enumerator = new TypeInfo.eType( 16 );
- public static final TypeInfo.eType t_block = new TypeInfo.eType( 17 );
- public static final TypeInfo.eType t_template = new TypeInfo.eType( 18 );
- public static final TypeInfo.eType t_asm = new TypeInfo.eType( 19 );
- public static final TypeInfo.eType t_linkage = new TypeInfo.eType( 20 );
- public static final TypeInfo.eType t__Bool = new TypeInfo.eType( 21 );
+ public static final TypeInfo.eType t__Bool = new TypeInfo.eType( 9 );
+ public static final TypeInfo.eType t_bool = new TypeInfo.eType( 10 );
+ public static final TypeInfo.eType t_char = new TypeInfo.eType( 11 );
+ public static final TypeInfo.eType t_wchar_t = new TypeInfo.eType( 12 );
+ public static final TypeInfo.eType t_int = new TypeInfo.eType( 13 );
+ public static final TypeInfo.eType t_float = new TypeInfo.eType( 14 );
+ public static final TypeInfo.eType t_double = new TypeInfo.eType( 15 );
+ public static final TypeInfo.eType t_void = new TypeInfo.eType( 16 );
+ public static final TypeInfo.eType t_enumerator = new TypeInfo.eType( 17 );
+ public static final TypeInfo.eType t_block = new TypeInfo.eType( 18 );
+ public static final TypeInfo.eType t_template = new TypeInfo.eType( 19 );
+ public static final TypeInfo.eType t_asm = new TypeInfo.eType( 20 );
+ public static final TypeInfo.eType t_linkage = new TypeInfo.eType( 21 );
+
//public static final eType t_templateParameter = new eType( 18 );
public static class eType implements Comparable{
Index: parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java
diff -N parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java 1 Jan 1970 00:00:00 -0000
@@ -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();
+}