2019-07-28 23:53:15 +03:00
|
|
|
|
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
|
2015-06-01 22:15:17 +03:00
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
|
|
|
|
using System;
|
2015-05-14 22:35:07 +03:00
|
|
|
|
using PascalABCCompiler.SyntaxTree;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TreeConverter.LambdaExpressions
|
|
|
|
|
|
{
|
2016-06-12 02:39:03 +03:00
|
|
|
|
public class LambdaSearcher : WalkingVisitorNew
|
2015-05-14 22:35:07 +03:00
|
|
|
|
{
|
|
|
|
|
|
private readonly syntax_tree_node _treeNodeToProcess;
|
|
|
|
|
|
private class LambdaIsFound : Exception { }
|
|
|
|
|
|
|
|
|
|
|
|
public function_lambda_definition FoundLambda
|
|
|
|
|
|
{
|
|
|
|
|
|
get;
|
|
|
|
|
|
private set;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LambdaSearcher(syntax_tree_node syntaxTreeNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
_treeNodeToProcess = syntaxTreeNode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void visit(function_lambda_definition lambdaDef)
|
|
|
|
|
|
{
|
|
|
|
|
|
FoundLambda = lambdaDef;
|
|
|
|
|
|
throw new LambdaIsFound();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool CheckIfContainsLambdas()
|
|
|
|
|
|
{
|
|
|
|
|
|
var lambdaIsFound = false;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ProcessNode(_treeNodeToProcess);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (LambdaIsFound)
|
|
|
|
|
|
{
|
|
|
|
|
|
lambdaIsFound = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return lambdaIsFound;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|