www.pudn.com > cppcc.rar > dfa_profile.cc


/*
 *  File:       dfa_profile.cc
 *              $Id: dfa_profile.cc,v 1.1 2002/06/23 23:42:29 alec Exp $
 *
 *  Author:     Alec Panoviciu (alecu@email.com)
 *
 *  Comments:
 *
 *  Revision history:
 *
 *  $Log: dfa_profile.cc,v $
 *  Revision 1.1  2002/06/23 23:42:29  alec
 *  profiling based optimization added
 *
 */

/* 
  Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 */


#include 

#include "dfa_profile.hh"
#include "scanner_dfa_spec.hh"
#include "basic_dfa_spec.hh"

ScannerDfaProfile::ScannerDfaProfile (ScannerDfaSpec &dfa)
{
  for (int i = 0; i < dfa.states.size(); i++)
    dfaProfiles.push_back(BasicDfaProfile(*dfa.states[i]));
}

BasicDfaProfile::BasicDfaProfile (BasicDfaSpec &dfa)
{
  for (int i = 0; i < dfa.states.size(); i++)
    stateProfiles.push_back(DfaStateProfile(dfa.states[i]));
}

DfaStateProfile::DfaStateProfile (BasicDfaSpec::State &s)
{
  set toSet;
  for (int i = 0; i < s.transitions.size(); i++)
    toSet.insert(s.transitions[i].to);
  freqs.resize(toSet.size());
  for (int i = 0; i < freqs.size(); i++)
    freqs[i] = 0;
}
  
bool ScannerDfaProfile::read (istream &is)
{
  for (int i = 0; i < dfaProfiles.size(); i++)
    if (!dfaProfiles[i].read(is))
      return false;
  return true;
}

bool BasicDfaProfile::read (istream &is)
{
  for (int i = 0; i < stateProfiles.size(); i++)
    if (!stateProfiles[i].read(is))
      return false;
  return true;
}


bool DfaStateProfile::read (istream &is)
{
  for (int i = 0; i < freqs.size(); i++) {
    is >> freqs[i];
  }

  return (bool) is;
}

void ScannerDfaProfile::reset ()
{
  for (int i = 0; i < dfaProfiles.size(); i++)
    dfaProfiles[i].reset();
}

void BasicDfaProfile::reset ()
{
  for (int i = 0; i < stateProfiles.size(); i++)
    stateProfiles[i].reset();
}


void DfaStateProfile::reset ()
{
  for (int i = 0; i < freqs.size(); i++) {
    freqs[i] = 0;;
  }
}