parsing of new []-style captures, and creation of associated data structures

This commit is contained in:
Vern Paxson 2021-01-04 13:58:20 -08:00
parent f673f85acc
commit 955384291d
3 changed files with 107 additions and 13 deletions

View file

@ -10,6 +10,7 @@
#include <optional>
#include "zeek/Obj.h"
#include "zeek/ID.h"
#include "zeek/Attr.h"
#include "zeek/ZeekList.h"
#include "zeek/IntrusivePtr.h"
@ -540,6 +541,29 @@ public:
const std::vector<Prototype>& Prototypes() const
{ return prototypes; }
/**
* A single lambda "capture" (outer variable used in a lambda's body).
*/
struct Capture {
detail::IDPtr id;
bool deep_copy;
};
/**
* Sets this function's set of captures. Only valid for lambdas.
*
* @param captures if non-nil, a list of the lambda's captures
*/
void SetCaptures(std::vector<Capture*>* captures);
/**
* Returns the captures declared for this function, or nil if none.
*
* @return a vector giving the captures
*/
const std::vector<Capture*>* GetCaptures() const
{ return captures; }
protected:
friend FuncTypePtr make_intrusive<FuncType>();
@ -549,6 +573,8 @@ protected:
TypePtr yield;
FunctionFlavor flavor;
std::vector<Prototype> prototypes;
std::vector<Capture*>* captures; // if nil then no captures specified
};
class TypeType final : public Type {