# HG changeset patch # User Aziz K?ksal # Date 1189597425 -7200 # Node ID ae154eceba6534718f8eb5be52b17d7396650df5 # Parent ad0cbd1c8881124acc397de53b4893bab00cc32e Applied some fixes to scanning and printing #line tokens. Fix: Token.line_num can be null which could cause a segfault in printToken(). Renamed MID.ExpectedNumberAfterSTLine to ExpectedIntegerAfterSTLine. Fix: Added a check for TOK.Int32 and TOK.Uint32 after a number was scanned in scanSpecialTokenSequence(). diff -r ad0cbd1c8881 -r ae154eceba65 trunk/src/cmd/Generate.d --- a/trunk/src/cmd/Generate.d Wed Sep 12 12:04:21 2007 +0200 +++ b/trunk/src/cmd/Generate.d Wed Sep 12 13:43:45 2007 +0200 @@ -169,7 +169,7 @@ // Keyword `%s`, // HLineBegin - `#line`, + ``, // HLineEnd "", // Filespec @@ -232,7 +232,7 @@ // Keyword "%s", // HLineBegin - "#line", + "", // HLineEnd "", // Filespec @@ -475,9 +475,15 @@ } writef(tags[DP.HLineBegin]); auto num = token.line_num; + if (num is null) + { + writef(token.start[0 .. token.end - token.start]); + writef(tags[DP.HLineEnd]); + break; + } // Print whitespace between #line and number - auto ptr = token.start + "#line".length; - printWS(ptr, num.start); + auto ptr = token.start; + printWS(ptr, num.start); // prints "#line" as well printToken(num, tags); if (token.line_filespec) { diff -r ad0cbd1c8881 -r ae154eceba65 trunk/src/dil/Lexer.d --- a/trunk/src/dil/Lexer.d Wed Sep 12 12:04:21 2007 +0200 +++ b/trunk/src/dil/Lexer.d Wed Sep 12 13:43:45 2007 +0200 @@ -1711,10 +1711,12 @@ } p += 3; + // TODO: #line58"path/file" is legal. Require spaces? + // State.Space could be used for that purpose. enum State - { Number, Filespec, End } + { /+Space,+/ Integer, Filespec, End } - State state; + State state = State.Integer; Loop: while (1) @@ -1736,16 +1738,21 @@ default: if (isspace(*p)) continue; - if (state == State.Number) + if (state == State.Integer) { if (!isdigit(*p)) { - mid = MID.ExpectedNumberAfterSTLine; + mid = MID.ExpectedIntegerAfterSTLine; goto Lerr; } t.line_num = new Token; scan(*t.line_num); --p; + if (t.line_num.type != TOK.Int32 && t.line_num.type != TOK.Uint32) + { + mid = MID.ExpectedIntegerAfterSTLine; + goto Lerr; + } state = State.Filespec; } else if (state == State.Filespec) @@ -1791,9 +1798,9 @@ } } - if (state == State.Number) + if (state == State.Integer) { - mid = MID.ExpectedNumberAfterSTLine; + mid = MID.ExpectedIntegerAfterSTLine; goto Lerr; } diff -r ad0cbd1c8881 -r ae154eceba65 trunk/src/dil/Messages.d --- a/trunk/src/dil/Messages.d Wed Sep 12 12:04:21 2007 +0200 +++ b/trunk/src/dil/Messages.d Wed Sep 12 13:43:45 2007 +0200 @@ -17,7 +17,7 @@ EmptyCharacterLiteral, // #line ExpectedIdentifierSTLine, - ExpectedNumberAfterSTLine, + ExpectedIntegerAfterSTLine, ExpectedFilespec, UnterminatedFilespec, UnterminatedSpecialToken,