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

org.eclipse.cdt.core

Updated SelectionSearch to work for functions, variables with initializers, etc.
	Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=39705
	Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=44336  
	Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=36770  
	Partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=51428  
	Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=39694  

org.eclipse.cdt.core.tests
	Added SelectionParseTest::testBaseCase_FunctionDeclaration().  
	Added SelectionParseTest::testBaseCase_FunctionDeclaration2().  
	Added SelectionParseTest::testBaseCase_VariableDeclaration().  
	Added SelectionParseTest::testBaseCase_Parameter().  
	Added QuickParseASTTests::testBug44336().  
	Added ScannerTestCase::testBug36770B(). 
	Moved testBug39705() from ASTFailedTests to QuickParseASTTests.  
	Moved testBug39694() from ASTFailedTests to QuickParseASTTests.
This commit is contained in:
John Camelon 2004-04-02 18:51:01 +00:00
parent 9a23d4eb95
commit 11d74c9995
15 changed files with 317 additions and 120 deletions

View file

@ -1,3 +1,13 @@
2004-04-02 John Camelon
Added SelectionParseTest::testBaseCase_FunctionDeclaration().
Added SelectionParseTest::testBaseCase_FunctionDeclaration2().
Added SelectionParseTest::testBaseCase_VariableDeclaration().
Added SelectionParseTest::testBaseCase_Parameter().
Added QuickParseASTTests::testBug44336().
Added ScannerTestCase::testBug36770B().
Moved testBug39705() from ASTFailedTests to QuickParseASTTests.
Moved testBug39694() from ASTFailedTests to QuickParseASTTests.
2004-03-29 John Camelon 2004-03-29 John Camelon
Added ScannerTestCase::testBug56517(). Added ScannerTestCase::testBug56517().

View file

@ -116,13 +116,7 @@ public class ASTFailedTests extends BaseASTTest
} }
assertCodeFailsParse(code.toString()); assertCodeFailsParse(code.toString());
} }
public void testBug39694() throws Exception
{
IASTVariable variable = (IASTVariable)parse("int ab$cd = 1;").getDeclarations().next();
assertFalse(
"The expected error did not occur.",
variable.equals("ab$cd"));
}
public void testBug39695() throws Exception public void testBug39695() throws Exception
{ {
assertCodeFailsParse("int a = __alignof__ (int);"); assertCodeFailsParse("int a = __alignof__ (int);");
@ -225,10 +219,7 @@ public class ASTFailedTests extends BaseASTTest
{ {
assertCodeFailsParse("__declspec(dllexport) int func1 (int a) {}"); assertCodeFailsParse("__declspec(dllexport) int func1 (int a) {}");
} }
public void testBug39705() throws Exception
{
assertCodeFailsParse("#ident \"@(#)filename.c 1.3 90/02/12\"");
}
public void testBug40422() throws Exception { public void testBug40422() throws Exception {

View file

@ -184,6 +184,8 @@ public class BaseScannerTest extends TestCase {
} }
} }
public void validateDefinition(String name, String value) public void validateDefinition(String name, String value)
{ {
String definition= null; String definition= null;

View file

@ -2115,4 +2115,25 @@ public class QuickParseASTTests extends BaseASTTest
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
} }
public void testBug44336() throws Exception
{
Iterator i = parse( "class A {}; typedef typename A foo;" ).getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
assertEquals( classA.getClassKind(), ASTClassKind.CLASS );
assertEquals( classA.getName(), "A");
IASTTypedefDeclaration typedefDeclaration = (IASTTypedefDeclaration) i.next();
assertFalse( i.hasNext() );
}
public void testBug39705() throws Exception
{
parse("#ident \"@(#)filename.c 1.3 90/02/12\"");
}
public void testBug39694() throws Exception
{
IASTVariable variable = (IASTVariable)parse("int ab$cd = 1;").getDeclarations().next();
assertEquals( variable.getName(), "ab$cd");
}
} }

View file

@ -1588,12 +1588,21 @@ public class ScannerTestCase extends BaseScannerTest
writer.write( "#endif\n"); writer.write( "#endif\n");
initializeScanner( writer.toString() ); initializeScanner( writer.toString() );
validateEOF(); validateEOF();
// validateToken( IToken.t_char); }
// validateToken( IToken.tSTAR);
// validateIdentifier( "x"); public void testBug36770B() throws Exception
// validateToken( IToken.tASSIGN ); {
// validateString( "#boo"); Writer writer = new StringWriter();
// validateToken(IToken.tSEMI); writer.write( "#define A 0\n" );
// validateEOF(); writer.write( "#if ( A == 1 )\n" );
writer.write( "# define foo\n" );
writer.write( "#else\n" );
writer.write( "# define bar\n" );
writer.write( "#endif\n" );
initializeScanner( writer.toString(), ParserMode.QUICK_PARSE );
validateEOF();
validateDefinition( "A", 0 );
validateDefinition( "bar", "" );
} }
} }

