expression_ast unary_op::evaluate(filter_handler handler) const { factory::un_op_type impl = factory::get_unary_operator(op); value_type type = get_return_type(op, type_invalid); if (type_is_int(type)) { return impl->evaluate(handler, subject); } handler->error(_T("Missing operator implementation")); return expression_ast(int_value(FALSE)); }
value_type infer_binary_type(object_converter factory, node_type &left, node_type &right) { value_type rt = right->infer_type(factory); value_type lt = left->infer_type(factory); if (lt == type_multi || rt == type_multi) { if (lt == rt) return type_tbd; if (lt == type_multi) lt = left->infer_type(factory, rt); else rt = right->infer_type(factory, lt); } if (lt == rt) return lt; if (type_is_float(lt) && type_is_int(rt)) rt = right->infer_type(factory, lt); if (type_is_float(rt) && type_is_int(lt)) lt = left->infer_type(factory, rt); if (lt == rt) return lt; if (rt == type_invalid || lt == type_invalid) return type_invalid; if (rt == type_tbd && lt == type_tbd) return type_tbd; if (factory->can_convert(rt, lt)) { right = add_convert_node(right, lt); return lt; } if (factory->can_convert(lt, rt)) { left = add_convert_node(left, rt); return rt; } if (can_convert(rt, lt)) { right = add_convert_node(right, lt); return lt; } if (can_convert(lt, rt)) { left = add_convert_node(left, rt); return rt; } factory->error("Cannot compare " + left->to_string() + " to " + right->to_string() + " (" + type_to_string(lt) + " to " + type_to_string(rt) + ")"); return type_invalid; }
static void makecfg( FILE *ifp, FILE *ofp, FILE *ofp2) { char buffer[BUFSIZ]; MYDATA *p, *q; static const char *const table_1[] = { "/* This file is generated by MAKECFG */" ,"" ,"#ifndef TINCFG_H" ,"#define TINCFG_H 1" ,"" ,"/* Macros for defining symbolic offsets that can be ifdef'd */" ,"#undef OINX" ,"#undef OVAL" ,"#undef OEND" ,"#undef OTYP" ,"" ,"#ifdef lint" ,"#\tdefine OINX(T, M) 0 /* 'lint -c' cannot be appeased */" ,"#\tdefine OVAL(T, M) char M;" ,"#\tdefine OEND(T, M) char M;" ,"#\tdefine OTYP struct" ,"#else" ,"#\tifdef CPP_DOES_CONCAT" ,"#\t\tdefine OINX(T, M) T ## M" ,"#\t\tdefine OVAL(T, M) T ## M," ,"#\t\tdefine OEND(T, M) T ## M" ,"#\t\tdefine OTYP enum" ,"#\telse" ,"#\t\tdefine OINX(T, M) \\" ,"\t\t\t(((int)&(((T*)0)->M))/ \\" ,"\t\t\t ((int)&(((T*)0)->Q1) - (int)&(((T*)0)->s_MAX)))" ,"#\t\tdefine OVAL(T, M) char M;" ,"#\t\tdefine OEND(T, M) char M;" ,"#\t\tdefine OTYP struct" ,"#\tendif /* CPP_DOES_CONCAT */" ,"#endif /* lint */" ,0 }; static const char *const table_2[] = { "" ,"/* We needed these only to make the table compile */" ,"#undef OINX" ,"#undef OVAL" ,"#undef OEND" ,"#undef OTYP" ,"" ,"#endif /* TINCFG_H */" ,0 }; static const char *const table_3[] = { "/* This file is generated by MAKECFG */", "", "#ifndef OPTIONS_MENU_H", "#define OPTIONS_MENU_H 1", "", 0 }; static const char *const table_4[] = { "", "#endif /* OPTIONS_MENU_H */", 0 }; /* * Process the input file. */ line_no = 0; while (fgets(buffer, sizeof(buffer) - 1, ifp)) parse_tbl(buffer); fclose(ifp); /* * Generate the output file */ write_it(ofp, table_1); /* * For each type used in the table, generate a list of pointers to * that type. */ for (p = all_data; p != 0; p = p->link) { int found = FALSE; if (p->name[0] == '#') continue; if (type_is_int(p) || is_title(p)) continue; for (q = all_data; p != q; q = q->link) { if (!strcmp(p->type, q->type)) { found = TRUE; break; } } if (!found && !strncmp(p->type, "OPT_", 4)) { generate_ptr (ofp, p->type, typename_of(p), 0); generate_ptr (ofp, p->type, typename_of(p), 1); generate_ptr (ofp, p->type, typename_of(p), 2); } } generate_tbl(ofp); write_it(ofp, table_2); fclose(ofp); if (ofp2) { write_it(ofp2, table_3); generate_enum(ofp2); write_it(ofp2, table_4); fclose(ofp2); } }
static void generate_tbl( FILE *ofp) { static const char *const table_1[] = { "" ,"#define OPT_TITLE 0" ,"#define OPT_ON_OFF 1" ,"#define OPT_LIST 2" ,"#define OPT_STRING 3" ,"#define OPT_NUM 4" ,"#define OPT_CHAR 5" ,"" ,"struct t_option option_table[]={" ,0 }; static const char *const table_2[] = { "};" ,0 }; static const char prefix[] = " { "; static const char suffix[] = "},"; MYDATA *p; char temp[BUFSIZ]; /* generate the access table */ write_it(ofp, table_1); for (p = all_data; p != 0; p = p->link) { if (p->name[0] == '#') fprintf(ofp, "%s\n", p->name); else { int is_opt = !strncmp(p->type, "OPT_", 4); int is_int = type_is_int(p); char *dft_name = p->name; /* TODO: is this still necessary? */ /* shorten message-variable names */ if (!strncmp(dft_name, "default_", 8)) dft_name += 8; else if (!strncmp(dft_name, "attrib_", 7)) dft_name += 7; fprintf(ofp, "%s", prefix); sprintf(temp, "%s,", is_opt ? p->type : "OPT_LIST"); fprintf(ofp, "%-13s", temp); if (is_title(p)) { fprintf(ofp, "0, NULL, "); } else if (!is_int) { fprintf(ofp, "OINX_%s, 0, ", p->name); } else { fprintf(ofp, "0, &tinrc.%s, ", p->name); } if (is_opt) fprintf(ofp, "NULL, "); else fprintf(ofp, "%s, ", p->type); fprintf(ofp, "&txt_%s ", dft_name); fprintf(ofp, "%s\n", suffix); } } write_it(ofp, table_2); }