/* Generated by Nim Compiler v0.12.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 Tpasscontext276005 Tpasscontext276005;
typedef struct Tsym224841 Tsym224841;
typedef struct Tgen559010 Tgen559010;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Tdocumentor383007 Tdocumentor383007;
typedef struct Cell48947 Cell48947;
typedef struct Cellseq48963 Cellseq48963;
typedef struct Gcheap51018 Gcheap51018;
typedef struct Gcstack51016 Gcstack51016;
typedef struct Cellset48959 Cellset48959;
typedef struct Pagedesc48955 Pagedesc48955;
typedef struct Memregion30890 Memregion30890;
typedef struct Smallchunk30842 Smallchunk30842;
typedef struct Llchunk30884 Llchunk30884;
typedef struct Bigchunk30844 Bigchunk30844;
typedef struct Intset30817 Intset30817;
typedef struct Trunk30813 Trunk30813;
typedef struct Avlnode30888 Avlnode30888;
typedef struct Gcstat51014 Gcstat51014;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Stringtableobj145212 Stringtableobj145212;
typedef struct Tidobj197015 Tidobj197015;
typedef struct Ttypeseq224843 Ttypeseq224843;
typedef struct Tscope224835 Tscope224835;
typedef struct TY224944 TY224944;
typedef struct Tstrtable224813 Tstrtable224813;
typedef struct Tsymseq224811 Tsymseq224811;
typedef struct Ttype224847 Ttype224847;
typedef struct Tident197021 Tident197021;
typedef struct Tlineinfo189352 Tlineinfo189352;
typedef struct Tnode224809 Tnode224809;
typedef struct Tloc224823 Tloc224823;
typedef struct Ropeobj175009 Ropeobj175009;
typedef struct Tlib224827 Tlib224827;
typedef struct Rstgenerator346016 Rstgenerator346016;
typedef struct TY346035 TY346035;
typedef struct Table346053 Table346053;
typedef struct Keyvaluepairseq346056 Keyvaluepairseq346056;
typedef struct Exception Exception;
typedef struct TSafePoint TSafePoint;
typedef struct Basechunk30840 Basechunk30840;
typedef struct Freecell30832 Freecell30832;
typedef struct Keyvaluepairseq145210 Keyvaluepairseq145210;
typedef struct Tnodeseq224803 Tnodeseq224803;
typedef struct Tinstantiation224831 Tinstantiation224831;
typedef struct Tlistentry140022 Tlistentry140022;
typedef struct Tocentry346012 Tocentry346012;
typedef struct Rstnode331011 Rstnode331011;
typedef struct Keyvaluepair346059 Keyvaluepair346059;
typedef struct Keyvaluepair145208 Keyvaluepair145208;
typedef struct TY224932 TY224932;
typedef struct Rstnodeseq331009 Rstnodeseq331009;
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  Tpasscontext276005  {
  TNimObject Sup;
NIM_BOOL fromcache;
};
struct  Tgen559010  {
  Tpasscontext276005 Sup;
Tdocumentor383007* doc;
Tsym224841* module;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Cell48947  {
NI refcount;
TNimType* typ;
};
struct  Cellseq48963  {
NI len;
NI cap;
Cell48947** d;
};
struct  Cellset48959  {
NI counter;
NI max;
Pagedesc48955* head;
Pagedesc48955** data;
};
typedef Smallchunk30842* TY30905[512];
typedef Trunk30813* Trunkbuckets30815[256];
struct  Intset30817  {
Trunkbuckets30815 data;
};
struct  Memregion30890  {
NI minlargeobj;
NI maxlargeobj;
TY30905 freesmallchunks;
Llchunk30884* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk30844* freechunkslist;
Intset30817 chunkstarts;
Avlnode30888* root;
Avlnode30888* deleted;
Avlnode30888* last;
Avlnode30888* freeavlnodes;
};
struct  Gcstat51014  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap51018  {
Gcstack51016* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq48963 zct;
Cellseq48963 decstack;
Cellset48959 cycleroots;
Cellseq48963 tempstack;
NI recgclock;
Memregion30890 region;
Gcstat51014 stat;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tidobj197015  {
  TNimObject Sup;
NI id;
};
struct  Tstrtable224813  {
NI counter;
Tsymseq224811* data;
};
struct  Tlineinfo189352  {
NI16 line;
NI16 col;
NI32 fileindex;
};
struct  Tloc224823  {
NU8 k;
NU8 s;
NU16 flags;
Ttype224847* t;
Ropeobj175009* r;
Ropeobj175009* heaproot;
};
struct  Tsym224841  {
  Tidobj197015 Sup;
NU8 kind;
union{
struct {Ttypeseq224843* typeinstcache;
Tscope224835* typscope;
} S1;
struct {TY224944* procinstcache;
Tsym224841* gcunsafetyreason;
} S2;
struct {TY224944* usedgenerics;
Tstrtable224813 tab;
} S3;
struct {Tsym224841* guard;
NI bitsize;
} S4;
} kindU;
NU8 magic;
Ttype224847* typ;
Tident197021* name;
Tlineinfo189352 info;
Tsym224841* owner;
NU32 flags;
Tnode224809* ast;
NU32 options;
NI position;
NI offset;
Tloc224823 loc;
Tlib224827* annex;
Tnode224809* constraint;
};
typedef N_NIMCALL_PTR(NimStringDesc*, Findfilehandler332023) (NimStringDesc* filename);
typedef N_NIMCALL_PTR(void, Msghandler332021) (NimStringDesc* filename, NI line, NI col, NU8 msgkind, NimStringDesc* arg);
typedef NimStringDesc* TY346045[5];
struct  Table346053  {
Keyvaluepairseq346056* data;
NI counter;
};
struct  Rstgenerator346016  {
  TNimObject Sup;
NU8 target;
Stringtableobj145212* config;
NI splitafter;
NI listingcounter;
TY346035* tocpart;
NIM_BOOL hastoc;
NimStringDesc* theindex;
NU8 options;
Findfilehandler332023 findfile;
Msghandler332021 msghandler;
NimStringDesc* filename;
TY346045 meta;
NimStringDesc* currentsection;
Table346053 seenindexterms;
};
typedef Ropeobj175009* Tsections383005[26];
struct  Tdocumentor383007  {
  Rstgenerator346016 Sup;
Ropeobj175009* moddesc;
NI id;
Tsections383005 toc;
Tsections383005 section;
NimStringDesc* indexvalfilename;
NimStringDesc* analytics;
Stringtableobj145212* 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;
} TY19211;
struct  TSafePoint  {
TSafePoint* prev;
NI status;
jmp_buf context;
NIM_BOOL hasRaiseAction;
TY19211 raiseAction;
};
struct  Gcstack51016  {
Gcstack51016* prev;
Gcstack51016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY30821[16];
struct  Pagedesc48955  {
Pagedesc48955* next;
NI key;
TY30821 bits;
};
struct  Basechunk30840  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk30842  {
  Basechunk30840 Sup;
Smallchunk30842* next;
Smallchunk30842* prev;
Freecell30832* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk30884  {
NI size;
NI acc;
Llchunk30884* next;
};
struct  Bigchunk30844  {
  Basechunk30840 Sup;
Bigchunk30844* next;
Bigchunk30844* prev;
NI align;
NF data;
};
struct  Trunk30813  {
Trunk30813* next;
NI key;
TY30821 bits;
};
typedef Avlnode30888* TY30895[2];
struct  Avlnode30888  {
TY30895 link;
NI key;
NI upperbound;
NI level;
};
struct  Stringtableobj145212  {
  TNimObject Sup;
NI counter;
Keyvaluepairseq145210* data;
NU8 mode;
};
struct  Tscope224835  {
NI depthlevel;
Tstrtable224813 symbols;
Tnodeseq224803* usingsyms;
Tscope224835* parent;
};
struct  Ttype224847  {
  Tidobj197015 Sup;
NU8 kind;
NU8 callconv;
NU32 flags;
Ttypeseq224843* sons;
Tnode224809* n;
Tsym224841* owner;
Tsym224841* sym;
Tsym224841* destructor;
Tsym224841* deepcopy;
Tsym224841* assignment;
NI64 size;
NI16 align;
NI16 locklevel;
Tloc224823 loc;
};
struct  Tident197021  {
  Tidobj197015 Sup;
NimStringDesc* s;
Tident197021* next;
NI h;
};
struct  Tnode224809  {
Ttype224847* typ;
Tlineinfo189352 info;
NU16 flags;
NU8 kind;
union{
struct {NI64 intval;
} S1;
struct {NF floatval;
} S2;
struct {NimStringDesc* strval;
} S3;
struct {Tsym224841* sym;
} S4;
struct {Tident197021* ident;
} S5;
struct {Tnodeseq224803* sons;
} S6;
} kindU;
NimStringDesc* comment;
};
struct  Ropeobj175009  {
  TNimObject Sup;
Ropeobj175009* left;
Ropeobj175009* right;
NI length;
NimStringDesc* data;
};
struct  Tlistentry140022  {
  TNimObject Sup;
Tlistentry140022* prev;
Tlistentry140022* next;
};
struct  Tlib224827  {
  Tlistentry140022 Sup;
NU8 kind;
NIM_BOOL generated;
NIM_BOOL isoverriden;
Ropeobj175009* name;
Tnode224809* path;
};
struct  Tocentry346012  {
Rstnode331011* n;
NimStringDesc* refname;
NimStringDesc* header;
};
struct Keyvaluepair346059 {
NI Field0;
NimStringDesc* Field1;
NI Field2;
};
struct  Freecell30832  {
Freecell30832* next;
NI zerofield;
};
struct Keyvaluepair145208 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  Tinstantiation224831  {
Tsym224841* sym;
Ttypeseq224843* concretetypes;
TY224932* usedby;
NI compilesid;
};
struct  Rstnode331011  {
NU8 kind;
NimStringDesc* text;
NI level;
Rstnodeseq331009* sons;
};
struct Ttypeseq224843 {
  TGenericSeq Sup;
  Ttype224847* data[SEQ_DECL_SIZE];
};
struct TY224944 {
  TGenericSeq Sup;
  Tinstantiation224831* data[SEQ_DECL_SIZE];
};
struct Tsymseq224811 {
  TGenericSeq Sup;
  Tsym224841* data[SEQ_DECL_SIZE];
};
struct TY346035 {
  TGenericSeq Sup;
  Tocentry346012 data[SEQ_DECL_SIZE];
};
struct Keyvaluepairseq346056 {
  TGenericSeq Sup;
  Keyvaluepair346059 data[SEQ_DECL_SIZE];
};
struct Keyvaluepairseq145210 {
  TGenericSeq Sup;
  Keyvaluepair145208 data[SEQ_DECL_SIZE];
};
struct Tnodeseq224803 {
  TGenericSeq Sup;
  Tnode224809* data[SEQ_DECL_SIZE];
};
struct TY224932 {
  TGenericSeq Sup;
  NI32 data[SEQ_DECL_SIZE];
};
struct Rstnodeseq331009 {
  TGenericSeq Sup;
  Rstnode331011* data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP5143)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
static N_INLINE(Cell48947*, usrtocell_52646)(void* usr);
static N_INLINE(void, rtladdzct_54204)(Cell48947* c);
N_NOINLINE(void, addzct_52617)(Cellseq48963* s, Cell48947* c);
N_NIMCALL(Tdocumentor383007*, newdocumentor_383065)(NimStringDesc* filename, Stringtableobj145212* config);
N_NIMCALL(NimStringDesc*, tofilename_190655)(NI32 fileidx);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incref_55022)(Cell48947* c);
static N_INLINE(NIM_BOOL, canbecycleroot_52667)(Cell48947* c);
static N_INLINE(void, rtladdcycleroot_53423)(Cell48947* c);
N_NOINLINE(void, incl_49665)(Cellset48959* s, Cell48947* cell);
static N_INLINE(void, decref_54604)(Cell48947* c);
N_NIMCALL(void, generatedoc_384218)(Tdocumentor383007* d, Tnode224809* n);
N_NIMCALL(void, writeoutput_386337)(Tdocumentor383007* d, NimStringDesc* filename, NimStringDesc* outext, NIM_BOOL usewarning);
static N_INLINE(void, pushSafePoint)(TSafePoint* s);
N_NIMCALL(void, generateindex_386318)(Tdocumentor383007* 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(TMP5144, "html", 4);
extern TNimType NTI276005; /* TPassContext */
TNimType NTI559010; /* TGen */
extern TNimType NTI383009; /* PDoc */
extern TNimType NTI224807; /* PSym */
TNimType NTI559012; /* PGen */
extern Gcheap51018 gch_51059;
extern Stringtableobj145212* gconfigvars_166230;
extern NIM_BOOL gwholeproject_166143;
extern TSafePoint* exchandler_20843;
extern TNimType NTI4031; /* IOError */
extern Exception* currexception_20845;
N_NIMCALL(void, TMP5143)(void* p, NI op) {
	Tgen559010* a;
	a = (Tgen559010*)p;
	nimGCvisit((void*)(*a).doc, op);
	nimGCvisit((void*)(*a).module, op);
}

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

