Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-core-dev] Bug Fix for Scanner #ifdef

I have found a bug and fixed it in the CDT 1.2.1 sources we are working on. I have checked the latest 2.0 sources i have, M7, and the bug was still there. So i am sending this in for someone to check the latest sources to see if it still applies.

The code being parsed is:
#ifdef __X__
	// comment
#endif

In the scanner code below, the #ifdef has set the passOnToClient flag to false and we are now skipping source code like crazy. Only stopping to check for # directives with the one exception of commenting them out. However, as we are skipping text that is not a '#', in the case of having "//", our first '/' passes the not # test and then we immediately do a c = getChar(), throwing away that comment character before we test it. The defective code from 2.0 M7 is below and my fix at the bottom.

Hope it helps.

-Keithen

---------------------------------------------------------------------------------------------------------------------------

From CDT 2.0M7 Scanner.java:

	public IToken nextToken( boolean pasting, boolean lookingForNextAlready ) throws ScannerException, EndOfFileException 
	{
// Missing code //

		int c = getChar();

		while (c != NOCHAR) {
			if ( ! passOnToClient ) {
							
				while (c != NOCHAR && c != '#' ) 
				{
					c = getChar();
					if( c == '/' )
					{
						c = getChar();
						if( c == '/' )
						{
							skipOverSinglelineComment();
							c = getChar();
							continue;
						}
						else if( c == '*' )
						{
							skipOverMultilineComment();
							c = getChar();
							continue;
						}
					}
				}
				
				if( c == NOCHAR )

---------------------------------------------------------------------------------------------------------------------------

My fix:

				while (c != NOCHAR && c != '#' ) 
				{
					if( c == '/' )
					{
						c = getChar();
						if( c == '/' )
						{
							skipOverSinglelineComment();
						}
						else if( c == '*' )
						{
							skipOverMultilineComment();
						}
					}
					c = getChar();
				}




Back to the top