]> granicus.if.org Git - clang/commitdiff
Make octal constant lexing use AdvanceToTokenCharacter to give more
authorChris Lattner <sabre@nondot.org>
Mon, 16 Jul 2007 06:55:01 +0000 (06:55 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 16 Jul 2007 06:55:01 +0000 (06:55 +0000)
accurate diagnostics.  For test/Lexer/comments.c we now emit:

int x = 000000080;  /* expected-error {{invalid digit}} */
               ^
constants.c:7:4: error: invalid digit '8' in octal constant
00080;             /* expected-error {{invalid digit}} */
   ^

The last line is due to an escaped newline.  The full line looks like:

int y = 0000\
00080;             /* expected-error {{invalid digit}} */

Previously, we emitted:
constants.c:4:9: error: invalid digit '8' in octal constant
int x = 000000080;  /* expected-error {{invalid digit}} */
        ^
constants.c:6:9: error: invalid digit '8' in octal constant
int y = 0000\
        ^

which isn't too bad, but the new way is better for the user,
regardless of whether there is an escaped newline or not.

All the other lexer-related diagnostics should switch over
to using AdvanceToTokenCharacter where appropriate.  Help
wanted :).

This implements test/Lexer/constants.c.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39906 91177308-0d34-0410-b5e6-96231b3b80d8

Basic/SourceManager.cpp
Lex/LiteralSupport.cpp
TODO.txt
clang.xcodeproj/project.pbxproj
test/Lexer/constants.c [new file with mode: 0644]

index a2520e3aff3e315b41054509221afdd28e0b5caa..2177c982d453261ff16c38c51389773bf5577802 100644 (file)
@@ -339,7 +339,6 @@ unsigned SourceManager::getSourceFilePos(SourceLocation Loc) const {
   return getFilePos(Loc);
 }
 
-
 /// PrintStats - Print statistics to stderr.
 ///
 void SourceManager::PrintStats() const {
index 5d9c7bd11eb541365fb32879d3bc2a90eb34f11d..8978c796a8cc493fa3cea6dad596bcd9be63fb0b 100644 (file)
@@ -14,8 +14,9 @@
 
 #include "clang/Lex/LiteralSupport.h"
 #include "clang/Lex/Preprocessor.h"
-#include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/StringExtras.h"
 using namespace clang;
@@ -261,6 +262,7 @@ NumericLiteralParser(const char *begin, const char *end,
       if (s == ThisTokEnd) {
         // Done.
       } else if (isxdigit(*s)) {
+        TokLoc = PP.AdvanceToTokenCharacter(TokLoc, s-begin);
         Diag(TokLoc, diag::err_invalid_octal_digit, std::string(s, s+1));
         return;
       } else if (*s == '.') {
index d2b944bb6bead4054bf751fb56fab992bcee9e0f..94e471dcdd4c71a334f9dbde83274e9dfe86966e 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -22,6 +22,8 @@ diag.c:4:9: error: invalid digit '8' in octal constant
 00080;
    ^
 
+This specific diagnostic is implemented, but others should be updated.
+
 //===---------------------------------------------------------------------===//
 
 
index 560076196ae1d974557e7afbc5b596fea14a62a5..6059d2ac79eefbca737b5bd881fcf8a670180fc4 100644 (file)
                1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = LiteralSupport.cpp; sourceTree = "<group>"; };
                84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
                84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
-               8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+               8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
                DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
                DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
                DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
diff --git a/test/Lexer/constants.c b/test/Lexer/constants.c
new file mode 100644 (file)
index 0000000..f7e4cd0
--- /dev/null
@@ -0,0 +1,8 @@
+/* RUN: clang -parse-ast-check %s
+ */
+
+int x = 000000080;  /* expected-error {{invalid digit}} */
+
+int y = 0000\
+00080;             /* expected-error {{invalid digit}} */
+