static N_INLINE(void, rtladdzct_54204)(Cell48947* c) {
	addzct_52617((&gch_51059.zct), c);
}

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

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

static N_INLINE(void, rtladdcycleroot_53423)(Cell48947* c) {
	{
		if (!!((((NI) ((NI)((*c).refcount & ((NI) 3)))) == ((NI) 3)))) goto LA3;
		(*c).refcount = (NI)((NI)((*c).refcount & ((NI) -4)) | ((NI) 3));
		incl_49665((&gch_51059.cycleroots), c);
	}
	LA3: ;
}

static N_INLINE(void, incref_55022)(Cell48947* c) {
	(*c).refcount = (NI)((NU32)((*c).refcount) + (NU32)(((NI) 8)));
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = canbecycleroot_52667(c);
		if (!LOC3) goto LA4;
		rtladdcycleroot_53423(c);
	}
	LA4: ;
}

static N_INLINE(void, decref_54604)(Cell48947* c) {
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
		rtladdzct_54204(c);
	}
	goto LA1;
	LA3: ;
	{
		NIM_BOOL LOC6;
		LOC6 = 0;
		LOC6 = canbecycleroot_52667(c);
		if (!LOC6) goto LA7;
		rtladdcycleroot_53423(c);
	}
	goto LA1;
	LA7: ;
	LA1: ;
}

