implement type encoding

This commit is contained in:
Bill Currie 2002-05-10 23:19:57 +00:00
parent c04785fe0f
commit 73e6cf062c
5 changed files with 107 additions and 5 deletions

View file

@ -40,6 +40,9 @@ typedef enum {
ev_uinteger,
ev_short, // value is embedded in the opcode
ev_struct,
ev_object,
ev_class,
ev_sel,
ev_type_count // not a type, gives number of types
} etype_t;

View file

@ -71,6 +71,9 @@ int pr_type_size[ev_type_count] = {
1,
0, // value in opcode
1, // variable
1, // variable
1,
2,
};
const char *pr_type_name[ev_type_count] = {
@ -87,6 +90,9 @@ const char *pr_type_name[ev_type_count] = {
"uinteger",
"short",
"struct",
"object",
"Class",
"SEL",
};
ddef_t *ED_FieldAtOfs (progs_t * pr, int ofs);

View file

@ -57,11 +57,14 @@ extern type_t *type_method;
extern def_t def_void;
extern def_t def_function;
struct dstring_s;
type_t *find_type (type_t *new);
void new_typedef (const char *name, struct type_s *type);
struct type_s *get_typedef (const char *name);
struct type_s *pointer_type (struct type_s *aux);
void print_type (struct type_s *type);
void new_typedef (const char *name, type_t *type);
type_t *get_typedef (const char *name);
type_t *pointer_type (type_t *aux);
void print_type (type_t *type);
void encode_type (struct dstring_s *encodking, type_t *type);
void init_types (void);

View file

@ -1064,6 +1064,9 @@ test_expr (expr_t *e, int test)
new->type = ex_quaternion;
break;
case ev_struct:
case ev_object:
case ev_class:
case ev_sel:
return error (e, "struct cannot be tested");
}
new->line = e->line;
@ -1961,7 +1964,14 @@ protocol_expr (const char *protocol)
expr_t *
encode_expr (type_t *type)
{
return error (0, "not implemented");
dstring_t *encoding = dstring_newstr ();
expr_t *e = new_expr ();
encode_type (encoding, type);
e->type = ex_string;
e->e.string_val = encoding->str;
free (encoding);
return e;
}
expr_t *

View file

@ -34,6 +34,7 @@ static const char rcsid[] =
#include "QF/hash.h"
#include "QF/sys.h"
#include "QF/dstring.h"
#include "qfcc.h"
#include "function.h"
@ -236,6 +237,85 @@ print_type (type_t *type)
}
}
void
_encode_type (dstring_t *encoding, type_t *type, int level)
{
struct_field_t *field;
switch (type->type) {
case ev_void:
dstring_appendstr (encoding, "v");
break;
case ev_string:
dstring_appendstr (encoding, "*");
break;
case ev_float:
dstring_appendstr (encoding, "f");
break;
case ev_vector:
dstring_appendstr (encoding, "?");
break;
case ev_entity:
dstring_appendstr (encoding, "?");
break;
case ev_field:
dstring_appendstr (encoding, "F");
break;
case ev_func:
dstring_appendstr (encoding, "?");
break;
case ev_pointer:
type = type->aux_type;
switch (type->type) {
case ev_object:
dstring_appendstr (encoding, "@");
break;
case ev_class:
dstring_appendstr (encoding, "#");
break;
default:
dstring_appendstr (encoding, "^");
_encode_type (encoding, type, level + 1);
break;
}
break;
case ev_quaternion:
dstring_appendstr (encoding, "?");
break;
case ev_integer:
dstring_appendstr (encoding, "i");
break;
case ev_uinteger:
dstring_appendstr (encoding, "I");
break;
case ev_short:
dstring_appendstr (encoding, "s");
break;
case ev_struct:
case ev_object:
case ev_class:
dstring_appendstr (encoding, "{");
//XXX dstring_appendstr (encoding, name);
dstring_appendstr (encoding, "=");
for (field = type->struct_head; field; field = field->next)
_encode_type (encoding, field->type, level + 1);
dstring_appendstr (encoding, "}");
break;
case ev_sel:
dstring_appendstr (encoding, ":");
break;
case ev_type_count:
dstring_appendstr (encoding, "?");
break;
}
}
void
encode_type (dstring_t *encoding, type_t *type)
{
_encode_type (encoding, type, 0);
}
void
init_types (void)
{