ASTaux.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 <assert.h>
00039 #include <stdint.h>
00040 #include <stdlib.h>
00041 #include <dirent.h>
00042 #include <fstream>
00043 #include <iostream>
00044 #include <string>
00045 #include <sstream>
00046 
00047 #include "UocInfo.hxx"
00048 #include "AST.hxx"
00049 #include "Type.hxx"
00050 #include "TypeInfer.hxx"
00051 #include "inter-pass.hxx"
00052 #include "FQName.hxx"
00053 
00054 using namespace boost;
00055 using namespace sherpa;
00056 
00057 shared_ptr<Type>
00058 AST::getType()
00059 {
00060   return symType->getType();
00061 }
00062 
00063 shared_ptr <const Type>
00064 AST::getType() const
00065 {
00066   return symType->getType();
00067 }
00068 
00069 shared_ptr<AST>
00070 AST::genIdent(const char *label, const bool isTV)
00071 {
00072   shared_ptr<AST> id = AST::make(at_ident);
00073 
00074   std::stringstream ss;
00075   if (isTV)
00076     ss << "'__";
00077   else
00078     ss << "__";
00079   ss << label << id->ID;
00080 
00081   id->s = ss.str();
00082 
00083   return id;
00084 }
00085 
00086 shared_ptr<AST>
00087 AST::genSym(shared_ptr<AST> ast, const char *label, const bool isTV)
00088 {
00089   shared_ptr<AST> id = genIdent(label, isTV);
00090   // FQN to be set by the next call to the ersolver
00091 
00092   id->identType = ast->identType;
00093   id->flags = ast->flags | ID_IS_GENSYM;
00094   id->symType = ast->symType;
00095   id->scheme = ast->scheme;
00096 
00097   return id;
00098 }
00099 
00100 std::string
00101 AST::asString() const
00102 {
00103   std::stringstream ss;
00104   PrettyPrint(ss, pp_NONE);
00105   return ss.str();
00106 }
00107 
00108 std::string
00109 AST::asString(PrettyPrintFlags flags) const
00110 {
00111   std::stringstream ss;
00112   PrettyPrint(ss, flags);
00113   return ss.str();
00114 }
00115 
00116 bool
00117 AST::isFnxn()
00118 {
00119   return (symType->getBareType()->typeTag == ty_fn);
00120 }
00121 
00122 size_t
00123 AST::nBits()
00124 {
00125   if (field_bits != 0)
00126     return field_bits;
00127   else
00128     return tagType->nBits();
00129 }
00130 
00131 
00132 shared_ptr<AST>
00133 AST::Use()
00134 {
00135   assert(astType == at_ident);
00136   assert(!symbolDef || isIdentType(id_tvar));
00137   shared_ptr<AST> idUse = getDeepCopy();
00138   idUse->flags  &= ~MASK_FLAGS_FROM_USE;
00139   idUse->symbolDef = shared_from_this();
00140   if (symType)
00141     idUse->symType = symType->getDCopy();
00142   return idUse;
00143 }
00144 
00145 
00146 AST::AST(shared_ptr<AST> ast, bool shallowCopyChildren)
00147 {
00148   astType = ast->astType;
00149   ID = ++(AST::astCount);
00150   identType = ast->identType;
00151   s = ast->s;
00152   loc = ast->loc;
00153   fqn = ast->fqn;
00154   flags = ast->flags;
00155   externalName = ast->externalName;
00156   symbolDef = ast->symbolDef;
00157   defn = ast->defn;
00158   decl = ast->decl;
00159   symType = ast->symType;
00160   scheme = ast->scheme;
00161   envs = ast->envs;
00162   defForm = ast->defForm;
00163   defbps = ast->defbps;
00164   litValue = ast->litValue;
00165   litBase = ast->litBase;
00166   isDecl = ast->isDecl;
00167   printVariant = ast->printVariant;
00168   tagType = ast->tagType;
00169   field_bits = ast->field_bits;
00170   unin_discm = ast->unin_discm;
00171   total_fill = ast->total_fill;
00172 
00173   if (shallowCopyChildren)
00174     children = ast->children;
00175 }
00176 
00177 
00178 shared_ptr<AST>
00179 AST::getTrueCopy()
00180 {
00181   shared_ptr<AST> to = AST::make(shared_from_this(), false);
00182 
00183   for (size_t i=0; i < children.size(); i++)
00184     to->children.push_back(child(i)->getTrueCopy());
00185 
00186   return to;
00187 }
00188 
00189 shared_ptr<AST>
00190 AST::getDeepCopy()
00191 {
00192   shared_ptr<AST> to = AST::make(shared_from_this(), false);
00193   to->symbolDef = GC_NULL;
00194   to->defn = GC_NULL;
00195   to->decl = GC_NULL;
00196   to->symType = GC_NULL;
00197   to->scheme = GC_NULL;
00198   to->envs = envs;
00199   to->defForm = GC_NULL;
00200   to->defbps = GC_NULL;
00201 
00202   for (size_t i=0; i<children.size(); i++)
00203     to->children.push_back(child(i)->getDeepCopy());
00204   return to;
00205 }

Generated on Sat Feb 4 23:59:28 2012 for BitC Compiler by  doxygen 1.4.7