Permalink
Browse files

* remove old GOTO checks, put in new ones

  that actually _work_
* new function resolve.c:g95_resolve_goto()
  makes sure branch is legal
* new function g95_resolve_construct_blocks()
  resolve blocks top down instead of bottom
  up like old code
* cleanups in parse.c, match.c, st.c
* update CONTRIB, README
  • Loading branch information...
1 parent b9e4e35 commit bcb13eb46cd8871a86fa73620a7df5fb8a1aac5c steven97 committed Apr 13, 2002
Showing with 168 additions and 87 deletions.
  1. +1 −0 CONTRIB
  2. +3 −2 README
  3. +16 −13 g95.h
  4. +4 −3 match.c
  5. +10 −19 parse.c
  6. +124 −34 resolve.c
  7. +2 −0 select.c
  8. +6 −14 st.c
  9. +2 −2 symbol.c
View
@@ -9,6 +9,7 @@ Andy Vaught
Katherine Holcomb
Niels Kristian Bech Jensen
Tobi Schlueter
+Steven Bosscher
View
5 README
@@ -1,11 +1,12 @@
The goal of the g95 project is to create a free, open source Fortran 95
compiler. The code has been donated to the Free Software Foundation
-for inclusion in GCC, the Gnu Compiler Collection.
+for inclusion in GCC, the GNU Compiler Collection.
WARNING:
G95 is in a larval state. Perusing the g77 source, we estimate that
about 200,000 lines of code will be necessary to implement g95. G95
-is currently about 34,000 lines long, making it about version 0.17.
+is currently about 37,000 lines long, making it about version 0.185.
The current g95 does nothing except print the contents of internal
data structures.
+
View
29 g95.h
@@ -401,7 +401,6 @@ typedef struct g95_namelist {
typedef struct g95_st_label {
int label;
- int block_no;
g95_sl_type defined, referenced;
@@ -415,15 +414,17 @@ typedef struct g95_st_label {
#define g95_get_st_label() g95_getmem(sizeof(g95_st_label))
-/* Stack of block numbers for validating GOTO statements */
+/* Stack of block entry points for validating GOTO statements.
+ The idea here is to keep a stack of all the labels that are
+ in the back path of the parse tree in the current namespace.
+ See resolve_goto() in resolve.c for details. */
-typedef struct g95_block_stack {
- int block_no;
- struct g95_block_stack *prev;
-} g95_block_stack;
-
-#define g95_get_block_stack() g95_getmem(sizeof(g95_block_stack))
+typedef struct g95_code_stack {
+ struct g95_code *code;
+ struct g95_code_stack *prev;
+} g95_code_stack;
+#define g95_get_code_stack() g95_getmem(sizeof(g95_code_stack))
/* g95_interface()-- Interfaces are lists of symbols strung together */
@@ -574,7 +575,6 @@ extern g95_interface_info current_interface;
typedef struct g95_state_data {
g95_compile_state state;
g95_symbol *sym; /* Block name associated with this level */
- int this_block_no;
struct g95_code *head, *tail;
struct g95_state_data *previous;
} g95_state_data;
@@ -865,7 +865,7 @@ typedef struct g95_forall_iterator {
typedef enum {
EXEC_NOP=1, EXEC_ASSIGN, EXEC_POINTER_ASSIGN, EXEC_GOTO, EXEC_CALL,
- EXEC_RETURN, EXEC_STOP,
+ EXEC_RETURN, EXEC_STOP, EXEC_CONTINUE,
EXEC_IF, EXEC_ARITHMETIC_IF, EXEC_DO, EXEC_DO_WHILE, EXEC_SELECT,
EXEC_FORALL, EXEC_WHERE, EXEC_CYCLE, EXEC_EXIT,
EXEC_ALLOCATE, EXEC_DEALLOCATE, EXEC_NULLIFY,
@@ -878,7 +878,6 @@ typedef struct g95_code {
struct g95_code *block, *next;
locus loc;
- int block_no;
int here, label, label2, label3;
g95_symbol *sym;
@@ -900,6 +899,9 @@ typedef struct g95_code {
} g95_code;
+#define g95_get_code() g95_getmem(sizeof(g95_code))
+
+
extern g95_code new_st;
@@ -1204,7 +1206,7 @@ void g95_show_components(g95_symbol *);
void g95_check_st_labels(g95_namespace *);
int g95_new_internal_label();
-void g95_define_st_label(int, locus *, int, g95_sl_type);
+void g95_define_st_label(int, locus *, g95_sl_type);
try g95_reference_st_label(int, g95_sl_type);
g95_namespace *g95_get_namespace(void);
@@ -1387,7 +1389,6 @@ int g95_kind_max(g95_expr *, g95_expr *);
extern g95_code new_st, *program_tail;
void g95_clear_new_st(void);
-g95_code *g95_get_code(void);
g95_code *g95_new_level(g95_code *);
g95_code *g95_add_statement(void);
g95_code *g95_append_code(g95_code *, g95_code *);
@@ -1404,6 +1405,8 @@ int g95_impure_variable(g95_symbol *);
int g95_pure(g95_symbol *);
int g95_elemental(g95_symbol *);
try g95_resolve_iterator(g95_iterator *);
+void g95_push_code(g95_code *); /* I'd rather not have these here, but */
+void g95_pop_code(); /* we need them in select.c */
/* array.c */
View
@@ -889,6 +889,7 @@ match m, n;
p = g95_get_code();
p->next = g95_get_code();
*p->next = new_st;
+ p->next->loc = *g95_current_locus();
p->expr = expr;
p->op = EXEC_IF;
@@ -1212,7 +1213,7 @@ match g95_match_continue(void) {
return MATCH_ERROR;
}
- new_st.op = EXEC_NOP;
+ new_st.op = EXEC_CONTINUE;
return MATCH_YES;
}
@@ -1286,11 +1287,11 @@ match m;
tail->block = g95_get_code();
tail = tail->block;
}
- tail->label = label;
- tail->op = EXEC_SELECT;
cp = g95_get_case();
cp->low = cp->high = g95_int_expr(i++);
+
+ tail->op = EXEC_SELECT;
tail->ext.case_list = cp;
tail->next = g95_get_code();
View
29 parse.c
@@ -35,15 +35,6 @@ int g95_statement_label;
static locus label_locus;
static jmp_buf eof;
-
-/* Current block no. We use this to make sure branching statements
- * are conforming. A unique number is assigned to each block. The
- * main parser function initializes this to 0 for each new file.
- * Note that this number has nothing to do with g95_current_block,
- * which is a g95_symbol associated with the current block */
-
-int g95_new_block_no;
-
g95_state_data *g95_state_stack;
static void check_statement_label(g95_statement);
@@ -489,7 +480,6 @@ static void push_state(g95_state_data *p, g95_compile_state new_state,
p->state = new_state;
p->previous = g95_state_stack;
- p->this_block_no = ++g95_new_block_no;
p->sym = sym;
p->head = p->tail = NULL;
@@ -545,8 +535,7 @@ g95_sl_type type;
break;
}
- g95_define_st_label(g95_statement_label, &label_locus,
- g95_state_stack->this_block_no, type);
+ g95_define_st_label(g95_statement_label, &label_locus, type);
}
@@ -708,11 +697,13 @@ static void accept_statement(g95_statement st) {
g95_current_ns->proc_name = g95_new_block;
break;
- case ST_ENDDO: case ST_ENDIF: case ST_END_SELECT:
+ case ST_ENDIF:
+ case ST_ENDDO:
+ case ST_END_SELECT:
if (g95_statement_label == 0) break;
-
new_st.op = EXEC_NOP;
-
+ /* Fall through */
+
case_executable:
case_exec_markers:
g95_add_statement();
@@ -1374,7 +1365,6 @@ int seen_else;
break;
case ST_ENDIF:
- accept_statement(st);
break;
default:
@@ -1384,6 +1374,7 @@ int seen_else;
} while(st != ST_ENDIF);
pop_state();
+ accept_statement(st);
}
@@ -1451,7 +1442,6 @@ g95_select s;
break;
case ST_END_SELECT:
- accept_statement(st);
break;
/* Can't have an executable statement because of parse_executable() */
@@ -1463,6 +1453,7 @@ g95_select s;
} while(st != ST_END_SELECT);
pop_state();
+ accept_statement(st);
}
@@ -1530,7 +1521,7 @@ g95_do s;
case ST_ENDDO:
if (s.label != 0 && s.label != g95_statement_label)
g95_error("Statement label in ENDDO at %C doesn't match DO label");
- /* fall throught */
+ /* Fall through */
case ST_IMPLIED_ENDDO:
break;
@@ -1541,6 +1532,7 @@ g95_do s;
}
pop_state();
+ accept_statement(st);
}
@@ -1835,7 +1827,6 @@ locus prog_locus;
g95_clear_new_st();
g95_statement_label = 0;
- g95_new_block_no = 0;
if (setjmp(eof)) return FAILURE; /* Come here on unexpected EOF */
Oops, something went wrong.

0 comments on commit bcb13eb

Please sign in to comment.