mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
org.eclipse.cdt.core
Added preliminary (crude) SelectionParser IParser implementation for SELECTION_PARSE clients. org.eclipse.cdt.core.tests Added preliminary SelectionParseTests to test SELECTION_PARSE clients. Added SelectionParseTests to ParserTestSuite.
This commit is contained in:
parent
395c81dceb
commit
1f042fb9a2
11 changed files with 189 additions and 58 deletions
|
@ -1,5 +1,5 @@
|
|||
2004-02-04 John Camelon
|
||||
Added preliminary (crude) SelectionParser IParser implementation for SELECTION_PARSE clients.
|
||||
Added preliminary (crude) bSelectionParser IParser implementation for SELECTION_PARSE clients.
|
||||
|
||||
2004-02-01 John Camelon
|
||||
Added CompletionKind.UNREACHABLE_CODE to IASTCompletionNode.
|
||||
|
|
|
@ -12,6 +12,10 @@ package org.eclipse.cdt.core.parser;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -25,6 +29,8 @@ public interface ITokenDuple {
|
|||
* @return
|
||||
*/
|
||||
public abstract IToken getLastToken();
|
||||
|
||||
|
||||
public abstract Iterator iterator();
|
||||
public abstract String toString();
|
||||
public abstract boolean isIdentifier();
|
||||
|
@ -34,4 +40,6 @@ public interface ITokenDuple {
|
|||
public IToken getToken(int index);
|
||||
|
||||
public int findLastTokenType( int type );
|
||||
|
||||
public IASTNode lookup( IASTFactory factory, IASTScope scope );
|
||||
}
|
|
@ -24,7 +24,7 @@ public class ParseError extends Error {
|
|||
|
||||
// offset specified is within a section of code #if'd out by the preprocessor
|
||||
// semantic context cannot be provided in this case
|
||||
public static final ParseErrorKind OFFSET_PREPROCESSED_OUT = new ParseErrorKind( 1 );
|
||||
public static final ParseErrorKind OFFSETDUPLE_UNREACHABLE = new ParseErrorKind( 1 );
|
||||
|
||||
// offset range specified is not a valid identifier or qualified name
|
||||
// semantic context cannot be provided in this case
|
||||
|
|
|
@ -16,10 +16,11 @@ import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
|||
import org.eclipse.cdt.core.parser.extension.ExtensionDialect;
|
||||
import org.eclipse.cdt.core.parser.extension.IParserExtensionFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.CompleteParser;
|
||||
import org.eclipse.cdt.internal.core.parser.ContextualParser;
|
||||
import org.eclipse.cdt.internal.core.parser.CompletionParser;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserExtensionFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.QuickParseCallback;
|
||||
import org.eclipse.cdt.internal.core.parser.QuickParser;
|
||||
import org.eclipse.cdt.internal.core.parser.SelectionParser;
|
||||
import org.eclipse.cdt.internal.core.parser.StructuralParseCallback;
|
||||
import org.eclipse.cdt.internal.core.parser.StructuralParser;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
|
||||
|
@ -57,9 +58,9 @@ public class ParserFactory {
|
|||
else if( ourMode == ParserMode.STRUCTURAL_PARSE )
|
||||
return new StructuralParser( scanner, ourCallback, language, logService );
|
||||
else if( ourMode == ParserMode.COMPLETION_PARSE )
|
||||
return new ContextualParser( scanner, ourCallback, language, logService );
|
||||
else if( ourMode == ParserMode.SELECTION_PARSE )
|
||||
return null; // TODO Implementation required
|
||||
return new CompletionParser( scanner, ourCallback, language, logService );
|
||||
else if (ourMode == ParserMode.SELECTION_PARSE )
|
||||
return new SelectionParser( scanner, ourCallback, language, logService );
|
||||
else
|
||||
return new QuickParser( scanner, ourCallback, language, logService );
|
||||
}
|
||||
|
|
|
@ -240,5 +240,7 @@ public interface IASTFactory
|
|||
* @param kind
|
||||
* @param firstExpression
|
||||
*/
|
||||
public IASTNode getCompletionContext(Kind kind, IASTExpression expression);
|
||||
public IASTNode getCompletionContext(Kind kind, IASTExpression expression);
|
||||
|
||||
public IASTNode lookupSymbolInContext( IASTScope scope, ITokenDuple duple ) throws ASTNotImplementedException;
|
||||
}
|
|
@ -22,6 +22,7 @@ import org.eclipse.cdt.core.parser.IScanner;
|
|||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
|
||||
import org.eclipse.cdt.core.parser.ParseError;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
|
@ -40,21 +41,22 @@ import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
|
|||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class ContextualParser extends Parser implements IParser {
|
||||
public class CompletionParser extends CompleteParser implements IParser {
|
||||
|
||||
protected CompletionKind kind;
|
||||
protected IASTScope scope;
|
||||
protected IASTNode context;
|
||||
protected IToken finalToken;
|
||||
private Set keywordSet;
|
||||
|
||||
protected IASTScope scope;
|
||||
|
||||
|
||||
/**
|
||||
* @param scanner
|
||||
* @param callback
|
||||
* @param language
|
||||
* @param log
|
||||
*/
|
||||
public ContextualParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log) {
|
||||
public CompletionParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log) {
|
||||
super(scanner, callback, language, log);
|
||||
astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETION_PARSE, language);
|
||||
scanner.setASTFactory(astFactory);
|
||||
|
@ -91,31 +93,24 @@ public class ContextualParser extends Parser implements IParser {
|
|||
/**
|
||||
* @return
|
||||
*/
|
||||
private Set getKeywordSet() {
|
||||
protected Set getKeywordSet() {
|
||||
return keywordSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private String getCompletionPrefix() {
|
||||
protected String getCompletionPrefix() {
|
||||
return ( finalToken == null ? "" : finalToken.getImage() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private IASTNode getCompletionContext() {
|
||||
protected IASTNode getCompletionContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private IASTScope getCompletionScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
|
@ -123,24 +118,6 @@ public class ContextualParser extends Parser implements IParser {
|
|||
return kind;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
||||
*/
|
||||
public IASTNode parse(int startingOffset, int endingOffset) {
|
||||
scanner.setOffsetBoundary(endingOffset);
|
||||
translationUnit();
|
||||
return getCompletionContext();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.Parser#setCurrentScope(org.eclipse.cdt.core.parser.ast.IASTScope)
|
||||
*/
|
||||
protected void setCompletionScope(IASTScope scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
protected void setCompletionContext( IASTNode node )
|
||||
{
|
||||
this.context = node;
|
||||
|
@ -152,19 +129,6 @@ public class ContextualParser extends Parser implements IParser {
|
|||
}
|
||||
|
||||
|
||||
protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws BacktrackException, EndOfFileException
|
||||
{
|
||||
if ( isInlineFunction )
|
||||
skipOverCompoundStatement();
|
||||
else
|
||||
functionBody(scope);
|
||||
}
|
||||
|
||||
protected void catchBlockCompoundStatement(IASTScope scope) throws BacktrackException, EndOfFileException
|
||||
{
|
||||
compoundStatement(scope, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.Parser#handleOffsetLimitException()
|
||||
*/
|
||||
|
@ -191,7 +155,7 @@ public class ContextualParser extends Parser implements IParser {
|
|||
* @param object
|
||||
* @param string
|
||||
*/
|
||||
private void setCompletionValues(CompletionKind kind, Set keywordSet, String prefix ) {
|
||||
protected void setCompletionValues(CompletionKind kind, Set keywordSet, String prefix ) {
|
||||
setCompletionScope(compilationUnit);
|
||||
this.keywordSet = keywordSet;
|
||||
setCompletionKind(kind);
|
||||
|
@ -316,6 +280,24 @@ public class ContextualParser extends Parser implements IParser {
|
|||
catchBlockCompoundStatement(scope);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected IASTScope getCompletionScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public IASTNode parse(int startingOffset, int endingOffset) {
|
||||
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
||||
}
|
||||
|
||||
protected void setCompletionScope(IASTScope scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public boolean parse() {
|
||||
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
||||
}
|
||||
|
||||
}
|
|
@ -5293,7 +5293,9 @@ public abstract class Parser implements IParser
|
|||
|
||||
try
|
||||
{
|
||||
return scanner.nextToken();
|
||||
IToken value = scanner.nextToken();
|
||||
handleNewToken( value );
|
||||
return value;
|
||||
}
|
||||
catch( OffsetLimitReachedException olre )
|
||||
{
|
||||
|
@ -5310,7 +5312,13 @@ public abstract class Parser implements IParser
|
|||
}
|
||||
}
|
||||
|
||||
protected void handleOffsetLimitException(OffsetLimitReachedException exception) throws EndOfFileException {
|
||||
/**
|
||||
* @param value
|
||||
*/
|
||||
protected void handleNewToken(IToken value) throws EndOfFileException {
|
||||
}
|
||||
|
||||
protected void handleOffsetLimitException(OffsetLimitReachedException exception) throws EndOfFileException {
|
||||
// unexpected, throw EOF instead (equivalent)
|
||||
throw new EndOfFileException();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/**********************************************************************
|
||||
* 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.parser;
|
||||
|
||||
import org.eclipse.cdt.core.parser.EndOfFileException;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
import org.eclipse.cdt.core.parser.ParseError;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.internal.core.parser.token.OffsetDuple;
|
||||
import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class SelectionParser extends CompletionParser {
|
||||
|
||||
private OffsetDuple offsetRange;
|
||||
private IToken firstTokenOfDuple = null, lastTokenOfDuple = null;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.Parser#handleNewToken(org.eclipse.cdt.core.parser.IToken)
|
||||
*/
|
||||
protected void handleNewToken(IToken value) throws EndOfFileException {
|
||||
if( value != null )
|
||||
{
|
||||
if( value.getOffset() == offsetRange.getFloorOffset() )
|
||||
firstTokenOfDuple = value;
|
||||
if( value.getEndOffset() == offsetRange.getCeilingOffset() )
|
||||
{
|
||||
lastTokenOfDuple = value;
|
||||
throw new EndOfFileException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param scanner
|
||||
* @param callback
|
||||
* @param mode
|
||||
* @param language
|
||||
* @param log
|
||||
*/
|
||||
public SelectionParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log) {
|
||||
super(scanner, callback, language, log);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
|
||||
*/
|
||||
public IASTNode parse(int startingOffset, int endingOffset) {
|
||||
scanner.setOffsetBoundary(endingOffset);
|
||||
offsetRange = new OffsetDuple( startingOffset, endingOffset );
|
||||
translationUnit();
|
||||
return reconcileTokenDuple();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected IASTNode reconcileTokenDuple() throws ParseError {
|
||||
if( firstTokenOfDuple == null || lastTokenOfDuple == null )
|
||||
throw new ParseError( ParseError.ParseErrorKind.OFFSET_RANGE_NOT_NAME );
|
||||
|
||||
if( getCompletionKind() == IASTCompletionNode.CompletionKind.UNREACHABLE_CODE )
|
||||
throw new ParseError( ParseError.ParseErrorKind.OFFSETDUPLE_UNREACHABLE );
|
||||
|
||||
ITokenDuple duple = new TokenDuple( firstTokenOfDuple, lastTokenOfDuple );
|
||||
return duple.lookup( astFactory, getCompletionScope() );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IParser#parse(int)
|
||||
*/
|
||||
public IASTCompletionNode parse(int offset) {
|
||||
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
|
||||
}
|
||||
}
|
|
@ -2821,4 +2821,18 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
return null;
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#lookupSymbolInContext(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ITokenDuple)
|
||||
*/
|
||||
public IASTNode lookupSymbolInContext(IASTScope scope, ITokenDuple duple) throws ASTNotImplementedException {
|
||||
ISymbol s = null;
|
||||
try {
|
||||
s = lookupQualifiedName( scopeToSymbol( scope ), duple, new ArrayList(), false );
|
||||
} catch (ASTSemanticException e) {
|
||||
}
|
||||
if ( s == null )
|
||||
return null;
|
||||
return s.getASTExtension().getPrimaryDeclaration();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -347,4 +347,11 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
|
|||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#lookupSymbolInContext(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ITokenDuple)
|
||||
*/
|
||||
public IASTNode lookupSymbolInContext(IASTScope scope, ITokenDuple duple) throws ASTNotImplementedException {
|
||||
throw new ASTNotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,10 @@ import java.util.NoSuchElementException;
|
|||
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ITokenDuple;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -110,7 +114,7 @@ public class TokenDuple implements ITokenDuple {
|
|||
|
||||
public boolean isIdentifier()
|
||||
{
|
||||
return ( firstToken == lastToken );
|
||||
return ( (firstToken == lastToken ) && (firstToken.getType() == IToken.tIDENTIFIER ));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -172,5 +176,18 @@ public class TokenDuple implements ITokenDuple {
|
|||
|
||||
return lastFound;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ITokenDuple#lookup(org.eclipse.cdt.core.parser.ast.IASTFactory)
|
||||
*/
|
||||
public IASTNode lookup(IASTFactory factory, IASTScope scope) {
|
||||
// check syntax of the node
|
||||
|
||||
try {
|
||||
return factory.lookupSymbolInContext(scope, this );
|
||||
} catch (ASTNotImplementedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue