mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Hoda Amer.
- The core patch modifies the CModelBuilder to recognize pointers to functions. - The tests patch changes the CModelElementsTests and puts the pointer to function test back in its original place (as a variable). - The ui patch modifies the NewClassWizard to use search in finding a base class ( the new indexer must be on for it to work ).
This commit is contained in:
parent
7b4de80105
commit
5aae8a1f5d
8 changed files with 131 additions and 89 deletions
|
@ -1,3 +1,7 @@
|
|||
2003-07-30 Hoda Amer
|
||||
The CModelElementsTests has the pointer to function test back in its original place
|
||||
(a variable)
|
||||
|
||||
2003-07-30 Victor Mozgin
|
||||
Moved testBug39532() from ASTFailedTests.java to QuickParseASTTests.java.
|
||||
|
||||
|
|
|
@ -306,10 +306,10 @@ public class CModelElementsTests extends TestCase {
|
|||
checkLineNumbers((CElement)var3, 75, 75);
|
||||
|
||||
// MyPackage ---> function pointer: orig_malloc_hook
|
||||
// IVariable vDecl2 = (IVariable) nsVars.get(3);
|
||||
// assertEquals(vDecl2.getElementName(), new String("orig_malloc_hook"));
|
||||
// assertEquals(vDecl2.getTypeName(), new String ("void*(*)(const char*, int, size_t)"));
|
||||
// checkLineNumbers((CElement)vDecl2, 81, 81);
|
||||
IVariable vDecl2 = (IVariable) nsVars.get(3);
|
||||
assertEquals(vDecl2.getElementName(), new String("orig_malloc_hook"));
|
||||
assertEquals(vDecl2.getTypeName(), new String ("void*(*)(const char*, int, size_t)"));
|
||||
checkLineNumbers((CElement)vDecl2, 81, 81);
|
||||
}
|
||||
|
||||
private void checkVariableDeclarations(IParent namespace){
|
||||
|
@ -324,20 +324,14 @@ public class CModelElementsTests extends TestCase {
|
|||
private void checkFunctions(IParent namespace){
|
||||
ArrayList nsFunctionDeclarations = namespace.getChildrenOfType(ICElement.C_FUNCTION_DECLARATION);
|
||||
|
||||
// MyPackage ---> function pointer: orig_malloc_hook
|
||||
IFunctionDeclaration pointerToFunction = (IFunctionDeclaration) nsFunctionDeclarations.get(0);
|
||||
assertEquals(pointerToFunction.getElementName(), new String("orig_malloc_hook"));
|
||||
// assertEquals(pointerToFunction.getReturnType(), new String ("void*(*)(const char*, int, size_t)"));
|
||||
checkLineNumbers((CElement)pointerToFunction, 81, 81);
|
||||
|
||||
// MyPackage ---> function: void foo()
|
||||
IFunctionDeclaration f1 = (IFunctionDeclaration) nsFunctionDeclarations.get(1);
|
||||
IFunctionDeclaration f1 = (IFunctionDeclaration) nsFunctionDeclarations.get(0);
|
||||
assertEquals(f1.getElementName(), new String("foo"));
|
||||
assertEquals(f1.getReturnType(), new String("void"));
|
||||
checkLineNumbers((CElement)f1, 85, 85);
|
||||
|
||||
// MyPackage ---> function: char* foo(int&, char**)
|
||||
IFunctionDeclaration f2 = (IFunctionDeclaration) nsFunctionDeclarations.get(2);
|
||||
IFunctionDeclaration f2 = (IFunctionDeclaration) nsFunctionDeclarations.get(1);
|
||||
assertEquals(f2.getElementName(), new String("foo"));
|
||||
assertEquals(f2.getReturnType(), new String("char*"));
|
||||
checkLineNumbers((CElement)f2, 87, 88);
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
2003-07-30 Hoda Amer
|
||||
The C Model recognizes pointers to functions.
|
||||
|
||||
2003-07-29 Alain Magloire
|
||||
|
||||
To discover if an application has debug info for DWARF-2 format
|
||||
|
|
|
@ -164,23 +164,8 @@ public class CModelBuilder {
|
|||
if(declaration instanceof IASTTypedefDeclaration ) {
|
||||
generateModelElements(parent, (IASTTypedefDeclaration) declaration);
|
||||
}
|
||||
|
||||
/* if ((declaration instanceof IASTPointerToFunction)
|
||||
|| (declaration instanceof IASTPointerToMethod))
|
||||
{
|
||||
createPointerToFunction(parent, declaration, false);
|
||||
}
|
||||
// variable or field
|
||||
else */
|
||||
if (declaration instanceof IASTVariable)
|
||||
{
|
||||
createVariableSpecification(parent, (IASTVariable)declaration, false);
|
||||
}
|
||||
// function or method
|
||||
else if(declaration instanceof IASTFunction )
|
||||
{
|
||||
createFunctionSpecification(parent, (IASTFunction)declaration, false);
|
||||
}
|
||||
|
||||
createSimpleElement(parent, declaration, false);
|
||||
}
|
||||
|
||||
protected void generateModelElements (Parent parent, IASTNamespaceDefinition declaration) throws ASTNotImplementedException{
|
||||
|
@ -208,31 +193,13 @@ public class CModelBuilder {
|
|||
CElement element = createAbstractElement(parent, abstractDeclaration , true);
|
||||
// set the element position
|
||||
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
|
||||
// set the element lines
|
||||
//element.setLines(templateDeclaration.getTopLine(), templateDeclaration.getBottomLine());
|
||||
// set the template parameters
|
||||
String[] parameterTypes = getTemplateParameters(templateDeclaration);
|
||||
ITemplate classTemplate = (ITemplate) element;
|
||||
classTemplate.setTemplateParameterTypes(parameterTypes);
|
||||
}
|
||||
ITemplate template = null;
|
||||
|
||||
/* if ((declaration instanceof IASTPointerToFunction)
|
||||
|| (declaration instanceof IASTPointerToMethod))
|
||||
{
|
||||
template = (ITemplate) createPointerToFunction(parent, declaration, true);
|
||||
}
|
||||
// template of variable or field
|
||||
else */
|
||||
if (declaration instanceof IASTVariable)
|
||||
{
|
||||
template = (ITemplate) createVariableSpecification(parent, (IASTVariable)declaration, true);
|
||||
}
|
||||
// Template of function or method
|
||||
else if(declaration instanceof IASTFunction )
|
||||
{
|
||||
template = (ITemplate) createFunctionSpecification(parent, (IASTFunction)declaration, true);
|
||||
}
|
||||
template = (ITemplate) createSimpleElement(parent, declaration, true);
|
||||
|
||||
if(template != null){
|
||||
CElement element = (CElement)template;
|
||||
|
@ -278,6 +245,21 @@ public class CModelBuilder {
|
|||
return element;
|
||||
}
|
||||
|
||||
private CElement createSimpleElement(Parent parent, IASTDeclaration declaration, boolean isTemplate)throws ASTNotImplementedException{
|
||||
|
||||
CElement element = null;
|
||||
if (declaration instanceof IASTVariable)
|
||||
{
|
||||
element = createVariableSpecification(parent, (IASTVariable)declaration, isTemplate);
|
||||
}
|
||||
// function or method
|
||||
else if(declaration instanceof IASTFunction )
|
||||
{
|
||||
element = createFunctionSpecification(parent, (IASTFunction)declaration, isTemplate);
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
protected Include createInclusion(Parent parent, IASTInclusion inclusion){
|
||||
// create element
|
||||
Include element = new Include((CElement)parent, inclusion.getName(), !inclusion.isLocal());
|
||||
|
@ -642,9 +624,22 @@ public class CModelBuilder {
|
|||
type.append(getPointerOperation(declaration));
|
||||
type.append(getArrayQualifiers(declaration));
|
||||
|
||||
type.append(getPointerToFunctionType(declaration));
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
private String getPointerToFunctionType(IASTAbstractDeclaration declaration){
|
||||
StringBuffer type = new StringBuffer();
|
||||
ASTPointerOperator po = declaration.getPointerToFunctionOperator();
|
||||
if(po != null){
|
||||
type.append("(");
|
||||
type.append(getPointerOperator(po));
|
||||
type.append(")");
|
||||
String[] parameters =getParameterTypes(declaration.getParameters());
|
||||
type.append(getParametersString(parameters));
|
||||
}
|
||||
return type.toString();
|
||||
}
|
||||
private String getDeclarationType(IASTAbstractDeclaration declaration){
|
||||
StringBuffer type = new StringBuffer();
|
||||
|
||||
|
@ -657,7 +652,7 @@ public class CModelBuilder {
|
|||
}else if(typeSpecifier instanceof IASTSimpleTypeSpecifier){
|
||||
IASTSimpleTypeSpecifier simpleSpecifier = (IASTSimpleTypeSpecifier) typeSpecifier;
|
||||
type.append(simpleSpecifier.getTypename());
|
||||
}
|
||||
}
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
|
@ -686,21 +681,28 @@ public class CModelBuilder {
|
|||
Iterator i = declaration.getPointerOperators();
|
||||
while(i.hasNext()){
|
||||
ASTPointerOperator po = (ASTPointerOperator) i.next();
|
||||
if(po == ASTPointerOperator.POINTER)
|
||||
pointerString.append("*");
|
||||
|
||||
if(po == ASTPointerOperator.REFERENCE)
|
||||
pointerString.append("&");
|
||||
|
||||
if(po == ASTPointerOperator.CONST_POINTER)
|
||||
pointerString.append(" const");
|
||||
|
||||
if(po == ASTPointerOperator.VOLATILE_POINTER)
|
||||
pointerString.append(" volatile");
|
||||
pointerString.append(getPointerOperator(po));
|
||||
}
|
||||
return pointerString.toString();
|
||||
}
|
||||
|
||||
private String getPointerOperator(ASTPointerOperator po){
|
||||
String pointerString ="";
|
||||
if(po == ASTPointerOperator.POINTER)
|
||||
pointerString = ("*");
|
||||
|
||||
if(po == ASTPointerOperator.REFERENCE)
|
||||
pointerString =("&");
|
||||
|
||||
if(po == ASTPointerOperator.CONST_POINTER)
|
||||
pointerString =("* const");
|
||||
|
||||
if(po == ASTPointerOperator.VOLATILE_POINTER)
|
||||
pointerString =("* volatile");
|
||||
|
||||
return pointerString;
|
||||
}
|
||||
|
||||
private String getArrayQualifiers(IASTAbstractDeclaration declaration){
|
||||
StringBuffer arrayString = new StringBuffer();
|
||||
Iterator i = declaration.getArrayModifiers();
|
||||
|
@ -714,18 +716,21 @@ public class CModelBuilder {
|
|||
private String[] getFunctionParameterTypes(IASTFunction functionDeclaration)
|
||||
{
|
||||
Iterator parameters = functionDeclaration.getParameters();
|
||||
List paramList = new ArrayList();
|
||||
while (parameters.hasNext()){
|
||||
return getParameterTypes(parameters);
|
||||
}
|
||||
|
||||
private String[] getParameterTypes(Iterator parameters){
|
||||
List paramList = new ArrayList();
|
||||
while (parameters.hasNext()){
|
||||
IASTParameterDeclaration param = (IASTParameterDeclaration)parameters.next();
|
||||
paramList.add(getType(param));
|
||||
}
|
||||
}
|
||||
String[] parameterTypes = new String[paramList.size()];
|
||||
for(int i=0; i<paramList.size(); ++i){
|
||||
parameterTypes[i] = (String)paramList.get(i);
|
||||
}
|
||||
return parameterTypes;
|
||||
}
|
||||
|
||||
return parameterTypes;
|
||||
}
|
||||
private String getParametersString(String[] parameterTypes)
|
||||
{
|
||||
StringBuffer parameters = new StringBuffer("");
|
||||
|
|
|
@ -71,6 +71,14 @@ public class BasicSearchMatch implements IMatch {
|
|||
public IResource getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
public IPath getLocation() {
|
||||
if(resource != null)
|
||||
return resource.getLocation();
|
||||
else if (path != null)
|
||||
return path;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public int getStartOffset() {
|
||||
return startOffset;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.cdt.core.search;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -32,6 +33,8 @@ public interface IMatch {
|
|||
String getParentName();
|
||||
|
||||
IResource getResource();
|
||||
|
||||
IPath getLocation();
|
||||
|
||||
int getStartOffset();
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
2003-07-30 Hoda Amer
|
||||
The New Class Wizard uses search to look for base classes in the workspace.
|
||||
|
||||
2003-07-29 Andrew Niefer
|
||||
- Refactoring Search Result Collecting:
|
||||
* CSearchResultCollector now extends BasicSearchResultCollector
|
||||
|
|
|
@ -15,7 +15,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -27,6 +27,12 @@ import org.eclipse.cdt.core.model.IOpenable;
|
|||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.cdt.core.model.IStructure;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
|
||||
|
@ -42,7 +48,7 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFie
|
|||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.Separator;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
|
||||
import org.eclipse.cdt.ui.CElementLabelProvider;
|
||||
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.CodeGeneration;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
|
@ -103,7 +109,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
// the created class element
|
||||
private /*IStructure*/ ICElement createdClass = null;
|
||||
|
||||
private ArrayList elementsOfTypeClassInProject = null;
|
||||
private List elementsOfTypeClassInProject = null;
|
||||
|
||||
// Controls
|
||||
private StringDialogField fClassNameDialogField;
|
||||
|
@ -119,6 +125,9 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
protected IStatus fClassNameStatus;
|
||||
protected IStatus fBaseClassStatus;
|
||||
|
||||
BasicSearchResultCollector resultCollector;
|
||||
SearchEngine searchEngine;
|
||||
|
||||
// -------------------- Initialization ------------------
|
||||
public NewClassWizardPage(IStructuredSelection selection) {
|
||||
super(PAGE_NAME);
|
||||
|
@ -163,6 +172,9 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
fClassNameStatus= new StatusInfo();
|
||||
fBaseClassStatus= new StatusInfo();
|
||||
|
||||
resultCollector = new BasicSearchResultCollector ();
|
||||
searchEngine = new SearchEngine();
|
||||
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
@ -297,9 +309,9 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
|
||||
private void classPageChangeControlPressed(DialogField field) {
|
||||
if (field == fBaseClassDialogField) {
|
||||
ICElement element= chooseBaseClass();
|
||||
BasicSearchMatch element= (BasicSearchMatch)chooseBaseClass();
|
||||
if (element != null) {
|
||||
fBaseClassDialogField.setText(element.getElementName());
|
||||
fBaseClassDialogField.setText(element.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -376,7 +388,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
return null;
|
||||
}
|
||||
|
||||
private void getChildrenOfTypeClass(IParent parent, ArrayList elementsFound, IProgressMonitor monitor, int worked){
|
||||
private void getChildrenOfTypeClass(IParent parent, List elementsFound, IProgressMonitor monitor, int worked){
|
||||
ICElement[] elements = parent.getChildren();
|
||||
monitor.worked( worked );
|
||||
|
||||
|
@ -391,20 +403,29 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
private ArrayList getClassElementsInProject(){
|
||||
private void searchForClasses(ICProject cProject, List elementsFound, IProgressMonitor monitor, int worked){
|
||||
ICSearchPattern pattern = SearchEngine.createSearchPattern( "*", ICSearchConstants.CLASS, ICSearchConstants.DECLARATIONS, false );
|
||||
// TODO: change that to project scope later
|
||||
ICSearchScope scope = SearchEngine.createWorkspaceScope();;
|
||||
|
||||
searchEngine.search(CUIPlugin.getWorkspace(), pattern, scope, resultCollector);
|
||||
elementsFound.addAll(resultCollector.getSearchResults());
|
||||
}
|
||||
|
||||
private List getClassElementsInProject(){
|
||||
return elementsOfTypeClassInProject;
|
||||
}
|
||||
|
||||
private ArrayList findClassElementsInProject(){
|
||||
private List findClassElementsInProject(){
|
||||
if(eSelection == null){
|
||||
return new ArrayList();
|
||||
return new LinkedList();
|
||||
}
|
||||
|
||||
if( elementsOfTypeClassInProject != null ){
|
||||
return elementsOfTypeClassInProject;
|
||||
}
|
||||
|
||||
elementsOfTypeClassInProject = new ArrayList();
|
||||
elementsOfTypeClassInProject = new LinkedList();
|
||||
IRunnableWithProgress runnable= new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||
if (monitor == null) {
|
||||
|
@ -413,7 +434,8 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
monitor.beginTask(NewWizardMessages.getString("NewClassWizardPage.operations.getProjectClasses"), 5); //$NON-NLS-1$
|
||||
try{
|
||||
ICProject cProject = eSelection.getCProject();
|
||||
getChildrenOfTypeClass((IParent)cProject, elementsOfTypeClassInProject, monitor, 1);
|
||||
searchForClasses(cProject, elementsOfTypeClassInProject, monitor, 1);
|
||||
//getChildrenOfTypeClass((IParent)cProject, elementsOfTypeClassInProject, monitor, 1);
|
||||
monitor.worked(5);
|
||||
} finally{
|
||||
monitor.done();
|
||||
|
@ -431,18 +453,18 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
return elementsOfTypeClassInProject;
|
||||
}
|
||||
|
||||
protected ICElement chooseBaseClass(){
|
||||
protected Object chooseBaseClass(){
|
||||
// find the available classes in this project
|
||||
ArrayList elementsFound = findClassElementsInProject();
|
||||
List elementsFound = findClassElementsInProject();
|
||||
|
||||
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new CElementLabelProvider());
|
||||
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new CSearchResultLabelProvider());
|
||||
dialog.setTitle(NewWizardMessages.getString("BaseClassSelectionDialog.title")); //$NON-NLS-1$
|
||||
dialog.setMessage(NewWizardMessages.getString("BaseClassSelectionDialog.message")); //$NON-NLS-1$
|
||||
dialog.setElements(elementsFound.toArray());
|
||||
dialog.setFilter("*");
|
||||
|
||||
if (dialog.open() == ElementListSelectionDialog.OK) {
|
||||
ICElement element= (ICElement) dialog.getFirstResult();
|
||||
Object element= dialog.getFirstResult();
|
||||
return element;
|
||||
}
|
||||
return null;
|
||||
|
@ -738,11 +760,11 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
if((baseClassName != null) && (baseClassName.length() > 0))
|
||||
{
|
||||
extendingBase = true;
|
||||
ArrayList classElements = findClassElementsInProject();
|
||||
ICElement baseClass = findInList(baseClassName, classElements);
|
||||
List classElements = findClassElementsInProject();
|
||||
BasicSearchMatch baseClass = (BasicSearchMatch)findInList(baseClassName, classElements);
|
||||
|
||||
if(baseClass != null){
|
||||
baseClassFileName = baseClass.getUnderlyingResource().getName();
|
||||
baseClassFileName = baseClass.getLocation().toString();
|
||||
} else {
|
||||
baseClassFileName = baseClassName + HEADER_EXT;
|
||||
}
|
||||
|
@ -930,7 +952,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
// class name must follow the C/CPP convensions
|
||||
|
||||
// if class does not exist, give warning
|
||||
ArrayList elementsFound = findClassElementsInProject();
|
||||
List elementsFound = findClassElementsInProject();
|
||||
if(!foundInList(getBaseClassName(), elementsFound)){
|
||||
status.setWarning(NewWizardMessages.getString("NewClassWizardPage.warning.BaseClassNotExists")); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -938,17 +960,17 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
|||
|
||||
}
|
||||
|
||||
private ICElement findInList(String name, ArrayList elements){
|
||||
private Object findInList(String name, List elements){
|
||||
Iterator i = elements.iterator();
|
||||
while (i.hasNext()){
|
||||
ICElement element = (ICElement)i.next();
|
||||
if (name.equals(element.getElementName()))
|
||||
BasicSearchMatch element = (BasicSearchMatch)i.next();
|
||||
if (name.equals(element.getName()))
|
||||
return element;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean foundInList(String name, ArrayList elements){
|
||||
private boolean foundInList(String name, List elements){
|
||||
if(findInList(name, elements) != null)
|
||||
return true;
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue