summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0833fd8)
raw | patch | inline | side by side (parent: 0833fd8)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 24 Jul 2017 19:53:43 +0000 (22:53 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 24 Jul 2017 19:53:43 +0000 (22:53 +0300) |
generator.c | patch | blob | history | |
notes | patch | blob | history | |
oberon.c | patch | blob | history | |
test.c | patch | blob | history |
diff --git a/generator.c b/generator.c
index b7c24b3968cd780b14e47bc5a26c591179dc8f1a..991b6dd83c416be4d19a81a0722c30f29d6e12d5 100644 (file)
--- a/generator.c
+++ b/generator.c
}
static void
-oberon_generator_get_full_name(char * name, int max_len, oberon_object_t * o)
+oberon_generator_get_full_name(char * name, int max_len, oberon_object_t * x)
{
- if(!o)
+ if(!x)
{
name[0] = 0;
return;
}
char parent[256];
- oberon_generator_get_full_name(parent, 256, o -> parent);
-
- char * xname;
-// if(o -> class == OBERON_CLASS_MODULE)
-// {
-// xname = o -> module -> name;
-// }
-// else
-// {
- xname = o -> name;
-// }
+ parent[0] = 0;
+
+ switch(x -> class)
+ {
+ case OBERON_CLASS_FIELD:
+ case OBERON_CLASS_PARAM:
+ case OBERON_CLASS_VAR_PARAM:
+ /* В локальных областях префиксы излишни */
+ break;
+ default:
+ oberon_generator_get_full_name(parent, 256, x -> parent);
+ break;
+ }
if(strlen(parent) > 0)
{
- snprintf(name, max_len, "%s_%s", parent, xname);
+ snprintf(name, max_len, "%s_%s", parent, x -> name);
}
else
{
- snprintf(name, max_len, "%s", xname);
+ snprintf(name, max_len, "%s", x -> name);
}
}
index e07d89d002f2b95fb1f22405e53549dcb974a228..148c0b4607839a11b72ca610804dd7e425fdf2ad 100644 (file)
--- a/notes
+++ b/notes
+- поля структур всегда доступны
- нету проверки экспорта для чтения
-- нету списков переменных/параметров. (* VAR x, y, z : INTEGER; *)
- нету комментариев
- нету тестовых процедур для ввода-вывода
diff --git a/oberon.c b/oberon.c
index 817da1ae02b4f417f9c005f902bd2d26b0f5f3a1..5b4c4ea84efada1e388a0c775f4d363e16df49d8 100644 (file)
--- a/oberon.c
+++ b/oberon.c
@@ -161,6 +161,7 @@ oberon_define_object(oberon_scope_t * scope, char * name, int class, int export,
return newvar;
}
+/*
static void
oberon_define_field(oberon_context_t * ctx, oberon_type_t * rec, char * name, oberon_type_t * type)
{
rec -> num_decl += 1;
x -> next = field;
}
+*/
static oberon_object_t *
oberon_find_object_in_list(oberon_object_t * list, char * name)
}
static oberon_object_t *
-oberon_define_type(oberon_scope_t * scope, char * name, oberon_type_t * type, int export, int read_only)
+oberon_define_type(oberon_scope_t * scope, char * name, oberon_type_t * type, int export)
{
oberon_object_t * id;
- id = oberon_define_object(scope, name, OBERON_CLASS_TYPE, export, read_only);
+ id = oberon_define_object(scope, name, OBERON_CLASS_TYPE, export, 0);
id -> type = type;
oberon_generator_init_type(scope -> ctx, type);
return id;
}
-static oberon_object_t *
-oberon_define_var(oberon_scope_t * scope, int class, char * name, oberon_type_t * type, int export, int read_only)
-{
- oberon_object_t * var;
- var = oberon_define_object(scope, name, class, export, read_only);
- var -> type = type;
- return var;
-}
-
// =======================================================================
// SCANER
// =======================================================================
return x;
}
+static void
+oberon_ident_list(oberon_context_t * ctx, int class, int * num, oberon_object_t ** list)
+{
+ *num = 1;
+ *list = oberon_ident_def(ctx, class);
+ while(ctx -> token == COMMA)
+ {
+ oberon_assert_token(ctx, COMMA);
+ oberon_ident_def(ctx, class);
+ *num += 1;
+ }
+}
+
static void
oberon_var_decl(oberon_context_t * ctx)
{
- oberon_object_t * var;
+ int num;
+ oberon_object_t * list;
oberon_type_t * type;
type = oberon_new_type_ptr(OBERON_TYPE_VOID);
- var = oberon_ident_def(ctx, OBERON_CLASS_VAR);
+ oberon_ident_list(ctx, OBERON_CLASS_VAR, &num, &list);
oberon_assert_token(ctx, COLON);
oberon_type(ctx, &type);
- var -> type = type;
-}
-
-static oberon_object_t *
-oberon_make_param(oberon_context_t * ctx, int token, char * name, oberon_type_t * type)
-{
- oberon_object_t * param;
- if(token == VAR)
+ oberon_object_t * var = list;
+ for(int i = 0; i < num; i++)
{
- param = oberon_define_var(ctx -> decl, OBERON_CLASS_VAR_PARAM, name, type, 0, 0);
+ var -> type = type;
+ var = var -> next;
}
- else if(token == IDENT)
- {
- param = oberon_define_var(ctx -> decl, OBERON_CLASS_PARAM, name, type, 0, 0);
- }
- else
- {
- oberon_error(ctx, "oberon_make_param: wat");
- }
-
- return param;
}
static oberon_object_t *
oberon_fp_section(oberon_context_t * ctx, int * num_decl)
{
- int modifer_token = ctx -> token;
+ int class = OBERON_CLASS_PARAM;
if(ctx -> token == VAR)
{
oberon_read_token(ctx);
+ class = OBERON_CLASS_VAR_PARAM;
}
- char * name;
- name = oberon_assert_ident(ctx);
+ int num;
+ oberon_object_t * list;
+ oberon_ident_list(ctx, class, &num, &list);
oberon_assert_token(ctx, COLON);
type = oberon_new_type_ptr(OBERON_TYPE_VOID);
oberon_type(ctx, &type);
- oberon_object_t * first;
- first = oberon_make_param(ctx, modifer_token, name, type);
+ oberon_object_t * param = list;
+ for(int i = 0; i < num; i++)
+ {
+ param -> type = type;
+ param = param -> next;
+ }
- *num_decl += 1;
- return first;
+ *num_decl += num;
+ return list;
}
#define ISFPSECTION \
{
if(ctx -> token == IDENT)
{
- char * name;
+ int num;
+ oberon_object_t * list;
oberon_type_t * type;
type = oberon_new_type_ptr(OBERON_TYPE_VOID);
- name = oberon_assert_ident(ctx);
+ oberon_ident_list(ctx, OBERON_CLASS_FIELD, &num, &list);
oberon_assert_token(ctx, COLON);
oberon_type(ctx, &type);
- oberon_define_field(ctx, rec, name, type);
+
+ oberon_object_t * field = list;
+ for(int i = 0; i < num; i++)
+ {
+ field -> type = type;
+ field = field -> next;
+ }
+
+ rec -> num_decl += num;
}
}
oberon_type_t * rec;
rec = *type;
rec -> class = OBERON_TYPE_RECORD;
- oberon_object_t * list = malloc(sizeof *list);
- memset(list, 0, sizeof *list);
- rec -> num_decl = 0;
- rec -> base = NULL;
- rec -> decl = list;
+
+ oberon_scope_t * record_scope;
+ record_scope = oberon_open_scope(ctx);
+ // TODO parent object
+ //record_scope -> parent = NULL;
+ record_scope -> local = 1;
oberon_assert_token(ctx, RECORD);
oberon_field_list(ctx, rec);
}
oberon_assert_token(ctx, END);
- rec -> decl = rec -> decl -> next;
+ rec -> decl = record_scope -> list -> next;
+ oberon_close_scope(record_scope);
+
*type = rec;
}
else if(ctx -> token == POINTER)
oberon_generator_init_type(ctx, ctx -> void_ptr_type);
ctx -> int_type = oberon_new_type_integer(sizeof(int));
- oberon_define_type(ctx -> world_scope, "INTEGER", ctx -> int_type, 1, 0);
+ oberon_define_type(ctx -> world_scope, "INTEGER", ctx -> int_type, 1);
ctx -> bool_type = oberon_new_type_boolean(sizeof(int));
- oberon_define_type(ctx -> world_scope, "BOOLEAN", ctx -> bool_type, 1, 0);
+ oberon_define_type(ctx -> world_scope, "BOOLEAN", ctx -> bool_type, 1);
}
static void
index 5b2fc48e91e4e54175f56baa5dd1ea247781bcb3..4bef02c8bd7bc3c33d0788d4243d49e875f575ad 100644 (file)
--- a/test.c
+++ b/test.c
"MODULE Test;"
"IMPORT I := Imported;"
"VAR"
- " x : I.Rider;"
+ " x, y : I.Rider;"
+ "PROCEDURE Proc(x, y, z : INTEGER);"
+ "END Proc;"
"BEGIN"
+ " x.i := 1;"
" I.Ln;"
+ " I.i := 666;"
"END Test."
;
static char source_imported[] =
"MODULE Imported;"
"TYPE"
- " Rider* = RECORD i : INTEGER; END;"
+ " Rider* = RECORD i, j, k : INTEGER; END;"
+ "VAR"
+ " i- : INTEGER;"
""
"PROCEDURE Ln*;"
"END Ln;"