Index: translator/Parser/TypeData.cc
===================================================================
--- translator/Parser/TypeData.cc	(revision 8c17ab009047298326a3dc92f5ddacbdc08bdc94)
+++ translator/Parser/TypeData.cc	(revision c8ffe20b6084e6e8082ff367961b87d47cfe83ff)
@@ -10,918 +10,813 @@
 
 
-TypeData::TypeData( Kind k )
-  : kind( k ), base( 0 ), forall( 0 )
-{
-  switch( kind ) {
-  case Unknown:
-  case Pointer:
-  case EnumConstant:
-    // nothing else to initialize
-    break;
-
-  case Basic:
-    basic = new Basic_t;
-    break;
-
-  case Array:
-    array = new Array_t;
-    array->dimension = 0;
-    array->isVarLen = false;
-    array->isStatic = false;
-    break;
-
-  case Function:
-    function = new Function_t;
-    function->params = 0;
-    function->idList = 0;
-    function->oldDeclList = 0;
-    function->body = 0;
-    function->hasBody = false;
-    break;
-
-  case Aggregate:
-    aggregate = new Aggregate_t;
-    aggregate->params = 0;
-    aggregate->actuals = 0;
-    aggregate->members = 0;
-    break;
-
-  case AggregateInst:
-    aggInst = new AggInst_t;
-    aggInst->aggregate = 0;
-    aggInst->params = 0;
-    break;
-
-  case Enum:
-    enumeration = new Enumeration_t;
-    enumeration->constants = 0;
-    break;
-
-  case Symbolic:
-  case SymbolicInst:
-    symbolic = new Symbolic_t;
-    symbolic->params = 0;
-    symbolic->actuals = 0;
-    symbolic->assertions = 0;
-    break;
-
-  case Variable:
-    variable = new Variable_t;
-    variable->tyClass = DeclarationNode::Type;
-    variable->assertions = 0;
-    break;
-
-  case Tuple:
-    tuple = new Tuple_t;
-    tuple->members = 0;
-    break;
+TypeData::TypeData( Kind k ) : kind( k ), base( 0 ), forall( 0 ) {
+    switch ( kind ) {
+      case Unknown:
+      case Pointer:
+      case EnumConstant:
+	// nothing else to initialize
+	break;
+      case Basic:
+	basic = new Basic_t;
+	break;
+      case Array:
+	array = new Array_t;
+	array->dimension = 0;
+	array->isVarLen = false;
+	array->isStatic = false;
+	break;
+      case Function:
+	function = new Function_t;
+	function->params = 0;
+	function->idList = 0;
+	function->oldDeclList = 0;
+	function->body = 0;
+	function->hasBody = false;
+	break;
+      case Aggregate:
+	aggregate = new Aggregate_t;
+	aggregate->params = 0;
+	aggregate->actuals = 0;
+	aggregate->members = 0;
+	break;
+      case AggregateInst:
+	aggInst = new AggInst_t;
+	aggInst->aggregate = 0;
+	aggInst->params = 0;
+	break;
+      case Enum:
+	enumeration = new Enumeration_t;
+	enumeration->constants = 0;
+	break;
+      case Symbolic:
+      case SymbolicInst:
+	symbolic = new Symbolic_t;
+	symbolic->params = 0;
+	symbolic->actuals = 0;
+	symbolic->assertions = 0;
+	break;
+      case Variable:
+	variable = new Variable_t;
+	variable->tyClass = DeclarationNode::Type;
+	variable->assertions = 0;
+	break;
+      case Tuple:
+	tuple = new Tuple_t;
+	tuple->members = 0;
+	break;
   
-  case Typeof:
-    typeexpr = new Typeof_t;
-    typeexpr->expr = 0;
-    break;
+      case Typeof:
+	typeexpr = new Typeof_t;
+	typeexpr->expr = 0;
+	break;
   
-  case Attr:
-    attr = new Attr_t;
-    attr->expr = 0;
-    attr->type = 0;
-    break;
-  }
-}
-
-TypeData::~TypeData()
-{
-  delete base;
-  delete forall;
-
-  switch( kind ) {
-  case Unknown:
-  case Pointer:
-  case EnumConstant:
-    // nothing to destroy
-    break;
-
-  case Basic:
-    delete basic;
-    break;
-
-  case Array:
-    delete array->dimension;
-    delete array;
-    break;
-
-  case Function:
-    delete function->params;
-    delete function->idList;
-    delete function->oldDeclList;
-    delete function->body;
-    delete function;
-    break;
-
-  case Aggregate:
-    delete aggregate->params;
-    delete aggregate->actuals;
-    delete aggregate->members;
-    delete aggregate;
-    break;
-
-  case AggregateInst:
-    delete aggInst->aggregate;
-    delete aggInst->params;
-    delete aggInst;
-    break;
-
-  case Enum:
-    delete enumeration->constants;
-    delete enumeration;
-    break;
-
-  case Symbolic:
-  case SymbolicInst:
-    delete symbolic->params;
-    delete symbolic->actuals;
-    delete symbolic->assertions;
-    delete symbolic;
-    break;
-
-  case Variable:
-    delete variable->assertions;
-    delete variable;
-    break;
-
-  case Tuple:
-    delete tuple->members;
-    delete tuple;
-    break;
+      case Attr:
+	attr = new Attr_t;
+	attr->expr = 0;
+	attr->type = 0;
+	break;
+    }
+}
+
+TypeData::~TypeData() {
+    delete base;
+    delete forall;
+
+    switch ( kind ) {
+      case Unknown:
+      case Pointer:
+      case EnumConstant:
+	// nothing to destroy
+	break;
+      case Basic:
+	delete basic;
+	break;
+      case Array:
+	delete array->dimension;
+	delete array;
+	break;
+      case Function:
+	delete function->params;
+	delete function->idList;
+	delete function->oldDeclList;
+	delete function->body;
+	delete function;
+	break;
+      case Aggregate:
+	delete aggregate->params;
+	delete aggregate->actuals;
+	delete aggregate->members;
+	delete aggregate;
+	break;
+      case AggregateInst:
+	delete aggInst->aggregate;
+	delete aggInst->params;
+	delete aggInst;
+	break;
+      case Enum:
+	delete enumeration->constants;
+	delete enumeration;
+	break;
+      case Symbolic:
+      case SymbolicInst:
+	delete symbolic->params;
+	delete symbolic->actuals;
+	delete symbolic->assertions;
+	delete symbolic;
+	break;
+      case Variable:
+	delete variable->assertions;
+	delete variable;
+	break;
+      case Tuple:
+	delete tuple->members;
+	delete tuple;
+	break;
   
-  case Typeof:
-    delete typeexpr->expr;
-    delete typeexpr;
-    break;
+      case Typeof:
+	delete typeexpr->expr;
+	delete typeexpr;
+	break;
   
-  case Attr:
-    delete attr->expr;
-    delete attr->type;
-    delete attr;
-    break;
-  }
-}
-
-TypeData *
-TypeData::clone() const
-{
-  TypeData *newtype = new TypeData( kind );
-  newtype->qualifiers = qualifiers;
-  newtype->base = maybeClone( base );
-  newtype->forall = maybeClone( forall );
-
-  switch( kind ) {
-  case Unknown:
-  case EnumConstant:
-  case Pointer:
-    // nothing else to copy
-    break;
-
-  case Basic:
-    newtype->basic->typeSpec = basic->typeSpec;
-    newtype->basic->modifiers = basic->modifiers;
-    break;
-
-  case Array:
-    newtype->array->dimension = maybeClone( array->dimension );
-    newtype->array->isVarLen = array->isVarLen;
-    newtype->array->isStatic = array->isStatic;
-    break;
-
-  case Function:
-    newtype->function->params = maybeClone( function->params );
-    newtype->function->idList = maybeClone( function->idList );
-    newtype->function->oldDeclList = maybeClone( function->oldDeclList );
-    newtype->function->body = maybeClone( function->body );
-    newtype->function->hasBody = function->hasBody;
-    newtype->function->newStyle = function->newStyle;
-    break;
-
-  case Aggregate:
-    newtype->aggregate->params = maybeClone( aggregate->params );
-    newtype->aggregate->actuals = maybeClone( aggregate->actuals );
-    newtype->aggregate->members = maybeClone( aggregate->members );
-    newtype->aggregate->name = aggregate->name;
-    newtype->aggregate->kind = aggregate->kind;
-    break;
-
-  case AggregateInst:
-    newtype->aggInst->aggregate = maybeClone( aggInst->aggregate );
-    newtype->aggInst->params = maybeClone( aggInst->params );
-    break;
-
-  case Enum:
-    newtype->enumeration->name = enumeration->name;
-    newtype->enumeration->constants = maybeClone( enumeration->constants );
-    break;
-
-  case Symbolic:
-  case SymbolicInst:
-    newtype->symbolic->params = maybeClone( symbolic->params );
-    newtype->symbolic->actuals = maybeClone( symbolic->actuals );
-    newtype->symbolic->assertions = maybeClone( symbolic->assertions );
-    newtype->symbolic->isTypedef = symbolic->isTypedef;
-    newtype->symbolic->name = symbolic->name;
-    break;
-
-  case Variable:
-    newtype->variable->assertions = maybeClone( variable->assertions );
-    newtype->variable->name = variable->name;
-    newtype->variable->tyClass = variable->tyClass;
-    break;
-
-  case Tuple:
-    newtype->tuple->members = maybeClone( tuple->members );
-    break;
+      case Attr:
+	delete attr->expr;
+	delete attr->type;
+	delete attr;
+	break;
+    }
+}
+
+TypeData *TypeData::clone() const {
+    TypeData *newtype = new TypeData( kind );
+    newtype->qualifiers = qualifiers;
+    newtype->base = maybeClone( base );
+    newtype->forall = maybeClone( forall );
+
+    switch ( kind ) {
+      case Unknown:
+      case EnumConstant:
+      case Pointer:
+	// nothing else to copy
+	break;
+      case Basic:
+	newtype->basic->typeSpec = basic->typeSpec;
+	newtype->basic->modifiers = basic->modifiers;
+	break;
+      case Array:
+	newtype->array->dimension = maybeClone( array->dimension );
+	newtype->array->isVarLen = array->isVarLen;
+	newtype->array->isStatic = array->isStatic;
+	break;
+      case Function:
+	newtype->function->params = maybeClone( function->params );
+	newtype->function->idList = maybeClone( function->idList );
+	newtype->function->oldDeclList = maybeClone( function->oldDeclList );
+	newtype->function->body = maybeClone( function->body );
+	newtype->function->hasBody = function->hasBody;
+	newtype->function->newStyle = function->newStyle;
+	break;
+      case Aggregate:
+	newtype->aggregate->params = maybeClone( aggregate->params );
+	newtype->aggregate->actuals = maybeClone( aggregate->actuals );
+	newtype->aggregate->members = maybeClone( aggregate->members );
+	newtype->aggregate->name = aggregate->name;
+	newtype->aggregate->kind = aggregate->kind;
+	break;
+      case AggregateInst:
+	newtype->aggInst->aggregate = maybeClone( aggInst->aggregate );
+	newtype->aggInst->params = maybeClone( aggInst->params );
+	break;
+      case Enum:
+	newtype->enumeration->name = enumeration->name;
+	newtype->enumeration->constants = maybeClone( enumeration->constants );
+	break;
+      case Symbolic:
+      case SymbolicInst:
+	newtype->symbolic->params = maybeClone( symbolic->params );
+	newtype->symbolic->actuals = maybeClone( symbolic->actuals );
+	newtype->symbolic->assertions = maybeClone( symbolic->assertions );
+	newtype->symbolic->isTypedef = symbolic->isTypedef;
+	newtype->symbolic->name = symbolic->name;
+	break;
+      case Variable:
+	newtype->variable->assertions = maybeClone( variable->assertions );
+	newtype->variable->name = variable->name;
+	newtype->variable->tyClass = variable->tyClass;
+	break;
+      case Tuple:
+	newtype->tuple->members = maybeClone( tuple->members );
+	break;
     
-  case Typeof:
-    newtype->typeexpr->expr = maybeClone( typeexpr->expr );
-    break;
+      case Typeof:
+	newtype->typeexpr->expr = maybeClone( typeexpr->expr );
+	break;
   
-  case Attr:
-    newtype->attr->expr = maybeClone( attr->expr );
-    newtype->attr->type = maybeClone( attr->type );
-    break;
-  }
-  return newtype;
-}
-
-void 
-TypeData::print( std::ostream &os, int indent ) const
-{
-  using std::endl;
-  using std::string;
-
-  printEnums( qualifiers.begin(), qualifiers.end(), DeclarationNode::qualifierName, os );
-
-  if( forall ) {
-    os << "forall " << endl;
-    forall->printList( os, indent+4 );
-  }
-
-  switch( kind ) {
-  case Unknown:
-    os << "entity of unknown type ";
-    break;
-
-  case Pointer:
-    os << "pointer ";
-    if( base ) {
-      os << "to ";
-      base->print( os, indent );
-    }
-    break;
-
-  case EnumConstant:
-    os << "enumeration constant ";
-    break;
-
-  case Basic:
-    printEnums( basic->modifiers.begin(), basic->modifiers.end(), DeclarationNode::modifierName, os );
-    printEnums( basic->typeSpec.begin(), basic->typeSpec.end(), DeclarationNode::basicTypeName, os );
-    break;
-
-  case Array:
-    if( array->isStatic ) {
-      os << "static ";
-    }
-    if( array->dimension ) {
-      os << "array of ";
-      array->dimension->printOneLine( os, indent );
-    } else if ( array->isVarLen ) {
-      os << "variable-length array of ";
-    } else {
-      os << "open array of ";
-    }
-    if( base ) {
-      base->print( os, indent );
-    }
-    break;
-
-  case Function:
-    os << "function" << endl;
-    if ( function->params ) {
-      os << string( indent+2, ' ' ) << "with parameters " << endl;
-      function->params->printList( os, indent+4 );
-    } else {
-      os << string( indent+2, ' ' ) << "with no parameters " << endl;
-    }
-    if ( function->idList ) {
-      os << string( indent+2, ' ' ) << "with old-style identifier list " << endl;
-      function->idList->printList( os, indent+4 );
-    }
-    if ( function->oldDeclList ) {
-      os << string( indent+2, ' ' ) << "with old-style declaration list " << endl;
-      function->oldDeclList->printList( os, indent+4 );
-    }
-    os << string( indent+2, ' ' ) << "returning ";
-    if ( base ) {
-      base->print( os, indent+4 );
-    } else {
-      os << "nothing ";
-    }
-    os << endl;
-    if ( function->hasBody ) {
-      os << string( indent+2, ' ' ) << "with body " << endl;
-    }
-    if ( function->body ) {
-      function->body->printList( os, indent+2 );
-    }
-    break;
-
-  case Aggregate:
-    os << DeclarationNode::tyConName[ aggregate->kind ] << ' ' << aggregate->name << endl;
-    if( aggregate->params ) {
-      os << string( indent+2, ' ' ) << "with type parameters " << endl;
-      aggregate->params->printList( os, indent+4 );
-    }
-    if( aggregate->actuals ) {
-      os << string( indent+2, ' ' ) << "instantiated with actual parameters " << endl;
-      aggregate->actuals->printList( os, indent+4 );
-    }
-    if( aggregate->members ) {
-      os << string( indent+2, ' ' ) << "with members " << endl;
-      aggregate->members->printList( os, indent+4 );
+      case Attr:
+	newtype->attr->expr = maybeClone( attr->expr );
+	newtype->attr->type = maybeClone( attr->type );
+	break;
+    }
+    return newtype;
+}
+
+void TypeData::print( std::ostream &os, int indent ) const {
+    using std::endl;
+    using std::string;
+
+    printEnums( qualifiers.begin(), qualifiers.end(), DeclarationNode::qualifierName, os );
+
+    if ( forall ) {
+	os << "forall " << endl;
+	forall->printList( os, indent+4 );
+    }
+
+    switch ( kind ) {
+      case Unknown:
+	os << "entity of unknown type ";
+	break;
+      case Pointer:
+	os << "pointer ";
+	if ( base ) {
+	    os << "to ";
+	    base->print( os, indent );
+	}
+	break;
+      case EnumConstant:
+	os << "enumeration constant ";
+	break;
+      case Basic:
+	printEnums( basic->modifiers.begin(), basic->modifiers.end(), DeclarationNode::modifierName, os );
+	printEnums( basic->typeSpec.begin(), basic->typeSpec.end(), DeclarationNode::basicTypeName, os );
+	break;
+      case Array:
+	if ( array->isStatic ) {
+	    os << "static ";
+	}
+	if ( array->dimension ) {
+	    os << "array of ";
+	    array->dimension->printOneLine( os, indent );
+	} else if ( array->isVarLen ) {
+	    os << "variable-length array of ";
+	} else {
+	    os << "open array of ";
+	}
+	if ( base ) {
+	    base->print( os, indent );
+	}
+	break;
+      case Function:
+	os << "function" << endl;
+	if ( function->params ) {
+	    os << string( indent+2, ' ' ) << "with parameters " << endl;
+	    function->params->printList( os, indent+4 );
+	} else {
+	    os << string( indent+2, ' ' ) << "with no parameters " << endl;
+	}
+	if ( function->idList ) {
+	    os << string( indent+2, ' ' ) << "with old-style identifier list " << endl;
+	    function->idList->printList( os, indent+4 );
+	}
+	if ( function->oldDeclList ) {
+	    os << string( indent+2, ' ' ) << "with old-style declaration list " << endl;
+	    function->oldDeclList->printList( os, indent+4 );
+	}
+	os << string( indent+2, ' ' ) << "returning ";
+	if ( base ) {
+	    base->print( os, indent+4 );
+	} else {
+	    os << "nothing ";
+	}
+	os << endl;
+	if ( function->hasBody ) {
+	    os << string( indent+2, ' ' ) << "with body " << endl;
+	}
+	if ( function->body ) {
+	    function->body->printList( os, indent+2 );
+	}
+	break;
+      case Aggregate:
+	os << DeclarationNode::tyConName[ aggregate->kind ] << ' ' << aggregate->name << endl;
+	if ( aggregate->params ) {
+	    os << string( indent+2, ' ' ) << "with type parameters " << endl;
+	    aggregate->params->printList( os, indent+4 );
+	}
+	if ( aggregate->actuals ) {
+	    os << string( indent+2, ' ' ) << "instantiated with actual parameters " << endl;
+	    aggregate->actuals->printList( os, indent+4 );
+	}
+	if ( aggregate->members ) {
+	    os << string( indent+2, ' ' ) << "with members " << endl;
+	    aggregate->members->printList( os, indent+4 );
 ///     } else {
 ///       os << string( indent+2, ' ' ) << "with no members " << endl;
-    }
-    break;
-
-  case AggregateInst:
-    if( aggInst->aggregate ) {
-      os << "instance of " ;
-      aggInst->aggregate->print( os, indent );
+	}
+	break;
+      case AggregateInst:
+	if ( aggInst->aggregate ) {
+	    os << "instance of " ;
+	    aggInst->aggregate->print( os, indent );
+	} else {
+	    os << "instance of an unspecified aggregate ";
+	}
+	if ( aggInst->params ) {
+	    os << string( indent+2, ' ' ) << "with parameters " << endl;
+	    aggInst->params->printList( os, indent+2 );
+	}
+	break;
+      case Enum:
+	os << "enumeration ";
+	if ( enumeration->constants ) {
+	    os << "with constants" << endl;
+	    enumeration->constants->printList( os, indent+2 );
+	}
+	break;
+      case SymbolicInst:
+	os << "instance of type " << symbolic->name;
+	if ( symbolic->actuals ) {
+	    os << " with parameters" << endl;
+	    symbolic->actuals->printList( os, indent + 2 );
+	}
+	break;
+      case Symbolic:
+	if ( symbolic->isTypedef ) {
+	    os << "typedef definition ";
+	} else {
+	    os << "type definition ";
+	}
+	if ( symbolic->params ) {
+	    os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
+	    symbolic->params->printList( os, indent + 2 );
+	}
+	if ( symbolic->assertions ) {
+	    os << endl << string( indent+2, ' ' ) << "with assertions" << endl;
+	    symbolic->assertions->printList( os, indent + 4 );
+	    os << string( indent+2, ' ' );
+	}
+	if ( base ) {
+	    os << "for ";
+	    base->print( os, indent + 2 );
+	}
+	break;
+      case Variable:
+	os << DeclarationNode::typeClassName[ variable->tyClass ] << " variable ";
+	if ( variable->assertions ) {
+	    os << endl << string( indent+2, ' ' ) << "with assertions" << endl;
+	    variable->assertions->printList( os, indent + 4 );
+	    os << string( indent+2, ' ' );
+	}
+	break;
+      case Tuple:
+	os << "tuple ";
+	if ( tuple->members ) {
+	    os << "with members " << endl;
+	    tuple->members->printList( os, indent + 2 );
+	}
+	break;
+    
+      case Typeof:
+	os << "type-of expression ";
+	if ( typeexpr->expr ) {
+	    typeexpr->expr->print( os, indent + 2 );
+	}
+	break;
+    
+      case Attr:
+	os << "attribute type decl " << attr->name << " applied to ";
+	if ( attr->expr ) {
+	    attr->expr->print( os, indent + 2 );
+	}
+	if ( attr->type ) {
+	    attr->type->print( os, indent + 2 );
+	}
+	break;
+    }
+}
+
+TypeData *TypeData::extractAggregate( bool toplevel ) const {
+    TypeData *ret = 0;
+
+    switch ( kind ) {
+      case Aggregate:
+	if ( !toplevel && aggregate->members ) {
+	    ret = clone();
+	    ret->qualifiers.clear();
+	}
+	break;
+      case Enum:
+	if ( !toplevel && enumeration->constants ) {
+	    ret = clone();
+	    ret->qualifiers.clear();
+	}
+	break;
+      case AggregateInst:
+	if ( aggInst->aggregate ) {
+	    ret = aggInst->aggregate->extractAggregate( false );
+	}
+	break;
+      default:
+	if ( base ) {
+	    ret = base->extractAggregate( false );
+	}
+    }
+    return ret;
+}
+
+void buildForall( const DeclarationNode *firstNode, std::list< TypeDecl* > &outputList ) {
+  
+    buildList( firstNode, outputList );
+    for ( std::list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) {
+	if ( (*i)->get_kind() == TypeDecl::Any ) {
+	    FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
+	    assignType->get_parameters().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
+	    assignType->get_parameters().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
+	    assignType->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
+	    (*i)->get_assertions().push_front( new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::Cforall,  assignType, 0, false ) );
+	}
+    }
+}
+
+Declaration *TypeData::buildDecl( std::string name, Declaration::StorageClass sc, Expression *bitfieldWidth, bool isInline, LinkageSpec::Type linkage, Initializer *init ) const {
+    if ( kind == TypeData::Function ) {
+	FunctionDecl *decl;
+	if ( function->hasBody ) {
+	    if ( function->body ) {
+		Statement *stmt = function->body->build();
+		CompoundStmt *body = dynamic_cast< CompoundStmt* >( stmt );
+		assert( body );
+		decl = new FunctionDecl( name, sc, linkage, buildFunction(), body, isInline );
+	    } else {
+		// std::list<Label> ls;
+		decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list<Label>() ), isInline );
+	    }
+	} else {
+	    decl = new FunctionDecl( name, sc, linkage, buildFunction(), 0, isInline );
+	}
+	for ( DeclarationNode *cur = function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_link() ) ) {
+	    if ( cur->get_name() != "" ) {
+		decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() );
+	    }
+	}
+	buildList( function->oldDeclList, decl->get_oldDecls() );
+	return decl;
+    } else if ( kind == TypeData::Aggregate ) {
+	return buildAggregate();
+    } else if ( kind == TypeData::Enum ) {
+	return buildEnum();
+    } else if ( kind == TypeData::Symbolic ) {
+	return buildSymbolic( name, sc );
+    } else if ( kind == TypeData::Variable ) {
+	return buildVariable();
     } else {
-      os << "instance of an unspecified aggregate ";
-    }
-    if( aggInst->params ) {
-      os << string( indent+2, ' ' ) << "with parameters " << endl;
-      aggInst->params->printList( os, indent+2 );
-    }
-    break;
-
-  case Enum:
-    os << "enumeration ";
-    if( enumeration->constants ) {
-      os << "with constants" << endl;
-      enumeration->constants->printList( os, indent+2 );
-    }
-    break;
-
-  case SymbolicInst:
-    os << "instance of type " << symbolic->name;
-    if( symbolic->actuals ) {
-      os << " with parameters" << endl;
-      symbolic->actuals->printList( os, indent + 2 );
-    }
-    break;
-
-  case Symbolic:
-    if( symbolic->isTypedef ) {
-      os << "typedef definition ";
+	if ( isInline ) {
+	    throw SemanticError( "invalid inline specification in declaration of ", this );
+	} else {
+	    return new ObjectDecl( name, sc, linkage, bitfieldWidth, build(), init );
+	}
+    }
+    return 0;
+}
+
+Type *TypeData::build() const {
+
+    switch ( kind ) {
+      case Unknown:
+	// fill in implicit int
+	return new BasicType( buildQualifiers(), BasicType::SignedInt );
+
+      case Basic:
+	return buildBasicType();
+
+      case Pointer:
+	return buildPointer();
+
+      case Array:
+	return buildArray();
+
+      case Function:
+	return buildFunction();
+
+      case AggregateInst:
+	return buildAggInst();
+
+      case EnumConstant:
+	// the name gets filled in later -- by SymTab::Validate
+	return new EnumInstType( buildQualifiers(), "" );
+
+      case SymbolicInst:
+	return buildSymbolicInst();;
+
+      case Tuple:
+	return buildTuple();
+  
+      case Typeof:
+	return buildTypeof();
+
+      case Attr:
+	return buildAttr();
+
+      case Symbolic:
+      case Enum:
+      case Aggregate:
+      case Variable:
+	assert( false );
+    }
+
+    return 0;
+}
+
+Type::Qualifiers TypeData::buildQualifiers() const {
+    Type::Qualifiers q;
+    for ( std::list< DeclarationNode::Qualifier >::const_iterator i = qualifiers.begin(); i != qualifiers.end(); ++i ) {
+	switch ( *i ) {
+	  case DeclarationNode::Const:
+	    q.isConst = true;
+	    break;
+	  case DeclarationNode::Volatile:
+	    q.isVolatile = true;
+	    break;
+	  case DeclarationNode::Restrict:
+	    q.isRestrict = true;
+	    break;
+	  case DeclarationNode::Lvalue:
+	    q.isLvalue = true;
+	    break;
+	}
+    }
+    return q;
+}
+
+Type *TypeData::buildBasicType() const {
+    static const BasicType::Kind kindMap[] = { BasicType::Char, BasicType::SignedInt, BasicType::Float, BasicType::Double,
+					       BasicType::Char /* void */, BasicType::Bool, BasicType::DoubleComplex,
+					       BasicType::DoubleImaginary };
+    bool init = false;
+    bool sawDouble = false;
+    bool sawSigned = false;
+    BasicType::Kind ret;
+
+    for ( std::list< DeclarationNode::BasicType >::const_iterator i = basic->typeSpec.begin(); i != basic->typeSpec.end(); ++i ) {
+	if ( !init ) {
+	    init = true;
+	    if ( *i == DeclarationNode::Void ) {
+		if ( basic->typeSpec.size() != 1 || !basic->modifiers.empty() ) {
+		    throw SemanticError( "invalid type specifier \"void\" in type ", this );
+		} else {
+		    return new VoidType( buildQualifiers() );
+		}
+	    } else {
+		ret = kindMap[ *i ];
+	    }
+	} else {
+	    switch ( *i ) {
+	      case DeclarationNode::Float:
+		if ( sawDouble ) {
+		    throw SemanticError( "invalid type specifier \"float\" in type ", this );
+		} else {
+		    switch ( ret ) {
+		      case BasicType::DoubleComplex:
+			ret = BasicType::FloatComplex;
+			break;
+		      case BasicType::DoubleImaginary:
+			ret = BasicType::FloatImaginary;
+			break;
+		      default:
+			throw SemanticError( "invalid type specifier \"float\" in type ", this );
+		    }
+		}
+		break;
+	      case DeclarationNode::Double:
+		if ( sawDouble ) {
+		    throw SemanticError( "duplicate type specifier \"double\" in type ", this );
+		} else {
+		    switch ( ret ) {
+		      case BasicType::DoubleComplex:
+		      case BasicType::DoubleImaginary:
+			break;
+		      default:
+			throw SemanticError( "invalid type specifier \"double\" in type ", this );
+		    }
+		}
+		break;
+	
+	      case DeclarationNode::Complex:
+		switch ( ret ) {
+		  case BasicType::Float:
+		    ret = BasicType::FloatComplex;
+		    break;
+          
+		  case BasicType::Double:
+		    ret = BasicType::DoubleComplex;
+		    break;
+		  default:
+		    throw SemanticError( "invalid type specifier \"complex\" in type ", this );
+		}
+		break;
+        
+	      case DeclarationNode::Imaginary:
+		switch ( ret ) {
+		  case BasicType::Float:
+		    ret = BasicType::FloatImaginary;
+		    break;
+          
+		  case BasicType::Double:
+		    ret = BasicType::DoubleImaginary;
+		    break;
+		  default:
+		    throw SemanticError( "invalid type specifier \"imaginary\" in type ", this );
+		}
+		break;
+        
+	      default:
+		throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type ", this );
+	    }
+	}
+	if ( *i == DeclarationNode::Double ) {
+	    sawDouble = true;
+	}
+    }
+
+    for ( std::list< DeclarationNode::Modifier >::const_iterator i = basic->modifiers.begin(); i != basic->modifiers.end(); ++i ) {
+	switch ( *i ) {
+	  case DeclarationNode::Long:
+	    if ( !init ) {
+		init = true;
+		ret = BasicType::LongSignedInt;
+	    } else {
+		switch ( ret ) {
+		  case BasicType::SignedInt:
+		    ret = BasicType::LongSignedInt;
+		    break;
+		  case BasicType::UnsignedInt:
+		    ret = BasicType::LongUnsignedInt;
+		    break;
+		  case BasicType::LongSignedInt:
+		    ret = BasicType::LongLongSignedInt;
+		    break;
+		  case BasicType::LongUnsignedInt:
+		    ret = BasicType::LongLongUnsignedInt;
+		    break;
+		  case BasicType::Double:
+		    ret = BasicType::LongDouble;
+		    break;
+		  case BasicType::DoubleComplex:
+		    ret = BasicType::LongDoubleComplex;
+		    break;
+		  case BasicType::DoubleImaginary:
+		    ret = BasicType::LongDoubleImaginary;
+		    break;
+		  default:
+		    throw SemanticError( "invalid type modifier \"long\" in type ", this );
+		}
+	    }
+	    break;
+	  case DeclarationNode::Short:
+	    if ( !init ) {
+		init = true;
+		ret = BasicType::ShortSignedInt;
+	    } else {
+		switch ( ret ) {
+		  case BasicType::SignedInt:
+		    ret = BasicType::ShortSignedInt;
+		    break;
+		  case BasicType::UnsignedInt:
+		    ret = BasicType::ShortUnsignedInt;
+		    break;
+		  default:
+		    throw SemanticError( "invalid type modifier \"short\" in type ", this );
+		}
+	    }
+	    break;
+	  case DeclarationNode::Signed:
+	    if ( !init ) {
+		init = true;
+		ret = BasicType::SignedInt;
+	    } else if ( sawSigned ) {
+		throw SemanticError( "duplicate type modifer \"signed\" in type ", this );
+	    } else {
+		switch ( ret ) {
+		  case BasicType::SignedInt:
+		  case BasicType::ShortSignedInt:
+		    break;
+		  case BasicType::Char:
+		    ret = BasicType::SignedChar;
+		    break;
+		  default:
+		    throw SemanticError( "invalid type modifer \"signed\" in type ", this );
+		}
+	    }
+	    break;
+	  case DeclarationNode::Unsigned:
+	    if ( !init ) {
+		init = true;
+		ret = BasicType::UnsignedInt;
+	    } else if ( sawSigned ) {
+		throw SemanticError( "invalid type modifer \"unsigned\" in type ", this );
+	    } else {
+		switch ( ret ) {
+		  case BasicType::LongSignedInt:
+		    ret = BasicType::LongUnsignedInt;
+		    break;
+		  case BasicType::SignedInt:
+		    ret = BasicType::UnsignedInt;
+		    break;
+		  case BasicType::ShortSignedInt:
+		    ret = BasicType::ShortUnsignedInt;
+		    break;
+		  case BasicType::Char:
+		    ret = BasicType::UnsignedChar;
+		    break;
+		  default:
+		    throw SemanticError( "invalid type modifer \"unsigned\" in type ", this );
+		}
+	    }
+	    break;
+	}
+
+	if ( *i == DeclarationNode::Signed ) {
+	    sawSigned = true;
+	}
+    }
+
+    BasicType *bt;
+    if ( !init ) {
+	bt = new BasicType( buildQualifiers(), BasicType::SignedInt );
     } else {
-      os << "type definition ";
-    }
-    if( symbolic->params ) {
-      os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
-      symbolic->params->printList( os, indent + 2 );
-    }
-    if( symbolic->assertions ) {
-      os << endl << string( indent+2, ' ' ) << "with assertions" << endl;
-      symbolic->assertions->printList( os, indent + 4 );
-      os << string( indent+2, ' ' );
-    }
-    if( base ) {
-      os << "for ";
-      base->print( os, indent + 2 );
-    }
-    break;
-
-  case Variable:
-    os << DeclarationNode::typeClassName[ variable->tyClass ] << " variable ";
-    if( variable->assertions ) {
-      os << endl << string( indent+2, ' ' ) << "with assertions" << endl;
-      variable->assertions->printList( os, indent + 4 );
-      os << string( indent+2, ' ' );
-    }
-    break;
-
-  case Tuple:
-    os << "tuple ";
-    if( tuple->members ) {
-      os << "with members " << endl;
-      tuple->members->printList( os, indent + 2 );
-    }
-    break;
+	bt = new BasicType( buildQualifiers(), ret );
+    }
+    buildForall( forall, bt->get_forall() );
+    return bt;
+}
+
+
+PointerType *TypeData::buildPointer() const {
+    PointerType *pt;
+    if ( base ) {
+	pt = new PointerType( buildQualifiers(), base->build() );
+    } else {
+	pt = new PointerType( buildQualifiers(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
+    }
+    buildForall( forall, pt->get_forall() );
+    return pt;
+}
+
+ArrayType *TypeData::buildArray() const {
+  
+    ArrayType *at;
+    if ( base ) {
+	at = new ArrayType( buildQualifiers(), base->build(), maybeBuild< Expression >( array->dimension ),
+			    array->isVarLen, array->isStatic );
+    } else {
+	at = new ArrayType( buildQualifiers(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ),
+			    maybeBuild< Expression >( array->dimension ), array->isVarLen, array->isStatic );
+    }
+    buildForall( forall, at->get_forall() );
+    return at;
+}
+
+FunctionType *TypeData::buildFunction() const {
+    assert( kind == Function );
+    bool hasEllipsis = function->params ? function->params->get_hasEllipsis() : true;
+    if ( !function->params ) hasEllipsis = !function->newStyle;
+    FunctionType *ft = new FunctionType( buildQualifiers(), hasEllipsis );
+    buildList( function->params, ft->get_parameters() );
+    buildForall( forall, ft->get_forall() );
+    if ( base ) {
+	switch ( base->kind ) {
+	  case Tuple:
+	    buildList( base->tuple->members, ft->get_returnVals() );
+	    break;
+	  default:
+	    ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( base->buildDecl( "", Declaration::NoStorageClass, 0, false, LinkageSpec::Cforall ) ) );
+	}
+    } else {
+	ft->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 ) );
+    }
+    return ft;
+}
+
+AggregateDecl *TypeData::buildAggregate() const {
+    assert( kind == Aggregate );
+    AggregateDecl *at;
+    switch ( aggregate->kind ) {
+      case DeclarationNode::Struct:
+	at = new StructDecl( aggregate->name );
+	break;
     
-  case Typeof:
-    os << "type-of expression ";
-    if( typeexpr->expr ) {
-      typeexpr->expr->print( os, indent + 2 );
-    }
-    break;
+      case DeclarationNode::Union:
+	at = new UnionDecl( aggregate->name );
+	break;
     
-  case Attr:
-    os << "attribute type decl " << attr->name << " applied to ";
-    if( attr->expr ) {
-      attr->expr->print( os, indent + 2 );
-    }
-    if( attr->type ) {
-      attr->type->print( os, indent + 2 );
-    }
-    break;
-  }
-}
-
-TypeData *
-TypeData::extractAggregate( bool toplevel ) const
-{
-  TypeData *ret = 0;
-
-  switch( kind ) {
-  case Aggregate:
-    if( !toplevel && aggregate->members ) {
-      ret = clone();
-      ret->qualifiers.clear();
-    }
-    break;
-
-  case Enum:
-    if( !toplevel && enumeration->constants ) {
-      ret = clone();
-      ret->qualifiers.clear();
-    }
-    break;
-
-  case AggregateInst:
-    if( aggInst->aggregate ) {
-      ret = aggInst->aggregate->extractAggregate( false );
-    }
-    break;
-
-  default:
-    if( base ) {
-      ret = base->extractAggregate( false );
-    }
-  }
-  return ret;
-}
-
-void
-buildForall( const DeclarationNode *firstNode, std::list< TypeDecl* > &outputList )
-{
+      case DeclarationNode::Context:
+	at = new ContextDecl( aggregate->name );
+	break;
+    
+      default:
+	assert( false );
+    }
   
