diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-08 01:34:56 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-08 01:34:56 +0000 |
| commit | 75b67d6dc5c8917c6d2460d053ba234722f209a1 (patch) | |
| tree | c5af0ed3b4f65046546ba993e986c7293fec894b /clang/lib/Sema | |
| parent | 978dfc0d1e27e5d2a0966a407333b4fe18644a41 (diff) | |
| download | bcm5719-llvm-75b67d6dc5c8917c6d2460d053ba234722f209a1.tar.gz bcm5719-llvm-75b67d6dc5c8917c6d2460d053ba234722f209a1.zip | |
User-defined literal support for character literals.
llvm-svn: 152277
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 7d99732e682..f82ff4395de 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1122,6 +1122,14 @@ Sema::CreateGenericSelectionExpr(SourceLocation KeyLoc, ResultIndex)); } +/// getUDSuffixLoc - Create a SourceLocation for a ud-suffix, given the +/// location of the token and the offset of the ud-suffix within it. +static SourceLocation getUDSuffixLoc(Sema &S, SourceLocation TokLoc, + unsigned Offset) { + return Lexer::AdvanceToTokenCharacter(TokLoc, Offset, S.getSourceManager(), + S.getLangOptions()); +} + /// ActOnStringLiteral - The specified tokens were lexed as pasted string /// fragments (e.g. "foo" "bar" L"baz"). The result string has to handle string /// concatenation ([C99 5.1.1.2, translation phase #6]), so it may come from @@ -1181,8 +1189,9 @@ Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) { // We're building a user-defined literal. IdentifierInfo *UDSuffix = &Context.Idents.get(Literal.getUDSuffix()); - SourceLocation UDSuffixLoc = StringTokLocs[0]; - // FIXME: = Literal.getUDSuffixLoc(getSourceManager()); + SourceLocation UDSuffixLoc = + getUDSuffixLoc(*this, StringTokLocs[Literal.getUDSuffixToken()], + Literal.getUDSuffixOffset()); // C++11 [lex.ext]p5: The literal L is treated as a call of the form // operator "" X (str, len) @@ -2404,8 +2413,22 @@ ExprResult Sema::ActOnCharacterConstant(const Token &Tok) { else if (Literal.isUTF32()) Kind = CharacterLiteral::UTF32; - return Owned(new (Context) CharacterLiteral(Literal.getValue(), Kind, Ty, - Tok.getLocation())); + Expr *Lit = new (Context) CharacterLiteral(Literal.getValue(), Kind, Ty, + Tok.getLocation()); + + if (Literal.getUDSuffix().empty()) + return Owned(Lit); + + // We're building a user-defined literal. + IdentifierInfo *UDSuffix = &Context.Idents.get(Literal.getUDSuffix()); + SourceLocation UDSuffixLoc = + getUDSuffixLoc(*this, Tok.getLocation(), Literal.getUDSuffixOffset()); + + // C++11 [lex.ext]p6: The literal L is treated as a call of the form + // operator "" X (ch) + return BuildLiteralOperatorCall(UDSuffix, UDSuffixLoc, + llvm::makeArrayRef(&Lit, 1), + Tok.getLocation()); } ExprResult Sema::ActOnIntegerConstant(SourceLocation Loc, uint64_t Val) { |

