134 lines
2.9 KiB
C
134 lines
2.9 KiB
C
|
|
/**
|
||
|
|
* @file visitor.h
|
||
|
|
* @brief Visitor base class for mnemonic traversal (Visitor pattern).
|
||
|
|
*/
|
||
|
|
|
||
|
|
#ifndef VISITOR_H
|
||
|
|
#define VISITOR_H
|
||
|
|
|
||
|
|
#include "mne.h"
|
||
|
|
|
||
|
|
/* Forward declarations for concrete mnemonic classes. */
|
||
|
|
typedef struct _print_t print_t;
|
||
|
|
typedef struct _add_t add_t;
|
||
|
|
typedef struct _sub_t sub_t;
|
||
|
|
typedef struct _mul_t mul_t;
|
||
|
|
typedef struct _division_t division_t;
|
||
|
|
typedef struct _push_t push_t;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Forward declaration of base class Visitor.
|
||
|
|
*
|
||
|
|
*/
|
||
|
|
typedef struct _visitor_t visitor_t;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Virtual method table for Visitor.
|
||
|
|
*
|
||
|
|
*/
|
||
|
|
typedef struct {
|
||
|
|
/**
|
||
|
|
* @brief Base class (Mne) virtual method table.
|
||
|
|
*/
|
||
|
|
mne_vtable_t super;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visit a Print mnemonic.
|
||
|
|
*/
|
||
|
|
void (*visit_print_fn)(visitor_t *const, const print_t *const);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visit an Add mnemonic.
|
||
|
|
*/
|
||
|
|
void (*visit_add_fn)(visitor_t *const, const add_t *const);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visit a Sub mnemonic.
|
||
|
|
*/
|
||
|
|
void (*visit_sub_fn)(visitor_t *const, const sub_t *const);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visit a Mul mnemonic.
|
||
|
|
*/
|
||
|
|
void (*visit_mul_fn)(visitor_t *const, const mul_t *const);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visit a Division mnemonic.
|
||
|
|
*/
|
||
|
|
void (*visit_div_fn)(visitor_t *const, const division_t *const);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visit a Push mnemonic.
|
||
|
|
*/
|
||
|
|
void (*visit_push_fn)(visitor_t *const, const push_t *const);
|
||
|
|
} visitor_vtable_t;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Constructs a visitor with default behavior (empty visit methods).
|
||
|
|
*
|
||
|
|
* @return A newly allocated visitor.
|
||
|
|
*/
|
||
|
|
visitor_t* visitor_build_default(void);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Polymorphic destructor: calls the destroy method via vtable.
|
||
|
|
*
|
||
|
|
* @param self The visitor (can be NULL).
|
||
|
|
*/
|
||
|
|
void visitor_destroy(visitor_t *self);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visits a Print mnemonic.
|
||
|
|
*
|
||
|
|
* @param self The visitor.
|
||
|
|
* @param mne The Print mnemonic.
|
||
|
|
* @pre self != NULL && mne != NULL.
|
||
|
|
*/
|
||
|
|
void visitor_visit_print(visitor_t *const self, const print_t *const mne);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visits an Add mnemonic.
|
||
|
|
*
|
||
|
|
* @param self The visitor.
|
||
|
|
* @param mne The Add mnemonic.
|
||
|
|
* @pre self != NULL && mne != NULL.
|
||
|
|
*/
|
||
|
|
void visitor_visit_add(visitor_t *const self, const add_t *const mne);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visits a Sub mnemonic.
|
||
|
|
*
|
||
|
|
* @param self The visitor.
|
||
|
|
* @param mne The Sub mnemonic.
|
||
|
|
* @pre self != NULL && mne != NULL.
|
||
|
|
*/
|
||
|
|
void visitor_visit_sub(visitor_t *const self, const sub_t *const mne);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visits a Mul mnemonic.
|
||
|
|
*
|
||
|
|
* @param self The visitor.
|
||
|
|
* @param mne The Mul mnemonic.
|
||
|
|
* @pre self != NULL && mne != NULL.
|
||
|
|
*/
|
||
|
|
void visitor_visit_mul(visitor_t *const self, const mul_t *const mne);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visits a Division mnemonic.
|
||
|
|
*
|
||
|
|
* @param self The visitor.
|
||
|
|
* @param mne The Division mnemonic.
|
||
|
|
* @pre self != NULL && mne != NULL.
|
||
|
|
*/
|
||
|
|
void visitor_visit_div(visitor_t *const self, const division_t *const mne);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Visits a Push mnemonic.
|
||
|
|
*
|
||
|
|
* @param self The visitor.
|
||
|
|
* @param mne The Push mnemonic.
|
||
|
|
* @pre self != NULL && mne != NULL.
|
||
|
|
*/
|
||
|
|
void visitor_visit_push(visitor_t *const self, const push_t *const mne);
|
||
|
|
|
||
|
|
#endif /* VISITOR_H */
|