-  buildList( firstNode, outputList );
-  for( std::list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) {
-    if( (*i)->get_kind() == TypeDecl::Any ) {
-      FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
-      assignType->get_parameters().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
-      assignType->get_parameters().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
-      assignType->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
-      (*i)->get_assertions().push_front( new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::Cforall,  assignType, 0, false ) );
-    }
-  }
-}
-
-Declaration *
-TypeData::buildDecl( std::string name, Declaration::StorageClass sc, Expression *bitfieldWidth, bool isInline, LinkageSpec::Type linkage, Initializer *init ) const
-{
-
-  if ( kind == TypeData::Function ) {
-    FunctionDecl *decl;
-    if( function->hasBody ) {
-      if( function->body ) {
-        Statement *stmt = function->body->build();
-        CompoundStmt *body = dynamic_cast< CompoundStmt* >( stmt );
-        assert( body );
-        decl = new FunctionDecl( name, sc, linkage, buildFunction(), body, isInline );
-      } else {
-	// std::list<Label> ls;
-        decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list<Label>() ), isInline );
-      }
-    } else {
-      decl = new FunctionDecl( name, sc, linkage, buildFunction(), 0, isInline );
-    }
-    for( DeclarationNode *cur = function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_link() ) ) {
-      if( cur->get_name() != "" ) {
-        decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() );
-      }
-    }
-    buildList( function->oldDeclList, decl->get_oldDecls() );
-    return decl;
-  } else if ( kind == TypeData::Aggregate ) {
-    return buildAggregate();
-  } else if ( kind == TypeData::Enum ) {
-    return buildEnum();
-  } else if ( kind == TypeData::Symbolic ) {
-    return buildSymbolic( name, sc );
-  } else if ( kind == TypeData::Variable ) {
-    return buildVariable();
-  } else {
-    if( isInline ) {
-      throw SemanticError( "invalid inline specification in declaration of ", this );
-    } else {
-      return new ObjectDecl( name, sc, linkage, bitfieldWidth, build(), init );
-    }
-  }
-  return 0;
-}
-
-Type *
-TypeData::build() const
-{
-
-  switch( kind ) {
-  case Unknown:
-    // fill in implicit int
-    return new BasicType( buildQualifiers(), BasicType::SignedInt );
-
-  case Basic:
-    return buildBasicType();
-
-  case Pointer:
-    return buildPointer();
-
-  case Array:
-    return buildArray();
-
-  case Function:
-    return buildFunction();
-
-  case AggregateInst:
-    return buildAggInst();
-
-  case EnumConstant:
-    // the name gets filled in later -- by SymTab::Validate
-    return new EnumInstType( buildQualifiers(), "" );
-
-  case SymbolicInst:
-    return buildSymbolicInst();;
-
-  case Tuple:
-    return buildTuple();
-  
-  case Typeof:
-    return buildTypeof();
-
-  case Attr:
-    return buildAttr();
-
-  case Symbolic:
-  case Enum:
-  case Aggregate:
-  case Variable:
-    assert( false );
-  }
-
-  return 0;
-}
-
-Type::Qualifiers
-TypeData::buildQualifiers() const
-{
-  Type::Qualifiers q;
-  for( std::list< DeclarationNode::Qualifier >::const_iterator i = qualifiers.begin(); i != qualifiers.end(); ++i ) {
-    switch( *i ) {
-    case DeclarationNode::Const:
-      q.isConst = true;
-      break;
-
-    case DeclarationNode::Volatile:
-      q.isVolatile = true;
-      break;
-
-    case DeclarationNode::Restrict:
-      q.isRestrict = true;
-      break;
-
-    case DeclarationNode::Lvalue:
-      q.isLvalue = true;
-      break;
-    }
-  }
-  return q;
-}
-
-Type*
-TypeData::buildBasicType() const
-{
-
-  static const BasicType::Kind kindMap[] = { BasicType::Char, BasicType::SignedInt, BasicType::Float, BasicType::Double,
-                                             BasicType::Char /* void */, BasicType::Bool, BasicType::DoubleComplex,
-					     BasicType::DoubleImaginary };
-
-  bool init = false;
-  bool sawDouble = false;
-  bool sawSigned = false;
-  BasicType::Kind ret;
-
-  for( std::list< DeclarationNode::BasicType >::const_iterator i = basic->typeSpec.begin(); i != basic->typeSpec.end(); ++i ) {
-    if( !init ) {
-      init = true;
-      if( *i == DeclarationNode::Void ) {
-        if( basic->typeSpec.size() != 1 || !basic->modifiers.empty() ) {
-	  throw SemanticError( "invalid type specifier \"void\" in type ", this );
-	} else {
-	  return new VoidType( buildQualifiers() );
-	}
-      } else {
-        ret = kindMap[ *i ];
-      }
-    } else {
-      switch( *i ) {
-      case DeclarationNode::Float:
-	if( sawDouble ) {
-	  throw SemanticError( "invalid type specifier \"float\" in type ", this );
-	} else {
-	  switch( ret ) {
-	  case BasicType::DoubleComplex:
-	    ret = BasicType::FloatComplex;
-	    break;
-
-	  case BasicType::DoubleImaginary:
-	    ret = BasicType::FloatImaginary;
-	    break;
-
-	  default:
-	    throw SemanticError( "invalid type specifier \"float\" in type ", this );
-	  }
-	}
-	break;
-
-      case DeclarationNode::Double:
-	if( sawDouble ) {
-	  throw SemanticError( "duplicate type specifier \"double\" in type ", this );
-	} else {
-	  switch( ret ) {
-	  case BasicType::DoubleComplex:
-	  case BasicType::DoubleImaginary:
-	    break;
-
-	  default:
-	    throw SemanticError( "invalid type specifier \"double\" in type ", this );
-	  }
-	}
-	break;
-	
-      case DeclarationNode::Complex:
-        switch( ret ) {
-        case BasicType::Float:
-          ret = BasicType::FloatComplex;
-          break;
-          
-        case BasicType::Double:
-          ret = BasicType::DoubleComplex;
-          break;
-
-	default:
-	  throw SemanticError( "invalid type specifier \"complex\" in type ", this );
-        }
-	break;
-        
-      case DeclarationNode::Imaginary:
-        switch( ret ) {
-        case BasicType::Float:
-          ret = BasicType::FloatImaginary;
-          break;
-          
-        case BasicType::Double:
-          ret = BasicType::DoubleImaginary;
-          break;
-
-	default:
-	  throw SemanticError( "invalid type specifier \"imaginary\" in type ", this );
-        }
-	break;
-        
-      default:
-	throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type ", this );
-      }
-    }
-    if( *i == DeclarationNode::Double ) {
-      sawDouble = true;
-    }
-  }
-
-  for( std::list< DeclarationNode::Modifier >::const_iterator i = basic->modifiers.begin(); i != basic->modifiers.end(); ++i ) {
-    switch( *i ) {
-    case DeclarationNode::Long:
-      if( !init ) {
-	init = true;
-	ret = BasicType::LongSignedInt;
-      } else {
-	switch( ret ) {
-	case BasicType::SignedInt:
-	  ret = BasicType::LongSignedInt;
-	  break;
-
-	case BasicType::UnsignedInt:
-	  ret = BasicType::LongUnsignedInt;
-	  break;
-
-	case BasicType::LongSignedInt:
-	  ret = BasicType::LongLongSignedInt;
-	  break;
-
-	case BasicType::LongUnsignedInt:
-	  ret = BasicType::LongLongUnsignedInt;
-	  break;
-
-	case BasicType::Double:
-	  ret = BasicType::LongDouble;
-	  break;
-
-	case BasicType::DoubleComplex:
-	  ret = BasicType::LongDoubleComplex;
-	  break;
-
-	case BasicType::DoubleImaginary:
-	  ret = BasicType::LongDoubleImaginary;
-	  break;
-
-	default:
-	  throw SemanticError( "invalid type modifier \"long\" in type ", this );
-	}
-      }
-      break;
-
-    case DeclarationNode::Short:
-      if( !init ) {
-	init = true;
-	ret = BasicType::ShortSignedInt;
-      } else {
-	switch( ret ) {
-	case BasicType::SignedInt:
-	  ret = BasicType::ShortSignedInt;
-	  break;
-
-	case BasicType::UnsignedInt:
-	  ret = BasicType::ShortUnsignedInt;
-	  break;
-
-	default:
-	  throw SemanticError( "invalid type modifier \"short\" in type ", this );
-	}
-      }
-      break;
-
-    case DeclarationNode::Signed:
-      if( !init ) {
-	init = true;
-	ret = BasicType::SignedInt;
-      } else if( sawSigned ) {
-	throw SemanticError( "duplicate type modifer \"signed\" in type ", this );
-      } else {
-	switch( ret ) {
-	case BasicType::SignedInt:
-	case BasicType::ShortSignedInt:
-	  break;
-
-	case BasicType::Char:
-	  ret = BasicType::SignedChar;
-	  break;
-
-	default:
-	  throw SemanticError( "invalid type modifer \"signed\" in type ", this );
-	}
-      }
-      break;
-
-    case DeclarationNode::Unsigned:
-      if( !init ) {
-	init = true;
-	ret = BasicType::UnsignedInt;
-      } else if( sawSigned ) {
-	throw SemanticError( "invalid type modifer \"unsigned\" in type ", this );
-      } else {
-	switch( ret ) {
-	case BasicType::LongSignedInt:
-	  ret = BasicType::LongUnsignedInt;
-	  break;
-
-	case BasicType::SignedInt:
-	  ret = BasicType::UnsignedInt;
-	  break;
-
-	case BasicType::ShortSignedInt:
-	  ret = BasicType::ShortUnsignedInt;
-	  break;
-
-	case BasicType::Char:
-	  ret = BasicType::UnsignedChar;
-	  break;
-
-	default:
-	  throw SemanticError( "invalid type modifer \"unsigned\" in type ", this );
-	}
-      }
-      break;
-    }
-
-    if( *i == DeclarationNode::Signed ) {
-      sawSigned = true;
-    }
-  }
-
-  BasicType *bt;
-  if( !init ) {
-    bt = new BasicType( buildQualifiers(), BasicType::SignedInt );
-  } else {
-    bt = new BasicType( buildQualifiers(), ret );
-  }
-  buildForall( forall, bt->get_forall() );
-  return bt;
-}
-
-
-PointerType * 
-TypeData::buildPointer() const
-{
-  
-  PointerType *pt;
-  if( base ) {
-    pt = new PointerType( buildQualifiers(), base->build() );
-  } else {
-    pt = new PointerType( buildQualifiers(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
-  }
-  buildForall( forall, pt->get_forall() );
-  return pt;
-}
-
-ArrayType * 
-TypeData::buildArray() const
-{
-  
-  ArrayType *at;
-  if( base ) {
-    at = new ArrayType( buildQualifiers(), base->build(), maybeBuild< Expression >( array->dimension ),
-	                  array->isVarLen, array->isStatic );
-  } else {
-    at = new ArrayType( buildQualifiers(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ),
-	                  maybeBuild< Expression >( array->dimension ), array->isVarLen, array->isStatic );
-  }
-  buildForall( forall, at->get_forall() );
-  return at;
-}
-
-FunctionType *
-TypeData::buildFunction() const
-{
-  assert( kind == Function );
-
-
-  bool hasEllipsis = function->params ? function->params->get_hasEllipsis() : true;
-  if( !function->params ) hasEllipsis = !function->newStyle;
-  FunctionType *ft = new FunctionType( buildQualifiers(), hasEllipsis );
-  buildList( function->params, ft->get_parameters() );
-  buildForall( forall, ft->get_forall() );
-  if( base ) {
-    switch( base->kind ) {
-    case Tuple:
-      buildList( base->tuple->members, ft->get_returnVals() );
-      break;
-
-    default:
-      ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( base->buildDecl( "", Declaration::NoStorageClass, 0, false, LinkageSpec::Cforall ) ) );
-    }
-  } else {
-    ft->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 ) );
-  }
-  return ft;
-}
-
-AggregateDecl *
-TypeData::buildAggregate() const
-{
-  assert( kind == Aggregate );
-
-
-  AggregateDecl *at;
-  switch( aggregate->kind ) {
-  case DeclarationNode::Struct:
-    at = new StructDecl( aggregate->name );
-    break;
-    
-  case DeclarationNode::Union:
-    at = new UnionDecl( aggregate->name );
-    break;
-    
-  case DeclarationNode::Context:
-    at = new ContextDecl( aggregate->name );
-    break;
-    
-  default:
-    assert( false );
-  }
-  
-  buildList( aggregate->params, at->get_parameters() );
-  buildList( aggregate->members, at->get_members() );
-
-  return at;
+    buildList( aggregate->params, at->get_parameters() );
+    buildList( aggregate->members, at->get_members() );
+
+    return at;
 }
 
