[PATCH] D50428: [ASTImporter] Add support for importing imaginary literals
Gabor Marton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 9 05:18:57 PDT 2018
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(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50428.159902.patch
Type: text/x-patch
Size: 3131 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180809/7e79b0de/attachment.bin>
More information about the cfe-commits
mailing list