📄 gbc_output.c
字号:
PRIVATE void output_method(void){ int i, n; FUNCTION *func; /*SYMBOL *sym;*/ n = ARRAY_count(Class->function); begin_section("Methods", 8 * sizeof(long)); for (i = 0; i < n; i++) { func = &Class->function[i]; /* type */ write_type((func->type)); /* n_param */ write_short(func->nparam); /* n_param_min */ write_short(func->npmin); /* n_local */ write_short(func->nlocal); /* n_ctrl */ write_short(func->nctrl); /* stack_usage */ write_short(func->stack); /* gestion d'erreur */ if (func->catch && func->finally) write_short(Min(func->finally, func->catch)); else if (func->catch) write_short(func->catch); else write_short(func->finally); /* addr_code */ write_long(ARRAY_count(func->code)); /* desc_param */ write_long(0); /* desc_local */ write_long(0); /* debug_info */ write_long(0); } end_section();}PRIVATE void output_param_local(void){ int i, j; FUNCTION *func; EVENT *event; PARAM *param; begin_section("Parameters", sizeof(long)); for (i = 0; i < ARRAY_count(Class->function); i++) { func = &Class->function[i]; if (func->name != NO_SYMBOL) { /* Les param�res sont remis dans les variables locales ! for (j = 0; j < func->nparam; j++) { param = &func->param[j]; write_long(param->type); } */ for (j = 0; j < func->nlocal + func->nparam; j++) { param = &func->local[j]; /* type */ write_type((param->type)); } } } for (i = 0; i < ARRAY_count(Class->event); i++) { event = &Class->event[i]; for (j = 0; j < event->nparam; j++) { param = &event->param[j]; /* type */ write_type((param->type)); } } end_section();}PRIVATE void output_array(void){ long i, j, p; CLASS_ARRAY *array; begin_section("Arrays", sizeof(long)); p = ARRAY_count(Class->array) * sizeof(long); for (i = 0; i < ARRAY_count(Class->array); i++) { array = &Class->array[i]; write_long(p); p += sizeof(long) + array->ndim * sizeof(long); } for (i = 0; i < ARRAY_count(Class->array); i++) { array = &Class->array[i]; write_type((array->type)); for (j = 0; j < array->ndim; j++) { p = array->dim[j]; if (j == (array->ndim - 1)) p = (-p); write_long(p); } } end_section();}PRIVATE void output_code(){ int i, j; long n; FUNCTION *func; for (i = 0; i < ARRAY_count(Class->function); i++) { func = &Class->function[i]; n = ARRAY_count(func->code); begin_section("Code", sizeof(short)); if (_swap) { for (j = 0; j < n; j++) write_short(func->code[j]); } else write_buffer(func->code, n * sizeof(short)); end_section(); }}PRIVATE void output_debug_global(){ int i, nn = 0; CLASS_SYMBOL *csym; TYPE type; begin_section("Global symbol table", 4 * sizeof(long)); for (i = 0; i < TABLE_count(Class->table); i++) { csym = (CLASS_SYMBOL *)TABLE_get_symbol(Class->table, i); csym = (CLASS_SYMBOL *)TABLE_get_symbol(Class->table, csym->symbol.sort); type = csym->global.type; switch (TYPE_get_kind(type)) { case TK_VARIABLE: case TK_FUNCTION: case TK_PROPERTY: case TK_EXTERN: case TK_CONST: nn++; /* sort */ write_short((short)nn); /* len */ write_short(csym->symbol.len); /* name */ write_long(get_string(csym->symbol.name, csym->symbol.len)); /* type */ write_type((csym->global.type)); /* value */ write_long(csym->global.value); break; default: /* ignore */ break; } } end_section();}PRIVATE void output_debug_method(){ int i, j, n; SYMBOL *sym; OUTPUT_SYMBOL *osym; CLASS_SYMBOL *csym; PARAM *param; FUNCTION *func; TABLE *table; begin_section("Debug method info", 5 * sizeof(long)); for (i = 0; i < ARRAY_count(Class->function); i++) { func = &Class->function[i]; if (func->pos_line != NULL) { /* line */ write_short(func->line); write_short(ARRAY_count(func->pos_line)); /* pos_line */ write_long(0); /* nom */ sym = TABLE_get_symbol(Class->table, func->name); write_long(get_string(sym->name, sym->len)); /* local symbols */ write_long(0); /* n_local */ write_short(0); /* reserved */ write_short(0); } else { write_short(0); write_short(0); write_long(0); write_long(0); write_long(0); write_short(0); write_short(0); } } end_section(); for (i = 0; i < ARRAY_count(Class->function); i++) { func = &Class->function[i]; n = func->pos_line ? ARRAY_count(func->pos_line) : 0; begin_section("Debug method lines", sizeof(short)); if (_swap) { for (j = 0; j < n; j++) write_short(func->pos_line[j]); } else write_buffer(func->pos_line, n * sizeof(short)); end_section(); } for (i = 0; i < ARRAY_count(Class->function); i++) { func = &Class->function[i]; begin_section("Debug method local symbols", sizeof(long) * 3); if (func->name != NO_SYMBOL) { sym = (SYMBOL *)TABLE_get_symbol(Class->table, func->name); /*printf("%.*s()\n", sym->len, sym->name);*/ TABLE_create(&table, sizeof(OUTPUT_SYMBOL), TF_IGNORE_CASE); for (j = 0; j < func->nlocal + func->nparam; j++) { param = &func->local[j]; csym = (CLASS_SYMBOL *)TABLE_get_symbol(Class->table, param->index); TABLE_add_symbol(table, csym->symbol.name, csym->symbol.len, (SYMBOL **)&osym, NULL); osym->value = param->value;/*TYPE_long(param->type);*/ } for (j = 0; j < TABLE_count(table); j++) { param = &func->local[j]; osym = (OUTPUT_SYMBOL *)TABLE_get_symbol(table, j); /* sort */ write_short(osym->sym.sort); /* len */ write_short(osym->sym.len); /* name */ write_long(get_string(osym->sym.name, osym->sym.len)); /* value */ write_long(osym->value); /*printf("%.*s %ld\n", osym->sym.len, osym->sym.name, osym->value);*/ } TABLE_delete(&table); } end_section(); }}PRIVATE void output_debug_filename(void){ char path[MAX_PATH + 1]; long n; begin_section("Debug file name", 1); if (JOB->name[0] == '/') { strcpy(path, JOB->name); } else { getcwd(path, MAX_PATH); n = strlen(path); if (path[n - 1] != '/') strcpy(&path[n], "/"); strcat(&path[n], JOB->name); } n = strlen(path); write_buffer(path, n); /*write_pad();*/ end_section();}PRIVATE void output_string(void){ long i; SYMBOL *sym; begin_section("Strings", 1); for (i = 0; i < TABLE_count(StringTable); i++) { sym = TABLE_get_symbol(StringTable, i); write_string(sym->name, sym->len); } end_section();}PUBLIC const char *OUTPUT_get_file(const char *file){ const char *output; char *p; const char *dir; char *name; dir = STR_copy(FILE_get_dir(file)); name = STR_copy(FILE_get_name(file)); for (p = name; *p; p++) { if (*p == '.') { *p = 0; break; } *p = toupper(*p); } output = FILE_cat(dir, ".gambas", NULL); mkdir(output, 0777); output = STR_copy(FILE_cat(dir, ".gambas", name, NULL)); STR_free(dir); STR_free(name); return output;}PUBLIC const char *OUTPUT_get_trans_file(const char *file){ const char *output; const char *dir; const char *name; dir = STR_copy(FILE_get_dir(file)); name = STR_copy(FILE_get_name(file)); output = FILE_cat(dir, ".lang", NULL); mkdir(output, 0777); output = FILE_cat(dir, ".lang", name, NULL); output = STR_copy(FILE_set_ext(output, "pot")); STR_free(dir); STR_free(name); return output;}PRIVATE void output_translation(void){ FILE *file; int i, j, n; CONSTANT *constant; SYMBOL *sym; unsigned char c; /*printf("Generating %s\n", JOB->tname);*/ file = fopen(JOB->tname, "w"); if (!file) THROW("Cannot create file '&1'", JOB->tname); fprintf(file, "# %s\n# Generated by Gambas compiler\n\n", JOB->name); fprintf(file, "# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n" "#\n" "#, fuzzy\n" "msgid \"\"\n" "msgstr \"\"\n" "\"Project-Id-Version: PACKAGE VERSION\\n\"" "\"POT-Creation-Date: 2002-11-01 04:27+0100\\n\"\n" "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n" "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n" "\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n" "\"MIME-Version: 1.0\\n\"\n" "\"Content-Type: text/plain; charset=UTF-8\\n\"\n" "\"Content-Transfer-Encoding: 8bit\\n\"\n\n"); n = ARRAY_count(Class->constant); for (i = 0; i < n; i++) { constant = &Class->constant[i]; if (TYPE_get_id(constant->type) != T_CSTRING) continue; sym = TABLE_get_symbol(Class->string, constant->value); if (sym->len == 0) continue; fprintf(file, "#: %s:%ld\n", FILE_get_name(JOB->name), constant->line); fprintf(file, "msgid \""); for (j = 0; j < sym->len; j++) { c = sym->name[j]; if (c == '\n') fprintf(file, "\\n"); else if (c == '\t') fprintf(file, "\\t"); else if (c == '\r') fprintf(file, "\\r"); else if (c == '\\') fprintf(file, "\\\\"); else if (c == '"') fprintf(file, "\\\""); else fputc(c, file); } fprintf(file, "\"\n"); fprintf(file, "msgstr \"\"\n\n"); sym->len = 0; /* Immonde ruse pour ne pas �rire deux fois les m�es chaines */ } fclose(file);}PUBLIC void OUTPUT_do(bool swap){ const char *name; _swap = swap; output_init(); /* La premi�e cha�e est toujours le nom de la classe */ get_string(JOB->class->name, strlen(JOB->class->name)); name = JOB->output; #ifdef DEBUG printf("Output to %s\n", name); #endif File = fopen(name, "w"); if (!File) THROW("Cannot create file '&1'", name); Class = JOB->class; #ifdef DEBUG printf("pos = %lu\n", get_pos()); #endif output_header(); output_class(); output_desc(); output_constant(); output_class_ref(); output_unknown_ref(); output_static(); output_dynamic(); output_event(); output_method(); output_param_local(); output_array(); output_code(); if (JOB->debug) { output_debug_global(); output_debug_method(); output_debug_filename(); } output_string(); fclose(File); output_exit(); /* Internationalisation */ if (JOB->trans) output_translation();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -