Constraints.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 
00041 
00042 #include <assert.h>
00043 #include <stdint.h>
00044 #include <stdlib.h>
00045 #include <dirent.h>
00046 #include <fstream>
00047 #include <iostream>
00048 #include <string>
00049 #include <sstream>
00050 
00051 #include <libsherpa/UExcept.hxx>
00052 
00053 #include "UocInfo.hxx"
00054 #include "AST.hxx"
00055 #include "Type.hxx"
00056 #include "TypeInfer.hxx"
00057 #include "TypeScheme.hxx"
00058 #include "Typeclass.hxx"
00059 #include "inter-pass.hxx"
00060 
00061 using namespace std;
00062 using namespace boost;
00063 using namespace sherpa;
00064 
00067 bool
00068 TCConstraints::contains(shared_ptr<Typeclass> tc)
00069 {
00070   for (iterator itr = begin(); itr != end(); ++itr)
00071     if ((*itr)->strictlyEquals(tc, false, true))
00072       return true;
00073 
00074   return false;
00075 }
00076 
00086 
00087 void
00088 TCConstraints::addPred(shared_ptr<Typeclass> tc)
00089 {
00090   for (iterator itr = begin(); itr != end(); ++itr) {
00091     if ((*itr)->strictlyEquals(tc, false, true)) {
00092       // Compare the two constraints for strict-equality. That is,
00093       // alpha-renaming is not allowed here. Addition of predcates is
00094       // not a unifying operation.
00095       if (tc->flags & TY_CT_SUBSUMED)
00096         (*itr)->flags |= TY_CT_SUBSUMED;
00097       return;
00098     }
00099   }
00100 
00101   pred.insert(tc);
00102 }
00103 
00106 void
00107 TCConstraints::clearPred(shared_ptr<Constraint> ct)
00108 {
00109   ct =  ct->getType();
00110   for (iterator itr = begin(); itr != end(); ++itr) {
00111     shared_ptr<Constraint> pr = (*itr)->getType();
00112     if (pr == ct) {
00113       pred.erase(itr);
00114       return;
00115     }
00116   }
00117 }
00118 
00121 void
00122 TCConstraints::normalize()
00123 {
00124   TypeSet allPreds = pred;
00125   pred.clear();
00126 
00127   for (iterator itr = allPreds.begin(); itr != allPreds.end(); ++itr)
00128     addPred((*itr));
00129 }
00130 

Generated on Fri Feb 10 07:59:20 2012 for BitC Compiler by  doxygen 1.4.7