mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
reductions of expressions in ASTs - code compiles but doesn't yet link
This commit is contained in:
parent
6aa84087b0
commit
10e80dfcd3
8 changed files with 3264 additions and 164 deletions
76
src/Stmt.h
76
src/Stmt.h
|
@ -11,9 +11,12 @@
|
|||
#include "zeek/ID.h"
|
||||
|
||||
ZEEK_FORWARD_DECLARE_NAMESPACED(CompositeHash, zeek::detail);
|
||||
ZEEK_FORWARD_DECLARE_NAMESPACED(NameExpr, zeek::detail);
|
||||
|
||||
namespace zeek::detail {
|
||||
|
||||
using NameExprPtr = IntrusivePtr<zeek::detail::NameExpr>;
|
||||
|
||||
class ExprListStmt : public Stmt {
|
||||
public:
|
||||
const ListExpr* ExprList() const { return l.get(); }
|
||||
|
@ -366,6 +369,11 @@ public:
|
|||
StmtPtr Duplicate() override;
|
||||
void Inline(Inliner* inl) override;
|
||||
|
||||
// Idioms commonly used in reduction.
|
||||
StmtList(StmtPtr s1, Stmt* s2);
|
||||
StmtList(StmtPtr s1, StmtPtr s2);
|
||||
StmtList(StmtPtr s1, StmtPtr s2, StmtPtr s3);
|
||||
|
||||
protected:
|
||||
bool IsPure() const override;
|
||||
|
||||
|
@ -439,6 +447,74 @@ protected:
|
|||
bool is_return;
|
||||
};
|
||||
|
||||
|
||||
// Internal statement used for inlining. Executes a block and stops
|
||||
// the propagation of any "return" inside the block. Generated in
|
||||
// an already-reduced state.
|
||||
class CatchReturnStmt : public Stmt {
|
||||
public:
|
||||
explicit CatchReturnStmt(StmtPtr block, NameExprPtr ret_var);
|
||||
|
||||
StmtPtr Block() const { return block; }
|
||||
|
||||
// This returns a bare pointer rather than a NameExprPtr only
|
||||
// because we don't want to have to include Expr.h in this header.
|
||||
const NameExpr* RetVar() const { return ret_var.get(); }
|
||||
|
||||
// The assignment statement this statement transformed into,
|
||||
// or nil if it hasn't (the common case).
|
||||
StmtPtr AssignStmt() const { return assign_stmt; }
|
||||
|
||||
ValPtr Exec(Frame* f, StmtFlowType& flow) const override;
|
||||
|
||||
bool IsPure() const override;
|
||||
|
||||
// Even though these objects are generated in reduced form, we still
|
||||
// have a reduction method to support the subsequent optimizer pass.
|
||||
StmtPtr DoReduce(Reducer* c) override;
|
||||
|
||||
// Note, no need for a NoFlowAfter() method because anything that
|
||||
// has "NoFlowAfter" inside the body still gets caught and we
|
||||
// continue afterwards.
|
||||
|
||||
StmtPtr Duplicate() override;
|
||||
|
||||
void StmtDescribe(ODesc* d) const override;
|
||||
|
||||
TraversalCode Traverse(TraversalCallback* cb) const override;
|
||||
|
||||
protected:
|
||||
// The inlined function body.
|
||||
StmtPtr block;
|
||||
|
||||
// Expression that holds the return value. Only used for compiling.
|
||||
NameExprPtr ret_var;
|
||||
|
||||
// If this statement transformed into an assignment, that
|
||||
// corresponding statement.
|
||||
StmtPtr assign_stmt;
|
||||
};
|
||||
|
||||
// Statement that makes sure at run-time that an "any" type has the
|
||||
// correct number of (list) entries to enable sub-assigning to it via
|
||||
// statements like "[a, b, c] = x;". Generated in an already-reduced state.
|
||||
class CheckAnyLenStmt : public ExprStmt {
|
||||
public:
|
||||
explicit CheckAnyLenStmt(ExprPtr e, int expected_len);
|
||||
|
||||
ValPtr Exec(Frame* f, StmtFlowType& flow) const override;
|
||||
|
||||
StmtPtr Duplicate() override;
|
||||
|
||||
bool IsReduced(Reducer* c) const override;
|
||||
StmtPtr DoReduce(Reducer* c) override;
|
||||
|
||||
void StmtDescribe(ODesc* d) const override;
|
||||
|
||||
protected:
|
||||
int expected_len;
|
||||
};
|
||||
|
||||
} // namespace zeek::detail
|
||||
|
||||
using ExprListStmt [[deprecated("Remove in v4.1. Use zeek::detail::ExprListStmt instead.")]] = zeek::detail::ExprListStmt;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue