@@ -48,7 +48,7 @@ void registerMigrationRule(const std::string &Name, Functor &&F) {
4848}
4949
5050void registerMacroRule (MetaRuleObject &R) {
51- if (!R. Out . has_value ( ))
51+ if (!validateOutFieldAndWarn (R ))
5252 return ;
5353 auto It = MapNames::MacroRuleMap.find (R.In );
5454 if (It != MapNames::MacroRuleMap.end ()) {
@@ -70,7 +70,7 @@ void registerMacroRule(MetaRuleObject &R) {
7070}
7171
7272void registerAPIRule (MetaRuleObject &R) {
73- if (!R. Out . has_value ( ))
73+ if (!validateOutFieldAndWarn (R ))
7474 return ;
7575 using namespace clang ::dpct;
7676 // register rule
@@ -122,7 +122,7 @@ void registerAPIRule(MetaRuleObject &R) {
122122}
123123
124124void registerHeaderRule (MetaRuleObject &R) {
125- if (!R. Out . has_value ( ))
125+ if (!validateOutFieldAndWarn (R ))
126126 return ;
127127 auto It = MapNames::HeaderRuleMap.find (R.In );
128128 if (It != MapNames::HeaderRuleMap.end ()) {
@@ -135,7 +135,7 @@ void registerHeaderRule(MetaRuleObject &R) {
135135}
136136
137137void registerTypeRule (MetaRuleObject &R) {
138- if (!R. Out . has_value ( ))
138+ if (!validateOutFieldAndWarn (R ))
139139 return ;
140140 std::shared_ptr TOB = std::make_shared<TypeOutputBuilder>();
141141 TOB->Kind = TypeOutputBuilder::Kind::Top;
@@ -185,6 +185,9 @@ void registerClassRule(MetaRuleObject &R) {
185185 // register class name migration rule
186186 if (R.Out .has_value ())
187187 registerTypeRule (R);
188+ if (R.Fields .empty () && R.Methods .empty ()) {
189+ (void )validateOutFieldAndWarn (R);
190+ }
188191 // register all field rules
189192 for (auto ItField = R.Fields .begin (); ItField != R.Fields .end (); ItField++) {
190193 std::string BaseAndFieldName = R.In + " ." + (*ItField)->In ;
@@ -258,7 +261,7 @@ void registerClassRule(MetaRuleObject &R) {
258261}
259262
260263void registerEnumRule (MetaRuleObject &R) {
261- if (!R. Out . has_value ( ))
264+ if (!validateOutFieldAndWarn (R ))
262265 return ;
263266 auto It = MapNames::EnumNamesMap.find (R.In );
264267 if (It != MapNames::EnumNamesMap.end ()) {
@@ -287,22 +290,22 @@ void registerEnumRule(MetaRuleObject &R) {
287290}
288291
289292void deregisterAPIRule (MetaRuleObject &R) {
290- if (!R. Out . has_value ( ))
293+ if (!validateOutFieldAndWarn (R ))
291294 return ;
292295 using namespace clang ::dpct;
293296 CallExprRewriterFactoryBase::RewriterMap->erase (R.In );
294297}
295298
296299void registerPatternRewriterRule (MetaRuleObject &R) {
297- if (!R. Out . has_value ( ))
300+ if (!validateOutFieldAndWarn (R ))
298301 return ;
299302 MapNames::PatternRewriters.emplace_back (MetaRuleObject::PatternRewriter (
300303 R.In , R.Out .value (), R.Subrules , R.MatchMode , R.Warning , R.RuleId ,
301304 R.BuildScriptSyntax , R.Priority ));
302305}
303306
304307void registerHelperFunctionRule (MetaRuleObject &R) {
305- if (!R. Out . has_value ( ))
308+ if (!validateOutFieldAndWarn (R ))
306309 return ;
307310 static const std::unordered_map<std::string, dpct::HelperFuncCatalog>
308311 String2HelperFuncCatalogMap{
@@ -562,6 +565,14 @@ void importRules(std::vector<clang::tooling::UnifiedPath> &RuleFiles) {
562565 }
563566}
564567
568+ bool validateOutFieldAndWarn (const MetaRuleObject &R) {
569+ if (R.Out .has_value ())
570+ return true ;
571+ llvm::errs () << " warning: The \" Out\" field of rule " << R.RuleId << " (in "
572+ << R.RuleFile << " ) is not specified. This rule is ignored.\n " ;
573+ return false ;
574+ }
575+
565576// /RuleOutputString is the string specified in rule's "Out" session
566577void OutputBuilder::parse (std::string &RuleOutputString) {
567578 size_t i, StrStartIdx = 0 ;
0 commit comments