static N_INLINE(void, asgnRef)(void** dest, void* src) {
	{
		Cell48947* LOC5;
		if (!!((src == NIM_NIL))) goto LA3;
		LOC5 = 0;
		LOC5 = usrtocell_52646(src);
		incref_55022(LOC5);
	}
	LA3: ;
	{
		Cell48947* LOC10;
		if (!!(((*dest) == NIM_NIL))) goto LA8;
		LOC10 = 0;
		LOC10 = usrtocell_52646((*dest));
		decref_54604(LOC10);
	}
	LA8: ;
	(*dest) = src;
}

N_NIMCALL(Tpasscontext276005*, myopen_559069)(Tsym224841* module) {
	Tpasscontext276005* result;
	Tgen559010* g;
	Tdocumentor383007* d;
	NimStringDesc* LOC1;
	result = 0;
	g = 0;
	g = (Tgen559010*) newObj((&NTI559012), sizeof(Tgen559010));
	(*g).Sup.Sup.m_type = (&NTI559010);
	asgnRefNoCycle((void**) (&(*g).module), module);
	LOC1 = 0;
	LOC1 = tofilename_190655(((NI32) ((*module).position)));
	d = newdocumentor_383065(LOC1, gconfigvars_166230);
	(*d).Sup.hastoc = NIM_TRUE;
	asgnRef((void**) (&(*g).doc), d);
	result = &g->Sup;
	return result;
}

