| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifndef VMPAT_H |
| 23 |
#define VMPAT_H |
| 24 |
|
| 25 |
#include <stdlib.h> |
| 26 |
#include "os.h" |
| 27 |
#include "vmtype.h" |
| 28 |
#include "vmobj.h" |
| 29 |
#include "vmglob.h" |
| 30 |
#include "vmregex.h" |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
struct vmobj_pat_ext |
| 51 |
{ |
| 52 |
|
| 53 |
re_compiled_pattern *pat; |
| 54 |
|
| 55 |
|
| 56 |
vm_val_t str; |
| 57 |
}; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
class CVmObjPattern: public CVmObject |
| 64 |
{ |
| 65 |
friend class CVmMetaclassPattern; |
| 66 |
|
| 67 |
public: |
| 68 |
|
| 69 |
static class CVmMetaclass *metaclass_reg_; |
| 70 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 71 |
|
| 72 |
|
| 73 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 74 |
{ |
| 75 |
|
| 76 |
return (meta == metaclass_reg_ |
| 77 |
|| CVmObject::is_of_metaclass(meta)); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
static int is_pattern_obj(VMG_ vm_obj_id_t obj) |
| 82 |
{ return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); } |
| 83 |
|
| 84 |
|
| 85 |
static vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, |
| 86 |
uint argc); |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 93 |
const uchar **pc_ptr, uint *argc, |
| 94 |
vm_prop_id_t prop) |
| 95 |
{ |
| 96 |
|
| 97 |
return CVmObject::call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
void notify_delete(VMG_ int in_root_set); |
| 102 |
|
| 103 |
|
| 104 |
void set_prop(VMG_ class CVmUndo *undo, |
| 105 |
vm_obj_id_t self, vm_prop_id_t prop, const vm_val_t *val); |
| 106 |
|
| 107 |
|
| 108 |
int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *val, |
| 109 |
vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc); |
| 110 |
|
| 111 |
|
| 112 |
const char *cast_to_string(VMG_ vm_obj_id_t self, |
| 113 |
vm_val_t *new_str) const |
| 114 |
{ |
| 115 |
|
| 116 |
*new_str = *get_orig_str(); |
| 117 |
return new_str->get_as_string(vmg0_); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
void notify_new_savept() { } |
| 122 |
void apply_undo(VMG_ struct CVmUndoRecord *) { } |
| 123 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *) { } |
| 124 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 125 |
|
| 126 |
|
| 127 |
void mark_refs(VMG_ uint); |
| 128 |
|
| 129 |
|
| 130 |
void remove_stale_weak_refs(VMG0_) { } |
| 131 |
|
| 132 |
|
| 133 |
void load_from_image(VMG_ vm_obj_id_t, const char *ptr, size_t); |
| 134 |
|
| 135 |
|
| 136 |
void post_load_init(VMG_ vm_obj_id_t self); |
| 137 |
|
| 138 |
|
| 139 |
virtual ulong rebuild_image(VMG_ char *buf, ulong buflen); |
| 140 |
|
| 141 |
|
| 142 |
virtual void convert_to_const_data(VMG_ class CVmConstMapper *mapper, |
| 143 |
vm_obj_id_t self); |
| 144 |
|
| 145 |
|
| 146 |
void save_to_file(VMG_ class CVmFile *fp); |
| 147 |
|
| 148 |
|
| 149 |
void restore_from_file(VMG_ vm_obj_id_t self, |
| 150 |
class CVmFile *fp, class CVmObjFixup *fixup); |
| 151 |
|
| 152 |
|
| 153 |
re_compiled_pattern *get_pattern(VMG0_) { return get_ext()->pat; } |
| 154 |
|
| 155 |
|
| 156 |
const vm_val_t *get_orig_str() const { return &get_ext()->str; } |
| 157 |
|
| 158 |
protected: |
| 159 |
|
| 160 |
CVmObjPattern() { ext_ = 0; } |
| 161 |
|
| 162 |
|
| 163 |
CVmObjPattern(VMG_ re_compiled_pattern *pat, const vm_val_t *src_str); |
| 164 |
|
| 165 |
|
| 166 |
void set_pattern(re_compiled_pattern *pat) { get_ext()->pat = pat; } |
| 167 |
|
| 168 |
|
| 169 |
void set_orig_str(const vm_val_t *val) { get_ext()->str = *val; } |
| 170 |
|
| 171 |
|
| 172 |
vmobj_pat_ext *get_ext() const { return (vmobj_pat_ext *)ext_; } |
| 173 |
|
| 174 |
|
| 175 |
int getp_undef(VMG_ vm_obj_id_t, vm_val_t *, uint *) { return FALSE; } |
| 176 |
|
| 177 |
|
| 178 |
int getp_get_str(VMG_ vm_obj_id_t, vm_val_t *val, uint *argc); |
| 179 |
|
| 180 |
|
| 181 |
static int (CVmObjPattern::*func_table_[])(VMG_ vm_obj_id_t self, |
| 182 |
vm_val_t *retval, uint *argc); |
| 183 |
}; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
class CVmMetaclassPattern: public CVmMetaclass |
| 190 |
{ |
| 191 |
public: |
| 192 |
|
| 193 |
const char *get_meta_name() const { return "regex-pattern/030000"; } |
| 194 |
|
| 195 |
|
| 196 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 197 |
{ |
| 198 |
new (vmg_ id) CVmObjPattern(); |
| 199 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 204 |
{ |
| 205 |
new (vmg_ id) CVmObjPattern(); |
| 206 |
G_obj_table->set_obj_gc_characteristics(id, TRUE, FALSE); |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 211 |
{ return CVmObjPattern::create_from_stack(vmg_ pc_ptr, argc); } |
| 212 |
|
| 213 |
|
| 214 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 215 |
const uchar **pc_ptr, uint *argc, |
| 216 |
vm_prop_id_t prop) |
| 217 |
{ |
| 218 |
return CVmObjPattern::call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 219 |
} |
| 220 |
}; |
| 221 |
|
| 222 |
#endif |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
VM_REGISTER_METACLASS(CVmObjPattern) |
| 228 |
|