From: Chris Lattner Date: Sat, 7 Jun 2008 22:35:38 +0000 (+0000) Subject: capture whether a CharacterLiteral was wide or not in the AST. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c250aae4f645833aed3a6321bc8598f7330dce8d;p=clang capture whether a CharacterLiteral was wide or not in the AST. Patch by Mike Stump! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52081 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 9a76823ff2..42344d0fea 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -234,12 +234,14 @@ public: class CharacterLiteral : public Expr { unsigned Value; SourceLocation Loc; + bool IsWide; public: // type should be IntTy - CharacterLiteral(unsigned value, QualType type, SourceLocation l) - : Expr(CharacterLiteralClass, type), Value(value), Loc(l) { + CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) + : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) { } SourceLocation getLoc() const { return Loc; } + bool isWide() const { return IsWide; } virtual SourceRange getSourceRange() const { return SourceRange(Loc); } diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 5e347435b6..dc686f9bf5 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -513,8 +513,9 @@ void StmtPrinter::VisitPreDefinedExpr(PreDefinedExpr *Node) { } void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) { - // FIXME should print an L for wchar_t constants unsigned value = Node->getValue(); + if (Node->isWide()) + OS << "L"; switch (value) { case '\\': OS << "'\\\\'"; diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp index 99a890946d..6fcc1ef428 100644 --- a/lib/AST/StmtSerialization.cpp +++ b/lib/AST/StmtSerialization.cpp @@ -375,14 +375,16 @@ CastExpr* CastExpr::CreateImpl(Deserializer& D, ASTContext& C) { void CharacterLiteral::EmitImpl(Serializer& S) const { S.Emit(Value); S.Emit(Loc); + S.EmitBool(IsWide); S.Emit(getType()); } CharacterLiteral* CharacterLiteral::CreateImpl(Deserializer& D, ASTContext& C) { unsigned value = D.ReadInt(); SourceLocation Loc = SourceLocation::ReadVal(D); + bool iswide = D.ReadBool(); QualType T = QualType::ReadVal(D); - return new CharacterLiteral(value,T,Loc); + return new CharacterLiteral(value,iswide,T,Loc); } void CompoundAssignOperator::EmitImpl(Serializer& S) const { diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index e918572f35..e84971062e 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -183,7 +183,8 @@ Sema::ExprResult Sema::ActOnCharacterConstant(const Token &Tok) { QualType type = getLangOptions().CPlusPlus ? Context.CharTy : Context.IntTy; - return new CharacterLiteral(Literal.getValue(), type, Tok.getLocation()); + return new CharacterLiteral(Literal.getValue(), Literal.isWide(), type, + Tok.getLocation()); } Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {