mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
work for bug 50807
This commit is contained in:
parent
66678f3126
commit
2ae68378fa
6 changed files with 129 additions and 58 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
2004-04-16 Andrew Niefer
|
||||||
|
refactor ASTNode.lookup, partially addressing bug 50807
|
||||||
|
|
||||||
2004-04-15 David Daoust
|
2004-04-15 David Daoust
|
||||||
Modified Scanner Performance by
|
Modified Scanner Performance by
|
||||||
1. Moved ScannerContext sentinal to ContextStack
|
1. Moved ScannerContext sentinal to ContextStack
|
||||||
|
|
|
@ -23,7 +23,13 @@ import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplate;
|
import org.eclipse.cdt.core.parser.ast.IASTTemplate;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
|
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol;
|
import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
|
||||||
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -206,4 +212,34 @@ public class ASTMethod extends ASTFunction implements IASTMethod
|
||||||
|
|
||||||
return (IASTClassSpecifier) getOwnerScope();
|
return (IASTClassSpecifier) getOwnerScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param prefix
|
||||||
|
* @param thisContainer
|
||||||
|
* @param qualification
|
||||||
|
* @param lookInThis
|
||||||
|
* @param filter
|
||||||
|
* @param lookupResults
|
||||||
|
* @return
|
||||||
|
* @throws LookupError
|
||||||
|
*/
|
||||||
|
protected List performPrefixLookup(String prefix, IContainerSymbol thisContainer, IContainerSymbol qualification, TypeFilter filter) throws LookupError {
|
||||||
|
if( filter.isLookingInThis() ){
|
||||||
|
try{
|
||||||
|
ISymbol thisPointer = thisContainer.lookup( ParserSymbolTable.THIS );
|
||||||
|
ISymbol thisClass = ( thisPointer != null ) ? thisPointer.getTypeSymbol() : null;
|
||||||
|
if( thisClass != null && thisClass instanceof IContainerSymbol ){
|
||||||
|
return ((IContainerSymbol) thisClass).prefixLookup( filter, prefix, true );
|
||||||
|
}
|
||||||
|
} catch (ParserSymbolTableException e) {
|
||||||
|
throw new LookupError();
|
||||||
|
} catch (ParserSymbolTableError e ){
|
||||||
|
throw new LookupError();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return super.performPrefixLookup( prefix, thisContainer, qualification, filter );
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.util.ListIterator;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.SymbolIterator;
|
import org.eclipse.cdt.internal.core.parser.ast.SymbolIterator;
|
||||||
|
@ -24,7 +25,6 @@ import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol;
|
import org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
|
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner;
|
import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError;
|
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError;
|
||||||
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.TypeFilter;
|
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
|
||||||
|
@ -44,52 +44,23 @@ public class ASTNode implements IASTNode {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
IContainerSymbol thisContainer = (IContainerSymbol) ((ISymbolOwner)this).getSymbol();
|
IExtensibleSymbol symbol = ((ISymbolOwner)this).getSymbol();
|
||||||
IContainerSymbol qualification = null;
|
if( symbol == null || !(symbol instanceof IContainerSymbol) ){
|
||||||
|
throw new LookupError();
|
||||||
|
}
|
||||||
|
IContainerSymbol thisContainer = (IContainerSymbol) symbol;
|
||||||
|
IContainerSymbol qualification = getQualificationSymbol(context);
|
||||||
|
|
||||||
if( thisContainer.getSymbolTable().getParserMode() != ParserMode.COMPLETION_PARSE ){
|
if( thisContainer.getSymbolTable().getParserMode() != ParserMode.COMPLETION_PARSE ){
|
||||||
throw new ASTNotImplementedException();
|
throw new ASTNotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( context != null ){
|
|
||||||
ISymbol sym = null;
|
|
||||||
if( context instanceof IASTTypedefDeclaration ){
|
|
||||||
ISymbol typedef = ((ISymbolOwner)context).getSymbol();
|
|
||||||
TypeInfo info = null;
|
|
||||||
try{
|
|
||||||
info = typedef.getTypeInfo().getFinalType();
|
|
||||||
} catch( ParserSymbolTableError e ){
|
|
||||||
throw new LookupError();
|
|
||||||
}
|
|
||||||
sym = info.getTypeSymbol();
|
|
||||||
} else if ( context instanceof IASTVariable ){
|
|
||||||
sym = ((ISymbolOwner)context).getSymbol().getTypeSymbol(); // good enough for now
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sym = (IContainerSymbol) ((ISymbolOwner)context).getSymbol();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( sym == null || !(sym instanceof IContainerSymbol) ){
|
|
||||||
throw new LookupError();
|
|
||||||
}
|
|
||||||
qualification = (IContainerSymbol) sym;
|
|
||||||
}
|
|
||||||
|
|
||||||
ISymbolOwner owner = (ISymbolOwner) this;
|
|
||||||
IExtensibleSymbol symbol = owner.getSymbol();
|
|
||||||
if( symbol == null || !(symbol instanceof IContainerSymbol) ){
|
|
||||||
throw new LookupError();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean lookInThis = false;
|
|
||||||
|
|
||||||
TypeFilter filter = new TypeFilter();
|
TypeFilter filter = new TypeFilter();
|
||||||
if( kind != null ){
|
if( kind != null ){
|
||||||
for( int i = 0; i < kind.length; i++ ){
|
for( int i = 0; i < kind.length; i++ ){
|
||||||
filter.addAcceptedType( kind[i] );
|
filter.addAcceptedType( kind[i] );
|
||||||
if( kind[i] == LookupKind.THIS ){
|
if( kind[i] == LookupKind.THIS ){
|
||||||
lookInThis = true;
|
filter.setLookingInThis( true );
|
||||||
if( kind.length == 1 ){
|
if( kind.length == 1 ){
|
||||||
filter.addAcceptedType( LookupKind.ALL );
|
filter.addAcceptedType( LookupKind.ALL );
|
||||||
}
|
}
|
||||||
|
@ -101,24 +72,7 @@ public class ASTNode implements IASTNode {
|
||||||
filter.addAcceptedType( LookupKind.ALL );
|
filter.addAcceptedType( LookupKind.ALL );
|
||||||
}
|
}
|
||||||
|
|
||||||
List lookupResults = null;
|
List lookupResults = performPrefixLookup(prefix, thisContainer, qualification, filter);
|
||||||
try {
|
|
||||||
if( lookInThis ){
|
|
||||||
ISymbol thisPointer = thisContainer.lookup( ParserSymbolTable.THIS );
|
|
||||||
ISymbol thisClass = ( thisPointer != null ) ? thisPointer.getTypeSymbol() : null;
|
|
||||||
if( thisClass != null && thisClass instanceof IContainerSymbol ){
|
|
||||||
lookupResults = ((IContainerSymbol) thisClass).prefixLookup( filter, prefix, true );
|
|
||||||
}
|
|
||||||
} else if( qualification != null ){
|
|
||||||
lookupResults = qualification.prefixLookup( filter, prefix, true );
|
|
||||||
} else {
|
|
||||||
lookupResults = thisContainer.prefixLookup( filter, prefix, false );
|
|
||||||
}
|
|
||||||
} catch (ParserSymbolTableException e) {
|
|
||||||
throw new LookupError();
|
|
||||||
} catch (ParserSymbolTableError e ){
|
|
||||||
throw new LookupError();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(lookupResults == null)
|
if(lookupResults == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -140,6 +94,67 @@ public class ASTNode implements IASTNode {
|
||||||
return new Result( prefix, iterator, lookupResults.size() );
|
return new Result( prefix, iterator, lookupResults.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param prefix
|
||||||
|
* @param thisContainer
|
||||||
|
* @param qualification
|
||||||
|
* @param lookInThis
|
||||||
|
* @param filter
|
||||||
|
* @param lookupResults
|
||||||
|
* @return
|
||||||
|
* @throws LookupError
|
||||||
|
*/
|
||||||
|
protected List performPrefixLookup(String prefix, IContainerSymbol thisContainer, IContainerSymbol qualification, TypeFilter filter) throws LookupError {
|
||||||
|
List results = null;
|
||||||
|
try {
|
||||||
|
if( qualification != null ){
|
||||||
|
results = qualification.prefixLookup( filter, prefix, true );
|
||||||
|
} else {
|
||||||
|
results = thisContainer.prefixLookup( filter, prefix, false );
|
||||||
|
}
|
||||||
|
} catch (ParserSymbolTableException e) {
|
||||||
|
throw new LookupError();
|
||||||
|
} catch (ParserSymbolTableError e ){
|
||||||
|
throw new LookupError();
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param context
|
||||||
|
* @param qualification
|
||||||
|
* @return
|
||||||
|
* @throws LookupError
|
||||||
|
*/
|
||||||
|
protected IContainerSymbol getQualificationSymbol(IASTNode context) throws LookupError {
|
||||||
|
if( context == null )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
ISymbol sym = null;
|
||||||
|
if( context instanceof IASTTypedefDeclaration ||
|
||||||
|
context instanceof IASTVariable ||
|
||||||
|
context instanceof IASTParameterDeclaration )
|
||||||
|
{
|
||||||
|
sym = ((ISymbolOwner)context).getSymbol();
|
||||||
|
TypeInfo info = null;
|
||||||
|
try{
|
||||||
|
info = sym.getTypeInfo().getFinalType();
|
||||||
|
} catch( ParserSymbolTableError e ){
|
||||||
|
throw new LookupError();
|
||||||
|
}
|
||||||
|
sym = info.getTypeSymbol();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sym = (IContainerSymbol) ((ISymbolOwner)context).getSymbol();
|
||||||
|
}
|
||||||
|
|
||||||
|
if( sym == null || !(sym instanceof IContainerSymbol) ){
|
||||||
|
throw new LookupError();
|
||||||
|
}
|
||||||
|
return (IContainerSymbol) sym;
|
||||||
|
}
|
||||||
|
|
||||||
private class Result implements ILookupResult{
|
private class Result implements ILookupResult{
|
||||||
private String prefix;
|
private String prefix;
|
||||||
private Iterator iterator;
|
private Iterator iterator;
|
||||||
|
|
|
@ -123,7 +123,15 @@ public class TypeFilter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLookingInThis( boolean inThis ){
|
||||||
|
lookingInThis = inThis;
|
||||||
|
}
|
||||||
|
public boolean isLookingInThis(){
|
||||||
|
return lookingInThis;
|
||||||
|
}
|
||||||
|
|
||||||
private Set acceptedTypes = new HashSet();
|
private Set acceptedTypes = new HashSet();
|
||||||
private Set acceptedKinds = new HashSet();
|
private Set acceptedKinds = new HashSet();
|
||||||
|
|
||||||
|
private boolean lookingInThis = false;
|
||||||
}
|
}
|
|
@ -1,3 +1,6 @@
|
||||||
|
2004-04-16 Andrew Niefer
|
||||||
|
modify CompletionEngine.completionOnFunctionReference for bug 50807
|
||||||
|
|
||||||
2004-04-16 Hoda Amer
|
2004-04-16 Hoda Amer
|
||||||
Fix for bug#44370 : [Content Assist] function-style macros have arguments
|
Fix for bug#44370 : [Content Assist] function-style macros have arguments
|
||||||
|
|
||||||
|
|
|
@ -628,10 +628,16 @@ public class CompletionEngine implements RelevanceConstants {
|
||||||
// and examples. If my assumptions are not correct as to what deserves to be
|
// and examples. If my assumptions are not correct as to what deserves to be
|
||||||
// looked up for FUNCTION_REFRENCE then please update the documentation in
|
// looked up for FUNCTION_REFRENCE then please update the documentation in
|
||||||
// IASTCompletionNode.java.
|
// IASTCompletionNode.java.
|
||||||
|
|
||||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
|
||||||
kinds[0] = IASTNode.LookupKind.ALL;
|
|
||||||
String prefix = completionNode.getCompletionPrefix();
|
String prefix = completionNode.getCompletionPrefix();
|
||||||
|
|
||||||
|
IASTNode.LookupKind[] kinds = null;
|
||||||
|
if( prefix.length() == 0 )
|
||||||
|
{
|
||||||
|
kinds = new IASTNode.LookupKind[] { IASTNode.LookupKind.CONSTRUCTORS, IASTNode.LookupKind.FUNCTIONS, IASTNode.LookupKind.METHODS };
|
||||||
|
prefix = completionNode.getFunctionName();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
kinds = new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL };
|
||||||
|
|
||||||
ILookupResult result = lookup(completionNode.getCompletionScope(), prefix, kinds, completionNode.getCompletionContext());
|
ILookupResult result = lookup(completionNode.getCompletionScope(), prefix, kinds, completionNode.getCompletionContext());
|
||||||
addToCompletions(result);
|
addToCompletions(result);
|
||||||
|
|
Loading…
Add table
Reference in a new issue