Index: src/AST/Attribute.hpp
===================================================================
--- src/AST/Attribute.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Attribute.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -47,4 +47,13 @@
 };
 
+
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Attribute * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class Attribute * node, Node::ref_type ref ) { node->decrement( ref ); }
 }
 
Index: src/AST/Bitfield.hpp
===================================================================
--- src/AST/Bitfield.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Bitfield.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -22,44 +22,53 @@
 /// does not allow it. Requires type to have `unsigned val` field
 /// @param BFType  Name of containing type
-#define MakeBitfield( BFType )                                         \
-	constexpr BFType() : val( 0 ) {}                                   \
-	constexpr BFType( unsigned int v ) : val( v ) {}                   \
-	bool operator[]( unsigned int i ) const { return val & (1 << i); } \
-	bool any() const { return val != 0; }                              \
-	void reset() { val = 0; }                                          \
-	int ffs() { return ::ffs( val ) - 1; }                             \
-	BFType operator&=( BFType other ) {                                \
-		val &= other.val; return *this;                                \
-	}                                                                  \
-	BFType operator&( BFType other ) const {                           \
-		BFType q = other;                                              \
-		q &= *this;                                                    \
-		return q;                                                      \
-	}                                                                  \
-	BFType operator|=( BFType other ) {                                \
-		val |= other.val; return *this;                                \
-	}                                                                  \
-	BFType operator|( BFType other ) const {                           \
-		BFType q = other;                                              \
-		q |= *this;                                                    \
-		return q;                                                      \
-	}                                                                  \
-	BFType operator-=( BFType other ) {                                \
-		val &= ~other.val; return *this;                               \
+template<typename T>
+struct bitfield : public T {
+	static_assert(sizeof(T) == sizeof(unsigned int), "Type has incorrect size");
+	using T::val;
+	using val_t = decltype(val);
+
+	constexpr bitfield() : T( 0 ) {}
+	constexpr bitfield( val_t v ) : T( v ) {}
+
+	bool operator[]( val_t i ) const { return val & (1 << i); }
+	bool any() const { return val != 0; }
+	void reset() { val = 0; }
+	int ffs() { return ::ffs( val ) - 1; }
+
+	bitfield operator&=( bitfield other ) {
+		val &= other.val; return *this;
 	}
+	bitfield operator&( bitfield other ) const {
+		bitfield q = other;
+		q &= *this;
+		return q;
+	}
+	bitfield operator|=( bitfield other ) {
+		val |= other.val; return *this;
+	}
+	bitfield operator|( bitfield other ) const {
+		bitfield q = other;
+		q |= *this;
+		return q;
+	}
+	bitfield operator-=( bitfield other ) {
+		val &= ~other.val; return *this;
+	}
+};
 
 /// Adds default printing operator to a bitfield type.
 /// Include in definition to add print function, requires other bitfield operators.
 /// @param N  Number of bits in bitfield
-#define MakeBitfieldPrint( N )                                         \
-	static const char* Names[];                                        \
-	void print( std::ostream & os ) const {                            \
-		if ( (*this).any() ) {                                         \
-			for ( unsigned int i = 0; i < N; i += 1 ) {                \
-				if ( (*this)[i] ) {                                    \
-					os << Names[i] << ' ';                             \
-				}                                                      \
-			}                                                          \
-		}                                                              \
+#define MakeBitfieldPrint( N ) \
+	static const char* Names[]; \
+ \
+	void print( std::ostream & os ) const { \
+		if ( (*this).any() ) { \
+			for ( unsigned int i = 0; i < N; i += 1 ) { \
+				if ( (*this)[i] ) { \
+					os << Names[i] << ' '; \
+				} \
+			} \
+		} \
 	}
 
Index: src/AST/Decl.hpp
===================================================================
--- src/AST/Decl.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Decl.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -122,5 +122,5 @@
 	std::vector<ptr<DeclWithType>> assertions;
 
-	NamedTypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, 
+	NamedTypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage,
 		Type* b, Linkage::Spec spec = Linkage::Cforall )
 	: Decl( loc, name, storage, spec ), base( b ), parameters(), assertions() {}
@@ -149,5 +149,5 @@
 		Data( TypeDecl* d ) : kind( d->kind ), isComplete( d->sized ) {}
 		Data( Kind k, bool c ) : kind( k ), isComplete( c ) {}
-		Data( const Data& d1, const Data& d2 ) 
+		Data( const Data& d1, const Data& d2 )
 		: kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
 
@@ -158,5 +158,5 @@
 	};
 
-	TypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, Type* b, 
+	TypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, Type* b,
 		Kind k, bool s, Type* i = nullptr )
 	: NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == Ttype || s ), init( i ) {}
@@ -174,5 +174,5 @@
 class TypedefDecl final : public NamedTypeDecl {
 public:
-	TypedefDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, 
+	TypedefDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage,
 		Type* b, Linkage::Spec spec = Linkage::Cforall )
 	: NamedTypeDecl( loc, name, storage, b, spec ) {}
@@ -275,4 +275,43 @@
 };
 
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Decl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class Decl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class DeclWithType * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class DeclWithType * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class ObjectDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class ObjectDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class AggregateDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class AggregateDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class StructDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class StructDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class UnionDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class UnionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class EnumDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class EnumDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class TraitDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class TraitDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class NamedTypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class NamedTypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class TypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class TypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class FtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class FtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class DtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class DtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class TypedefDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class TypedefDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+
 }
 
Index: src/AST/FunctionSpec.hpp
===================================================================
--- src/AST/FunctionSpec.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/FunctionSpec.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -31,16 +31,20 @@
 
 	/// Bitflag type for storage classes
-	union Specs {
-		unsigned int val;
-		struct {
-			bool is_inline   : 1;
-			bool is_noreturn : 1;
-			bool is_fortran  : 1;
+	struct spec_flags {
+		union {
+			unsigned int val;
+			struct {
+				bool is_inline   : 1;
+				bool is_noreturn : 1;
+				bool is_fortran  : 1;
+			};
+
+			// MakeBitfieldPrint( NumSpecs )
 		};
 
-		MakeBitfield( Specs )
-		MakeBitfieldPrint( NumSpecs )
+		constexpr spec_flags( unsigned int val ) : val(val) {}
 	};
 
+	using Specs = bitfield<spec_flags>;
 }
 }
Index: src/AST/Fwd.hpp
===================================================================
--- src/AST/Fwd.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Fwd.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -16,7 +16,8 @@
 #pragma once
 
