Index: src/CodeTools/TrackLoc.cc
===================================================================
--- src/CodeTools/TrackLoc.cc	(revision dba6db9a6025d74a9abed179c7aefcec1d0d09ab)
+++ src/CodeTools/TrackLoc.cc	(revision 13932f1466902c0dc5d4b542261856dbf70e34fa)
@@ -16,10 +16,14 @@
 #include "TrackLoc.h"
 
+#include <cstdlib>
+
 #include <iostream>
 #include <sstream>
+#include <stack>
 #include <string>
-#include <cstdlib>
+#include <typeindex>
 
 #include "Common/utility.h"
+#include "Common/PassVisitor.h"
 #include "Common/VectorMap.h"
 #include "GenPoly/GenPoly.h"
@@ -27,157 +31,66 @@
 #include "SynTree/Declaration.h"
 #include "SynTree/Initializer.h"
-#include "SynTree/Visitor.h"
 
 namespace CodeTools {
 
-    std::ostream & operator<<(std::ostream & out, CodeLocation const & loc) {
-        return out << loc.filename << '[' << loc.linenumber << ']';
-    }
+	std::ostream & operator<<(std::ostream & out, CodeLocation const & loc) {
+		return out << loc.filename << '[' << loc.linenumber << ']';
+	}
 
-	class LocationPrinter : public Visitor {
-		unsigned int printLevel;
-		unsigned int currentLevel;
+	class LocationPrinter {
+		size_t printLevel;
 
-		CodeLocation *parent;
 		CodeLocation *lastNode;
 
-    public:
-        LocationPrinter(unsigned int printLevel) :
-            Visitor(), printLevel(printLevel), currentLevel(0),
-			parent(nullptr), lastNode(nullptr)
-        {}
+		std::stack< CodeLocation * > parents;
+	public:
+		LocationPrinter(size_t printLevel) : 
+			printLevel(printLevel), lastNode(nullptr)
+		{}
 
-        void print(char const * name, BaseSyntaxNode *node) {
-            for (unsigned int i = 0 ; i < currentLevel ; ++i) {
+		void print( const std::string& name, BaseSyntaxNode *node) {
+			for (size_t i = 0 ; i < parents.size() ; ++i) {
 				std::cout << "    ";
 			}
-            if (2 <= printLevel) {
+			if (2 <= printLevel) {
 				std::cout << name << '@';
 			}
 			std::cout << node->location << std::endl;
-        }
+		}
 
-		void atNode(char const * name, BaseSyntaxNode *node) {
-			if (-1 == node->location.linenumber) {
-				if (nullptr != parent) {
-					node->location.linenumber = parent->linenumber;
-					node->location.filename = parent->filename;
-				} else if (nullptr != lastNode) {
-					node->location.linenumber = lastNode->linenumber;
-					node->location.filename = lastNode->filename;
-				} else {
-					std::cerr << "Top level node has no CodeLocation " <<
-								 name << std::endl;
+		void atNode( BaseSyntaxNode *node ) {
+			std::string name = std::type_index(typeid(*node)).name();
+			if ( node->location.isUnset() ) {
+				if ( !parents.empty() ) {
+					node->location = *parents.top();
+				} 
+				else if (nullptr != lastNode) {
+					node->location = *lastNode;
+				} 
+				else {
+					std::cerr << "Top level node has no CodeLocation " << name << std::endl;
 					exit(EXIT_FAILURE);
 				}
 			}
+
 			if (0 < printLevel) {
-				print(name, node);
+				print( name, node );
 			}
 			lastNode = &node->location;
 		}
 
-#define VISIT_FUNCTION(SyntaxNodeType)				\
-		virtual void visit(SyntaxNodeType *node) {	\
-			atNode(#SyntaxNodeType, node);			\
-			++currentLevel;							\
-			CodeLocation * myParent = parent;		\
-			parent = &node->location;				\
-			Visitor::visit(node);					\
-			parent = myParent;						\
-			--currentLevel;							\
+		void previsit(BaseSyntaxNode * node) {
+			atNode(node);
+			parents.push( &node->location );
 		}
 
-		VISIT_FUNCTION(ObjectDecl)
-		VISIT_FUNCTION(FunctionDecl)
-		VISIT_FUNCTION(StructDecl)
-		VISIT_FUNCTION(UnionDecl)
-		VISIT_FUNCTION(EnumDecl)
-		VISIT_FUNCTION(TraitDecl)
-		VISIT_FUNCTION(TypeDecl)
-		VISIT_FUNCTION(TypedefDecl)
-		VISIT_FUNCTION(AsmDecl)
-
-		VISIT_FUNCTION(CompoundStmt)
-		VISIT_FUNCTION(ExprStmt)
-		VISIT_FUNCTION(AsmStmt)
-		VISIT_FUNCTION(IfStmt)
-		VISIT_FUNCTION(WhileStmt)
-		VISIT_FUNCTION(ForStmt)
-		VISIT_FUNCTION(SwitchStmt)
-		VISIT_FUNCTION(CaseStmt)
-		VISIT_FUNCTION(BranchStmt)
-		VISIT_FUNCTION(ReturnStmt)
-		VISIT_FUNCTION(TryStmt)
-		VISIT_FUNCTION(CatchStmt)
-		VISIT_FUNCTION(FinallyStmt)
-		VISIT_FUNCTION(NullStmt)
-		VISIT_FUNCTION(DeclStmt)
-		VISIT_FUNCTION(ImplicitCtorDtorStmt)
-
-		VISIT_FUNCTION(ApplicationExpr)
-		VISIT_FUNCTION(UntypedExpr)
-		VISIT_FUNCTION(NameExpr)
-		VISIT_FUNCTION(CastExpr)
-		VISIT_FUNCTION(AddressExpr)
-		VISIT_FUNCTION(LabelAddressExpr)
-		VISIT_FUNCTION(UntypedMemberExpr)
-		VISIT_FUNCTION(MemberExpr)
-		VISIT_FUNCTION(VariableExpr)
-		VISIT_FUNCTION(ConstantExpr)
-		VISIT_FUNCTION(SizeofExpr)
-		VISIT_FUNCTION(AlignofExpr)
-		VISIT_FUNCTION(UntypedOffsetofExpr)
-		VISIT_FUNCTION(OffsetofExpr)
-		VISIT_FUNCTION(OffsetPackExpr)
-		VISIT_FUNCTION(AttrExpr)
-		VISIT_FUNCTION(LogicalExpr)
-		VISIT_FUNCTION(ConditionalExpr)
-		VISIT_FUNCTION(CommaExpr)
-		VISIT_FUNCTION(TypeExpr)
-		VISIT_FUNCTION(AsmExpr)
-		VISIT_FUNCTION(ImplicitCopyCtorExpr)
-		VISIT_FUNCTION(ConstructorExpr)
-		VISIT_FUNCTION(CompoundLiteralExpr)
-		VISIT_FUNCTION(UntypedValofExpr)
-		VISIT_FUNCTION(RangeExpr)
-		VISIT_FUNCTION(UntypedTupleExpr)
-		VISIT_FUNCTION(TupleExpr)
-		VISIT_FUNCTION(TupleIndexExpr)
-		VISIT_FUNCTION(MemberTupleExpr)
-		VISIT_FUNCTION(TupleAssignExpr)
-		VISIT_FUNCTION(StmtExpr)
-		VISIT_FUNCTION(UniqueExpr)
-
-		VISIT_FUNCTION(VoidType)
-		VISIT_FUNCTION(BasicType)
-		VISIT_FUNCTION(PointerType)
-		VISIT_FUNCTION(ArrayType)
-		VISIT_FUNCTION(FunctionType)
-		VISIT_FUNCTION(StructInstType)
-		VISIT_FUNCTION(UnionInstType)
-		VISIT_FUNCTION(EnumInstType)
-		VISIT_FUNCTION(TraitInstType)
-		VISIT_FUNCTION(TypeInstType)
-		VISIT_FUNCTION(TupleType)
-		VISIT_FUNCTION(TypeofType)
-		VISIT_FUNCTION(AttrType)
-		VISIT_FUNCTION(VarArgsType)
-		VISIT_FUNCTION(ZeroType)
-		VISIT_FUNCTION(OneType)
-
-		VISIT_FUNCTION(SingleInit)
-		VISIT_FUNCTION(ListInit)
-		VISIT_FUNCTION(ConstructorInit)
-
-		//VISIT_FUNCTION(Subrange)
-
-		//VISIT_FUNCTION(Constant)
+		void postvisit(BaseSyntaxNode * node) {
+			parents.pop();
+		}
 
 	}; // LocationPrinter
 
-	void fillLocations( std::list< Declaration * > & translationUnit,
-			unsigned int printLevel) {
-		LocationPrinter printer(printLevel);
+	void fillLocations( std::list< Declaration * > & translationUnit, size_t printLevel) {
+		PassVisitor<LocationPrinter> printer(printLevel);
 		acceptAll( translationUnit, printer );
 	}
Index: src/CodeTools/TrackLoc.h
===================================================================
--- src/CodeTools/TrackLoc.h	(revision dba6db9a6025d74a9abed179c7aefcec1d0d09ab)
+++ src/CodeTools/TrackLoc.h	(revision 13932f1466902c0dc5d4b542261856dbf70e34fa)
@@ -24,6 +24,5 @@
 	// printLevel: how much printing while filling in the node locations.
 	// 0 - No Printing, 1 - Print Location, 2 - Print Node Type and Location
-	void fillLocations( std::list< Declaration * > &translationUnit,
-			unsigned int printLevel = 0 );
+	void fillLocations( std::list< Declaration * > &translationUnit, size_t printLevel = 0 );
 
 }  // namespace CodeTools
