@@ -48,27 +48,30 @@ void registerMigrationRule(const std::string &Name, Functor &&F) {
48
48
}
49
49
50
50
void registerMacroRule (MetaRuleObject &R) {
51
+ if (!R.Out .has_value ())
52
+ return ;
51
53
auto It = MapNames::MacroRuleMap.find (R.In );
52
54
if (It != MapNames::MacroRuleMap.end ()) {
53
55
if (It->second .Priority > R.Priority ) {
54
56
It->second .Id = R.RuleId ;
55
57
It->second .Priority = R.Priority ;
56
58
It->second .In = R.In ;
57
- It->second .Out = R.Out ;
59
+ It->second .Out = R.Out . value () ;
58
60
It->second .HelperFeature =
59
61
clang::dpct::HelperFeatureEnum::none;
60
62
It->second .Includes = R.Includes ;
61
63
}
62
64
} else {
63
65
MapNames::MacroRuleMap.emplace (
64
66
R.In ,
65
- MacroMigrationRule (R.RuleId , R.Priority , R.In , R.Out ,
66
- clang::dpct::HelperFeatureEnum::none,
67
- R.Includes ));
67
+ MacroMigrationRule (R.RuleId , R.Priority , R.In , R.Out .value (),
68
+ clang::dpct::HelperFeatureEnum::none, R.Includes ));
68
69
}
69
70
}
70
71
71
72
void registerAPIRule (MetaRuleObject &R) {
73
+ if (!R.Out .has_value ())
74
+ return ;
72
75
using namespace clang ::dpct;
73
76
// register rule
74
77
registerMigrationRule (
@@ -119,6 +122,8 @@ void registerAPIRule(MetaRuleObject &R) {
119
122
}
120
123
121
124
void registerHeaderRule (MetaRuleObject &R) {
125
+ if (!R.Out .has_value ())
126
+ return ;
122
127
auto It = MapNames::HeaderRuleMap.find (R.In );
123
128
if (It != MapNames::HeaderRuleMap.end ()) {
124
129
if (It->second .Priority > R.Priority ) {
@@ -130,11 +135,13 @@ void registerHeaderRule(MetaRuleObject &R) {
130
135
}
131
136
132
137
void registerTypeRule (MetaRuleObject &R) {
138
+ if (!R.Out .has_value ())
139
+ return ;
133
140
std::shared_ptr TOB = std::make_shared<TypeOutputBuilder>();
134
141
TOB->Kind = TypeOutputBuilder::Kind::Top;
135
142
TOB->RuleName = R.RuleId ;
136
143
TOB->RuleFile = R.RuleFile ;
137
- TOB->parse (R.Out );
144
+ TOB->parse (R.Out . value () );
138
145
139
146
if (R.RuleAttributes .NumOfTemplateArgs != -1 ) {
140
147
dpct::TypeMatchingDesc TMD =
@@ -155,7 +162,7 @@ void registerTypeRule(MetaRuleObject &R) {
155
162
auto It = MapNames::TypeNamesMap.find (R.In );
156
163
if (It != MapNames::TypeNamesMap.end ()) {
157
164
if (It->second ->Priority > R.Priority ) {
158
- It->second ->NewName = R.Out ;
165
+ It->second ->NewName = R.Out . value () ;
159
166
It->second ->Priority = R.Priority ;
160
167
It->second ->RequestFeature =
161
168
clang::dpct::HelperFeatureEnum::none;
@@ -167,7 +174,7 @@ void registerTypeRule(MetaRuleObject &R) {
167
174
return std::make_unique<clang::dpct::UserDefinedTypeRule>(In);
168
175
});
169
176
auto RulePtr = std::make_shared<TypeNameRule>(
170
- R.Out , clang::dpct::HelperFeatureEnum::none, R.Priority );
177
+ R.Out . value () , clang::dpct::HelperFeatureEnum::none, R.Priority );
171
178
RulePtr->Includes .insert (RulePtr->Includes .end (), R.Includes .begin (),
172
179
R.Includes .end ());
173
180
MapNames::TypeNamesMap.emplace (R.In , RulePtr);
@@ -176,7 +183,8 @@ void registerTypeRule(MetaRuleObject &R) {
176
183
177
184
void registerClassRule (MetaRuleObject &R) {
178
185
// register class name migration rule
179
- registerTypeRule (R);
186
+ if (R.Out .has_value ())
187
+ registerTypeRule (R);
180
188
// register all field rules
181
189
for (auto ItField = R.Fields .begin (); ItField != R.Fields .end (); ItField++) {
182
190
std::string BaseAndFieldName = R.In + " ." + (*ItField)->In ;
@@ -250,11 +258,13 @@ void registerClassRule(MetaRuleObject &R) {
250
258
}
251
259
252
260
void registerEnumRule (MetaRuleObject &R) {
261
+ if (!R.Out .has_value ())
262
+ return ;
253
263
auto It = MapNames::EnumNamesMap.find (R.In );
254
264
if (It != MapNames::EnumNamesMap.end ()) {
255
265
if (It->second ->Priority > R.Priority ) {
256
266
It->second ->Priority = R.Priority ;
257
- It->second ->NewName = R.Out ;
267
+ It->second ->NewName = R.Out . value () ;
258
268
It->second ->RequestFeature =
259
269
clang::dpct::HelperFeatureEnum::none;
260
270
It->second ->Includes .insert (It->second ->Includes .end (),
@@ -268,7 +278,7 @@ void registerEnumRule(MetaRuleObject &R) {
268
278
return std::make_unique<clang::dpct::UserDefinedEnumRule>(Enum);
269
279
});
270
280
auto RulePtr = std::make_shared<EnumNameRule>(
271
- R.Out , clang::dpct::HelperFeatureEnum::none, R.Priority );
281
+ R.Out . value () , clang::dpct::HelperFeatureEnum::none, R.Priority );
272
282
RulePtr->Includes .insert (RulePtr->Includes .end (), R.Includes .begin (),
273
283
R.Includes .end ());
274
284
MapNames::EnumNamesMap.emplace (
@@ -277,17 +287,23 @@ void registerEnumRule(MetaRuleObject &R) {
277
287
}
278
288
279
289
void deregisterAPIRule (MetaRuleObject &R) {
290
+ if (!R.Out .has_value ())
291
+ return ;
280
292
using namespace clang ::dpct;
281
293
CallExprRewriterFactoryBase::RewriterMap->erase (R.In );
282
294
}
283
295
284
296
void registerPatternRewriterRule (MetaRuleObject &R) {
297
+ if (!R.Out .has_value ())
298
+ return ;
285
299
MapNames::PatternRewriters.emplace_back (MetaRuleObject::PatternRewriter (
286
- R.In , R.Out , R.Subrules , R.MatchMode , R.Warning , R.RuleId ,
300
+ R.In , R.Out . value () , R.Subrules , R.MatchMode , R.Warning , R.RuleId ,
287
301
R.BuildScriptSyntax , R.Priority ));
288
302
}
289
303
290
304
void registerHelperFunctionRule (MetaRuleObject &R) {
305
+ if (!R.Out .has_value ())
306
+ return ;
291
307
static const std::unordered_map<std::string, dpct::HelperFuncCatalog>
292
308
String2HelperFuncCatalogMap{
293
309
{" get_default_queue" , dpct::HelperFuncCatalog::GetDefaultQueue},
@@ -300,7 +316,7 @@ void registerHelperFunctionRule(MetaRuleObject &R) {
300
316
// This map is inited here.
301
317
// It saves the customized string which used for each kind of helper
302
318
// function call in the migrated code.
303
- MapNames::CustomHelperFunctionMap.insert ({Iter->second , R.Out });
319
+ MapNames::CustomHelperFunctionMap.insert ({Iter->second , R.Out . value () });
304
320
dpct::DpctGlobalInfo::setUsingDRYPattern (false );
305
321
dpct::DpctGlobalInfo::getCustomHelperFunctionAddtionalIncludes ().insert (
306
322
R.Includes .begin (), R.Includes .end ());
0 commit comments