[COMPILER]

* BUG: Optional exported classes are now correctly inserted into '*.list' files.


git-svn-id: svn://localhost/gambas/trunk@7535 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2015-12-22 20:41:18 +00:00
parent bf3b070c70
commit f63e8caf6b

View file

@ -54,7 +54,7 @@ static const char *get_name(int index)
static void get_string(int index, const char **str, int *len) static void get_string(int index, const char **str, int *len)
{ {
SYMBOL *sym; SYMBOL *sym;
if (index == VOID_STRING) if (index == VOID_STRING)
{ {
*str = ""; *str = "";
@ -71,7 +71,7 @@ static void get_string(int index, const char **str, int *len)
static void print_quoted(FILE *file, const char *str, int len) static void print_quoted(FILE *file, const char *str, int len)
{ {
unsigned char c; unsigned char c;
fputc('"', file); fputc('"', file);
while (len--) while (len--)
{ {
@ -140,7 +140,7 @@ static void dump_function(FUNCTION *func)
int i; int i;
//printf("<%lld> ", func->byref); //printf("<%lld> ", func->byref);
printf("("); printf("(");
for (i = 0; i < func->nparam; i++) for (i = 0; i < func->nparam; i++)
@ -149,7 +149,7 @@ static void dump_function(FUNCTION *func)
if (i >= func->npmin) if (i >= func->npmin)
printf("Optional "); printf("Optional ");
if (func->byref & (1LL << i)) if (func->byref & (1LL << i))
printf("ByRef "); printf("ByRef ");
@ -359,7 +359,7 @@ static void close_file_and_rename(FILE *f, const char *file, const char *dest)
if (f) if (f)
{ {
fclose(f); fclose(f);
FILE_unlink(dest); FILE_unlink(dest);
FILE_rename(file, dest); FILE_rename(file, dest);
FILE_set_owner(dest, COMP_project); FILE_set_owner(dest, COMP_project);
} }
@ -383,19 +383,19 @@ static void read_line(char **line, int *len)
int l; int l;
char c; char c;
int lmax; int lmax;
*line = NULL; *line = NULL;
*len = 0; *len = 0;
if (!_buffer) if (!_buffer)
return; return;
lmax = BUFFER_length(_buffer); lmax = BUFFER_length(_buffer);
if (_buffer_ptr >= lmax) if (_buffer_ptr >= lmax)
return; return;
*line = &_buffer[_buffer_ptr]; *line = &_buffer[_buffer_ptr];
l = 0; l = 0;
for(;;) for(;;)
{ {
@ -409,7 +409,7 @@ static void read_line(char **line, int *len)
} }
l++; l++;
} }
*len = l; *len = l;
} }
@ -435,13 +435,13 @@ static void class_update_exported(CLASS *class)
bool optional; bool optional;
bool has_static; bool has_static;
int cmp; int cmp;
if (load_file(".list") && !class->exported) if (load_file(".list") && !class->exported)
return; return;
//if (!fr && !class->exported) //if (!fr && !class->exported)
// return; // return;
for(;;) for(;;)
{ {
read_line(&name, &len); read_line(&name, &len);
@ -456,15 +456,17 @@ static void class_update_exported(CLASS *class)
{ {
optional = TRUE; optional = TRUE;
name[len - 1] = 0; name[len - 1] = 0;
len--;
} }
if (name[len - 1] == '!') if (name[len - 1] == '!')
{ {
has_static = TRUE; has_static = TRUE;
name[len - 1] = 0; name[len - 1] = 0;
len--;
} }
cmp = strcmp(name, class->name); cmp = strcmp(name, class->name);
} }
if (cmp == 0) if (cmp == 0)
{ {
if (JOB->verbose) if (JOB->verbose)
@ -484,16 +486,16 @@ static void class_update_exported(CLASS *class)
fputc('\n', fw); fputc('\n', fw);
inserted = TRUE; inserted = TRUE;
} }
if (!name) if (!name)
break; break;
if (exist_bytecode_file(name)) if (exist_bytecode_file(name))
{ {
if (JOB->verbose) if (JOB->verbose)
printf("Copy '%s' in .list file\n", name); printf("Copy '%s' in .list file\n", name);
create_file(&fw, ".list#"); create_file(&fw, ".list#");
fputs(name, fw); fputs(name, fw);
if (has_static && COMPILE_version >= 0x03060090) if (has_static && COMPILE_version >= 0x03060090)
fputc('!', fw); fputc('!', fw);
@ -507,10 +509,10 @@ static void class_update_exported(CLASS *class)
printf("Remove '%s' from .list file\n", name); printf("Remove '%s' from .list file\n", name);
} }
} }
if (_buffer) if (_buffer)
BUFFER_delete(&_buffer); BUFFER_delete(&_buffer);
close_file_and_rename(fw, ".list#", ".list"); close_file_and_rename(fw, ".list#", ".list");
} }
@ -528,10 +530,10 @@ static void insert_class_info(CLASS *class, FILE *fw)
int line; int line;
const char *str; const char *str;
int len; int len;
if (JOB->verbose) if (JOB->verbose)
printf("Insert '%s' information into .info file\n", class->name); printf("Insert '%s' information into .info file\n", class->name);
_finfo = fw; _finfo = fw;
fprintf(_finfo, "#%s\n", class->name); fprintf(_finfo, "#%s\n", class->name);
@ -549,7 +551,7 @@ static void insert_class_info(CLASS *class, FILE *fw)
export_newline(); export_newline();
HELP_search_and_print_for_class(_finfo); HELP_search_and_print_for_class(_finfo);
for (i = 0; i < TABLE_count(class->table); i++) for (i = 0; i < TABLE_count(class->table); i++)
{ {
sym = CLASS_get_symbol(class, i); sym = CLASS_get_symbol(class, i);
@ -639,12 +641,12 @@ static void insert_class_info(CLASS *class, FILE *fw)
case T_LONG: case T_LONG:
fprintf(_finfo, "%" PRId64 "\n", cst->lvalue); fprintf(_finfo, "%" PRId64 "\n", cst->lvalue);
break; break;
case T_SINGLE: case T_SINGLE:
case T_FLOAT: case T_FLOAT:
fprintf(_finfo, "%s\n", get_name(cst->value)); fprintf(_finfo, "%s\n", get_name(cst->value));
break; break;
case T_STRING: case T_STRING:
get_string(cst->value, &str, &len); get_string(cst->value, &str, &len);
print_quoted(_finfo, str, len); print_quoted(_finfo, str, len);
@ -676,7 +678,7 @@ static void insert_class_info(CLASS *class, FILE *fw)
default: default:
export_newline(); export_newline();
} }
HELP_search_and_print(_finfo, line); HELP_search_and_print(_finfo, line);
} }
} }
@ -721,15 +723,15 @@ static void output_help(void)
int i; int i;
JOB->hname = OUTPUT_get_help_file(JOB->name); JOB->hname = OUTPUT_get_help_file(JOB->name);
if (!JOB->help) if (!JOB->help)
{ {
FILE_unlink(JOB->hname); FILE_unlink(JOB->hname);
return; return;
} }
file = fopen(JOB->hname, "w"); file = fopen(JOB->hname, "w");
if (!file) if (!file)
THROW("Cannot create file: &1", JOB->hname); THROW("Cannot create file: &1", JOB->hname);
@ -737,10 +739,10 @@ static void output_help(void)
{ {
if (!JOB->help[i]) if (!JOB->help[i])
continue; continue;
fprintf(stderr, "[%d] = %.*s\n", i + JOB->help_first_line, get_help_comment_length(JOB->help[i]), JOB->help[i]); fprintf(stderr, "[%d] = %.*s\n", i + JOB->help_first_line, get_help_comment_length(JOB->help[i]), JOB->help[i]);
} }
fclose(file); fclose(file);
FILE_set_owner(JOB->hname, COMP_project); FILE_set_owner(JOB->hname, COMP_project);
} }
@ -762,11 +764,11 @@ void CLASS_export(void)
msg = "Cannot change directory"; msg = "Cannot change directory";
goto __ERROR; goto __ERROR;
} }
class_update_exported(class); class_update_exported(class);
load_file(".info"); load_file(".info");
read_line(&line, &len); read_line(&line, &len);
for(;;) for(;;)
@ -780,29 +782,29 @@ void CLASS_export(void)
{ {
if (JOB->verbose) if (JOB->verbose)
printf("Remove '%s' information from .info file\n", class->name); printf("Remove '%s' information from .info file\n", class->name);
for(;;) for(;;)
{ {
read_line(&line, &len); read_line(&line, &len);
if (!line || *line == '#') if (!line || *line == '#')
break; break;
} }
continue; continue;
} }
if (cmp > 0 && class->exported && !inserted) if (cmp > 0 && class->exported && !inserted)
{ {
create_file(&fw, ".info#"); create_file(&fw, ".info#");
insert_class_info(class, fw); insert_class_info(class, fw);
inserted = TRUE; inserted = TRUE;
} }
if (!line) if (!line)
break; break;
// copying class information // copying class information
if (exist_bytecode_file(&line[1])) if (exist_bytecode_file(&line[1]))
{ {
if (JOB->verbose) if (JOB->verbose)
@ -829,13 +831,13 @@ void CLASS_export(void)
} }
} }
} }
if (_buffer) if (_buffer)
BUFFER_delete(&_buffer); BUFFER_delete(&_buffer);
close_file_and_rename(fw, ".info#", ".info"); close_file_and_rename(fw, ".info#", ".info");
return; return;
__ERROR: __ERROR:
THROW("Cannot create class information: &1: &2", msg, strerror(errno)); THROW("Cannot create class information: &1: &2", msg, strerror(errno));