-------------------------------------------------------------- select a loop control variable, which is restricted to integers * only * * JYTODO: make pointers control variables? ************************************************************/
| 1131 | * JYTODO: make pointers control variables? |
| 1132 | ************************************************************/ |
| 1133 | Variable * |
| 1134 | VariableSelector::SelectLoopCtrlVar(const CGContext &cg_context, const vector<const Variable*>& invalid_vars) |
| 1135 | { |
| 1136 | // Note that many of the functions that select `var' can return null, if |
| 1137 | const Type* type = get_int_type(); |
| 1138 | vector<Variable*> vars; |
| 1139 | find_all_non_array_visible_vars(cg_context.get_current_block(), vars); |
| 1140 | // remove union variables that have both integer field(s) and pointer field(s) |
| 1141 | // because incrementing the integer field causes the pointer to be invalid, and the current |
| 1142 | // points-to analysis simply assumes loop stepping has no pointer effect |
| 1143 | size_t len = vars.size(); |
| 1144 | for (size_t i=0; i<len; i++) { |
| 1145 | if (vars[i]->type && |
| 1146 | (!vars[i]->type->has_int_field() || // remove variables isn't (or doesn't contain) integers |
| 1147 | (vars[i]->type->eType == eUnion && |
| 1148 | vars[i]->type->contain_pointer_field()))) { |
| 1149 | vars.erase(vars.begin() + i); |
| 1150 | i--; |
| 1151 | len--; |
| 1152 | } |
| 1153 | } |
| 1154 | Variable* var = choose_var(vars, Effect::WRITE, cg_context, type, 0, eConvert, invalid_vars, true); |
| 1155 | ERROR_GUARD(NULL); |
| 1156 | if (var == NULL) { |
| 1157 | if (CGOptions::global_variables()) { |
| 1158 | var = GenerateNewGlobal(Effect::WRITE, cg_context, type, 0); |
| 1159 | } |
| 1160 | else { |
| 1161 | var = GenerateNewParentLocal(*cg_context.get_current_block(), |
| 1162 | Effect::WRITE, cg_context, type, 0); |
| 1163 | } |
| 1164 | } |
| 1165 | return var; |
| 1166 | } |
| 1167 | |
| 1168 | // -------------------------------------------------------------- |
| 1169 | // Select or Create a new variable visible to this scope (new var may be |
nothing calls this directly
no test coverage detected