mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Insert contents of #included script-opt files directly
Otherwise there is a functional problem caused by using #include to insert the disconnected source code: language server/analysis tools, like clangd, may get confused by those files and report everything in them as an error.
This commit is contained in:
parent
fa418cb179
commit
a0552f9771
10 changed files with 98 additions and 158 deletions
|
@ -40,9 +40,7 @@ const char* expr_name(BroExprTag t)
|
|||
"()", "function()", "event", "schedule",
|
||||
"coerce", "record_coerce", "table_coerce", "vector_coerce",
|
||||
"sizeof", "cast", "is", "[:]=",
|
||||
|
||||
#include "zeek/script_opt/ExprOpt-Names.h"
|
||||
|
||||
"inline()",
|
||||
"nop",
|
||||
|
||||
};
|
||||
|
|
68
src/Expr.h
68
src/Expr.h
|
@ -67,9 +67,7 @@ enum BroExprTag : int {
|
|||
EXPR_CAST,
|
||||
EXPR_IS,
|
||||
EXPR_INDEX_SLICE_ASSIGN,
|
||||
|
||||
#include "zeek/script_opt/ExprOpt-Enums.h"
|
||||
|
||||
EXPR_INLINE,
|
||||
EXPR_NOP,
|
||||
|
||||
#define NUM_EXPRS (int(EXPR_NOP) + 1)
|
||||
|
@ -196,7 +194,39 @@ public:
|
|||
|
||||
virtual TraversalCode Traverse(TraversalCallback* cb) const = 0;
|
||||
|
||||
#include "zeek/script_opt/ExprOpt-Public.h"
|
||||
// Returns a duplicate of the expression.
|
||||
virtual ExprPtr Duplicate() = 0;
|
||||
|
||||
// Recursively traverses the AST to inline eligible function calls.
|
||||
virtual ExprPtr Inline(Inliner* inl) { return ThisPtr(); }
|
||||
|
||||
// Access to the original expression from which this one is derived,
|
||||
// or this one if we don't have an original. Returns a bare pointer
|
||||
// rather than an ExprPtr to emphasize that the access is read-only.
|
||||
const Expr* Original() const
|
||||
{ return original ? original->Original() : this; }
|
||||
|
||||
// Designate the given Expr node as the original for this one.
|
||||
void SetOriginal(ExprPtr _orig)
|
||||
{
|
||||
if ( ! original )
|
||||
original = std::move(_orig);
|
||||
}
|
||||
|
||||
// A convenience function for taking a newly-created Expr,
|
||||
// making it point to us as the successor, and returning it.
|
||||
//
|
||||
// Takes an Expr* rather than a ExprPtr to de-clutter the calling
|
||||
// code, which is always passing in "new XyzExpr(...)". This
|
||||
// call, as a convenient side effect, transforms that bare pointer
|
||||
// into an ExprPtr.
|
||||
virtual ExprPtr SetSucc(Expr* succ)
|
||||
{
|
||||
succ->SetOriginal(ThisPtr());
|
||||
if ( IsParen() )
|
||||
succ->MarkParen();
|
||||
return {AdoptRef{}, succ};
|
||||
}
|
||||
|
||||
protected:
|
||||
Expr() = default;
|
||||
|
@ -223,7 +253,10 @@ protected:
|
|||
TypePtr type;
|
||||
bool paren;
|
||||
|
||||
#include "zeek/script_opt/ExprOpt-Private.h"
|
||||
// The original expression from which this statement was
|
||||
// derived, if any. Used as an aid for generating meaningful
|
||||
// and correctly-localized error messages.
|
||||
ExprPtr original = nullptr;
|
||||
};
|
||||
|
||||
class NameExpr final : public Expr {
|
||||
|
@ -1100,7 +1133,30 @@ private:
|
|||
};
|
||||
|
||||
|
||||
#include "zeek/script_opt/ExprOpt-Subclasses.h"
|
||||
class InlineExpr : public Expr {
|
||||
public:
|
||||
InlineExpr(ListExprPtr arg_args, IDPList* params, StmtPtr body,
|
||||
int frame_offset, TypePtr ret_type);
|
||||
|
||||
bool IsPure() const override;
|
||||
|
||||
ListExprPtr Args() const { return args; }
|
||||
StmtPtr Body() const { return body; }
|
||||
|
||||
ValPtr Eval(Frame* f) const override;
|
||||
|
||||
ExprPtr Duplicate() override;
|
||||
|
||||
TraversalCode Traverse(TraversalCallback* cb) const override;
|
||||
|
||||
protected:
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
IDPList* params;
|
||||
int frame_offset;
|
||||
ListExprPtr args;
|
||||
StmtPtr body;
|
||||
};
|
||||
|
||||
|
||||
inline Val* Expr::ExprVal() const
|
||||
|
|
|
@ -81,7 +81,37 @@ public:
|
|||
|
||||
virtual TraversalCode Traverse(TraversalCallback* cb) const = 0;
|
||||
|
||||
#include "zeek/script_opt/StmtOpt-Public.h"
|
||||
// Returns a duplicate of the statement.
|
||||
virtual StmtPtr Duplicate() = 0;
|
||||
|
||||
// Recursively traverses the AST to inline eligible function calls.
|
||||
virtual void Inline(Inliner* inl) { }
|
||||
|
||||
// Access to the original statement from which this one is derived,
|
||||
// or this one if we don't have an original. Returns a bare pointer
|
||||
// rather than a StmtPtr to emphasize that the access is read-only.
|
||||
const Stmt* Original() const
|
||||
{ return original ? original->Original() : this; }
|
||||
|
||||
// Designate the given Stmt node as the original for this one.
|
||||
void SetOriginal(StmtPtr _orig)
|
||||
{
|
||||
if ( ! original )
|
||||
original = std::move(_orig);
|
||||
}
|
||||
|
||||
// A convenience function for taking a newly-created Stmt,
|
||||
// making it point to us as the successor, and returning it.
|
||||
//
|
||||
// Takes a Stmt* rather than a StmtPtr to de-clutter the calling
|
||||
// code, which is always passing in "new XyzStmt(...)". This
|
||||
// call, as a convenient side effect, transforms that bare pointer
|
||||
// into a StmtPtr.
|
||||
virtual StmtPtr SetSucc(Stmt* succ)
|
||||
{
|
||||
succ->SetOriginal({NewRef{}, this});
|
||||
return {AdoptRef{}, succ};
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit Stmt(StmtTag arg_tag);
|
||||
|
@ -97,7 +127,10 @@ protected:
|
|||
mutable double last_access; // time of last execution
|
||||
mutable uint32_t access_count; // number of executions
|
||||
|
||||
#include "zeek/script_opt/StmtOpt-Private.h"
|
||||
// The original statement from which this statement was
|
||||
// derived, if any. Used as an aid for generating meaningful
|
||||
// and correctly-localized error messages.
|
||||
StmtPtr original = nullptr;
|
||||
};
|
||||
|
||||
} // namespace zeek::detail
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
// Enums associated with script optimization.
|
||||
|
||||
EXPR_INLINE,
|
|
@ -1,6 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
// Names of Expr subclasses associated with script optimization.
|
||||
// Companion to script_opt/ExprOpt-Enums.h.
|
||||
|
||||
"inline()",
|
|
@ -1,13 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
// Private (protected) Expr methods and member varibles associated
|
||||
// with script optimization. See script_opt/ExprOpt-public.h for
|
||||
// why these aren't factored into a separate class.
|
||||
//
|
||||
// Right now, this file is small, but it will grow as we expand into
|
||||
// other forms of script optimization.
|
||||
|
||||
// The original expression from which this statement was
|
||||
// derived, if any. Used as an aid for generating meaningful
|
||||
// and correctly-localized error messages.
|
||||
ExprPtr original = nullptr;
|
|
@ -1,44 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
// Public Expr methods associated with script optimization.
|
||||
//
|
||||
// We can't effectively factor these out into a separate class to
|
||||
// include via multiple inheritance, because in general they rely
|
||||
// on other Expr methods or member variables, so to do so we'd
|
||||
// have to (1) make all of the methods virtual, and (2) still
|
||||
// include (re-)definitions for them in Expr.h, defeating most
|
||||
// of the benefits of using a separate class.
|
||||
|
||||
// Returns a duplicate of the expression.
|
||||
virtual ExprPtr Duplicate() = 0;
|
||||
|
||||
// Recursively traverses the AST to inline eligible function calls.
|
||||
virtual ExprPtr Inline(Inliner* inl) { return ThisPtr(); }
|
||||
|
||||
// Access to the original expression from which this one is derived,
|
||||
// or this one if we don't have an original. Returns a bare pointer
|
||||
// rather than an ExprPtr to emphasize that the access is read-only.
|
||||
const Expr* Original() const
|
||||
{ return original ? original->Original() : this; }
|
||||
|
||||
// Designate the given Expr node as the original for this one.
|
||||
void SetOriginal(ExprPtr _orig)
|
||||
{
|
||||
if ( ! original )
|
||||
original = std::move(_orig);
|
||||
}
|
||||
|
||||
// A convenience function for taking a newly-created Expr,
|
||||
// making it point to us as the successor, and returning it.
|
||||
//
|
||||
// Takes an Expr* rather than a ExprPtr to de-clutter the calling
|
||||
// code, which is always passing in "new XyzExpr(...)". This
|
||||
// call, as a convenient side effect, transforms that bare pointer
|
||||
// into an ExprPtr.
|
||||
virtual ExprPtr SetSucc(Expr* succ)
|
||||
{
|
||||
succ->SetOriginal(ThisPtr());
|
||||
if ( IsParen() )
|
||||
succ->MarkParen();
|
||||
return {AdoptRef{}, succ};
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
// Expr subclasses and associated functions associated with script
|
||||
// optimization.
|
||||
|
||||
class InlineExpr : public Expr {
|
||||
public:
|
||||
InlineExpr(ListExprPtr arg_args, IDPList* params, StmtPtr body,
|
||||
int frame_offset, TypePtr ret_type);
|
||||
|
||||
bool IsPure() const override;
|
||||
|
||||
ListExprPtr Args() const { return args; }
|
||||
StmtPtr Body() const { return body; }
|
||||
|
||||
ValPtr Eval(Frame* f) const override;
|
||||
|
||||
ExprPtr Duplicate() override;
|
||||
|
||||
TraversalCode Traverse(TraversalCallback* cb) const override;
|
||||
|
||||
protected:
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
||||
IDPList* params;
|
||||
int frame_offset;
|
||||
ListExprPtr args;
|
||||
StmtPtr body;
|
||||
};
|
|
@ -1,13 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
// Private (protected) Stmt methods and member varibles associated
|
||||
// with script optimization. See script_opt/ExprOpt-public.h for
|
||||
// why these aren't factored into a separate class.
|
||||
//
|
||||
// Right now, this file is small, but it will grow as we expand into
|
||||
// other forms of script optimization.
|
||||
|
||||
// The original statement from which this statement was
|
||||
// derived, if any. Used as an aid for generating meaningful
|
||||
// and correctly-localized error messages.
|
||||
StmtPtr original = nullptr;
|
|
@ -1,37 +0,0 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
// Stmt methods and member varibles associated with script optimization.
|
||||
// See script_opt/ExprOpt-public.h for why these aren't factored into a
|
||||
// separate class.
|
||||
|
||||
// Returns a duplicate of the statement.
|
||||
virtual StmtPtr Duplicate() = 0;
|
||||
|
||||
// Recursively traverses the AST to inline eligible function calls.
|
||||
virtual void Inline(Inliner* inl) { }
|
||||
|
||||
// Access to the original statement from which this one is derived,
|
||||
// or this one if we don't have an original. Returns a bare pointer
|
||||
// rather than a StmtPtr to emphasize that the access is read-only.
|
||||
const Stmt* Original() const
|
||||
{ return original ? original->Original() : this; }
|
||||
|
||||
// Designate the given Stmt node as the original for this one.
|
||||
void SetOriginal(StmtPtr _orig)
|
||||
{
|
||||
if ( ! original )
|
||||
original = std::move(_orig);
|
||||
}
|
||||
|
||||
// A convenience function for taking a newly-created Stmt,
|
||||
// making it point to us as the successor, and returning it.
|
||||
//
|
||||
// Takes a Stmt* rather than a StmtPtr to de-clutter the calling
|
||||
// code, which is always passing in "new XyzStmt(...)". This
|
||||
// call, as a convenient side effect, transforms that bare pointer
|
||||
// into a StmtPtr.
|
||||
virtual StmtPtr SetSucc(Stmt* succ)
|
||||
{
|
||||
succ->SetOriginal({NewRef{}, this});
|
||||
return {AdoptRef{}, succ};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue