mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
C++ script generation fix for lambdas that have identical bodies
This commit is contained in:
parent
7210225bba
commit
dbae112bdc
1 changed files with 18 additions and 14 deletions
|
@ -155,20 +155,24 @@ void CPPCompile::Compile(bool report_uncompilable)
|
||||||
if ( ! func.ShouldSkip() )
|
if ( ! func.ShouldSkip() )
|
||||||
DeclareFunc(func);
|
DeclareFunc(func);
|
||||||
|
|
||||||
// We track lambdas by their internal names, because two different
|
// We track lambdas by their internal names, and associate those
|
||||||
// LambdaExpr's can wind up referring to the same underlying lambda
|
// with their AST bodies. Two different LambdaExpr's can wind up
|
||||||
// if the bodies happen to be identical. In that case, we don't
|
// referring to the same underlying lambda if the bodies happen to
|
||||||
// want to generate the lambda twice.
|
// be identical. In that case, we don't want to generate the lambda
|
||||||
unordered_set<string> lambda_names;
|
// twice, but we do want to map the second one to the same body name.
|
||||||
|
unordered_map<string, const Stmt*> lambda_ASTs;
|
||||||
for ( const auto& l : pfs.Lambdas() )
|
for ( const auto& l : pfs.Lambdas() )
|
||||||
{
|
{
|
||||||
const auto& n = l->Name();
|
const auto& n = l->Name();
|
||||||
if ( lambda_names.count(n) > 0 )
|
const auto body = l->Ingredients().body.get();
|
||||||
// Skip it.
|
if ( lambda_ASTs.count(n) > 0 )
|
||||||
continue;
|
// Reuse previous body.
|
||||||
|
body_names[body] = body_names[lambda_ASTs[n]];
|
||||||
|
else
|
||||||
|
{
|
||||||
DeclareLambda(l, pfs.ExprProf(l).get());
|
DeclareLambda(l, pfs.ExprProf(l).get());
|
||||||
lambda_names.insert(n);
|
lambda_ASTs[n] = body;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NL();
|
NL();
|
||||||
|
@ -178,15 +182,15 @@ void CPPCompile::Compile(bool report_uncompilable)
|
||||||
if ( ! func.ShouldSkip() )
|
if ( ! func.ShouldSkip() )
|
||||||
CompileFunc(func);
|
CompileFunc(func);
|
||||||
|
|
||||||
lambda_names.clear();
|
lambda_ASTs.clear();
|
||||||
for ( const auto& l : pfs.Lambdas() )
|
for ( const auto& l : pfs.Lambdas() )
|
||||||
{
|
{
|
||||||
const auto& n = l->Name();
|
const auto& n = l->Name();
|
||||||
if ( lambda_names.count(n) > 0 )
|
if ( lambda_ASTs.count(n) > 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CompileLambda(l, pfs.ExprProf(l).get());
|
CompileLambda(l, pfs.ExprProf(l).get());
|
||||||
lambda_names.insert(n);
|
lambda_ASTs[n] = l->Ingredients().body.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
NL();
|
NL();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue