/* Generated by Nim Compiler v0.12.0 */
/*   (c) 2015 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 64

#include "nimbase.h"
#include <setjmp.h>
typedef struct Tpasscontext277005 Tpasscontext277005;
typedef struct Tsym225841 Tsym225841;
typedef struct Tgen560010 Tgen560010;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Tdocumentor384007 Tdocumentor384007;
typedef struct Cell49146 Cell49146;
typedef struct Cellseq49162 Cellseq49162;
typedef struct Gcheap51218 Gcheap51218;
typedef struct Gcstack51216 Gcstack51216;
typedef struct Cellset49158 Cellset49158;
typedef struct Pagedesc49154 Pagedesc49154;
typedef struct Memregion31091 Memregion31091;
typedef struct Smallchunk31043 Smallchunk31043;
typedef struct Llchunk31085 Llchunk31085;
typedef struct Bigchunk31045 Bigchunk31045;
typedef struct Intset31017 Intset31017;
typedef struct Trunk31013 Trunk31013;
typedef struct Avlnode31089 Avlnode31089;
typedef struct Gcstat51214 Gcstat51214;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Stringtableobj146212 Stringtableobj146212;
typedef struct Tidobj198015 Tidobj198015;
typedef struct Ttypeseq225843 Ttypeseq225843;
typedef struct Tscope225835 Tscope225835;
typedef struct TY225944 TY225944;
typedef struct Tstrtable225813 Tstrtable225813;
typedef struct Tsymseq225811 Tsymseq225811;
typedef struct Ttype225847 Ttype225847;
typedef struct Tident198021 Tident198021;
typedef struct Tlineinfo190352 Tlineinfo190352;
typedef struct Tnode225809 Tnode225809;
typedef struct Tloc225823 Tloc225823;
typedef struct Ropeobj176009 Ropeobj176009;
typedef struct Tlib225827 Tlib225827;
typedef struct Rstgenerator347016 Rstgenerator347016;
typedef struct TY347035 TY347035;
typedef struct Table347053 Table347053;
typedef struct Keyvaluepairseq347056 Keyvaluepairseq347056;
typedef struct Exception Exception;
typedef struct TSafePoint TSafePoint;
typedef struct Basechunk31041 Basechunk31041;
typedef struct Freecell31033 Freecell31033;
typedef struct Keyvaluepairseq146210 Keyvaluepairseq146210;
typedef struct Tnodeseq225803 Tnodeseq225803;
typedef struct Tinstantiation225831 Tinstantiation225831;
typedef struct Tlistentry141022 Tlistentry141022;
typedef struct Tocentry347012 Tocentry347012;
typedef struct Rstnode332011 Rstnode332011;
typedef struct Keyvaluepair347059 Keyvaluepair347059;
typedef struct Keyvaluepair146208 Keyvaluepair146208;
typedef struct TY225932 TY225932;
typedef struct Rstnodeseq332009 Rstnodeseq332009;
typedef N_NIMCALL_PTR(void, TY3889) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3894) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3889 marker;
TY3894 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Tpasscontext277005  {
  TNimObject Sup;
NIM_BOOL fromcache;
};
struct  Tgen560010  {
  Tpasscontext277005 Sup;
Tdocumentor384007* doc;
Tsym225841* module;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Cell49146  {
NI refcount;
TNimType* typ;
};
struct  Cellseq49162  {
NI len;
NI cap;
Cell49146** d;
};
struct  Cellset49158  {
NI counter;
NI max;
Pagedesc49154* head;
Pagedesc49154** data;
};
typedef Smallchunk31043* TY31106[512];
typedef Trunk31013* Trunkbuckets31015[256];
struct  Intset31017  {
Trunkbuckets31015 data;
};
struct  Memregion31091  {
NI minlargeobj;
NI maxlargeobj;
TY31106 freesmallchunks;
Llchunk31085* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk31045* freechunkslist;
Intset31017 chunkstarts;
Avlnode31089* root;
Avlnode31089* deleted;
Avlnode31089* last;
Avlnode31089* freeavlnodes;
};
struct  Gcstat51214  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap51218  {
Gcstack51216* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq49162 zct;
Cellseq49162 decstack;
Cellset49158 cycleroots;
Cellseq49162 tempstack;
NI recgclock;
Memregion31091 region;
Gcstat51214 stat;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tidobj198015  {
  TNimObject Sup;
NI id;
};
struct  Tstrtable225813  {
NI counter;
Tsymseq225811* data;
};
struct  Tlineinfo190352  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  Tloc225823  {
NU8 k;
NU8 s;
NU16 flags;
Ttype225847* t;
Ropeobj176009* r;
Ropeobj176009* heaproot;
};
struct  Tsym225841  {
  Tidobj198015 Sup;
NU8 kind;
union{
struct {Ttypeseq225843* typeinstcache;
Tscope225835* typscope;
} S1;
struct {TY225944* procinstcache;
Tsym225841* gcunsafetyreason;
} S2;
struct {TY225944* usedgenerics;
Tstrtable225813 tab;
} S3;
struct {Tsym225841* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype225847* typ;
Tident198021* name;
Tlineinfo190352 info;
Tsym225841* owner;
NU32 flags;
Tnode225809* ast;
NU32 options;
NI position;
NI offset;
Tloc225823 loc;
Tlib225827* annex;
Tnode225809* constraint;
};
typedef N_NIMCALL_PTR(NimStringDesc*, Findfilehandler333023) (NimStringDesc* filename);
typedef N_NIMCALL_PTR(void, Msghandler333021) (NimStringDesc* filename, NI line, NI col, NU8 msgkind, NimStringDesc* arg);
typedef NimStringDesc* TY347045[5];
struct  Table347053  {
Keyvaluepairseq347056* data;
NI counter;
};
struct  Rstgenerator347016  {
  TNimObject Sup;
NU8 target;
Stringtableobj146212* config;
NI splitafter;
NI listingcounter;
TY347035* tocpart;
NIM_BOOL hastoc;
NimStringDesc* theindex;
NU8 options;
Findfilehandler333023 findfile;
Msghandler333021 msghandler;
NimStringDesc* filename;
TY347045 meta;
NimStringDesc* currentsection;
Table347053 seenindexterms;
};
typedef Ropeobj176009* Tsections384005[26];
struct  Tdocumentor384007  {
  Rstgenerator347016 Sup;
Ropeobj176009* moddesc;
NI id;
Tsections384005 toc;
Tsections384005 section;
NimStringDesc* indexvalfilename;
NimStringDesc* analytics;
Stringtableobj146212* seensymbols;
};
struct  Exception  {
  TNimObject Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
typedef struct {
N_NIMCALL_PTR(NIM_BOOL, ClPrc) (Exception* e, void* ClEnv);
void* ClEnv;
} TY19411;
struct  TSafePoint  {
TSafePoint* prev;
NI status;
jmp_buf context;
NIM_BOOL hasRaiseAction;
TY19411 raiseAction;
};
struct  Gcstack51216  {
Gcstack51216* prev;
Gcstack51216* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY31022[8];
struct  Pagedesc49154  {
Pagedesc49154* next;
NI key;
TY31022 bits;
};
struct  Basechunk31041  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk31043  {
  Basechunk31041 Sup;
Smallchunk31043* next;
Smallchunk31043* prev;
Freecell31033* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk31085  {
NI size;
NI acc;
Llchunk31085* next;
};
struct  Bigchunk31045  {
  Basechunk31041 Sup;
Bigchunk31045* next;
Bigchunk31045* prev;
NI align;
NF data;
};
struct  Trunk31013  {
Trunk31013* next;
NI key;
TY31022 bits;
};
typedef Avlnode31089* TY31096[2];
struct  Avlnode31089  {
TY31096 link;
NI key;
NI upperbound;
NI level;
};
struct  Stringtableobj146212  {
  TNimObject Sup;
NI counter;
Keyvaluepairseq146210* data;
NU8 mode;
};
struct  Tscope225835  {
NI depthlevel;
Tstrtable225813 symbols;
Tnodeseq225803* usingsyms;
Tscope225835* parent;
};
struct  Ttype225847  {
  Tidobj198015 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq225843* sons;
Tnode225809* n;
Tsym225841* owner;
Tsym225841* sym;
Tsym225841* destructor;
Tsym225841* deepcopy;
Tsym225841* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc225823 loc;
};
struct  Tident198021  {
  Tidobj198015 Sup;
NimStringDesc* s;
Tident198021* next;
NI h;
};
struct  Tnode225809  {
Ttype225847* typ;
Tlineinfo190352 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym225841* sym;
} S4;
struct {Tident198021* ident;
} S5;
struct {Tnodeseq225803* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
struct  Ropeobj176009  {
  TNimObject Sup;
Ropeobj176009* left;
Ropeobj176009* right;
NI length;
NimStringDesc* data;
};
struct  Tlistentry141022  {
  TNimObject Sup;
Tlistentry141022* prev;
Tlistentry141022* next;
};
struct  Tlib225827  {
  Tlistentry141022 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj176009* name;
Tnode225809* path;
};
struct  Tocentry347012  {
Rstnode332011* n;
NimStringDesc* refname;
NimStringDesc* header;
};
struct Keyvaluepair347059 {
NI Field0;
NimStringDesc* Field1;
NI Field2;
};
struct  Freecell31033  {
Freecell31033* next;
NI zerofield;
};
struct Keyvaluepair146208 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  Tinstantiation225831  {
Tsym225841* sym;
Ttypeseq225843* concretetypes;
TY225932* usedby;
NI compilesid;
};
struct  Rstnode332011  {
NU8 kind;
NimStringDesc* text;
NI level;
Rstnodeseq332009* sons;
};
struct Ttypeseq225843 {
  TGenericSeq Sup;
  Ttype225847* data[SEQ_DECL_SIZE];
};
struct TY225944 {
  TGenericSeq Sup;
  Tinstantiation225831* data[SEQ_DECL_SIZE];
};
struct Tsymseq225811 {
  TGenericSeq Sup;
  Tsym225841* data[SEQ_DECL_SIZE];
};
struct TY347035 {
  TGenericSeq Sup;
  Tocentry347012 data[SEQ_DECL_SIZE];
};
struct Keyvaluepairseq347056 {
  TGenericSeq Sup;
  Keyvaluepair347059 data[SEQ_DECL_SIZE];
};
struct Keyvaluepairseq146210 {
  TGenericSeq Sup;
  Keyvaluepair146208 data[SEQ_DECL_SIZE];
};
struct Tnodeseq225803 {
  TGenericSeq Sup;
  Tnode225809* data[SEQ_DECL_SIZE];
};
struct TY225932 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
struct Rstnodeseq332009 {
  TGenericSeq Sup;
  Rstnode332011* data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP5139)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell49146*, usrtocell_52846)(void* usr);
static N_INLINE(void, rtladdzct_54404)(Cell49146* c);
N_NOINLINE(void, addzct_52817)(Cellseq49162* s, Cell49146* c);
N_NIMCALL(Tdocumentor384007*, newdocumentor_384065)(NimStringDesc* filename, Stringtableobj146212* config);
N_NIMCALL(NimStringDesc*, tofilename_191652)(NI32 fileidx);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_55222)(Cell49146* c);
static N_INLINE(NIM_BOOL, canbecycleroot_52867)(Cell49146* c);
static N_INLINE(void, rtladdcycleroot_53623)(Cell49146* c);
N_NOINLINE(void, incl_49865)(Cellset49158* s, Cell49146* cell);
static N_INLINE(void, decref_54804)(Cell49146* c);
N_NIMCALL(void, generatedoc_385218)(Tdocumentor384007* d, Tnode225809* n);
N_NIMCALL(void, writeoutput_387337)(Tdocumentor384007* d, NimStringDesc* filename, NimStringDesc* outext, NIM_BOOL usewarning);
static N_INLINE(void, pushSafePoint)(TSafePoint* s);
N_NIMCALL(void, generateindex_387318)(Tdocumentor384007* d);
static N_INLINE(void, popSafePoint)(void);
N_NIMCALL(NIM_BOOL, isObj)(TNimType* obj, TNimType* subclass);
static N_INLINE(Exception*, getCurrentException)(void);
static N_INLINE(void, popCurrentException)(void);
N_NIMCALL(void, reraiseException)(void);
STRING_LITERAL(TMP5140, "html", 4);
extern TNimType NTI277005; /* TPassContext */
TNimType NTI560010; /* TGen */
extern TNimType NTI384009; /* PDoc */
extern TNimType NTI225807; /* PSym */
TNimType NTI560012; /* PGen */
extern Gcheap51218 gch_51259;
extern Stringtableobj146212* gconfigvars_167230;
extern NIM_BOOL gwholeproject_167143;
extern TSafePoint* exchandler_21043;
extern TNimType NTI4031; /* IOError */
extern Exception* currexception_21045;
N_NIMCALL(void, TMP5139)(void* p, NI op) {
	Tgen560010* a;
	a = (Tgen560010*)p;
	nimGCvisit((void*)(*a).doc, op);
	nimGCvisit((void*)(*a).module, op);
}

