Index: src/main.cc
===================================================================
--- src/main.cc	(revision f43146e411ed4e5e92fc5256b6ce039536536923)
+++ src/main.cc	(revision 0b5e780a2f1cefd9000944925965a3be14bc56a5)
@@ -31,4 +31,5 @@
 #include "AST/Convert.hpp"
 #include "AST/Pass.hpp"                     // for pass_visitor_stats
+#include "AST/Print.hpp"                    // for printAll
 #include "AST/TranslationUnit.hpp"          // for TranslationUnit
 #include "AST/Util.hpp"                     // for checkInvariants
@@ -132,5 +133,4 @@
 
 static void parse_cmdline( int argc, char * argv[] );
-static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
 static void dump( ast::TranslationUnit && transUnit, ostream & out = cout );
 
@@ -246,5 +246,4 @@
 	FILE * input;										// use FILE rather than istream because yyin is FILE
 	ostream * output = & cout;
-	list< Declaration * > translationUnit;
 	ast::TranslationUnit transUnit;
 
@@ -440,11 +439,5 @@
 		if ( errorp ) {
 			cerr << "---AST at error:---" << endl;
-			// We check which section the errors came from without looking at
-			// transUnit because std::move means it could look like anything.
-			if ( !translationUnit.empty() ) {
-				dump( translationUnit, cerr );
-			} else {
-				dump( std::move( transUnit ), cerr );
-			}
+			dump( std::move( transUnit ), cerr );
 			cerr << endl << "---End of AST, begin error message:---\n" << endl;
 		} // if
@@ -472,5 +465,4 @@
 	} // try
 
-	deleteAll( translationUnit );
 	Stats::print();
 	return EXIT_SUCCESS;
@@ -702,29 +694,23 @@
 } // parse_cmdline
 
-static bool notPrelude( Declaration * decl ) {
-	return ! LinkageSpec::isBuiltin( decl->get_linkage() );
-} // notPrelude
-
-static void dump( list< Declaration * > & translationUnit, ostream & out ) {
-	list< Declaration * > decls;
-
+static bool notPrelude( ast::ptr<ast::Decl> & decl ) {
+	return !decl->linkage.is_builtin;
+}
+
+static void dump( ast::TranslationUnit && unit, std::ostream & out ) {
+	// May filter out all prelude declarations.
 	if ( genproto ) {
-		filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude );
+		std::list<ast::ptr<ast::Decl>> decls;
+		std::copy_if( unit.decls.begin(), unit.decls.end(),
+			std::back_inserter( decls ), notPrelude );
+		decls.swap( unit.decls );
+	}
+
+	// May print as full dump or as code generation.
+	if ( codegenp ) {
+		CodeGen::generate( unit, out, !genproto, prettycodegenp, false, false, false );
 	} else {
-		decls = translationUnit;
-	} // if
-
-	// depending on commandline options, either generate code or dump the AST
-	if ( codegenp ) {
-		CodeGen::generate( decls, out, ! genproto, prettycodegenp );
-	} else {
-		printAll( decls, out );
-	} // if
-	deleteAll( translationUnit );
-} // dump
-
-static void dump( ast::TranslationUnit && transUnit, ostream & out ) {
-	std::list< Declaration * > translationUnit = convert( std::move( transUnit ) );
-	dump( translationUnit, out );
+		ast::printAll( out, unit.decls );
+	}
 }
 
