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

#include "nimbase.h"
#include <setjmp.h>
typedef struct Tpasscontext260002 Tpasscontext260002;
typedef struct Tsym213822 Tsym213822;
typedef struct Tgen514004 Tgen514004;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Tdocumentor358004 Tdocumentor358004;
typedef struct Cell47705 Cell47705;
typedef struct Cellseq47721 Cellseq47721;
typedef struct Gcheap50018 Gcheap50018;
typedef struct Gcstack50016 Gcstack50016;
typedef struct Cellset47717 Cellset47717;
typedef struct Pagedesc47713 Pagedesc47713;
typedef struct Memregion29887 Memregion29887;
typedef struct Smallchunk29839 Smallchunk29839;
typedef struct Llchunk29881 Llchunk29881;
typedef struct Bigchunk29841 Bigchunk29841;
typedef struct Intset29814 Intset29814;
typedef struct Trunk29810 Trunk29810;
typedef struct Avlnode29885 Avlnode29885;
typedef struct Gcstat50014 Gcstat50014;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Stringtableobj140209 Stringtableobj140209;
typedef struct Tidobj188006 Tidobj188006;
typedef struct Ttypeseq213824 Ttypeseq213824;
typedef struct Tscope213816 Tscope213816;
typedef struct TY213925 TY213925;
typedef struct Tstrtable213794 Tstrtable213794;
typedef struct Tsymseq213792 Tsymseq213792;
typedef struct Ttype213828 Ttype213828;
typedef struct Tident188012 Tident188012;
typedef struct Tlineinfo181337 Tlineinfo181337;
typedef struct Tnode213790 Tnode213790;
typedef struct Tloc213804 Tloc213804;
typedef struct Ropeobj168006 Ropeobj168006;
typedef struct Tlib213808 Tlib213808;
typedef struct Rstgenerator325010 Rstgenerator325010;
typedef struct TY325029 TY325029;
typedef struct Table325047 Table325047;
typedef struct Keyvaluepairseq325050 Keyvaluepairseq325050;
typedef struct Exception Exception;
typedef struct TSafePoint TSafePoint;
typedef struct Basechunk29837 Basechunk29837;
typedef struct Freecell29829 Freecell29829;
typedef struct Keyvaluepairseq140207 Keyvaluepairseq140207;
typedef struct Tnodeseq213784 Tnodeseq213784;
typedef struct Tinstantiation213812 Tinstantiation213812;
typedef struct Tlistentry135010 Tlistentry135010;
typedef struct Tocentry325006 Tocentry325006;
typedef struct Rstnode312008 Rstnode312008;
typedef struct Keyvaluepair325053 Keyvaluepair325053;
typedef struct Keyvaluepair140205 Keyvaluepair140205;
typedef struct TY213913 TY213913;
typedef struct Rstnodeseq312006 Rstnodeseq312006;
typedef N_NIMCALL_PTR(void, TY3489) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3494) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3489 marker;
TY3494 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Tpasscontext260002  {
  TNimObject Sup;
NIM_BOOL fromcache;
};
struct  Tgen514004  {
  Tpasscontext260002 Sup;
Tdocumentor358004* doc;
Tsym213822* module;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Cell47705  {
NI refcount;
TNimType* typ;
};
struct  Cellseq47721  {
NI len;
NI cap;
Cell47705** d;
};
struct  Cellset47717  {
NI counter;
NI max;
Pagedesc47713* head;
Pagedesc47713** data;
};
typedef Smallchunk29839* TY29902[512];
typedef Trunk29810* Trunkbuckets29812[256];
struct  Intset29814  {
Trunkbuckets29812 data;
};
struct  Memregion29887  {
NI minlargeobj;
NI maxlargeobj;
TY29902 freesmallchunks;
Llchunk29881* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk29841* freechunkslist;
Intset29814 chunkstarts;
Avlnode29885* root;
Avlnode29885* deleted;
Avlnode29885* last;
Avlnode29885* freeavlnodes;
};
struct  Gcstat50014  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap50018  {
Gcstack50016* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq47721 zct;
Cellseq47721 decstack;
Cellset47717 cycleroots;
Cellseq47721 tempstack;
NI recgclock;
Memregion29887 region;
Gcstat50014 stat;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tidobj188006  {
  TNimObject Sup;
NI id;
};
struct  Tstrtable213794  {
NI counter;
Tsymseq213792* data;
};
struct  Tlineinfo181337  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  Tloc213804  {
NU8 k;
NU8 s;
NU16 flags;
Ttype213828* t;
Ropeobj168006* r;
Ropeobj168006* heaproot;
};
struct  Tsym213822  {
  Tidobj188006 Sup;
NU8 kind;
union{
struct {Ttypeseq213824* typeinstcache;
Tscope213816* typscope;
} S1;
struct {TY213925* procinstcache;
Tsym213822* gcunsafetyreason;
} S2;
struct {TY213925* usedgenerics;
Tstrtable213794 tab;
} S3;
struct {Tsym213822* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype213828* typ;
Tident188012* name;
Tlineinfo181337 info;
Tsym213822* owner;
NU32 flags;
Tnode213790* ast;
NU32 options;
NI position;
NI offset;
Tloc213804 loc;
Tlib213808* annex;
Tnode213790* constraint;
};
typedef N_NIMCALL_PTR(NimStringDesc*, Findfilehandler313014) (NimStringDesc* filename);
typedef N_NIMCALL_PTR(void, Msghandler313012) (NimStringDesc* filename, NI line, NI col, NU8 msgkind, NimStringDesc* arg);
typedef NimStringDesc* TY325039[5];
struct  Table325047  {
Keyvaluepairseq325050* data;
NI counter;
};
struct  Rstgenerator325010  {
  TNimObject Sup;
NU8 target;
Stringtableobj140209* config;
NI splitafter;
NI listingcounter;
TY325029* tocpart;
NIM_BOOL hastoc;
NimStringDesc* theindex;
NU8 options;
Findfilehandler313014 findfile;
Msghandler313012 msghandler;
NimStringDesc* filename;
TY325039 meta;
NimStringDesc* currentsection;
Table325047 seenindexterms;
};
typedef Ropeobj168006* Tsections358002[25];
struct  Tdocumentor358004  {
  Rstgenerator325010 Sup;
Ropeobj168006* moddesc;
NI id;
Tsections358002 toc;
Tsections358002 section;
NimStringDesc* indexvalfilename;
NimStringDesc* analytics;
Stringtableobj140209* 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;
} TY18011;
struct  TSafePoint  {
TSafePoint* prev;
NI status;
jmp_buf context;
NIM_BOOL hasRaiseAction;
TY18011 raiseAction;
};
struct  Gcstack50016  {
Gcstack50016* prev;
Gcstack50016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29818[16];
struct  Pagedesc47713  {
Pagedesc47713* next;
NI key;
TY29818 bits;
};
struct  Basechunk29837  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk29839  {
  Basechunk29837 Sup;
Smallchunk29839* next;
Smallchunk29839* prev;
Freecell29829* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk29881  {
NI size;
NI acc;
Llchunk29881* next;
};
struct  Bigchunk29841  {
  Basechunk29837 Sup;
Bigchunk29841* next;
Bigchunk29841* prev;
NI align;
NF data;
};
struct  Trunk29810  {
Trunk29810* next;
NI key;
TY29818 bits;
};
typedef Avlnode29885* TY29892[2];
struct  Avlnode29885  {
TY29892 link;
NI key;
NI upperbound;
NI level;
};
struct  Stringtableobj140209  {
  TNimObject Sup;
NI counter;
Keyvaluepairseq140207* data;
NU8 mode;
};
struct  Tscope213816  {
NI depthlevel;
Tstrtable213794 symbols;
Tnodeseq213784* usingsyms;
Tscope213816* parent;
};
struct  Ttype213828  {
  Tidobj188006 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq213824* sons;
Tnode213790* n;
Tsym213822* owner;
Tsym213822* sym;
Tsym213822* destructor;
Tsym213822* deepcopy;
Tsym213822* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc213804 loc;
};
struct  Tident188012  {
  Tidobj188006 Sup;
NimStringDesc* s;
Tident188012* next;
NI h;
};
struct  Tnode213790  {
Ttype213828* typ;
Tlineinfo181337 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym213822* sym;
} S4;
struct {Tident188012* ident;
} S5;
struct {Tnodeseq213784* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
struct  Ropeobj168006  {
  TNimObject Sup;
Ropeobj168006* left;
Ropeobj168006* right;
NI length;
NimStringDesc* data;
};
struct  Tlistentry135010  {
  TNimObject Sup;
Tlistentry135010* prev;
Tlistentry135010* next;
};
struct  Tlib213808  {
  Tlistentry135010 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj168006* name;
Tnode213790* path;
};
struct  Tocentry325006  {
Rstnode312008* n;
NimStringDesc* refname;
NimStringDesc* header;
};
struct Keyvaluepair325053 {
NI Field0;
NimStringDesc* Field1;
NI Field2;
};
struct  Freecell29829  {
Freecell29829* next;
NI zerofield;
};
struct Keyvaluepair140205 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  Tinstantiation213812  {
Tsym213822* sym;
Ttypeseq213824* concretetypes;
TY213913* usedby;
NI compilesid;
};
struct  Rstnode312008  {
NU8 kind;
NimStringDesc* text;
NI level;
Rstnodeseq312006* sons;
};
struct Ttypeseq213824 {
  TGenericSeq Sup;
  Ttype213828* data[SEQ_DECL_SIZE];
};
struct TY213925 {
  TGenericSeq Sup;
  Tinstantiation213812* data[SEQ_DECL_SIZE];
};
struct Tsymseq213792 {
  TGenericSeq Sup;
  Tsym213822* data[SEQ_DECL_SIZE];
};
struct TY325029 {
  TGenericSeq Sup;
  Tocentry325006 data[SEQ_DECL_SIZE];
};
struct Keyvaluepairseq325050 {
  TGenericSeq Sup;
  Keyvaluepair325053 data[SEQ_DECL_SIZE];
};
struct Keyvaluepairseq140207 {
  TGenericSeq Sup;
  Keyvaluepair140205 data[SEQ_DECL_SIZE];
};
struct Tnodeseq213784 {
  TGenericSeq Sup;
  Tnode213790* data[SEQ_DECL_SIZE];
};
struct TY213913 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
struct Rstnodeseq312006 {
  TGenericSeq Sup;
  Rstnode312008* data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP5158)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell47705*, usrtocell_51640)(void* usr);
static N_INLINE(void, rtladdzct_53201)(Cell47705* c);
N_NOINLINE(void, addzct_51617)(Cellseq47721* s, Cell47705* c);
N_NIMCALL(Tdocumentor358004*, newdocumentor_358041)(NimStringDesc* filename, Stringtableobj140209* config);
N_NIMCALL(NimStringDesc*, tofilename_182265)(NI32 fileidx);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_54019)(Cell47705* c);
static N_INLINE(NIM_BOOL, canbecycleroot_51658)(Cell47705* c);
static N_INLINE(void, rtladdcycleroot_52420)(Cell47705* c);
N_NOINLINE(void, incl_48447)(Cellset47717* s, Cell47705* cell);
static N_INLINE(void, decref_53601)(Cell47705* c);
N_NIMCALL(void, generatedoc_358976)(Tdocumentor358004* d, Tnode213790* n);
N_NIMCALL(void, writeoutput_360697)(Tdocumentor358004* d, NimStringDesc* filename, NimStringDesc* outext, NIM_BOOL usewarning);
static N_INLINE(void, pushSafePoint)(TSafePoint* s);
N_NIMCALL(void, generateindex_360684)(Tdocumentor358004* 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(TMP5159, "html", 4);
extern TNimType NTI260002; /* TPassContext */
TNimType NTI514004; /* TGen */
extern TNimType NTI358006; /* PDoc */
extern TNimType NTI213788; /* PSym */
TNimType NTI514006; /* PGen */
extern Gcheap50018 gch_50059;
extern Stringtableobj140209* gconfigvars_159195;
extern NIM_BOOL gwholeproject_159132;
extern TSafePoint* exchandler_19637;
extern TNimType NTI3628; /* IOError */
extern Exception* currexception_19639;
N_NIMCALL(void, TMP5158)(void* p, NI op) {
	Tgen514004* a;
	a = (Tgen514004*)p;
	nimGCvisit((void*)(*a).doc, op);
	nimGCvisit((void*)(*a).module, op);
}

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

static N_INLINE(void, rtladdzct_53201)(Cell47705* c) {
	addzct_51617((&gch_50059.zct), c);
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell47705* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_51640(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell47705* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_51640((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA11;
			rtladdzct_53201(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

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

static N_INLINE(void, rtladdcycleroot_52420)(Cell47705* c) {
	{
		if (!!((((NI) ((NI)((*c).refcount & ((NI) 3)))) == ((NI) 3)))) goto LA3;
		(*c).refcount = (NI)((NI)((*c).refcount & ((NI) -4)) | ((NI) 3));
		incl_48447((&gch_50059.cycleroots), c);
	}
	LA3: ;
}

static N_INLINE(void, incref_54019)(Cell47705* c) {
	(*c).refcount = (NI)((NU32)((*c).refcount) + (NU32)(((NI) 8)));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = canbecycleroot_51658(c);
		if (!LOC3) goto LA4;
		rtladdcycleroot_52420(c);
	}
	LA4: ;
}

static N_INLINE(void, decref_53601)(Cell47705* c) {
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
		rtladdzct_53201(c);
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = canbecycleroot_51658(c);
		if (!LOC6) goto LA7;
		rtladdcycleroot_52420(c);
	}
	goto LA1;
	LA7: ;
	LA1: ;
}

static N_INLINE(void, asgnRef)(void** dest, void* src) {
	{
		Cell47705* LOC5;
		if (!!((src == NIM_NIL))) goto LA3;
		LOC5 = 0;
		LOC5 = usrtocell_51640(src);
		incref_54019(LOC5);
	}
	LA3: ;
	{
		Cell47705* LOC10;
		if (!!(((*dest) == NIM_NIL))) goto LA8;
		LOC10 = 0;
		LOC10 = usrtocell_51640((*dest));
		decref_53601(LOC10);
	}
	LA8: ;
	(*dest) = src;
}

N_NIMCALL(Tpasscontext260002*, myopen_514048)(Tsym213822* module) {
	Tpasscontext260002* result;
	Tgen514004* g;
	Tdocumentor358004* d;
	NimStringDesc* LOC1;
	result = 0;
	g = 0;
	g = (Tgen514004*) newObj((&NTI514006), sizeof(Tgen514004));
	(*g).Sup.Sup.m_type = (&NTI514004);
	asgnRefNoCycle((void**) (&(*g).module), module);
	LOC1 = 0;
	LOC1 = tofilename_182265(((NI32) ((*module).position)));
	d = newdocumentor_358041(LOC1, gconfigvars_159195);
	(*d).Sup.hastoc = NIM_TRUE;
	asgnRef((void**) (&(*g).doc), d);
	result = &g->Sup;
	return result;
}

N_NIMCALL(Tnode213790*, processnode_514042)(Tpasscontext260002* c, Tnode213790* n) {
	Tnode213790* result;
	Tgen514004* g;
	result = 0;
	result = n;
	g = ((Tgen514004*) (c));
	generatedoc_358976((*g).doc, n);
	return result;
}

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

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

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

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

N_NIMCALL(Tnode213790*, close_514009)(Tpasscontext260002* p, Tnode213790* n) {
	Tnode213790* result;
	Tgen514004* g;
	NIM_BOOL usewarning;
	result = 0;
	g = ((Tgen514004*) (p));
	usewarning = !((((*(*g).module).flags &(1U<<((NU)(((NU8) 12))&31U)))!=0));
	{
		NIM_BOOL LOC3;
		NimStringDesc* LOC7;
		TSafePoint TMP5160;
		LOC3 = 0;
		LOC3 = gwholeproject_159132;
		if (LOC3) goto LA4;
		LOC3 = (((*(*g).module).flags &(1U<<((NU)(((NU8) 12))&31U)))!=0);
		LA4: ;
		if (!LOC3) goto LA5;
		LOC7 = 0;
		LOC7 = tofilename_182265(((NI32) ((*(*g).module).position)));
		writeoutput_360697((*g).doc, LOC7, ((NimStringDesc*) &TMP5159), usewarning);
		pushSafePoint(&TMP5160);
		TMP5160.status = _setjmp(TMP5160.context);
		if (TMP5160.status == 0) {
			generateindex_360684((*g).doc);
			popSafePoint();
		}
		else {
			popSafePoint();
			if (isObj(getCurrentException()->Sup.m_type, (&NTI3628))) {
				TMP5160.status = 0;
				popCurrentException();
			}
		}
		if (TMP5160.status != 0) reraiseException();
	}
	LA5: ;
	return result;
}

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

NIM_EXTERNC N_NOINLINE(void, compiler_docgen2DatInit000)(void) {
static TNimNode* TMP5157[2];
static TNimNode TMP1185[3];
NTI514004.size = sizeof(Tgen514004);
NTI514004.kind = 17;
NTI514004.base = (&NTI260002);
TMP5157[0] = &TMP1185[1];
TMP1185[1].kind = 1;
TMP1185[1].offset = offsetof(Tgen514004, doc);
TMP1185[1].typ = (&NTI358006);
TMP1185[1].name = "doc";
TMP5157[1] = &TMP1185[2];
TMP1185[2].kind = 1;
TMP1185[2].offset = offsetof(Tgen514004, module);
TMP1185[2].typ = (&NTI213788);
TMP1185[2].name = "module";
TMP1185[0].len = 2; TMP1185[0].kind = 2; TMP1185[0].sons = &TMP5157[0];
NTI514004.node = &TMP1185[0];
NTI514006.size = sizeof(Tgen514004*);
NTI514006.kind = 22;
NTI514006.base = (&NTI514004);
NTI514006.marker = TMP5158;
}