static N_INLINE(Cell49146*, usrtocell_52846)(void* usr) {
	Cell49146* result;
	result = 0;
	result = ((Cell49146*) ((NI)((NU64)(((NI) (usr))) - (NU64)(((NI)sizeof(Cell49146))))));
	return result;
}

static N_INLINE(void, rtladdzct_54404)(Cell49146* c) {
	addzct_52817((&gch_51259.zct), c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell49146* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_52846(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell49146* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_52846((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU64)((*c).refcount) < (NU64)(((NI) 8)))) goto LA11;
			rtladdzct_54404(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

static N_INLINE(NIM_BOOL, canbecycleroot_52867)(Cell49146* c) {
	NIM_BOOL result;
	result = 0;
	result = !((((*(*c).typ).flags &(1<<((((NU8) 1))&7)))!=0));
	return result;
}

static N_INLINE(void, rtladdcycleroot_53623)(Cell49146* c) {
	{
		if (!!((((NI) ((NI)((*c).refcount & ((NI) 3)))) == ((NI) 3)))) goto LA3;
		(*c).refcount = (NI)((NI)((*c).refcount & ((NI) -4)) | ((NI) 3));
		incl_49865((&gch_51259.cycleroots), c);
	}
	LA3: ;
}

static N_INLINE(void, incref_55222)(Cell49146* c) {
	(*c).refcount = (NI)((NU64)((*c).refcount) + (NU64)(((NI) 8)));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = canbecycleroot_52867(c);
		if (!LOC3) goto LA4;
		rtladdcycleroot_53623(c);
	}
	LA4: ;
}

static N_INLINE(void, decref_54804)(Cell49146* c) {
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU64)((*c).refcount) < (NU64)(((NI) 8)))) goto LA3;
		rtladdzct_54404(c);
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = canbecycleroot_52867(c);
		if (!LOC6) goto LA7;
		rtladdcycleroot_53623(c);
	}
	goto LA1;
	LA7: ;
	LA1: ;
}

