1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 10:25:32 +02:00

Fix for [Bug 47234] new ParserMode required for a better CModel

This commit is contained in:
Hoda Amer 2003-12-15 19:50:46 +00:00
parent 1148b378c8
commit a8950694c7
20 changed files with 519 additions and 136 deletions

View file

@ -15,12 +15,17 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.ITemplate; import org.eclipse.cdt.core.model.ITemplate;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IQuickParseCallback; import org.eclipse.cdt.core.parser.IQuickParseCallback;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserFactoryException; import org.eclipse.cdt.core.parser.ParserFactoryException;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -67,53 +72,80 @@ public class CModelBuilder {
this.newElements = new HashMap(); this.newElements = new HashMap();
} }
private IASTCompilationUnit parse( String code, boolean hasCppNature, boolean quick, boolean throwExceptionOnError ) throws ParserException private IASTCompilationUnit parse( ITranslationUnit translationUnit, boolean quickParseMode, boolean throwExceptionOnError ) throws ParserException
{ {
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; IProject currentProject = null;
quickParseCallback = ParserFactory.createQuickParseCallback(); boolean hasCppNature = true;
String code = "";
// get the current project
if (translationUnit != null && translationUnit.getCProject() != null) {
currentProject = translationUnit.getCProject().getProject();
}
// check the project's nature
if( currentProject != null )
{
hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
}
// get the code to parse
try{
code = translationUnit.getBuffer().getContents();
} catch (CModelException e) {
}
// use quick or structural parse mode
ParserMode mode = quickParseMode ? ParserMode.QUICK_PARSE : ParserMode.STRUCTURAL_PARSE;
if(quickParseMode)
quickParseCallback = ParserFactory.createQuickParseCallback();
else
quickParseCallback = ParserFactory.createStructuralParseCallback();
// pick the language
ParserLanguage language = hasCppNature ? ParserLanguage.CPP : ParserLanguage.C; ParserLanguage language = hasCppNature ? ParserLanguage.CPP : ParserLanguage.C;
// create the parser
IParser parser = null; IParser parser = null;
try try
{ {
IScannerInfo scanInfo = new ScannerInfo();
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject);
if (provider != null){
IScannerInfo buildScanInfo = provider.getScannerInformation(currentProject);
if (buildScanInfo != null){
scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths());
}
}
parser = ParserFactory.createParser( parser = ParserFactory.createParser(
ParserFactory.createScanner( new StringReader( code ), "code", ParserFactory.createScanner(
new ScannerInfo(), mode, language, quickParseCallback, ParserUtil.getParserLogService()), quickParseCallback, mode, language, ParserUtil.getParserLogService() ); new StringReader( code ),
translationUnit.getUnderlyingResource().getLocation().toOSString(),
scanInfo,
mode,
language,
quickParseCallback,
ParserUtil.getParserLogService())
,quickParseCallback,
mode,
language,
ParserUtil.getParserLogService() );
} }
catch( ParserFactoryException pfe ) catch( ParserFactoryException pfe )
{ {
throw new ParserException( "Parser/Scanner construction failure."); throw new ParserException( "Parser/Scanner construction failure.");
} }
// call parse
if( ! parser.parse() && throwExceptionOnError ) if( ! parser.parse() && throwExceptionOnError )
throw new ParserException("Parse failure"); throw new ParserException("Parse failure");
return quickParseCallback.getCompilationUnit(); return quickParseCallback.getCompilationUnit();
} }
private IASTCompilationUnit parse( String code, boolean hasCppNature )throws ParserException
{
return parse( code, hasCppNature, true, true );
}
public Map parse() throws Exception { public Map parse(boolean quickParseMode) throws Exception {
Map options = null;
IProject currentProject = null;
boolean hasCppNature = true;
if (translationUnit != null && translationUnit.getCProject() != null) {
options = translationUnit.getCProject().getOptions(true);
currentProject = translationUnit.getCProject().getProject();
}
if( currentProject != null )
{
hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
}
try try
{ {
compilationUnit = parse( translationUnit.getBuffer().getContents(), hasCppNature); compilationUnit = parse( translationUnit, quickParseMode, true);
} }
catch( ParserException e ) catch( ParserException e )

View file

@ -0,0 +1,246 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software 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 Rational Software - Initial API and implementation
***********************************************************************/package org.eclipse.cdt.internal.core.model;
import java.util.LinkedList;
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTField;
import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
import org.eclipse.cdt.core.parser.ast.IASTMacro;
import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTScope;
/**
* @author hamer
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class StructuralParseCallback extends QuickParseCallback{
protected LinkedList scopeStack = new LinkedList();
protected IASTScope currentScope = null;
protected int inclusionLevel = 0;
private void addElement (IASTDeclaration element){
if(inclusionLevel == 0)
((ASTScope)currentScope).addDeclaration(element);
}
private void enterScope(IASTNode node){
if(node instanceof IASTScope){
pushScope((IASTScope)node);
}
}
private void exitScope(IASTNode node){
if(node instanceof IASTScope){
popScope();
}
}
private void pushScope( IASTScope scope ){
scopeStack.addFirst( currentScope );
currentScope = (IASTScope)scope;
}
private IASTScope popScope(){
IASTScope oldScope = currentScope;
currentScope = (scopeStack.size() > 0 ) ? (IASTScope) scopeStack.removeFirst() : null;
return oldScope;
}
private IASTScope peekAtScope(){
return currentScope;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro)
*/
public void acceptMacro(IASTMacro macro) {
if(inclusionLevel == 0)
macros.add(macro);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable)
*/
public void acceptVariable(IASTVariable variable) {
addElement(variable);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction)
*/
public void acceptFunctionDeclaration(IASTFunction function) {
addElement(function);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefDeclaration(org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration)
*/
public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef) {
addElement(typedef);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier)
*/
public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) {
enterScope(enumeration);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier)
*/
public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType) {
enterScope(elaboratedType);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration)
*/
public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) {
addElement(abstractDeclaration);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
*/
public void enterInclusion(IASTInclusion inclusion) {
if(inclusionLevel == 0)
inclusions.add(inclusion);
inclusionLevel++;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
*/
public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
addElement(namespaceDefinition);
enterScope(namespaceDefinition);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
*/
public void enterClassSpecifier(IASTClassSpecifier classSpecification) {
enterScope(classSpecification);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
*/
public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) {
enterScope(linkageSpec);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
*/
public void enterCompilationUnit(IASTCompilationUnit compilationUnit) {
enterScope(compilationUnit);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod)
*/
public void acceptMethodDeclaration(IASTMethod method) {
addElement(method);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField)
*/
public void acceptField(IASTField field) {
addElement(field);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit)
*/
public void exitCompilationUnit(IASTCompilationUnit compilationUnit) {
exitScope(compilationUnit);
this.compilationUnit = compilationUnit;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion)
*/
public void exitInclusion( IASTInclusion inclusion )
{
inclusionLevel--;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IQuickParseCallback#getCompilationUnit()
*/
public IASTCompilationUnit getCompilationUnit() {
return compilationUnit; }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
*/
public void exitClassSpecifier(IASTClassSpecifier classSpecification) {
exitScope(classSpecification);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification)
*/
public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) {
exitScope(linkageSpec);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition)
*/
public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
exitScope(namespaceDefinition);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction)
*/
public void enterFunctionBody(IASTFunction function) {
addElement(function);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod)
*/
public void enterMethodBody(IASTMethod method) {
addElement(method);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
*/
public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) {
addElement(declaration);
}
}

View file

@ -10,6 +10,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
@ -465,7 +466,9 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
try { try {
removeChildren(); removeChildren();
CModelBuilder modelBuilder = new CModelBuilder(this); CModelBuilder modelBuilder = new CModelBuilder(this);
return modelBuilder.parse();
boolean quickParseMode = ! (CCorePlugin.getDefault().useStructuralParseMode());
return modelBuilder.parse(quickParseMode);
} catch (Exception e) { } catch (Exception e) {
// FIXME: use the debug log for this exception. // FIXME: use the debug log for this exception.
//System.out.println(e); //System.out.println(e);

View file

@ -1,3 +1,9 @@
2003-12-15 Hoda Amer
Fixed [Bug 47234] new ParserMode required for a better CModel :
- Added a core plugin preference to build the CModel in Structural mode
- Added StructuralParseCallBack class
- Added lists of declarations to AST Scopes in the complete AST
2003-12-12 John Camelon 2003-12-12 John Camelon
Added preliminary keyword support into IASTCompletionNode::getKeywords(). Added preliminary keyword support into IASTCompletionNode::getKeywords().
Refactored parser to put keyword string literals in one utility class. Refactored parser to put keyword string literals in one utility class.

View file

@ -13,13 +13,15 @@ package org.eclipse.cdt.core.parser;
import java.io.Reader; import java.io.Reader;
import org.eclipse.cdt.core.parser.ast.IASTFactory; import org.eclipse.cdt.core.parser.ast.IASTFactory;
import org.eclipse.cdt.internal.core.parser.*; import org.eclipse.cdt.internal.core.model.StructuralParseCallback;
import org.eclipse.cdt.internal.core.parser.CompleteParser; import org.eclipse.cdt.internal.core.parser.CompleteParser;
import org.eclipse.cdt.internal.core.parser.ContextualParser;
import org.eclipse.cdt.internal.core.parser.LineOffsetReconciler; import org.eclipse.cdt.internal.core.parser.LineOffsetReconciler;
import org.eclipse.cdt.internal.core.parser.Preprocessor; import org.eclipse.cdt.internal.core.parser.Preprocessor;
import org.eclipse.cdt.internal.core.parser.QuickParseCallback; import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
import org.eclipse.cdt.internal.core.parser.QuickParser; import org.eclipse.cdt.internal.core.parser.QuickParser;
import org.eclipse.cdt.internal.core.parser.Scanner; import org.eclipse.cdt.internal.core.parser.Scanner;
import org.eclipse.cdt.internal.core.parser.StructuralParser;
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory; import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory; import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
@ -85,7 +87,12 @@ public class ParserFactory {
{ {
return new QuickParseCallback(); return new QuickParseCallback();
} }
public static IQuickParseCallback createStructuralParseCallback()
{
return new StructuralParseCallback();
}
public static IParserLogService createDefaultLogService() public static IParserLogService createDefaultLogService()
{ {
return defaultLogService; return defaultLogService;

View file

@ -42,6 +42,15 @@ public class QuickParseCallback extends NullSourceElementRequestor implements IQ
return macros.iterator(); return macros.iterator();
} }
public Iterator getDeclarations(){
try{
return compilationUnit.getDeclarations();
}
catch (ASTNotImplementedException ne )
{
return null;
}
}
public void exitMethodBody( IASTMethod method ) public void exitMethodBody( IASTMethod method )
{ {
@ -89,25 +98,19 @@ public class QuickParseCallback extends NullSourceElementRequestor implements IQ
public OffsetableIterator() public OffsetableIterator()
{ {
try declarationIter = getDeclarations();
{ inclusionIter = getInclusions();
declarationIter = compilationUnit.getDeclarations(); macroIter = getMacros();
}
catch (ASTNotImplementedException ne )
{
}
inclusionIter = inclusions.iterator();
macroIter = macros.iterator();
updateInclusionIterator(); updateInclusionIterator();
updateDeclarationIterator();
updateMacroIterator(); updateMacroIterator();
updateDeclarationIterator();
} }
private Object updateDeclarationIterator() private Object updateDeclarationIterator()
{ {
Object offsetable = currentDeclaration; Object offsetable = currentDeclaration;
currentDeclaration = ( declarationIter.hasNext() ) ? (IASTOffsetableElement)declarationIter.next() : null; if(declarationIter != null)
currentDeclaration = ( declarationIter.hasNext() ) ? (IASTOffsetableElement)declarationIter.next() : null;
return offsetable; return offsetable;
} }

View file

@ -10,6 +10,7 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete; package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -19,6 +20,7 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind; import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
@ -32,7 +34,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParen
*/ */
public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier
{ {
private List declarations = new ArrayList();
public class BaseIterator implements Iterator public class BaseIterator implements Iterator
{ {
@ -256,6 +258,16 @@ public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier
{ {
offsets.setNameEndOffset(o); offsets.setNameEndOffset(o);
} }
public Iterator getDeclarations()
{
return declarations.iterator();
}
public void addDeclaration(IASTDeclaration declaration)
{
declarations.add(declaration);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind) * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/ */

View file

@ -6,8 +6,13 @@
*/ */
package org.eclipse.cdt.internal.core.parser.ast.complete; package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope; import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
/** /**
@ -18,6 +23,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
*/ */
public class ASTCodeScope extends ASTScope implements IASTCodeScope { public class ASTCodeScope extends ASTScope implements IASTCodeScope {
private List declarations = new ArrayList();
private final IASTCodeScope ownerCodeScope; private final IASTCodeScope ownerCodeScope;
/** /**
@ -71,7 +77,17 @@ public class ASTCodeScope extends ASTScope implements IASTCodeScope {
{ {
return ownerCodeScope; return ownerCodeScope;
} }
public Iterator getDeclarations()
{
return declarations.iterator();
}
public void addDeclaration(IASTDeclaration declaration)
{
declarations.add(declaration);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind) * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/ */

View file

@ -10,8 +10,13 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete; package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
/** /**
@ -22,7 +27,8 @@ public class ASTCompilationUnit
extends ASTScope extends ASTScope
implements IASTCompilationUnit implements IASTCompilationUnit
{ {
/** private List declarations = new ArrayList();
/**
* @param symbol * @param symbol
*/ */
public ASTCompilationUnit(ISymbol symbol) public ASTCompilationUnit(ISymbol symbol)
@ -64,7 +70,16 @@ public class ASTCompilationUnit
/* do nothing */ /* do nothing */
} }
} }
public Iterator getDeclarations()
{
return declarations.iterator();
}
public void addDeclaration(IASTDeclaration declaration)
{
declarations.add(declaration);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind) * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/ */

View file

@ -10,6 +10,7 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete; package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -17,6 +18,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope; import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification;
import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
@ -42,7 +44,7 @@ public class ASTFunction extends ASTScope implements IASTFunction
private final List parameters; private final List parameters;
protected final ASTReferenceStore references; protected final ASTReferenceStore references;
private final int nameEndOffset; private final int nameEndOffset;
private List declarations = new ArrayList();
/** /**
* @param symbol * @param symbol
* @param parameters * @param parameters
@ -319,7 +321,15 @@ public class ASTFunction extends ASTScope implements IASTFunction
return hasFunctionTryBlock; return hasFunctionTryBlock;
} }
public Iterator getDeclarations()
{
return declarations.iterator();
}
public void addDeclaration(IASTDeclaration declaration)
{
declarations.add(declaration);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind) * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/ */

View file

@ -10,7 +10,12 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete; package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
@ -27,6 +32,7 @@ public class ASTNamespaceDefinition
private NamedOffsets namedOffsets = new NamedOffsets(); private NamedOffsets namedOffsets = new NamedOffsets();
private final ASTQualifiedNamedElement qualifiedName; private final ASTQualifiedNamedElement qualifiedName;
private List declarations = new ArrayList();
/** /**
* @param namespaceSymbol * @param namespaceSymbol
@ -158,7 +164,16 @@ public class ASTNamespaceDefinition
{ {
namedOffsets.setNameEndOffset(o); namedOffsets.setNameEndOffset(o);
} }
public Iterator getDeclarations()
{
return declarations.iterator();
}
public void addDeclaration(IASTDeclaration declaration)
{
declarations.add(declaration);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind) * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/ */

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
@ -39,9 +40,13 @@ public abstract class ASTScope extends ASTSymbol implements IASTScope
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations()
*/ */
public Iterator getDeclarations() throws ASTNotImplementedException public Iterator getDeclarations()
{
return null;
}
public void addDeclaration(IASTDeclaration declaration)
{ {
throw new ASTNotImplementedException();
} }
} }

View file

@ -65,7 +65,8 @@ public class CCorePlugin extends Plugin {
public final static String PREF_BINARY_PARSER = "binaryparser"; public final static String PREF_BINARY_PARSER = "binaryparser";
public final static String DEFAULT_BINARY_PARSER_SIMPLE_ID = "ELF"; public final static String DEFAULT_BINARY_PARSER_SIMPLE_ID = "ELF";
public final static String DEFAULT_BINARY_PARSER_UNIQ_ID = PLUGIN_ID + "." + DEFAULT_BINARY_PARSER_SIMPLE_ID; public final static String DEFAULT_BINARY_PARSER_UNIQ_ID = PLUGIN_ID + "." + DEFAULT_BINARY_PARSER_SIMPLE_ID;
public final static String PREF_USE_STRUCTURAL_PARSE_MODE = "useStructualParseMode";
public final static String ERROR_PARSER_SIMPLE_ID = "ErrorParser"; //$NON-NLS-1$ public final static String ERROR_PARSER_SIMPLE_ID = "ErrorParser"; //$NON-NLS-1$
// Build Model Interface Discovery // Build Model Interface Discovery
@ -236,6 +237,10 @@ public class CCorePlugin extends Plugin {
fDescriptorManager = new CDescriptorManager(); fDescriptorManager = new CDescriptorManager();
fDescriptorManager.startup(); fDescriptorManager.startup();
// Set the default for using the structual parse mode to build the CModel
getPluginPreferences().setDefault(PREF_USE_STRUCTURAL_PARSE_MODE, false);
} }
@ -750,4 +755,16 @@ public class CCorePlugin extends Plugin {
} }
} }
} }
// Preference to turn on/off the use of structural parse mode to build the CModel
public void setStructuralParseMode(boolean useNewParser) {
getPluginPreferences().setValue(PREF_USE_STRUCTURAL_PARSE_MODE, useNewParser);
savePluginPreferences();
}
public boolean useStructuralParseMode() {
return getPluginPreferences().getBoolean(PREF_USE_STRUCTURAL_PARSE_MODE);
}
} }

