Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] [FIXED][79339]Selection search fails on SDL/SDL.h


[FIXED][79339]Selection search fails on SDL/SDL.h

Devin Steffler
IBM's Eclipse CDT
Ottawa (Palladium), Ontario, Canada


Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java,v
retrieving revision 1.8
diff -u -r1.8 CompleteParsePluginTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java	19 Oct 2004 14:26:06 -0000	1.8
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java	29 Nov 2004 20:27:03 -0000
@@ -14,6 +14,8 @@
  */
 package org.eclipse.cdt.core.parser.tests;
 
+import java.io.StringWriter;
+import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -21,6 +23,9 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.ast.IASTFunction;
+import org.eclipse.cdt.core.parser.ast.IASTNode;
 import org.eclipse.cdt.core.parser.ast.IASTVariable;
 import org.eclipse.core.resources.IFile;
 
@@ -187,4 +192,34 @@
         assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT );
         assertFalse( i.hasNext() );
     }
+    
+	public void testBug79339() throws Exception{
+	    Writer writer = new StringWriter();
+	    writer.write("#ifndef _HEADER_\n"); //$NON-NLS-1$
+	    writer.write("#define _HEADER_\n"); //$NON-NLS-1$
+	    writer.write("#define ONE 1\n"); //$NON-NLS-1$
+	    writer.write("int foo(int);\n"); //$NON-NLS-1$
+	    writer.write("#endif // _HEADER_\n"); //$NON-NLS-1$
+	    String header = writer.toString();
+	    importFile( "header.h", header ); //$NON-NLS-1$
+	    
+	    writer = new StringWriter();
+	    writer.write( "#include \"header.h\"  \n"); //$NON-NLS-1$
+	    writer.write( "int foo2(){\n"); //$NON-NLS-1$
+	    writer.write( "   return foo(ONE);\n"); //$NON-NLS-1$
+	    writer.write( "}\n"); //$NON-NLS-1$
+	    String source = writer.toString();
+	    IFile cpp = importFile( "test.cpp", source ); //$NON-NLS-1$
+	    
+	    int start = source.indexOf( "foo(ONE)" ); //$NON-NLS-1$
+	    
+	    List calls = new ArrayList();
+	    IASTNode node = parse( cpp, calls, start, start + 3 ); //$NON-NLS-1$
+	    assertTrue(node instanceof IASTFunction);
+	    IASTFunction foo = (IASTFunction)node;
+	    assertEquals(foo.getStartingLine(), 4);
+	    assertEquals(foo.getNameOffset(), 52);
+	    assertEquals(foo.getName(), "foo"); //$NON-NLS-1$
+	    assertTrue(new String(foo.getFilename()).indexOf("header.h") > 0); //$NON-NLS-1$
+	}
 }
Index: parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java,v
retrieving revision 1.1
diff -u -r1.1 FileBasePluginTest.java
--- parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java	11 Oct 2004 03:00:02 -0000	1.1
+++ parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java	29 Nov 2004 20:27:03 -0000
@@ -18,6 +18,7 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
@@ -31,6 +32,7 @@
 import org.eclipse.cdt.core.parser.IProblem;
 import org.eclipse.cdt.core.parser.ISourceElementRequestor;
 import org.eclipse.cdt.core.parser.NullLogService;
+import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
 import org.eclipse.cdt.core.parser.ParserFactory;
 import org.eclipse.cdt.core.parser.ParserLanguage;
 import org.eclipse.cdt.core.parser.ParserMode;
@@ -58,6 +60,7 @@
 import org.eclipse.cdt.core.parser.ast.IASTMethodReference;
 import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
 import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference;
+import org.eclipse.cdt.core.parser.ast.IASTNode;
 import org.eclipse.cdt.core.parser.ast.IASTParameterReference;
 import org.eclipse.cdt.core.parser.ast.IASTScope;
 import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
@@ -332,5 +335,30 @@
 		}
         return callback.getCompilationUnit();
     }
