Trail.cxx

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright (C) 2008, Johns Hopkins University.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or
00007  * without modification, are permitted provided that the following
00008  * conditions are met:
00009  *
00010  *   - Redistributions of source code must contain the above 
00011  *     copyright notice, this list of conditions, and the following
00012  *     disclaimer. 
00013  *
00014  *   - Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions, and the following
00016  *     disclaimer in the documentation and/or other materials 
00017  *     provided with the distribution.
00018  *
00019  *   - Neither the names of the copyright holders nor the names of any
00020  *     of any contributors may be used to endorse or promote products
00021  *     derived from this software without specific prior written
00022  *     permission. 
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00027  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00028  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00029  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00030  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00032  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00033  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  **************************************************************************/
00037 
00038 #include <stdlib.h>
00039 #include <assert.h>
00040 
00041 
00042 #include "Options.hxx"
00043 #include "Type.hxx"
00044 #include "Trail.hxx"
00045 
00046 using namespace boost;
00047 using namespace sherpa;
00048 
00061 void
00062 Trail::link(shared_ptr<Type> from, shared_ptr<Type> to)
00063 {  
00064   from = from->getType();
00065   to = to->getType();
00066   
00067   if (to->boundInType(from)) {
00068     std::cerr << "CYCLIC SUBSTITUTION "
00069               << from->asString(Options::debugTvP)
00070               << " |-> "
00071               << to->asString(Options::debugTvP)
00072               << std::endl;
00073     assert(false);
00074   }
00075 
00076   DEBUG(TRAIL) 
00077     std::cerr << "LINKING: "
00078               << from->asString(Options::debugTvP)
00079               << " |-> "
00080               << to->asString(Options::debugTvP)
00081               << std::endl;
00082   
00083   vec.push_back(from);   
00084   from->link = to; 
00085 } 
00086 
00087 void
00088 Trail::subst(shared_ptr<Type> from, shared_ptr<Type> to)
00089 { 
00090   from = from->getType();
00091   to = to->getType();
00092   
00093   assert(from->typeTag == ty_tvar || from->typeTag == ty_kvar);
00094   
00095   if (to->boundInType(from)) {
00096     std::cerr << "CYCLIC SUBSTITUTION "
00097               << from->asString(Options::debugTvP)
00098               << " |-> "
00099               << to->asString(Options::debugTvP)
00100               << std::endl;
00101     assert(false);
00102   }
00103 
00104   DEBUG(TRAIL) 
00105     std::cerr << "SUBSTITUTING: "
00106               << from->asString(Options::debugTvP)
00107               << " |-> "
00108               << to->asString(Options::debugTvP)
00109               << std::endl;
00110 
00111   
00112   vec.push_back(from);   
00113   from->link = to; 
00114 }
00115 
00116 void
00117 Trail::rollBack(size_t upto)
00118 {
00119   assert(upto <= vec.size());
00120   
00121   for (size_t i = upto; i < vec.size(); i++) {
00122     vec[i]->link = GC_NULL;
00123     DEBUG(TRAIL) 
00124       std::cerr << "[RB] Releasing: "
00125                 << vec[i]->asString(Options::debugTvP)
00126                 << std::endl;
00127   }
00128 
00129   vec.erase(vec.begin() + upto, vec.end());
00130 }
00131 
00132 void
00133 Trail::release(const size_t n, shared_ptr<Type> rel)
00134 {
00135   assert(vec[n] == rel); // not getType()
00136   
00137   rel->link = GC_NULL;
00138   
00139   DEBUG(TRAIL) 
00140     std::cerr << "[RB] Releasing: "
00141               << rel->asString(Options::debugTvP)
00142               << std::endl;
00143 
00144   vec.erase(vec.begin() + n);
00145 }

Generated on Thu May 17 23:59:16 2012 for BitC Compiler by  doxygen 1.4.7