Run through clang-format.

This commit is contained in:
David Given 2017-01-07 22:56:00 +01:00
parent cca6171e55
commit d50a6f99de

View file

@ -9,48 +9,49 @@
/* $Id$ */ /* $Id$ */
#include "debug.h"
#include "parameters.h" #include "parameters.h"
#include "debug.h"
#include <alloc.h>
#include <assert.h>
#include <em_arith.h>
#include <em_label.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <em_arith.h>
#include <em_label.h>
#include <alloc.h>
#include "idf.h" #include "LLlex.h"
#include "input.h" #include "Lpars.h"
#include "scope.h" #include "def.h"
#include "LLlex.h" #include "f_info.h"
#include "def.h" #include "idf.h"
#include "Lpars.h" #include "input.h"
#include "f_info.h" #include "main.h"
#include "main.h" #include "misc.h"
#include "node.h" #include "node.h"
#include "type.h" #include "scope.h"
#include "misc.h" #include "type.h"
#ifdef DEBUG #ifdef DEBUG
long sys_filesize(); long sys_filesize();
#endif #endif
t_idf *DefId; t_idf* DefId;
char * char*
getwdir(fn) getwdir(fn) register char* fn;
register char *fn;
{ {
register char *p; register char* p;
char *strrchr(); char* strrchr();
while ((p = strrchr(fn,'/')) && *(p + 1) == '\0') { while ((p = strrchr(fn, '/')) && *(p + 1) == '\0')
{
/* remove trailing /'s */ /* remove trailing /'s */
*p = '\0'; *p = '\0';
} }
if (p) { if (p)
{
*p = '\0'; *p = '\0';
fn = Salloc(fn, (unsigned) (p - &fn[0] + 1)); fn = Salloc(fn, (unsigned)(p - &fn[0] + 1));
*p = '/'; *p = '/';
return fn; return fn;
} }
@ -58,8 +59,7 @@ getwdir(fn)
} }
STATIC STATIC
GetFile(name) GetFile(name) char* name;
char *name;
{ {
/* Try to find a file with basename "name" and extension ".def", /* Try to find a file with basename "name" and extension ".def",
in the directories mentioned in "DEFPATH". in the directories mentioned in "DEFPATH".
@ -68,10 +68,11 @@ GetFile(name)
char *strncpy(), *strcat(); char *strncpy(), *strcat();
strncpy(buf, name, 10); strncpy(buf, name, 10);
buf[10] = '\0'; /* maximum length */ buf[10] = '\0'; /* maximum length */
strcat(buf, ".def"); strcat(buf, ".def");
DEFPATH[0] = WorkingDir; DEFPATH[0] = WorkingDir;
if (! InsertFile(buf, DEFPATH, &(FileName))) { if (!InsertFile(buf, DEFPATH, &(FileName)))
{
error("could not find a DEFINITION MODULE for \"%s\"", name); error("could not find a DEFINITION MODULE for \"%s\"", name);
return 0; return 0;
} }
@ -81,25 +82,25 @@ GetFile(name)
return 1; return 1;
} }
t_def * t_def*
GetDefinitionModule(id, incr) GetDefinitionModule(id, incr) register t_idf* id;
register t_idf *id;
{ {
/* Return a pointer to the "def" structure of the definition /* Return a pointer to the "def" structure of the definition
module indicated by "id". module indicated by "id".
We may have to read the definition module itself. We may have to read the definition module itself.
Also increment level by "incr". Also increment level by "incr".
*/ */
register t_def *df; register t_def* df;
static int level; static int level;
t_scopelist *vis; t_scopelist* vis;
char *fn = FileName; char* fn = FileName;
int ln = LineNumber; int ln = LineNumber;
t_scope *newsc; t_scope* newsc;
level += incr; level += incr;
df = lookup(id, GlobalScope, D_IMPORTED, 0); df = lookup(id, GlobalScope, D_IMPORTED, 0);
if (!df) { if (!df)
{
/* Read definition module. Make an exception for SYSTEM. /* Read definition module. Make an exception for SYSTEM.
*/ */
extern int ForeignFlag; extern int ForeignFlag;
@ -110,53 +111,62 @@ GetDefinitionModule(id, incr)
newsc = CurrentScope; newsc = CurrentScope;
vis = CurrVis; vis = CurrVis;
newsc->sc_defmodule = incr; newsc->sc_defmodule = incr;
if (!strcmp(id->id_text, "SYSTEM")) { if (!strcmp(id->id_text, "SYSTEM"))
{
do_SYSTEM(); do_SYSTEM();
df = lookup(id, GlobalScope, D_IMPORTED, 0); df = lookup(id, GlobalScope, D_IMPORTED, 0);
} }
else { else
if (!is_anon_idf(id) && GetFile(id->id_text)) { {
if (!is_anon_idf(id) && GetFile(id->id_text))
{
char *f = FileName; char* f = FileName;
DefModule(); DefModule();
df = lookup(id, GlobalScope, D_IMPORTED, 0); df = lookup(id, GlobalScope, D_IMPORTED, 0);
if (level == 1 && if (level == 1 && (df && !(df->df_flags & D_FOREIGN)))
(df && !(df->df_flags & D_FOREIGN))) { {
/* The module is directly imported by /* The module is directly imported by
the currently defined module, and the currently defined module, and
is not foreign, so we have to is not foreign, so we have to
remember its name because we have remember its name because we have
to call its initialization routine to call its initialization routine
*/ */
static t_node *nd_end; static t_node* nd_end;
register t_node *n; register t_node* n;
extern t_node *Modules; extern t_node* Modules;
n = dot2leaf(Def); n = dot2leaf(Def);
n->nd_def = newsc->sc_definedby; n->nd_def = newsc->sc_definedby;
if (nd_end) nd_end->nd_NEXT = n; if (nd_end)
else Modules = n; nd_end->nd_NEXT = n;
else
Modules = n;
nd_end = n; nd_end = n;
} }
free(f); free(f);
} }
else { else
{
df = lookup(id, GlobalScope, D_IMPORTED, 0); df = lookup(id, GlobalScope, D_IMPORTED, 0);
newsc->sc_name = id->id_text; newsc->sc_name = id->id_text;
} }
} }
close_scope(SC_CHKFORW); close_scope(SC_CHKFORW);
if (! df) { if (!df)
{
df = MkDef(id, GlobalScope, D_ERROR); df = MkDef(id, GlobalScope, D_ERROR);
df->mod_vis = vis; df->mod_vis = vis;
newsc->sc_definedby = df; newsc->sc_definedby = df;
} }
} }
else if (df->df_flags & D_BUSY) { else if (df->df_flags & D_BUSY)
{
error("definition module \"%s\" depends on itself", error("definition module \"%s\" depends on itself",
id->id_text); id->id_text);
} }
else if (df == Defined && level == 1) { else if (df == Defined && level == 1)
{
error("cannot import from current module \"%s\"", id->id_text); error("cannot import from current module \"%s\"", id->id_text);
df->df_kind = D_ERROR; df->df_kind = D_ERROR;
} }