N_NIMCALL(Tnode224809*, processnode_559057)(Tpasscontext276005* c, Tnode224809* n) {
	Tnode224809* result;
	Tgen559010* g;
	result = 0;
	result = n;
	g = ((Tgen559010*) (c));
	generatedoc_384218((*g).doc, n);
	return result;
}

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

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

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

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

N_NIMCALL(Tnode224809*, close_559018)(Tpasscontext276005* p, Tnode224809* n) {
	Tnode224809* result;
	Tgen559010* g;
	NIM_BOOL usewarning;
	result = 0;
	g = ((Tgen559010*) (p));
	usewarning = !((((*(*g).module).flags &(1<<((((NU8) 12))&31)))!=0));
	{
		NIM_BOOL LOC3;
		NimStringDesc* LOC7;
		TSafePoint TMP5145;
		LOC3 = 0;
		LOC3 = gwholeproject_166143;
		if (LOC3) goto LA4;
		LOC3 = (((*(*g).module).flags &(1<<((((NU8) 12))&31)))!=0);
		LA4: ;
		if (!LOC3) goto LA5;
		LOC7 = 0;
		LOC7 = tofilename_190655(((NI32) ((*(*g).module).position)));
		writeoutput_386337((*g).doc, LOC7, ((NimStringDesc*) &TMP5144), usewarning);
		pushSafePoint(&TMP5145);
		TMP5145.status = _setjmp(TMP5145.context);
		if (TMP5145.status == 0) {
			generateindex_386318((*g).doc);
			popSafePoint();
		}
		else {
			popSafePoint();
			if (isObj(getCurrentException()->Sup.m_type, (&NTI4031))) {
				TMP5145.status = 0;
				popCurrentException();
			}
		}
		if (TMP5145.status != 0) reraiseException();
	}
	LA5: ;
	return result;
}

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

NIM_EXTERNC N_NOINLINE(void, compiler_docgen2DatInit000)(void) {
static TNimNode* TMP5142[2];
static TNimNode TMP1148[3];
NTI559010.size = sizeof(Tgen559010);
NTI559010.kind = 17;
NTI559010.base = (&NTI276005);
TMP5142[0] = &TMP1148[1];
TMP1148[1].kind = 1;
TMP1148[1].offset = offsetof(Tgen559010, doc);
TMP1148[1].typ = (&NTI383009);
TMP1148[1].name = "doc";
TMP5142[1] = &TMP1148[2];
TMP1148[2].kind = 1;
TMP1148[2].offset = offsetof(Tgen559010, module);
TMP1148[2].typ = (&NTI224807);
TMP1148[2].name = "module";
TMP1148[0].len = 2; TMP1148[0].kind = 2; TMP1148[0].sons = &TMP5142[0];
NTI559010.node = &TMP1148[0];
NTI559012.size = sizeof(Tgen559010*);
NTI559012.kind = 22;
NTI559012.base = (&NTI559010);
NTI559012.marker = TMP5143;
}