View file

@ -21,6 +21,7 @@ import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariable;
/** /**
@ -55,7 +56,7 @@ public class SelectionParseTest extends CompleteParseBaseTest {
public void testBaseCase_VariableReference() throws Exception public void testBaseCase_VariableReference() throws Exception
{ {
String code = "int x; x=3;"; String code = "void f() { int x; x=3; }";
int offset1 = code.indexOf( "x=" ); int offset1 = code.indexOf( "x=" );
int offset2 = code.indexOf( '='); int offset2 = code.indexOf( '=');
IASTNode node = parse( code, offset1, offset2 ); IASTNode node = parse( code, offset1, offset2 );
@ -81,25 +82,47 @@ public class SelectionParseTest extends CompleteParseBaseTest {
assertNull( parse( code, offset1, offset2 )); assertNull( parse( code, offset1, offset2 ));
} }
// public void testBaseCase_FunctionDeclaration() throws Exception public void testBaseCase_FunctionDeclaration() throws Exception
// { {
// String code = "int x(); x( );"; String code = "int x(); x( );";
// int offset1 = code.indexOf( "x()" ); int offset1 = code.indexOf( "x()" );
// int offset2 = code.indexOf( "()"); int offset2 = code.indexOf( "()");
// IASTNode node = parse( code, offset1, offset2 ); IASTNode node = parse( code, offset1, offset2 );
// assertTrue( node instanceof IASTFunction ); assertTrue( node instanceof IASTFunction );
// assertEquals( ((IASTFunction)node).getName(), "x" ); assertEquals( ((IASTFunction)node).getName(), "x" );
// } }
//
// public void testBaseCase_VariableDeclaration() throws Exception public void testBaseCase_FunctionDeclaration2() throws Exception
// { {
// String code = "int x = 3;"; String code = "int printf( const char *, ... ); ";
// int offset1 = code.indexOf( "x" ); int offset1 = code.indexOf( "printf" );
// int offset2 = code.indexOf( " ="); int offset2 = code.indexOf( "( const");
// IASTNode node = parse( code, offset1, offset2 ); IASTNode node = parse( code, offset1, offset2 );
// assertTrue( node instanceof IASTVariable ); assertTrue( node instanceof IASTFunction );
// assertEquals( ((IASTVariable)node).getName(), "x" ); assertEquals( ((IASTFunction)node).getName(), "printf" );
// } }
public void testBaseCase_VariableDeclaration() throws Exception
{
String code = "int x = 3;";
int offset1 = code.indexOf( "x" );
int offset2 = code.indexOf( " =");
IASTNode node = parse( code, offset1, offset2 );
assertNotNull( node );
assertTrue( node instanceof IASTVariable );
assertEquals( ((IASTVariable)node).getName(), "x" );
}
public void testBaseCase_Parameter() throws Exception
{
String code = "int main( int argc ) { int x = argc; }";
int offset1 = code.indexOf( "argc;" );
int offset2 = code.indexOf( ";" );
IASTNode node = parse( code, offset1, offset2 );
assertNotNull( node );
assertTrue( node instanceof IASTParameterDeclaration );
assertEquals( ((IASTParameterDeclaration)node).getName(), "argc" );
}
} }

View file

@ -1,3 +1,11 @@
2004-04-02 John Camelon
Updated SelectionSearch to work for functions, variables with initializers, etc.
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=39705
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=44336
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=36770
Partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=51428
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=39694
2004-03-30 John Camelon 2004-03-30 John Camelon
Partial fix for Bug 56614 - Content Assist] Global variables do not appear in a global completion list Partial fix for Bug 56614 - Content Assist] Global variables do not appear in a global completion list

View file

@ -52,4 +52,8 @@ public interface ITokenDuple {
public int getStartOffset(); public int getStartOffset();
public int getEndOffset(); public int getEndOffset();
public int getLineNumber(); public int getLineNumber();
/**
* @return
*/
public abstract boolean syntaxOfName();
} }

View file

@ -24,4 +24,16 @@ public interface IScannerExtension extends Cloneable {
public boolean canHandlePreprocessorDirective( String directive ); public boolean canHandlePreprocessorDirective( String directive );
public void handlePreprocessorDirective( String directive, String restOfLine ); public void handlePreprocessorDirective( String directive, String restOfLine );
/**
* @return
*/
public boolean offersDifferentIdentifierCharacters();
/**
* @param c
* @return
*/
public boolean isValidIdentifierStartCharacter(int c);
public boolean isValidIdentifierCharacter( int c );
} }

View file

@ -749,7 +749,6 @@ public abstract class Parser extends ExpressionParser implements IParser
simpleDeclarationStrategyUnion(scope, ownerTemplate, overideKind ); simpleDeclarationStrategyUnion(scope, ownerTemplate, overideKind );
} }
setCompletionValues(scope, kind, Key.DECLARATION ); setCompletionValues(scope, kind, Key.DECLARATION );
checkEndOfFile();
} }
/** /**
@ -1066,10 +1065,9 @@ public abstract class Parser extends ExpressionParser implements IParser
{ {
try try
{ {
astFactory astFactory.createTypeSpecDeclaration(
.createTypeSpecDeclaration( sdw.getScope(),
sdw.getScope(), sdw.getTypeSpecifier(),
sdw.getTypeSpecifier(),
ownerTemplate, ownerTemplate,
sdw.getStartingOffset(), sdw.getStartingOffset(),
sdw.getStartingLine(), lastToken.getEndOffset(), lastToken.getLineNumber()) sdw.getStartingLine(), lastToken.getEndOffset(), lastToken.getLineNumber())
@ -1551,9 +1549,11 @@ public abstract class Parser extends ExpressionParser implements IParser
consume(IToken.t_template); consume(IToken.t_template);
last = templateId(sdw.getScope(), CompletionKind.SINGLE_NAME_REFERENCE ); last = templateId(sdw.getScope(), CompletionKind.SINGLE_NAME_REFERENCE );
} }
if( sdw.getName() != null )
first = sdw.getName().getFirstToken();
ITokenDuple duple = new TokenDuple(first, last); ITokenDuple duple = new TokenDuple(first, last);
sdw.setTypeName(duple); sdw.setTypeName(duple);
flags.setEncounteredTypename(true);
break; break;
case IToken.tCOLONCOLON : case IToken.tCOLONCOLON :
consume(IToken.tCOLONCOLON); consume(IToken.tCOLONCOLON);

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.internal.core.parser.token.OffsetDuple; import org.eclipse.cdt.internal.core.parser.token.OffsetDuple;
import org.eclipse.cdt.internal.core.parser.token.TokenDuple; import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
@ -30,6 +31,9 @@ public class SelectionParser extends ContextualParser {
private OffsetDuple offsetRange; private OffsetDuple offsetRange;
private IToken firstTokenOfDuple = null, lastTokenOfDuple = null; private IToken firstTokenOfDuple = null, lastTokenOfDuple = null;
private IASTScope ourScope = null;
private IASTCompletionNode.CompletionKind ourKind = null;
private IASTNode ourContext = null;
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.Parser#handleNewToken(org.eclipse.cdt.core.parser.IToken) * @see org.eclipse.cdt.internal.core.parser.Parser#handleNewToken(org.eclipse.cdt.core.parser.IToken)
@ -48,6 +52,16 @@ public class SelectionParser extends ContextualParser {
log.traceLog( "Offset Ceiling Hit w/token \"" + value.getImage() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ log.traceLog( "Offset Ceiling Hit w/token \"" + value.getImage() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
lastTokenOfDuple = value; lastTokenOfDuple = value;
} }
if( scanner.isOnTopContext() && lastTokenOfDuple != null && lastTokenOfDuple.getEndOffset() >= offsetRange.getCeilingOffset() )
{
if ( ourScope == null )
ourScope = getCompletionScope();
if( ourContext == null )
ourContext = getCompletionContext();
if( ourKind == null )
ourKind = getCompletionKind();
}
} }
} }
@ -67,7 +81,6 @@ public class SelectionParser extends ContextualParser {
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int) * @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
*/ */
public IASTNode parse(int startingOffset, int endingOffset) { public IASTNode parse(int startingOffset, int endingOffset) {
// scanner.setOffsetBoundary(endingOffset);
offsetRange = new OffsetDuple( startingOffset, endingOffset ); offsetRange = new OffsetDuple( startingOffset, endingOffset );
translationUnit(); translationUnit();
return reconcileTokenDuple(); return reconcileTokenDuple();
@ -84,7 +97,11 @@ public class SelectionParser extends ContextualParser {
throw new ParseError( ParseError.ParseErrorKind.OFFSETDUPLE_UNREACHABLE ); throw new ParseError( ParseError.ParseErrorKind.OFFSETDUPLE_UNREACHABLE );
ITokenDuple duple = new TokenDuple( firstTokenOfDuple, lastTokenOfDuple ); ITokenDuple duple = new TokenDuple( firstTokenOfDuple, lastTokenOfDuple );
return duple.lookup( astFactory, getCompletionScope() );
if( ! duple.syntaxOfName() )
throw new ParseError( ParseError.ParseErrorKind.OFFSET_RANGE_NOT_NAME );
return duple.lookup( astFactory, ourScope );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -99,8 +116,6 @@ public class SelectionParser extends ContextualParser {
* @see org.eclipse.cdt.internal.core.parser.Parser#checkEndOfFile() * @see org.eclipse.cdt.internal.core.parser.Parser#checkEndOfFile()
*/ */
protected void checkEndOfFile() throws EndOfFileException { protected void checkEndOfFile() throws EndOfFileException {
if( scanner.isOnTopContext() && lastTokenOfDuple != null && lastTokenOfDuple.getEndOffset() >= offsetRange.getCeilingOffset() )
throw new EndOfFileException();
} }
} }

View file

@ -11,11 +11,15 @@
package org.eclipse.cdt.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
import org.eclipse.cdt.core.parser.extension.IScannerExtension; import org.eclipse.cdt.core.parser.extension.IScannerExtension;
import org.eclipse.cdt.internal.core.parser.scanner.ScannerUtility.InclusionParseException;
/** /**
* @author jcamelon * @author jcamelon
@ -65,6 +69,7 @@ public class GCCScannerExtension implements IScannerExtension {
directives = new HashSet(); directives = new HashSet();
directives.add( "#include_next" ); //$NON-NLS-1$ directives.add( "#include_next" ); //$NON-NLS-1$
directives.add( "#warning"); //$NON-NLS-1$ directives.add( "#warning"); //$NON-NLS-1$
directives.add( "#ident"); //$NON-NLS-1$
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -82,17 +87,78 @@ public class GCCScannerExtension implements IScannerExtension {
{ {
scannerData.getLogService().traceLog( "GCCScannerExtension handling #include_next directive" ); //$NON-NLS-1$ scannerData.getLogService().traceLog( "GCCScannerExtension handling #include_next directive" ); //$NON-NLS-1$
// figure out the name of the current file and its path // figure out the name of the current file and its path
// IScannerContext context = scannerData.getContextStack().getCurrentContext(); IScannerContext context = scannerData.getContextStack().getCurrentContext();
// if( context.getKind() != IScannerContext.ContextKind.INCLUSION ) if( context.getKind() != IScannerContext.ContextKind.INCLUSION )
// { return;
// //handle appropriate error
// }
// String fullInclusionPath = context.getFilename();
// IASTInclusion inclusion = context.getExtension();
String fullInclusionPath = context.getFilename();
IASTInclusion inclusion = context.getExtension();
Iterator iter = scannerData.getIncludePathNames().iterator();
while (iter.hasNext()) {
String path = (String)iter.next();
String completePath = ScannerUtility.createReconciledPath(path, inclusion.getName() );
if( completePath.equals( fullInclusionPath ) )
break;
}
ScannerUtility.InclusionDirective parsedDirective = null;
try {
parsedDirective = ScannerUtility.parseInclusionDirective( scannerData, this, restOfLine, scannerData.getContextStack().getCurrentContext().getOffset() );
} catch (InclusionParseException e) {
return;
}
CodeReader duple = null;
// search through include paths
while (iter.hasNext()) {
String path = (String)iter.next();
duple = ScannerUtility.createReaderDuple( path, parsedDirective.getFilename(), scannerData.getClientRequestor() );
if( duple != null )
break;
}
if( duple != null )
{
try
{
scannerData.getContextStack().updateContext(duple.getUnderlyingReader(), duple.getFilename(), ScannerContext.ContextKind.INCLUSION, inclusion, scannerData.getClientRequestor() );
scannerData.getLogService().traceLog( "GCCScannerExtension handling #include_next directive successfully pushed on new include file" ); //$NON-NLS-1$
}
catch (ContextException e1)
{
return;
}
}
// search through include paths
} }
else if( directive.equals( "#warning") || directive.equals("#ident"))
return; // good enough -- the rest of the line has been consumed
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#offersDifferentIdentifierCharacters()
*/
public boolean offersDifferentIdentifierCharacters() {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isValidIdentifierStartCharacter(int)
*/
public boolean isValidIdentifierStartCharacter(int c) {
return Character.isLetter((char)c) || ( c == '_') || ( c == '$' );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.extension.IScannerExtension#isValidIdentifierCharacter(int)
*/
public boolean isValidIdentifierCharacter(int c) {
return ((c >= 'a') && (c <= 'z'))
|| ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))
|| (c == '_') || ( c== '$' ) ||
Character.isUnicodeIdentifierPart( (char)c);
} }
} }

