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

Add IASTQualifiedNameElement.getFullyQualifiedNameCharArrays()

and modify Search to take advantage of the IAST providing char[]s.
This commit is contained in:
Andrew Niefer 2004-08-10 20:40:14 +00:00
parent a23d2613ac
commit 04b2ae06b5
22 changed files with 78 additions and 74 deletions

View file

@ -17,4 +17,5 @@ package org.eclipse.cdt.core.parser.ast;
public interface IASTQualifiedNameElement
{
public String[] getFullyQualifiedName();
public char[][] getFullyQualifiedNameCharArrays();
}

View file

@ -73,6 +73,10 @@ public class ASTQualifiedNamedElement implements IASTQualifiedNameElement
}
return result;
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedNames;
}
private final char[][] qualifiedNames;

View file

@ -212,6 +212,9 @@ public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope()
*/

View file

@ -109,7 +109,9 @@ public class ASTElaboratedTypeSpecifier extends ASTSymbol implements IASTElabora
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
public List getReferences()
{
return references;

View file

@ -124,6 +124,9 @@ public class ASTEnumerationSpecifier
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager)

View file

@ -160,6 +160,9 @@ public class ASTFunction extends ASTScope implements IASTFunction
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/

View file

@ -108,6 +108,9 @@ public class ASTNamespaceDefinition
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
public Iterator getDeclarations()
{

View file

@ -115,6 +115,9 @@ public class ASTTypedef extends ASTSymbol implements IASTTypedefDeclaration
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration#getFinalTypeSpecifier()

View file

@ -144,6 +144,9 @@ public class ASTVariable extends ASTSymbol implements IASTVariable
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope()
*/

View file

@ -81,6 +81,9 @@ public class ASTElaboratedTypeSpecifier extends ASTNode implements IASTElaborate
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/

View file

@ -148,6 +148,9 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/

View file

@ -74,6 +74,9 @@ public class ASTNamespaceDefinition extends ASTDeclaration implements IASTNamesp
{
return qualifiedNameElement.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedNameElement.getFullyQualifiedNameCharArrays();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/

View file

@ -75,6 +75,9 @@ public class ASTTypedefDeclaration extends ASTDeclaration implements IASTTypedef
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/

View file

@ -147,6 +147,9 @@ public class ASTVariable extends ASTDeclaration implements IASTVariable
{
return qualifiedName.getFullyQualifiedName();
}
public char[][] getFullyQualifiedNameCharArrays(){
return qualifiedName.getFullyQualifiedNameCharArrays();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/

View file

@ -630,11 +630,13 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
}
return false;
}
protected boolean matchQualifications( char[][] qualifications, char[][] candidate ){
return matchQualifications( qualifications, candidate, false );
}
protected boolean matchQualifications( char[][] qualifications, char[][] candidate, boolean skipLastName ){
int qualLength = qualifications != null ? qualifications.length : 0;
int candidateLength = candidate != null ? candidate.length : 0;
int candidateLength = candidate != null ? candidate.length - ( skipLastName ? 1 : 0 ) : 0;
if( qualLength == 0 ){
return true;

View file

@ -86,32 +86,27 @@ public class ClassDeclarationPattern extends CSearchPattern {
if( ! canAccept( limit ) )
return IMPOSSIBLE_MATCH;
String nodeName = null;
char[] nodeName = null;
if (node instanceof IASTElaboratedTypeSpecifier)
{
nodeName = ((IASTElaboratedTypeSpecifier)node).getName();
nodeName = ((IASTElaboratedTypeSpecifier)node).getNameCharArray();
}
else if( node instanceof IASTOffsetableNamedElement )
{
nodeName = ((IASTOffsetableNamedElement)node).getName();
nodeName = ((IASTOffsetableNamedElement)node).getNameCharArray();
} else {
return IMPOSSIBLE_MATCH;
}
//check name, if simpleName == null, its treated the same as "*"
if( simpleName != null && !matchesName( simpleName, nodeName.toCharArray() ) ){
if( simpleName != null && !matchesName( simpleName, nodeName ) ){
return IMPOSSIBLE_MATCH;
}
if( node instanceof IASTQualifiedNameElement ){
//create char[][] out of full name,
String [] fullName = ((IASTQualifiedNameElement) node).getFullyQualifiedName();
char [][] qualName = new char [ fullName.length - 1 ][];
for( int i = 0; i < fullName.length - 1; i++ ){
qualName[i] = fullName[i].toCharArray();
}
char [][] qualName = ((IASTQualifiedNameElement) node).getFullyQualifiedNameCharArrays();
//check containing scopes
if( !matchQualifications( qualifications, qualName ) ){
if( !matchQualifications( qualifications, qualName, true ) ){
return IMPOSSIBLE_MATCH;
}
}

View file

@ -86,24 +86,16 @@ public class DerivedTypesPattern extends ClassDeclarationPattern {
} catch (ASTNotImplementedException e) {}
if (typeSpec instanceof IASTClassSpecifier){
IASTClassSpecifier baseClassSpec = (IASTClassSpecifier) typeSpec;
String[] baseFullyQualifiedName = baseClassSpec.getFullyQualifiedName();
//check name, if simpleName == null, its treated the same as "*"
if( simpleName != null && !matchesName( simpleName, baseClassSpec.getName().toCharArray() ) ){
if( simpleName != null && !matchesName( simpleName, baseClassSpec.getNameCharArray() ) ){
continue;
}
char [][] qualName = new char [ baseFullyQualifiedName.length - 1 ][];
for( int j = 0; j < baseFullyQualifiedName.length - 1; j++ ){
qualName[j] = baseFullyQualifiedName[j].toCharArray();
}
char [][] qualName = baseClassSpec.getFullyQualifiedNameCharArrays();
//check containing scopes
if( !matchQualifications( qualifications, qualName ) ){
if( !matchQualifications( qualifications, qualName, true ) ){
continue;
}
matchFlag = true;
break;
}

View file

@ -75,42 +75,30 @@ public class FieldDeclarationPattern extends CSearchPattern {
} else return IMPOSSIBLE_MATCH;
String nodeName = ((IASTOffsetableNamedElement)node).getName();
char[] nodeName = ((IASTOffsetableNamedElement)node).getNameCharArray();
//check name, if simpleName == null, its treated the same as "*"
if( simpleName != null && !matchesName( simpleName, nodeName.toCharArray() ) ){
if( simpleName != null && !matchesName( simpleName, nodeName ) ){
return IMPOSSIBLE_MATCH;
}
//check containing scopes
//create char[][] out of full name,
String [] fullName = null;
char [][] qualName = null;
if( node instanceof IASTEnumerator ){
//Enumerators don't derive from IASTQualifiedElement, so make the fullName
//from the enumerations name.
// 7.2 - 10 : each enumerator declared by an enum-specifier is declared in the
//scope that immediately contains the enum-specifier.
IASTEnumerationSpecifier enumeration = ((IASTEnumerator)node).getOwnerEnumerationSpecifier();
fullName = enumeration.getFullyQualifiedName();
String[] enumeratorFullName = new String[ fullName.length ];
System.arraycopy( fullName, 0, enumeratorFullName, 0, fullName.length);
enumeratorFullName[ fullName.length - 1 ] = nodeName;
fullName = enumeratorFullName;
qualName = enumeration.getFullyQualifiedNameCharArrays();
} else if( node instanceof IASTQualifiedNameElement ){
fullName = ((IASTQualifiedNameElement) node).getFullyQualifiedName();
qualName = ((IASTQualifiedNameElement) node).getFullyQualifiedNameCharArrays();
}
if( fullName != null ){
char [][] qualName = new char [ fullName.length - 1 ][];
for( int i = 0; i < fullName.length - 1; i++ ){
qualName[i] = fullName[i].toCharArray();
}
if( qualName != null ){
//check containing scopes
if( !matchQualifications( qualifications, qualName ) ){
if( !matchQualifications( qualifications, qualName, true ) ){
return IMPOSSIBLE_MATCH;
}
}

View file

@ -76,37 +76,33 @@ public class FriendPattern extends ClassDeclarationPattern {
Iterator i = tempNode.getFriends();
boolean matchFlag=false;
String[] fullName=null;
while (i.hasNext()){
Object friend = i.next();
String[] baseFullyQualifiedName = null;
char [][] qualName = null;
if (friend instanceof IASTClassSpecifier)
{
IASTClassSpecifier classSpec = (IASTClassSpecifier) friend;
baseFullyQualifiedName = classSpec.getFullyQualifiedName();
qualName = classSpec.getFullyQualifiedNameCharArrays();
//check name, if simpleName == null, its treated the same as "*"
if( simpleName != null && !matchesName( simpleName, classSpec.getName().toCharArray() ) ){
if( simpleName != null && !matchesName( simpleName, classSpec.getNameCharArray() ) ){
continue;
}
}
else if (friend instanceof IASTElaboratedTypeSpecifier ){
IASTElaboratedTypeSpecifier elabType = (IASTElaboratedTypeSpecifier) friend;
baseFullyQualifiedName = elabType.getFullyQualifiedName();
qualName = elabType.getFullyQualifiedNameCharArrays();
//check name, if simpleName == null, its treated the same as "*"
if( simpleName != null && !matchesName( simpleName, elabType.getName().toCharArray() ) ){
if( simpleName != null && !matchesName( simpleName, elabType.getNameCharArray() ) ){
continue;
}
}
if (baseFullyQualifiedName != null){
char [][] qualName = new char [ baseFullyQualifiedName.length - 1 ][];
for( int j = 0; j < baseFullyQualifiedName.length - 1; j++ ){
qualName[j] = baseFullyQualifiedName[j].toCharArray();
}
if (qualName!= null){
//check containing scopes
if( !matchQualifications( qualifications, qualName ) ){
if( !matchQualifications( qualifications, qualName, true ) ){
continue;
}

View file

@ -54,10 +54,10 @@ public class MacroDeclarationPattern extends CSearchPattern {
return IMPOSSIBLE_MATCH;
}
String nodeName = ((IASTOffsetableNamedElement)node).getName();
char[] nodeName = ((IASTOffsetableNamedElement)node).getNameCharArray();
//check name, if simpleName == null, its treated the same as "*"
if( simpleName != null && !matchesName( simpleName, nodeName.toCharArray() ) ){
if( simpleName != null && !matchesName( simpleName, nodeName ) ){
return IMPOSSIBLE_MATCH;
}

View file

@ -74,23 +74,18 @@ public class MethodDeclarationPattern extends CSearchPattern {
}
IASTFunction function = (IASTFunction) node;
String nodeName = function.getName();
char[] nodeName = function.getNameCharArray();
//check name, if simpleName == null, its treated the same as "*"
if( simpleName != null && !matchesName( simpleName, nodeName.toCharArray() ) ){
if( simpleName != null && !matchesName( simpleName, nodeName ) ){
return IMPOSSIBLE_MATCH;
}
if( node instanceof IASTQualifiedNameElement ){
//create char[][] out of full name,
String [] fullName = ((IASTQualifiedNameElement) node).getFullyQualifiedName();
char [][] qualName = new char [ fullName.length - 1 ][];
for( int i = 0; i < fullName.length - 1; i++ ){
qualName[i] = fullName[i].toCharArray();
}
char [][] qualName = ((IASTQualifiedNameElement) node).getFullyQualifiedNameCharArrays();
//check containing scopes
if( !matchQualifications( qualifications, qualName ) ){
if( !matchQualifications( qualifications, qualName, true ) ){
return IMPOSSIBLE_MATCH;
}
}

View file

@ -57,18 +57,14 @@ public class NamespaceDeclarationPattern extends CSearchPattern {
IASTNamespaceDefinition namespace = (IASTNamespaceDefinition)node;
if( simpleName != null && !matchesName( simpleName, namespace.getName().toCharArray() ) ){
if( simpleName != null && !matchesName( simpleName, namespace.getNameCharArray() ) ){
return IMPOSSIBLE_MATCH;
}
//create char[][] out of full name,
String [] fullName = namespace.getFullyQualifiedName();
char [] [] qualName = new char [ fullName.length - 1 ][];
for( int i = 0; i < fullName.length - 1; i++ ){
qualName[i] = fullName[i].toCharArray();
}
char [] [] qualName = namespace.getFullyQualifiedNameCharArrays();
if( !matchQualifications( qualifications, qualName ) ){
if( !matchQualifications( qualifications, qualName, true ) ){
return IMPOSSIBLE_MATCH;
}