From 9b33f17d3f9e3c295cf830f4d3a26130e318ede0 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Wed, 1 Oct 2003 20:34:58 +0000 Subject: [PATCH] CORE Fixed Bug 43987 : Search results: Declaration of class not highlighted when selected Fixed Bug 43997 : Search results: selection includes preceding whitespace Fixed Bug 44034 : Scanner failure on #undef --- core/org.eclipse.cdt.core/parser/ChangeLog | 5 ++ .../eclipse/cdt/core/parser/ITokenDuple.java | 2 + .../cdt/core/parser/ScannerException.java | 3 - .../cdt/core/parser/ast/IASTFactory.java | 2 +- .../core/parser/DeclarationWrapper.java | 2 +- .../cdt/internal/core/parser/Parser.java | 2 +- .../cdt/internal/core/parser/Scanner.java | 3 +- .../cdt/internal/core/parser/TokenDuple.java | 19 ++++ .../ast/complete/CompleteParseASTFactory.java | 87 +++++++++---------- .../ast/quick/QuickParseASTFactory.java | 4 +- 10 files changed, 72 insertions(+), 57 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 5752b2c50fc..24411a308bf 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,8 @@ +2003-10-01 John Camelon + Fixed Bug 43987 : Search results: Declaration of class not highlighted when selected + Fixed Bug 43997 : Search results: selection includes preceding whitespace + Fixed Bug 44034 : Scanner failure on #undef + 2003-10-01 Bogdan Gheorghe Modified CDT log dump in Parser.fetchToken to include error message diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java index bb70ce689a0..e77af7c4200 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java @@ -32,4 +32,6 @@ public interface ITokenDuple { public abstract ITokenDuple getSubrange( int startIndex, int endIndex ); public IToken getToken(int index); + + public int findLastTokenType( int type ); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ScannerException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ScannerException.java index 40b6feea139..2d9d75d614a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ScannerException.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ScannerException.java @@ -33,7 +33,6 @@ public class ScannerException extends Exception { public static final ErrorCode BAD_HEXIDECIMAL_FORMAT = new ErrorCode( 7 ); public static final ErrorCode INVALID_PREPROCESSOR_DIRECTIVE = new ErrorCode( 8 ); public static final ErrorCode ATTEMPTED_REDEFINITION = new ErrorCode( 9 ); - public static final ErrorCode UNDEF_DEFINITION_NOT_FOUND = new ErrorCode( 10 ); public static final ErrorCode INVALID_ESCAPE_CHARACTER_SEQUENCE = new ErrorCode( 11 ); public static final ErrorCode EXPRESSION_EVALUATION_ERROR = new ErrorCode( 12 ); public static final ErrorCode UNEXPECTED_EOF = new ErrorCode(13); @@ -82,7 +81,6 @@ public class ScannerException extends Exception { this == ErrorCode.UNEXPECTED_EOF || this == ErrorCode.MACRO_USAGE_ERROR || this == ErrorCode.MACRO_PASTING_ERROR || - this == ErrorCode.UNDEF_DEFINITION_NOT_FOUND || this == ErrorCode.EXPRESSION_EVALUATION_ERROR || this == ErrorCode.INVALID_PREPROCESSOR_DIRECTIVE || this == ErrorCode.ATTEMPTED_REDEFINITION ) @@ -114,7 +112,6 @@ public class ScannerException extends Exception { errorMessages.put( ErrorCode.DEFINITION_NOT_FOUND, "Definition not found: " ); errorMessages.put( ErrorCode.MALFORMED_MACRO_DEFN, "Macro definition malformed: " ); errorMessages.put( ErrorCode.ATTEMPTED_REDEFINITION, "" ); - errorMessages.put( ErrorCode.UNDEF_DEFINITION_NOT_FOUND, "" ); errorMessages.put( ErrorCode.INVALID_ESCAPE_CHARACTER_SEQUENCE, "" ); errorMessages.put( ErrorCode.EXPRESSION_EVALUATION_ERROR, "" ); errorMessages.put( ErrorCode.MACRO_USAGE_ERROR, "" ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java index b2149ec60c0..f60289eec83 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java @@ -132,7 +132,7 @@ public interface IASTFactory boolean isUnsigned, boolean isTypename) throws ASTSemanticException, Exception; public IASTFunction createFunction( IASTScope scope, - String name, + ITokenDuple name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java index 8fb09a1becd..e48311c92cf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java @@ -503,7 +503,7 @@ public class DeclarationWrapper implements IDeclaratorOwner { return astFactory.createFunction( scope, - nested ? declarator.getOwnedDeclarator().getName() : declarator.getName(), + nested ? declarator.getOwnedDeclarator().getNamedDuple() : declarator.getNamedDuple(), createParameterList(declarator.getParameters()), astFactory.createAbstractDeclaration( constt, diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index bb35d3b3bf7..40b52e07814 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -2602,7 +2602,7 @@ public class Parser implements IParser access, classKey.getOffset(), duple == null ? classKey.getOffset() : duple.getFirstToken().getOffset(), - duple == null ? classKey.getEndOffset() : duple.getFirstToken().getOffset() ); + duple == null ? classKey.getEndOffset() : duple.getFirstToken().getEndOffset() ); } catch (ASTSemanticException e) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java index 9bb7f1ae2fc..a1ef6396ac4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java @@ -1047,8 +1047,7 @@ public class Scanner implements IScanner { // definition String toBeUndefined = getNextIdentifier(); - if( ( definitions.remove(toBeUndefined) == null ) && mode == ParserMode.COMPLETE_PARSE ) - throw new ScannerException( ScannerException.ErrorCode.UNDEF_DEFINITION_NOT_FOUND, toBeUndefined, getCurrentFile(), getCurrentOffset() ); + definitions.remove(toBeUndefined); skipOverTextUntilNewline(); c = getChar(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java index 1cf3b5ed72c..e0d0c99b78f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TokenDuple.java @@ -153,5 +153,24 @@ public class TokenDuple implements ITokenDuple { } return null; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ITokenDuple#findLastTokenType(int) + */ + public int findLastTokenType(int type) + { + int count = 0; + int lastFound = -1; + Iterator i = iterator(); + while( i.hasNext() ) + { + IToken token = (IToken)i.next(); + if( token.getType() == type ) + lastFound = count; + ++count; + } + + return lastFound; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index f73186a1fbc..4801dd51c09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -1418,7 +1418,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto */ public IASTFunction createFunction( IASTScope scope, - String name, + ITokenDuple name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, @@ -1441,43 +1441,15 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto IContainerSymbol ownerScope = scopeToSymbol( scope ); // check if this is a method in a body file - StringTokenizer tokenizer = new StringTokenizer(name,DOUBLE_COLON); - int tokencount = tokenizer.countTokens(); - if(tokencount > 1){ - List tokens = new ArrayList(); - String oneToken = ""; - // This is NOT a function. This is a method definition - while (tokenizer.hasMoreTokens()){ - oneToken = tokenizer.nextToken(); - tokens.add(oneToken); - } - - String functionName = oneToken; -// String parentName = name.substring(0, name.lastIndexOf(DOUBLE_COLON)); + Iterator tokenizer = name.iterator(); + if(name.length() > 1){ + IContainerSymbol parentScope = (IContainerSymbol) + lookupQualifiedName( + ownerScope, + name.getSubrange( 0, name.findLastTokenType( IToken.tCOLONCOLON ) - 1), + references, + false ); - int numOfTokens = 1; - int offset = nameOffset; - IContainerSymbol parentScope = ownerScope; - Iterator i = tokens.iterator(); - while (i.hasNext() && (numOfTokens++) < tokens.size()){ - String token = (String) i.next(); - IContainerSymbol parentSymbol = - (IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_class, null, offset, references, false); - if(parentSymbol == null){ - parentSymbol = (IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_namespace, null, offset, references, false); - } - if(parentSymbol == null){ - parentSymbol = (IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_struct, null, offset, references, false); - } - if(parentSymbol == null){ - parentSymbol = (IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_union, null, offset, references, false); - } if(parentSymbol == null) - break; - else { - parentScope = parentSymbol; - offset += token.length()+ DOUBLE_COLON.length(); - } - } if((parentScope != null) && ( (parentScope.getType() == TypeInfo.t_class) @@ -1485,14 +1457,35 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto || (parentScope.getType() == TypeInfo.t_union)) ){ IASTScope methodParentScope = (IASTScope)parentScope.getASTExtension().getPrimaryDeclaration(); - return createMethod(methodParentScope, functionName,nameEndOffset, parameters, returnType, - exception, isInline, isFriend, isStatic, startOffset, offset, - ownerTemplate, isConst, isVolatile, isVirtual, isExplicit, isPureVirtual, - ASTAccessVisibility.PRIVATE, constructorChain, references, isFunctionDefinition); + ITokenDuple newName = name.getSubrange( + name.findLastTokenType( IToken.tCOLONCOLON) + 1, + name.length() - 1 ); + return createMethod( + methodParentScope, + newName.toString(), + parameters, + returnType, + exception, + isInline, + isFriend, + isStatic, + startOffset, + newName.getFirstToken().getOffset(), + nameEndOffset, + ownerTemplate, + isConst, + isVolatile, + isVirtual, + isExplicit, + isPureVirtual, + ASTAccessVisibility.PRIVATE, + constructorChain, + references, + isFunctionDefinition); } } - IParameterizedSymbol symbol = pst.newParameterizedSymbol( name, TypeInfo.t_function ); + IParameterizedSymbol symbol = pst.newParameterizedSymbol( name.getLastToken().getImage(), TypeInfo.t_function ); setFunctionTypeInfoBits(isInline, isFriend, isStatic, symbol); setParameter( symbol, returnType, false, references ); @@ -1514,7 +1507,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto IParameterizedSymbol functionDeclaration = null; functionDeclaration = - (IParameterizedSymbol) lookupQualifiedName(ownerScope, name, TypeInfo.t_function, functionParameters, 0, new ArrayList(), false); + (IParameterizedSymbol) lookupQualifiedName(ownerScope, name.getLastToken().getImage(), TypeInfo.t_function, functionParameters, 0, new ArrayList(), false); if( functionDeclaration != null ) { @@ -1741,8 +1734,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isFunctionDefinition ) throws ASTSemanticException { - return createMethod(scope, name, nameEndOffset, parameters, returnType, - exception, isInline, isFriend, isStatic, startOffset, nameOffset, + return createMethod(scope, name, parameters, returnType, exception, + isInline, isFriend, isStatic, startOffset, nameOffset, nameEndOffset, ownerTemplate, isConst, isVolatile, isVirtual, isExplicit, isPureVirtual, visibility, constructorChain, null, isFunctionDefinition ); } @@ -1750,8 +1743,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto public IASTMethod createMethod( IASTScope scope, String name, - int nameEndOffset, - List parameters, + List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, @@ -1759,6 +1751,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto boolean isStatic, int startOffset, int nameOffset, + int nameEndOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java index e349faf0a14..4445e3b9b90 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java @@ -184,9 +184,9 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createFunction(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) */ - public IASTFunction createFunction(IASTScope scope, String name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, int nameEndOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, List constructorChain, boolean isFunctionDefinition ) + public IASTFunction createFunction(IASTScope scope, ITokenDuple name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, int nameEndOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, List constructorChain, boolean isFunctionDefinition ) { - return new ASTFunction(scope, name, nameEndOffset, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate ); + return new ASTFunction(scope, name.toString(), nameEndOffset, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate ); } /* (non-Javadoc)