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

Fix for PR 93573: "[Indexer] endl references are not added to the DOM index"

Fixed different encoding of functions references vs. declarations in the index.
Applied Devin's patch for PR 101114: "[AST Util] Inconsistent string representation of IType elements" with slight modifications.
Modified JUnit tests accordingly.
This commit is contained in:
Vladimir Hirsl 2005-06-22 21:10:11 +00:00
parent 828b704126
commit e28ba5192f
7 changed files with 130 additions and 74 deletions

View file

@ -61,39 +61,46 @@ public class AST2UtilTests extends AST2BaseTest {
buff.append("int * b(char y, int x);\n"); //$NON-NLS-1$
buff.append("void c(int * z, float **b);\n"); //$NON-NLS-1$
buff.append("static int d(int a[restrict]);\n"); //$NON-NLS-1$
buff.append("void e(const char* const);\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C);
IASTDeclaration[] d = tu.getDeclarations();
isParameterSignatureEqual(((IASTSimpleDeclaration)d[0]).getDeclarators()[0], "(int)"); //$NON-NLS-1$
isParameterSignatureEqual(((IASTSimpleDeclaration)d[1]).getDeclarators()[0], "(char, int)"); //$NON-NLS-1$
isParameterSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "(int *, float **)"); //$NON-NLS-1$
isParameterSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "(int *, float * *)"); //$NON-NLS-1$
isParameterSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclarators()[0], "(int [restrict])"); //$NON-NLS-1$
isParameterSignatureEqual(((IASTSimpleDeclaration)d[4]).getDeclarators()[0], "(const char * const)"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[0]).getDeclarators()[0], "int (int)"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[1]).getDeclarators()[0], "int *(char, int)"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "void (int *, float **)"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "void (int *, float * *)"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclarators()[0], "static int (int [restrict])"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[4]).getDeclarators()[0], "void (const char * const)"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[0]).getDeclSpecifier(), "int"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[1]).getDeclSpecifier(), "int"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclSpecifier(), "void"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclSpecifier(), "static int"); //$NON-NLS-1$
isSignatureEqual(((IASTSimpleDeclaration)d[4]).getDeclSpecifier(), "void"); //$NON-NLS-1$
isTypeEqual(((IASTSimpleDeclaration)d[0]).getDeclarators()[0], "int (int)"); //$NON-NLS-1$
isTypeEqual(((IASTSimpleDeclaration)d[1]).getDeclarators()[0], "int * (char, int)"); //$NON-NLS-1$
isTypeEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "void (int *, float * *)"); //$NON-NLS-1$
isTypeEqual(((IASTSimpleDeclaration)d[3]).getDeclarators()[0], "int (int * restrict)"); //$NON-NLS-1$
isTypeEqual(((IASTSimpleDeclaration)d[4]).getDeclarators()[0], "void (const char * const)"); //$NON-NLS-1$
isTypeEqual(((IFunction)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getName().resolveBinding()).getType(), "int (int)"); //$NON-NLS-1$
isTypeEqual(((IFunction)((IASTSimpleDeclaration)d[1]).getDeclarators()[0].getName().resolveBinding()).getType(), "int * (char, int)"); //$NON-NLS-1$
isTypeEqual(((IFunction)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getName().resolveBinding()).getType(), "void (int *, float * *)"); //$NON-NLS-1$
isTypeEqual(((IFunction)((IASTSimpleDeclaration)d[3]).getDeclarators()[0].getName().resolveBinding()).getType(), "int (int * restrict)"); //$NON-NLS-1$
isTypeEqual(((IFunction)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getName().resolveBinding()).getType(), "void (const char * const)"); //$NON-NLS-1$
isParameterTypeEqual(((IFunction)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getName().resolveBinding()).getType(), "(int)"); //$NON-NLS-1$
isParameterTypeEqual(((IFunction)((IASTSimpleDeclaration)d[1]).getDeclarators()[0].getName().resolveBinding()).getType(), "(char, int)"); //$NON-NLS-1$
isParameterTypeEqual(((IFunction)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getName().resolveBinding()).getType(), "(int *, float * *)"); //$NON-NLS-1$
isParameterTypeEqual(((IFunction)((IASTSimpleDeclaration)d[3]).getDeclarators()[0].getName().resolveBinding()).getType(), "(int * restrict)"); //$NON-NLS-1$
isParameterTypeEqual(((IFunction)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getName().resolveBinding()).getType(), "(const char * const)"); //$NON-NLS-1$
}
public void testSimpleCParameterSignature() throws Exception {
@ -108,7 +115,7 @@ public class AST2UtilTests extends AST2BaseTest {
isParameterSignatureEqual(((IASTSimpleDeclaration)d[0]).getDeclarators()[0], "(int)"); //$NON-NLS-1$
isParameterSignatureEqual(((IASTSimpleDeclaration)d[1]).getDeclarators()[0], "(char, int)"); //$NON-NLS-1$
isParameterSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "(int *, float **)"); //$NON-NLS-1$
isParameterSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "(int *, float * *)"); //$NON-NLS-1$
isParameterSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclarators()[0], "(int [restrict])"); //$NON-NLS-1$
}
@ -127,12 +134,12 @@ public class AST2UtilTests extends AST2BaseTest {
// verify signatures
isSignatureEqual( ((IASTTypeIdExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId(), "int"); //$NON-NLS-1$
isSignatureEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "union"); //$NON-NLS-1$
isSignatureEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "Squaw"); //$NON-NLS-1$
isSignatureEqual( ((IASTCastExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId() , "jc"); //$NON-NLS-1$
// verify types
isTypeEqual( ((IASTTypeIdExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId(), "int"); //$NON-NLS-1$
isTypeEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "union Squaw"); //$NON-NLS-1$
isTypeEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "Squaw"); //$NON-NLS-1$
isTypeEqual( ((IASTCastExpression)((IASTInitializerExpression)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getExpression()).getTypeId() , "short int"); //$NON-NLS-1$
}

View file

@ -1,3 +1,16 @@
2005-06-22 Vladimir Hirsl
Fix for PR 93573: "[Indexer] endl references are not added to the DOM index"
Fixed different encoding of functions references vs. declarations in the index.
Applied Devin's patch for PR 101114: "[AST Util] Inconsistent string representation
of IType elements" with slight modifications.
Modified JUnit tests accordingly.
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java
* parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java
* parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
2005-06-21 Vladimir Hirsl
Fix for 100598: DOM Indexer encodes weird things when indexing a CPP file in a C project
Fixed correlation between parser's parser language and indexer visitor.

View file

@ -247,7 +247,7 @@ public class CGenerateIndexVisitor extends CASTVisitor {
}
FunctionEntry indexEntry = new FunctionEntry(IIndex.FUNCTION, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.setSignature(IndexVisitorUtil.getParameters(name));
indexEntry.setSignature(IndexVisitorUtil.getParameters((IFunction) binding));
indexEntry.setReturnType(IndexVisitorUtil.getReturnType((IFunction) binding));
indexEntry.serialize(indexer.getOutput());

View file

@ -297,8 +297,8 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
}
FunctionEntry indexEntry = new FunctionEntry(IIndex.METHOD, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.setSignature(IndexVisitorUtil.getParameters(name));
indexEntry.setReturnType(IndexVisitorUtil.getReturnType((IFunction) binding));
indexEntry.setSignature(IndexVisitorUtil.getParameters((ICPPMethod) binding));
indexEntry.setReturnType(IndexVisitorUtil.getReturnType((ICPPMethod) binding));
serialize(indexEntry);
// TODO In case we want to add friend method declarations to index
@ -313,7 +313,7 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
}
FunctionEntry indexEntry = new FunctionEntry(IIndex.FUNCTION, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.setSignature(IndexVisitorUtil.getParameters(name));
indexEntry.setSignature(IndexVisitorUtil.getParameters((IFunction) binding));
indexEntry.setReturnType(IndexVisitorUtil.getReturnType((IFunction) binding));
serialize(indexEntry);

View file

@ -10,6 +10,9 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.index.domsourceindexer;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
@ -22,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
@ -202,7 +206,27 @@ public class IndexVisitorUtil {
}
return new char[0][];
}
/**
* @param function
* @return
*/
public static char[][] getParameters(IFunction function) {
List parameterList = new ArrayList();
try {
IParameter[] parameters = function.getParameters();
for (int i = 0; i < parameters.length; i++) {
IType paramType = parameters[i].getType();
parameterList.add(ASTTypeUtil.getType(paramType).toCharArray());
}
if (parameterList.isEmpty()) {
parameterList.add("void".toCharArray()); //$NON-NLS-1$
}
}
catch (DOMException e) {
}
return (char[][]) parameterList.toArray(new char[parameterList.size()][]);
}
/**
* @param function
* @return

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
@ -23,11 +22,9 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
@ -180,6 +177,7 @@ public class ASTSignatureUtil {
if (ops != null && ops.length > 0) {
for(int i=0; i<ops.length; i++) {
if (ops[i] != null) {
if (needSpace) { result.append(SPACE); }
if (ops[i] instanceof IASTPointer) {
result.append(Keywords.cpSTAR); // want to have this before keywords on the pointer
needSpace=true;
@ -388,43 +386,48 @@ public class ASTSignatureUtil {
// handle complex cases
if (declSpec instanceof IASTCompositeTypeSpecifier) {
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
switch(((ICPPASTCompositeTypeSpecifier)declSpec).getKey()) {
case ICPPASTCompositeTypeSpecifier.k_class:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.CLASS); needSpace=true;
break;
case IASTCompositeTypeSpecifier.k_struct:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.STRUCT); needSpace=true;
break;
case IASTCompositeTypeSpecifier.k_union:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.UNION); needSpace=true;
break;
}
} else if (declSpec instanceof ICASTCompositeTypeSpecifier) {
switch(((ICASTCompositeTypeSpecifier)declSpec).getKey()) {
case IASTCompositeTypeSpecifier.k_struct:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.STRUCT); needSpace=true;
break;
case IASTCompositeTypeSpecifier.k_union:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.UNION); needSpace=true;
break;
}
}
// 101114 fix, do not display class, and for consistency don't display struct/union as well
// if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
// switch(((ICPPASTCompositeTypeSpecifier)declSpec).getKey()) {
// case ICPPASTCompositeTypeSpecifier.k_class:
// if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.CLASS); needSpace=true;
// break;
// case IASTCompositeTypeSpecifier.k_struct:
// if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.STRUCT); needSpace=true;
// break;
// case IASTCompositeTypeSpecifier.k_union:
// if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.UNION); needSpace=true;
// break;
// }
// } else if (declSpec instanceof ICASTCompositeTypeSpecifier) {
// switch(((ICASTCompositeTypeSpecifier)declSpec).getKey()) {
// case IASTCompositeTypeSpecifier.k_struct:
// if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.STRUCT); needSpace=true;
// break;
// case IASTCompositeTypeSpecifier.k_union:
// if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.UNION); needSpace=true;
// break;
// }
// }
result.append(((IASTCompositeTypeSpecifier)declSpec).getName());
} else if (declSpec instanceof IASTElaboratedTypeSpecifier) {
switch(((IASTElaboratedTypeSpecifier)declSpec).getKind()) {
case ICPPASTElaboratedTypeSpecifier.k_class:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.CLASS); needSpace=true;
break;
case IASTElaboratedTypeSpecifier.k_enum:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.ENUM); needSpace=true;
break;
case IASTElaboratedTypeSpecifier.k_struct:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.STRUCT); needSpace=true;
break;
case IASTElaboratedTypeSpecifier.k_union:
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.UNION); needSpace=true;
break;
}
// 101114 fix, do not display class, and for consistency don't display struct/union as well
// switch(((IASTElaboratedTypeSpecifier)declSpec).getKind()) {
// case ICPPASTElaboratedTypeSpecifier.k_class:
// if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.CLASS); needSpace=true;
// break;
// case IASTElaboratedTypeSpecifier.k_enum:
// if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.ENUM); needSpace=true;
// break;
// case IASTElaboratedTypeSpecifier.k_struct:
// if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.STRUCT); needSpace=true;
// break;
// case IASTElaboratedTypeSpecifier.k_union:
// if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.UNION); needSpace=true;
// break;
// }
result.append(((IASTElaboratedTypeSpecifier)declSpec).getName());
} else if (declSpec instanceof IASTEnumerationSpecifier) {
if (needSpace) { result.append(SPACE); needSpace=false; } result.append(Keywords.ENUM); needSpace=true;
} else if (declSpec instanceof IASTNamedTypeSpecifier) {

View file

@ -16,7 +16,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.core.dom.ast.c.ICPointerType;
import org.eclipse.cdt.core.dom.ast.c.ICQualifierType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
@ -173,29 +172,30 @@ public class ASTTypeUtil {
break;
}
} catch (DOMException e) {}
} else if (type instanceof ICompositeType) {
if (type instanceof ICPPClassType) {
try {
switch(((ICPPClassType)type).getKey()) {
case ICPPClassType.k_class:
result.append(Keywords.CLASS);
break;
}
} catch (DOMException e) {}
}
try {
switch(((ICompositeType)type).getKey()) {
case ICompositeType.k_struct:
result.append(Keywords.STRUCT);
break;
case ICompositeType.k_union:
result.append(Keywords.UNION);
break;
}
} catch (DOMException e) {}
result.append(SPACE);
// 101114 fix, do not display class, and for consistency don't display struct/union as well
// if (type instanceof ICPPClassType) {
// try {
// switch(((ICPPClassType)type).getKey()) {
// case ICPPClassType.k_class:
// result.append(Keywords.CLASS);
// break;
// }
// } catch (DOMException e) {}
// }
//
// try {
// switch(((ICompositeType)type).getKey()) {
// case ICompositeType.k_struct:
// result.append(Keywords.STRUCT);
// break;
// case ICompositeType.k_union:
// result.append(Keywords.UNION);
// break;
// }
// } catch (DOMException e) {}
// result.append(SPACE);
result.append(((ICompositeType)type).getName());
} else if (type instanceof ICPPReferenceType) {
result.append(Keywords.cpAMPER);
@ -277,8 +277,17 @@ public class ASTTypeUtil {
if (types[j] != null && result.length() > 0) result.append(SPACE); // only add a space if this is not the first type being added
if (types[j] != null)
result.append(getTypeString(types[j]));
if (types[j] != null) {
if (j > 0 && types[j-1] instanceof IQualifierType) {
result.append(getTypeString(types[j-1]));
result.append(SPACE);
result.append(getTypeString(types[j]));
--j;
}
else {
result.append(getTypeString(types[j]));
}
}
}
return result.toString();