Skip to content

Commit 789215d

Browse files
vabridgerseinvbri
authored andcommitted
[ASTImporter] Add support for importing fixed point literals
Summary: This patch adds support for importing fixed point literals, following up to https://reviews.llvm.org/D46915 specifically for importing AST. Reviewers: martong, leonardchan, ebevhan, a.sidorin, shafik Reviewed By: martong Subscribers: balazske, rnkovacs, teemperor, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77721
1 parent bddac41 commit 789215d

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,10 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral>
22712271
extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral>
22722272
imaginaryLiteral;
22732273

2274+
/// Matches fixed point literals
2275+
extern const internal::VariadicDynCastAllOfMatcher<Stmt, FixedPointLiteral>
2276+
fixedPointLiteral;
2277+
22742278
/// Matches user defined literal operator call.
22752279
///
22762280
/// Example match: "foo"_suffix

clang/lib/AST/ASTImporter.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ namespace clang {
588588
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
589589
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
590590
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
591+
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
591592
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
592593
ExpectedStmt VisitStringLiteral(StringLiteral *E);
593594
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -6503,6 +6504,20 @@ ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
65036504
*ToSubExprOrErr, *ToTypeOrErr);
65046505
}
65056506

6507+
ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) {
6508+
auto ToTypeOrErr = import(E->getType());
6509+
if (!ToTypeOrErr)
6510+
return ToTypeOrErr.takeError();
6511+
6512+
ExpectedSLoc ToLocationOrErr = import(E->getLocation());
6513+
if (!ToLocationOrErr)
6514+
return ToLocationOrErr.takeError();
6515+
6516+
return new (Importer.getToContext()) FixedPointLiteral(
6517+
Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
6518+
Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
6519+
}
6520+
65066521
ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) {
65076522
ExpectedType ToTypeOrErr = import(E->getType());
65086523
if (!ToTypeOrErr)

clang/lib/ASTMatchers/ASTMatchersInternal.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral>
804804
integerLiteral;
805805
const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral;
806806
const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> imaginaryLiteral;
807+
const internal::VariadicDynCastAllOfMatcher<Stmt, FixedPointLiteral>
808+
fixedPointLiteral;
807809
const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral>
808810
userDefinedLiteral;
809811
const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr>

clang/unittests/AST/ASTImporterFixtures.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ class CompilerOptionSpecificTest : public ::testing::Test {
6666
}
6767
};
6868

69-
const auto DefaultTestValuesForRunOptions = ::testing::Values(
69+
const auto DefaultTestArrayForRunOptions = std::array<ArgVector, 4>{
7070
ArgVector(), ArgVector{"-fdelayed-template-parsing"},
7171
ArgVector{"-fms-compatibility"},
72-
ArgVector{"-fdelayed-template-parsing", "-fms-compatibility"});
72+
ArgVector{"-fdelayed-template-parsing", "-fms-compatibility"}};
73+
74+
const auto DefaultTestValuesForRunOptions =
75+
::testing::ValuesIn(DefaultTestArrayForRunOptions);
7376

7477
// This class provides generic methods to write tests which can check internal
7578
// attributes of AST nodes like getPreviousDecl(), isVirtual(), etc. Also,

clang/unittests/AST/ASTImporterTest.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ static const RecordDecl *getRecordDeclOfFriend(FriendDecl *FD) {
255255
struct ImportExpr : TestImportBase {};
256256
struct ImportType : TestImportBase {};
257257
struct ImportDecl : TestImportBase {};
258+
struct ImportFixedPointExpr : ImportExpr {};
258259

259260
struct CanonicalRedeclChain : ASTImporterOptionSpecificTestBase {};
260261

@@ -527,6 +528,14 @@ TEST_P(ImportExpr, ImportFloatinglLiteralExpr) {
527528
floatLiteral(equals(1.0e-5f), hasType(asString("float"))))));
528529
}
529530

531+
TEST_P(ImportFixedPointExpr, ImportFixedPointerLiteralExpr) {
532+
MatchVerifier<Decl> Verifier;
533+
testImport("void declToImport() { (void)1.0k; }", Lang_C, "", Lang_C,
534+
Verifier, functionDecl(hasDescendant(fixedPointLiteral())));
535+
testImport("void declToImport() { (void)0.75r; }", Lang_C, "", Lang_C,
536+
Verifier, functionDecl(hasDescendant(fixedPointLiteral())));
537+
}
538+
530539
TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
531540
MatchVerifier<Decl> Verifier;
532541
testImport(
@@ -5922,6 +5931,17 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
59225931
EXPECT_TRUE(ToA);
59235932
}
59245933

5934+
template <typename T>
5935+
auto ExtendWithOptions(const T &Values, const ArgVector &Args) {
5936+
auto Copy = Values;
5937+
for (ArgVector &ArgV : Copy) {
5938+
for (const std::string &Arg : Args) {
5939+
ArgV.push_back(Arg);
5940+
}
5941+
}
5942+
return ::testing::ValuesIn(Copy);
5943+
}
5944+
59255945
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
59265946
DefaultTestValuesForRunOptions, );
59275947

@@ -5931,6 +5951,10 @@ INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportPath,
59315951
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportExpr,
59325952
DefaultTestValuesForRunOptions, );
59335953

5954+
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFixedPointExpr,
5955+
ExtendWithOptions(DefaultTestArrayForRunOptions,
5956+
ArgVector{"-ffixed-point"}), );
5957+
59345958
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
59355959
DefaultTestValuesForRunOptions, );
59365960

0 commit comments

Comments
 (0)