View file

@ -1437,12 +1437,9 @@ public class Scanner implements IScanner {
c = getChar(); c = getChar();
// do the least expensive tests first! // do the least expensive tests first!
while ( while ( ( scannerExtension.offersDifferentIdentifierCharacters() &&
((c >= 'a') && (c <= 'z')) scannerExtension.isValidIdentifierCharacter(c) ) ||
|| ((c >= 'A') && (c <= 'Z')) isValidIdentifierCharacter(c) ) {
|| ((c >= '0') && (c <= '9'))
|| (c == '_') || Character.isUnicodeIdentifierPart( (char)c)
) {
buff.append((char) c); buff.append((char) c);
c = getChar(); c = getChar();
if (c == '\\') { if (c == '\\') {
@ -1491,6 +1488,17 @@ public class Scanner implements IScanner {
return newToken(IToken.tIDENTIFIER, ident, scannerData.getContextStack().getCurrentContext()); return newToken(IToken.tIDENTIFIER, ident, scannerData.getContextStack().getCurrentContext());
} }
/**
* @param c
* @return
*/
protected boolean isValidIdentifierCharacter(int c) {
return ((c >= 'a') && (c <= 'z'))
|| ((c >= 'A') && (c <= 'Z'))
|| ((c >= '0') && (c <= '9'))
|| (c == '_') || Character.isUnicodeIdentifierPart( (char)c);
}
public IToken nextToken( boolean pasting ) throws ScannerException, EndOfFileException public IToken nextToken( boolean pasting ) throws ScannerException, EndOfFileException
{ {
if( ! initialContextInitialized ) if( ! initialContextInitialized )
@ -1573,11 +1581,6 @@ public class Scanner implements IScanner {
continue; continue;
} }
return token; return token;
// case '/':
// expandDefinition("??/", "\\", baseOffset); //$NON-NLS-1$ //$NON-NLS-2$
// c = getChar(insideString);
// break;
default: default:
// Not a trigraph // Not a trigraph
ungetChar(c); ungetChar(c);
@ -1850,12 +1853,9 @@ public class Scanner implements IScanner {
return token; return token;
default: default:
if ( if ( ( scannerExtension.offersDifferentIdentifierCharacters() &&
// JOHNC - Accept non-ASCII Input scannerExtension.isValidIdentifierStartCharacter(c) ) ||
// ((c >= 'a') && (c <= 'z')) isValidIdentifierStartCharacter(c) )
// || ((c >= 'A') && (c <= 'Z')) || (c == '_')) {
Character.isLetter((char)c) || ( c == '_')
)
{ {
token = processKeywordOrLiteral(c, pasting); token = processKeywordOrLiteral(c, pasting);
if (token == null) if (token == null)
@ -1885,6 +1885,14 @@ public class Scanner implements IScanner {
/** /**
* @param c
* @return
*/
protected boolean isValidIdentifierStartCharacter(int c) {
return Character.isLetter((char)c) || ( c == '_');
}
/**
* @param definition * @param definition
*/ */
protected void handleCompletionOnDefinition(String definition) throws EndOfFileException { protected void handleCompletionOnDefinition(String definition) throws EndOfFileException {
@ -2292,47 +2300,43 @@ public class Scanner implements IScanner {
protected boolean evaluateExpression(String expression, int beginningOffset ) protected boolean evaluateExpression(String expression, int beginningOffset )
throws ScannerException { throws ScannerException {
if( scannerData.getParserMode() == ParserMode.QUICK_PARSE ) IExpressionParser parser = null;
{ StringBuffer expressionBuffer = new StringBuffer( expression );
if( expression.trim().equals( "0" ) ) //$NON-NLS-1$ expressionBuffer.append( ';');
return false;
return true;
}
else
{
IExpressionParser parser = null;
StringBuffer expressionBuffer = new StringBuffer( expression );
expressionBuffer.append( ';');
IScanner trial = new Scanner( IScanner trial = new Scanner(
new StringReader(expressionBuffer.toString()), new StringReader(expressionBuffer.toString()),
EXPRESSION, EXPRESSION,
scannerData.getDefinitions(), scannerData.getDefinitions(),
scannerData.getIncludePathNames(), scannerData.getIncludePathNames(),
NULL_REQUESTOR, NULL_REQUESTOR,
ParserMode.QUICK_PARSE, ParserMode.QUICK_PARSE,
scannerData.getLanguage(), scannerData.getLanguage(),
NULL_LOG_SERVICE, NULL_LOG_SERVICE,
scannerExtension ); scannerExtension );
parser = InternalParserUtil.createExpressionParser(trial, scannerData.getLanguage(), NULL_LOG_SERVICE); parser = InternalParserUtil.createExpressionParser(trial, scannerData.getLanguage(), NULL_LOG_SERVICE);
try { try {
IASTExpression exp = parser.expression(null); IASTExpression exp = parser.expression(null);
if( exp.evaluateExpression() == 0 ) if( exp.evaluateExpression() == 0 )
return false; return false;
return true; return true;
} catch( BacktrackException backtrack ) } catch( BacktrackException backtrack )
{ {
handleProblem( IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR, expression, beginningOffset, false, true ); if( scannerData.getParserMode() == ParserMode.QUICK_PARSE )
} return false;
catch (ASTExpressionEvaluationException e) { handleProblem( IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR, expression, beginningOffset, false, true );
handleProblem( IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR, expression, beginningOffset, false, true );
} catch (EndOfFileException e) {
handleProblem( IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR, expression, beginningOffset, false, true );
}
return true;
} }
catch (ASTExpressionEvaluationException e) {
if( scannerData.getParserMode() == ParserMode.QUICK_PARSE )
return false;
handleProblem( IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR, expression, beginningOffset, false, true );
} catch (EndOfFileException e) {
if( scannerData.getParserMode() == ParserMode.QUICK_PARSE )
return false;
handleProblem( IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR, expression, beginningOffset, false, true );
}
return true;
} }

View file

@ -62,22 +62,30 @@ public class ScannerUtility {
return buffer.toString(); return buffer.toString();
} }
static CodeReader createReaderDuple( String path, String fileName, ISourceElementRequestor requestor ) static CodeReader createReaderDuple( String path, String fileName, ISourceElementRequestor requestor )
{ {
File pathFile = new File(path); String finalPath = createReconciledPath(path, fileName);
//TODO assert pathFile.isDirectory();
StringBuffer newPathBuffer = new StringBuffer( pathFile.getPath() );
newPathBuffer.append( File.separatorChar );
newPathBuffer.append( fileName );
//remove ".." and "." segments
String finalPath = reconcilePath( newPathBuffer.toString() );
Reader r = requestor.createReader( finalPath ); Reader r = requestor.createReader( finalPath );
if( r != null ) if( r != null )
return new CodeReader( finalPath, r ); return new CodeReader( finalPath, r );
return null; return null;
} }
/**
* @param path
* @param fileName
* @return
*/
static String createReconciledPath(String path, String fileName) {
//TODO assert pathFile.isDirectory();
StringBuffer newPathBuffer = new StringBuffer( new File(path).getPath() );
newPathBuffer.append( File.separatorChar );
newPathBuffer.append( fileName );
//remove ".." and "." segments
return reconcilePath( newPathBuffer.toString() );
}
static class InclusionDirective static class InclusionDirective
{ {
public InclusionDirective( String fileName, boolean useIncludePaths, int startOffset, int endOffset ) public InclusionDirective( String fileName, boolean useIncludePaths, int startOffset, int endOffset )

View file

@ -402,4 +402,28 @@ public class TokenDuple implements ITokenDuple {
public List[] getTemplateIdArgLists() { public List[] getTemplateIdArgLists() {
return argLists; return argLists;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#syntaxOfName()
*/
public boolean syntaxOfName() {
Iterator iter = iterator();
if( ! iter.hasNext() ) return false; // empty is not good
while( iter.hasNext() )
{
IToken token = (IToken) iter.next();
if( token.isOperator() ) continue;
switch( token.getType() )
{
case IToken.tCOMPL:
case IToken.tIDENTIFIER:
case IToken.tCOLONCOLON:
case IToken.t_operator:
continue;
default:
return false;
}
}
return true;
}
} }