Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Scanner bugfixes

CORE
	Added timing printout for CModelTests.
	Provided partial fix for bug36255 to get past infinite loop, will
leave defect open.
	Fixed bug36045 (Again).  
	Fixed bug36287.

TESTS
	Updated ScannerTest::testBug36045().
	Added ScannerTest::testBug36287().
	Added DOMTests::testBug36288(). 

JohnC


Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.22
diff -u -r1.22 ChangeLog
--- parser/ChangeLog	7 Apr 2003 21:43:01 -0000	1.22
+++ parser/ChangeLog	9 Apr 2003 14:29:54 -0000
@@ -1,7 +1,13 @@
+2003-04-09 John Camelon
+	Added timing printout for CModelTests.
+	Provided partial fix for bug36255 to get past infinite loop, will leave defect open.
+	Fixed bug36045 (Again).  
+	Fixed bug36287.
+	
 2003-04-06 Andrew Niefer
 	Added ParserSymbolTable::Cost and used it to fix up the conversion sequence ranking
 
-2003-04-04 John Camelon
+2003-04-06 John Camelon
 	Fixed defect 36073.
 	Fixed error handling for unterminated strings in Scanner.
 	Significantly updated callback structure to better suite the nature of the Code Model.
Index: parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java,v
retrieving revision 1.1
diff -u -r1.1 CModelBuilder.java
--- parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java	8 Apr 2003 21:30:53 -0000	1.1
+++ parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java	9 Apr 2003 14:29:55 -0000
@@ -53,8 +53,10 @@
 		DOMBuilder domBuilder = new DOMBuilder();
 		String code = translationUnit.getBuffer().getContents();
 		Parser parser = new Parser(code, domBuilder, true);
-		if( ! parser.parse() ) throw new ParserException( "Parse failure" ); 
+		if( ! parser.parse() ) throw new ParserException( "Parse failure" );
+		long startTime = System.currentTimeMillis(); 
 		generateModelElements(domBuilder.getTranslationUnit());
+		System.out.println("CModel build: "+ ( System.currentTimeMillis() - startTime ) + "ms" );
 		return domBuilder.getTranslationUnit();
 	}
 	
Index: parser/org/eclipse/cdt/internal/core/parser/Scanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java,v
retrieving revision 1.17
diff -u -r1.17 Scanner.java
--- parser/org/eclipse/cdt/internal/core/parser/Scanner.java	8 Apr 2003 03:41:05 -0000	1.17
+++ parser/org/eclipse/cdt/internal/core/parser/Scanner.java	9 Apr 2003 14:29:55 -0000
@@ -348,6 +348,7 @@
 	private boolean throwExceptionOnEOFWithinMultilineComment = true;
 	private boolean throwExceptionOnEOFWithoutBalancedEndifs = true;
 	private boolean throwExceptionOnBadCharacterRead = false; 
+	private boolean atEOF = false;
 
 	private boolean quickScan = false;
 	public void setQuickScan(boolean qs) {
@@ -505,13 +506,16 @@
 				 
 				// string
 				StringBuffer buff = new StringBuffer(); 
+				int beforePrevious = NOCHAR;
 				int previous = c;
 				c = getChar(true);
 
 				for( ; ; )
 				{
-					if( ( c == '"' && previous != '\\' )|| ( c == NOCHAR) )break;  
+					if ( ( c =='"' ) && ( previous != '\\' || beforePrevious == '\\') ) break;
+					if( c == NOCHAR) break;  
 					buff.append((char) c);
+					beforePrevious = previous;
 					previous = c;
 					c = getChar(true);
 				}
@@ -527,8 +531,7 @@
 				} else {
 					if (throwExceptionOnUnboundedString)
 						throw new ScannerException(
-							"Unbounded string found at offset "
-								+ currentContext.getOffset());
+							"Unbounded string" );
 				}
 		
 			} else if (
@@ -710,11 +713,17 @@
 					}
 				}
 				
-				int tokenType = floatingPoint ? Token.tFLOATINGPT : Token.tINTEGER; 
+				int tokenType;
+				String result = buff.toString(); 
+				
+				if( floatingPoint && result.equals(".") )
+					tokenType = Token.tDOT;
+				else
+					tokenType = floatingPoint ? Token.tFLOATINGPT : Token.tINTEGER; 
 				
 				return newToken(
 					tokenType,
-					buff.toString(),
+					result,
 					currentContext);
 				
 			} else if (c == '#') {
@@ -1244,8 +1253,11 @@
 			}
 		}
 
