[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [cdt-core-dev] Bug Fix for Scanner #ifdef
|
John-
Our
original code that was causing the parser to fail was this:
#ifdef
__ALLOW_68K_ASM__
asl.l #kBias,D0
#endif
But in
order to isolate what was causing the problem, i would comment out bits of our
headers. I used both #if 0/#endif pairs and single line comments. On top of
that, when i was getting inconsistent results, i would try to back out attempts
to regress what i was finding by commenting out the #if lines. I found 3
separate sets of bugs that i have represented by the test cases
below.
#if
0
//#endif
bogus code;
#endif
#if
0
#bogus directive
#endif
#if
0
Comment about why #endif is here
#endif
In the
first case, the #endif was processed in spite of being commented out. That was
the real bug that i was fixing with the code i sent off to you. Note, i also
discovered my fix wasn't quite perfect. In the case we already had the first
slash, we get a second char to see if it might be a single line or multi-line
comment. But if it was neither, i already had the next character to be tested in
the 'not #' condition, so i shouldn't have fallen all the way to the concluding
c = getChar() call again. My fixed code below:
public
IToken nextToken( boolean pasting, boolean lookingForNextAlready ) throws
ScannerException, EndOfFile
{
....
while (c != NOCHAR) {
if ( ! passOnToClient )
{
while
(c != NOCHAR && c != '#' )
{
if ( c == '/' )
{
c = getChar();
if ( c == '/' )
{
skipOverSinglelineComment(();
}
else if ( c == '*' )
{
skipOverMultilineComment();
}
else continue; // My bug fix bug
fix
}
c = getChar();
}
if ( c
== NOCHAR ) continue;
}
That
fixed up my debugging problem. But i still had to fix the real issue when i
found the assembly language immediate argument being interpreted as a
preprocessor directive. For that i went down to the '#' cases and
added:
} else if (c == '#')
{
....
String
token = buff.toString();
Object
directive = ppDirectives.get(token);
if
(directive == null {
// My addition
if (passOnToClient)
handleProblem( IProblem.PREPROCESSOR_INVALID_DIRECTIVE, "#"+token,
beginningOffset, false, true, true );
else {
c = getChar();
continue;
}
This
fixed the scanner trying to analyze my assembly language, so that is how i left
my version. However, if the word following the '#' character were a valid
directive, it would get processed. I thought the right fix for that would be
some form of calling skipOverTextUntilNewline(). However, i wasn't sure how that
would affect ## macro processing, so i haven't proceeded to the last element of
the bug fix.
-Keithen
-----Original Message-----
From:
cdt-core-dev-admin@xxxxxxxxxxx [mailto:cdt-core-dev-admin@xxxxxxxxxxx]On
Behalf Of John Camelon
Sent: Monday, June 14, 2004 5:50
AM
To: cdt-core-dev@xxxxxxxxxxx
Subject: Re: [cdt-core-dev]
Bug Fix for Scanner #ifdef
Hi Keithen,
I see the bug, but I do not see how it actually
affected clients. How did you discover this?
I've applied a variation on the patch, as our sources
have changed somewhat.
Thanks,
JohnC
www.eclipse.org/cdt
cdt-core-dev-admin@xxxxxxxxxxx wrote on 06/10/2004 08:24:03
PM:
> 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();
>
}
>
>
>
_______________________________________________
> cdt-core-dev mailing
list
> cdt-core-dev@xxxxxxxxxxx
>
http://dev.eclipse.org/mailman/listinfo/cdt-core-dev