@@ -930,5 +825,5 @@
 /// makeType( Declaration* decl )
 /// {
-///   if( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) {
+///   if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) {
 ///     return dwt->get_type()->clone();
 ///   } else {
@@ -938,137 +833,105 @@
 /// }
 
-ReferenceToType *
-TypeData::buildAggInst() const
-{
-  assert( kind == AggregateInst );
-
-
-  std::string name;
-
-  ReferenceToType *ret;
-  if( aggInst->aggregate->kind == Enum ) {
-    ret = new EnumInstType( buildQualifiers(), aggInst->aggregate->enumeration->name );
-  } else {
-    assert( aggInst->aggregate->kind == Aggregate );
-    switch( aggInst->aggregate->aggregate->kind ) {
-    case DeclarationNode::Struct:
-      ret = new StructInstType( buildQualifiers(), aggInst->aggregate->aggregate->name );
-      break;
-
-    case DeclarationNode::Union:
-      ret = new UnionInstType( buildQualifiers(), aggInst->aggregate->aggregate->name );
-      break;
-
-    case DeclarationNode::Context:
-      ret = new ContextInstType( buildQualifiers(), aggInst->aggregate->aggregate->name );
-      break;
-
-    default:
-      assert( false );
-    }
-  }
-  buildList( aggInst->params, ret->get_parameters() );
-  buildForall( forall, ret->get_forall() );
-  return ret;
-}
-
-NamedTypeDecl*
-TypeData::buildSymbolic( const std::string &name, Declaration::StorageClass sc ) const
-{
-  assert( kind == Symbolic );
-
-
-  NamedTypeDecl *ret;
-  if( symbolic->isTypedef ) {
-    ret = new TypedefDecl( name, sc, maybeBuild< Type >( base ) );
-  } else {
-    ret = new TypeDecl( name, sc, maybeBuild< Type >( base ), TypeDecl::Any );
-  }
-  buildList( symbolic->params, ret->get_parameters() );
-  buildList( symbolic->assertions, ret->get_assertions() );
-  return ret;
-}
-
-TypeDecl*
-TypeData::buildVariable() const
-{
-  assert( kind == Variable );
-
-
-  static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
-
-  TypeDecl *ret = new TypeDecl( variable->name, Declaration::NoStorageClass, 0, kindMap[ variable->tyClass ] );
-  buildList( variable->assertions, ret->get_assertions() );
+ReferenceToType *TypeData::buildAggInst() const {
+    assert( kind == AggregateInst );
+    std::string name;
+
+    ReferenceToType *ret;
+    if ( aggInst->aggregate->kind == Enum ) {
+	ret = new EnumInstType( buildQualifiers(), aggInst->aggregate->enumeration->name );
+    } else {
+	assert( aggInst->aggregate->kind == Aggregate );
+	switch ( aggInst->aggregate->aggregate->kind ) {
+	  case DeclarationNode::Struct:
+	    ret = new StructInstType( buildQualifiers(), aggInst->aggregate->aggregate->name );
+	    break;
+	  case DeclarationNode::Union:
+	    ret = new UnionInstType( buildQualifiers(), aggInst->aggregate->aggregate->name );
+	    break;
+	  case DeclarationNode::Context:
+	    ret = new ContextInstType( buildQualifiers(), aggInst->aggregate->aggregate->name );
+	    break;
+	  default:
+	    assert( false );
+	}
+    }
+    buildList( aggInst->params, ret->get_parameters() );
+    buildForall( forall, ret->get_forall() );
+    return ret;
+}
+
+NamedTypeDecl *TypeData::buildSymbolic( const std::string &name, Declaration::StorageClass sc ) const {
+    assert( kind == Symbolic );
+    NamedTypeDecl *ret;
+    if ( symbolic->isTypedef ) {
+	ret = new TypedefDecl( name, sc, maybeBuild< Type >( base ) );
+    } else {
+	ret = new TypeDecl( name, sc, maybeBuild< Type >( base ), TypeDecl::Any );
+    }
+    buildList( symbolic->params, ret->get_parameters() );
+    buildList( symbolic->assertions, ret->get_assertions() );
+    return ret;
+}
+
+TypeDecl *TypeData::buildVariable() const {
+    assert( kind == Variable );
+    static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
+
+    TypeDecl *ret = new TypeDecl( variable->name, Declaration::NoStorageClass, 0, kindMap[ variable->tyClass ] );
+    buildList( variable->assertions, ret->get_assertions() );
     
-  return ret;
-}
-
-EnumDecl* 
-TypeData::buildEnum() const
-{
-  assert( kind == Enum );
-
-
-  EnumDecl *ret = new EnumDecl( enumeration->name );
-  buildList( enumeration->constants, ret->get_members() );
-
-  return ret;
-}
-
-TypeInstType * 
-TypeData::buildSymbolicInst() const
-{
-  assert( kind == SymbolicInst );
-
-
-  TypeInstType *ret = new TypeInstType( buildQualifiers(), symbolic->name, false );
-  buildList( symbolic->actuals, ret->get_parameters() );
-  buildForall( forall, ret->get_forall() );
-
-  return ret;
-}
-
-TupleType * 
-TypeData::buildTuple() const
-{
-  assert( kind == Tuple );
-
-
-  TupleType *ret = new TupleType( buildQualifiers() );
-  buildTypeList( tuple->members, ret->get_types() );
-  buildForall( forall, ret->get_forall() );
-
-  return ret;
-}
-
-TypeofType * 
-TypeData::buildTypeof() const
-{
-  assert( kind == Typeof );
-
-
-  assert( typeexpr );
-  assert( typeexpr->expr );
-  TypeofType *ret = new TypeofType( buildQualifiers(), typeexpr->expr->build() );
-
-  return ret;
-}
-
-AttrType * 
-TypeData::buildAttr() const
-{
-  assert( kind == Attr );
-
-
-  assert( attr );
-  AttrType *ret;
-  if( attr->expr ) {
-    ret = new AttrType( buildQualifiers(), attr->name, attr->expr->build() );
-  } else {
-    assert( attr->type );
-    ret = new AttrType( buildQualifiers(), attr->name, attr->type->buildType() );
-  }
-
-  return ret;
-}
-
+    return ret;
+}
+
+EnumDecl *TypeData::buildEnum() const {
+    assert( kind == Enum );
+    EnumDecl *ret = new EnumDecl( enumeration->name );
+    buildList( enumeration->constants, ret->get_members() );
+
+    return ret;
+}
+
+TypeInstType *TypeData::buildSymbolicInst() const {
+    assert( kind == SymbolicInst );
+
+
+    TypeInstType *ret = new TypeInstType( buildQualifiers(), symbolic->name, false );
+    buildList( symbolic->actuals, ret->get_parameters() );
+    buildForall( forall, ret->get_forall() );
+
+    return ret;
+}
+
+TupleType *TypeData::buildTuple() const {
+    assert( kind == Tuple );
+
+
+    TupleType *ret = new TupleType( buildQualifiers() );
+    buildTypeList( tuple->members, ret->get_types() );
+    buildForall( forall, ret->get_forall() );
+
+    return ret;
+}
+
+TypeofType *TypeData::buildTypeof() const {
+    assert( kind == Typeof );
+    assert( typeexpr );
+    assert( typeexpr->expr );
+    TypeofType *ret = new TypeofType( buildQualifiers(), typeexpr->expr->build() );
+
+    return ret;
+}
+
+AttrType *TypeData::buildAttr() const {
+    assert( kind == Attr );
+    assert( attr );
+    AttrType *ret;
+    if ( attr->expr ) {
+	ret = new AttrType( buildQualifiers(), attr->name, attr->expr->build() );
+    } else {
+	assert( attr->type );
+	ret = new AttrType( buildQualifiers(), attr->name, attr->type->buildType() );
+    }
+
+    return ret;
+}
Index: translator/Parser/TypeData.h
===================================================================
--- translator/Parser/TypeData.h	(revision 8c17ab009047298326a3dc92f5ddacbdc08bdc94)
+++ translator/Parser/TypeData.h	(revision c8ffe20b6084e6e8082ff367961b87d47cfe83ff)
@@ -10,119 +10,118 @@
 #include "LinkageSpec.h"
 
