1986-03-26 15:11:02 +00:00
|
|
|
/* O V E R A L L S T R U C T U R E */
|
|
|
|
|
|
|
|
{
|
1986-05-01 19:06:53 +00:00
|
|
|
#include "debug.h"
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
#include <alloc.h>
|
|
|
|
#include <em_arith.h>
|
1986-03-26 22:46:48 +00:00
|
|
|
#include <em_label.h>
|
1986-04-21 17:27:06 +00:00
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
#include "main.h"
|
1986-04-08 18:15:46 +00:00
|
|
|
#include "idf.h"
|
1986-03-26 15:11:02 +00:00
|
|
|
#include "LLlex.h"
|
1986-03-26 17:53:13 +00:00
|
|
|
#include "scope.h"
|
1986-03-26 22:46:48 +00:00
|
|
|
#include "def.h"
|
|
|
|
#include "type.h"
|
1986-04-06 17:42:56 +00:00
|
|
|
#include "node.h"
|
1986-08-26 14:33:24 +00:00
|
|
|
#include "f_info.h"
|
1986-11-05 14:33:00 +00:00
|
|
|
#include "warning.h"
|
1986-04-21 17:27:06 +00:00
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
/*
|
|
|
|
The grammar as given by Wirth is already almost LL(1); the
|
|
|
|
main problem is that the full form of a qualified designator
|
|
|
|
may be:
|
|
|
|
[ module_ident '.' ]* IDENT [ '.' field_ident ]*
|
|
|
|
which is quite confusing to an LL(1) parser. Rather than
|
|
|
|
resorting to context-sensitive techniques, I have decided
|
|
|
|
to render this as:
|
|
|
|
IDENT [ '.' IDENT ]*
|
|
|
|
on the grounds that it is quite natural to consider the first
|
|
|
|
IDENT to be the name of the object and regard the others as
|
|
|
|
field identifiers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
%lexical LLlex;
|
|
|
|
|
|
|
|
%start CompUnit, CompilationUnit;
|
1986-04-03 00:44:39 +00:00
|
|
|
%start DefModule, DefinitionModule;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-03-29 01:04:49 +00:00
|
|
|
ModuleDeclaration
|
|
|
|
{
|
1986-07-08 14:59:02 +00:00
|
|
|
register struct def *df;
|
1986-04-28 18:06:58 +00:00
|
|
|
struct node *exportlist = 0;
|
|
|
|
int qualified;
|
1986-03-29 01:04:49 +00:00
|
|
|
} :
|
1986-10-06 20:36:30 +00:00
|
|
|
MODULE IDENT { df = DefineLocalModule(dot.TOK_IDF); }
|
1986-12-01 10:06:53 +00:00
|
|
|
priority(df)
|
1986-04-17 09:28:09 +00:00
|
|
|
';'
|
1986-03-29 01:04:49 +00:00
|
|
|
import(1)*
|
1986-06-10 13:18:52 +00:00
|
|
|
export(&qualified, &exportlist)?
|
1986-07-08 14:59:02 +00:00
|
|
|
block(&(df->mod_body))
|
|
|
|
IDENT { if (exportlist) {
|
1986-06-10 13:18:52 +00:00
|
|
|
EnterExportList(exportlist, qualified);
|
1986-04-28 18:06:58 +00:00
|
|
|
}
|
1986-04-23 22:12:22 +00:00
|
|
|
close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE);
|
1986-10-06 20:36:30 +00:00
|
|
|
match_id(df->df_idf, dot.TOK_IDF);
|
1986-04-21 17:27:06 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-12-01 10:06:53 +00:00
|
|
|
priority(register struct def *df;)
|
1986-04-06 17:42:56 +00:00
|
|
|
{
|
1986-11-26 16:40:45 +00:00
|
|
|
register struct node *nd;
|
1986-04-17 09:28:09 +00:00
|
|
|
} :
|
1986-12-01 10:06:53 +00:00
|
|
|
[
|
|
|
|
'[' ConstExpression(&(df->mod_priority)) ']'
|
|
|
|
{ if (!(df->mod_priority->nd_type->tp_fund &
|
|
|
|
T_CARDINAL)) {
|
|
|
|
node_error(df->mod_priority,
|
|
|
|
"illegal priority");
|
1986-04-21 17:27:06 +00:00
|
|
|
}
|
|
|
|
}
|
1986-12-01 10:06:53 +00:00
|
|
|
|
|
|
|
|
{ df->mod_priority = 0; }
|
|
|
|
]
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-11-26 16:40:45 +00:00
|
|
|
export(int *QUALflag; struct node **ExportList;):
|
1986-03-26 22:46:48 +00:00
|
|
|
EXPORT
|
|
|
|
[
|
1986-04-21 17:27:06 +00:00
|
|
|
QUALIFIED
|
1986-06-10 13:18:52 +00:00
|
|
|
{ *QUALflag = D_QEXPORTED; }
|
1986-04-28 18:06:58 +00:00
|
|
|
|
|
1986-06-10 13:18:52 +00:00
|
|
|
{ *QUALflag = D_EXPORTED; }
|
1986-04-28 18:06:58 +00:00
|
|
|
]
|
|
|
|
IdentList(ExportList) ';'
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
import(int local;)
|
1986-03-20 14:52:03 +00:00
|
|
|
{
|
1986-04-06 17:42:56 +00:00
|
|
|
struct node *ImportList;
|
1986-11-26 16:40:45 +00:00
|
|
|
register struct node *FromId = 0;
|
1986-08-26 14:33:24 +00:00
|
|
|
register struct def *df;
|
|
|
|
extern struct def *GetDefinitionModule();
|
1986-03-20 14:52:03 +00:00
|
|
|
} :
|
|
|
|
[ FROM
|
1986-11-05 14:33:00 +00:00
|
|
|
IDENT { FromId = MkLeaf(Name, &dot);
|
|
|
|
if (local) df = lookfor(FromId,enclosing(CurrVis),0);
|
|
|
|
else df = GetDefinitionModule(dot.TOK_IDF, 1);
|
1986-08-26 14:33:24 +00:00
|
|
|
}
|
1986-11-05 14:33:00 +00:00
|
|
|
]?
|
1986-03-20 14:52:03 +00:00
|
|
|
IMPORT IdentList(&ImportList) ';'
|
|
|
|
/*
|
|
|
|
When parsing a global module, this is the place where we must
|
|
|
|
read already compiled definition modules.
|
|
|
|
If the FROM clause is present, the identifier in it is a module
|
|
|
|
name, otherwise the names in the import list are module names.
|
|
|
|
*/
|
1986-11-05 14:33:00 +00:00
|
|
|
{ if (FromId) {
|
|
|
|
EnterFromImportList(ImportList, df, FromId);
|
|
|
|
}
|
1986-06-10 13:18:52 +00:00
|
|
|
else EnterImportList(ImportList, local);
|
1986-03-26 15:11:02 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
DefinitionModule
|
|
|
|
{
|
1986-04-03 00:44:39 +00:00
|
|
|
register struct def *df;
|
1986-07-08 14:59:02 +00:00
|
|
|
struct node *exportlist;
|
1986-04-28 18:06:58 +00:00
|
|
|
int dummy;
|
1986-03-26 22:46:48 +00:00
|
|
|
} :
|
1986-04-03 17:41:26 +00:00
|
|
|
DEFINITION
|
1986-10-06 20:36:30 +00:00
|
|
|
MODULE IDENT { df = define(dot.TOK_IDF, GlobalScope, D_MODULE);
|
1986-04-21 17:27:06 +00:00
|
|
|
if (!Defined) Defined = df;
|
1986-10-06 20:36:30 +00:00
|
|
|
CurrentScope->sc_name = df->df_idf->id_text;
|
1986-06-17 12:04:05 +00:00
|
|
|
df->mod_vis = CurrVis;
|
1986-12-01 10:06:53 +00:00
|
|
|
df->df_type = standard_type(T_RECORD, 1, (arith) 1);
|
1986-04-28 18:06:58 +00:00
|
|
|
df->df_type->rec_scope = df->mod_vis->sc_scope;
|
1986-04-18 17:53:47 +00:00
|
|
|
DefinitionModule++;
|
1986-03-26 22:46:48 +00:00
|
|
|
}
|
1986-03-26 15:11:02 +00:00
|
|
|
';'
|
|
|
|
import(0)*
|
1986-07-08 14:59:02 +00:00
|
|
|
[
|
|
|
|
export(&dummy, &exportlist)
|
|
|
|
/* New Modula-2 does not have export lists in definition
|
|
|
|
modules. Issue a warning.
|
|
|
|
*/
|
|
|
|
{
|
1986-11-17 11:41:28 +00:00
|
|
|
node_warning(exportlist, W_OLDFASHIONED, "export list in definition module ignored");
|
1986-06-10 13:18:52 +00:00
|
|
|
FreeNode(exportlist);
|
|
|
|
}
|
1986-07-08 14:59:02 +00:00
|
|
|
|
|
|
|
|
/* empty */
|
|
|
|
]
|
1986-04-03 17:41:26 +00:00
|
|
|
definition* END IDENT
|
1986-10-06 20:36:30 +00:00
|
|
|
{ register struct def *df1 = CurrentScope->sc_def;
|
|
|
|
while (df1) {
|
1986-04-03 00:44:39 +00:00
|
|
|
/* Make all definitions "QUALIFIED EXPORT" */
|
1986-10-06 20:36:30 +00:00
|
|
|
df1->df_flags |= D_QEXPORTED;
|
|
|
|
df1 = df1->df_nextinscope;
|
1986-04-03 00:44:39 +00:00
|
|
|
}
|
1986-04-18 17:53:47 +00:00
|
|
|
DefinitionModule--;
|
1986-10-06 20:36:30 +00:00
|
|
|
match_id(df->df_idf, dot.TOK_IDF);
|
1986-03-29 01:04:49 +00:00
|
|
|
}
|
1986-04-03 17:41:26 +00:00
|
|
|
'.'
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
definition
|
|
|
|
{
|
1986-07-08 14:59:02 +00:00
|
|
|
register struct def *df;
|
|
|
|
struct def *dummy;
|
1986-03-26 22:46:48 +00:00
|
|
|
} :
|
1986-11-28 11:59:08 +00:00
|
|
|
CONST [ %persistent ConstantDeclaration ';' ]*
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
|
TYPE
|
1986-11-28 11:59:08 +00:00
|
|
|
[ %persistent
|
|
|
|
IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); }
|
1986-04-08 18:15:46 +00:00
|
|
|
[ '=' type(&(df->df_type))
|
1986-03-20 14:52:03 +00:00
|
|
|
| /* empty */
|
|
|
|
/*
|
|
|
|
Here, the exported type has a hidden implementation.
|
|
|
|
The export is said to be opaque.
|
|
|
|
It is restricted to pointer types.
|
|
|
|
*/
|
1986-04-15 17:51:53 +00:00
|
|
|
{ df->df_kind = D_HIDDEN;
|
1986-06-04 09:01:48 +00:00
|
|
|
df->df_type = construct_type(T_HIDDEN, NULLTYPE);
|
1986-04-15 17:51:53 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
]
|
1986-11-05 14:33:00 +00:00
|
|
|
';'
|
1986-03-20 14:52:03 +00:00
|
|
|
]*
|
|
|
|
|
|
1986-11-28 11:59:08 +00:00
|
|
|
VAR [ %persistent VariableDeclaration ';' ]*
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
1986-07-08 14:59:02 +00:00
|
|
|
ProcedureHeading(&dummy, D_PROCHEAD)
|
1986-04-17 09:28:09 +00:00
|
|
|
';'
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-05-28 18:36:51 +00:00
|
|
|
ProgramModule
|
1986-04-03 00:44:39 +00:00
|
|
|
{
|
1986-11-17 11:41:28 +00:00
|
|
|
extern struct def *GetDefinitionModule();
|
1986-04-17 09:28:09 +00:00
|
|
|
register struct def *df;
|
1986-03-29 01:04:49 +00:00
|
|
|
} :
|
1986-04-03 17:41:26 +00:00
|
|
|
MODULE
|
1986-10-06 20:36:30 +00:00
|
|
|
IDENT { if (state == IMPLEMENTATION) {
|
|
|
|
df = GetDefinitionModule(dot.TOK_IDF, 0);
|
1986-04-28 18:06:58 +00:00
|
|
|
CurrVis = df->mod_vis;
|
1986-06-04 09:01:48 +00:00
|
|
|
RemoveImports(&(CurrentScope->sc_def));
|
1986-04-17 09:28:09 +00:00
|
|
|
}
|
|
|
|
else {
|
1986-12-01 10:06:53 +00:00
|
|
|
Defined = df = define(dot.TOK_IDF, GlobalScope, D_MODULE);
|
1986-04-17 09:28:09 +00:00
|
|
|
open_scope(CLOSEDSCOPE);
|
1986-04-28 18:06:58 +00:00
|
|
|
df->mod_vis = CurrVis;
|
1986-06-26 09:39:36 +00:00
|
|
|
CurrentScope->sc_name = "_M2M";
|
1986-04-17 09:28:09 +00:00
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
CurrentScope->sc_definedby = df;
|
1986-04-17 09:28:09 +00:00
|
|
|
}
|
1986-12-01 10:06:53 +00:00
|
|
|
priority(df)
|
1986-03-29 01:04:49 +00:00
|
|
|
';' import(0)*
|
1986-07-08 14:59:02 +00:00
|
|
|
block(&(df->mod_body)) IDENT
|
|
|
|
{ close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE);
|
1986-10-06 20:36:30 +00:00
|
|
|
match_id(df->df_idf, dot.TOK_IDF);
|
1986-04-17 09:28:09 +00:00
|
|
|
}
|
1986-03-26 17:53:13 +00:00
|
|
|
'.'
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-05-28 18:36:51 +00:00
|
|
|
Module:
|
1986-11-26 16:40:45 +00:00
|
|
|
DEFINITION
|
|
|
|
{ fatal("Compiling a definition module"); }
|
|
|
|
| %default
|
1986-03-26 15:11:02 +00:00
|
|
|
[
|
|
|
|
IMPLEMENTATION { state = IMPLEMENTATION; }
|
1986-05-28 18:36:51 +00:00
|
|
|
|
|
1986-07-08 14:59:02 +00:00
|
|
|
/* empty */ { state = PROGRAM; }
|
1986-05-28 18:36:51 +00:00
|
|
|
]
|
|
|
|
ProgramModule
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
CompilationUnit:
|
|
|
|
Module
|
|
|
|
;
|