mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
support "any" coercions for "-O gen-C++"
This commit is contained in:
parent
7a96d2fa61
commit
47783cb9fd
3 changed files with 43 additions and 0 deletions
|
@ -126,6 +126,22 @@ string CPPCompile::GenExpr(const Expr* e, GenType gt, bool top_level)
|
||||||
GenTypeName(e->GetType()) + ")";
|
GenTypeName(e->GetType()) + ")";
|
||||||
return GenericValPtrToGT(gen, e->GetType(), gt);
|
return GenericValPtrToGT(gen, e->GetType(), gt);
|
||||||
|
|
||||||
|
case EXPR_TO_ANY_COERCE:
|
||||||
|
return GenExpr(e->GetOp1(), GEN_VAL_PTR);
|
||||||
|
|
||||||
|
case EXPR_FROM_ANY_COERCE:
|
||||||
|
gen = string("from_any__CPP(") +
|
||||||
|
GenExpr(e->GetOp1(), GEN_VAL_PTR) + ", " +
|
||||||
|
GenTypeName(e->GetType()) + ")";
|
||||||
|
return GenericValPtrToGT(gen, e->GetType(), gt);
|
||||||
|
|
||||||
|
case EXPR_FROM_ANY_VEC_COERCE:
|
||||||
|
gen = string("from_any_vec__CPP(") +
|
||||||
|
GenExpr(e->GetOp1(), GEN_VAL_PTR) + ", " +
|
||||||
|
GenTypeName(e->GetType()->Yield()) + ")";
|
||||||
|
return GenericValPtrToGT(gen, e->GetType(), gt);
|
||||||
|
|
||||||
|
|
||||||
case EXPR_FIELD_ASSIGN:
|
case EXPR_FIELD_ASSIGN:
|
||||||
case EXPR_INDEX_SLICE_ASSIGN:
|
case EXPR_INDEX_SLICE_ASSIGN:
|
||||||
case EXPR_INLINE:
|
case EXPR_INLINE:
|
||||||
|
|
|
@ -75,6 +75,25 @@ ValPtr cast_value_to_type__CPP(const ValPtr& v, const TypePtr& t)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValPtr from_any__CPP(const ValPtr& v, const TypePtr& t)
|
||||||
|
{
|
||||||
|
auto vt = v->GetType()->Tag();
|
||||||
|
|
||||||
|
if ( vt != t->Tag() && vt != TYPE_ERROR )
|
||||||
|
reporter->CPPRuntimeError("incompatible \"any\" type (%s vs. %s)",
|
||||||
|
type_name(vt), type_name(t->Tag()));
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
ValPtr from_any_vec__CPP(const ValPtr& v, const TypePtr& t)
|
||||||
|
{
|
||||||
|
if ( ! v->AsVectorVal()->Concretize(t) )
|
||||||
|
reporter->CPPRuntimeError("incompatible \"vector of any\" type");
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
SubNetValPtr addr_mask__CPP(const IPAddr& a, uint32_t mask)
|
SubNetValPtr addr_mask__CPP(const IPAddr& a, uint32_t mask)
|
||||||
{
|
{
|
||||||
if ( a.GetFamily() == IPv4 )
|
if ( a.GetFamily() == IPv4 )
|
||||||
|
|
|
@ -55,6 +55,14 @@ extern ValPtr set_event__CPP(IDPtr g, ValPtr v, EventHandlerPtr& gh);
|
||||||
// A separate function in order to package up the error handling.
|
// A separate function in order to package up the error handling.
|
||||||
extern ValPtr cast_value_to_type__CPP(const ValPtr& v, const TypePtr& t);
|
extern ValPtr cast_value_to_type__CPP(const ValPtr& v, const TypePtr& t);
|
||||||
|
|
||||||
|
// Convert a value of type "any" to the given concrete type. A separate
|
||||||
|
// function in order to package up the error handling.
|
||||||
|
extern ValPtr from_any__CPP(const ValPtr& v, const TypePtr& t);
|
||||||
|
|
||||||
|
// Convert a vector-of-any to a vector-of-t. A separate function in order
|
||||||
|
// to package up the error handling.
|
||||||
|
extern ValPtr from_any_vec__CPP(const ValPtr& v, const TypePtr& t);
|
||||||
|
|
||||||
// Returns the subnet corresponding to the given mask of the given address.
|
// Returns the subnet corresponding to the given mask of the given address.
|
||||||
// A separate function in order to package up the error handling.
|
// A separate function in order to package up the error handling.
|
||||||
extern SubNetValPtr addr_mask__CPP(const IPAddr& a, uint32_t mask);
|
extern SubNetValPtr addr_mask__CPP(const IPAddr& a, uint32_t mask);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue