Index: src/SymTab/IdTable.cc
===================================================================
--- src/SymTab/IdTable.cc	(revision 839ccbb4f2b1444ec5ecfdc58dafbca86c655aec)
+++ src/SymTab/IdTable.cc	(revision 5189888c01c25f70a752b7907df395785fca58cd)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Sun May 17 17:04:02 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sun May 17 17:07:43 2015
-// Update Count     : 3
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Oct 07 12:21:13 2015
+// Update Count     : 73
 //
 
@@ -37,4 +37,5 @@
 			for ( InnerTableType::iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) {
 				std::stack< DeclEntry >& entry = inner->second;
+				// xxx - should be while?
 				if ( ! entry.empty() && entry.top().second == scopeLevel ) {
 					entry.pop();
@@ -52,4 +53,9 @@
 		if ( decl->get_linkage() == LinkageSpec::C ) {
 			manglename = name;
+		} else if ( LinkageSpec::isOverridable( decl->get_linkage() ) ) {
+			// mangle the name without including the appropriate suffix
+			// this will make it so that overridable routines are placed
+			// into the same "bucket" as their user defined versions.
+			manglename = Mangler::mangle( decl, false );
 		} else {
 			manglename = Mangler::mangle( decl );
@@ -60,18 +66,36 @@
 
 		if ( it == declTable.end() ) {
+			// first time this name mangling has been defined
 			declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
 		} else {
 			std::stack< DeclEntry >& entry = it->second;
 			if ( ! entry.empty() && entry.top().second == scopeLevel ) {
-				if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
+				// if we're giving the same name mangling to things of
+				//  different types then there is something wrong
+				Declaration *old = entry.top().first;
+				assert( (dynamic_cast<ObjectDecl*>( decl ) && dynamic_cast<ObjectDecl*>( old ) )
+				  || (dynamic_cast<FunctionDecl*>( decl ) && dynamic_cast<FunctionDecl*>( old ) ) );
+
+				if ( LinkageSpec::isOverridable( old->get_linkage() ) ) {
+					// new definition shadows the autogenerated one, even at the same scope
+					declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
+				} else if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
+					// typesCompatible doesn't really do the right thing here. When checking compatibility of function types,
+					// we should ignore outermost pointer qualifiers, except _Atomic?
 					FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( decl );
-					FunctionDecl *old = dynamic_cast< FunctionDecl* >( entry.top().first );
-					if ( newentry && old && newentry->get_statements() && old->get_statements() ) {
-						throw SemanticError( "duplicate function definition for ", decl );
+					FunctionDecl *oldentry = dynamic_cast< FunctionDecl* >( old );
+					if ( newentry && oldentry ) {
+						if ( newentry->get_statements() && oldentry->get_statements() ) {
+							throw SemanticError( "duplicate function definition for 1 ", decl );
+						} // if
 					} else {
+						// two objects with the same mangled name defined in the same scope.
+						// both objects must be marked extern or both must be intrinsic for this to be okay
+						// xxx - perhaps it's actually if either is intrinsic then this is okay?
+						//       might also need to be same storage class?
 						ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( decl );
-						ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( entry.top().first );
-						if ( newobj && oldobj && newobj->get_init() && oldobj->get_init() ) {
-							throw SemanticError( "duplicate definition for ", decl );
+						ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( old );
+						if (newobj->get_storageClass() != DeclarationNode::Extern && oldobj->get_storageClass() != DeclarationNode::Extern ) {
+							throw SemanticError( "duplicate definition for 3 ", decl );
 						} // if
 					} // if
@@ -80,8 +104,9 @@
 				} // if
 			} else {
+				// new scope level - shadow existing definition
 				declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
 			} // if
 		} // if
-		// ensure the set of routines with C linkage cannot be overloaded
+		// this ensures that no two declarations with the same unmangled name both have C linkage
 		for ( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) {
 			if ( ! i->second.empty() && i->second.top().first->get_linkage() == LinkageSpec::C && declTable.size() > 1 ) {
Index: src/SymTab/Mangler.cc
===================================================================
--- src/SymTab/Mangler.cc	(revision 839ccbb4f2b1444ec5ecfdc58dafbca86c655aec)
+++ src/SymTab/Mangler.cc	(revision 5189888c01c25f70a752b7907df395785fca58cd)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Sun May 17 21:40:29 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Jun  8 15:12:12 2015
-// Update Count     : 8
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Aug 19 15:52:24 2015
+// Update Count     : 19
 //
 
@@ -30,5 +30,5 @@
 
 namespace SymTab {
-	Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) {
+	Mangler::Mangler( bool mangleOverridable ) : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ) {
 	}
 
@@ -41,4 +41,5 @@
 		nextVarNum = rhs.nextVarNum;
 		isTopLevel = rhs.isTopLevel;
+		mangleOverridable = rhs.mangleOverridable;
 	}
 
@@ -59,4 +60,16 @@
 		mangleName << "__";
 		maybeAccept( declaration->get_type(), *this );
+		if ( mangleOverridable && LinkageSpec::isOverridable( declaration->get_linkage() ) ) {
+			// want to be able to override autogenerated and intrinsic routines,
+			// so they need a different name mangling
+			if ( declaration->get_linkage() == LinkageSpec::AutoGen ) {
+				mangleName << "autogen__";
+			} else if ( declaration->get_linkage() == LinkageSpec::Intrinsic ) {
+				mangleName << "intrinsic__";
+			} else {
+				// if we add another kind of overridable function, this has to change
+				assert( false );
+			} // if
+		}
 		isTopLevel = wasTopLevel;
 	}
@@ -214,5 +227,5 @@
 				varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() );
 				for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
-					Mangler sub_mangler;
+					Mangler sub_mangler( mangleOverridable );
 					sub_mangler.nextVarNum = nextVarNum;
 					sub_mangler.isTopLevel = false;
Index: src/SymTab/Mangler.h
===================================================================
--- src/SymTab/Mangler.h	(revision 839ccbb4f2b1444ec5ecfdc58dafbca86c655aec)
+++ src/SymTab/Mangler.h	(revision 5189888c01c25f70a752b7907df395785fca58cd)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Sun May 17 21:44:03 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Jun  8 14:47:14 2015
-// Update Count     : 5
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Aug 19 15:48:46 2015
+// Update Count     : 14
 //
 
@@ -25,5 +25,5 @@
 	  public:
 		template< typename SynTreeClass >
-	    static std::string mangle( SynTreeClass *decl ); // interface to clients
+	    static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true ); // interface to clients
 
 ///   using Visitor::visit;
@@ -50,6 +50,7 @@
 		int nextVarNum;
 		bool isTopLevel;
+		bool mangleOverridable;
   
-		Mangler();
+		Mangler( bool mangleOverridable );
 		Mangler( const Mangler & );
   
@@ -61,6 +62,6 @@
 
 	template< typename SynTreeClass >
-	std::string Mangler::mangle( SynTreeClass *decl ) {
-		Mangler mangler;
+	std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable ) {
+		Mangler mangler( mangleOverridable );
 		maybeAccept( decl, mangler );
 		return mangler.get_mangleName();
Index: src/SymTab/Validate.cc
===================================================================
--- src/SymTab/Validate.cc	(revision 839ccbb4f2b1444ec5ecfdc58dafbca86c655aec)
+++ src/SymTab/Validate.cc	(revision 5189888c01c25f70a752b7907df395785fca58cd)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Sun May 17 21:50:04 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Nov 19 22:31:41 2015
-// Update Count     : 197
+// Last Modified By : Rob Schluntz
+// Last Modified On : Fri Nov 20 16:33:52 2015
+// Update Count     : 201
 //
 
@@ -54,4 +54,5 @@
 #include "MakeLibCfa.h"
 #include "TypeEquality.h"
+#include "ResolvExpr/typeops.h"
 
 #define debugPrint( x ) if ( doDebug ) { std::cout << x; }
@@ -125,8 +126,8 @@
 	};
 
-	class AddStructAssignment : public Visitor {
+	class AutogenerateRoutines : public Visitor {
 	  public:
 		/// Generates assignment operators for aggregate types as required
-		static void addStructAssignment( std::list< Declaration * > &translationUnit );
+		static void autogenerateRoutines( std::list< Declaration * > &translationUnit );
 
 		std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
@@ -151,5 +152,5 @@
 		virtual void visit( CatchStmt *catchStmt );
 
-		AddStructAssignment() : functionNesting( 0 ) {}
+		AutogenerateRoutines() : functionNesting( 0 ) {}
 	  private:
 		template< typename StmtClass > void visitStatement( StmtClass *stmt );
@@ -195,7 +196,5 @@
 		acceptAll( translationUnit, pass1 );
 		acceptAll( translationUnit, pass2 );
-		// need to collect all of the assignment operators prior to this point and only generate assignment operators if
-		// one doesn't exist
-		AddStructAssignment::addStructAssignment( translationUnit );
+		AutogenerateRoutines::autogenerateRoutines( translationUnit );
 		acceptAll( translationUnit, pass3 );
 	}
@@ -501,6 +500,6 @@
 	static const std::list< std::string > noLabels;
 
-	void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {
-		AddStructAssignment visitor;
+	void AutogenerateRoutines::autogenerateRoutines( std::list< Declaration * > &translationUnit ) {
+		AutogenerateRoutines visitor;
 		acceptAndAdd( translationUnit, visitor, false );
 	}
@@ -704,5 +703,5 @@
 	}
 
-	void AddStructAssignment::visit( EnumDecl *enumDecl ) {
+	void AutogenerateRoutines::visit( EnumDecl *enumDecl ) {
 		if ( ! enumDecl->get_members().empty() ) {
 			EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() );
@@ -713,5 +712,5 @@
 	}
 
-	void AddStructAssignment::visit( StructDecl *structDecl ) {
+	void AutogenerateRoutines::visit( StructDecl *structDecl ) {
 		if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
 			StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
@@ -722,5 +721,5 @@
 	}
 
-	void AddStructAssignment::visit( UnionDecl *unionDecl ) {
+	void AutogenerateRoutines::visit( UnionDecl *unionDecl ) {
 		if ( ! unionDecl->get_members().empty() ) {
 			UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
@@ -730,5 +729,5 @@
 	}
 
-	void AddStructAssignment::visit( TypeDecl *typeDecl ) {
+	void AutogenerateRoutines::visit( TypeDecl *typeDecl ) {
 		CompoundStmt *stmts = 0;
 		TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false );
@@ -758,18 +757,18 @@
 	}
 
-	void AddStructAssignment::visit( FunctionType *) {
+	void AutogenerateRoutines::visit( FunctionType *) {
 		// ensure that we don't add assignment ops for types defined as part of the function
 	}
 
-	void AddStructAssignment::visit( PointerType *) {
+	void AutogenerateRoutines::visit( PointerType *) {
 		// ensure that we don't add assignment ops for types defined as part of the pointer
 	}
 
-	void AddStructAssignment::visit( ContextDecl *) {
+	void AutogenerateRoutines::visit( ContextDecl *) {
 		// ensure that we don't add assignment ops for types defined as part of the context
 	}
 
 	template< typename StmtClass >
-	inline void AddStructAssignment::visitStatement( StmtClass *stmt ) {
+	inline void AutogenerateRoutines::visitStatement( StmtClass *stmt ) {
 		std::set< std::string > oldStructs = structsDone;
 		addVisit( stmt, *this );
@@ -777,5 +776,5 @@
 	}
 
-	void AddStructAssignment::visit( FunctionDecl *functionDecl ) {
+	void AutogenerateRoutines::visit( FunctionDecl *functionDecl ) {
 		maybeAccept( functionDecl->get_functionType(), *this );
 		acceptAll( functionDecl->get_oldDecls(), *this );
@@ -785,33 +784,33 @@
 	}
 
-	void AddStructAssignment::visit( CompoundStmt *compoundStmt ) {
+	void AutogenerateRoutines::visit( CompoundStmt *compoundStmt ) {
 		visitStatement( compoundStmt );
 	}
 
-	void AddStructAssignment::visit( IfStmt *ifStmt ) {
+	void AutogenerateRoutines::visit( IfStmt *ifStmt ) {
 		visitStatement( ifStmt );
 	}
 
-	void AddStructAssignment::visit( WhileStmt *whileStmt ) {
+	void AutogenerateRoutines::visit( WhileStmt *whileStmt ) {
 		visitStatement( whileStmt );
 	}
 
-	void AddStructAssignment::visit( ForStmt *forStmt ) {
+	void AutogenerateRoutines::visit( ForStmt *forStmt ) {
 		visitStatement( forStmt );
 	}
 
-	void AddStructAssignment::visit( SwitchStmt *switchStmt ) {
+	void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) {
 		visitStatement( switchStmt );
 	}
 
-	void AddStructAssignment::visit( ChooseStmt *switchStmt ) {
+	void AutogenerateRoutines::visit( ChooseStmt *switchStmt ) {
 		visitStatement( switchStmt );
 	}
 
-	void AddStructAssignment::visit( CaseStmt *caseStmt ) {
+	void AutogenerateRoutines::visit( CaseStmt *caseStmt ) {
 		visitStatement( caseStmt );
 	}
 
-	void AddStructAssignment::visit( CatchStmt *cathStmt ) {
+	void AutogenerateRoutines::visit( CatchStmt *cathStmt ) {
 		visitStatement( cathStmt );
 	}
@@ -857,5 +856,5 @@
 			Type * t1 = tyDecl->get_base();
 			Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
-			if ( ! typeEquals( t1, t2, true ) ) {
+			if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) {
 				throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
 			}