-struct TypeData
-{
-  enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
-	      Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Attr } kind;
+struct TypeData {
+    enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
+		Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Attr } kind;
 
-  TypeData( Kind k = Unknown );
-  ~TypeData();
-  void print( std::ostream &, int indent = 0 ) const;
-  TypeData *clone() const;
+    TypeData( Kind k = Unknown );
+    ~TypeData();
+    void print( std::ostream &, int indent = 0 ) const;
+    TypeData *clone() const;
 
-  Type *build() const;
-  FunctionType *buildFunction() const;
+    Type *build() const;
+    FunctionType *buildFunction() const;
 
-  TypeData *base;
-  std::list< DeclarationNode::Qualifier > qualifiers;
-  DeclarationNode *forall;
+    TypeData *base;
+    std::list< DeclarationNode::Qualifier > qualifiers;
+    DeclarationNode *forall;
 
-  struct Basic_t {
-    std::list< DeclarationNode::BasicType > typeSpec;
-    std::list< DeclarationNode::Modifier > modifiers;
-  };
+    struct Basic_t {
+	std::list< DeclarationNode::BasicType > typeSpec;
+	std::list< DeclarationNode::Modifier > modifiers;
+    };
 
-  struct Aggregate_t {
-    DeclarationNode::TyCon kind;
-    std::string name;
-    DeclarationNode *params;
-    ExpressionNode *actuals;	// holds actual parameters that will later be applied to AggInst
-    DeclarationNode *members;
-  };
+    struct Aggregate_t {
+	DeclarationNode::TyCon kind;
+	std::string name;
+	DeclarationNode *params;
+	ExpressionNode *actuals;			// holds actual parameters later applied to AggInst
+	DeclarationNode *members;
+    };
 
-  struct AggInst_t {
-    TypeData *aggregate;
-    ExpressionNode *params;
-  };
+    struct AggInst_t {
+	TypeData *aggregate;
+	ExpressionNode *params;
+    };
 
-  struct Array_t {
-    ExpressionNode *dimension;
-    bool isVarLen;
-    bool isStatic;
-  };
+    struct Array_t {
+	ExpressionNode *dimension;
+	bool isVarLen;
+	bool isStatic;
+    };
 
-  struct Enumeration_t {
-    std::string name;
-    DeclarationNode *constants;
-  };
+    struct Enumeration_t {
+	std::string name;
+	DeclarationNode *constants;
+    };
 
-  struct Function_t {
-    DeclarationNode *params;
-    DeclarationNode *idList; // old-style
-    DeclarationNode *oldDeclList;
-    StatementNode *body;
-    bool hasBody;
-    bool newStyle;
-  };
+    struct Function_t {
+	DeclarationNode *params;
+	DeclarationNode *idList;			// old-style
+	DeclarationNode *oldDeclList;
+	StatementNode *body;
+	bool hasBody;
+	bool newStyle;
+    };
 
-  struct Symbolic_t {
-    std::string name;
-    bool isTypedef;
-    DeclarationNode *params;
-    ExpressionNode *actuals;
-    DeclarationNode *assertions;
-  };
+    struct Symbolic_t {
+	std::string name;
+	bool isTypedef;
+	DeclarationNode *params;
+	ExpressionNode *actuals;
+	DeclarationNode *assertions;
+    };
 
-  struct Variable_t {
-    DeclarationNode::TypeClass tyClass;
-    std::string name;
-    DeclarationNode *assertions;
-  };
+    struct Variable_t {
+	DeclarationNode::TypeClass tyClass;
+	std::string name;
+	DeclarationNode *assertions;
+    };
 
-  struct Tuple_t {
-    DeclarationNode *members;
-  };
+    struct Tuple_t {
+	DeclarationNode *members;
+    };
   
-  struct Typeof_t {
-    ExpressionNode *expr;
-  };
+    struct Typeof_t {
+	ExpressionNode *expr;
+    };
 
-  struct Attr_t {
-    std::string name;
-    ExpressionNode *expr;
-    DeclarationNode *type;
-  };
+    struct Attr_t {
+	std::string name;
+	ExpressionNode *expr;
+	DeclarationNode *type;
+    };
 
-  union {
-    Basic_t *basic;
-    Aggregate_t *aggregate;
-    AggInst_t *aggInst;
-    Array_t *array;
-    Enumeration_t *enumeration;
-    Function_t *function;
-    Symbolic_t *symbolic;
-    Variable_t *variable;
-    Tuple_t *tuple;
-    Typeof_t *typeexpr;
-    Attr_t *attr;
-  };
+    union {
+	Basic_t *basic;
+	Aggregate_t *aggregate;
+	AggInst_t *aggInst;
+	Array_t *array;
+	Enumeration_t *enumeration;
+	Function_t *function;
+	Symbolic_t *symbolic;
+	Variable_t *variable;
+	Tuple_t *tuple;
+	Typeof_t *typeexpr;
+	Attr_t *attr;
+    };
 
-  TypeData *extractAggregate( bool toplevel = true ) const;
-  /* helper function for DeclNodeImpl::build */
-  Declaration * buildDecl( std::string name, Declaration::StorageClass sc, Expression *bitfieldWidth, bool isInline, LinkageSpec::Type linkage, Initializer *init = 0 ) const;
-  /* helper functions for build() */
-  Type::Qualifiers buildQualifiers() const;
-  Type *buildBasicType() const;
-  PointerType * buildPointer() const;
-  ArrayType * buildArray() const;
-  AggregateDecl * buildAggregate() const;
-  ReferenceToType * buildAggInst() const;
-  NamedTypeDecl * buildSymbolic( const std::string &name, Declaration::StorageClass sc ) const;
-  TypeDecl* buildVariable() const;
-  EnumDecl* buildEnum() const;
-  TypeInstType * buildSymbolicInst() const;
-  TupleType * buildTuple() const;
-  TypeofType * buildTypeof() const;
-  AttrType * buildAttr() const;
+    TypeData *extractAggregate( bool toplevel = true ) const;
+    // helper function for DeclNodeImpl::build
+    Declaration * buildDecl( std::string name, Declaration::StorageClass sc, Expression *bitfieldWidth, bool isInline, LinkageSpec::Type linkage, Initializer *init = 0 ) const;
+    // helper functions for build()
+    Type::Qualifiers buildQualifiers() const;
+    Type *buildBasicType() const;
+    PointerType * buildPointer() const;
+    ArrayType * buildArray() const;
+    AggregateDecl * buildAggregate() const;
+    ReferenceToType * buildAggInst() const;
+    NamedTypeDecl * buildSymbolic( const std::string &name, Declaration::StorageClass sc ) const;
+    TypeDecl* buildVariable() const;
+    EnumDecl* buildEnum() const;
+    TypeInstType * buildSymbolicInst() const;
+    TupleType * buildTuple() const;
+    TypeofType * buildTypeof() const;
+    AttrType * buildAttr() const;
 };
 
-#endif /* #ifndef TYPEDATA_H */
+#endif // TYPEDATA_H
Index: translator/Parser/TypedefTable.h
===================================================================
--- translator/Parser/TypedefTable.h	(revision 8c17ab009047298326a3dc92f5ddacbdc08bdc94)
+++ translator/Parser/TypedefTable.h	(revision c8ffe20b6084e6e8082ff367961b87d47cfe83ff)
@@ -1,9 +1,2 @@
-/*
- * This file is part of the Cforall project
- *
- * $Id: TypedefTable.h,v 1.5 2003/05/11 15:24:05 rcbilson Exp $
- *
- */
-
 #ifndef TYPEDEFTABLE_H
 #define TYPEDEFTABLE_H
@@ -14,19 +7,16 @@
 #include <stack>
 