-	
+
+    protected IASTNode parse(IFile code, List callbacks, int start, int end) throws Exception
+    {
+    	return parse(code, callbacks, start, end, true, ParserLanguage.CPP);
+    	
+    }
+    
+    protected IASTNode parse(IFile code, List callbacks, int offset1, int offset2, boolean expectedToPass, ParserLanguage language) throws Exception {
+    	callback = new CallbackTracker( callbacks ); 
+   	
+		IParser parser = ParserFactory.createParser( 
+	    		ParserFactory.createScanner( new CodeReader( code.getLocation().toOSString(), code.getCharset() ), new ScannerInfo(), //$NON-NLS-1$
+	    			ParserMode.SELECTION_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.SELECTION_PARSE, language, null 	
+	    		);
+		
+		IParser.ISelectionParseResult result =parser.parse( offset1, offset2 );
+		if( expectedToPass )
+		{
+			assertNotNull( result );
+			String filename = result.getFilename();
+			assertNotNull( filename );
+			assertTrue( !filename.equals( "")); //$NON-NLS-1$
+			return (IASTNode) result.getOffsetableNamedElement();
+		}
+		return null;
+	}
 }
Index: parser/org/eclipse/cdt/core/parser/IScanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java,v
retrieving revision 1.29
diff -u -r1.29 IScanner.java
--- parser/org/eclipse/cdt/core/parser/IScanner.java	11 Oct 2004 03:00:10 -0000	1.29
+++ parser/org/eclipse/cdt/core/parser/IScanner.java	29 Nov 2004 20:26:44 -0000
@@ -37,4 +37,5 @@
 	public boolean isOnTopContext();
 	public CharArrayObjectMap getRealDefinitions();
 	public void cancel();
+	public char[] getMainFilename();
 }
Index: parser/org/eclipse/cdt/internal/core/parser/Parser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java,v
retrieving revision 1.267
diff -u -r1.267 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java	20 Nov 2004 17:56:43 -0000	1.267
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java	29 Nov 2004 20:26:46 -0000
@@ -106,6 +106,7 @@
 	protected int firstErrorLine = FIRST_ERROR_UNSET;
 	private BacktrackException backtrack = new BacktrackException();
 	private int backtrackCount = 0;
+	private char[] parserStartFilename = null;
 
 	protected final void throwBacktrack( IProblem problem ) throws BacktrackException {
 		++backtrackCount;
@@ -2909,6 +2910,7 @@
         ISourceElementRequestor callback,
         ParserLanguage language, IParserLogService log, IParserExtension extension )
     {
+    	this.parserStartFilename = scanner.getMainFilename();
 		this.scanner = scanner;
 		this.language = language;
 		this.log = log;
@@ -6576,7 +6578,7 @@
 	 */
 	protected void handleNewToken(IToken value) {
 		if( mode != ParserMode.SELECTION_PARSE ) return;
-		if( value != null && scanner.isOnTopContext() )
+		if( value != null && CharArrayUtils.equals(value.getFilename(), parserStartFilename))
 		{
 			TraceUtil.outputTrace(log, "IToken provided w/offsets ", null, value.getOffset(), " & ", value.getEndOffset() ); //$NON-NLS-1$ //$NON-NLS-2$
 			boolean change = false;
@@ -6749,7 +6751,7 @@
 	protected void setGreaterNameContext(ITokenDuple tokenDuple) {
 		if( mode != ParserMode.SELECTION_PARSE ) return;
 		if( pastPointOfSelection ) return;
-		if( greaterContextDuple == null && scanner.isOnTopContext() && lastTokenOfDuple != null && firstTokenOfDuple != null )
+		if( greaterContextDuple == null && lastTokenOfDuple != null && firstTokenOfDuple != null && CharArrayUtils.equals(tokenDuple.getFilename(), parserStartFilename))
 		{
 			if( tokenDuple.getStartOffset() > lastTokenOfDuple.getEndOffset() )
 			{
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java,v
retrieving revision 1.200
diff -u -r1.200 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	24 Nov 2004 21:15:16 -0000	1.200
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	29 Nov 2004 20:26:47 -0000
@@ -1395,14 +1395,14 @@
 		// 5.6 Multiplicative Operators: The operands of * and / shall have arithmetic or enumeration type; the operands of % shall have integral or enumeration type.
 		if (kind == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY || kind == IASTExpression.Kind.MULTIPLICATIVE_DIVIDE) {
 			if( !lhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator ) )
-				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp.getStartingOffset(), lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true ); // TODO Devin used to be true
+				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp.getStartingOffset(), lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true );
 			if( !rhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator ) )
-				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp.getStartingOffset(), rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true ); // TODO Devin used to be true
+				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp.getStartingOffset(), rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true );
 		} else if (kind == IASTExpression.Kind.MULTIPLICATIVE_MODULUS) {
 			if( !(isIntegralType(lhs, isLhsPointer) || lhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator ) ))
