Added functions for casting a dynval to aop_t_all_pointer().
authorJustin Seyster <jseyster@cs.sunysb.edu>
Mon, 7 Feb 2011 21:06:31 +0000 (16:06 -0500)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Mon, 7 Feb 2011 21:06:31 +0000 (16:06 -0500)
src/aop-type.c
src/aop.h

index 435fdc13e8a8a6558c4e0c87b30e5514b03c748c..c9d2194d91addf4301e67052b37c8b59e623bc02 100644 (file)
@@ -44,6 +44,7 @@
 #include <toplev.h>
 
 #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. */
 /**
  * \}
index efc68fdc2a809542625ad25a313857c5b978bcea..55ef3705da26b1dd2258344fafa6898b8ab71c74 100644 (file)
--- 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);