/* Generated by Nimrod Compiler v0.9.5 */
/*   (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, i386, gcc */
/* Command for C compiler:
   gcc -c  -w -O3 -fno-strict-aliasing  -I/build/nimrod/src/nimrod/lib -o compiler/nimcache/docgen2.o compiler/nimcache/docgen2.c */
#define NIM_INTBITS 32
#include "nimbase.h"

#include <setjmp.h>
typedef struct tpasscontext246003 tpasscontext246003;
typedef struct tsym188833 tsym188833;
typedef struct tgen520008 tgen520008;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tdocumentor341005 tdocumentor341005;
typedef struct tcell41090 tcell41090;
typedef struct tcellseq41106 tcellseq41106;
typedef struct tgcheap43016 tgcheap43016;
typedef struct tcellset41102 tcellset41102;
typedef struct tpagedesc41098 tpagedesc41098;
typedef struct tmemregion23410 tmemregion23410;
typedef struct tsmallchunk22638 tsmallchunk22638;
typedef struct tllchunk23404 tllchunk23404;
typedef struct tbigchunk22640 tbigchunk22640;
typedef struct tintset22615 tintset22615;
typedef struct ttrunk22611 ttrunk22611;
typedef struct tavlnode23408 tavlnode23408;
typedef struct tgcstat43014 tgcstat43014;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tstringtable121810 tstringtable121810;
typedef struct tidobj167013 tidobj167013;
typedef struct ttypeseq188835 ttypeseq188835;
typedef struct ttype188837 ttype188837;
typedef struct tscope188827 tscope188827;
typedef struct TY188933 TY188933;
typedef struct tinstantiation188823 tinstantiation188823;
typedef struct tstrtable188807 tstrtable188807;
typedef struct tsymseq188805 tsymseq188805;
typedef struct tident167019 tident167019;
typedef struct tlineinfo163527 tlineinfo163527;
typedef struct tnode188803 tnode188803;
typedef struct tloc188817 tloc188817;
typedef struct trope145007 trope145007;
typedef struct tlib188821 tlib188821;
typedef struct trstgenerator309012 trstgenerator309012;
typedef struct TY309028 TY309028;
typedef struct ttocentry309008 ttocentry309008;
typedef struct trstnode297009 trstnode297009;
typedef struct E_Base E_Base;
typedef struct TSafePoint TSafePoint;
typedef struct tbasechunk22636 tbasechunk22636;
typedef struct tfreecell22628 tfreecell22628;
typedef struct tkeyvaluepairseq121808 tkeyvaluepairseq121808;
typedef struct tkeyvaluepair121806 tkeyvaluepair121806;
typedef struct tnodeseq188797 tnodeseq188797;
typedef struct TY188922 TY188922;
typedef struct tlistentry118017 tlistentry118017;
typedef struct trstnodeseq297007 trstnodeseq297007;
typedef N_NIMCALL_PTR(void, TY2289) (void* p, NI op);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY2289 marker;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  tpasscontext246003  {
  TNimObject Sup;
NIM_BOOL Fromcache;
};
struct  tgen520008  {
  tpasscontext246003 Sup;
tdocumentor341005* Doc;
tsym188833* Module;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  tcell41090  {
NI Refcount;
TNimType* Typ;
};
struct  tcellseq41106  {
NI Len;
NI Cap;
tcell41090** D;
};
struct  tcellset41102  {
NI Counter;
NI Max;
tpagedesc41098* Head;
tpagedesc41098** Data;
};
typedef tsmallchunk22638* TY23422[512];
typedef ttrunk22611* ttrunkbuckets22613[256];
struct  tintset22615  {
ttrunkbuckets22613 Data;
};
struct  tmemregion23410  {
NI Minlargeobj;
NI Maxlargeobj;
TY23422 Freesmallchunks;
tllchunk23404* Llmem;
NI Currmem;
NI Maxmem;
NI Freemem;
NI Lastsize;
tbigchunk22640* Freechunkslist;
tintset22615 Chunkstarts;
tavlnode23408* Root;
tavlnode23408* Deleted;
tavlnode23408* Last;
tavlnode23408* Freeavlnodes;
};
struct  tgcstat43014  {
NI Stackscans;
NI Cyclecollections;
NI Maxthreshold;
NI Maxstacksize;
NI Maxstackcells;
NI Cycletablesize;
NI64 Maxpause;
};
struct  tgcheap43016  {
void* Stackbottom;
NI Cyclethreshold;
tcellseq41106 Zct;
tcellseq41106 Decstack;
tcellset41102 Cycleroots;
tcellseq41106 Tempstack;
NI Recgclock;
tmemregion23410 Region;
tgcstat43014 Stat;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  tidobj167013  {
  TNimObject Sup;
NI Id;
};
struct  tstrtable188807  {
NI Counter;
tsymseq188805* Data;
};
struct  tlineinfo163527  {
NI16 Line;
NI16 Col;
NI32 Fileindex;
};
struct  tloc188817  {
NU8 K;
NU8 S;
NU8 Flags;
ttype188837* T;
trope145007* R;
trope145007* Heaproot;
NI A;
};
struct  tsym188833  {
  tidobj167013 Sup;
NU8 Kind;
union {
struct {ttypeseq188835* Typeinstcache;
tscope188827* Typscope;
} S1;
struct {TY188933* Procinstcache;
tscope188827* Scope;
} S2;
struct {TY188933* Usedgenerics;
tstrtable188807 Tab;
} S3;
} kindU;
NU16 Magic;
ttype188837* Typ;
tident167019* Name;
tlineinfo163527 Info;
tsym188833* Owner;
NU32 Flags;
tnode188803* Ast;
NU32 Options;
NI Position;
NI Offset;
tloc188817 Loc;
tlib188821* Annex;
tnode188803* Constraint;
};
struct  ttocentry309008  {
trstnode297009* N;
NimStringDesc* Refname;
NimStringDesc* Header;
};
typedef N_NIMCALL_PTR(NimStringDesc*, tfindfilehandler298018) (NimStringDesc* filename);
typedef N_NIMCALL_PTR(void, tmsghandler298016) (NimStringDesc* filename, NI line, NI col, NU8 msgkind, NimStringDesc* arg);
typedef NimStringDesc* TY309036[5];
struct  trstgenerator309012  {
  TNimObject Sup;
NU8 Target;
tstringtable121810* Config;
NI Splitafter;
TY309028* Tocpart;
NIM_BOOL Hastoc;
NimStringDesc* Theindex;
NU8 Options;
tfindfilehandler298018 Findfile;
tmsghandler298016 Msghandler;
NimStringDesc* Filename;
TY309036 Meta;
NimStringDesc* Currentsection;
};
typedef trope145007* tsections341003[25];
struct  tdocumentor341005  {
  trstgenerator309012 Sup;
trope145007* Moddesc;
NI Id;
tsections341003 Toc;
tsections341003 Section;
NimStringDesc* Indexvalfilename;
tstringtable121810* Seensymbols;
};
struct  E_Base  {
  TNimObject Sup;
E_Base* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
typedef struct {
N_NIMCALL_PTR(NIM_BOOL, ClPrc) (E_Base* e, void* ClEnv);
void* ClEnv;
} TY11626;
struct  TSafePoint  {
TSafePoint* prev;
NI status;
jmp_buf context;
NIM_BOOL hasRaiseAction;
TY11626 raiseAction;
};
typedef NI TY22618[16];
struct  tpagedesc41098  {
tpagedesc41098* Next;
NI Key;
TY22618 Bits;
};
struct  tbasechunk22636  {
NI Prevsize;
NI Size;
NIM_BOOL Used;
};
struct  tsmallchunk22638  {
  tbasechunk22636 Sup;
tsmallchunk22638* Next;
tsmallchunk22638* Prev;
tfreecell22628* Freelist;
NI Free;
NI Acc;
NF Data;
};
struct  tllchunk23404  {
NI Size;
NI Acc;
tllchunk23404* Next;
};
struct  tbigchunk22640  {
  tbasechunk22636 Sup;
tbigchunk22640* Next;
tbigchunk22640* Prev;
NI Align;
NF Data;
};
struct  ttrunk22611  {
ttrunk22611* Next;
NI Key;
TY22618 Bits;
};
typedef tavlnode23408* TY23414[2];
struct  tavlnode23408  {
TY23414 Link;
NI Key;
NI Upperbound;
NI Level;
};
struct tkeyvaluepair121806 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  tstringtable121810  {
  TNimObject Sup;
NI Counter;
tkeyvaluepairseq121808* Data;
NU8 Mode;
};
struct  ttype188837  {
  tidobj167013 Sup;
NU8 Kind;
NU8 Callconv;
NU32 Flags;
ttypeseq188835* Sons;
tnode188803* N;
tsym188833* Destructor;
tsym188833* Owner;
tsym188833* Sym;
NI64 Size;
NI Align;
tloc188817 Loc;
};
struct  tscope188827  {
NI Depthlevel;
tstrtable188807 Symbols;
tnodeseq188797* Usingsyms;
tscope188827* Parent;
};
struct  tinstantiation188823  {
tsym188833* Sym;
ttypeseq188835* Concretetypes;
TY188922* Usedby;
};
struct  tident167019  {
  tidobj167013 Sup;
NimStringDesc* S;
tident167019* Next;
NI H;
};
struct  tnode188803  {
ttype188837* Typ;
tlineinfo163527 Info;
NU16 Flags;
NU8 Kind;
union {
struct {NI64 Intval;
} S1;
struct {NF Floatval;
} S2;
struct {NimStringDesc* Strval;
} S3;
struct {tsym188833* Sym;
} S4;
struct {tident167019* Ident;
} S5;
struct {tnodeseq188797* Sons;
} S6;
} kindU;
NimStringDesc* Comment;
};
struct  trope145007  {
  TNimObject Sup;
trope145007* Left;
trope145007* Right;
NI Length;
NimStringDesc* Data;
};
struct  tlistentry118017  {
  TNimObject Sup;
tlistentry118017* Prev;
tlistentry118017* Next;
};
struct  tlib188821  {
  tlistentry118017 Sup;
NU8 Kind;
NIM_BOOL Generated;
NIM_BOOL Isoverriden;
trope145007* Name;
tnode188803* Path;
};
struct  trstnode297009  {
NU8 Kind;
NimStringDesc* Text;
NI Level;
trstnodeseq297007* Sons;
};
struct  tfreecell22628  {
tfreecell22628* Next;
NI Zerofield;
};
struct ttypeseq188835 {
  TGenericSeq Sup;
  ttype188837* data[SEQ_DECL_SIZE];
};
struct TY188933 {
  TGenericSeq Sup;
  tinstantiation188823* data[SEQ_DECL_SIZE];
};
struct tsymseq188805 {
  TGenericSeq Sup;
  tsym188833* data[SEQ_DECL_SIZE];
};
struct TY309028 {
  TGenericSeq Sup;
  ttocentry309008 data[SEQ_DECL_SIZE];
};
struct tkeyvaluepairseq121808 {
  TGenericSeq Sup;
  tkeyvaluepair121806 data[SEQ_DECL_SIZE];
};
struct tnodeseq188797 {
  TGenericSeq Sup;
  tnode188803* data[SEQ_DECL_SIZE];
};
struct TY188922 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
struct trstnodeseq297007 {
  TGenericSeq Sup;
  trstnode297009* data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP4449)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(tcell41090*, usrtocell_44443)(void* usr);
static N_INLINE(void, rtladdzct_46002)(tcell41090* c);
N_NOINLINE(void, addzct_44418)(tcellseq41106* s, tcell41090* c);
N_NIMCALL(tdocumentor341005*, newdocumentor_341048)(NimStringDesc* filename, tstringtable121810* config);
N_NIMCALL(NimStringDesc*, tofilename_164780)(NI32 fileidx);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_46827)(tcell41090* c);
static N_INLINE(NIM_BOOL, canbecycleroot_44462)(tcell41090* c);
static N_INLINE(void, rtladdcycleroot_45235)(tcell41090* c);
N_NOINLINE(void, incl_41855)(tcellset41102* s, tcell41090* cell);
static N_INLINE(void, decref_46402)(tcell41090* c);
N_NIMCALL(void, generatedoc_342457)(tdocumentor341005* d, tnode188803* n);
N_NIMCALL(void, writeoutput_344719)(tdocumentor341005* d, NimStringDesc* filename, NimStringDesc* outext, NIM_BOOL usewarning);
static N_INLINE(void, pushSafePoint)(TSafePoint* s);
N_NIMCALL(void, generateindex_344700)(tdocumentor341005* d);
static N_INLINE(void, popSafePoint)(void);
N_NIMCALL(NIM_BOOL, isObj)(TNimType* obj, TNimType* subclass);
static N_INLINE(E_Base*, getCurrentException)(void);
static N_INLINE(void, popCurrentException)(void);
N_NIMCALL(void, reraiseException)(void);
STRING_LITERAL(TMP4450, "html", 4);
extern TNimType NTI246003; /* TPassContext */
TNimType NTI520008; /* TGen */
extern TNimType NTI341007; /* PDoc */
extern TNimType NTI188801; /* PSym */
TNimType NTI520010; /* PGen */
extern tgcheap43016 gch_43044;
extern tstringtable121810* gconfigvars_137203;
extern NIM_BOOL gwholeproject_137122;
extern TSafePoint* exchandler_13039;
extern TNimType NTI2433; /* EIO */
extern E_Base* currexception_13041;
N_NIMCALL(void, TMP4449)(void* p, NI op) {
	tgen520008* a;
	a = (tgen520008*)p;
	nimGCvisit((void*)(*a).Doc, op);
	nimGCvisit((void*)(*a).Module, op);
}

static N_INLINE(tcell41090*, usrtocell_44443)(void* usr) {
	tcell41090* result;
	result = 0;
	result = ((tcell41090*) ((NI)((NU32)(((NI) (usr))) - (NU32)(((NI)sizeof(tcell41090))))));
	return result;
}

static N_INLINE(void, rtladdzct_46002)(tcell41090* c) {
	addzct_44418(&gch_43044.Zct, c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		tcell41090* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_44443(src);
		(*c).Refcount += 8;
	}
	LA3: ;
	{
		tcell41090* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_44443((*dest));
		{
			(*c).Refcount -= 8;
			if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA11;
			rtladdzct_46002(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

static N_INLINE(NIM_BOOL, canbecycleroot_44462)(tcell41090* c) {
	NIM_BOOL result;
	result = 0;
	result = !((((*(*c).Typ).flags &(1<<((((NU8) 1))&7)))!=0));
	return result;
}

static N_INLINE(void, rtladdcycleroot_45235)(tcell41090* c) {
	{
		if (!!((((NI) ((NI)((*c).Refcount & 3))) == 3))) goto LA3;
		(*c).Refcount = (NI)((NI)((*c).Refcount & -4) | 3);
		incl_41855(&gch_43044.Cycleroots, c);
	}
	LA3: ;
}

static N_INLINE(void, incref_46827)(tcell41090* c) {
	(*c).Refcount = (NI)((NU32)((*c).Refcount) + (NU32)(8));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = canbecycleroot_44462(c);
		if (!LOC3) goto LA4;
		rtladdcycleroot_45235(c);
	}
	LA4: ;
}

static N_INLINE(void, decref_46402)(tcell41090* c) {
	{
		(*c).Refcount -= 8;
		if (!((NU32)((*c).Refcount) < (NU32)(8))) goto LA3;
		rtladdzct_46002(c);
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = canbecycleroot_44462(c);
		if (!LOC6) goto LA7;
		rtladdcycleroot_45235(c);
	}
	goto LA1;
	LA7: ;
	LA1: ;
}

static N_INLINE(void, asgnRef)(void** dest, void* src) {
	{
		tcell41090* LOC5;
		if (!!((src == NIM_NIL))) goto LA3;
		LOC5 = 0;
		LOC5 = usrtocell_44443(src);
		incref_46827(LOC5);
	}
	LA3: ;
	{
		tcell41090* LOC10;
		if (!!(((*dest) == NIM_NIL))) goto LA8;
		LOC10 = 0;
		LOC10 = usrtocell_44443((*dest));
		decref_46402(LOC10);
	}
	LA8: ;
	(*dest) = src;
}

N_NIMCALL(tpasscontext246003*, myopen_520058)(tsym188833* module) {
	tpasscontext246003* result;
	tgen520008* g;
	tdocumentor341005* d;
	NimStringDesc* LOC1;
	result = 0;
	g = 0;
	g = (tgen520008*) newObj((&NTI520010), sizeof(tgen520008));
	(*g).Sup.Sup.m_type = (&NTI520008);
	asgnRefNoCycle((void**) &(*g).Module, module);
	LOC1 = 0;
	LOC1 = tofilename_164780(((NI32) ((*module).Position)));
	d = newdocumentor_341048(LOC1, gconfigvars_137203);
	(*d).Sup.Hastoc = NIM_TRUE;
	asgnRef((void**) &(*g).Doc, d);
	result = &g->Sup;
	return result;
}

N_NIMCALL(tnode188803*, processnode_520050)(tpasscontext246003* c, tnode188803* n) {
	tnode188803* result;
	tgen520008* g;
	result = 0;
	result = n;
	g = ((tgen520008*) (c));
	generatedoc_342457((*g).Doc, n);
	return result;
}

static N_INLINE(void, pushSafePoint)(TSafePoint* s) {
	(*s).hasRaiseAction = NIM_FALSE;
	(*s).prev = exchandler_13039;
	exchandler_13039 = s;
}

static N_INLINE(void, popSafePoint)(void) {
	exchandler_13039 = (*exchandler_13039).prev;
}

static N_INLINE(E_Base*, getCurrentException)(void) {
	E_Base* result;
	result = 0;
	result = currexception_13041;
	return result;
}

static N_INLINE(void, popCurrentException)(void) {
	asgnRef((void**) &currexception_13041, (*currexception_13041).parent);
}

N_NIMCALL(tnode188803*, close_520014)(tpasscontext246003* p, tnode188803* n) {
	tnode188803* result;
	tgen520008* g;
	NIM_BOOL usewarning;
	result = 0;
	g = ((tgen520008*) (p));
	usewarning = !((((*(*g).Module).Flags &(1<<((((NU8) 12))&31)))!=0));
	{
		NIM_BOOL LOC3;
		NimStringDesc* LOC7;
		TSafePoint TMP4451;
		LOC3 = 0;
		LOC3 = gwholeproject_137122;
		if (LOC3) goto LA4;
		LOC3 = (((*(*g).Module).Flags &(1<<((((NU8) 12))&31)))!=0);
		LA4: ;
		if (!LOC3) goto LA5;
		LOC7 = 0;
		LOC7 = tofilename_164780(((NI32) ((*(*g).Module).Position)));
		writeoutput_344719((*g).Doc, LOC7, ((NimStringDesc*) &TMP4450), usewarning);
		pushSafePoint(&TMP4451);
		TMP4451.status = setjmp(TMP4451.context);
		if (TMP4451.status == 0) {
			generateindex_344700((*g).Doc);
			popSafePoint();
		}
		else {
			popSafePoint();
			if (isObj(getCurrentException()->Sup.m_type, (&NTI2433))) {
				TMP4451.status = 0;
				popCurrentException();
			}
		}
		if (TMP4451.status != 0) reraiseException();
	}
	LA5: ;
	return result;
}

N_NIMCALL(void, finishdoc2pass_520087)(NimStringDesc* project) {
}
N_NOINLINE(void, docgen2Init)(void) {
}

N_NOINLINE(void, docgen2DatInit)(void) {
static TNimNode* TMP4448[2];
static TNimNode TMP968[3];
NTI520008.size = sizeof(tgen520008);
NTI520008.kind = 17;
NTI520008.base = (&NTI246003);
TMP4448[0] = &TMP968[1];
TMP968[1].kind = 1;
TMP968[1].offset = offsetof(tgen520008, Doc);
TMP968[1].typ = (&NTI341007);
TMP968[1].name = "doc";
TMP4448[1] = &TMP968[2];
TMP968[2].kind = 1;
TMP968[2].offset = offsetof(tgen520008, Module);
TMP968[2].typ = (&NTI188801);
TMP968[2].name = "module";
TMP968[0].len = 2; TMP968[0].kind = 2; TMP968[0].sons = &TMP4448[0];
NTI520008.node = &TMP968[0];
NTI520010.size = sizeof(tgen520008*);
NTI520010.kind = 22;
NTI520010.base = (&NTI520008);
NTI520010.marker = TMP4449;
}