static N_INLINE(void, asgnRef)(void** dest, void* src) {
	{
		Cell49146* LOC5;
		if (!!((src == NIM_NIL))) goto LA3;
		LOC5 = 0;
		LOC5 = usrtocell_52846(src);
		incref_55222(LOC5);
	}
	LA3: ;
	{
		Cell49146* LOC10;
		if (!!(((*dest) == NIM_NIL))) goto LA8;
		LOC10 = 0;
		LOC10 = usrtocell_52846((*dest));
		decref_54804(LOC10);
	}
	LA8: ;
	(*dest) = src;
}

N_NIMCALL(Tpasscontext277005*, myopen_560068)(Tsym225841* module) {
	Tpasscontext277005* result;
	Tgen560010* g;
	Tdocumentor384007* d;
	NimStringDesc* LOC1;
	result = 0;
	g = 0;
	g = (Tgen560010*) newObj((&NTI560012), sizeof(Tgen560010));
	(*g).Sup.Sup.m_type = (&NTI560010);
	asgnRefNoCycle((void**) (&(*g).module), module);
	LOC1 = 0;
	LOC1 = tofilename_191652(((NI32) ((*module).position)));
	d = newdocumentor_384065(LOC1, gconfigvars_167230);
	(*d).Sup.hastoc = NIM_TRUE;
	asgnRef((void**) (&(*g).doc), d);
	result = &g->Sup;
	return result;
}

