00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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 }