View file

@ -1,3 +1,9 @@
2003-12-15 Hoda Amer
Fixed [Bug 47234] new ParserMode required for a better CModel :
- Added a user preference to build the CModel using Structural mode
Enabled the Completion Engine and called the parser in Contextual Mode
Changed default user preference to Project scope until the completion engine is ready
2003-12-15 Thomas Fletcher 2003-12-15 Thomas Fletcher
Re-activate the hover help based on the function summary extension point. Re-activate the hover help based on the function summary extension point.
Fix a bug in the FunctionSummary class which displayed arguments as Fix a bug in the FunctionSummary class which displayed arguments as

View file

@ -17,7 +17,7 @@ CBasePreferencePage.consoleOnTop.label=Bring C-Build view to top when building (
CBasePreferencePage.buildConsole.errorMessage=Value must be an integer between 10 and 2147483647 CBasePreferencePage.buildConsole.errorMessage=Value must be an integer between 10 and 2147483647
CBasePreferencePage.linkToEditor.label=Link view selection to active editor CBasePreferencePage.linkToEditor.label=Link view selection to active editor
CBasePreferencePage.CUChildren.label=Show file members in Project View CBasePreferencePage.CUChildren.label=Show file members in Project View
CBasePreferencePage.useNewParser.label=Use New Parser for Code Model CBasePreferencePage.OutlineView.structuralParseMode.label=Use Structural-Parse mode to build the CModel
CBasePreferencePage.editorFont.label=C Editor font: CBasePreferencePage.editorFont.label=C Editor font:
CBasePreferencePage.consoleFont.label=C-Build view font: CBasePreferencePage.consoleFont.label=C-Build view font:

View file

@ -277,6 +277,10 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
store.setDefault(ExtendedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER, true); store.setDefault(ExtendedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER, true);
store.setDefault(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE, false);
store.setDefault(ContentAssistPreference.PROJECT_SEARCH_SCOPE, true);
store.setDefault(ContentAssistPreference.PROJECT_AND_DEPENDENCY_SEARCH_SCOPE, false);
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOT, true); store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOT, true);
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_ARROW, true); store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_ARROW, true);
store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOUBLECOLON, true); store.setDefault(ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOUBLECOLON, true);
@ -293,9 +297,6 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
//store.setDefault(ContentAssistPreference.CASE_SENSITIVITY, false); //store.setDefault(ContentAssistPreference.CASE_SENSITIVITY, false);
store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false); store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false);
store.setDefault(ContentAssistPreference.ADD_INCLUDE, true); store.setDefault(ContentAssistPreference.ADD_INCLUDE, true);
store.setDefault(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE, true);
store.setDefault(ContentAssistPreference.PROJECT_SEARCH_SCOPE, false);
store.setDefault(ContentAssistPreference.PROJECT_AND_DEPENDENCY_SEARCH_SCOPE, false);
} }