-		if (throwExceptionOnEOFWithoutBalancedEndifs && ( getDepth() != 0))
+		if (throwExceptionOnEOFWithoutBalancedEndifs && ( getDepth() != 0) && !atEOF )
+		{
+			atEOF = true;
 			throw new ScannerException("End of file encountered without terminating #endif");
+		}
 
 		// we're done
 		throw Parser.endOfFile;
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/ChangeLog,v
retrieving revision 1.21
diff -u -r1.21 ChangeLog
--- ChangeLog	7 Apr 2003 21:42:56 -0000	1.21
+++ ChangeLog	9 Apr 2003 14:32:39 -0000
@@ -1,3 +1,8 @@
+2003-04-09 John Camelon
+	Updated ScannerTest::testBug36045().
+	Added ScannerTest::testBug36287().
+	Added DOMTests::testBug36288(). 
+
 2003-04-06 Andrew Niefer
 	Added ParserSymbolTableTest::testOverloadRanking()
 
Index: parser/org/eclipse/cdt/core/parser/tests/DOMTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java,v
retrieving revision 1.15
diff -u -r1.15 DOMTests.java
--- parser/org/eclipse/cdt/core/parser/tests/DOMTests.java	8 Apr 2003 03:40:53 -0000	1.15
+++ parser/org/eclipse/cdt/core/parser/tests/DOMTests.java	9 Apr 2003 14:32:40 -0000
@@ -1121,6 +1121,22 @@
 		writer.write( "A::A(const A&v) : x(v.x) { }\n" );
 		TranslationUnit tu = parse( writer.toString() ); 
 	}
+	
+	public void testBug36288() throws Exception
+	{
+		TranslationUnit tu = parse( "int foo() {}\nlong foo2(){}", true);  
+		assertEquals( tu.getDeclarations().size(), 2 );
+		for( int i = 0; i < 2; ++i )
+		{
+			SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(i);
+			assertEquals( declaration.getDeclarators().size(), 1 );
+			Declarator d = (Declarator)declaration.getDeclarators().get(0);
+			assertEquals( d.getName().toString(), ( i == 0 ) ? "foo" : "foo2");
+			assertEquals( declaration.getDeclSpecifier().getType(), (i == 0 ) ? DeclSpecifier.t_int : DeclSpecifier.t_type );
+			assertEquals( declaration.getDeclSpecifier().isLong(), ( i == 0 ) ? false : true ); 
+		}
+	}
+
 
 }
 
Index: parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java,v
retrieving revision 1.10
diff -u -r1.10 ScannerTestCase.java
--- parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java	8 Apr 2003 03:40:53 -0000	1.10
+++ parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java	9 Apr 2003 14:32:40 -0000
@@ -1141,6 +1141,42 @@
 				validateAsUndefined(row.symbolName(i));
 		}
 	}
+	
+	public void testBug36287() throws Exception
+	{
+		initializeScanner( "X::X( const X & rtg_arg ) : U( rtg_arg ) , Z( rtg_arg.Z ) , br( rtg_arg.br ){}" );
+		validateIdentifier("X");
+		validateToken( Token.tCOLONCOLON);
+		validateIdentifier("X");
+		validateToken( Token.tLPAREN );
+		validateToken( Token.t_const );
+		validateIdentifier("X");
+		validateToken( Token.tAMPER );
+		validateIdentifier( "rtg_arg");
+		validateToken( Token.tRPAREN );  
+		validateToken( Token.tCOLON );
+		validateIdentifier( "U");
+		validateToken( Token.tLPAREN );
+		validateIdentifier( "rtg_arg");
+		validateToken( Token.tRPAREN );
+		validateToken( Token.tCOMMA );
+		validateIdentifier( "Z");
+		validateToken( Token.tLPAREN );
+		validateIdentifier( "rtg_arg");
+		validateToken( Token.tDOT );
+		validateIdentifier( "Z");
+		validateToken( Token.tRPAREN );
+		validateToken( Token.tCOMMA );
+		validateIdentifier( "br");
+		validateToken( Token.tLPAREN );
+		validateIdentifier( "rtg_arg");
+		validateToken( Token.tDOT );
+		validateIdentifier( "br");
+		validateToken( Token.tRPAREN );
+		validateToken( Token.tLBRACE);
+		validateToken( Token.tRBRACE);
+		validateEOF();
+	}
 
 	public void testBug35892()
 	{
@@ -1180,8 +1216,15 @@
 		buffer.append( '\\');
 		buffer.append( '"'); 
 		buffer.append( '"');
+		
+		buffer.append( '"');
+		buffer.append( '\\');
+		buffer.append( '\\');
+		buffer.append( '"');
+		buffer.append( "\n\n");
 		initializeScanner( buffer.toString());
 		validateString( "\\\"");
+		validateString( "\\\\");
 	}
 
 	public void testConditionalWithBraces()

Back to the top