N_NIMCALL(Tnode225809*, processnode_560056)(Tpasscontext277005* c, Tnode225809* n) {
	Tnode225809* result;
	Tgen560010* g;
	result = 0;
	result = n;
	g = ((Tgen560010*) (c));
	generatedoc_385218((*g).doc, n);
	return result;
}

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

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

static N_INLINE(Exception*, getCurrentException)(void) {
	Exception* result;
	result = 0;
	result = currexception_21045;
	return result;
}

static N_INLINE(void, popCurrentException)(void) {
	asgnRef((void**) (&currexception_21045), NIM_NIL);
}

N_NIMCALL(Tnode225809*, close_560018)(Tpasscontext277005* p, Tnode225809* n) {
	Tnode225809* result;
	Tgen560010* g;
	NIM_BOOL usewarning;
	result = 0;
	g = ((Tgen560010*) (p));
	usewarning = !((((*(*g).module).flags &(1<<((((NU8) 12))&31)))!=0));
	{
		NIM_BOOL LOC3;
		NimStringDesc* LOC7;
		TSafePoint TMP5141;
		LOC3 = 0;
		LOC3 = gwholeproject_167143;
		if (LOC3) goto LA4;
		LOC3 = (((*(*g).module).flags &(1<<((((NU8) 12))&31)))!=0);
		LA4: ;
		if (!LOC3) goto LA5;
		LOC7 = 0;
		LOC7 = tofilename_191652(((NI32) ((*(*g).module).position)));
		writeoutput_387337((*g).doc, LOC7, ((NimStringDesc*) &TMP5140), usewarning);
		pushSafePoint(&TMP5141);
		TMP5141.status = _setjmp(TMP5141.context);
		if (TMP5141.status == 0) {
			generateindex_387318((*g).doc);
			popSafePoint();
		}
		else {
			popSafePoint();
			if (isObj(getCurrentException()->Sup.m_type, (&NTI4031))) {
				TMP5141.status = 0;
				popCurrentException();
			}
		}
		if (TMP5141.status != 0) reraiseException();
	}
	LA5: ;
	return result;
}

N_NIMCALL(void, finishdoc2pass_560106)(NimStringDesc* project) {
}
NIM_EXTERNC N_NOINLINE(void, compiler_docgen2Init000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, compiler_docgen2DatInit000)(void) {
static TNimNode* TMP5138[2];
static TNimNode TMP1148[3];
NTI560010.size = sizeof(Tgen560010);
NTI560010.kind = 17;
NTI560010.base = (&NTI277005);
TMP5138[0] = &TMP1148[1];
TMP1148[1].kind = 1;
TMP1148[1].offset = offsetof(Tgen560010, doc);
TMP1148[1].typ = (&NTI384009);
TMP1148[1].name = "doc";
TMP5138[1] = &TMP1148[2];
TMP1148[2].kind = 1;
TMP1148[2].offset = offsetof(Tgen560010, module);
TMP1148[2].typ = (&NTI225807);
TMP1148[2].name = "module";
TMP1148[0].len = 2; TMP1148[0].kind = 2; TMP1148[0].sons = &TMP5138[0];
NTI560010.node = &TMP1148[0];
NTI560012.size = sizeof(Tgen560010*);
NTI560012.kind = 22;
NTI560012.base = (&NTI560010);
NTI560012.marker = TMP5139;
}

