This revision was automatically updated to reflect the committed changes. Closed by commit rL339334: Add support for importing imaginary literals (authored by martong, committed by ). Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D50428?vs=159662&id=159902#toc Repository: rL LLVM https://reviews.llvm.org/D50428 Files: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h cfe/trunk/lib/AST/ASTImporter.cpp cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp cfe/trunk/unittests/AST/ASTImporterTest.cpp Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h @@ -1975,6 +1975,11 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral; +/// Matches imaginary literals, which are based on integer and floating +/// point literals e.g.: 1i, 1.0i +extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> + imaginaryLiteral; + /// Matches user defined literal operator call. /// /// Example match: "foo"_suffix Index: cfe/trunk/lib/AST/ASTImporter.cpp =================================================================== --- cfe/trunk/lib/AST/ASTImporter.cpp +++ cfe/trunk/lib/AST/ASTImporter.cpp @@ -434,6 +434,7 @@ Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); Expr *VisitIntegerLiteral(IntegerLiteral *E); Expr *VisitFloatingLiteral(FloatingLiteral *E); + Expr *VisitImaginaryLiteral(ImaginaryLiteral *E); Expr *VisitCharacterLiteral(CharacterLiteral *E); Expr *VisitStringLiteral(StringLiteral *E); Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); @@ -5613,6 +5614,18 @@ Importer.Import(E->getLocation())); } +Expr *ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { + QualType T = Importer.Import(E->getType()); + if (T.isNull()) + return nullptr; + + Expr *SubE = Importer.Import(E->getSubExpr()); + if (!SubE) + return nullptr; + + return new (Importer.getToContext()) ImaginaryLiteral(SubE, T); +} + Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { QualType T = Importer.Import(E->getType()); if (T.isNull()) Index: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp =================================================================== --- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp +++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -710,6 +710,7 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral> integerLiteral; const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral; +const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> imaginaryLiteral; const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral> userDefinedLiteral; const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr> Index: cfe/trunk/unittests/AST/ASTImporterTest.cpp =================================================================== --- cfe/trunk/unittests/AST/ASTImporterTest.cpp +++ cfe/trunk/unittests/AST/ASTImporterTest.cpp @@ -553,6 +553,14 @@ floatLiteral(equals(1.0e-5f), hasType(asString("float")))))); } +TEST_P(ImportExpr, ImportImaginaryLiteralExpr) { + MatchVerifier<Decl> Verifier; + testImport( + "void declToImport() { (void)1.0i; }", + Lang_CXX14, "", Lang_CXX14, Verifier, + functionDecl(hasDescendant(imaginaryLiteral()))); +} + TEST_P(ImportExpr, ImportCompoundLiteralExpr) { MatchVerifier<Decl> Verifier; testImport(
Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h @@ -1975,6 +1975,11 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral; +/// Matches imaginary literals, which are based on integer and floating +/// point literals e.g.: 1i, 1.0i +extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> + imaginaryLiteral; + /// Matches user defined literal operator call. /// /// Example match: "foo"_suffix Index: cfe/trunk/lib/AST/ASTImporter.cpp =================================================================== --- cfe/trunk/lib/AST/ASTImporter.cpp +++ cfe/trunk/lib/AST/ASTImporter.cpp @@ -434,6 +434,7 @@ Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); Expr *VisitIntegerLiteral(IntegerLiteral *E); Expr *VisitFloatingLiteral(FloatingLiteral *E); + Expr *VisitImaginaryLiteral(ImaginaryLiteral *E); Expr *VisitCharacterLiteral(CharacterLiteral *E); Expr *VisitStringLiteral(StringLiteral *E); Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); @@ -5613,6 +5614,18 @@ Importer.Import(E->getLocation())); } +Expr *ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { + QualType T = Importer.Import(E->getType()); + if (T.isNull()) + return nullptr; + + Expr *SubE = Importer.Import(E->getSubExpr()); + if (!SubE) + return nullptr; + + return new (Importer.getToContext()) ImaginaryLiteral(SubE, T); +} + Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { QualType T = Importer.Import(E->getType()); if (T.isNull()) Index: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp =================================================================== --- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp +++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -710,6 +710,7 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral> integerLiteral; const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral; +const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> imaginaryLiteral; const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral> userDefinedLiteral; const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr> Index: cfe/trunk/unittests/AST/ASTImporterTest.cpp =================================================================== --- cfe/trunk/unittests/AST/ASTImporterTest.cpp +++ cfe/trunk/unittests/AST/ASTImporterTest.cpp @@ -553,6 +553,14 @@ floatLiteral(equals(1.0e-5f), hasType(asString("float")))))); } +TEST_P(ImportExpr, ImportImaginaryLiteralExpr) { + MatchVerifier<Decl> Verifier; + testImport( + "void declToImport() { (void)1.0i; }", + Lang_CXX14, "", Lang_CXX14, Verifier, + functionDecl(hasDescendant(imaginaryLiteral()))); +} + TEST_P(ImportExpr, ImportCompoundLiteralExpr) { MatchVerifier<Decl> Verifier; testImport(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits