1987-04-29 10:22:07 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
|
|
|
|
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 */
|
|
|
|
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1987-04-29 10:22:07 +00:00
|
|
|
|
2017-01-07 21:56:00 +00:00
|
|
|
#include "debug.h"
|
2013-05-14 21:24:38 +00:00
|
|
|
#include "parameters.h"
|
1986-04-04 13:47:04 +00:00
|
|
|
|
2017-01-07 21:56:00 +00:00
|
|
|
#include <alloc.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <em_arith.h>
|
|
|
|
#include <em_label.h>
|
2013-05-16 23:04:54 +00:00
|
|
|
#include <stdlib.h>
|
2019-02-18 16:30:47 +00:00
|
|
|
#include <stdio.h>
|
2017-11-14 02:34:31 +00:00
|
|
|
#include <string.h>
|
2017-01-07 21:56:00 +00:00
|
|
|
|
|
|
|
#include "LLlex.h"
|
|
|
|
#include "Lpars.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "f_info.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "input.h"
|
2019-03-01 17:39:25 +00:00
|
|
|
#include "error.h"
|
2017-01-07 21:56:00 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "node.h"
|
2019-03-01 17:39:25 +00:00
|
|
|
#include "lookup.h"
|
|
|
|
#include "main.h"
|
2017-01-07 21:56:00 +00:00
|
|
|
#include "scope.h"
|
|
|
|
#include "type.h"
|
1986-04-21 17:27:06 +00:00
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
#ifdef DEBUG
|
2019-02-18 16:30:47 +00:00
|
|
|
size_t sys_filesize();
|
1986-04-08 18:15:46 +00:00
|
|
|
#endif
|
1986-04-03 00:44:39 +00:00
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
extern void DefModule(void); /* Lpars */
|
|
|
|
|
2019-05-10 17:09:03 +00:00
|
|
|
struct idf* DefId;
|
1986-12-09 17:41:06 +00:00
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
char* getwdir(register char *fn)
|
1987-04-29 10:22:07 +00:00
|
|
|
{
|
2017-01-07 21:56:00 +00:00
|
|
|
register char* p;
|
1987-04-29 10:22:07 +00:00
|
|
|
|
2017-01-07 21:56:00 +00:00
|
|
|
while ((p = strrchr(fn, '/')) && *(p + 1) == '\0')
|
|
|
|
{
|
1988-04-13 18:37:45 +00:00
|
|
|
/* remove trailing /'s */
|
1987-04-29 10:22:07 +00:00
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
|
2017-01-07 21:56:00 +00:00
|
|
|
if (p)
|
|
|
|
{
|
1987-04-29 10:22:07 +00:00
|
|
|
*p = '\0';
|
2017-01-07 21:56:00 +00:00
|
|
|
fn = Salloc(fn, (unsigned)(p - &fn[0] + 1));
|
1987-04-29 10:22:07 +00:00
|
|
|
*p = '/';
|
|
|
|
return fn;
|
|
|
|
}
|
1989-02-16 11:24:01 +00:00
|
|
|
return "";
|
1987-04-29 10:22:07 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
static int GetFile(char *name)
|
1986-04-03 00:44:39 +00:00
|
|
|
{
|
|
|
|
/* Try to find a file with basename "name" and extension ".def",
|
|
|
|
in the directories mentioned in "DEFPATH".
|
|
|
|
*/
|
2017-11-14 02:34:31 +00:00
|
|
|
size_t len;
|
|
|
|
int found;
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
len = strlen(name);
|
|
|
|
buf = Malloc(len + 5);
|
|
|
|
memcpy(buf, name, len);
|
|
|
|
memcpy(buf + len, ".def", 5);
|
1987-04-29 10:22:07 +00:00
|
|
|
DEFPATH[0] = WorkingDir;
|
2017-11-14 02:34:31 +00:00
|
|
|
found = InsertFile(buf, DEFPATH, &(FileName));
|
|
|
|
free(buf);
|
|
|
|
if (!found)
|
2017-01-07 21:56:00 +00:00
|
|
|
{
|
1986-11-26 16:40:45 +00:00
|
|
|
error("could not find a DEFINITION MODULE for \"%s\"", name);
|
1986-11-05 14:33:00 +00:00
|
|
|
return 0;
|
1986-04-03 00:44:39 +00:00
|
|
|
}
|
1987-04-29 10:22:07 +00:00
|
|
|
WorkingDir = getwdir(FileName);
|
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
|
|
|
}
|
|
|
|
|
2019-05-10 17:09:03 +00:00
|
|
|
struct def* GetDefinitionModule(register struct idf* id, int incr)
|
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
|
|
|
*/
|
2019-05-10 17:09:03 +00:00
|
|
|
register struct def* df;
|
1986-05-28 18:36:51 +00:00
|
|
|
static int level;
|
2019-05-10 17:09:03 +00:00
|
|
|
struct scopelist* vis;
|
2017-01-07 21:56:00 +00:00
|
|
|
char* fn = FileName;
|
1987-06-18 15:46:08 +00:00
|
|
|
int ln = LineNumber;
|
2019-05-10 17:09:03 +00:00
|
|
|
struct scope* newsc;
|
1986-04-03 00:44:39 +00:00
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
level += incr;
|
1987-11-11 13:10:08 +00:00
|
|
|
df = lookup(id, GlobalScope, D_IMPORTED, 0);
|
2017-01-07 21:56:00 +00:00
|
|
|
if (!df)
|
|
|
|
{
|
1986-04-03 00:44:39 +00:00
|
|
|
/* Read definition module. Make an exception for SYSTEM.
|
|
|
|
*/
|
1988-04-13 18:37:45 +00:00
|
|
|
extern int ForeignFlag;
|
|
|
|
|
|
|
|
ForeignFlag = 0;
|
1987-04-29 10:22:07 +00:00
|
|
|
DefId = id;
|
1988-04-13 18:37:45 +00:00
|
|
|
open_scope(CLOSEDSCOPE);
|
1988-10-25 17:43:19 +00:00
|
|
|
newsc = CurrentScope;
|
1988-10-13 15:43:23 +00:00
|
|
|
vis = CurrVis;
|
1988-10-25 17:43:19 +00:00
|
|
|
newsc->sc_defmodule = incr;
|
2017-01-07 21:56:00 +00:00
|
|
|
if (!strcmp(id->id_text, "SYSTEM"))
|
|
|
|
{
|
1986-04-03 00:44:39 +00:00
|
|
|
do_SYSTEM();
|
1987-11-11 13:10:08 +00:00
|
|
|
df = lookup(id, GlobalScope, D_IMPORTED, 0);
|
1986-04-03 00:44:39 +00:00
|
|
|
}
|
2017-01-07 21:56:00 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!is_anon_idf(id) && GetFile(id->id_text))
|
|
|
|
{
|
1987-06-18 15:46:08 +00:00
|
|
|
|
2017-01-07 21:56:00 +00:00
|
|
|
char* f = FileName;
|
1986-11-05 14:33:00 +00:00
|
|
|
DefModule();
|
1987-11-11 13:10:08 +00:00
|
|
|
df = lookup(id, GlobalScope, D_IMPORTED, 0);
|
2017-01-07 21:56:00 +00:00
|
|
|
if (level == 1 && (df && !(df->df_flags & D_FOREIGN)))
|
|
|
|
{
|
1986-11-05 14:33:00 +00:00
|
|
|
/* The module is directly imported by
|
1987-04-29 10:22:07 +00:00
|
|
|
the currently defined module, and
|
|
|
|
is not foreign, so we have to
|
|
|
|
remember its name because we have
|
|
|
|
to call its initialization routine
|
1986-11-05 14:33:00 +00:00
|
|
|
*/
|
2019-05-10 17:09:03 +00:00
|
|
|
static struct node* nd_end;
|
|
|
|
register struct node* n;
|
|
|
|
extern struct node* Modules;
|
1986-10-06 20:36:30 +00:00
|
|
|
|
1988-03-23 17:44:25 +00:00
|
|
|
n = dot2leaf(Def);
|
1988-04-13 18:37:45 +00:00
|
|
|
n->nd_def = newsc->sc_definedby;
|
2017-01-07 21:56:00 +00:00
|
|
|
if (nd_end)
|
|
|
|
nd_end->nd_NEXT = n;
|
|
|
|
else
|
|
|
|
Modules = n;
|
1986-11-05 14:33:00 +00:00
|
|
|
nd_end = n;
|
|
|
|
}
|
1993-01-19 15:33:35 +00:00
|
|
|
free(f);
|
1986-05-28 18:36:51 +00:00
|
|
|
}
|
2017-01-07 21:56:00 +00:00
|
|
|
else
|
|
|
|
{
|
1987-11-11 13:10:08 +00:00
|
|
|
df = lookup(id, GlobalScope, D_IMPORTED, 0);
|
1987-06-29 12:46:00 +00:00
|
|
|
newsc->sc_name = id->id_text;
|
1987-04-29 10:22:07 +00:00
|
|
|
}
|
1986-04-03 00:44:39 +00:00
|
|
|
}
|
1988-04-13 18:37:45 +00:00
|
|
|
close_scope(SC_CHKFORW);
|
2017-01-07 21:56:00 +00:00
|
|
|
if (!df)
|
|
|
|
{
|
1986-11-05 14:33:00 +00:00
|
|
|
df = MkDef(id, GlobalScope, D_ERROR);
|
1986-11-17 11:41:28 +00:00
|
|
|
df->mod_vis = vis;
|
1987-06-29 12:46:00 +00:00
|
|
|
newsc->sc_definedby = df;
|
1986-11-05 14:33:00 +00:00
|
|
|
}
|
1986-04-03 00:44:39 +00:00
|
|
|
}
|
2017-01-07 21:56:00 +00:00
|
|
|
else if (df->df_flags & D_BUSY)
|
|
|
|
{
|
1986-12-16 15:22:33 +00:00
|
|
|
error("definition module \"%s\" depends on itself",
|
2017-01-07 21:56:00 +00:00
|
|
|
id->id_text);
|
1986-12-16 15:22:33 +00:00
|
|
|
}
|
2017-01-07 21:56:00 +00:00
|
|
|
else if (df == Defined && level == 1)
|
|
|
|
{
|
1987-07-13 11:49:32 +00:00
|
|
|
error("cannot import from current module \"%s\"", id->id_text);
|
1986-11-17 11:41:28 +00:00
|
|
|
df->df_kind = D_ERROR;
|
|
|
|
}
|
1987-06-18 15:46:08 +00:00
|
|
|
FileName = fn;
|
|
|
|
LineNumber = ln;
|
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;
|
|
|
|
}
|