ack/lang/m2/comp/defmodule.c

105 lines
2.1 KiB
C
Raw Normal View History

1986-04-03 00:44:39 +00:00
/* D E F I N I T I O N M O D U L E S */
1986-05-01 19:06:53 +00:00
#include "debug.h"
1986-04-04 13:47:04 +00:00
1986-04-03 00:44:39 +00:00
#include <assert.h>
#include <em_arith.h>
#include <em_label.h>
1986-04-21 17:27:06 +00:00
1986-04-03 00:44:39 +00:00
#include "idf.h"
#include "input.h"
#include "scope.h"
#include "def.h"
#include "LLlex.h"
1986-10-06 20:36:30 +00:00
#include "Lpars.h"
1986-04-03 00:44:39 +00:00
#include "f_info.h"
1986-04-21 17:27:06 +00:00
#include "main.h"
1986-10-06 20:36:30 +00:00
#include "node.h"
1986-11-05 14:33:00 +00:00
#include "type.h"
1986-04-21 17:27:06 +00:00
1986-04-08 18:15:46 +00:00
#ifdef DEBUG
long sys_filesize();
#endif
1986-04-03 00:44:39 +00:00
1986-11-05 14:33:00 +00:00
STATIC
1986-04-03 00:44:39 +00:00
GetFile(name)
char *name;
{
/* Try to find a file with basename "name" and extension ".def",
in the directories mentioned in "DEFPATH".
*/
1986-10-06 20:36:30 +00:00
char buf[15];
1986-04-08 23:34:10 +00:00
char *strcpy(), *strcat();
1986-04-03 00:44:39 +00:00
1986-10-06 20:36:30 +00:00
strncpy(buf, name, 10);
1986-06-06 02:22:09 +00:00
buf[10] = '\0'; /* maximum length */
strcat(buf, ".def");
1986-04-03 00:44:39 +00:00
if (! InsertFile(buf, DEFPATH, &(FileName))) {
1986-11-05 14:33:00 +00:00
error("could'nt find a DEFINITION MODULE for \"%s\"", name);
return 0;
1986-04-03 00:44:39 +00:00
}
LineNumber = 1;
1986-06-26 09:39:36 +00:00
DO_DEBUG(options['F'], debug("File %s : %ld characters", FileName, sys_filesize(FileName)));
1986-11-05 14:33:00 +00:00
return 1;
1986-04-03 00:44:39 +00:00
}
struct def *
1986-10-06 20:36:30 +00:00
GetDefinitionModule(id, incr)
register struct idf *id;
1986-04-03 00:44:39 +00:00
{
/* Return a pointer to the "def" structure of the definition
module indicated by "id".
We may have to read the definition module itself.
1986-10-06 20:36:30 +00:00
Also increment level by "incr".
1986-04-03 00:44:39 +00:00
*/
struct def *df;
1986-05-28 18:36:51 +00:00
static int level;
1986-11-05 14:33:00 +00:00
struct scopelist *vis;
1986-04-03 00:44:39 +00:00
1986-10-06 20:36:30 +00:00
level += incr;
1986-04-15 17:51:53 +00:00
df = lookup(id, GlobalScope);
1986-04-03 00:44:39 +00:00
if (!df) {
/* Read definition module. Make an exception for SYSTEM.
*/
if (!strcmp(id->id_text, "SYSTEM")) {
do_SYSTEM();
}
else {
1986-10-06 20:36:30 +00:00
open_scope(CLOSEDSCOPE);
1986-11-05 14:33:00 +00:00
if (GetFile(id->id_text)) {
DefModule();
if (level == 1) {
/* The module is directly imported by
the currently defined module, so we
have to remember its name because
we have to call its initialization
routine
*/
static struct node *nd_end;
register struct node *n;
extern struct node *Modules;
1986-10-06 20:36:30 +00:00
1986-11-05 14:33:00 +00:00
n = MkLeaf(Name, &dot);
n->nd_IDF = id;
n->nd_symb = IDENT;
if (nd_end) nd_end->next = n;
else Modules = n;
nd_end = n;
}
1986-05-28 18:36:51 +00:00
}
1986-11-05 14:33:00 +00:00
vis = CurrVis;
1986-10-06 20:36:30 +00:00
close_scope(SC_CHKFORW);
1986-04-03 00:44:39 +00:00
}
1986-04-15 17:51:53 +00:00
df = lookup(id, GlobalScope);
1986-11-05 14:33:00 +00:00
if (! df) {
df = MkDef(id, GlobalScope, D_ERROR);
df->df_type = error_type;
df->mod_vis = CurrVis;
return df;
}
1986-04-03 00:44:39 +00:00
}
1986-11-05 14:33:00 +00:00
assert(df);
1986-10-06 20:36:30 +00:00
level -= incr;
1986-04-03 00:44:39 +00:00
return df;
}