/*
 * This file is part of the Cforall project
 *
 * $Id: FixNames.cc,v 1.8 2005/08/29 20:14:12 rcbilson Exp $
 *
 */

#include "FixNames.h"
#include "SynTree/Declaration.h"
#include "SynTree/Expression.h"
#include "SynTree/Visitor.h"
#include "SymTab/Mangler.h"
#include "OperatorTable.h"

namespace CodeGen {

class FixNames : public Visitor
{
public:
  virtual void visit( ObjectDecl *objectDecl );
  virtual void visit( FunctionDecl *functionDecl );
};

void
fixNames( std::list< Declaration* > translationUnit )
{
  FixNames fixer;
  acceptAll( translationUnit, fixer );
}

void
fixDWT( DeclarationWithType *dwt )
{
  if( dwt->get_name() != "" ) {
    if( LinkageSpec::isDecoratable( dwt->get_linkage() ) ) {
      dwt->set_mangleName( SymTab::Mangler::mangle( dwt ) );
    }
  }
}

void 
FixNames::visit( ObjectDecl *objectDecl )
{
  Visitor::visit( objectDecl );
  fixDWT( objectDecl );
}

void 
FixNames::visit( FunctionDecl *functionDecl )
{
  Visitor::visit( functionDecl );
  fixDWT( functionDecl );
}

} // namespace CodeGen
