2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
8 /* O V E R A L L S T R U C T U R E */
10 /* $Id: program.g,v 1.72 1997/02/21 17:10:13 ceriel Exp $ */
22 #include "strict3rd.h"
34 extern t_def *GetDefinitionModule();
38 The grammar as given by Wirth is already almost LL(1); the
39 main problem is that the full form of a qualified designator
41 [ module_ident '.' ]* IDENT [ '.' field_ident ]*
42 which is quite confusing to an LL(1) parser. Rather than
43 resorting to context-sensitive techniques, I have decided
46 on the grounds that it is quite natural to consider the first
47 IDENT to be the name of the object and regard the others as
53 %start CompUnit, CompilationUnit;
54 %start DefModule, DefinitionModule;
62 MODULE IDENT { df = DefineLocalModule(dot.TOK_IDF); }
63 priority(&(df->mod_priority))
66 export(&qualified, &exportlist)
67 block(&(df->mod_body))
68 IDENT { EnterExportList(exportlist, qualified);
69 close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE);
70 match_id(df->df_idf, dot.TOK_IDF);
74 priority(register t_node **prio;):
76 '[' ConstExpression(prio) ']'
77 { if (! ((*prio)->nd_type->tp_fund & T_CARDINAL)) {
78 node_error(*prio, "illegal priority");
85 export(int *QUALflag; t_node **ExportList;):
86 { *ExportList = 0; *QUALflag = D_EXPORTED; }
91 { *QUALflag = D_QEXPORTED; }
94 IdentList(ExportList) ';'
102 register t_node *FromId = 0;
106 When parsing a global module, this is the place where we must
107 read already compiled definition modules.
108 If the FROM clause is present, the identifier in it is a module
109 name, otherwise the names in the import list are module names.
113 %substart DefinitionModule;
114 { FromId = dot2leaf(Name);
116 df = lookfor(FromId,enclosing(CurrVis),0,D_USED);
118 else df = GetDefinitionModule(dot.TOK_IDF, 1);
121 IMPORT IdentList(&ImportList) ';'
122 %substart DefinitionModule;
124 EnterFromImportList(ImportList, df, FromId);
127 EnterImportList(ImportList,
129 enclosing(CurrVis)->sc_scope);
131 FreeNode(ImportList);
141 extern int ForeignFlag;
142 extern char *sprint();
143 register t_scope *currscope = CurrentScope;
147 MODULE IDENT { df = define(dot.TOK_IDF, GlobalScope, D_MODULE);
148 df->df_flags |= D_BUSY | ForeignFlag;
149 currscope->sc_definedby = df;
151 df->df_idf != DefId &&
152 !is_anon_idf(df->df_idf)) {
153 error("DEFINITION MODULE name is \"%s\", not \"%s\"",
154 df->df_idf->id_text, DefId->id_text);
156 sprint(buf, "_%s_", df->df_idf->id_text);
157 currscope->sc_name = Salloc(buf, (unsigned) strlen(buf) + 1);
158 df->mod_vis = CurrVis;
159 df->df_type = standard_type(T_RECORD, 1, (arith) 1);
160 df->df_type->rec_scope = currscope;
168 export(&dummy, &exportlist)
169 /* New Modula-2 does not have export lists in definition
170 modules. Issue a warning.
174 #ifndef STRICT_3RD_ED
176 node_warning(exportlist, W_OLDFASHIONED, "export list in definition module ignored");
179 error("export list not allowed in definition module");
180 FreeNode(exportlist);
183 definition* END IDENT
184 { end_definition_list(&(currscope->sc_def));
186 match_id(dot.TOK_IDF, df->df_idf);
187 df->df_flags &= ~D_BUSY;
197 CONST [ %persistent ConstantDeclaration ';' ]*
201 IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); }
202 [ '=' type(&(df->df_type))
203 { SolveForwardTypeRefs(df); }
206 Here, the exported type has a hidden implementation.
207 The export is said to be opaque.
208 It is restricted to pointer types.
210 { df->df_kind = D_HIDDEN;
211 df->df_type = construct_type(T_HIDDEN, NULLTYPE);
216 if (options['g']) stb_string(df, D_TYPE);
222 VAR [ %persistent VariableDeclaration ';' ]*
224 ProcedureHeading(&dummy, D_PROCHEAD) ';'
233 %substart DefinitionModule;
235 if (state == IMPLEMENTATION) {
236 int len = strlen(dot.TOK_IDF->id_text);
238 if (len > 10) len = 10;
239 if (strncmp(FileName, dot.TOK_IDF->id_text, len)) {
240 warning(W_ORDINARY, "modulename %s does not match filename %s", dot.TOK_IDF->id_text, FileName);
242 df = GetDefinitionModule(dot.TOK_IDF, 0);
243 CurrVis = df->mod_vis;
246 Defined = df = define(dot.TOK_IDF, GlobalScope, D_MODULE);
247 open_scope(CLOSEDSCOPE);
248 df->mod_vis = CurrVis;
249 CurrentScope->sc_name = "__M2M_";
250 CurrentScope->sc_definedby = df;
253 priority(&(df->mod_priority))
255 block(&(df->mod_body)) IDENT
257 close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE);
258 match_id(df->df_idf, dot.TOK_IDF);
264 { error("Compiling a definition module");
265 open_scope(CLOSEDSCOPE);
269 { close_scope(SC_CHKFORW); }
273 { state = IMPLEMENTATION; }