Skip to content

Commit ce3b5f6

Browse files
committed
[PP-EXT][Refactoring] Outline utils function from Parser to CGFunctionInfo header
1 parent 7e438e5 commit ce3b5f6

File tree

3 files changed

+93
-67
lines changed

3 files changed

+93
-67
lines changed

clang/include/clang/CodeGen/CGFunctionInfo.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,23 @@ class CGFunctionInfo final
799799
};
800800

801801
} // end namespace CodeGen
802+
803+
enum class PPStructType {
804+
Default,
805+
Generalization,
806+
Specialization
807+
};
808+
809+
PPStructType PPExtGetStructType(const RecordDecl* RD);
810+
811+
struct PPStructInitDesc {
812+
NamedDecl* VD;
813+
const RecordDecl* RD;
814+
const PPStructType Type;
815+
};
816+
817+
std::vector<PPStructInitDesc> PPExtGetRDListToInit(const RecordDecl* RD);
818+
802819
} // end namespace clang
803820

804821
#endif

clang/include/clang/Parse/Parser.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Basic/OpenMPKinds.h"
1919
#include "clang/Basic/OperatorPrecedence.h"
2020
#include "clang/Basic/Specifiers.h"
21+
#include "clang/CodeGen/CGFunctionInfo.h"
2122
#include "clang/Lex/CodeCompletionHandler.h"
2223
#include "clang/Lex/Preprocessor.h"
2324
#include "clang/Sema/DeclSpec.h"
@@ -287,22 +288,6 @@ class Parser : public CodeCompletionHandler {
287288
bool NeedToAddLParen = true
288289
);
289290

290-
enum class PPStructType {
291-
Default,
292-
Generalization,
293-
Specialization
294-
};
295-
296-
PPStructType PPExtGetStructType(const RecordDecl* RD) const;
297-
298-
struct PPStructInitDesc {
299-
NamedDecl* VD;
300-
const RecordDecl* RD;
301-
const PPStructType Type;
302-
};
303-
304-
std::vector<PPStructInitDesc> PPExtGetRDListToInit(const RecordDecl* RD) const;
305-
306291
std::string PPExtConstructTagName(StringRef GenName);
307292

308293
struct PPMemberInitData {

clang/lib/Parse/ParseStmt.cpp

Lines changed: 75 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,81 @@ StmtResult Parser::ParseStatement(SourceLocation *TrailingElseLoc,
4545
return Res;
4646
}
4747

48+
namespace clang
49+
{
50+
51+
PPStructType
52+
PPExtGetStructType(const RecordDecl* RD)
53+
{
54+
StringRef TagFieldName("__pp_specialization_type");
55+
for (auto FieldIter = RD->field_begin();
56+
FieldIter != RD->field_end(); ++FieldIter) {
57+
if (FieldIter->getName().equals(TagFieldName)) {
58+
return PPStructType::Generalization;
59+
}
60+
}
61+
62+
if (RD->getName().startswith("__pp_struct")) {
63+
return PPStructType::Specialization;
64+
}
65+
66+
return PPStructType::Default;
67+
}
68+
69+
std::vector<PPStructInitDesc>
70+
PPExtGetRDListToInit(const RecordDecl* RD)
71+
{
72+
std::vector<PPStructInitDesc> Result;
73+
assert(!RD->field_empty());
74+
auto HeadElem = *RD->field_begin();
75+
auto HeadType = HeadElem->getType();
76+
const RecordDecl* RDHead = HeadType.getCanonicalType().getTypePtr()->
77+
getAsRecordDecl();
78+
79+
if (!RDHead ||
80+
!HeadElem->getName().equals("__pp_head")) {
81+
RDHead = RD;
82+
}
83+
84+
for (auto FieldIter = RDHead->field_begin();
85+
FieldIter != RDHead->field_end(); ++FieldIter) {
86+
auto FieldType = FieldIter->getType();
87+
RecordDecl* RDField = FieldType.getCanonicalType().getTypePtr()->
88+
getAsRecordDecl();
89+
if (RDField) {
90+
auto StrTy = PPExtGetStructType(RDField);
91+
if (StrTy != PPStructType::Default) {
92+
Result.emplace_back(
93+
PPStructInitDesc{*FieldIter, RDField, StrTy});
94+
}
95+
}
96+
}
97+
98+
return Result;
99+
}
100+
101+
} // namespace clang
102+
103+
104+
105+
PPStructType
106+
PPExtGetStructType(const RecordDecl* RD)
107+
{
108+
StringRef TagFieldName("__pp_specialization_type");
109+
for (auto FieldIter = RD->field_begin();
110+
FieldIter != RD->field_end(); ++FieldIter) {
111+
if (FieldIter->getName().equals(TagFieldName)) {
112+
return PPStructType::Generalization;
113+
}
114+
}
115+
116+
if (RD->getName().startswith("__pp_struct")) {
117+
return PPStructType::Specialization;
118+
}
119+
120+
return PPStructType::Default;
121+
}
122+
48123
/// ParseStatementOrDeclaration - Read 'statement' or 'declaration'.
49124
/// StatementOrDeclaration:
50125
/// statement
@@ -1168,57 +1243,6 @@ StmtResult Parser::handleExprStmt(ExprResult E, ParsedStmtContext StmtCtx) {
11681243
return Actions.ActOnExprStmt(E, /*DiscardedValue=*/!IsStmtExprResult);
11691244
}
11701245

1171-
Parser::PPStructType
1172-
Parser::PPExtGetStructType(const RecordDecl* RD) const
1173-
{
1174-
StringRef TagFieldName("__pp_specialization_type");
1175-
for (auto FieldIter = RD->field_begin();
1176-
FieldIter != RD->field_end(); ++FieldIter) {
1177-
if (FieldIter->getName().equals(TagFieldName)) {
1178-
return PPStructType::Generalization;
1179-
}
1180-
}
1181-
1182-
if (RD->getName().startswith("__pp_struct")) {
1183-
return PPStructType::Specialization;
1184-
}
1185-
1186-
return PPStructType::Default;
1187-
}
1188-
1189-
1190-
std::vector<Parser::PPStructInitDesc>
1191-
Parser::PPExtGetRDListToInit(const RecordDecl* RD) const
1192-
{
1193-
std::vector<Parser::PPStructInitDesc> Result;
1194-
assert(!RD->field_empty());
1195-
auto HeadElem = *RD->field_begin();
1196-
auto HeadType = HeadElem->getType();
1197-
const RecordDecl* RDHead = HeadType.getCanonicalType().getTypePtr()->
1198-
getAsRecordDecl();
1199-
1200-
if (!RDHead ||
1201-
!HeadElem->getName().equals("__pp_head")) {
1202-
RDHead = RD;
1203-
}
1204-
1205-
for (auto FieldIter = RDHead->field_begin();
1206-
FieldIter != RDHead->field_end(); ++FieldIter) {
1207-
auto FieldType = FieldIter->getType();
1208-
RecordDecl* RDField = FieldType.getCanonicalType().getTypePtr()->
1209-
getAsRecordDecl();
1210-
if (RDField) {
1211-
auto StrTy = PPExtGetStructType(RDField);
1212-
if (StrTy != PPStructType::Default) {
1213-
Result.emplace_back(
1214-
PPStructInitDesc{*FieldIter, RDField, StrTy});
1215-
}
1216-
}
1217-
}
1218-
1219-
return Result;
1220-
}
1221-
12221246

12231247
Parser::PPMemberInitData
12241248
Parser::PPExtInitPPStruct(PPStructInitDesc IDesc, Expr* MemberAccess)

0 commit comments

Comments
 (0)