avoid compilerplugin's sharedvisitor bailing out prematurely

The simplifyconstruct test can return false from a Visit*() function
(thus ending the whole traversal) because anyPluginActive() would
return false just because a plugin would be temporarily disabled
in Traverse*() because of its PreTraverse*() returning false. Keep
a count of temporarily disabled plugins to prevent this.

Change-Id: I413d88749257acff2220182d13e8fcd0f7289540
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87636
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
This commit is contained in:
Luboš Luňák 2020-01-28 15:55:33 +01:00
parent 545f198a3b
commit 1565bcaff4

View File

@ -141,8 +141,16 @@ void generateVisitor( PluginType type )
" : FilteringPlugin(rData)\n"; " : FilteringPlugin(rData)\n";
for( const PluginInfo& plugin : plugins[ type ] ) for( const PluginInfo& plugin : plugins[ type ] )
output << " , " << plugin.variableName << "( nullptr )\n"; output << " , " << plugin.variableName << "( nullptr )\n";
output << " , activeRefCount( 0 )\n";
output << " {}\n"; output << " {}\n";
output <<
" ~SharedRecursiveASTVisitor" << pluginTypeNames[ type ] << "()\n"
" {\n"
" if( activeRefCount != 0 )\n"
" abort();\n"
" }\n";
output << output <<
" virtual bool preRun() override\n" " virtual bool preRun() override\n"
" {\n"; " {\n";
@ -251,7 +259,10 @@ void generateVisitor( PluginType type )
output << " if( !" << plugin.variableName << "->Pre" << traverse.name << "( arg ))\n"; output << " if( !" << plugin.variableName << "->Pre" << traverse.name << "( arg ))\n";
// This will disable the plugin for the time of the traverse, until restored later, // This will disable the plugin for the time of the traverse, until restored later,
// just like directly returning from Traverse* would skip that part. // just like directly returning from Traverse* would skip that part.
output << " {\n";
output << " " << plugin.variableName << " = nullptr;\n"; output << " " << plugin.variableName << " = nullptr;\n";
output << " ++activeRefCount;\n";
output << " }\n";
output << " }\n"; output << " }\n";
} }
} }
@ -271,6 +282,8 @@ void generateVisitor( PluginType type )
output << " save" << plugin.className << " = nullptr;\n"; output << " save" << plugin.className << " = nullptr;\n";
output << " }\n"; output << " }\n";
} }
output << " if( " << plugin.variableName << " == nullptr && save" << plugin.className << " != nullptr )\n";
output << " --activeRefCount;\n";
output << " " << plugin.variableName << " = save" << plugin.className << ";\n"; output << " " << plugin.variableName << " = save" << plugin.className << ";\n";
} }
output << " return ret;\n"; output << " return ret;\n";
@ -282,21 +295,16 @@ void generateVisitor( PluginType type )
output << output <<
" bool anyPluginActive() const\n" " bool anyPluginActive() const\n"
" {\n"; " {\n"
first = true; " return activeRefCount > 0";
for( const PluginInfo& plugin : plugins[ type ] ) for( const PluginInfo& plugin : plugins[ type ] )
{
if( first )
output << " return " << plugin.variableName << " != nullptr";
else
output << "\n || " << plugin.variableName << " != nullptr"; output << "\n || " << plugin.variableName << " != nullptr";
first = false;
}
output << ";\n"; output << ";\n";
output << " }\n"; output << " }\n";
for( const PluginInfo& plugin : plugins[ type ] ) for( const PluginInfo& plugin : plugins[ type ] )
output << " " << plugin.className << "* " << plugin.variableName << ";\n"; output << " " << plugin.className << "* " << plugin.variableName << ";\n";
output << " int activeRefCount;\n";
output << output <<
"};\n" "};\n"