-class TypedefTable
-{
+class TypedefTable {
   public:
     enum kind_t { ID, TD, TG };
   private:
-    struct Entry
-    {
+    struct Entry {
 	int scope;
 	kind_t kind;
     };
     
-    struct DeferredEntry
-    {
-      std::string identifier;
-      kind_t kind;
+    struct DeferredEntry {
+	std::string identifier;
+	kind_t kind;
     };
 
@@ -44,31 +34,29 @@
     std::stack< std::string > nextIdentifiers;
 
-    bool isKind(std::string identifier, kind_t kind) const;
-    void addToScope(const std::string &identifier, kind_t kind, int scope);
+    bool isKind( std::string identifier, kind_t kind ) const;
+    void addToScope( const std::string &identifier, kind_t kind, int scope );
   public:
     TypedefTable();
 
-    bool isIdentifier(std::string identifier) const;
-    bool isTypedef(std::string identifier) const;
-    bool isTypegen(std::string identifier) const;
+    bool isIdentifier( std::string identifier ) const;
+    bool isTypedef( std::string identifier ) const;
+    bool isTypegen( std::string identifier ) const;
     
-    // "addToCurrentScope" adds the identifier/type pair to the current scope This does less
-    // than you think it does, since each declaration is within its own scope.  Mostly useful for
-    // type parameters.
-    void addToCurrentScope(const std::string &identifier, kind_t kind);
-    void addToCurrentScope(kind_t kind);   // use nextIdentifiers.top()
+    // "addToCurrentScope" adds the identifier/type pair to the current scope This does less than you think it does,
+    // since each declaration is within its own scope.  Mostly useful for type parameters.
+    void addToCurrentScope( const std::string &identifier, kind_t kind );
+    void addToCurrentScope( kind_t kind );		// use nextIdentifiers.top()
 
-    // "addToEnclosingScope" adds the identifier/type pair to the scope that encloses the current
-    // one.  This is the right way to handle type and typedef names
-    void addToEnclosingScope(const std::string &identifier, kind_t kind);
-    void addToEnclosingScope(kind_t kind); // use nextIdentifiers.top()
+    // "addToEnclosingScope" adds the identifier/type pair to the scope that encloses the current one.  This is the
+    // right way to handle type and typedef names
+    void addToEnclosingScope( const std::string &identifier, kind_t kind );
+    void addToEnclosingScope( kind_t kind );		// use nextIdentifiers.top()
     
-    // "addToEnclosingScope2" adds the identifier/type pair to the scope that encloses the scope
-    // enclosing the the current one.  This is the right way to handle assertion names
-    void addToEnclosingScope2(const std::string &identifier, kind_t kind);
-    void addToEnclosingScope2(kind_t kind); // use nextIdentifiers.top()
+    // "addToEnclosingScope2" adds the identifier/type pair to the scope that encloses the scope enclosing the the
+    // current one.  This is the right way to handle assertion names
+    void addToEnclosingScope2( const std::string &identifier, kind_t kind );
+    void addToEnclosingScope2( kind_t kind );		// use nextIdentifiers.top()
     
-    // set the next identifier to be used by an "add" operation without an identifier parameter
-    // within the current scope
+    // set the next identifier to be used by an "add" operation without an identifier parameter within the current scope
     void setNextIdentifier( const std::string &identifier );
     
@@ -76,11 +64,11 @@
     void openContext( std::string contextName );
     
-    void enterScope(void);
-    void leaveScope(void);
+    void enterScope( void );
+    void leaveScope( void );
     void enterContext( std::string contextName );
-    void leaveContext(void);
+    void leaveContext( void );
 
-    void print(void) const;
+    void print( void ) const;
 };
 
-#endif /* ifndef TYPEDEFTABLE_H */
+#endif // TYPEDEFTABLE_H
Index: translator/SymTab/Validate.cc
===================================================================
--- translator/SymTab/Validate.cc	(revision 8c17ab009047298326a3dc92f5ddacbdc08bdc94)
+++ translator/SymTab/Validate.cc	(revision c8ffe20b6084e6e8082ff367961b87d47cfe83ff)
@@ -1,33 +1,26 @@
 /*
- * This file is part of the Cforall project
- *
- * $Id: Validate.cc,v 1.22 2005/08/29 20:14:18 rcbilson Exp $
- *
- */
-
-/*
-   The "validate" phase of translation is used to take a syntax tree and convert it into a
-   standard form that aims to be as regular in structure as possible.  Some assumptions can be
-   made regarding the state of the tree after this pass is complete, including:
-
-   - No nested structure or union definitions; any in the input are "hoisted" to the level of
-     the containing struct or union.
-
-   - All enumeration constants have type EnumInstType.
-
-   - The type "void" never occurs in lists of function parameter or return types; neither do
-     tuple types.  A function taking no arguments has no argument types, and tuples are flattened.
-
-   - No context instances exist; they are all replaced by the set of declarations signified by
-     the context, instantiated by the particular set of type arguments.
-
-   - Every declaration is assigned a unique id.
-
-   - No typedef declarations or instances exist; the actual type is substituted for each instance.
-
-   - Each type, struct, and union definition is followed by an appropriate assignment operator.
-
-   - Each use of a struct or union is connected to a complete definition of that struct or union,
-     even if that definition occurs later in the input.
+  The "validate" phase of translation is used to take a syntax tree and convert it into a
+  standard form that aims to be as regular in structure as possible.  Some assumptions can be
+  made regarding the state of the tree after this pass is complete, including:
+
+  - No nested structure or union definitions; any in the input are "hoisted" to the level of
+  the containing struct or union.
+
+  - All enumeration constants have type EnumInstType.
+
+  - The type "void" never occurs in lists of function parameter or return types; neither do
+  tuple types.  A function taking no arguments has no argument types, and tuples are flattened.
+
+  - No context instances exist; they are all replaced by the set of declarations signified by
+  the context, instantiated by the particular set of type arguments.
+
+  - Every declaration is assigned a unique id.
+
+  - No typedef declarations or instances exist; the actual type is substituted for each instance.
+
+  - Each type, struct, and union definition is followed by an appropriate assignment operator.
+
+  - Each use of a struct or union is connected to a complete definition of that struct or union,
+  even if that definition occurs later in the input.
 */
 
@@ -48,863 +41,725 @@
 
 
-#define debugPrint(x) if( doDebug ) { std::cout << x; }
+#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
 
 namespace SymTab {
-
-class HoistStruct : public Visitor
-{
-public:
-  static void hoistStruct( std::list< Declaration* > &translationUnit );
-  
-  std::list< Declaration* > &get_declsToAdd() { return declsToAdd; }
-  
-  virtual void visit(StructDecl *aggregateDecl);
-  virtual void visit(UnionDecl *aggregateDecl);
-
-  virtual void visit(CompoundStmt *compoundStmt);
-  virtual void visit(IfStmt *ifStmt);
-  virtual void visit(WhileStmt *whileStmt);
-  virtual void visit(ForStmt *forStmt);
-  virtual void visit(SwitchStmt *switchStmt);
-  virtual void visit(ChooseStmt *chooseStmt);
-  virtual void visit(CaseStmt *caseStmt);
-  virtual void visit(CatchStmt *catchStmt);
-  
-private:
-  HoistStruct();
-
-  template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
-
-  std::list< Declaration* > declsToAdd;
-  bool inStruct;
-};
-
-class Pass1 : public Visitor
-{
-  typedef Visitor Parent;
-  virtual void visit( EnumDecl *aggregateDecl);
-  virtual void visit( FunctionType *func );
-};
-  
-class Pass2 : public Indexer
-{
-  typedef Indexer Parent;
-
-public:
-  Pass2( bool doDebug, const Indexer *indexer );
-
-private:
-  virtual void visit( StructInstType *structInst );
-  virtual void visit( UnionInstType *unionInst );
-  virtual void visit( ContextInstType *contextInst );
-  virtual void visit( StructDecl *structDecl );
-  virtual void visit( UnionDecl *unionDecl );
-  virtual void visit( TypeInstType *typeInst );
-
-  const Indexer *indexer;
-  
-  typedef std::map< std::string, std::list< StructInstType* > > ForwardStructsType;
-  typedef std::map< std::string, std::list< UnionInstType* > > ForwardUnionsType;
-  ForwardStructsType forwardStructs;
-  ForwardUnionsType forwardUnions;
-};
-
-class Pass3 : public Indexer
-{
-  typedef Indexer Parent;
-
-public:
-  Pass3( const Indexer *indexer );
-
-private:
-  virtual void visit( ObjectDecl *object );
-  virtual void visit( FunctionDecl *func );
-
-  const Indexer *indexer;
-};
-
-class AddStructAssignment : public Visitor
-{
-public:
-  static void addStructAssignment( std::list< Declaration* > &translationUnit );
-
-  std::list< Declaration* > &get_declsToAdd() { return declsToAdd; }
-  
-  virtual void visit( StructDecl *structDecl );
-  virtual void visit( UnionDecl *structDecl );
-  virtual void visit( TypeDecl *typeDecl );
-  virtual void visit( ContextDecl *ctxDecl );
-
-  virtual void visit( FunctionType *ftype );
-  virtual void visit( PointerType *ftype );
-  
-  virtual void visit(CompoundStmt *compoundStmt);
-  virtual void visit(IfStmt *ifStmt);
-  virtual void visit(WhileStmt *whileStmt);
-  virtual void visit(ForStmt *forStmt);
-  virtual void visit(SwitchStmt *switchStmt);
-  virtual void visit(ChooseStmt *chooseStmt);
-  virtual void visit(CaseStmt *caseStmt);
-  virtual void visit(CatchStmt *catchStmt);
-  
-private:
-  template< typename StmtClass > void visitStatement(StmtClass *stmt);
-  
-  std::list< Declaration* > declsToAdd;
-  std::set< std::string > structsDone;
-};
-
-class EliminateTypedef : public Mutator
-{
-public:
-  static void eliminateTypedef( std::list< Declaration* > &translationUnit );
-  
-private:
-  virtual Declaration* mutate(TypedefDecl *typeDecl);
-  virtual TypeDecl* mutate(TypeDecl *typeDecl);
-  virtual DeclarationWithType* mutate(FunctionDecl *funcDecl);
-  virtual ObjectDecl* mutate(ObjectDecl *objDecl);
-  virtual CompoundStmt* mutate(CompoundStmt *compoundStmt);
-  virtual Type* mutate(TypeInstType *aggregateUseType);
-  virtual Expression* mutate(CastExpr *castExpr);
-  
-  std::map< std::string, TypedefDecl* > typedefNames;
-};
-
-void 
-validate( std::list< Declaration* > &translationUnit, bool doDebug, const Indexer *indexer )
-{
-  Pass1 pass1;
-  Pass2 pass2( doDebug, indexer );
-  Pass3 pass3( indexer );
-  EliminateTypedef::eliminateTypedef( translationUnit );
-  HoistStruct::hoistStruct( translationUnit );
-  acceptAll( translationUnit, pass1 );
-  acceptAll( translationUnit, pass2 );
-  AddStructAssignment::addStructAssignment( translationUnit );
-  acceptAll( translationUnit, pass3 );
-}
-
-void
-validateType( Type *type, const Indexer *indexer )
-{
-  Pass1 pass1;
-  Pass2 pass2( false, indexer );
-  Pass3 pass3( indexer );
-  type->accept( pass1 );
-  type->accept( pass2 );
-  type->accept( pass3 );
-}
-
-template< typename Visitor >
-void
-acceptAndAdd( std::list< Declaration* > &translationUnit, Visitor &visitor, bool addBefore )
-{
-  std::list< Declaration* >::iterator i = translationUnit.begin();
-  while( i != translationUnit.end() ) {
-    (*i)->accept( visitor );
-    std::list< Declaration* >::iterator next = i;
-    next++;
-    if( !visitor.get_declsToAdd().empty() ) {
-      translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() );
-    }
-    i = next;
-  }
-}
-
-/* static class method */
-void 
-HoistStruct::hoistStruct( std::list< Declaration* > &translationUnit )
-{
-  HoistStruct hoister;
-  acceptAndAdd( translationUnit, hoister, true );
-}
-
-HoistStruct::HoistStruct()
-  : inStruct( false )
-{
-}
-
-void
-filter( std::list< Declaration* > &declList, bool (*pred)( Declaration* ), bool doDelete )
-{
-  std::list< Declaration* >::iterator i = declList.begin();
-  while( i != declList.end() ) {
-    std::list< Declaration* >::iterator next = i;
-    ++next;
-    if( pred( *i ) ) {
-      if( doDelete ) {
-        delete *i;
-      }
-      declList.erase( i );
-    }
-    i = next;
-  }
-}
-
-bool
-isStructOrUnion( Declaration *decl )
-{
-  return dynamic_cast< StructDecl* >( decl ) || dynamic_cast< UnionDecl* >( decl );
-}
-
-template< typename AggDecl >
-void
-HoistStruct::handleAggregate( AggDecl *aggregateDecl )
-{
-  if( inStruct ) {
-    declsToAdd.push_back( aggregateDecl );
-    Visitor::visit( aggregateDecl );
-  } else {
-    inStruct = true;
-    Visitor::visit( aggregateDecl );
-    inStruct = false;
-    filter( aggregateDecl->get_members(), isStructOrUnion, false );
-  }
-}
-
-void 
-HoistStruct::visit(StructDecl *aggregateDecl)
-{
-  handleAggregate( aggregateDecl );
-}
-
-void 
-HoistStruct::visit(UnionDecl *aggregateDecl)
-{
-  handleAggregate( aggregateDecl );
-}
-
-void
-HoistStruct::visit(CompoundStmt *compoundStmt)
-{
-  addVisit( compoundStmt, *this );
-}
-
-void
-HoistStruct::visit(IfStmt *ifStmt)
-{
-  addVisit( ifStmt, *this );
-}
-
-void
-HoistStruct::visit(WhileStmt *whileStmt)
-{
-  addVisit( whileStmt, *this );
-}
-
-void
-HoistStruct::visit(ForStmt *forStmt)
-{
-  addVisit( forStmt, *this );
-}
-
-void
-HoistStruct::visit(SwitchStmt *switchStmt)
-{
-  addVisit( switchStmt, *this );
-}
-
-void
-HoistStruct::visit(ChooseStmt *switchStmt)
-{
-  addVisit( switchStmt, *this );
-}
-
-void
-HoistStruct::visit(CaseStmt *caseStmt)
-{
-  addVisit( caseStmt, *this );
-}
-
-void
-HoistStruct::visit(CatchStmt *cathStmt)
-{
-  addVisit( cathStmt, *this );
-}
-
-void 
-Pass1::visit( EnumDecl *enumDecl)
-{
-  // Set the type of each member of the enumeration to be EnumConstant
-  
-  for( std::list< Declaration* >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
-    ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
-    assert( obj );
-    obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false ), enumDecl->get_name() ) );
-  }
-  Parent::visit( enumDecl );
-}
-
-namespace {
-template< typename DWTIterator >
-void
-fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func )
-{
-  // the only case in which "void" is valid is where it is the only one in the list; then
-  // it should be removed entirely
-  // other fix ups are handled by the FixFunction class
-  if( begin == end ) return;
-  FixFunction fixer;
-  DWTIterator i = begin;
-  *i = (*i)->acceptMutator( fixer );
-  if( fixer.get_isVoid() ) {
-    DWTIterator j = i;
-    ++i;
-    func->get_parameters().erase( j );
-    if( i != end ) { 
-      throw SemanticError( "invalid type void in function type ", func );
-    }
-  } else {
-    ++i;
-    for( ; i != end; ++i ) {
-      FixFunction fixer;
-      *i = (*i)->acceptMutator( fixer );
-      if( fixer.get_isVoid() ) {
-        throw SemanticError( "invalid type void in function type ", func );
-      }
-    }
-  }
-}
-}
-
-void 
-Pass1::visit( FunctionType *func )
-{
-  // Fix up parameters and return types
-  fixFunctionList( func->get_parameters().begin(), func->get_parameters().end(), func );
-  fixFunctionList( func->get_returnVals().begin(), func->get_returnVals().end(), func );
-  Visitor::visit( func );
-}
-
-Pass2::Pass2( bool doDebug, const Indexer *other_indexer )
-  : Indexer( doDebug )
-{
-  if( other_indexer ) {
-    indexer = other_indexer;
-  } else {
-    indexer = this;
-  }
-}
-
-void 
-Pass2::visit( StructInstType *structInst )
-{
-  Parent::visit( structInst );
-  StructDecl *st = indexer->lookupStruct( structInst->get_name() );
-  // it's not a semantic error if the struct is not found, just an implicit forward declaration
-  if( st ) {
-    assert( !structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || !st->get_members().empty() );
-    structInst->set_baseStruct( st );
-  }
-  if( !st || st->get_members().empty() ) {
-    // use of forward declaration
-    forwardStructs[ structInst->get_name() ].push_back( structInst );
-  }
-}
-
-void 
-Pass2::visit( UnionInstType *unionInst )
-{
-  Parent::visit( unionInst );
-  UnionDecl *un = indexer->lookupUnion( unionInst->get_name() );
-  // it's not a semantic error if the union is not found, just an implicit forward declaration
-  if( un ) {
-    unionInst->set_baseUnion( un );
-  }
-  if( !un || un->get_members().empty() ) {
-    // use of forward declaration
-    forwardUnions[ unionInst->get_name() ].push_back( unionInst );
-  }
-}
-
-void 
-Pass2::visit( ContextInstType *contextInst )
-{
-  Parent::visit( contextInst );
-  ContextDecl *ctx = indexer->lookupContext( contextInst->get_name() );
-  if( !ctx ) {
-    throw SemanticError( "use of undeclared context " + contextInst->get_name() );
-  }
-  for( std::list< TypeDecl* >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) {
-    for( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
-      if( ContextInstType *otherCtx = dynamic_cast< ContextInstType* >(*assert) ) {
-        cloneAll( otherCtx->get_members(), contextInst->get_members() );
-      } else {
-        contextInst->get_members().push_back( (*assert)->clone() );
-      }
-    }
-  }
-  applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) );
-}
-
-void 
-Pass2::visit( StructDecl *structDecl )
-{
-  if( !structDecl->get_members().empty() ) {
-    ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() );
-    if( fwds != forwardStructs.end() ) {
-      for( std::list< StructInstType* >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
-        (*inst)->set_baseStruct( structDecl );
-      }
-      forwardStructs.erase( fwds );
-    }
-  }
-  Indexer::visit( structDecl );
-}
-
-void 
-Pass2::visit( UnionDecl *unionDecl )
-{
-  if( !unionDecl->get_members().empty() ) {
-    ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() );
-    if( fwds != forwardUnions.end() ) {
-      for( std::list< UnionInstType* >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
-        (*inst)->set_baseUnion( unionDecl );
-      }
-      forwardUnions.erase( fwds );
-    }
-  }
-  Indexer::visit( unionDecl );
-}
-
-void 
-Pass2::visit( TypeInstType *typeInst )
-{
-  if( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) {
-    if( TypeDecl *typeDecl = dynamic_cast< TypeDecl* >( namedTypeDecl ) ) {
-      typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );
-    }
-  }
-}
-
-Pass3::Pass3( const Indexer *other_indexer )
-  : Indexer( false )
-{
-  if( other_indexer ) {
-    indexer = other_indexer;
-  } else {
-    indexer = this;
-  }
-}
-
-void 
-forallFixer( Type *func )
-{
-  // Fix up assertions
-  for( std::list< TypeDecl* >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {
-    std::list< DeclarationWithType* > toBeDone, nextRound;
-    toBeDone.splice( toBeDone.end(), (*type)->get_assertions() );
-    while( !toBeDone.empty() ) {
-      for( std::list< DeclarationWithType* >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) {
-        if( ContextInstType *ctx = dynamic_cast< ContextInstType* >( (*assertion)->get_type() ) ) {
-          for( std::list< Declaration* >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) {
-            DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i );
-            assert( dwt );
-            nextRound.push_back( dwt->clone() );
-          }
-          delete ctx;
-        } else {
-          FixFunction fixer;
-          *assertion = (*assertion)->acceptMutator( fixer );
-          if( fixer.get_isVoid() ) {
-            throw SemanticError( "invalid type void in assertion of function ", func );
-          }
-          (*type)->get_assertions().push_back( *assertion );
-        }
-      }
-      toBeDone.clear();
-      toBeDone.splice( toBeDone.end(), nextRound );
-    }
-  }
-}
-
-void 
-Pass3::visit( ObjectDecl *object )
-{
-  forallFixer( object->get_type() );
-  if( PointerType *pointer = dynamic_cast< PointerType* >( object->get_type() ) ) {
-    forallFixer( pointer->get_base() );
-  }
-  Parent::visit( object );
-  object->fixUniqueId();
-}
-
-void 
-Pass3::visit( FunctionDecl *func )
-{
-  forallFixer( func->get_type() );
-  Parent::visit( func );
-  func->fixUniqueId();
-}
-
-static const std::list< std::string > noLabels;
-
-/* static class method */
-void
-AddStructAssignment::addStructAssignment( std::list< Declaration* > &translationUnit )
-{
-  AddStructAssignment visitor;
-  acceptAndAdd( translationUnit, visitor, false );
-}
-
-template< typename OutputIterator >
-void
-makeScalarAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, OutputIterator out )
-{
-  ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member ); // PAB: unnamed bit fields are not copied
-  if ( obj != NULL && obj->get_name() == "" && obj->get_bitfieldWidth() != NULL ) return;
-
-  UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) );
-  
-  UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
-  derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
-  
-  // do something special for unnamed members
-  Expression *dstselect = new AddressExpr( new MemberExpr( member, derefExpr ) );
-  assignExpr->get_args().push_back( dstselect );
-  
-  Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );
-  assignExpr->get_args().push_back( srcselect );
-  
-  *out++ = new ExprStmt( noLabels, assignExpr );
-}
-
-template< typename OutputIterator >
-void
-makeArrayAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, ArrayType *array, OutputIterator out )
-{
-  static UniqueName indexName( "_index" );
-  
-  // for a flexible array member nothing is done -- user must define own assignment
-  if( !array->get_dimension() ) return;
-  
-  ObjectDecl *index = new ObjectDecl( indexName.newName(), Declaration::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 );
-  *out++ = new DeclStmt( noLabels, index );
-  
-  UntypedExpr *init = new UntypedExpr( new NameExpr( "?=?" ) );
-  init->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
-  init->get_args().push_back( new NameExpr( "0" ) );
-  Statement *initStmt = new ExprStmt( noLabels, init );
-  
-  UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) );
-  cond->get_args().push_back( new VariableExpr( index ) );
-  cond->get_args().push_back( array->get_dimension()->clone() );
-  
-  UntypedExpr *inc = new UntypedExpr( new NameExpr( "++?" ) );
-  inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
-  
-  UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) );
-  
-  UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
-  derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
-  
-  Expression *dstselect = new MemberExpr( member, derefExpr );
-  UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?+?" ) );
-  dstIndex->get_args().push_back( dstselect );
-  dstIndex->get_args().push_back( new VariableExpr( index ) );
-  assignExpr->get_args().push_back( dstIndex );
-  
-  Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );
-  UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
-  srcIndex->get_args().push_back( srcselect );
-  srcIndex->get_args().push_back( new VariableExpr( index ) );
-  assignExpr->get_args().push_back( srcIndex );
-  
-  *out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );
-}
-
-Declaration*
-makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType )
-{
-  FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
-  
-  ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
-  assignType->get_returnVals().push_back( returnVal );
-  
-  ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
-  assignType->get_parameters().push_back( dstParam );
-  
-  ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
-  assignType->get_parameters().push_back( srcParam );
-  
-  FunctionDecl *assignDecl = new FunctionDecl( "?=?", Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
-  assignDecl->fixUniqueId();
-  
-  for( std::list< Declaration* >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) {
-    if( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *member ) ) {
-      if( ArrayType *array = dynamic_cast< ArrayType* >( dwt->get_type() ) ) {
-        makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
-      } else {
-        makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
-      }
-    }
-  }
-  assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
-  
-  return assignDecl;
-}
-
-Declaration*
-makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType )
-{
-  FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
-  
-  ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
-  assignType->get_returnVals().push_back( returnVal );
-  
-  ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
-  assignType->get_parameters().push_back( dstParam );
-  
-  ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
-  assignType->get_parameters().push_back( srcParam );
-  
-  FunctionDecl *assignDecl = new FunctionDecl( "?=?", Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
-  assignDecl->fixUniqueId();
-  
-  UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) );
-  copy->get_args().push_back( new VariableExpr( dstParam ) );
-  copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
-  copy->get_args().push_back( new SizeofExpr( refType->clone() ) );
-
-  assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) );
-  assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
-  
-  return assignDecl;
-}
-
-void
-AddStructAssignment::visit( StructDecl *structDecl )
-{
-  if( !structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
-    StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
-    structInst->set_baseStruct( structDecl );
-    declsToAdd.push_back( makeStructAssignment( structDecl, structInst ) );
-    structsDone.insert( structDecl->get_name() );
-  }
-}
-
-void
-AddStructAssignment::visit( UnionDecl *unionDecl )
-{
-  if( !unionDecl->get_members().empty() ) {
-    UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
-    unionInst->set_baseUnion( unionDecl );
-    declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst ) );
-  }
-}
-
-void
-AddStructAssignment::visit( TypeDecl *typeDecl )
-{
-  CompoundStmt *stmts = 0;
-  TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false );
-  typeInst->set_baseType( typeDecl );
-  ObjectDecl *src = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst->clone(), 0 );
-  ObjectDecl *dst = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), typeInst->clone() ), 0 );
-  if( typeDecl->get_base() ) {
-    stmts = new CompoundStmt( std::list< Label >() );
-    UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
-    assign->get_args().push_back( new CastExpr( new VariableExpr( dst ), new PointerType( Type::Qualifiers(), typeDecl->get_base()->clone() ) ) );
-    assign->get_args().push_back( new CastExpr( new VariableExpr( src ), typeDecl->get_base()->clone() ) );
-    stmts->get_kids().push_back( new ReturnStmt( std::list< Label >(), assign ) );
-  }
-  FunctionType *type = new FunctionType( Type::Qualifiers(), false );
-  type->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst, 0 ) );
-  type->get_parameters().push_back( dst );
-  type->get_parameters().push_back( src );
-  FunctionDecl *func = new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false );
-  declsToAdd.push_back( func );
-}
-
-void
-addDecls( std::list< Declaration* > &declsToAdd, std::list< Statement* > &statements, std::list< Statement* >::iterator i )
-{
-  if( !declsToAdd.empty() ) {
-    for( std::list< Declaration* >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) {
-      statements.insert( i, new DeclStmt( noLabels, *decl ) );
-    }
-    declsToAdd.clear();
-  }
-}
-
-void
-AddStructAssignment::visit(FunctionType *)
-{
-  // ensure that we don't add assignment ops for types defined
-  // as part of the function
-}
-
-void
-AddStructAssignment::visit(PointerType *)
-{
-  // ensure that we don't add assignment ops for types defined
-  // as part of the pointer
-}
-
-void
-AddStructAssignment::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)
-{
-  std::set< std::string > oldStructs = structsDone;
-  addVisit( stmt, *this );
-  structsDone = oldStructs;
-}
-
-void
-AddStructAssignment::visit(CompoundStmt *compoundStmt)
-{
-  visitStatement( compoundStmt );
-}
-
-void
-AddStructAssignment::visit(IfStmt *ifStmt)
-{
-  visitStatement( ifStmt );
-}
-
-void
-AddStructAssignment::visit(WhileStmt *whileStmt)
-{
-  visitStatement( whileStmt );
-}
-
-void
-AddStructAssignment::visit(ForStmt *forStmt)
-{
-  visitStatement( forStmt );
-}
-
-void
-AddStructAssignment::visit(SwitchStmt *switchStmt)
-{
-  visitStatement( switchStmt );
-}
-
-void
-AddStructAssignment::visit(ChooseStmt *switchStmt)
-{
-  visitStatement( switchStmt );
-}
-
-void
-AddStructAssignment::visit(CaseStmt *caseStmt)
-{
-  visitStatement( caseStmt );
-}
-
-void
-AddStructAssignment::visit(CatchStmt *cathStmt)
-{
-  visitStatement( cathStmt );
-}
-
-bool
-isTypedef( Declaration *decl )
-{
-  return dynamic_cast< TypedefDecl* >( decl );
-}
-
-
-/* static class method */
-void 
-EliminateTypedef::eliminateTypedef( std::list< Declaration* > &translationUnit )
-{
-  EliminateTypedef eliminator;
-  mutateAll( translationUnit, eliminator );
-  filter( translationUnit, isTypedef, true );
-}
-
-Type*
-EliminateTypedef::mutate( TypeInstType *typeInst )
-{
-  std::map< std::string, TypedefDecl* >::const_iterator def = typedefNames.find( typeInst->get_name() );
-  if( def != typedefNames.end() ) {
-    Type *ret = def->second->get_base()->clone();
-    ret->get_qualifiers() += typeInst->get_qualifiers();
-    delete typeInst;
-    return ret;
-  }
-  return typeInst;
-}
-
-Declaration*
-EliminateTypedef::mutate( TypedefDecl *tyDecl )
-{
-  Declaration *ret = Mutator::mutate( tyDecl );
-  typedefNames[ tyDecl->get_name() ] = tyDecl;
-  if( AggregateDecl *aggDecl = dynamic_cast< AggregateDecl* >( tyDecl->get_base() ) ) {
-    tyDecl->set_base( 0 );
-    delete tyDecl;
-    return aggDecl;
-  } else {
-    return ret;
-  }
-}
-
-TypeDecl*
-EliminateTypedef::mutate(TypeDecl *typeDecl)
-{
-  std::map< std::string, TypedefDecl* >::iterator i = typedefNames.find( typeDecl->get_name() );
-  if( i != typedefNames.end() ) {
-    typedefNames.erase( i ) ;
-  }
-  return typeDecl;
-}
-
-DeclarationWithType*
-EliminateTypedef::mutate(FunctionDecl *funcDecl)
-{
-  std::map< std::string, TypedefDecl* > oldNames = typedefNames;
-  DeclarationWithType *ret = Mutator::mutate( funcDecl );
-  typedefNames = oldNames;
-  return ret;
-}
-
-ObjectDecl*
-EliminateTypedef::mutate(ObjectDecl *objDecl)
-{
-  std::map< std::string, TypedefDecl* > oldNames = typedefNames;
-  ObjectDecl *ret = Mutator::mutate( objDecl );
-  typedefNames = oldNames;
-  return ret;
-}
-
-Expression*
-EliminateTypedef::mutate(CastExpr *castExpr)
-{
-  std::map< std::string, TypedefDecl* > oldNames = typedefNames;
-  Expression *ret = Mutator::mutate( castExpr );
-  typedefNames = oldNames;
-  return ret;
-}
-
-CompoundStmt * 
-EliminateTypedef::mutate( CompoundStmt *compoundStmt )
-{
-  std::map< std::string, TypedefDecl* > oldNames = typedefNames;
-  CompoundStmt *ret = Mutator::mutate( compoundStmt );
-  std::list< Statement* >::iterator i = compoundStmt->get_kids().begin();
-  while( i != compoundStmt->get_kids().end() ) {
-    std::list< Statement* >::iterator next = i;
-    ++next;
-    if( DeclStmt *declStmt = dynamic_cast< DeclStmt* >( *i ) ) {
-      if( dynamic_cast< TypedefDecl* >( declStmt->get_decl() ) ) {
-        delete *i;
-        compoundStmt->get_kids().erase( i );
-      }
-    }
-    i = next;
-  }
-  typedefNames = oldNames;
-  return ret;
-}
-
+    class HoistStruct : public Visitor {
+      public:
+	static void hoistStruct( std::list< Declaration * > &translationUnit );
+  
+	std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
+  
+	virtual void visit( StructDecl *aggregateDecl );
+	virtual void visit( UnionDecl *aggregateDecl );
+
+	virtual void visit( CompoundStmt *compoundStmt );
+	virtual void visit( IfStmt *ifStmt );
+	virtual void visit( WhileStmt *whileStmt );
+	virtual void visit( ForStmt *forStmt );
+	virtual void visit( SwitchStmt *switchStmt );
+	virtual void visit( ChooseStmt *chooseStmt );
+	virtual void visit( CaseStmt *caseStmt );
+	virtual void visit( CatchStmt *catchStmt );
+      private:
+	HoistStruct();
+
+	template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
+
+	std::list< Declaration * > declsToAdd;
+	bool inStruct;
+    };
+
+    class Pass1 : public Visitor {
+	typedef Visitor Parent;
+	virtual void visit( EnumDecl *aggregateDecl );
+	virtual void visit( FunctionType *func );
+    };
+  
+    class Pass2 : public Indexer {
+	typedef Indexer Parent;
+      public:
+	Pass2( bool doDebug, const Indexer *indexer );
+      private:
+	virtual void visit( StructInstType *structInst );
+	virtual void visit( UnionInstType *unionInst );
+	virtual void visit( ContextInstType *contextInst );
+	virtual void visit( StructDecl *structDecl );
+	virtual void visit( UnionDecl *unionDecl );
+	virtual void visit( TypeInstType *typeInst );
+
+	const Indexer *indexer;
+  
+	typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;
+	typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;
+	ForwardStructsType forwardStructs;
+	ForwardUnionsType forwardUnions;
+    };
+
+    class Pass3 : public Indexer {
+	typedef Indexer Parent;
+      public:
+	Pass3( const Indexer *indexer );
+      private:
+	virtual void visit( ObjectDecl *object );
+	virtual void visit( FunctionDecl *func );
+
+	const Indexer *indexer;
+    };
+
+    class AddStructAssignment : public Visitor {
+      public:
+	static void addStructAssignment( std::list< Declaration * > &translationUnit );
+
+	std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
+  
+	virtual void visit( StructDecl *structDecl );
+	virtual void visit( UnionDecl *structDecl );
+	virtual void visit( TypeDecl *typeDecl );
+	virtual void visit( ContextDecl *ctxDecl );
+
+	virtual void visit( FunctionType *ftype );
+	virtual void visit( PointerType *ftype );
+  
+	virtual void visit( CompoundStmt *compoundStmt );
+	virtual void visit( IfStmt *ifStmt );
+	virtual void visit( WhileStmt *whileStmt );
+	virtual void visit( ForStmt *forStmt );
+	virtual void visit( SwitchStmt *switchStmt );
+	virtual void visit( ChooseStmt *chooseStmt );
+	virtual void visit( CaseStmt *caseStmt );
+	virtual void visit( CatchStmt *catchStmt );
+      private:
+	template< typename StmtClass > void visitStatement( StmtClass *stmt );
+  
+	std::list< Declaration * > declsToAdd;
+	std::set< std::string > structsDone;
+    };
+
+    class EliminateTypedef : public Mutator {
+      public:
+	static void eliminateTypedef( std::list< Declaration * > &translationUnit );
+      private:
+	virtual Declaration *mutate( TypedefDecl *typeDecl );
+	virtual TypeDecl *mutate( TypeDecl *typeDecl );
+	virtual DeclarationWithType *mutate( FunctionDecl *funcDecl );
+	virtual ObjectDecl *mutate( ObjectDecl *objDecl );
+	virtual CompoundStmt *mutate( CompoundStmt *compoundStmt );
+	virtual Type *mutate( TypeInstType *aggregateUseType );
+	virtual Expression *mutate( CastExpr *castExpr );
+  
+	std::map< std::string, TypedefDecl * > typedefNames;
+    };
+
+    void validate( std::list< Declaration * > &translationUnit, bool doDebug, const Indexer *indexer ) {
+	Pass1 pass1;
+	Pass2 pass2( doDebug, indexer );
+	Pass3 pass3( indexer );
+	EliminateTypedef::eliminateTypedef( translationUnit );
+	HoistStruct::hoistStruct( translationUnit );
+	acceptAll( translationUnit, pass1 );
+	acceptAll( translationUnit, pass2 );
+	AddStructAssignment::addStructAssignment( translationUnit );
+	acceptAll( translationUnit, pass3 );
+    }
+
+    void validateType( Type *type, const Indexer *indexer ) {
+	Pass1 pass1;
+	Pass2 pass2( false, indexer );
+	Pass3 pass3( indexer );
+	type->accept( pass1 );
+	type->accept( pass2 );
+	type->accept( pass3 );
+    }
+
+    template< typename Visitor >
+    void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) {
+	std::list< Declaration * >::iterator i = translationUnit.begin();
+	while ( i != translationUnit.end() ) {
+	    (*i )->accept( visitor );
+	    std::list< Declaration * >::iterator next = i;
+	    next++;
+	    if ( ! visitor.get_declsToAdd().empty() ) {
+		translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() );
+	    }
+	    i = next;
+	}
+    }
+
+    void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) {
+	HoistStruct hoister;
+	acceptAndAdd( translationUnit, hoister, true );
+    }
+
+    HoistStruct::HoistStruct()
+	: inStruct( false ) {
+    }
+
+    void filter( std::list< Declaration * > &declList, bool (*pred )( Declaration * ), bool doDelete ) {
+	std::list< Declaration * >::iterator i = declList.begin();
+	while ( i != declList.end() ) {
+	    std::list< Declaration * >::iterator next = i;
+	    ++next;
+	    if ( pred( *i ) ) {
+		if ( doDelete ) {
+		    delete *i;
+		}
+		declList.erase( i );
+	    }
+	    i = next;
+	}
+    }
+
+    bool
+    isStructOrUnion( Declaration *decl ) {
+	return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl );
+    }
+
+    template< typename AggDecl >
+    void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
+	if ( inStruct ) {
+	    declsToAdd.push_back( aggregateDecl );
+	    Visitor::visit( aggregateDecl );
+	} else {
+	    inStruct = true;
+	    Visitor::visit( aggregateDecl );
+	    inStruct = false;
+	    filter( aggregateDecl->get_members(), isStructOrUnion, false );
+	}
+    }
+
+    void HoistStruct::visit( StructDecl *aggregateDecl ) {
+	handleAggregate( aggregateDecl );
+    }
+
+    void HoistStruct::visit( UnionDecl *aggregateDecl ) {
+	handleAggregate( aggregateDecl );
+    }
+
+    void HoistStruct::visit( CompoundStmt *compoundStmt ) {
+	addVisit( compoundStmt, *this );
+    }
+
+    void HoistStruct::visit( IfStmt *ifStmt ) {
+	addVisit( ifStmt, *this );
+    }
+
+    void HoistStruct::visit( WhileStmt *whileStmt ) {
+	addVisit( whileStmt, *this );
+    }
+
+    void HoistStruct::visit( ForStmt *forStmt ) {
+	addVisit( forStmt, *this );
+    }
+
+    void HoistStruct::visit( SwitchStmt *switchStmt ) {
+	addVisit( switchStmt, *this );
+    }
+
+    void HoistStruct::visit( ChooseStmt *switchStmt ) {
+	addVisit( switchStmt, *this );
+    }
+
+    void HoistStruct::visit( CaseStmt *caseStmt ) {
+	addVisit( caseStmt, *this );
+    }
+
+    void HoistStruct::visit( CatchStmt *cathStmt ) {
+	addVisit( cathStmt, *this );
+    }
+
+    void Pass1::visit( EnumDecl *enumDecl ) {
+	// Set the type of each member of the enumeration to be EnumConstant
+  
+	for( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
+	    ObjectDecl *obj = dynamic_cast< ObjectDecl * >( *i );
+	    assert( obj );
+	    obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false ), enumDecl->get_name() ) );
+	}
+	Parent::visit( enumDecl );
+    }
+
+    namespace {
+	template< typename DWTIterator >
+	void
+	fixFunctionList( DWTIterator begin, DWTIterator end, FunctionType *func ) {
+	    // the only case in which "void" is valid is where it is the only one in the list; then
+	    // it should be removed entirely
+	    // other fix ups are handled by the FixFunction class
+	    if ( begin == end ) return;
+	    FixFunction fixer;
+	    DWTIterator i = begin;
+	    *i = (*i )->acceptMutator( fixer );
+	    if ( fixer.get_isVoid() ) {
+		DWTIterator j = i;
+		++i;
+		func->get_parameters().erase( j );
+		if ( i != end ) { 
+		    throw SemanticError( "invalid type void in function type ", func );
+		}
+	    } else {
+		++i;
+		for( ; i != end; ++i ) {
+		    FixFunction fixer;
+		    *i = (*i )->acceptMutator( fixer );
+		    if ( fixer.get_isVoid() ) {
+			throw SemanticError( "invalid type void in function type ", func );
+		    }
+		}
+	    }
+	}
+    }
+
+    void Pass1::visit( FunctionType *func ) {
+	// Fix up parameters and return types
+	fixFunctionList( func->get_parameters().begin(), func->get_parameters().end(), func );
+	fixFunctionList( func->get_returnVals().begin(), func->get_returnVals().end(), func );
+	Visitor::visit( func );
+    }
+
+    Pass2::Pass2( bool doDebug, const Indexer *other_indexer )
+	: Indexer( doDebug ) {
+	if ( other_indexer ) {
+	    indexer = other_indexer;
+	} else {
+	    indexer = this;
+	}
+    }
+
+    void Pass2::visit( StructInstType *structInst ) {
+	Parent::visit( structInst );
+	StructDecl *st = indexer->lookupStruct( structInst->get_name() );
+	// it's not a semantic error if the struct is not found, just an implicit forward declaration
+	if ( st ) {
+	    assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );
+	    structInst->set_baseStruct( st );
+	}
+	if ( ! st || st->get_members().empty() ) {
+	    // use of forward declaration
+	    forwardStructs[ structInst->get_name() ].push_back( structInst );
+	}
+    }
+
+    void Pass2::visit( UnionInstType *unionInst ) {
+	Parent::visit( unionInst );
+	UnionDecl *un = indexer->lookupUnion( unionInst->get_name() );
+	// it's not a semantic error if the union is not found, just an implicit forward declaration
+	if ( un ) {
+	    unionInst->set_baseUnion( un );
+	}
+	if ( ! un || un->get_members().empty() ) {
+	    // use of forward declaration
+	    forwardUnions[ unionInst->get_name() ].push_back( unionInst );
+	}
+    }
+
+    void Pass2::visit( ContextInstType *contextInst ) {
+	Parent::visit( contextInst );
+	ContextDecl *ctx = indexer->lookupContext( contextInst->get_name() );
+	if ( ! ctx ) {
+	    throw SemanticError( "use of undeclared context " + contextInst->get_name() );
+	}
+	for( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) {
+	    for( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
+		if ( ContextInstType *otherCtx = dynamic_cast< ContextInstType * >(*assert ) ) {
+		    cloneAll( otherCtx->get_members(), contextInst->get_members() );
+		} else {
+		    contextInst->get_members().push_back( (*assert )->clone() );
+		}
+	    }
+	}
+	applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) );
+    }
+
+    void Pass2::visit( StructDecl *structDecl ) {
+	if ( ! structDecl->get_members().empty() ) {
+	    ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() );
+	    if ( fwds != forwardStructs.end() ) {
+		for( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
+		    (*inst )->set_baseStruct( structDecl );
+		}
+		forwardStructs.erase( fwds );
+	    }
+	}
+	Indexer::visit( structDecl );
+    }
+
+    void Pass2::visit( UnionDecl *unionDecl ) {
+	if ( ! unionDecl->get_members().empty() ) {
+	    ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() );
+	    if ( fwds != forwardUnions.end() ) {
+		for( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
+		    (*inst )->set_baseUnion( unionDecl );
+		}
+		forwardUnions.erase( fwds );
+	    }
+	}
+	Indexer::visit( unionDecl );
+    }
+
+    void Pass2::visit( TypeInstType *typeInst ) {
+	if ( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) {
+	    if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
+		typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );
+	    }
+	}
+    }
+
+    Pass3::Pass3( const Indexer *other_indexer )
+	: Indexer( false ) {
+	if ( other_indexer ) {
+	    indexer = other_indexer;
+	} else {
+	    indexer = this;
+	}
+    }
+
+    void forallFixer( Type *func ) {
+	// Fix up assertions
+	for( std::list< TypeDecl * >::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {
+	    std::list< DeclarationWithType * > toBeDone, nextRound;
+	    toBeDone.splice( toBeDone.end(), (*type )->get_assertions() );
+	    while ( ! toBeDone.empty() ) {
+		for( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) {
+		    if ( ContextInstType *ctx = dynamic_cast< ContextInstType * >( (*assertion )->get_type() ) ) {
+			for( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) {
+			    DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *i );
+			    assert( dwt );
+			    nextRound.push_back( dwt->clone() );
+			}
+			delete ctx;
+		    } else {
+			FixFunction fixer;
+			*assertion = (*assertion )->acceptMutator( fixer );
+			if ( fixer.get_isVoid() ) {
+			    throw SemanticError( "invalid type void in assertion of function ", func );
+			}
+			(*type )->get_assertions().push_back( *assertion );
+		    }
+		}
+		toBeDone.clear();
+		toBeDone.splice( toBeDone.end(), nextRound );
+	    }
+	}
+    }
+
+    void Pass3::visit( ObjectDecl *object ) {
+	forallFixer( object->get_type() );
+	if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
+	    forallFixer( pointer->get_base() );
+	}
+	Parent::visit( object );
+	object->fixUniqueId();
+    }
+
+    void Pass3::visit( FunctionDecl *func ) {
+	forallFixer( func->get_type() );
+	Parent::visit( func );
+	func->fixUniqueId();
+    }
+
+    static const std::list< std::string > noLabels;
+
+    void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {
+	AddStructAssignment visitor;
+	acceptAndAdd( translationUnit, visitor, false );
+    }
+
+    template< typename OutputIterator >
+    void makeScalarAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, OutputIterator out ) {
+	ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member ); // PAB: unnamed bit fields are not copied
+	if ( obj != NULL && obj->get_name() == "" && obj->get_bitfieldWidth() != NULL ) return;
+
+	UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) );
+  
+	UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
+	derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
+  
+	// do something special for unnamed members
+	Expression *dstselect = new AddressExpr( new MemberExpr( member, derefExpr ) );
+	assignExpr->get_args().push_back( dstselect );
+  
+	Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );
+	assignExpr->get_args().push_back( srcselect );
+  
+	*out++ = new ExprStmt( noLabels, assignExpr );
+    }
+
+    template< typename OutputIterator >
+    void makeArrayAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, DeclarationWithType *member, ArrayType *array, OutputIterator out ) {
+	static UniqueName indexName( "_index" );
+  
+	// for a flexible array member nothing is done -- user must define own assignment
+	if ( ! array->get_dimension() ) return;
+  
+	ObjectDecl *index = new ObjectDecl( indexName.newName(), Declaration::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 );
+	*out++ = new DeclStmt( noLabels, index );
+  
+	UntypedExpr *init = new UntypedExpr( new NameExpr( "?=?" ) );
+	init->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
+	init->get_args().push_back( new NameExpr( "0" ) );
+	Statement *initStmt = new ExprStmt( noLabels, init );
+  
+	UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) );
+	cond->get_args().push_back( new VariableExpr( index ) );
+	cond->get_args().push_back( array->get_dimension()->clone() );
+  
+	UntypedExpr *inc = new UntypedExpr( new NameExpr( "++?" ) );
+	inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
+  
+	UntypedExpr *assignExpr = new UntypedExpr( new NameExpr( "?=?" ) );
+  
+	UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
+	derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
+  
+	Expression *dstselect = new MemberExpr( member, derefExpr );
+	UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?+?" ) );
+	dstIndex->get_args().push_back( dstselect );
+	dstIndex->get_args().push_back( new VariableExpr( index ) );
+	assignExpr->get_args().push_back( dstIndex );
+  
+	Expression *srcselect = new MemberExpr( member, new VariableExpr( srcParam ) );
+	UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
+	srcIndex->get_args().push_back( srcselect );
+	srcIndex->get_args().push_back( new VariableExpr( index ) );
+	assignExpr->get_args().push_back( srcIndex );
+  
+	*out++ = new ForStmt( noLabels, initStmt, cond, inc, new ExprStmt( noLabels, assignExpr ) );
+    }
+
+    Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType ) {
+	FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
+  
+	ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
+	assignType->get_returnVals().push_back( returnVal );
+  
+	ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
+	assignType->get_parameters().push_back( dstParam );
+  
+	ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
+	assignType->get_parameters().push_back( srcParam );
+  
+	FunctionDecl *assignDecl = new FunctionDecl( "?=?", Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
+	assignDecl->fixUniqueId();
+  
+	for( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) {
+	    if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ) ) {
+		if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) {
+		    makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
+		} else {
+		    makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
+		}
+	    }
+	}
+	assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
+  
+	return assignDecl;
+    }
+
+    Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType ) {
+	FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
+  
+	ObjectDecl *returnVal = new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType->clone(), 0 );
+	assignType->get_returnVals().push_back( returnVal );
+  
+	ObjectDecl *dstParam = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), refType->clone() ), 0 );
+	assignType->get_parameters().push_back( dstParam );
+  
+	ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
+	assignType->get_parameters().push_back( srcParam );
+  
+	FunctionDecl *assignDecl = new FunctionDecl( "?=?", Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
+	assignDecl->fixUniqueId();
+  
+	UntypedExpr *copy = new UntypedExpr( new NameExpr( "__builtin_memcpy" ) );
+	copy->get_args().push_back( new VariableExpr( dstParam ) );
+	copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
+	copy->get_args().push_back( new SizeofExpr( refType->clone() ) );
+
+	assignDecl->get_statements()->get_kids().push_back( new ExprStmt( noLabels, copy ) );
+	assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
+  
+	return assignDecl;
+    }
+
+    void AddStructAssignment::visit( StructDecl *structDecl ) {
+	if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
+	    StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
+	    structInst->set_baseStruct( structDecl );
+	    declsToAdd.push_back( makeStructAssignment( structDecl, structInst ) );
+	    structsDone.insert( structDecl->get_name() );
+	}
+    }
+
+    void AddStructAssignment::visit( UnionDecl *unionDecl ) {
+	if ( ! unionDecl->get_members().empty() ) {
+	    UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
+	    unionInst->set_baseUnion( unionDecl );
+	    declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst ) );
+	}
+    }
+
+    void AddStructAssignment::visit( TypeDecl *typeDecl ) {
+	CompoundStmt *stmts = 0;
+	TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false );
+	typeInst->set_baseType( typeDecl );
+	ObjectDecl *src = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst->clone(), 0 );
+	ObjectDecl *dst = new ObjectDecl( "_dst", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), typeInst->clone() ), 0 );
+	if ( typeDecl->get_base() ) {
+	    stmts = new CompoundStmt( std::list< Label >() );
+	    UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
+	    assign->get_args().push_back( new CastExpr( new VariableExpr( dst ), new PointerType( Type::Qualifiers(), typeDecl->get_base()->clone() ) ) );
+	    assign->get_args().push_back( new CastExpr( new VariableExpr( src ), typeDecl->get_base()->clone() ) );
+	    stmts->get_kids().push_back( new ReturnStmt( std::list< Label >(), assign ) );
+	}
+	FunctionType *type = new FunctionType( Type::Qualifiers(), false );
+	type->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, typeInst, 0 ) );
+	type->get_parameters().push_back( dst );
+	type->get_parameters().push_back( src );
+	FunctionDecl *func = new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false );
+	declsToAdd.push_back( func );
+    }
+
+    void addDecls( std::list< Declaration * > &declsToAdd, std::list< Statement * > &statements, std::list< Statement * >::iterator i ) {
+	if ( ! declsToAdd.empty() ) {
+	    for( std::list< Declaration * >::iterator decl = declsToAdd.begin(); decl != declsToAdd.end(); ++decl ) {
+		statements.insert( i, new DeclStmt( noLabels, *decl ) );
+	    }
+	    declsToAdd.clear();
+	}
+    }
+
+    void AddStructAssignment::visit( FunctionType *) {
+	// ensure that we don't add assignment ops for types defined
+	// as part of the function
+    }
+
+    void AddStructAssignment::visit( PointerType *) {
+	// ensure that we don't add assignment ops for types defined
+	// as part of the pointer
+    }
+
+    void AddStructAssignment::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 ) {
+	std::set< std::string > oldStructs = structsDone;
+	addVisit( stmt, *this );
+	structsDone = oldStructs;
+    }
+
+    void AddStructAssignment::visit( CompoundStmt *compoundStmt ) {
+	visitStatement( compoundStmt );
+    }
+
+    void AddStructAssignment::visit( IfStmt *ifStmt ) {
+	visitStatement( ifStmt );
+    }
+
+    void AddStructAssignment::visit( WhileStmt *whileStmt ) {
+	visitStatement( whileStmt );
+    }
+
+    void AddStructAssignment::visit( ForStmt *forStmt ) {
+	visitStatement( forStmt );
+    }
+
+    void AddStructAssignment::visit( SwitchStmt *switchStmt ) {
+	visitStatement( switchStmt );
+    }
+
+    void AddStructAssignment::visit( ChooseStmt *switchStmt ) {
+	visitStatement( switchStmt );
+    }
+
+    void AddStructAssignment::visit( CaseStmt *caseStmt ) {
+	visitStatement( caseStmt );
+    }
+
+    void AddStructAssignment::visit( CatchStmt *cathStmt ) {
+	visitStatement( cathStmt );
+    }
+
+    bool isTypedef( Declaration *decl ) {
+	return dynamic_cast< TypedefDecl * >( decl );
+    }
+
+    void EliminateTypedef::eliminateTypedef( std::list< Declaration * > &translationUnit ) {
+	EliminateTypedef eliminator;
+	mutateAll( translationUnit, eliminator );
+	filter( translationUnit, isTypedef, true );
+    }
+
+    Type *EliminateTypedef::mutate( TypeInstType *typeInst ) {
+	std::map< std::string, TypedefDecl * >::const_iterator def = typedefNames.find( typeInst->get_name() );
+	if ( def != typedefNames.end() ) {
+	    Type *ret = def->second->get_base()->clone();
+	    ret->get_qualifiers() += typeInst->get_qualifiers();
+	    delete typeInst;
+	    return ret;
+	}
+	return typeInst;
+    }
+
+    Declaration *EliminateTypedef::mutate( TypedefDecl *tyDecl ) {
+	Declaration *ret = Mutator::mutate( tyDecl );
+	typedefNames[ tyDecl->get_name() ] = tyDecl;
+	if ( AggregateDecl *aggDecl = dynamic_cast< AggregateDecl * >( tyDecl->get_base() ) ) {
+	    tyDecl->set_base( 0 );
+	    delete tyDecl;
+	    return aggDecl;
+	} else {
+	    return ret;
+	}
+    }
+
+    TypeDecl *EliminateTypedef::mutate( TypeDecl *typeDecl ) {
+	std::map< std::string, TypedefDecl * >::iterator i = typedefNames.find( typeDecl->get_name() );
+	if ( i != typedefNames.end() ) {
+	    typedefNames.erase( i ) ;
+	}
+	return typeDecl;
+    }
+
+    DeclarationWithType *EliminateTypedef::mutate( FunctionDecl *funcDecl ) {
+	std::map< std::string, TypedefDecl * > oldNames = typedefNames;
+	DeclarationWithType *ret = Mutator::mutate( funcDecl );
+	typedefNames = oldNames;
+	return ret;
+    }
+
+    ObjectDecl *EliminateTypedef::mutate( ObjectDecl *objDecl ) {
+	std::map< std::string, TypedefDecl * > oldNames = typedefNames;
+	ObjectDecl *ret = Mutator::mutate( objDecl );
+	typedefNames = oldNames;
+	return ret;
+    }
+
+    Expression *EliminateTypedef::mutate( CastExpr *castExpr ) {
+	std::map< std::string, TypedefDecl * > oldNames = typedefNames;
+	Expression *ret = Mutator::mutate( castExpr );
+	typedefNames = oldNames;
+	return ret;
+    }
+
+    CompoundStmt *EliminateTypedef::mutate( CompoundStmt *compoundStmt ) {
+	std::map< std::string, TypedefDecl * > oldNames = typedefNames;
+	CompoundStmt *ret = Mutator::mutate( compoundStmt );
+	std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
+	while ( i != compoundStmt->get_kids().end() ) {
+	    std::list< Statement * >::iterator next = i;
+	    ++next;
+	    if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) {
+		if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {
+		    delete *i;
+		    compoundStmt->get_kids().erase( i );
+		}
+	    }
+	    i = next;
+	}
+	typedefNames = oldNames;
+	return ret;
+    }
 } // namespace SymTab
