From 85768fd6afa970501038537b687a077765c71b46 Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Mon, 7 Feb 2011 16:06:31 -0500 Subject: [PATCH] Added functions for casting a dynval to aop_t_all_pointer(). --- src/aop-type.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/aop.h | 5 +++++ 2 files changed, 52 insertions(+) diff --git a/src/aop-type.c b/src/aop-type.c index 435fdc1..c9d2194 100644 --- a/src/aop-type.c +++ b/src/aop-type.c @@ -44,6 +44,7 @@ #include #include "aop.h" +#include "aop-dynval.h" #include "aop-type.h" static struct aop_type _aop_t_all_signed = { @@ -669,6 +670,52 @@ aop_t_pointer_to (const struct aop_type *type) return get_dedup_type (&pointer_type); } +/** + * Check if an #aop_type object matches a pointer type. This check is + * true if and only if the specified type matches a subset of types + * that aop_t_all_pointer() matches. + * \param type The type to check. + * \param Non-zero if the #aop_type object matches a pointer type, + * zero otherwise. + */ +int +aop_is_pointer_type (const struct aop_type *type) +{ + return (type->kind == ATK_ALL_POINTER || type->pointer_levels > 0); +} + +/** + * Modify an #aop_dynval object so that it will be passed to advice as + * if it were matched and captured using the aop_t_all_pointer() type. + * Casting is useful if you wish to capture values from pointcuts + * matched with different aop_type objects but pass those values to + * the same advice function. + * + * Only use this function on dynvals whose type passes + * aop_is_pointer_type(). Casting a non-pointer type with this + * function will raise a fatal compiler error. + * \param dv The #aop_dynval to cast. + */ +void +aop_cast_to_all_pointer (struct aop_dynval *dv) +{ + if (!aop_is_pointer_type (dv->type)) + fatal_error ("(InterAsepct) Illegal cast to all pointer type."); + + dv->type = aop_t_all_pointer (); +} + +/** + * Get the type for an #aop_dynval object. Every dynval has an + * associated type that is determined by how it was matched and + * captured. + * \return The type of the specified dynval. + */ +const struct aop_type *aop_get_dynval_type (struct aop_dynval *dv) +{ + return dv->type; +} + /* Close Doxygen defgroup block. */ /** * \} diff --git a/src/aop.h b/src/aop.h index efc68fd..55ef370 100644 --- a/src/aop.h +++ b/src/aop.h @@ -208,6 +208,11 @@ extern const struct aop_type *aop_t_union_ptr (const char *tag); extern const struct aop_type *aop_t_enum (const char *tag); extern const struct aop_type *aop_t_pointer_to (const struct aop_type *type); +extern int aop_is_pointer_type (const struct aop_type *type); +extern void aop_cast_to_all_pointer (struct aop_dynval *dv); + +extern const struct aop_type *aop_get_dynval_type (struct aop_dynval *dv); + extern void aop_register_pass (const char *pass_name, pass_callback callback); extern void aop_join_on (struct aop_pointcut *pc, join_callback callback, void *callback_param); -- 2.34.1