-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathqb_op_factory_result_linkage.c
135 lines (121 loc) · 6.35 KB
/
qb_op_factory_result_linkage.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2012 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Chung Leong <cleong@cal.berkeley.edu> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
static int32_t qb_link_results_real_or_complex(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_result_prototype *result_prototype) {
f = qb_select_complex_op_factory(f, flags);
return (f->link_results) ? f->link_results(cxt, f, flags, operands, operand_count, result_prototype) : TRUE;
}
static int32_t qb_link_results_multiply(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_result_prototype *result_prototype) {
f = qb_select_multiply_factory(f, flags);
return (f->link_results) ? f->link_results(cxt, f, flags, operands, operand_count, result_prototype) : TRUE;
}
// link all operands to the result generated by the op
static int32_t qb_link_results_all_operands(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_result_prototype *result_prototype) {
uint32_t i;
for(i = 0; i < operand_count; i++) {
qb_operand *value = &operands[i];
if(value->type == QB_OPERAND_RESULT_PROTOTYPE) {
value->result_prototype->parent = result_prototype;
}
}
return TRUE;
}
// link the value to the variable
static int32_t qb_link_results_variable(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_result_prototype *result_prototype) {
qb_operand *variable = &operands[0];
qb_operand *value = &operands[1];
if(value->type == QB_OPERAND_RESULT_PROTOTYPE) {
// indicate that the destination is the r-value
qb_result_destination *destination = qb_allocate_result_destination(cxt->pool);
destination->type = QB_RESULT_DESTINATION_VARIABLE;
destination->variable = *variable;
destination->prototype = result_prototype;
value->result_prototype->destination = destination;
}
if(variable->type == QB_OPERAND_EMPTY) {
// the variable doesn't really need to be there--try to bypass the assignment
result_prototype->address_flags |= QB_ADDRESS_TEMPORARY;
} else if(variable->type == QB_OPERAND_RESULT_PROTOTYPE) {
if(variable->result_prototype->address_flags & QB_ADDRESS_TEMPORARY) {
result_prototype->address_flags |= QB_ADDRESS_TEMPORARY;
}
}
return TRUE;
}
// link the value to the array element
static int32_t qb_link_results_array_element(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_result_prototype *result_prototype) {
qb_operand *container = &operands[0];
qb_operand *index = &operands[1];
qb_operand *value = &operands[2];
if(value->type == QB_OPERAND_RESULT_PROTOTYPE) {
qb_result_destination *destination = qb_allocate_result_destination(cxt->pool);
destination->type = QB_RESULT_DESTINATION_ELEMENT;
destination->element.container = *container;
destination->element.index = *index;
destination->prototype = result_prototype;
value->result_prototype->destination = destination;
}
return TRUE;
}
// link the value to the object property
static int32_t qb_link_results_assign_return_value(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_result_prototype *result_prototype) {
qb_operand *value = &operands[0];
if(value->type == QB_OPERAND_RESULT_PROTOTYPE) {
qb_result_destination *destination = qb_allocate_result_destination(cxt->pool);
destination->type = QB_RESULT_DESTINATION_RETURN;
destination->prototype = result_prototype;
value->result_prototype->destination = destination;
}
return TRUE;
}
// link the value to the print operator
static int32_t qb_link_results_print(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_result_prototype *result_prototype) {
qb_operand *value = &operands[0];
if(value->type == QB_OPERAND_RESULT_PROTOTYPE) {
qb_result_destination *destination = qb_allocate_result_destination(cxt->pool);
destination->type = QB_RESULT_DESTINATION_PRINT;
destination->prototype = result_prototype;
value->result_prototype->destination = destination;
}
return TRUE;
}
// link the value to the object property
static int32_t qb_link_results_free(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_result_prototype *result_prototype) {
qb_operand *value = &operands[0];
if(value->type == QB_OPERAND_RESULT_PROTOTYPE) {
qb_result_destination *destination = qb_allocate_result_destination(cxt->pool);
destination->type = QB_RESULT_DESTINATION_FREE;
destination->prototype = result_prototype;
value->result_prototype->destination = destination;
}
return TRUE;
}
static int32_t qb_link_results_array_init(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_result_prototype *result_prototype) {
qb_operand *value = &operands[0];
if(value->type == QB_OPERAND_RESULT_PROTOTYPE) {
value->result_prototype->parent = result_prototype;
}
return TRUE;
}
static int32_t qb_link_results_array_append(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_result_prototype *result_prototype) {
qb_operand *value = &operands[0];
if(value->type == QB_OPERAND_RESULT_PROTOTYPE) {
value->result_prototype->parent = result_prototype;
}
return TRUE;
}