-				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp.getStartingOffset(), lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true ); // TODO Devin used to be true
+				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp.getStartingOffset(), lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true );
 			if( !(isIntegralType(rhs, isRhsPointer) || rhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator ) ))
-				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp.getStartingOffset(), rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true ); // TODO Devin used to be true
+				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp.getStartingOffset(), rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true );
 
 		// 5.7 Additive Operators: 
 		// For addition, either both operands shall have arithmetic or enumeration type, or one operand shall be a
@@ -1416,24 +1416,24 @@
 			if (!((isLhsPointer && (isIntegralType(rhs, isRhsPointer) || rhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator ))) ||
 			(isRhsPointer && (isIntegralType(lhs, isRhsPointer) || lhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator ))))) {			
 				if( !(isIntegralType(lhs, isLhsPointer) || lhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator )) )
-					handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp.getStartingOffset(), lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true ); // TODO Devin used to be true
+					handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp.getStartingOffset(), lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true );
 				if( !(isIntegralType(rhs, isRhsPointer) || rhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator )) )
-					handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp.getStartingOffset(), rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true ); // TODO Devin used to be true
+					handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp.getStartingOffset(), rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true );
 				}
 		} else if (kind == IASTExpression.Kind.ADDITIVE_MINUS) {
 			if (!(isLhsPointer && (isIntegralType(rhs, isRhsPointer) || rhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator )))) {			
 				if( !(isIntegralType(lhs, isLhsPointer) || lhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator )) )
-					handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp.getStartingOffset(), lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true ); // TODO Devin used to be true
+					handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp.getStartingOffset(), lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true );
 				if( !(isIntegralType(rhs, isRhsPointer) || rhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator )) )
-					handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp.getStartingOffset(), rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true ); // TODO Devin used to be true
+					handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp.getStartingOffset(), rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true );
 			}
 
 		// 5.11, 5.12, 5.13: The operator applies only to integral or enumeration operands.
 		} else if (kind == IASTExpression.Kind.ANDEXPRESSION || kind == IASTExpression.Kind.EXCLUSIVEOREXPRESSION	|| kind == IASTExpression.Kind.INCLUSIVEOREXPRESSION) {
 			if( !(isIntegralType(lhs, isLhsPointer) || lhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator )) )
-				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp.getStartingOffset(), lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true ); // TODO Devin used to be true
+				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp.getStartingOffset(), lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true );
 			if( !(isIntegralType(rhs, isRhsPointer) || rhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator )) )
-				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp.getStartingOffset(), rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true ); // TODO Devin used to be true			
+				handleProblem( scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp.getStartingOffset(), rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true );			
 		}
 
 		ITypeInfo info = TypeInfoProvider.newTypeInfo( );
Index: parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java,v
retrieving revision 1.90
diff -u -r1.90 Scanner2.java
--- parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java	26 Nov 2004 18:42:25 -0000	1.90
+++ parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java	29 Nov 2004 20:26:48 -0000
@@ -3228,6 +3228,12 @@
 		return workingCopies.iterator();
 	}
 
+	public char[] getMainFilename() {
+		if( bufferData[0] instanceof CodeReader && bufferData != null && bufferData[0] != null )
+			return ((CodeReader)bufferData[0]).filename;
+
+		return emptyCharArray;
+	}
 	
 	public final char[] getCurrentFilename() {
 		for( int i = bufferStackPos; i >= 0; --i )

Back to the top