+#include "AST/Node.hpp"
+
 namespace ast {
 
-class Node;
 class ParseNode;
 
@@ -137,4 +138,228 @@
 class TypeSubstitution;
 
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void decrement( const class Node * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class Node * node, Node::ref_type ref ) { node->increment(ref); }
+inline void increment( const class ParseNode *, Node::ref_type );
+inline void decrement( const class ParseNode *, Node::ref_type );
+inline void increment( const class Decl *, Node::ref_type );
+inline void decrement( const class Decl *, Node::ref_type );
+inline void increment( const class DeclWithType *, Node::ref_type );
+inline void decrement( const class DeclWithType *, Node::ref_type );
+inline void increment( const class ObjectDecl *, Node::ref_type );
+inline void decrement( const class ObjectDecl *, Node::ref_type );
+inline void increment( const class FunctionDecl *, Node::ref_type );
+inline void decrement( const class FunctionDecl *, Node::ref_type );
+inline void increment( const class AggregateDecl *, Node::ref_type );
+inline void decrement( const class AggregateDecl *, Node::ref_type );
+inline void increment( const class StructDecl *, Node::ref_type );
+inline void decrement( const class StructDecl *, Node::ref_type );
+inline void increment( const class UnionDecl *, Node::ref_type );
+inline void decrement( const class UnionDecl *, Node::ref_type );
+inline void increment( const class EnumDecl *, Node::ref_type );
+inline void decrement( const class EnumDecl *, Node::ref_type );
+inline void increment( const class TraitDecl *, Node::ref_type );
+inline void decrement( const class TraitDecl *, Node::ref_type );
+inline void increment( const class NamedTypeDecl *, Node::ref_type );
+inline void decrement( const class NamedTypeDecl *, Node::ref_type );
+inline void increment( const class TypeDecl *, Node::ref_type );
+inline void decrement( const class TypeDecl *, Node::ref_type );
+inline void increment( const class FtypeDecl *, Node::ref_type );
+inline void decrement( const class FtypeDecl *, Node::ref_type );
+inline void increment( const class DtypeDecl *, Node::ref_type );
+inline void decrement( const class DtypeDecl *, Node::ref_type );
+inline void increment( const class TypedefDecl *, Node::ref_type );
+inline void decrement( const class TypedefDecl *, Node::ref_type );
+inline void increment( const class AsmDecl *, Node::ref_type );
+inline void decrement( const class AsmDecl *, Node::ref_type );
+inline void increment( const class StaticAssertDecl *, Node::ref_type );
+inline void decrement( const class StaticAssertDecl *, Node::ref_type );
+inline void increment( const class Stmt *, Node::ref_type );
+inline void decrement( const class Stmt *, Node::ref_type );
+inline void increment( const class CompoundStmt *, Node::ref_type );
+inline void decrement( const class CompoundStmt *, Node::ref_type );
+inline void increment( const class ExprStmt *, Node::ref_type );
+inline void decrement( const class ExprStmt *, Node::ref_type );
+inline void increment( const class AsmStmt *, Node::ref_type );
+inline void decrement( const class AsmStmt *, Node::ref_type );
+inline void increment( const class DirectiveStmt *, Node::ref_type );
+inline void decrement( const class DirectiveStmt *, Node::ref_type );
+inline void increment( const class IfStmt *, Node::ref_type );
+inline void decrement( const class IfStmt *, Node::ref_type );
+inline void increment( const class WhileStmt *, Node::ref_type );
+inline void decrement( const class WhileStmt *, Node::ref_type );
+inline void increment( const class ForStmt *, Node::ref_type );
+inline void decrement( const class ForStmt *, Node::ref_type );
+inline void increment( const class SwitchStmt *, Node::ref_type );
+inline void decrement( const class SwitchStmt *, Node::ref_type );
+inline void increment( const class CaseStmt *, Node::ref_type );
+inline void decrement( const class CaseStmt *, Node::ref_type );
+inline void increment( const class BranchStmt *, Node::ref_type );
+inline void decrement( const class BranchStmt *, Node::ref_type );
+inline void increment( const class ReturnStmt *, Node::ref_type );
+inline void decrement( const class ReturnStmt *, Node::ref_type );
+inline void increment( const class ThrowStmt *, Node::ref_type );
+inline void decrement( const class ThrowStmt *, Node::ref_type );
+inline void increment( const class TryStmt *, Node::ref_type );
+inline void decrement( const class TryStmt *, Node::ref_type );
+inline void increment( const class CatchStmt *, Node::ref_type );
+inline void decrement( const class CatchStmt *, Node::ref_type );
+inline void increment( const class FinallyStmt *, Node::ref_type );
+inline void decrement( const class FinallyStmt *, Node::ref_type );
+inline void increment( const class WaitForStmt *, Node::ref_type );
+inline void decrement( const class WaitForStmt *, Node::ref_type );
+inline void increment( const class WithStmt *, Node::ref_type );
+inline void decrement( const class WithStmt *, Node::ref_type );
+inline void increment( const class DeclStmt *, Node::ref_type );
+inline void decrement( const class DeclStmt *, Node::ref_type );
+inline void increment( const class NullStmt *, Node::ref_type );
+inline void decrement( const class NullStmt *, Node::ref_type );
+inline void increment( const class ImplicitCtorDtorStmt *, Node::ref_type );
+inline void decrement( const class ImplicitCtorDtorStmt *, Node::ref_type );
+inline void increment( const class Expr *, Node::ref_type );
+inline void decrement( const class Expr *, Node::ref_type );
+inline void increment( const class ApplicationExpr *, Node::ref_type );
+inline void decrement( const class ApplicationExpr *, Node::ref_type );
+inline void increment( const class UntypedExpr *, Node::ref_type );
+inline void decrement( const class UntypedExpr *, Node::ref_type );
+inline void increment( const class NameExpr *, Node::ref_type );
+inline void decrement( const class NameExpr *, Node::ref_type );
+inline void increment( const class AddressExpr *, Node::ref_type );
+inline void decrement( const class AddressExpr *, Node::ref_type );
+inline void increment( const class LabelAddressExpr *, Node::ref_type );
+inline void decrement( const class LabelAddressExpr *, Node::ref_type );
+inline void increment( const class CastExpr *, Node::ref_type );
+inline void decrement( const class CastExpr *, Node::ref_type );
+inline void increment( const class KeywordCastExpr *, Node::ref_type );
+inline void decrement( const class KeywordCastExpr *, Node::ref_type );
+inline void increment( const class VirtualCastExpr *, Node::ref_type );
+inline void decrement( const class VirtualCastExpr *, Node::ref_type );
+inline void increment( const class MemberExpr *, Node::ref_type );
+inline void decrement( const class MemberExpr *, Node::ref_type );
+inline void increment( const class UntypedMemberExpr *, Node::ref_type );
+inline void decrement( const class UntypedMemberExpr *, Node::ref_type );
+inline void increment( const class VariableExpr *, Node::ref_type );
+inline void decrement( const class VariableExpr *, Node::ref_type );
+inline void increment( const class ConstantExpr *, Node::ref_type );
+inline void decrement( const class ConstantExpr *, Node::ref_type );
+inline void increment( const class SizeofExpr *, Node::ref_type );
+inline void decrement( const class SizeofExpr *, Node::ref_type );
+inline void increment( const class AlignofExpr *, Node::ref_type );
+inline void decrement( const class AlignofExpr *, Node::ref_type );
+inline void increment( const class UntypedOffsetofExpr *, Node::ref_type );
+inline void decrement( const class UntypedOffsetofExpr *, Node::ref_type );
+inline void increment( const class OffsetofExpr *, Node::ref_type );
+inline void decrement( const class OffsetofExpr *, Node::ref_type );
+inline void increment( const class OffsetPackExpr *, Node::ref_type );
+inline void decrement( const class OffsetPackExpr *, Node::ref_type );
+inline void increment( const class AttrExpr *, Node::ref_type );
+inline void decrement( const class AttrExpr *, Node::ref_type );
+inline void increment( const class LogicalExpr *, Node::ref_type );
+inline void decrement( const class LogicalExpr *, Node::ref_type );
+inline void increment( const class ConditionalExpr *, Node::ref_type );
+inline void decrement( const class ConditionalExpr *, Node::ref_type );
+inline void increment( const class CommaExpr *, Node::ref_type );
+inline void decrement( const class CommaExpr *, Node::ref_type );
+inline void increment( const class TypeExpr *, Node::ref_type );
+inline void decrement( const class TypeExpr *, Node::ref_type );
+inline void increment( const class AsmExpr *, Node::ref_type );
+inline void decrement( const class AsmExpr *, Node::ref_type );
+inline void increment( const class ImplicitCopyCtorExpr *, Node::ref_type );
+inline void decrement( const class ImplicitCopyCtorExpr *, Node::ref_type );
+inline void increment( const class ConstructorExpr *, Node::ref_type );
+inline void decrement( const class ConstructorExpr *, Node::ref_type );
+inline void increment( const class CompoundLiteralExpr *, Node::ref_type );
+inline void decrement( const class CompoundLiteralExpr *, Node::ref_type );
+inline void increment( const class UntypedValofExpr *, Node::ref_type );
+inline void decrement( const class UntypedValofExpr *, Node::ref_type );
+inline void increment( const class RangeExpr *, Node::ref_type );
+inline void decrement( const class RangeExpr *, Node::ref_type );
+inline void increment( const class UntypedTupleExpr *, Node::ref_type );
+inline void decrement( const class UntypedTupleExpr *, Node::ref_type );
+inline void increment( const class TupleExpr *, Node::ref_type );
+inline void decrement( const class TupleExpr *, Node::ref_type );
+inline void increment( const class TupleIndexExpr *, Node::ref_type );
+inline void decrement( const class TupleIndexExpr *, Node::ref_type );
+inline void increment( const class TupleAssignExpr *, Node::ref_type );
+inline void decrement( const class TupleAssignExpr *, Node::ref_type );
+inline void increment( const class StmtExpr *, Node::ref_type );
+inline void decrement( const class StmtExpr *, Node::ref_type );
+inline void increment( const class UniqueExpr *, Node::ref_type );
+inline void decrement( const class UniqueExpr *, Node::ref_type );
+inline void increment( const class UntypedInitExpr *, Node::ref_type );
+inline void decrement( const class UntypedInitExpr *, Node::ref_type );
+inline void increment( const class InitExpr *, Node::ref_type );
+inline void decrement( const class InitExpr *, Node::ref_type );
+inline void increment( const class DeletedExpr *, Node::ref_type );
+inline void decrement( const class DeletedExpr *, Node::ref_type );
+inline void increment( const class DefaultArgExpr *, Node::ref_type );
+inline void decrement( const class DefaultArgExpr *, Node::ref_type );
+inline void increment( const class GenericExpr *, Node::ref_type );
+inline void decrement( const class GenericExpr *, Node::ref_type );
+inline void increment( const class Type *, Node::ref_type );
+inline void decrement( const class Type *, Node::ref_type );
+inline void increment( const class VoidType *, Node::ref_type );
+inline void decrement( const class VoidType *, Node::ref_type );
+inline void increment( const class BasicType *, Node::ref_type );
+inline void decrement( const class BasicType *, Node::ref_type );
+inline void increment( const class PointerType *, Node::ref_type );
+inline void decrement( const class PointerType *, Node::ref_type );
+inline void increment( const class ArrayType *, Node::ref_type );
+inline void decrement( const class ArrayType *, Node::ref_type );
+inline void increment( const class ReferenceType *, Node::ref_type );
+inline void decrement( const class ReferenceType *, Node::ref_type );
+inline void increment( const class QualifiedType *, Node::ref_type );
+inline void decrement( const class QualifiedType *, Node::ref_type );
+inline void increment( const class FunctionType *, Node::ref_type );
+inline void decrement( const class FunctionType *, Node::ref_type );
+inline void increment( const class ReferenceToType *, Node::ref_type );
+inline void decrement( const class ReferenceToType *, Node::ref_type );
+inline void increment( const class StructInstType *, Node::ref_type );
+inline void decrement( const class StructInstType *, Node::ref_type );
+inline void increment( const class UnionInstType *, Node::ref_type );
+inline void decrement( const class UnionInstType *, Node::ref_type );
+inline void increment( const class EnumInstType *, Node::ref_type );
+inline void decrement( const class EnumInstType *, Node::ref_type );
+inline void increment( const class TraitInstType *, Node::ref_type );
+inline void decrement( const class TraitInstType *, Node::ref_type );
+inline void increment( const class TypeInstType *, Node::ref_type );
+inline void decrement( const class TypeInstType *, Node::ref_type );
+inline void increment( const class TupleType *, Node::ref_type );
+inline void decrement( const class TupleType *, Node::ref_type );
+inline void increment( const class TypeofType *, Node::ref_type );
+inline void decrement( const class TypeofType *, Node::ref_type );
+inline void increment( const class AttrType *, Node::ref_type );
+inline void decrement( const class AttrType *, Node::ref_type );
+inline void increment( const class VarArgsType *, Node::ref_type );
+inline void decrement( const class VarArgsType *, Node::ref_type );
+inline void increment( const class ZeroType *, Node::ref_type );
+inline void decrement( const class ZeroType *, Node::ref_type );
+inline void increment( const class OneType *, Node::ref_type );
+inline void decrement( const class OneType *, Node::ref_type );
+inline void increment( const class GlobalScopeType *, Node::ref_type );
+inline void decrement( const class GlobalScopeType *, Node::ref_type );
+inline void increment( const class Designation *, Node::ref_type );
+inline void decrement( const class Designation *, Node::ref_type );
+inline void increment( const class Init *, Node::ref_type );
+inline void decrement( const class Init *, Node::ref_type );
+inline void increment( const class SingleInit *, Node::ref_type );
+inline void decrement( const class SingleInit *, Node::ref_type );
+inline void increment( const class ListInit *, Node::ref_type );
+inline void decrement( const class ListInit *, Node::ref_type );
+inline void increment( const class ConstructorInit *, Node::ref_type );
+inline void decrement( const class ConstructorInit *, Node::ref_type );
+inline void increment( const class Constant *, Node::ref_type );
+inline void decrement( const class Constant *, Node::ref_type );
+inline void increment( const class Label *, Node::ref_type );
+inline void decrement( const class Label *, Node::ref_type );
+inline void increment( const class Attribute *, Node::ref_type );
+inline void decrement( const class Attribute *, Node::ref_type );
+inline void increment( const class TypeSubstitution *, Node::ref_type );
+inline void decrement( const class TypeSubstitution *, Node::ref_type );
+
 typedef unsigned int UniqueId;
 
Index: src/AST/Init.hpp
===================================================================
--- src/AST/Init.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Init.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -28,5 +28,5 @@
 class Stmt;
 
-/// List of designator (NameExpr, VariableExpr, and ConstantExpr) expressions that specify an 
+/// List of designator (NameExpr, VariableExpr, and ConstantExpr) expressions that specify an
 /// object being initialized
 class Designation final : public ParseNode {
@@ -34,5 +34,5 @@
 	std::vector<ptr<Expr>> designators;
 
-	Designation( const CodeLocation& loc, std::vector<ptr<Expr>>&& ds = {} ) 
+	Designation( const CodeLocation& loc, std::vector<ptr<Expr>>&& ds = {} )
 	: ParseNode( loc ), designators( std::move(ds) ) {}
 
@@ -60,5 +60,5 @@
 	ptr<Expr> value;
 
-	SingleInit( const CodeLocation& loc, Expr* val, bool mc = false ) 
+	SingleInit( const CodeLocation& loc, Expr* val, bool mc = false )
 	: Init( loc, mc ), value( val ) {}
 
@@ -77,7 +77,7 @@
 	std::vector<ptr<Designation>> designations;
 
-	ListInit( const CodeLocation& loc, std::vector<ptr<Init>>&& is, 
+	ListInit( const CodeLocation& loc, std::vector<ptr<Init>>&& is,
 		std::vector<ptr<Designation>>&& ds = {}, bool mc = false );
-	
+
 	using iterator = std::vector<ptr<Init>>::iterator;
 	using const_iterator = std::vector<ptr<Init>>::const_iterator;
@@ -93,5 +93,5 @@
 
 /// Either a constructor expression or a C-style initializer.
-/// Should not be necessary to create manually; instead set `maybeConstructed` true on `SingleInit` 
+/// Should not be necessary to create manually; instead set `maybeConstructed` true on `SingleInit`
 /// or `ListInit` if the object should be constructed.
 class ConstructorInit final : public Init {
@@ -99,5 +99,5 @@
 	ptr<Stmt> ctor;
 	ptr<Stmt> dtor;
-	/// C-style initializer made up of SingleInit/ListInit nodes to use as a fallback if an 
+	/// C-style initializer made up of SingleInit/ListInit nodes to use as a fallback if an
 	/// appropriate constructor definition is not found by the resolver.
 	ptr<Init> init;
@@ -111,4 +111,18 @@
 };
 
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Init * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class Init * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class SingleInit * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class SingleInit * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ListInit * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ListInit * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ConstructorInit * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ConstructorInit * node, Node::ref_type ref ) { node->decrement( ref ); }
 }
 
Index: src/AST/Label.hpp
===================================================================
--- src/AST/Label.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Label.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -25,26 +25,35 @@
 namespace ast {
 
-	class Attribute;
+class Attribute;
 
-	/// Named labels for statements
-	class Label {
-	public:
-		CodeLocation location;
-		std::string name;
-		std::vector< ptr<Attribute> > attributes;
+/// Named labels for statements
+class Label {
+public:
+	CodeLocation location;
+	std::string name;
+	std::vector< ptr<Attribute> > attributes;
 
-		Label( CodeLocation loc, const std::string& name = "",
-			const std::vector<ptr<Attribute>>& attrs = std::vector<ptr<Attribute>>{} )
-		: location( loc ), name( name ), attributes( attrs ) {}
+	Label( CodeLocation loc, const std::string& name = "",
+		const std::vector<ptr<Attribute>>& attrs = std::vector<ptr<Attribute>>{} )
+	: location( loc ), name( name ), attributes( attrs ) {}
 
-		operator std::string () const { return name; }
-		bool empty() { return name.empty(); }
-	};
+	operator std::string () const { return name; }
+	bool empty() { return name.empty(); }
+};
 
-	inline bool operator== ( const Label& l1, const Label& l2 ) { return l1.name == l2.name; }
-	inline bool operator!= ( const Label& l1, const Label& l2 ) { return !(l1 == l2); }
-	inline bool operator<  ( const Label& l1, const Label& l2 ) { return l1.name < l2.name; }
+inline bool operator== ( const Label& l1, const Label& l2 ) { return l1.name == l2.name; }
+inline bool operator!= ( const Label& l1, const Label& l2 ) { return !(l1 == l2); }
+inline bool operator<  ( const Label& l1, const Label& l2 ) { return l1.name < l2.name; }
 
-	inline std::ostream& operator<< ( std::ostream& out, const Label& l ) { return out << l.name; }
+inline std::ostream& operator<< ( std::ostream& out, const Label& l ) { return out << l.name; }
+
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Label * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class Label * node, Node::ref_type ref ) { node->decrement( ref ); }
 
 }
