summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-03-08 08:45:32 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-03-08 08:45:32 +0000
commit39570d00201ce7d9b65750e8ea5fc95e0047f467 (patch)
tree7da1856afce67cd0b55ed2711ae1756b933ae266 /clang/lib/Lex
parent5a4bcc749acae6b92451cc9c2aa502d25600fbce (diff)
downloadbcm5719-llvm-39570d00201ce7d9b65750e8ea5fc95e0047f467.tar.gz
bcm5719-llvm-39570d00201ce7d9b65750e8ea5fc95e0047f467.zip
Add support for cooked forms of user-defined-integer-literal and
user-defined-floating-literal. Support for raw forms of these literals to follow. llvm-svn: 152302
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r--clang/lib/Lex/LiteralSupport.cpp18
-rw-r--r--clang/lib/Lex/PPExpressions.cpp6
2 files changed, 20 insertions, 4 deletions
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index e0bdc5f8589..901d96d21ae 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -333,6 +333,10 @@ static void EncodeUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd,
/// decimal-constant integer-suffix
/// octal-constant integer-suffix
/// hexadecimal-constant integer-suffix
+/// user-defiend-integer-literal: [C++11 lex.ext]
+/// decimal-literal ud-suffix
+/// octal-literal ud-suffix
+/// hexadecimal-literal ud-suffix
/// decimal-constant:
/// nonzero-digit
/// decimal-constant digit
@@ -382,6 +386,7 @@ NumericLiteralParser(const char *begin, const char *end,
s = DigitsBegin = begin;
saw_exponent = false;
saw_period = false;
+ saw_ud_suffix = false;
isLong = false;
isUnsigned = false;
isLongLong = false;
@@ -519,13 +524,20 @@ NumericLiteralParser(const char *begin, const char *end,
isImaginary = true;
continue; // Success.
}
- // If we reached here, there was an error.
+ // If we reached here, there was an error or a ud-suffix.
break;
}
- // Report an error if there are any.
if (s != ThisTokEnd) {
- PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-begin),
+ if (PP.getLangOptions().CPlusPlus0x && s == SuffixBegin && *s == '_') {
+ // We have a ud-suffix! By C++11 [lex.ext]p10, ud-suffixes not starting
+ // with an '_' are ill-formed.
+ saw_ud_suffix = true;
+ return;
+ }
+
+ // Report an error if there are any.
+ PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, SuffixBegin-begin),
isFPConstant ? diag::err_invalid_suffix_float_constant :
diag::err_invalid_suffix_integer_constant)
<< StringRef(SuffixBegin, ThisTokEnd-SuffixBegin);
diff --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp
index 8d8fe316e7e..ae2f5c1ab23 100644
--- a/clang/lib/Lex/PPExpressions.cpp
+++ b/clang/lib/Lex/PPExpressions.cpp
@@ -215,6 +215,10 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
}
assert(Literal.isIntegerLiteral() && "Unknown ppnumber");
+ // Complain about, and drop, any ud-suffix.
+ if (Literal.hasUDSuffix())
+ PP.Diag(PeekTok, diag::err_pp_invalid_udl) << /*integer*/1;
+
// long long is a C99 feature.
if (!PP.getLangOptions().C99 && Literal.isLongLong)
PP.Diag(PeekTok, PP.getLangOptions().CPlusPlus0x ?
@@ -253,7 +257,7 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
case tok::utf32_char_constant: // U'x'
// Complain about, and drop, any ud-suffix.
if (PeekTok.hasUDSuffix())
- PP.Diag(PeekTok, diag::err_pp_invalid_char_udl);
+ PP.Diag(PeekTok, diag::err_pp_invalid_udl) << /*character*/0;
SmallString<32> CharBuffer;
bool CharInvalid = false;
OpenPOWER on IntegriCloud