2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
gbc_dump.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2018-02-12 02:53:46 +01:00
|
|
|
(c) 2000-2017 Benoît Minisini <g4mba5@gmail.com>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __GBC_DUMP_C
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
2008-09-22 01:22:07 +02:00
|
|
|
#include "gb_common_buffer.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gb_error.h"
|
|
|
|
|
|
|
|
#include "gb_table.h"
|
2011-09-28 23:10:18 +02:00
|
|
|
#include "gb_str.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gbc_compile.h"
|
|
|
|
#include "gb_code.h"
|
|
|
|
#include "gb_file.h"
|
2008-05-11 20:07:16 +02:00
|
|
|
#include "gbc_chown.h"
|
2012-11-10 01:19:53 +01:00
|
|
|
#include "gbc_help.h"
|
2011-09-28 23:10:18 +02:00
|
|
|
#include "gbc_output.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
static FILE *_finfo;
|
2013-05-04 04:54:35 +02:00
|
|
|
static char *_buffer = NULL;
|
|
|
|
static int _buffer_ptr = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static const char *get_name(int index)
|
|
|
|
{
|
2015-06-19 09:10:05 +02:00
|
|
|
return TABLE_get_symbol_name(JOB->class->table, index);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
static void get_string(int index, const char **str, int *len)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2015-06-19 10:19:54 +02:00
|
|
|
SYMBOL *sym;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2018-08-31 15:58:53 +02:00
|
|
|
if (index == VOID_STRING_INDEX)
|
2015-06-19 10:19:54 +02:00
|
|
|
{
|
|
|
|
*str = "";
|
|
|
|
*len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sym = TABLE_get_symbol(JOB->class->string, index);
|
|
|
|
*str = sym->name;
|
|
|
|
*len = sym->len;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
static void print_quoted(FILE *file, const char *str, int len)
|
2013-06-19 04:01:08 +02:00
|
|
|
{
|
|
|
|
unsigned char c;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2015-05-21 17:39:20 +02:00
|
|
|
fputc('"', file);
|
2015-06-19 09:10:05 +02:00
|
|
|
while (len--)
|
2013-06-19 04:01:08 +02:00
|
|
|
{
|
|
|
|
c = *str++;
|
|
|
|
if (c == '\n')
|
|
|
|
fputs("\\n", file);
|
|
|
|
else if (c == '\t')
|
|
|
|
fputs("\\t", file);
|
2015-06-19 09:10:05 +02:00
|
|
|
else if (c == 0)
|
|
|
|
fputs("\\0", file);
|
2015-05-21 17:39:20 +02:00
|
|
|
else if (c == '"')
|
|
|
|
fputs("\\\"", file);
|
2013-06-19 04:01:08 +02:00
|
|
|
else
|
|
|
|
fputc(c, file);
|
|
|
|
}
|
2015-05-21 17:39:20 +02:00
|
|
|
fputc('"', file);
|
2013-06-19 04:01:08 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static void dump_name(int index)
|
|
|
|
{
|
2015-06-19 09:10:05 +02:00
|
|
|
printf("%s", get_name(index));
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
static void dump_type(TYPE type, bool as)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2015-06-19 09:10:05 +02:00
|
|
|
int value;
|
|
|
|
TYPE_ID id;
|
|
|
|
CLASS_ARRAY *array;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
id = TYPE_get_id(type);
|
|
|
|
value = TYPE_get_value(type);
|
|
|
|
|
|
|
|
if (id == T_ARRAY)
|
|
|
|
{
|
|
|
|
array = &JOB->class->array[value];
|
|
|
|
|
|
|
|
printf("[");
|
|
|
|
for (i = 0; i < array->ndim; i++)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
printf(",");
|
|
|
|
printf("%d", array->dim[i]);
|
|
|
|
}
|
|
|
|
printf("] As ");
|
|
|
|
dump_type(array->type, FALSE);
|
|
|
|
}
|
|
|
|
else if (id == T_OBJECT && value >= 0)
|
|
|
|
{
|
|
|
|
if (as)
|
|
|
|
printf(" As ");
|
|
|
|
dump_name(JOB->class->class[value].index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (as)
|
|
|
|
printf(" As ");
|
|
|
|
printf("%s", TYPE_get_desc(type));
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void dump_function(FUNCTION *func)
|
|
|
|
{
|
2015-06-19 09:10:05 +02:00
|
|
|
int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-28 09:47:49 +02:00
|
|
|
//printf("<%lld> ", func->byref);
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
printf("(");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
for (i = 0; i < func->nparam; i++)
|
|
|
|
{
|
|
|
|
if (i > 0) printf(", ");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
if (i >= func->npmin)
|
|
|
|
printf("Optional ");
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2009-05-19 17:59:29 +02:00
|
|
|
if (func->byref & (1LL << i))
|
|
|
|
printf("ByRef ");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
dump_name(func->param[i].index);
|
|
|
|
dump_type(func->param[i].type, TRUE);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
if (func->vararg)
|
|
|
|
{
|
|
|
|
if (func->nparam > 0)
|
|
|
|
printf(", ");
|
|
|
|
printf("...");
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
printf(")");
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void CLASS_dump(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2015-06-19 09:10:05 +02:00
|
|
|
int i;
|
|
|
|
TYPE type;
|
|
|
|
CLASS_SYMBOL *sym;
|
|
|
|
CLASS *class = JOB->class;
|
|
|
|
|
|
|
|
if (JOB->is_module)
|
|
|
|
printf("MODULE ");
|
|
|
|
else if (JOB->is_form)
|
|
|
|
printf("FORM ");
|
|
|
|
else
|
|
|
|
printf("CLASS ");
|
|
|
|
|
|
|
|
printf("%s\n", class->name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
if (class->parent != NO_SYMBOL)
|
|
|
|
{
|
|
|
|
printf("CLASS INHERITS ");
|
|
|
|
dump_name(class->class[class->parent].index);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (class->exported)
|
|
|
|
printf("EXPORT\n");
|
|
|
|
|
|
|
|
if (class->autocreate)
|
|
|
|
printf("CREATE\n");
|
|
|
|
|
|
|
|
if (class->optional)
|
|
|
|
printf("OPTIONAL\n");
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
|
|
|
|
printf("Static size : %d octets\n", class->size_stat);
|
|
|
|
printf("Dynamic size : %d octets\n\n", class->size_dyn);
|
|
|
|
|
|
|
|
for (i = 0; i < TABLE_count(class->table); i++)
|
|
|
|
{
|
|
|
|
sym = CLASS_get_symbol(class, i);
|
|
|
|
type = sym->global.type;
|
|
|
|
if (TYPE_is_null(type))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (TYPE_is_static(type)) printf("Static ");
|
|
|
|
if (TYPE_is_public(type)) printf("Public "); else printf("Private ");
|
|
|
|
|
|
|
|
switch(TYPE_get_kind(type))
|
|
|
|
{
|
|
|
|
case TK_VARIABLE:
|
|
|
|
|
|
|
|
dump_name(i);
|
|
|
|
dump_type(type, TRUE);
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
case TK_FUNCTION:
|
|
|
|
|
|
|
|
if (TYPE_get_id(type) == T_VOID)
|
|
|
|
printf("Procedure ");
|
|
|
|
else
|
|
|
|
printf("Function ");
|
|
|
|
|
|
|
|
dump_name(i);
|
|
|
|
dump_function(&class->function[sym->global.value]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_CONST:
|
|
|
|
|
|
|
|
printf("Const ");
|
|
|
|
dump_name(i);
|
|
|
|
dump_type(type, TRUE);
|
|
|
|
printf(" = ");
|
|
|
|
dump_name(class->constant[sym->global.value].index);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_PROPERTY:
|
|
|
|
|
|
|
|
printf("Property ");
|
|
|
|
if (class->prop[sym->global.value].write == NO_SYMBOL)
|
|
|
|
printf("Read ");
|
|
|
|
dump_name(i);
|
|
|
|
dump_type(type, TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_EVENT:
|
|
|
|
|
|
|
|
printf("Event ");
|
|
|
|
dump_name(i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_UNKNOWN: printf("Unknown "); break;
|
|
|
|
case TK_EXTERN: printf("Extern "); break;
|
|
|
|
case TK_LABEL: printf("Label "); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (TYPE_get_kind(type) == TK_FUNCTION)
|
|
|
|
{
|
|
|
|
func = &class->function[value];
|
|
|
|
printf(" L:%ld", func->line);
|
|
|
|
}
|
|
|
|
else if (TYPE_get_kind(type) == TK_EVENT)
|
|
|
|
func = (FUNCTION *)&class->event[value];
|
|
|
|
else if (TYPE_get_kind(type) == TK_EXTERN)
|
|
|
|
{
|
|
|
|
func = (FUNCTION *)&class->ext_func[value];
|
|
|
|
printf(" in %s", TABLE_get_symbol_name(class->table, class->ext_func[value].library));
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
putchar('\n');
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void export_newline(void)
|
|
|
|
{
|
2015-06-19 09:10:05 +02:00
|
|
|
fputc('\n', _finfo);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void export_type(TYPE type, bool scomma)
|
|
|
|
{
|
2015-06-19 09:10:05 +02:00
|
|
|
int value;
|
2010-05-21 01:23:39 +02:00
|
|
|
int index;
|
2015-06-19 09:10:05 +02:00
|
|
|
TYPE_ID id;
|
|
|
|
|
|
|
|
id = TYPE_get_id(type);
|
|
|
|
value = TYPE_get_value(type);
|
|
|
|
|
|
|
|
if (id == T_OBJECT && value >= 0)
|
|
|
|
{
|
|
|
|
fprintf(_finfo, "%s", get_name(JOB->class->class[value].index));
|
|
|
|
if (scomma)
|
|
|
|
fputc(';', _finfo);
|
|
|
|
}
|
|
|
|
else if (id == T_ARRAY)
|
2010-05-21 01:23:39 +02:00
|
|
|
{
|
|
|
|
type = JOB->class->array[value].type;
|
|
|
|
index = CLASS_get_array_class(JOB->class, TYPE_get_id(type), TYPE_get_value(type));
|
|
|
|
fprintf(_finfo, "%s", get_name(JOB->class->class[index].index));
|
2015-06-19 09:10:05 +02:00
|
|
|
if (scomma)
|
|
|
|
fputc(';', _finfo);
|
2010-05-21 01:23:39 +02:00
|
|
|
}
|
2015-06-19 09:10:05 +02:00
|
|
|
// TODO: Manage T_STRUCT
|
|
|
|
else
|
|
|
|
fprintf(_finfo, "%s", TYPE_get_short_desc(type));
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void export_signature(int nparam, int npmin, PARAM *param, bool vararg)
|
|
|
|
{
|
2015-06-19 09:10:05 +02:00
|
|
|
int i;
|
2019-07-15 15:38:52 +02:00
|
|
|
PARAM *p;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
for (i = 0; i < nparam; i++)
|
|
|
|
{
|
2019-07-15 15:38:52 +02:00
|
|
|
p = ¶m[i];
|
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
if (i == npmin)
|
|
|
|
fprintf(_finfo, "[");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2019-07-15 15:38:52 +02:00
|
|
|
fprintf(_finfo, "(%s%s)", (p->byref ? "&" : ""), get_name(p->index));
|
|
|
|
export_type(p->type, TRUE);
|
2015-06-19 09:10:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
if (npmin < nparam)
|
|
|
|
fprintf(_finfo, "]");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
if (vararg)
|
|
|
|
fprintf(_finfo, ".");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
export_newline();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2012-11-10 01:19:53 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
static void close_file_and_rename(FILE *f, const char *file, const char *dest)
|
|
|
|
{
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fclose(f);
|
2015-12-22 21:41:18 +01:00
|
|
|
FILE_unlink(dest);
|
2015-06-19 09:10:05 +02:00
|
|
|
FILE_rename(file, dest);
|
|
|
|
FILE_set_owner(dest, COMP_project);
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-29 02:24:15 +02:00
|
|
|
FILE_unlink(file);
|
|
|
|
FILE_unlink(dest);
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:10:18 +02:00
|
|
|
static bool exist_bytecode_file(char *name)
|
|
|
|
{
|
|
|
|
char *output = OUTPUT_get_file(name);
|
|
|
|
bool exist = FILE_exist(output);
|
|
|
|
STR_free(output);
|
|
|
|
return exist;
|
|
|
|
}
|
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
static void read_line(char **line, int *len)
|
|
|
|
{
|
|
|
|
int l;
|
|
|
|
char c;
|
|
|
|
int lmax;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
*line = NULL;
|
|
|
|
*len = 0;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
if (!_buffer)
|
|
|
|
return;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
lmax = BUFFER_length(_buffer);
|
|
|
|
if (_buffer_ptr >= lmax)
|
|
|
|
return;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
*line = &_buffer[_buffer_ptr];
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
l = 0;
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (_buffer_ptr >= lmax)
|
|
|
|
break;
|
|
|
|
c = _buffer[_buffer_ptr++];
|
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
_buffer[_buffer_ptr - 1] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
l++;
|
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
*len = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool load_file(const char *name)
|
|
|
|
{
|
|
|
|
_buffer_ptr = 0;
|
|
|
|
BUFFER_create(&_buffer);
|
|
|
|
if (BUFFER_load_file(&_buffer, name))
|
|
|
|
{
|
|
|
|
BUFFER_delete(&_buffer);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
static void class_update_exported(CLASS *class)
|
|
|
|
{
|
|
|
|
FILE *fw = NULL;
|
|
|
|
char *name;
|
|
|
|
int len;
|
|
|
|
bool inserted = FALSE;
|
2011-09-28 23:10:18 +02:00
|
|
|
bool optional;
|
2015-01-16 01:31:59 +01:00
|
|
|
bool has_static;
|
2008-09-22 01:22:07 +02:00
|
|
|
int cmp;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
if (load_file(".list") && !class->exported)
|
2008-09-22 01:22:07 +02:00
|
|
|
return;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
//if (!fr && !class->exported)
|
|
|
|
// return;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
for(;;)
|
|
|
|
{
|
2013-05-04 04:54:35 +02:00
|
|
|
read_line(&name, &len);
|
2011-09-28 23:10:18 +02:00
|
|
|
optional = FALSE;
|
2015-01-16 01:31:59 +01:00
|
|
|
has_static = FALSE;
|
2011-09-28 23:10:18 +02:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
if (!name)
|
|
|
|
cmp = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (name[len - 1] == '?')
|
|
|
|
{
|
2011-09-28 23:10:18 +02:00
|
|
|
optional = TRUE;
|
|
|
|
name[len - 1] = 0;
|
2015-12-22 21:41:18 +01:00
|
|
|
len--;
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
2015-01-16 01:31:59 +01:00
|
|
|
if (name[len - 1] == '!')
|
|
|
|
{
|
|
|
|
has_static = TRUE;
|
|
|
|
name[len - 1] = 0;
|
2015-12-22 21:41:18 +01:00
|
|
|
len--;
|
2015-01-16 01:31:59 +01:00
|
|
|
}
|
2011-09-28 23:10:18 +02:00
|
|
|
cmp = strcmp(name, class->name);
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
if (cmp == 0)
|
|
|
|
{
|
2020-05-09 20:55:04 +02:00
|
|
|
if (COMP_verbose)
|
2008-09-22 01:22:07 +02:00
|
|
|
printf("Remove '%s' from .list file\n", name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if ((cmp > 0) && class->exported && !inserted)
|
|
|
|
{
|
2020-02-22 15:57:46 +01:00
|
|
|
COMPILE_create_file(&fw, ".list#");
|
2020-05-09 20:55:04 +02:00
|
|
|
if (COMP_verbose)
|
2008-09-22 01:22:07 +02:00
|
|
|
printf("Insert '%s%s' into .list file\n", class->name, class->optional ? "?" : "");
|
|
|
|
fputs(class->name, fw);
|
2015-01-16 01:31:59 +01:00
|
|
|
if (class->has_static && COMPILE_version >= 0x03060090)
|
|
|
|
fputc('!', fw);
|
2008-09-22 01:22:07 +02:00
|
|
|
if (class->optional)
|
|
|
|
fputc('?', fw);
|
|
|
|
fputc('\n', fw);
|
|
|
|
inserted = TRUE;
|
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
if (!name)
|
|
|
|
break;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2011-09-28 23:10:18 +02:00
|
|
|
if (exist_bytecode_file(name))
|
|
|
|
{
|
2020-05-09 20:55:04 +02:00
|
|
|
if (COMP_verbose)
|
2011-09-28 23:10:18 +02:00
|
|
|
printf("Copy '%s' in .list file\n", name);
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2020-02-22 15:57:46 +01:00
|
|
|
COMPILE_create_file(&fw, ".list#");
|
2011-09-28 23:10:18 +02:00
|
|
|
fputs(name, fw);
|
2015-01-16 01:31:59 +01:00
|
|
|
if (has_static && COMPILE_version >= 0x03060090)
|
|
|
|
fputc('!', fw);
|
2011-09-28 23:10:18 +02:00
|
|
|
if (optional)
|
|
|
|
fputc('?', fw);
|
|
|
|
fputc('\n', fw);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-09 20:55:04 +02:00
|
|
|
if (COMP_verbose)
|
2011-09-28 23:10:18 +02:00
|
|
|
printf("Remove '%s' from .list file\n", name);
|
|
|
|
}
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
if (_buffer)
|
|
|
|
BUFFER_delete(&_buffer);
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
close_file_and_rename(fw, ".list#", ".list");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void insert_class_info(CLASS *class, FILE *fw)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2015-06-19 09:10:05 +02:00
|
|
|
int i;
|
|
|
|
TYPE type;
|
|
|
|
CLASS_SYMBOL *sym;
|
|
|
|
char kind;
|
|
|
|
int val;
|
|
|
|
FUNCTION *func;
|
|
|
|
EVENT *event;
|
|
|
|
EXTFUNC *extfunc;
|
|
|
|
CONSTANT *cst;
|
2012-11-10 01:19:53 +01:00
|
|
|
int line;
|
2015-06-19 09:10:05 +02:00
|
|
|
const char *str;
|
|
|
|
int len;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2020-05-09 20:55:04 +02:00
|
|
|
if (COMP_verbose)
|
2008-09-22 01:22:07 +02:00
|
|
|
printf("Insert '%s' information into .info file\n", class->name);
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
_finfo = fw;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
fprintf(_finfo, "#%s\n", class->name);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
if (class->parent != NO_SYMBOL)
|
|
|
|
fprintf(_finfo, "%s", get_name(JOB->class->class[class->parent].index));
|
|
|
|
export_newline();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (!class->nocreate)
|
|
|
|
fprintf(_finfo, "C");
|
2008-09-22 01:22:07 +02:00
|
|
|
if (class->autocreate)
|
|
|
|
fprintf(_finfo, "A");
|
|
|
|
if (class->optional)
|
|
|
|
fprintf(_finfo, "O");
|
|
|
|
export_newline();
|
|
|
|
|
2012-11-10 01:19:53 +01:00
|
|
|
HELP_search_and_print_for_class(_finfo);
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
for (i = 0; i < TABLE_count(class->table); i++)
|
|
|
|
{
|
|
|
|
sym = CLASS_get_symbol(class, i);
|
|
|
|
type = sym->global.type;
|
2012-11-10 01:19:53 +01:00
|
|
|
line = sym->global.line;
|
2008-09-22 01:22:07 +02:00
|
|
|
|
|
|
|
if (TYPE_is_null(type))
|
|
|
|
continue;
|
|
|
|
if (!TYPE_is_public(type))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch(TYPE_get_kind(type))
|
|
|
|
{
|
|
|
|
case TK_CONST:
|
|
|
|
|
|
|
|
kind = 'C';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_FUNCTION:
|
|
|
|
|
|
|
|
kind = 'm';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_PROPERTY:
|
|
|
|
|
|
|
|
if (class->prop[sym->global.value].write == NO_SYMBOL)
|
|
|
|
kind = 'r';
|
|
|
|
else
|
|
|
|
kind = 'p';
|
|
|
|
break;
|
|
|
|
|
2010-05-03 12:19:13 +02:00
|
|
|
case TK_VARIABLE:
|
|
|
|
|
|
|
|
kind = 'v';
|
|
|
|
break;
|
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
case TK_EVENT:
|
|
|
|
|
|
|
|
kind = ':';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TK_EXTERN:
|
|
|
|
|
|
|
|
kind = 'X';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(_finfo, "%s\n", get_name(i));
|
|
|
|
fprintf(_finfo, "%c\n", TYPE_is_static(type) ? toupper(kind) : kind);
|
|
|
|
|
|
|
|
export_type(type, FALSE);
|
|
|
|
|
|
|
|
if (kind == 'r' || kind == 'p')
|
|
|
|
{
|
|
|
|
val = class->prop[sym->global.value].comment;
|
|
|
|
if (val != NO_SYMBOL)
|
2015-06-19 09:10:05 +02:00
|
|
|
{
|
|
|
|
get_string(val, &str, &len);
|
|
|
|
fprintf(_finfo, "%.*s", len, str);
|
|
|
|
}
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export_newline();
|
|
|
|
|
|
|
|
switch(kind)
|
|
|
|
{
|
|
|
|
case 'C':
|
|
|
|
cst = &class->constant[sym->global.value];
|
|
|
|
|
|
|
|
switch(TYPE_get_id(type))
|
|
|
|
{
|
|
|
|
case T_BOOLEAN:
|
2014-10-24 22:06:18 +02:00
|
|
|
if (cst->value)
|
|
|
|
fputc('T', _finfo);
|
|
|
|
fputc('\n', _finfo);
|
|
|
|
break;
|
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
case T_BYTE:
|
|
|
|
case T_SHORT:
|
|
|
|
case T_INTEGER:
|
|
|
|
fprintf(_finfo, "%d\n", cst->value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_LONG:
|
|
|
|
fprintf(_finfo, "%" PRId64 "\n", cst->lvalue);
|
|
|
|
break;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
case T_SINGLE:
|
|
|
|
case T_FLOAT:
|
|
|
|
fprintf(_finfo, "%s\n", get_name(cst->value));
|
|
|
|
break;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
case T_STRING:
|
2015-06-19 09:10:05 +02:00
|
|
|
get_string(cst->value, &str, &len);
|
|
|
|
print_quoted(_finfo, str, len);
|
2013-06-19 04:01:08 +02:00
|
|
|
export_newline();
|
2008-09-22 01:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
export_newline();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
func = &class->function[sym->global.value];
|
|
|
|
export_signature(func->nparam, func->npmin, func->param, func->vararg);
|
2012-11-10 01:19:53 +01:00
|
|
|
line = func->line - 1;
|
2008-09-22 01:22:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ':':
|
|
|
|
event = &class->event[sym->global.value];
|
|
|
|
export_signature(event->nparam, event->nparam, event->param, FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
|
|
|
extfunc = &class->ext_func[sym->global.value];
|
|
|
|
export_signature(extfunc->nparam, extfunc->nparam, extfunc->param, FALSE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
export_newline();
|
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2012-11-10 01:19:53 +01:00
|
|
|
HELP_search_and_print(_finfo, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static char *OUTPUT_get_help_file(const char *file)
|
|
|
|
{
|
|
|
|
char *output;
|
|
|
|
char *p;
|
|
|
|
//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 = ".help";
|
|
|
|
if (mkdir(output, 0777) == 0)
|
|
|
|
FILE_set_owner(output, COMP_project);
|
|
|
|
|
|
|
|
output = STR_copy(FILE_cat(output, name, NULL));
|
|
|
|
|
|
|
|
//STR_free(dir);
|
|
|
|
STR_free(name);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void output_help(void)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
JOB->hname = OUTPUT_get_help_file(JOB->name);
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2012-11-10 01:19:53 +01:00
|
|
|
if (!JOB->help)
|
|
|
|
{
|
|
|
|
FILE_unlink(JOB->hname);
|
|
|
|
return;
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2012-11-10 01:19:53 +01:00
|
|
|
file = fopen(JOB->hname, "w");
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2012-11-10 01:19:53 +01:00
|
|
|
if (!file)
|
|
|
|
THROW("Cannot create file: &1", JOB->hname);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_count(JOB->help); i++)
|
|
|
|
{
|
|
|
|
if (!JOB->help[i])
|
|
|
|
continue;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2012-11-10 01:19:53 +01:00
|
|
|
fprintf(stderr, "[%d] = %.*s\n", i + JOB->help_first_line, get_help_comment_length(JOB->help[i]), JOB->help[i]);
|
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2012-11-10 01:19:53 +01:00
|
|
|
fclose(file);
|
|
|
|
FILE_set_owner(JOB->hname, COMP_project);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2012-11-10 01:19:53 +01:00
|
|
|
#endif
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void CLASS_export(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-09-22 01:22:07 +02:00
|
|
|
FILE *fw = NULL;
|
|
|
|
char *line;
|
|
|
|
int len;
|
|
|
|
bool inserted = FALSE;
|
2015-06-19 09:10:05 +02:00
|
|
|
CLASS *class = JOB->class;
|
|
|
|
int cmp;
|
|
|
|
const char *msg;
|
|
|
|
|
|
|
|
if (chdir(FILE_get_dir(COMP_project)))
|
|
|
|
{
|
|
|
|
msg = "Cannot change directory";
|
|
|
|
goto __ERROR;
|
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
class_update_exported(class);
|
2009-08-17 00:07:48 +02:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
load_file(".info");
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
read_line(&line, &len);
|
2008-09-22 01:22:07 +02:00
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (!line)
|
|
|
|
cmp = 1;
|
|
|
|
else
|
|
|
|
cmp = strcmp(&line[1], class->name);
|
|
|
|
|
|
|
|
if (cmp == 0)
|
|
|
|
{
|
2020-05-09 20:55:04 +02:00
|
|
|
if (COMP_verbose)
|
2008-09-22 01:22:07 +02:00
|
|
|
printf("Remove '%s' information from .info file\n", class->name);
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
for(;;)
|
|
|
|
{
|
2013-05-04 04:54:35 +02:00
|
|
|
read_line(&line, &len);
|
2008-09-22 01:22:07 +02:00
|
|
|
if (!line || *line == '#')
|
|
|
|
break;
|
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
if (cmp > 0 && class->exported && !inserted)
|
|
|
|
{
|
2020-02-22 15:57:46 +01:00
|
|
|
COMPILE_create_file(&fw, ".info#");
|
2008-09-22 01:22:07 +02:00
|
|
|
insert_class_info(class, fw);
|
|
|
|
inserted = TRUE;
|
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
if (!line)
|
|
|
|
break;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
// copying class information
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2011-09-28 23:10:18 +02:00
|
|
|
if (exist_bytecode_file(&line[1]))
|
2008-09-22 01:22:07 +02:00
|
|
|
{
|
2020-05-09 20:55:04 +02:00
|
|
|
if (COMP_verbose)
|
2011-09-28 23:10:18 +02:00
|
|
|
printf("Copy '%s' information in .info file\n", &line[1]);
|
|
|
|
for(;;)
|
|
|
|
{
|
2020-02-22 15:57:46 +01:00
|
|
|
COMPILE_create_file(&fw, ".info#");
|
2011-09-28 23:10:18 +02:00
|
|
|
fputs(line, fw);
|
|
|
|
fputc('\n', fw);
|
2013-05-04 04:54:35 +02:00
|
|
|
read_line(&line, &len);
|
2011-09-28 23:10:18 +02:00
|
|
|
if (!line || *line == '#')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-09 20:55:04 +02:00
|
|
|
if (COMP_verbose)
|
2011-09-28 23:10:18 +02:00
|
|
|
printf("Remove '%s' information from .info file\n", &line[1]);
|
|
|
|
for(;;)
|
|
|
|
{
|
2013-05-04 04:54:35 +02:00
|
|
|
read_line(&line, &len);
|
2011-09-28 23:10:18 +02:00
|
|
|
if (!line || *line == '#')
|
|
|
|
break;
|
|
|
|
}
|
2008-09-22 01:22:07 +02:00
|
|
|
}
|
|
|
|
}
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2013-05-04 04:54:35 +02:00
|
|
|
if (_buffer)
|
|
|
|
BUFFER_delete(&_buffer);
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2008-09-22 01:22:07 +02:00
|
|
|
close_file_and_rename(fw, ".info#", ".info");
|
2009-08-17 00:07:48 +02:00
|
|
|
return;
|
2015-12-22 21:41:18 +01:00
|
|
|
|
2009-08-17 00:07:48 +02:00
|
|
|
__ERROR:
|
|
|
|
|
2015-06-19 09:10:05 +02:00
|
|
|
THROW("Cannot create class information: &1: &2", msg, strerror(errno));
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|