View file

@ -5,6 +5,7 @@ package org.eclipse.cdt.internal.ui.preferences;
* All Rights Reserved. * All Rights Reserved.
*/ */
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.internal.ui.ICHelpContextIds; import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
@ -24,8 +25,8 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements
private static final String LINK_TO_EDITOR_LABEL= "CBasePreferencePage.linkToEditor.label"; private static final String LINK_TO_EDITOR_LABEL= "CBasePreferencePage.linkToEditor.label";
private static final String SHOW_CU_CHILDREN_LABEL= "CBasePreferencePage.CUChildren.label"; private static final String SHOW_CU_CHILDREN_LABEL= "CBasePreferencePage.CUChildren.label";
private static final String USE_NEW_PARSER_LABEL= "CBasePreferencePage.useNewParser.label"; private static final String USE_STRUCTURAL_PARSE_MODE_LABEL= "CBasePreferencePage.OutlineView.structuralParseMode.label";
public CPluginPreferencePage() { public CPluginPreferencePage() {
super(GRID); super(GRID);
setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore()); setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
@ -50,6 +51,9 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements
BooleanFieldEditor showCUChildrenEditor= new BooleanFieldEditor(PreferenceConstants.PREF_SHOW_CU_CHILDREN, CUIPlugin.getResourceString(SHOW_CU_CHILDREN_LABEL), parent); BooleanFieldEditor showCUChildrenEditor= new BooleanFieldEditor(PreferenceConstants.PREF_SHOW_CU_CHILDREN, CUIPlugin.getResourceString(SHOW_CU_CHILDREN_LABEL), parent);
addField(showCUChildrenEditor); addField(showCUChildrenEditor);
BooleanFieldEditor useStructuralParseMode= new BooleanFieldEditor(PreferenceConstants.PREF_USE_STRUCTURAL_PARSE_MODE, CUIPlugin.getResourceString(USE_STRUCTURAL_PARSE_MODE_LABEL), parent);
addField(useStructuralParseMode);
} }
@ -61,10 +65,15 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements
return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_SHOW_CU_CHILDREN); return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_SHOW_CU_CHILDREN);
} }
public static boolean useStructuralParseMode() {
return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_USE_STRUCTURAL_PARSE_MODE);
}
/** /**
* @see IWorkbenchPreferencePage#init * @see IWorkbenchPreferencePage#init
*/ */
public void init(IWorkbench workbench) { public void init(IWorkbench workbench) {
CUIPlugin.getDefault().getPreferenceStore().setValue(CCorePlugin.PREF_USE_STRUCTURAL_PARSE_MODE, CCorePlugin.getDefault().useStructuralParseMode());
} }
/** /**
@ -73,6 +82,7 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements
public static void initDefaults(IPreferenceStore prefs) { public static void initDefaults(IPreferenceStore prefs) {
prefs.setDefault(PreferenceConstants.PREF_LINK_TO_EDITOR, true); prefs.setDefault(PreferenceConstants.PREF_LINK_TO_EDITOR, true);
prefs.setDefault(PreferenceConstants.PREF_SHOW_CU_CHILDREN, true); prefs.setDefault(PreferenceConstants.PREF_SHOW_CU_CHILDREN, true);
prefs.setDefault(PreferenceConstants.PREF_USE_STRUCTURAL_PARSE_MODE, CCorePlugin.getDefault().useStructuralParseMode());
prefs.setDefault(PreferenceConstants.EDITOR_SHOW_SEGMENTS, false); prefs.setDefault(PreferenceConstants.EDITOR_SHOW_SEGMENTS, false);
} }
@ -82,7 +92,8 @@ public class CPluginPreferencePage extends FieldEditorPreferencePage implements
public boolean performOk() { public boolean performOk() {
if (!super.performOk()) if (!super.performOk())
return false; return false;
// tell the Core Plugin about this preference
CCorePlugin.getDefault().setStructuralParseMode(useStructuralParseMode());
return true; return true;
} }

View file

@ -12,15 +12,12 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IMember;
import org.eclipse.cdt.core.model.IMethod;
import org.eclipse.cdt.core.model.IMethodDeclaration;
import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.search.BasicSearchMatch; import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.BasicSearchResultCollector; import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchConstants;
@ -28,9 +25,7 @@ import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.model.CElement; import org.eclipse.cdt.internal.core.model.CElement;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.matching.OrPattern; import org.eclipse.cdt.internal.core.search.matching.OrPattern;
import org.eclipse.cdt.internal.core.sourcedependency.DependencyQueryJob;
import org.eclipse.cdt.internal.corext.template.ContextType; import org.eclipse.cdt.internal.corext.template.ContextType;
import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry; import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
import org.eclipse.cdt.internal.ui.CCompletionContributorManager; import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
@ -46,8 +41,6 @@ import org.eclipse.cdt.ui.IFunctionSummary;
import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.text.ICCompletionProposal; import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
@ -327,6 +320,12 @@ public class CCompletionProcessor implements IContentAssistProcessor {
* Evaluate the actual proposals for C * Evaluate the actual proposals for C
*/ */
public ICCompletionProposal[] evalProposals(IDocument document, int pos, int length, ITranslationUnit unit) { public ICCompletionProposal[] evalProposals(IDocument document, int pos, int length, ITranslationUnit unit) {
try{
currentOffset = pos;
currentSourceUnit = unit.getWorkingCopy();
} catch (CModelException e){
}
return order (evalProposals(document, pos, length, getCurrentScope (unit, pos))); return order (evalProposals(document, pos, length, getCurrentScope (unit, pos)));
} }
@ -336,6 +335,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
String frag = ""; String frag = "";
int pos = startPos; int pos = startPos;
// Move back the pos by one the position is 0-based // Move back the pos by one the position is 0-based
if (pos > 0) { if (pos > 0) {
pos--; pos--;
@ -415,7 +415,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
ArrayList completions = new ArrayList(); ArrayList completions = new ArrayList();
// Look in index manager // Look in index manager
addProposalsFromModel(region, frag,currentScope, completions); addProposalsFromModel(region, completions);
// Loot in the contributed completions // Loot in the contributed completions
addProposalsFromCompletionContributors(region, frag, completions); addProposalsFromCompletionContributors(region, frag, completions);
@ -472,20 +472,21 @@ public class CCompletionProcessor implements IContentAssistProcessor {
} }
private void addProposalsFromModel (IRegion region, String frag, ICElement currentScope, ArrayList completions) { private void addProposalsFromModel (IRegion region, ArrayList completions) {
List elementsFound = new LinkedList();
String prefix = frag + "*";
// TODO: change that to resource scope later if (currentSourceUnit == null)
if (currentScope == null)
return; return;
// clear the completion list at the result collector // clear the completion list at the result collector
resultCollector.clearCompletions(); resultCollector.clearCompletions();
//invoke the completion engine //invoke the completion engine
//IASTCompletionNode completionNode = completionEngine.complete(currentSourceUnit, currentOffset, completions); IASTCompletionNode completionNode = completionEngine.complete(currentSourceUnit, currentOffset, completions);
if(completionNode == null)
return;
String prefix = completionNode.getCompletionPrefix();
String searchPrefix = prefix + "*";
// figure out the search scope // figure out the search scope
IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore(); IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
boolean fileScope = store.getBoolean(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE); boolean fileScope = store.getBoolean(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE);
@ -494,14 +495,32 @@ public class CCompletionProcessor implements IContentAssistProcessor {
ICSearchScope scope = null; ICSearchScope scope = null;
if ((projectScope) || (projectScopeAndDependency)){ if ((projectScope) || (projectScopeAndDependency)){
List elementsFound = new LinkedList();
resultCollector.clearCompletions();
//////////////////////
ICElement[] projectScopeElement = new ICElement[1]; ICElement[] projectScopeElement = new ICElement[1];
projectScopeElement[0] = (ICElement)currentScope.getCProject(); projectScopeElement[0] = (ICElement)currentSourceUnit.getCProject();
scope = SearchEngine.createCSearchScope(projectScopeElement, projectScopeAndDependency); scope = SearchEngine.createCSearchScope(projectScopeElement, projectScopeAndDependency);
OrPattern orPattern = new OrPattern();
// search for global variables, functions, classes, structs, unions, enums, macros, and namespaces
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( searchPrefix, ICSearchConstants.NAMESPACE, ICSearchConstants.DEFINITIONS, false ));
searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, searchResultCollector, true);
elementsFound.addAll(searchResultCollector.getSearchResults());
sendResultsToCollector(elementsFound.iterator(), region.getOffset(), region.getLength(), prefix );
} }
else{ else{
//Try to get the file /* //Try to get the file
IResource actualFile = currentScope.getUnderlyingResource(); IResource actualFile = currentSourceUnit.getUnderlyingResource();
IProject project = currentScope.getCProject().getProject(); IProject project = currentSourceUnit.getCProject().getProject();
ArrayList dependencies = new ArrayList(); ArrayList dependencies = new ArrayList();
if (actualFile != null){ if (actualFile != null){
//Get file's dependencies //Get file's dependencies
@ -513,59 +532,8 @@ public class CCompletionProcessor implements IContentAssistProcessor {
} }
//Create CFileSearchScope //Create CFileSearchScope
scope = SearchEngine.createCFileSearchScope((IFile) actualFile, dependencies); scope = SearchEngine.createCFileSearchScope((IFile) actualFile, dependencies);
} */ }
OrPattern orPattern = new OrPattern();
// search for global variables, functions, classes, structs, unions, enums and macros
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, false ));
searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, searchResultCollector, true);
elementsFound.addAll(searchResultCollector.getSearchResults());
if((currentScope instanceof IMethod) || (currentScope instanceof IMethodDeclaration) ){
// add the methods and fields of the parent class
// Work around until CElement scope is implemented
IStructure parentClass = (IStructure) currentScope.getParent();
ArrayList children = new ArrayList();
children.addAll(parentClass.getChildrenOfType(ICElement.C_METHOD));
children.addAll(parentClass.getChildrenOfType(ICElement.C_METHOD_DECLARATION));
children.addAll(parentClass.getChildrenOfType(ICElement.C_FIELD));
Iterator c = children.iterator();
while (c.hasNext()){
IMember child = (IMember)c.next();
if (child.getElementName().startsWith(frag))
{
BasicSearchMatch childMatch = new BasicSearchMatch();
childMatch.setType(child.getElementType());
childMatch.setParentName(parentClass.getElementName());
if(child.getVisibility() == ASTAccessVisibility.PUBLIC )
childMatch.setVisibility(ICElement.CPP_PUBLIC);
else if(child.getVisibility() == ASTAccessVisibility.PROTECTED )
childMatch.setVisibility(ICElement.CPP_PROTECTED);
else if(child.getVisibility() == ASTAccessVisibility.PRIVATE )
childMatch.setVisibility(ICElement.CPP_PRIVATE);
childMatch.setConst(child.isConst());
childMatch.setVolatile(child.isVolatile());
childMatch.setStatic(child.isStatic());
if(child instanceof IMethodDeclaration){
childMatch.setName(((IMethodDeclaration)child).getSignature());
childMatch.setReturnType( ((IMethodDeclaration)child).getReturnType() );
}
else {
childMatch.setName(child.getElementName());
}
elementsFound.add(childMatch);
}
}
}
sendResultsToCollector(elementsFound.iterator(), region.getOffset(), region.getLength(), frag );
completions.addAll(resultCollector.getCompletions()); completions.addAll(resultCollector.getCompletions());
} }

View file

@ -165,8 +165,8 @@ public class CompletionEngine implements RelevanceConstants{
IParser parser = null; IParser parser = null;
try try
{ {
IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.COMPLETE_PARSE, language, requestor, ParserUtil.getParserLogService() ); IScanner scanner = ParserFactory.createScanner( reader, realPath.toOSString(), scanInfo, ParserMode.CONTEXTUAL_PARSE, language, requestor, ParserUtil.getParserLogService() );
parser = ParserFactory.createParser( scanner, requestor, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() ); parser = ParserFactory.createParser( scanner, requestor, ParserMode.CONTEXTUAL_PARSE, language, ParserUtil.getParserLogService() );
} }
catch( ParserFactoryException pfe ) catch( ParserFactoryException pfe )
{ {
@ -269,6 +269,8 @@ public class CompletionEngine implements RelevanceConstants{
} }
private void addToCompletions (LookupResult result){ private void addToCompletions (LookupResult result){
if(result == null)
return;
Iterator nodes = result.getNodes(); Iterator nodes = result.getNodes();
while (nodes.hasNext()){ while (nodes.hasNext()){
IASTNode node = (IASTNode) nodes.next(); IASTNode node = (IASTNode) nodes.next();

View file

@ -12,8 +12,8 @@ import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.cdt.internal.ui.text.ICColorConstants; import org.eclipse.cdt.internal.ui.text.ICColorConstants;
/** /**
* Preference constants used in the JDT-UI preference store. Clients should only read the * Preference constants used in the CDT-UI preference store. Clients should only read the
* JDT-UI preference store using these values. Clients are not allowed to modify the * CDT-UI preference store using these values. Clients are not allowed to modify the
* preference store programmatically. * preference store programmatically.
* *
* @since 2.0 * @since 2.0
@ -54,6 +54,14 @@ public class PreferenceConstants {
* </p> * </p>
*/ */
public static final String PREF_SHOW_CU_CHILDREN= "org.eclipse.cdt.ui.editor.CUChildren"; //$NON-NLS-1$ public static final String PREF_SHOW_CU_CHILDREN= "org.eclipse.cdt.ui.editor.CUChildren"; //$NON-NLS-1$
/**
* A named preference that speficies whether to use the parser's structural mode to build the CModel.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*/
public static final String PREF_USE_STRUCTURAL_PARSE_MODE= "org.eclipse.cdt.ui.editor.UseStructuralMode"; //$NON-NLS-1$
/** /**
* A named preference that controls if segmented view (show selected element only) is turned on or off. * A named preference that controls if segmented view (show selected element only) is turned on or off.