Index: src/AST/LinkageSpec.hpp
===================================================================
--- src/AST/LinkageSpec.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/LinkageSpec.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -35,16 +35,20 @@
 
 	/// Bitflag type for storage classes
-	union Spec {
-		unsigned int val;
-		struct {
-			bool is_mangled      : 1;
-			bool is_generatable  : 1;
-			bool is_overrideable : 1;
-			bool is_builtin      : 1;
-			bool is_gcc_builtin  : 1;
+	struct spec_flags {
+		union {
+			unsigned int val;
+			struct {
+				bool is_mangled      : 1;
+				bool is_generatable  : 1;
+				bool is_overrideable : 1;
+				bool is_builtin      : 1;
+				bool is_gcc_builtin  : 1;
+			};
 		};
 
-		MakeBitfield( Spec )
+		constexpr spec_flags( unsigned int val ) : val(val) {}
 	};
+
+	using Spec = bitfield<spec_flags>;
 
 	/// If `cmd` = "C" returns `spec` with `is_mangled = false`.
Index: src/AST/ParseNode.hpp
===================================================================
--- src/AST/ParseNode.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/ParseNode.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -22,18 +22,26 @@
 namespace ast {
 
-	/// AST node with an included source location
-	class ParseNode : public Node {
-	public:
-		CodeLocation location;
+/// AST node with an included source location
+class ParseNode : public Node {
+public:
+	CodeLocation location;
 
-		// Default constructor is deliberately omitted, all ParseNodes must have a location.
-		// Escape hatch if needed is to explicitly pass a default-constructed location, but
-		// this should be used sparingly.
+	// Default constructor is deliberately omitted, all ParseNodes must have a location.
+	// Escape hatch if needed is to explicitly pass a default-constructed location, but
+	// this should be used sparingly.
 
-		ParseNode( const CodeLocation& loc ) : Node(), location(loc) {}
+	ParseNode( const CodeLocation& loc ) : Node(), location(loc) {}
 
-		ParseNode( const ParseNode& o ) = default;
-	};
+	ParseNode( const ParseNode& o ) = default;
+};
 
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class ParseNode * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ParseNode * node, Node::ref_type ref ) { node->decrement( ref ); }
 }
 
Index: src/AST/Pass.hpp
===================================================================
--- src/AST/Pass.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Pass.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -1,4 +1,19 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// Pass.hpp --
+//
+// Author           : Thierry Delisle
+// Created On       : Thu May 09 15::37::05 2019
+// Last Modified By :
+// Last Modified On :
+// Update Count     :
+//
+
 #pragma once
-// IWYU pragma: private, include "Common/PassVisitor.h"
+// IWYU pragma: private, include "AST/Pass.hpp"
 
 #include <functional>
@@ -6,9 +21,13 @@
 #include <stack>
 
-#include "Fwd.hpp"
-#include "Node.hpp"
+#include "AST/Fwd.hpp"
+#include "AST/Node.hpp"
+#include "AST/Decl.hpp"
+#include "AST/Visitor.hpp"
+
+#include "SymTab/Indexer.h"
 
 // Private prelude header, needed for some of the magic tricks this class pulls off
-#include "Pass.proto.hpp"
+#include "AST/Pass.proto.hpp"
 
 namespace ast {
@@ -20,8 +39,12 @@
 //
 // Several additional features are available through inheritance
-// | WithTypeSubstitution - provides polymorphic TypeSubstitution * env for the current expression
+// | WithTypeSubstitution - provides polymorphic const TypeSubstitution * env for the
+//                          current expression
 // | WithStmtsToAdd       - provides the ability to insert statements before or after the current
 //                          statement by adding new statements into stmtsToAddBefore or
 //                          stmtsToAddAfter respectively.
+// | WithDeclsToAdd       - provides the ability to insert declarations before or after the current
+//                          declarations by adding new DeclStmt into declsToAddBefore or
+//                          declsToAddAfter respectively.
 // | WithShortCircuiting  - provides the ability to skip visiting child nodes; set visit_children
 //                          to false in pre{visit,visit} to skip visiting children
@@ -30,15 +53,19 @@
 //                          automatically be restored to its previous value after the corresponding
 //                          postvisit/postmutate teminates.
+// | WithVisitorRef       - provides an pointer to the templated visitor wrapper
+// | WithIndexer          - provides indexer functionality (i.e. up-to-date symbol table)
 //-------------------------------------------------------------------------------------------------
 template< typename pass_t >
 class Pass final : public ast::Visitor {
 public:
+	/// Forward any arguments to the pass constructor
+	/// Propagate 'this' if necessary
 	template< typename... Args >
 	Pass( Args &&... args)
-		: m_pass( std::forward<Args>( args )... )
+		: pass( std::forward<Args>( args )... )
 	{
 		// After the pass is constructed, check if it wants the have a pointer to the wrapping visitor
 		typedef Pass<pass_t> this_t;
-		this_t * const * visitor = __pass::visitor(m_pass, 0);
+		this_t * const * visitor = __pass::visitor(pass, 0);
 		if(visitor) {
 			*const_cast<this_t **>( visitor ) = this;
@@ -48,6 +75,8 @@
 	virtual ~Pass() = default;
 
-	pass_t m_pass;
-
+	/// Storage for the actual pass
+	pass_t pass;
+
+	/// Visit function declarations
 	virtual DeclWithType *     visit( const ObjectDecl           * ) override final;
 	virtual DeclWithType *     visit( const FunctionDecl         * ) override final;
@@ -145,128 +174,112 @@
 	virtual TypeSubstitution * visit( const TypeSubstitution     * ) override final;
 
+	friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_t>& visitor );
 private:
 
-	bool __visit_children() { __pass::bool_ref * ptr = __pass::visit_children(m_pass, 0); return ptr ? *ptr : true; }
+	bool __visit_children() { __pass::bool_ref * ptr = __pass::visit_children(pass, 0); return ptr ? *ptr : true; }
 
 private:
+	/// Logic to call the accept and mutate the parent if needed, delegates call to accept
 	template<typename parent_t, typename child_t>
 	void maybe_accept(parent_t * & , typename parent_t::child_t *);
 
-	ast::Statement  * call_accept( const ast::Statement  * );
-	ast::Expression * call_accept( const ast::Expression * );
+	Stmt * call_accept( const Stmt * );
+	Expr * call_accept( const Expr * );
 
 	template< template <class> class container_t >
-	container_t< ast::ptr<ast::Statement> > call_accept( const container_t< ast::ptr<ast::Statement> > & );
+	container_t< ptr<Stmt> > call_accept( const container_t< ptr<Stmt> > & );
 
 	template< template <class> class container_t, typename node_t >
-	container_t< ast::ptr<node_t> > call_accept( const container_t< ast::ptr<node_t> > & container );
+	container_t< ptr<node_t> > call_accept( const container_t< ptr<node_t> > & container );
 
 private:
-	struct indexer_guard {
+	/// Internal RAII guard for indexer features
+	struct guard_indexer {
+		guard_indexer( Pass<pass_t> & pass ): pass( pass ) { __pass::indexer::enter(pass, 0); }
+		~guard_indexer()                                   { __pass::indexer::leave(pass, 0); }
 		Pass<pass_t> & pass;
-
-		indexer_guard( Pass<pass_t> & pass ) : pass( pass ) { __pass::indexer::enter(pass, 0); }
-		~indexer_guard()                                    { __pass::indexer::leave(pass, 0); }
 	};
 
-	indexer_guard make_indexer_guard() { return { *this }; }
-
-private:
-	struct scope_guard {
+	/// Internal RAII guard for scope features
+	struct guard_scope {
+		guard_scope( Pass<pass_t> & pass ): pass( pass ) { __pass::scope::enter(pass, 0); }
+		~guard_scope()                                   { __pass::scope::leave(pass, 0); }
 		Pass<pass_t> & pass;
-
-		scope_guard( Pass<pass_t> & pass ) : pass( pass ) { __pass::scope::enter(pass, 0); }
-		~scope_guard()                                    { __pass::scope::leave(pass, 0); }
 	};
-
-	scope_guard make_scope_guard() { return { *this }; }
-};
-
-//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-// Guard value : RAII type to restore a value when the Pass finishes visiting this node
-template<typename pass_t, typename T>
-void GuardValue( pass_t * pass, T& val ) {
-	pass->at_cleanup( [ val ]( void * newVal ) {
-		* static_cast< T * >( newVal ) = val;
-	}, static_cast< void * >( & val ) );
-}
-
-//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+};
+
+template<typename pass_t>
+void acceptAll( std::list< ptr<Decl> >, Pass<pass_t>& visitor );
+
+//-------------------------------------------------------------------------------------------------
 // PASS ACCESSORIES
-//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
-// Keep track of the type substitution
-struct WithConstTypeSubstitution {
-	const ast::TypeSubstitution * env = nullptr;
-};
+//-------------------------------------------------------------------------------------------------
 
 template<typename T>
 using std_list = std::list<T>;
 
-// Used if visitor requires added statements before or after the current node.
-// The Pass template handles what *before* and *after* means automatically
+/// Keep track of the polymorphic const TypeSubstitution * env for the current expression
+struct WithConstTypeSubstitution {
+	const TypeSubstitution * env = nullptr;
+};
+
+/// Used if visitor requires added statements before or after the current node.
+/// The Pass template handles what *before* and *after* means automatically
 template< template<class> class container_t = std_list >
 struct WithStmtsToAdd {
-	container_t< ast::ptr< ast::Statement > > stmtsToAddBefore;
-	container_t< ast::ptr< ast::Statement > > stmtsToAddAfter;
-};
-
-// Used if visitor requires added declarations before or after the current node.
-// The Pass template handles what *before* and *after* means automatically
+	container_t< ptr<Stmt> > stmtsToAddBefore;
+	container_t< ptr<Stmt> > stmtsToAddAfter;
+};
+
+/// Used if visitor requires added declarations before or after the current node.
+/// The Pass template handles what *before* and *after* means automatically
 template< template<class> class container_t = std_list >
 struct WithDeclsToAdd {
-	~WithDeclsToAdd() {
-		assert( declsToAddBefore.empty() );
-	}
-
-	container_t< ast::ptr< ast::Declaration > > declsToAddBefore;
-	container_t< ast::ptr< ast::Declaration > > declsToAddAfter;
-};
-
-// Use if visitation should stop at certain levels
-// set visit_children false of all child nodes should be ignored
+	container_t< ptr<Decl> > declsToAddBefore;
+	container_t< ptr<Decl> > declsToAddAfter;
+};
+
+/// Use if visitation should stop at certain levels
+/// set visit_children false of all child nodes should be ignored
 struct WithShortCircuiting {
 	__pass::bool_ref visit_children;
 };
 
-// class WithGuards {
-// protected:
-// 	WithGuards() = default;
-// 	~WithGuards() = default;
-
-// public:
-// 	at_cleanup_t at_cleanup;
-
-// 	template< typename T >
-// 	void GuardValue( T& val ) {
-// 		at_cleanup( [ val ]( void * newVal ) {
-// 			* static_cast< T * >( newVal ) = val;
-// 		}, static_cast< void * >( & val ) );
-// 	}
-
-// 	template< typename T >
-// 	void GuardScope( T& val ) {
-// 		val.beginScope();
-// 		at_cleanup( []( void * val ) {
-// 			static_cast< T * >( val )->endScope();
-// 		}, static_cast< void * >( & val ) );
-// 	}
-
-// 	template< typename Func >
-// 	void GuardAction( Func func ) {
-// 		at_cleanup( [func](__attribute__((unused)) void *) { func(); }, nullptr );
-// 	}
-// };
-
-// template<typename pass_type>
-// class WithVisitorRef {
-// protected:
-// 	WithVisitorRef() {}
-// 	~WithVisitorRef() {}
-
-// public:
-// 	PassVisitor<pass_type> * const visitor = nullptr;
-// };
-
+/// Used to restore values/functions/etc. when the Pass finishes visiting this node
+class WithGuards {
+	__pass::at_cleanup_t at_cleanup;
+
+public:
+	/// When this node is finished being visited, restore the value of a variable
+	template< typename T >
+	void GuardValue( T& val ) {
+		at_cleanup( [ val ]( void * newVal ) {
+			* static_cast< T * >( newVal ) = val;
+		}, static_cast< void * >( & val ) );
+	}
+
+	/// On the object, all beginScope now and endScope when the current node is finished being visited
+	template< typename T >
+	void GuardScope( T& val ) {
+		val.beginScope();
+		at_cleanup( []( void * val ) {
+			static_cast< T * >( val )->endScope();
+		}, static_cast< void * >( & val ) );
+	}
+
+	/// When this node is finished being visited, call a function
+	template< typename Func >
+	void GuardAction( Func func ) {
+		at_cleanup( [func](void *) { func(); }, nullptr );
+	}
+};
+
+/// Used to get a pointer to the pass with its wrapped type
+template<typename pass_t>
+struct WithVisitorRef {
+	Pass<pass_t> * const visitor = nullptr;
+};
+
+/// Use when the templated visitor should update the indexer
 struct WithIndexer {
 	SymTab::Indexer indexer;
Index: src/AST/Pass.impl.hpp
===================================================================
--- src/AST/Pass.impl.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Pass.impl.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -1,12 +1,28 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// Pass.impl.hpp --
+//
+// Author           : Thierry Delisle
+// Created On       : Thu May 09 15::37::05 2019
+// Last Modified By :
+// Last Modified On :
+// Update Count     :
+//
+
 #pragma once
-// IWYU pragma: private, include "Pass.hpp"
+// IWYU pragma: private, include "AST/Pass.hpp"
 
 #define VISIT_START( node ) \
+	using namespace ast; \
 	/* back-up the visit children */ \
-	__attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(m_pass, 0) ); \
+	__attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(pass, 0) ); \
 	/* setup the scope for passes that want to run code at exit */ \
-	__attribute__((unused)) ast::__pass::guard_value          guard2( ast::__pass::at_cleanup    (m_pass, 0) ); \
+	__attribute__((unused)) ast::__pass::guard_value          guard2( ast::__pass::at_cleanup    (pass, 0) ); \
 	/* call the implementation of the previsit of this pass */ \
-	__pass::previsit( m_pass, node, 0 );
+	__pass::previsit( pass, node, 0 );
 
 #define VISIT( code ) \
@@ -98,9 +114,9 @@
 
 	template< typename pass_t >
-	ast::Expression * Pass< pass_t >::call_accept( const ast::Expression * expr ) {
+	ast::Expr * Pass< pass_t >::call_accept( const ast::Expr * expr ) {
 		__pedantic_pass_assert( __visit_children() );
 		__pedantic_pass_assert( expr );
 
-		const ast::TypeSubstitution ** env_ptr = __pass::env( m_pass, 0);
+		const ast::TypeSubstitution ** env_ptr = __pass::env( pass, 0);
 		if ( env_ptr && expr->env ) {
 			*env_ptr = expr->env;
@@ -111,64 +127,7 @@
 
 	template< typename pass_t >
-	ast::Statement * Pass< pass_t >::call_accept( const ast::Statement * stmt ) {
+	Stmt * Pass< pass_t >::call_accept( const Stmt * stmt ) {
 		__pedantic_pass_assert( __visit_children() );
 		__pedantic_pass_assert( stmt );
-
-		// add a few useful symbols to the scope
-		using __pass::empty;
-		using decls_t = typename std::remove_pointer< decltype(__decls_before()) >::type;
-		using stmts_t = typename std::remove_pointer< decltype(__stmts_before()) >::type;
-
-		// get the stmts/decls that will need to be spliced in
-		auto stmts_before = __pass::stmtsToAddBefore( m_pass, 0);
-		auto stmts_after  = __pass::stmtsToAddAfter ( m_pass, 0);
-		auto decls_before = __pass::declsToAddBefore( m_pass, 0);
-		auto decls_after  = __pass::declsToAddAfter ( m_pass, 0);
-
-		// These may be modified by subnode but most be restored once we exit this statemnet.
-		ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::env( m_pass, 0);  );
-		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > __old_decls_before( stmts_before );
-		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > __old_decls_after ( stmts_after  );
-		ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > __old_stmts_before( decls_before );
-		ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > __old_stmts_after ( decls_after  );
-
-		// Now is the time to actually visit the node
-		ast::Statement * nstmt = stmt->accept( *this );
-
-		// If the pass doesn't want to add anything then we are done
-		if( empty(stmts_before) && empty(stmts_after) && empty(decls_before) && empty(decls_after) ) {
-			return nstmt;
-		}
-
-		// Make sure that it is either adding statements or declartions but not both
-		// this is because otherwise the order would be awkward to predict
-		assert(( empty( stmts_before ) && empty( stmts_after ))
-		    || ( empty( decls_before ) && empty( decls_after )) );
-
-		// Create a new Compound Statement to hold the new decls/stmts
-		ast::CompoundStmt * compound = new ast::CompoundStmt( parent->*child.location );
-
-		// Take all the declarations that go before
-		__pass::take_all( std::back_inserter( compound->kids ), decls_before );
-		__pass::take_all( std::back_inserter( compound->kids ), stmts_before );
-
-		// Insert the original declaration
-		compound->kids.push_back( nstmt );
-
-		// Insert all the declarations that go before
-		__pass::take_all( std::back_inserter( compound->kids ), decls_after );
-		__pass::take_all( std::back_inserter( compound->kids ), stmts_after );
-
-		return compound;
-	}
-
-	template< typename pass_t >
-	template< template <class> class container_t >
-	container_t< ast::ptr<ast::Statement> > Pass< pass_t >::call_accept( const container_t< ast::ptr<ast::Statement> > & statements ) {
-		__pedantic_pass_assert( __visit_children() );
-		if( statements.empty() ) return {};
-
-		// We are going to aggregate errors for all these statements
-		SemanticErrorException errors;
 
 		// add a few useful symbols to the scope
@@ -182,4 +141,5 @@
 
 		// These may be modified by subnode but most be restored once we exit this statemnet.
+		ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::env( pass, 0);  );
 		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > __old_decls_before( stmts_before );
 		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > __old_decls_after ( stmts_after  );
@@ -187,4 +147,58 @@
 		ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > __old_stmts_after ( decls_after  );
 
+		// Now is the time to actually visit the node
+		ast::Statement * nstmt = stmt->accept( *this );
+
+		// If the pass doesn't want to add anything then we are done
+		if( empty(stmts_before) && empty(stmts_after) && empty(decls_before) && empty(decls_after) ) {
+			return nstmt;
+		}
+
+		// Make sure that it is either adding statements or declartions but not both
+		// this is because otherwise the order would be awkward to predict
+		assert(( empty( stmts_before ) && empty( stmts_after ))
+		    || ( empty( decls_before ) && empty( decls_after )) );
+
+		// Create a new Compound Statement to hold the new decls/stmts
+		ast::CompoundStmt * compound = new ast::CompoundStmt( parent->*child.location );
+
+		// Take all the declarations that go before
+		__pass::take_all( std::back_inserter( compound->kids ), decls_before );
+		__pass::take_all( std::back_inserter( compound->kids ), stmts_before );
+
+		// Insert the original declaration
+		compound->kids.push_back( nstmt );
+
+		// Insert all the declarations that go before
+		__pass::take_all( std::back_inserter( compound->kids ), decls_after );
+		__pass::take_all( std::back_inserter( compound->kids ), stmts_after );
+
+		return compound;
+	}
+
+	template< typename pass_t >
+	template< template <class> class container_t >
+	container_t< ptr<Stmt> > Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
+		__pedantic_pass_assert( __visit_children() );
+		if( statements.empty() ) return {};
+
+		// We are going to aggregate errors for all these statements
+		SemanticErrorException errors;
+
+		// add a few useful symbols to the scope
+		using __pass::empty;
+
+		// get the stmts/decls that will need to be spliced in
+		auto stmts_before = __pass::stmtsToAddBefore( pass, 0);
+		auto stmts_after  = __pass::stmtsToAddAfter ( pass, 0);
+		auto decls_before = __pass::declsToAddBefore( pass, 0);
+		auto decls_after  = __pass::declsToAddAfter ( pass, 0);
+
+		// These may be modified by subnode but most be restored once we exit this statemnet.
+		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > __old_decls_before( stmts_before );
+		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > __old_decls_after ( stmts_after  );
+		ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > __old_stmts_before( decls_before );
+		ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > __old_stmts_after ( decls_after  );
+
 		// update pass statitistics
 		pass_visitor_stats.depth++;
@@ -193,6 +207,6 @@
 
 		bool mutated = false;
-		container_t<ast::ptr< ast::Statement >> new_kids;
-		for( const ast::Statement * stmt : statements ) {
+		container_t< ptr<Stmt> > new_kids;
+		for( const Stmt * stmt : statements ) {
 			try {
 				__pedantic_pass_assert( stmt );
@@ -269,4 +283,44 @@
 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
+template< typename pass_t >
+inline void ast::acceptAll( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< pass_t > & visitor ) {
+	// We are going to aggregate errors for all these statements
+	SemanticErrorException errors;
+
+	// add a few useful symbols to the scope
+	using __pass::empty;
+
+	// get the stmts/decls that will need to be spliced in
+	auto decls_before = __pass::declsToAddBefore( pass, 0);
+	auto decls_after  = __pass::declsToAddAfter ( pass, 0);
+
+	// update pass statitistics
+	pass_visitor_stats.depth++;
+	pass_visitor_stats.max->push(pass_visitor_stats.depth);
+	pass_visitor_stats.avg->push(pass_visitor_stats.depth);
+
+	for ( std::list< ast::ptr<ast::Decl> >::iterator i = decls.begin(); ; ++i ) {
+		// splice in new declarations after previous decl
+		if ( !empty( decls_after ) ) { decls.splice( i, *decls_after ); }
+
+		if ( i == decls.end() ) break;
+
+		try {
+			// run visitor on declaration
+			ast::ptr<ast::Decl> & node = *i;
+			assert( node );
+			node = node->accept( visitor );
+		}
+		catch( SemanticErrorException &e ) {
+			errors.append( e );
+		}
+
+		// splice in new declarations before current decl
+		if ( !empty( decls_before ) ) { decls.splice( i, *decls_before ); }
+	}
+	pass_visitor_stats.depth--;
+	if ( !errors.isEmpty() ) { throw errors; }
+}
+
 // A NOTE ON THE ORDER OF TRAVERSAL
 //
@@ -289,20 +343,20 @@
 // ObjectDecl
 template< typename pass_t >
-ast::DeclarationWithType * Pass< pass_t >::mutate( ast::ObjectDecl * node ) {
+ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::ObjectDecl * node ) {
 	VISIT_START( node );
 
 	VISIT(
 		{
-			auto guard = make_indexer_guard();
-			maybe_accept( node, ast::ObjectDecl::type );
-		}
-		maybe_accept( node, ast::ObjectDecl::init          );
-		maybe_accept( node, ast::ObjectDecl::bitfieldWidth );
-		maybe_accept( node, ast::ObjectDecl::attributes    );
+			indexer_guard guard { *this };
+			maybe_accept( node, ObjectDecl::type );
+		}
+		maybe_accept( node, ObjectDecl::init          );
+		maybe_accept( node, ObjectDecl::bitfieldWidth );
+		maybe_accept( node, ObjectDecl::attributes    );
 	)
 
-	__pass::indexer::AddId( m_pass, 0, node );
-
-	VISIT_END( DeclarationWithType, node );
+	__pass::indexer::AddId( pass, 0, node );
+
+	VISIT_END( DeclWithType, node );
 }
 
@@ -310,5 +364,5 @@
 // Attribute
 template< typename pass_type >
-ast::Attribute * ast::Pass< pass_type >::visit( ast::ptr<ast::Attribute> & node  )  {
+ast::Attribute * ast::Pass< pass_type >::visit( const ast::Attribute * node  )  {
 	VISIT_START(node);
 
@@ -323,5 +377,5 @@
 // TypeSubstitution
 template< typename pass_type >
-TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
+TypeSubstitution * PassVisitor< pass_type >::mutate( const TypeSubstitution * node ) {
 	MUTATE_START( node );
 
Index: src/AST/Pass.proto.hpp
===================================================================
--- src/AST/Pass.proto.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Pass.proto.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -1,274 +1,290 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// Pass.impl.hpp --
+//
+// Author           : Thierry Delisle
+// Created On       : Thu May 09 15::37::05 2019
+// Last Modified By :
+// Last Modified On :
+// Update Count     :
+//
+
 #pragma once
 // IWYU pragma: private, include "Pass.hpp"
 
 namespace ast {
-	template<typename pass_type>
-	class Pass;
-
-	namespace __pass {
-		typedef std::function<void( void * )> cleanup_func_t;
-		typedef std::function<void( cleanup_func_t, void * )> at_cleanup_t;
-
-
-		// boolean reference that may be null
-		// either refers to a boolean value or is null and returns true
-		class bool_ref {
-		public:
-			bool_ref() = default;
-			~bool_ref() = default;
-
-			operator bool() { return m_ref ? *m_ref : true; }
-			bool operator=( bool val ) { assert(m_ref); return *m_ref = val; }
-
-		private:
-
-			friend class visit_children_guard;
-
-			bool * set( bool * val ) {
-				bool * prev = m_ref;
-				m_ref = val;
-				return prev;
+template<typename pass_type>
+class Pass;
+
+namespace __pass {
+	typedef std::function<void( void * )> cleanup_func_t;
+	typedef std::function<void( cleanup_func_t, void * )> at_cleanup_t;
+
+
+	// boolean reference that may be null
+	// either refers to a boolean value or is null and returns true
+	class bool_ref {
+	public:
+		bool_ref() = default;
+		~bool_ref() = default;
+
+		operator bool() { return m_ref ? *m_ref : true; }
+		bool operator=( bool val ) { assert(m_ref); return *m_ref = val; }
+
+	private:
+
+		friend class visit_children_guard;
+
+		bool * set( bool * val ) {
+			bool * prev = m_ref;
+			m_ref = val;
+			return prev;
+		}
+
+		bool * m_ref = nullptr;
+	};
+
+	// Implementation of the guard value
+	// Created inside the visit scope
+	class guard_value {
+	public:
+		/// Push onto the cleanup
+		guard_value( at_cleanup_t * at_cleanup ) {
+			if( at_cleanup ) {
+				*at_cleanup = [this]( cleanup_func_t && func, void* val ) {
+					push( std::move( func ), val );
+				};
 			}
-
-			bool * m_ref = nullptr;
+		}
+
+		~guard_value() {
+			while( !cleanups.empty() ) {
+				auto& cleanup = cleanups.top();
+				cleanup.func( cleanup.val );
+				cleanups.pop();
+			}
+		}
+
+		void push( cleanup_func_t && func, void* val ) {
+			cleanups.emplace( std::move(func), val );
+		}
+
+	private:
+		struct cleanup_t {
+			cleanup_func_t func;
+			void * val;
+
+			cleanup_t( cleanup_func_t&& func, void * val ) : func(func), val(val) {}
 		};
 
-		// Implementation of the guard value
-		// Created inside the visit scope
-		class guard_value {
-		public:
-			guard_value( at_cleanup_t * at_cleanup ) {
-				if( at_cleanup ) {
-					*at_cleanup = [this]( cleanup_func_t && func, void* val ) {
-						push( std::move( func ), val );
-					};
-				}
+		std::stack< cleanup_t > cleanups;
+	};
+
+	// Guard structure implementation for whether or not children should be visited
+	class visit_children_guard {
+	public:
+
+		visit_children_guard( bool_ref * ref )
+			: m_val ( true )
+			, m_prev( ref ? ref->set( &m_val ) : nullptr )
+			, m_ref ( ref )
+		{}
+
+		~visit_children_guard() {
+			if( m_ref ) {
+				m_ref->set( m_prev );
 			}
-
-			~guard_value() {
-				while( !cleanups.empty() ) {
-					auto& cleanup = cleanups.top();
-					cleanup.func( cleanup.val );
-					cleanups.pop();
-				}
-			}
-
-			void push( cleanup_func_t && func, void* val ) {
-				cleanups.emplace( std::move(func), val );
-			}
-
-		private:
-			struct cleanup_t {
-				cleanup_func_t func;
-				void * val;
-
-				cleanup_t( cleanup_func_t&& func, void * val ) : func(func), val(val) {}
-			};
-
-			std::stack< cleanup_t > cleanups;
-		};
-
-		// Guard structure implementation for whether or not children should be visited
-		class visit_children_guard {
-		public:
-
-			visit_children_guard( bool_ref * ref )
-				: m_val ( true )
-				, m_prev( ref ? ref->set( &m_val ) : nullptr )
-				, m_ref ( ref )
-			{}
-
-			~visit_children_guard() {
-				if( m_ref ) {
-					m_ref->set( m_prev );
-				}
-			}
-
-			operator bool() { return m_val; }
-
-		private:
-			bool       m_val;
-			bool     * m_prev;
-			bool_ref * m_ref;
-		};
-
-		//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-		// Deep magic (a.k.a template meta programming) to make the templated visitor work
-		// Basically the goal is to make 2 previsit
-		// 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of
-		//     'pass.previsit( node )' that compiles will be used for that node for that type
-		//     This requires that this option only compile for passes that actually define an appropriate visit.
-		//     SFINAE will make sure the compilation errors in this function don't halt the build.
-		//     See http://en.cppreference.com/w/cpp/language/sfinae for details on SFINAE
-		// 2 - Since the first implementation might not be specilizable, the second implementation exists and does nothing.
-		//     This is needed only to eliminate the need for passes to specify any kind of handlers.
-		//     The second implementation only works because it has a lower priority. This is due to the bogus last parameter.
-		//     The second implementation takes a long while the first takes an int. Since the caller always passes an literal 0
-		//     the first implementation takes priority in regards to overloading.
-		//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-		// PreVisit : may mutate the pointer passed in if the node is mutated in the previsit call
-		template<typename pass_t, typename node_t>
-		static inline auto previsit( pass_t & pass, const node_t * & node, int ) -> decltype( pass.previsit( node ), void() ) {
-			node = pass.previsit( node );
-			assert(node);
-		}
-
-		template<typename pass_t, typename node_t>
-		static inline auto previsit( pass_t &, const node_t *, long ) {}
-
-		// PostVisit : never mutates the passed pointer but may return a different node
-		template<typename pass_t, typename node_t>
-		static inline auto postvisit( pass_t & pass, const node_t * node, int ) -> decltype( pass.postvisit( node ), (const node_t *)nullptr ) {
-			return pass.postvisit( node );
-		}
-
-		template<typename pass_t, typename node_t>
-		static inline const node_t * postvisit( pass_t &, const node_t * node, long ) { return node; }
-
-		//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-		// Deep magic (a.k.a template meta programming) continued
-		// To make the templated visitor be more expressive, we allow 'accessories' : classes/structs the implementation can inherit
-		// from in order to get extra functionallity for example
-		// class ErrorChecker : WithShortCircuiting { ... };
-		// Pass<ErrorChecker> checker;
-		// this would define a pass that uses the templated visitor with the additionnal feature that it has short circuiting
-		// Note that in all cases the accessories are not required but guarantee the requirements of the feature is matched
-		//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-		// For several accessories, the feature is enabled by detecting that a specific field is present
-		// Use a macro the encapsulate the logic of detecting a particular field
-		// The type is not strictly enforced but does match the accessory
-		#define FIELD_PTR( name, default_type ) \
-		template< typename pass_t > \
-		static inline auto name( pass_t & pass, int ) -> decltype( &pass.name ) { return &pass.name; } \
+		}
+
+		operator bool() { return m_val; }
+
+	private:
+		bool       m_val;
+		bool     * m_prev;
+		bool_ref * m_ref;
+	};
+
+	//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+	// Deep magic (a.k.a template meta programming) to make the templated visitor work
+	// Basically the goal is to make 2 previsit
+	// 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of
+	//     'pass.previsit( node )' that compiles will be used for that node for that type
+	//     This requires that this option only compile for passes that actually define an appropriate visit.
+	//     SFINAE will make sure the compilation errors in this function don't halt the build.
+	//     See http://en.cppreference.com/w/cpp/language/sfinae for details on SFINAE
+	// 2 - Since the first implementation might not be specilizable, the second implementation exists and does nothing.
+	//     This is needed only to eliminate the need for passes to specify any kind of handlers.
+	//     The second implementation only works because it has a lower priority. This is due to the bogus last parameter.
+	//     The second implementation takes a long while the first takes an int. Since the caller always passes an literal 0
+	//     the first implementation takes priority in regards to overloading.
+	//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+	// PreVisit : may mutate the pointer passed in if the node is mutated in the previsit call
+	template<typename pass_t, typename node_t>
+	static inline auto previsit( pass_t & pass, const node_t * & node, int ) -> decltype( pass.previsit( node ), void() ) {
+		node = pass.previsit( node );
+		assert(node);
+	}
+
+	template<typename pass_t, typename node_t>
+	static inline auto previsit( pass_t &, const node_t *, long ) {}
+
+	// PostVisit : never mutates the passed pointer but may return a different node
+	template<typename pass_t, typename node_t>
+	static inline auto postvisit( pass_t & pass, const node_t * node, int ) -> decltype( pass.postvisit( node ), (const node_t *)nullptr ) {
+		return pass.postvisit( node );
+	}
+
+	template<typename pass_t, typename node_t>
+	static inline const node_t * postvisit( pass_t &, const node_t * node, long ) { return node; }
+
+	//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+	// Deep magic (a.k.a template meta programming) continued
+	// To make the templated visitor be more expressive, we allow 'accessories' : classes/structs the implementation can inherit
+	// from in order to get extra functionallity for example
+	// class ErrorChecker : WithShortCircuiting { ... };
+	// Pass<ErrorChecker> checker;
+	// this would define a pass that uses the templated visitor with the additionnal feature that it has short circuiting
+	// Note that in all cases the accessories are not required but guarantee the requirements of the feature is matched
+	//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+	// For several accessories, the feature is enabled by detecting that a specific field is present
+	// Use a macro the encapsulate the logic of detecting a particular field
+	// The type is not strictly enforced but does match the accessory
+	#define FIELD_PTR( name, default_type ) \
+	template< typename pass_t > \
+	static inline auto name( pass_t & pass, int ) -> decltype( &pass.name ) { return &pass.name; } \
+	\
+	template< typename pass_t > \
+	static inline default_type * name( pass_t &, long ) { return nullptr; }
+
+	// List of fields and their expected types
+	FIELD_PTR( env, const ast::TypeSubstitution )
+	FIELD_PTR( stmtsToAddBefore, std::list< ast::ptr< ast::Stmt > > )
+	FIELD_PTR( stmtsToAddAfter , std::list< ast::ptr< ast::Stmt > > )
+	FIELD_PTR( declsToAddBefore, std::list< ast::ptr< ast::Decl > > )
+	FIELD_PTR( declsToAddAfter , std::list< ast::ptr< ast::Decl > > )
+	FIELD_PTR( visit_children, __pass::bool_ref )
+	FIELD_PTR( at_cleanup, __pass::at_cleanup_t )
+	FIELD_PTR( visitor, ast::Pass<pass_t> * const )
+
+	// Remove the macro to make sure we don't clash
+	#undef FIELD_PTR
+
+	// Another feature of the templated visitor is that it calls beginScope()/endScope() for compound statement.
+	// All passes which have such functions are assumed desire this behaviour
+	// detect it using the same strategy
+	namespace scope {
+		template<typename pass_t>
+		static inline auto enter( pass_t & pass, int ) -> decltype( pass.beginScope(), void() ) {
+			pass.beginScope();
+		}
+
+		template<typename pass_t>
+		static inline void enter( pass_t &, long ) {}
+
+		template<typename pass_t>
+		static inline auto leave( pass_t & pass, int ) -> decltype( pass.endScope(), void() ) {
+			pass.endScope();
+		}
+
+		template<typename pass_t>
+		static inline void leave( pass_t &, long ) {}
+	};
+
+	// Finally certain pass desire an up to date indexer automatically
+	// detect the presence of a member name indexer and call all the members appropriately
+	namespace indexer {
+		// Some simple scoping rules
+		template<typename pass_t>
+		static inline auto enter( pass_t & pass, int ) -> decltype( pass.indexer.enterScope(), void() ) {
+			pass.indexer.enterScope();
+		}
+
+		template<typename pass_t>
+		static inline auto enter( pass_t &, long ) {}
+
+		template<typename pass_t>
+		static inline auto leave( pass_t & pass, int ) -> decltype( pass.indexer.leaveScope(), void() ) {
+			pass.indexer.leaveScope();
+		}
+
+		template<typename pass_t>
+		static inline auto leave( pass_t &, long ) {}
+
+		// The indexer has 2 kind of functions mostly, 1 argument and 2 arguments
+		// Create macro to condense these common patterns
+		#define INDEXER_FUNC1( func, type ) \
+		template<typename pass_t> \
+		static inline auto func( pass_t & pass, int, type arg ) -> decltype( pass.indexer.func( arg ), void() ) {\
+			pass.indexer.func( arg ); \
+		} \
 		\
-		template< typename pass_t > \
-		static inline default_type * name( pass_t &, long ) { return nullptr; }
-
-		// List of fields and their expected types
-		FIELD_PTR( env, const ast::TypeSubstitution )
-		FIELD_PTR( stmtsToAddBefore, std::list< ast::ptr< ast::Stmt > > )
-		FIELD_PTR( stmtsToAddAfter , std::list< ast::ptr< ast::Stmt > > )
-		FIELD_PTR( declsToAddBefore, std::list< ast::ptr< ast::Decl > > )
-		FIELD_PTR( declsToAddAfter , std::list< ast::ptr< ast::Decl > > )
-		FIELD_PTR( visit_children, __pass::bool_ref )
-		FIELD_PTR( at_cleanup, __pass::at_cleanup_t )
-		FIELD_PTR( visitor, ast::Pass<pass_t> * const )
-
-		// Remove the macro to make sure we don't clash
-		#undef FIELD_PTR
-
-		// Another feature of the templated visitor is that it calls beginScope()/endScope() for compound statement.
-		// All passes which have such functions are assumed desire this behaviour
-		// detect it using the same strategy
-		namespace scope {
-			template<typename pass_t>
-			static inline auto enter( pass_t & pass, int ) -> decltype( pass.beginScope(), void() ) {
-				pass.beginScope();
-			}
-
-			template<typename pass_t>
-			static inline void enter( pass_t &, long ) {}
-
-			template<typename pass_t>
-			static inline auto leave( pass_t & pass, int ) -> decltype( pass.endScope(), void() ) {
-				pass.endScope();
-			}
-
-			template<typename pass_t>
-			static inline void leave( pass_t &, long ) {}
-		};
-
-		// Finally certain pass desire an up to date indexer automatically
-		// detect the presence of a member name indexer and call all the members appropriately
-		namespace indexer {
-			// Some simple scoping rules
-			template<typename pass_t>
-			static inline auto enter( pass_t & pass, int ) -> decltype( pass.indexer.enterScope(), void() ) {
-				pass.indexer.enterScope();
-			}
-
-			template<typename pass_t>
-			static inline auto enter( pass_t &, long ) {}
-
-			template<typename pass_t>
-			static inline auto leave( pass_t & pass, int ) -> decltype( pass.indexer.leaveScope(), void() ) {
-				pass.indexer.leaveScope();
-			}
-
-			template<typename pass_t>
-			static inline auto leave( pass_t &, long ) {}
-
-			// The indexer has 2 kind of functions mostly, 1 argument and 2 arguments
-			// Create macro to condense these common patterns
-			#define INDEXER_FUNC1( func, type ) \
-			template<typename pass_t> \
-			static inline auto func( pass_t & pass, int, type arg ) -> decltype( pass.indexer.func( arg ), void() ) {\
-				pass.indexer.func( arg ); \
-			} \
+		template<typename pass_t> \
+		static inline void func( pass_t &, long, type ) {}
+
+		#define INDEXER_FUNC2( func, type1, type2 ) \
+		template<typename pass_t> \
+		static inline auto func( pass_t & pass, int, type1 arg1, type2 arg2 ) -> decltype( pass.indexer.func( arg1, arg2 ), void () ) {\
+			pass.indexer.func( arg1, arg2 ); \
+		} \
 			\
-			template<typename pass_t> \
-			static inline void func( pass_t &, long, type ) {}
-
-			#define INDEXER_FUNC2( func, type1, type2 ) \
-			template<typename pass_t> \
-			static inline auto func( pass_t & pass, int, type1 arg1, type2 arg2 ) -> decltype( pass.indexer.func( arg1, arg2 ), void () ) {\
-				pass.indexer.func( arg1, arg2 ); \
-			} \
-			 \
-			template<typename pass_t> \
-			static inline void func( pass_t &, long, type1, type2 ) {}
-
-			INDEXER_FUNC1( addId     , DeclarationWithType *       );
-			INDEXER_FUNC1( addType   , NamedTypeDecl *             );
-			INDEXER_FUNC1( addStruct , StructDecl *                );
-			INDEXER_FUNC1( addEnum   , EnumDecl *                  );
-			INDEXER_FUNC1( addUnion  , UnionDecl *                 );
-			INDEXER_FUNC1( addTrait  , TraitDecl *                 );
-			INDEXER_FUNC2( addWith   , std::list< Expression * > &, BaseSyntaxNode * );
-
-			// A few extra functions have more complicated behaviour, they are hand written
-			template<typename pass_t>
-			static inline auto addStructFwd( pass_t & pass, int, ast::StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) {
-				ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name );
-				fwd->parameters = decl->parameters;
-				pass.indexer.addStruct( fwd );
-			}
-
-			template<typename pass_t>
-			static inline void addStructFwd( pass_t &, long, ast::StructDecl * ) {}
-
-			template<typename pass_t>
-			static inline auto addUnionFwd( pass_t & pass, int, ast::UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) {
-				UnionDecl * fwd = new UnionDecl( decl->name );
-				fwd->parameters = decl->parameters;
-				pass.indexer.addUnion( fwd );
-			}
-
-			template<typename pass_t>
-			static inline void addUnionFwd( pass_t &, long, ast::UnionDecl * ) {}
-
-			template<typename pass_t>
-			static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addStruct( str ), void() ) {
-				if ( ! pass.indexer.lookupStruct( str ) ) {
-					pass.indexer.addStruct( str );
-				}
-			}
-
-			template<typename pass_t>
-			static inline void addStruct( pass_t &, long, const std::string & ) {}
-
-			template<typename pass_t>
-			static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addUnion( str ), void() ) {
-				if ( ! pass.indexer.lookupUnion( str ) ) {
-					pass.indexer.addUnion( str );
-				}
-			}
-
-			template<typename pass_t>
-			static inline void addUnion( pass_t &, long, const std::string & ) {}
-
-			#undef INDEXER_FUNC1
-			#undef INDEXER_FUNC2
-		};
+		template<typename pass_t> \
+		static inline void func( pass_t &, long, type1, type2 ) {}
+
+		INDEXER_FUNC1( addId     , DeclWithType *  );
+		INDEXER_FUNC1( addType   , NamedTypeDecl * );
+		INDEXER_FUNC1( addStruct , StructDecl *    );
+		INDEXER_FUNC1( addEnum   , EnumDecl *      );
+		INDEXER_FUNC1( addUnion  , UnionDecl *     );
+		INDEXER_FUNC1( addTrait  , TraitDecl *     );
+		INDEXER_FUNC2( addWith   , std::list< Expression * > &, Node * );
+
+		// A few extra functions have more complicated behaviour, they are hand written
+		// template<typename pass_t>
+		// static inline auto addStructFwd( pass_t & pass, int, ast::StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) {
+		// 	ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name );
+		// 	fwd->parameters = decl->parameters;
+		// 	pass.indexer.addStruct( fwd );
+		// }
+
+		// template<typename pass_t>
+		// static inline void addStructFwd( pass_t &, long, ast::StructDecl * ) {}
+
+		// template<typename pass_t>
+		// static inline auto addUnionFwd( pass_t & pass, int, ast::UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) {
+		// 	UnionDecl * fwd = new UnionDecl( decl->name );
+		// 	fwd->parameters = decl->parameters;
+		// 	pass.indexer.addUnion( fwd );
+		// }
+
+		// template<typename pass_t>
+		// static inline void addUnionFwd( pass_t &, long, ast::UnionDecl * ) {}
+
+		// template<typename pass_t>
+		// static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addStruct( str ), void() ) {
+		// 	if ( ! pass.indexer.lookupStruct( str ) ) {
+		// 		pass.indexer.addStruct( str );
+		// 	}
+		// }
+
+		// template<typename pass_t>
+		// static inline void addStruct( pass_t &, long, const std::string & ) {}
+
+		// template<typename pass_t>
+		// static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addUnion( str ), void() ) {
+		// 	if ( ! pass.indexer.lookupUnion( str ) ) {
+		// 		pass.indexer.addUnion( str );
+		// 	}
+		// }
+
+		// template<typename pass_t>
+		// static inline void addUnion( pass_t &, long, const std::string & ) {}
+
+		#undef INDEXER_FUNC1
+		#undef INDEXER_FUNC2
 	};
 };
+};
Index: src/AST/Stmt.hpp
===================================================================
--- src/AST/Stmt.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Stmt.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -89,4 +89,52 @@
 
 
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Stmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class Stmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class CompoundStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class CompoundStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ExprStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ExprStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class AsmStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class AsmStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class DirectiveStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class DirectiveStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class IfStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class IfStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class WhileStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class WhileStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class SwitchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class SwitchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class CaseStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class CaseStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class BranchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class BranchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ReturnStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ReturnStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ThrowStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ThrowStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class TryStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class TryStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class CatchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class CatchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class FinallyStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class FinallyStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class WaitForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class WaitForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class WithStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class WithStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class DeclStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class DeclStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class NullStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class NullStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+
 }
 
Index: src/AST/StorageClasses.hpp
===================================================================
--- src/AST/StorageClasses.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/StorageClasses.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -33,18 +33,22 @@
 
 	/// Bitflag type for storage classes
-	union Classes {
-		unsigned int val;
-		struct {
-			bool is_extern      : 1;
-			bool is_static      : 1;
-			bool is_auto        : 1;
-			bool is_register    : 1;
-			bool is_threadlocal : 1;
+	struct class_flags {
+		union {
+			unsigned int val;
+			struct {
+				bool is_extern      : 1;
+				bool is_static      : 1;
+				bool is_auto        : 1;
+				bool is_register    : 1;
+				bool is_threadlocal : 1;
+			};
+
+			// MakeBitfieldPrint( NumClasses )
 		};
 
-		MakeBitfield( Classes )
-		MakeBitfieldPrint( NumClasses )
+		constexpr class_flags( unsigned int val ) : val(val) {}
 	};
 
+	using Classes = bitfield<class_flags>;
 }
 }
Index: src/AST/Type.hpp
===================================================================
--- src/AST/Type.hpp	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/AST/Type.hpp	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -24,4 +24,54 @@
 };
 
+
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Type * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class Type * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class VoidType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class VoidType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class BasicType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class BasicType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class PointerType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class PointerType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ArrayType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ArrayType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ReferenceType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ReferenceType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class QualifiedType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class QualifiedType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class FunctionType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class FunctionType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ReferenceToType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ReferenceToType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class StructInstType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class StructInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class UnionInstType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class UnionInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class EnumInstType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class EnumInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class TraitInstType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class TraitInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class TypeInstType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class TypeInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class TupleType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class TupleType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class TypeofType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class TypeofType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class AttrType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class AttrType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class VarArgsType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class VarArgsType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ZeroType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ZeroType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class OneType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class OneType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class GlobalScopeType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class GlobalScopeType * node, Node::ref_type ref ) { node->decrement( ref ); }
+
 }
 
Index: src/Common/PassVisitor.impl.h
===================================================================
--- src/Common/PassVisitor.impl.h	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/Common/PassVisitor.impl.h	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -168,4 +168,5 @@
 template< typename Container, typename pass_type >
 inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) {
+
 	if ( ! mutator.get_visit_children() ) return;
 	SemanticErrorException errors;
@@ -217,4 +218,5 @@
 		try {
 			func( *i );
+			assert( *i );
 			assert(( empty( beforeStmts ) && empty( afterStmts ))
 			    || ( empty( beforeDecls ) && empty( afterDecls )) );
Index: src/Common/PassVisitor.proto.h
===================================================================
--- src/Common/PassVisitor.proto.h	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/Common/PassVisitor.proto.h	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -222,4 +222,6 @@
 INDEXER_FUNC2( addWith   , std::list< Expression * > &, BaseSyntaxNode * );
 
+#undef INDEXER_FUNC1
+#undef INDEXER_FUNC2
 
 template<typename pass_type>
Index: src/SynTree/Declaration.h
===================================================================
--- src/SynTree/Declaration.h	(revision 0727d97a496de36de89a35cb96c00a6772a97d98)
+++ src/SynTree/Declaration.h	(revision 336d0b358f47a852a1638773577aca306f416c9e)
@@ -71,7 +71,7 @@
 	static Declaration *declFromId( UniqueId id );
 
-  private:
+	UniqueId uniqueId;
 	Type::StorageClasses storageClasses;
-	UniqueId uniqueId;
+  private:
 };
 
@@ -213,9 +213,9 @@
 		TypeDecl::Kind kind;
 		bool isComplete;
-		
+
 		Data() : kind( (TypeDecl::Kind)-1 ), isComplete( false ) {}
 		Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {}
 		Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {}
-		Data( const Data& d1, const Data& d2 ) 
+		Data( const Data& d1, const Data& d2 )
 		: kind( d1.kind ), isComplete ( d1.isComplete || d2.isComplete ) {}
 