Index: translator/SynTree/FunctionType.cc
===================================================================
--- translator/SynTree/FunctionType.cc	(revision 8c17ab009047298326a3dc92f5ddacbdc08bdc94)
+++ translator/SynTree/FunctionType.cc	(revision c8ffe20b6084e6e8082ff367961b87d47cfe83ff)
@@ -1,9 +1,2 @@
-/*
- * This file is part of the Cforall project
- *
- * $Id: FunctionType.cc,v 1.8 2005/08/29 20:59:25 rcbilson Exp $
- *
- */
-
 #include <algorithm>
 
@@ -13,25 +6,18 @@
 
 
-FunctionType::FunctionType( const Type::Qualifiers &tq, bool isVarArgs )
-    : Type( tq ), isVarArgs( isVarArgs )
-{
+FunctionType::FunctionType( const Type::Qualifiers &tq, bool isVarArgs ) : Type( tq ), isVarArgs( isVarArgs ) {
 }
 
-FunctionType::FunctionType( const FunctionType &other )
-    : Type( other ), isVarArgs( other.isVarArgs )
-{
+FunctionType::FunctionType( const FunctionType &other ) : Type( other ), isVarArgs( other.isVarArgs ) {
     cloneAll( other.returnVals, returnVals );
     cloneAll( other.parameters, parameters );
 }
 
-FunctionType::~FunctionType()
-{
+FunctionType::~FunctionType() {
     deleteAll( returnVals );
     deleteAll( parameters );
 }
 
-void 
-FunctionType::print( std::ostream &os, int indent ) const
-{
+void FunctionType::print( std::ostream &os, int indent ) const {
     using std::string;
     using std::endl;
@@ -39,21 +25,20 @@
     Type::print( os, indent );
     os << "function" << endl;
-    if( !parameters.empty() ) {
-	os << string( indent+2, ' ' ) << "with parameters" << endl;
-	printAll( parameters, os, indent+4 );
-	if( isVarArgs ) {
-	    os << string( indent+4, ' ' ) << "and a variable number of other arguments" << endl;
+    if ( ! parameters.empty() ) {
+	os << string( indent + 2, ' ' ) << "with parameters" << endl;
+	printAll( parameters, os, indent + 4 );
+	if ( isVarArgs ) {
+	    os << string( indent + 4, ' ' ) << "and a variable number of other arguments" << endl;
 	}
-    } else if( isVarArgs ) {
-	os << string( indent+4, ' ' ) << "accepting unspecified arguments" << endl;
+    } else if ( isVarArgs ) {
+	os << string( indent + 4, ' ' ) << "accepting unspecified arguments" << endl;
     }
-    os << string( indent+2, ' ' ) << "returning ";
-    if( returnVals.empty() ) {
-	os << endl << string( indent+4, ' ' ) << "nothing " << endl;
+    os << string( indent + 2, ' ' ) << "returning ";
+    if ( returnVals.empty() ) {
+	os << endl << string( indent + 4, ' ' ) << "nothing " << endl;
     } else {
 	os << endl;
-	printAll( returnVals, os, indent+4 );
+	printAll( returnVals, os, indent + 4 );
     }
-
 }
 
Index: translator/SynTree/Type.h
===================================================================
--- translator/SynTree/Type.h	(revision 8c17ab009047298326a3dc92f5ddacbdc08bdc94)
+++ translator/SynTree/Type.h	(revision c8ffe20b6084e6e8082ff367961b87d47cfe83ff)
@@ -1,9 +1,2 @@
-/*
- * This file is part of the Cforall project
- *
- * $Id: Type.h,v 1.30 2005/08/29 20:59:26 rcbilson Exp $
- *
- */
-
 #ifndef TYPE_H
 #define TYPE_H
@@ -14,17 +7,15 @@
 
 
-class Type
-{
-public:
-    struct Qualifiers
-    {  
-	Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ) {}
-	Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ) {}
+class Type {
+  public:
+    struct Qualifiers {  
+      Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ) {}
+      Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ) {}
 	
-	Qualifiers &operator+=( const Qualifiers &other);
-	Qualifiers &operator-=( const Qualifiers &other);
+	Qualifiers &operator+=( const Qualifiers &other );
+	Qualifiers &operator-=( const Qualifiers &other );
 	Qualifiers operator+( const Type::Qualifiers &other );
-	bool operator==( const Qualifiers &other);
-	bool operator!=( const Qualifiers &other);
+	bool operator==( const Qualifiers &other );
+	bool operator!=( const Qualifiers &other );
 	bool operator<=( const Qualifiers &other );
 	bool operator>=( const Qualifiers &other );
@@ -57,13 +48,11 @@
     virtual Type *acceptMutator( Mutator &m ) = 0;
     virtual void print( std::ostream &os, int indent = 0 ) const;
-
-private:
+  private:
     Qualifiers tq;
     std::list<TypeDecl*> forall;
 };
 
-class VoidType : public Type
-{
-public:
+class VoidType : public Type {
+  public:
     VoidType( const Type::Qualifiers &tq );
 
@@ -74,32 +63,30 @@
 };
 
-class BasicType : public Type
-{
-public:
-    enum Kind
-	{  
-	    Bool,
-	    Char,
-	    SignedChar,
-	    UnsignedChar,
-	    ShortSignedInt,
-	    ShortUnsignedInt,
-	    SignedInt,
-	    UnsignedInt,
-	    LongSignedInt,
-	    LongUnsignedInt,
-	    LongLongSignedInt,
-	    LongLongUnsignedInt,
-	    Float,
-	    Double,
-	    LongDouble,
-	    FloatComplex,
-	    DoubleComplex,
-	    LongDoubleComplex,
-	    FloatImaginary,
-	    DoubleImaginary,
-	    LongDoubleImaginary,
-	    NUMBER_OF_BASIC_TYPES
-	};  
+class BasicType : public Type {
+  public:
+    enum Kind {  
+	Bool,
+	Char,
+	SignedChar,
+	UnsignedChar,
+	ShortSignedInt,
+	ShortUnsignedInt,
+	SignedInt,
+	UnsignedInt,
+	LongSignedInt,
+	LongUnsignedInt,
+	LongLongSignedInt,
+	LongLongUnsignedInt,
+	Float,
+	Double,
+	LongDouble,
+	FloatComplex,
+	DoubleComplex,
+	LongDoubleComplex,
+	FloatImaginary,
+	DoubleImaginary,
+	LongDoubleImaginary,
+	NUMBER_OF_BASIC_TYPES
+    };  
 
     BasicType( const Type::Qualifiers &tq, Kind bt );
@@ -114,12 +101,10 @@
 
     bool isInteger() const;
-
-private:
+  private:
     Kind kind;
 };
 
-class PointerType : public Type
-{
-public:
+class PointerType : public Type {
+  public:
     PointerType( const Type::Qualifiers &tq, Type *base );
     PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
@@ -140,10 +125,8 @@
     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     virtual void print( std::ostream &os, int indent = 0 ) const;
-
-private:
+  private:
     Type *base;
     
-    // in C99, pointer types can be qualified in many ways
-    // e.g., int f( int a[ static 3 ] )
+    // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
     Expression *dimension;
     bool isVarLen;
@@ -151,7 +134,6 @@
 };
 
-class ArrayType : public Type
-{
-public:
+class ArrayType : public Type {
+  public:
     ArrayType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
     ArrayType( const ArrayType& );
@@ -171,6 +153,5 @@
     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     virtual void print( std::ostream &os, int indent = 0 ) const;
-
-private:
+  private:
     Type *base;
     Expression *dimension;
@@ -179,7 +160,6 @@
 };
 
-class FunctionType : public Type
-{
-public:
+class FunctionType : public Type {
+  public:
     FunctionType( const Type::Qualifiers &tq, bool isVarArgs );
     FunctionType( const FunctionType& );
@@ -195,6 +175,5 @@
     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     virtual void print( std::ostream &os, int indent = 0 ) const;
-
-private:
+  private:
     std::list<DeclarationWithType*> returnVals;
     std::list<DeclarationWithType*> parameters;
@@ -207,7 +186,6 @@
 };
 
-class ReferenceToType : public Type
-{
-public:
+class ReferenceToType : public Type {
+  public:
     ReferenceToType( const Type::Qualifiers &tq, const std::string &name );
     ReferenceToType( const ReferenceToType &other );
@@ -222,19 +200,14 @@
     virtual Type *acceptMutator( Mutator &m ) = 0;
     virtual void print( std::ostream &os, int indent = 0 ) const;
-
-protected:
+  protected:
     virtual std::string typeString() const = 0;
     std::list< Expression* > parameters;
-    
-private:
+  private:
     std::string name;
-    
-};
-
-class StructInstType : public ReferenceToType
-{
+};
+
+class StructInstType : public ReferenceToType {
     typedef ReferenceToType Parent;
-    
-public:
+  public:
     StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {}
     StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {}
@@ -250,5 +223,5 @@
     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
 
-private:
+  private:
     virtual std::string typeString() const;
     
@@ -258,9 +231,7 @@
 };
 
-class UnionInstType : public ReferenceToType
-{
+class UnionInstType : public ReferenceToType {
     typedef ReferenceToType Parent;
-    
-public:
+  public:
     UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {}
     UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {}
@@ -275,6 +246,5 @@
     virtual void accept( Visitor &v ) { v.visit( this ); }
     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
-
-private:
+  private:
     virtual std::string typeString() const;
     
@@ -284,9 +254,7 @@
 };
 
-class EnumInstType : public ReferenceToType
-{
+class EnumInstType : public ReferenceToType {
     typedef ReferenceToType Parent;
-    
-public:
+  public:
     EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
     EnumInstType( const EnumInstType &other ) : Parent( other ) {}
@@ -296,13 +264,11 @@
     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
 
-private:
+  private:
     virtual std::string typeString() const;
 };
 
-class ContextInstType : public ReferenceToType
-{
+class ContextInstType : public ReferenceToType {
     typedef ReferenceToType Parent;
-    
-public:
+  public:
     ContextInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {}
     ContextInstType( const ContextInstType &other );
@@ -314,6 +280,5 @@
     virtual void accept( Visitor &v ) { v.visit( this ); }
     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
-
-private:
+  private:
     virtual std::string typeString() const;
     
@@ -323,9 +288,7 @@
 };
 
-class TypeInstType : public ReferenceToType
-{
+class TypeInstType : public ReferenceToType {
     typedef ReferenceToType Parent;
-    
-public:
+  public:
     TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType );
     TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype );
@@ -341,8 +304,6 @@
     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     virtual void print( std::ostream &os, int indent = 0 ) const;
-
-private:
+  private:
     virtual std::string typeString() const;
-    
     // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
     // where the type used here is actually defined
@@ -351,7 +312,6 @@
 };
 
-class TupleType : public Type
-{
-public:
+class TupleType : public Type {
+  public:
     TupleType( const Type::Qualifiers &tq );
     TupleType( const TupleType& );
@@ -364,12 +324,10 @@
     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     virtual void print( std::ostream &os, int indent = 0 ) const;
-
-private:
+  private:
     std::list<Type*> types;
 };
 
-class TypeofType : public Type
-{
-public:
+class TypeofType : public Type {
+  public:
     TypeofType( const Type::Qualifiers &tq, Expression *expr );
     TypeofType( const TypeofType& );
@@ -383,12 +341,10 @@
     virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     virtual void print( std::ostream &os, int indent = 0 ) const;
-
-private:
+  private:
     Expression *expr;
 };
 
-class AttrType : public Type
-{
-public:
+class AttrType : public Type {
+  public:
     AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr );
     AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type );
@@ -410,5 +366,5 @@
     virtual void print( std::ostream &os, int indent = 0 ) const;
 
-private:
+  private:
     std::string name;
     Expression *expr;
@@ -417,7 +373,5 @@
 };
 
-inline Type::Qualifiers &
-Type::Qualifiers::operator+=( const Type::Qualifiers &other )
-{
+inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {
     isConst |= other.isConst;
     isVolatile |= other.isVolatile;
@@ -427,16 +381,12 @@
 }
 
-inline Type::Qualifiers &
-Type::Qualifiers::operator-=( const Type::Qualifiers &other )
-{
-    if( other.isConst ) isConst = 0;
-    if( other.isVolatile ) isVolatile = 0;
-    if( other.isRestrict ) isRestrict = 0;
+inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) {
+    if ( other.isConst ) isConst = 0;
+    if ( other.isVolatile ) isVolatile = 0;
+    if ( other.isRestrict ) isRestrict = 0;
     return *this;
 }
 
-inline Type::Qualifiers
-Type::Qualifiers::operator+( const Type::Qualifiers &other )
-{
+inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) {
     Qualifiers q = other;
     q += *this;
@@ -444,16 +394,12 @@
 }
 
-inline bool 
-Type::Qualifiers::operator==( const Qualifiers &other)
-{
+inline bool Type::Qualifiers::operator==( const Qualifiers &other ) {
     return isConst == other.isConst
-	&& isVolatile == other.isVolatile
-	&& isRestrict == other.isRestrict;
+    && isVolatile == other.isVolatile
+    && isRestrict == other.isRestrict;
 ///	    && isLvalue == other.isLvalue;
 }
 
-inline bool 
-Type::Qualifiers::operator!=( const Qualifiers &other)
-{
+inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) {
     return isConst != other.isConst
 	|| isVolatile != other.isVolatile
@@ -462,7 +408,5 @@
 }
 
-inline bool 
-Type::Qualifiers::operator<=( const Type::Qualifiers &other )
-{
+inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) {
     return isConst <= other.isConst
 	&& isVolatile <= other.isVolatile
@@ -471,7 +415,5 @@
 }
 
-inline bool 
-Type::Qualifiers::operator>=( const Type::Qualifiers &other )
-{
+inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) {
     return isConst >= other.isConst
 	&& isVolatile >= other.isVolatile
@@ -480,16 +422,11 @@
 }
 
-inline bool 
-Type::Qualifiers::operator<( const Type::Qualifiers &other )
-{
+inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) {
     return operator!=( other ) && operator<=( other );
 }
 
-inline bool 
-Type::Qualifiers::operator>( const Type::Qualifiers &other )
-{
+inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) {
     return operator!=( other ) && operator>=( other );
 }
 
-
-#endif /* #ifndef TYPE_H */
+#endif // TYPE_H
