Symtab.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 
00065 
00066 #include <assert.h>
00067 #include <stdint.h>
00068 #include <stdlib.h>
00069 #include <dirent.h>
00070 #include <fstream>
00071 #include <iostream>
00072 #include <string>
00073 #include <stack>
00074 
00075 #include "Options.hxx"
00076 #include "AST.hxx"
00077 #include "Environment.hxx"
00078 #include "Symtab.hxx"
00079 #include "inter-pass.hxx"
00080 #include "MixFix.hxx"
00081 
00082 using namespace std;
00083 using namespace boost;
00084 using namespace sherpa;
00085  
00086 // Shap isn't convinced that the spec required this. Having said that,
00087 // this is similar to the unresolved forward static declaration
00088 // warning in C, and it is similarly useful.
00089 
00090 static bool
00091 warnUnresRef(std::ostream& errStream, 
00092              shared_ptr<AST> mod,
00093              shared_ptr<ASTEnvironment > env)
00094 {
00095   bool errorFree = true;
00096   
00097   assert(mod->astType == at_module);
00098   for (size_t c=0; c < mod->children.size(); c++) {
00099     shared_ptr<AST> ast = mod->child(c);
00100     switch(ast->astType) {
00101     case at_declunion:
00102     case at_declstruct:
00103     case at_proclaim:
00104       {
00105         // Various phases introduce proclaims internally. Don't
00106         // complain about those:
00107         if (ast->flags & PROCLAIM_IS_INTERNAL)
00108           break;
00109         
00110         // If the declaration is identified as externally provided,
00111         // don't complain about that:
00112         if (ast->flags & DEF_IS_EXTERNAL)
00113           break;
00114 
00115         // If we saw a declaration first, that will have been bound in
00116         // the environment. A subsequent definition replaces that
00117         // binding in-place, and following that a further declaration
00118         // will not change the environment. So if we look up the
00119         // symbol in the environment and get a declaration, we haven't
00120         // seen a definition:
00121         shared_ptr<AST> binding = env->getBinding(ast->child(0)->s);
00122         if (binding->isDecl) {
00123           errStream << ast->loc << ": WARNING: " 
00124                     << "Local declaration of " << ast->child(0)->s 
00125                     << " found here, but no definition found."
00126                     << std::endl;
00127           
00128           if (Options::Wall)
00129             errorFree = false;
00130           break;
00131         }
00132       }
00133     default:
00134       break;
00135     }
00136   }
00137   return errorFree;
00138 }
00139 
00140 static shared_ptr<UocInfo>
00141 findInterface(std::ostream& errStream, shared_ptr<AST> ifAst)
00142 {
00143   shared_ptr<UocInfo> iface=GC_NULL;
00144 
00145   UocMap::iterator itr = UocInfo::ifList.find(ifAst->s);
00146   if (itr != UocInfo::ifList.end()) {
00147     shared_ptr<UocInfo> thisIface = itr->second;
00148     iface = thisIface;
00149   }
00150       
00151   if (!iface) {
00152     errStream << ifAst->loc << ": "
00153               << "Internal Compiler Error. "
00154               << "Interface " << ifAst->s
00155               << " has NOT been processed"
00156               << std::endl;
00157     return GC_NULL;
00158   }
00159   
00160   if (!iface->env || !iface->gamma || !iface->instEnv) { 
00161     errStream << ifAst->loc << ": "
00162               << "Internal Compiler Error. "
00163               << "Interface " << ifAst->s
00164               << " has at least one NULL environment"
00165               << std::endl;
00166     return GC_NULL;
00167   }
00168   
00169   ifAst->envs.env = iface->env;
00170   ifAst->envs.gamma = iface->gamma;
00171   ifAst->envs.instEnv = iface->instEnv;
00172 
00173   return iface;
00174 }
00175 
00176 #if 0
00177 // Debugging function used for displaying the environment
00178 // along with status of completeness
00179 static void
00180 showEnv(std::ostream& errStream, 
00181         shared_ptr<ASTEnvironment > env)
00182 {
00183   for (ASTEnvironment::iterator itr = env->begin(); 
00184        itr != env->end(); ++ itr) {
00185     std::string name = itr->first;
00186     shared_ptr<Binding<AST> > bdng = itr->second;
00187     
00188     errStream << name << ": "
00189               << ((bdng->flags & BF_COMPLETE)? "Complete" : "Incomplete")
00190               << std::endl;
00191   }
00192   
00193   if(env->parent) {
00194     errStream << " -- " << std::endl;
00195     showEnv(errStream, env->parent);
00196   }
00197 }
00198 #endif
00199               
00200 static void
00201 aliasPublicBindings(const std::string& idName,
00202                     shared_ptr<ASTEnvironment > aliasEnv, 
00203                     shared_ptr<ASTEnvironment > fromEnv, 
00204                     shared_ptr<ASTEnvironment > toEnv)
00205 {
00206   for (ASTEnvironment::iterator itr = fromEnv->begin();
00207       itr != fromEnv->end(); ++itr) {
00208     std::string s = itr->first;
00209     shared_ptr<Binding<AST> > bdng = itr->second;
00210     
00211     if (bdng->flags & BF_PRIVATE)
00212       continue;
00213 
00214     shared_ptr<AST> ast = bdng->val;
00215 
00216     if (aliasEnv && aliasEnv->getBinding(ast->fqn.asString()))
00217       continue;
00218 
00219 
00220     if (idName.size())
00221       s = idName + FQName::LocalBindingSep + s;
00222 
00223     toEnv->addBinding(s, ast);
00224 
00225     // @bug There is a moderately serious bug here. If the importing
00226     // module is a consumer of an incomplete proclaim, then the
00227     // working assumption is that there are global initialization
00228     // constraints, and those constraints ensure that the provider has
00229     // already defined the proclaimed symbol, in which case it should
00230     // be marked complete in the importing module's context.
00231     //
00232     // However, it must NOT be marked complete in the *providing*
00233     // module's context until it is actually defined, and this yields
00234     // the following dilemma:
00235     //
00236     //  (import theModule X) ;; causing to be marked locally complete)
00237     //  ... use of X requiring completeness ...
00238     //  (provide theModule X) ;; at which point we suddenly realize
00239     //    that it can't be complete. We can un-mark it here, but the
00240     //    damage has already been done by the use.
00241     //
00242     // This is all tied in with the general problem of initialization
00243     // ordering.
00244     toEnv->setFlags(s, BF_PRIVATE|BF_COMPLETE);
00245   }
00246 }
00247 
00248 static bool
00249 importIfBinding(std::ostream& errStream, 
00250                 shared_ptr<ASTEnvironment > aliasEnv,
00251                 shared_ptr<AST> ifName)
00252 {
00253   if (!findInterface(errStream, ifName))
00254     return false;
00255 
00256   std::string canonicalIfName = ifName->s;
00257 
00258   // If we have seen this interface before, use the original import:
00259   shared_ptr<AST> ifAst = aliasEnv->getBinding(canonicalIfName);
00260   if (ifAst) {
00261     // Override the environments populated by findInterface with the
00262     // canonical duplicates.
00263     ifName->envs.env = ifAst->envs.env;
00264     ifName->envs.gamma = ifAst->envs.gamma;
00265     ifName->envs.instEnv = ifAst->envs.instEnv;
00266   }
00267 
00268   aliasEnv->addBinding(canonicalIfName, ifName);
00269 
00270   // Need to form the canonical duplicate environment in the current
00271   // importing UoC for this interface.
00272   shared_ptr<ASTEnvironment > dupEnv = 
00273     ASTEnvironment::make(ifName->envs.env->uocName);
00274 
00275   for (ASTEnvironment::iterator itr = ifName->envs.env->begin();
00276       itr != ifName->envs.env->end(); ++itr) {
00277     std::string s = itr->first;
00278     shared_ptr<Binding<AST> > bdng = itr->second;
00279     
00280     if (bdng->flags & BF_PRIVATE) {
00281       continue;
00282     }
00283       
00284     shared_ptr<AST> ast = bdng->val;
00285 
00286     dupEnv->addBinding(s, ast);
00287     dupEnv->setFlags(s, bdng->flags);
00288   }
00289 
00290   ifName->envs.env = dupEnv;
00291   return true;
00292 }
00293 
00294 static bool
00295 providing(shared_ptr<ASTEnvironment > aliasEnv, const FQName& fqn)
00296 {
00297   // Retrieve the thinned public environment for this fqn:
00298   shared_ptr<AST> ifName = aliasEnv->getBinding(fqn.iface);
00299 
00300   // If there is no binding for the canonical interface name, then we
00301   // areb processing the grand output AST, and providing has already
00302   // been checked.
00303   if (!ifName)
00304     return true;
00305 
00306   shared_ptr<ASTEnvironment > pubEnv = ifName->envs.env;
00307 
00308   // Retrieve the binding (if any) for fqn.ident:
00309   shared_ptr<Binding<AST> > bdng = pubEnv->doGetBinding(fqn.ident);
00310 
00311   assert(bdng);
00312 
00313   // Check the BF_PROVIDING flag on the binding:
00314   return (bdng->flags & BF_PROVIDING);
00315 }
00316 
00317 #if 0
00318 bool
00319 makeLocalAlias(shared_ptr<ASTEnvironment > fromEnv,
00320                std::string fromName,
00321                shared_ptr<ASTEnvironment > toEnv, 
00322                const std::string& toPfx,
00323                shared_ptr<AST> toIdent)
00324 {
00325   shared_ptr<Binding<AST> > bndg = fromEnv->doGetBinding(fromName);
00326 
00327   if (bndg->flags & BF_PRIVATE)
00328     return false;
00329       
00330   shared_ptr<AST> ast = bndg->val;
00331 
00332   std::string s = toIdent->s;
00333   if (toPfx.size())
00334     s = toPfx + FQName::sep + s;
00335 
00336   toEnv->addBinding(s, ast);
00337   toEnv->setFlags(s, BF_PRIVATE|BF_COMPLETE);
00338 
00339   return true;
00340 }
00341 #endif
00342 
00343 static void
00344 bindIdentDef(shared_ptr<AST> ast, shared_ptr<ASTEnvironment > env, 
00345              IdentType identType, shared_ptr<AST> currLB,
00346              ResolverFlags rflags)
00347 {  
00348   if (ast->isIdentType(id_tvar)) {
00349     env->addDefBinding(ast->s, ast);
00350     env->setFlags(ast->s, BF_COMPLETE | BF_NO_MERGE);
00351 
00352     assert(currLB);
00353     ast->tvarLB = currLB;   
00354   }
00355   else
00356     env->addBinding(ast->s, ast);
00357 
00358   // Type (arguments) Variables are not bound to incompleteness
00359   // restriction  I believe the following check is sufficient.
00360   // If there is problem, I will have to pass around an additional
00361   // bool addToIncomplete parameter, or at the caller, add them to a
00362   // dummy list.
00363   
00364   if (ast->identType != id_unresolved) 
00365     assert(ast->isIdentType(identType));
00366   else 
00367     ast->identType = identType;
00368   
00369 //   cout << "Added "<< ast->s << " at " << ast->loc 
00370 //        <<" with idType = " 
00371 //        << identTypeToString(identType)
00372 //        << std::endl;
00373 
00374 }
00375 
00376 static void
00377 markComplete(shared_ptr<ASTEnvironment > env)
00378 {
00379   for (ASTEnvironment::iterator itr = env->begin();
00380       itr != env->end(); ++itr)
00381     itr->second->flags |= BF_COMPLETE;
00382 }
00383 
00384 #define REWRITE_AST_IN_PLACE(_to, _from)          \
00385   do {                                            \
00386     shared_ptr<AST> to = (_to);                   \
00387     shared_ptr<AST> from = (_from);               \
00388                                                   \
00389     to->s = from->s;                              \
00390     to->astType = from->astType;                  \
00391     to->identType = from->identType;              \
00392     to->flags = from->flags;                      \
00393     to->children = from->children;                \
00394     to->fqn = from->fqn;                          \
00395   } while (0)
00396 
00397 //WARNING: **REQUIRES** answer and errorFree.
00398 // Carries aliasEnv passively throughout, as if closed over.
00399 #define RESOLVE(ast,env,lamLevel,mode,identType,currLB,flags)         \
00400   do {                                                                \
00401     bool answer =                                                     \
00402       resolve(errStream, (ast), aliasEnv, (env), (lamLevel),          \
00403               (mode), (identType), (currLB), (flags));                \
00404     if (answer == false)                                              \
00405       errorFree = false;                                              \
00406   } while (0)
00407 
00408 
00432 bool
00433 resolve(std::ostream& errStream, 
00434         shared_ptr<AST> ast, 
00435         shared_ptr<ASTEnvironment > aliasEnv,
00436         shared_ptr<ASTEnvironment > env,
00437         shared_ptr<ASTEnvironment > lamLevel,
00438         ResolutionMode mode, 
00439         IdentType identType,
00440         shared_ptr<AST> currLB,
00441         ResolverFlags flags)
00442 {
00443   bool errorFree = true;
00444 
00445   // Save the current environment in the AST.
00446   // If we create a new environment, we will update it later.
00447   ast->envs.env = env;
00448 
00449   //     errStream << "RES: " << ast->loc << ": " 
00450   //                 << ast->s << "[" << ast->astTypeName() << "]" 
00451   //                 << "   identType = " << identTypeToString(identType)
00452   //                 << " IncompleteOK = " 
00453   //                 << ((flags & RSLV_INCOMPLETE_OK)? "true" : "false")
00454   //                 << std::endl;  
00455   
00456   switch(ast->astType) {
00457 
00458   case at_Null:
00459   case at_boxedCat:
00460   case at_unboxedCat:
00461   case at_opaqueCat:
00462   case agt_category:
00463   case at_AnyGroup:
00464   case agt_literal:
00465   case agt_tvar:
00466   case agt_var:
00467   case agt_definition:
00468   case agt_type:
00469   case agt_expr:
00470   case agt_expr_or_define:
00471   case agt_eform:
00472   case agt_type_definition:
00473     //case agt_reprbodyitem:
00474   case agt_value_definition:
00475   case agt_uselhs:
00476   case at_letbindings:
00477   case at_loopbindings:
00478   case at_loopbinding:
00479   case agt_CompilationUnit:
00480   case agt_tc_definition:
00481   case agt_if_definition:
00482   case agt_ow:
00483   case at_localFrame:
00484   case at_frameBindings:
00485   case at_identList:
00486   case agt_qtype:
00487   case agt_fielditem:
00488   case at_defrepr:
00489     //case at_reprbody:
00490     //case at_reprcase:
00491     //case at_reprcaselegR:
00492     //case at_reprtag:
00493   case at_oc_closed:
00494   case at_oc_open:
00495   case agt_openclosed:
00496   case at_reprctrs:
00497   case at_reprctr:
00498   case at_reprrepr:
00499   case at_docString:
00500   case at_letGather:
00501   case agt_ucon:
00502     {
00503       errStream << ast->loc << ": Internal Compiler Error. " 
00504                 << "Function resolve, unexpected astType: " 
00505                 << ast->tagName()
00506                 << std::endl;
00507       
00508       errorFree = false;
00509       break;
00510     }
00511 
00512   case at_boolLiteral:
00513   case at_charLiteral:
00514   case at_intLiteral:
00515   case at_floatLiteral:
00516   case at_stringLiteral:
00517     break;
00518     
00519   case at_ident:
00520     {
00521       // If you change the way this works, see the comment in the
00522       // at_usesel case first!
00523       if (!ast->fqn.isInitialized()) {
00524         if (ast->isGlobal()) {
00525           ast->fqn = FQName(env->uocName, ast->s);
00526           ast->flags |= ID_IS_PRIVATE;
00527         }
00528         else
00529           ast->fqn = FQName(FQ_NOIF, ast->s);
00530       }
00531 
00532       switch(mode) {
00533         // DEF_MODE is mainly for top level. It can be a:
00534         // type name
00535         // value
00536         // constructor
00537         // field name
00538         // module/interface name
00539         // Individial cases distinguished using identType
00540 
00541       case DEF_MODE:
00542         {
00543           assert(env);
00544           assert(identType != id_unresolved);
00545           
00546           shared_ptr<AST> sym = env->getBinding(ast->s);
00547         
00548           if (sym) {
00549             if (sym->isDecl) {
00550               if ((sym->fqn.iface != ast->fqn.iface) &&
00551                   !providing(aliasEnv, sym->fqn)) {
00552                 // We are defining an ident that has an existing
00553                 // binding that came about through import. Confirm
00554                 // that we also marked it as providable:
00555 
00556                 errStream << ast->loc << ": " 
00557                           << ast->s
00558                           << " aliases an interface symbol that"
00559                           << " is not being provided."
00560                           << std::endl;
00561                 errorFree = false;
00562                 break;
00563                 
00564               }
00565 
00566               ast->identType = identType;
00567               if (!ast->isIdentType(sym->identType)) {
00568                 errStream << sym->loc << ": " 
00569                           << ast->s << " is declared here as "
00570                           << identTypeToString(sym->identType)
00571                           << std::endl
00572                           << ast->loc
00573                           << " and defined here as " 
00574                           << identTypeToString(identType)
00575                           << std::endl;
00576                 errorFree = false;
00577                 break;
00578               }
00579               
00580               sym->identType = ast->identType;
00581               sym->defn = ast;
00582               ast->decl = sym;
00583               env->removeBinding(ast->s);
00584               
00585               if (sym->externalName.size()) {
00586                 ast->externalName = sym->externalName;
00587               }
00588             }
00589             else if (ast->isGlobal()) {
00590               errStream << ast->loc << ": Redefinition of Symbol " 
00591                         << ast->s << ". Already defined at " 
00592                         << sym->loc << "." << std::endl;
00593               errorFree = false;
00594               break;
00595             }
00596           }
00597           
00598           assert(!ast->isDecl);
00599           bindIdentDef(ast, env, identType, currLB, flags);
00600           break;
00601         }
00602       
00603       case DECL_MODE:
00604         {
00605           assert(env);
00606           assert(identType != id_unresolved);
00607 
00608           ast->isDecl = true;
00609 
00610           shared_ptr<AST> sym = env->getBinding(ast->s);
00611           
00612           if (sym) {            
00613             if (!sym->isDecl) {
00614               // Will not be necessary in the new Polyinstantiator
00615               if ((flags & RSLV_NO_RESOLVE_DECL) == 0) {
00616                 errStream << ast->loc << ": Symbol " 
00617                           << ast->s << " already defined at " 
00618                           << sym->loc << "." << std::endl;
00619                 errorFree = false;
00620                 break;
00621               }
00622             }
00623             
00624             if (!sym->isIdentType(identType)) {
00625               errStream << sym->loc << ": " 
00626                         << ast->s << " is declared/defined here as "
00627                         << identTypeToString(sym->identType)
00628                         << std::endl
00629                         << ast->loc
00630                         << " and here as " 
00631                         << identTypeToString(identType)
00632                         << std::endl;
00633               errorFree = false;
00634               break;
00635             }
00636             ast->identType = sym->identType;
00637 
00638             if (ast->externalName.size()) {
00639               assert(ast->flags & DEF_IS_EXTERNAL);
00640               if (sym->externalName.size()) {
00641                 if (sym->externalName != ast->externalName) {
00642                   errStream << ast->loc << ": " 
00643                             << ast->s << " Identifier was previously "
00644                             << " declared with a different external name. "
00645                             << "Name here: " << ast->externalName
00646                             << "Previous name: " << sym->externalName
00647                             << std::endl;
00648                   errorFree = false;
00649                   break;
00650                 }  
00651               }
00652               else {
00653                 sym->externalName = ast->externalName;
00654               }
00655             }
00656             else {
00657               if (sym->externalName.size()) {
00658                 ast->externalName = sym->externalName;
00659               }
00660             }
00661             
00662             /* This is a compatible declaration, do nothing */
00663           }
00664           else
00665             bindIdentDef(ast, env, identType, currLB, flags);
00666           break;
00667         }
00668        
00669       case USE_MODE:
00670         {
00671           assert(env);
00672           assert((flags & RSLV_NO_CHK_USE_TYPE) || 
00673                  (identType != id_unresolved));
00674           
00675           // When resolving a label, must find it within current
00676           // lambda body or no joy.
00677           
00678           ast->symbolDef = env->getBinding(ast->s);
00679           
00680           //         if (ast->symbolDef == NULL) 
00681           //           cout << " Symdef is NULL for " << ast->s << endl;
00682           
00683           if (!ast->symbolDef) {
00684             // If there is a type-variable, it must be treated as though
00685             // it is a defining occurrence in order to support things
00686             // like:
00687             //
00688             // (define x:'a 100)
00689             //
00690             // However, a further caveat is that a type-variable should
00691             // be considered as a defining occurance ONLY for its first
00692             // opccurance in a defining scope.  This is to support
00693             // definitions like:
00694             //
00695             //   (lambda x:'a (lambda y:'a 0))
00696             //
00697             // That is, a type-variable in this slot should be treated
00698             // as a defining occurance ONLY if it is NOT ALREADY bound
00699             // in the current scope.  Also, it should only be done in
00700             // some cases -- the cases where RSLV_NEW_TV_OK is set in
00701             // flags. Otherwise, things like: (defunion list:ref (Next
00702             // 'a)) will also resolve.
00703         
00704              if (ast->isIdentType(id_tvar) &&
00705                ((flags & RSLV_NEW_TV_OK) || 
00706                 (ast->flags & TVAR_POLY_SPECIAL))) {
00707               bindIdentDef(ast, env, identType, currLB, flags);
00708               ast->symbolDef = ast;
00709               //errStream << "Created new ident for " << ast->s
00710               //              << " identType = " 
00711               //              << identTypeToString(ast->identType)
00712               //              << std::endl;
00713             }
00714             else {
00715               errStream << ast->loc << ": Identifier `"
00716                         << ast->s << "' used here, Undefined." 
00717                         << std::endl;
00718               
00719               //errStream << "Available bindings are: "
00720               //          << env->asString()
00721               //           << std::endl;
00722               
00723               errorFree = false;
00724               break;
00725             }
00726           }
00727           
00728           assert(ast->symbolDef);
00729 
00730           // If we are resolving a use occurrence of a label for
00731           // labeled escape, check that we did not cross a lambda
00732           // boundary.
00733           if ((identType == id_block) &&
00734               !env->getBinding(ast->s, lamLevel)) {
00735             errStream << ast->loc << ": Escape to "
00736                       << ast->s << "' must not cross lambda boundary."
00737                       << std::endl;
00738             errorFree = false;
00739             break;
00740           }
00741 
00742           shared_ptr<AST> def = ast->symbolDef;
00743 
00744           if ((flags & RSLV_USE_ONLY_PUBLIC) && 
00745              ((env->getFlags(ast->s) & BF_PRIVATE))) {
00746             errStream << ast->loc << ": Identifier `"
00747                       << ast->s << "' used here, But NO public definition "
00748                       << "found." << std::endl;
00749             errorFree = false;
00750             break;
00751           }
00752         
00753           if (((flags & RSLV_NO_CHK_USE_TYPE) == 0) && 
00754              (!def->isIdentType(identType))) {
00755             errStream << ast->loc << ": " << identTypeToString(identType) 
00756                       << " `" << ast->s << "' Undefined"
00757                       << " [But there is a " 
00758                       << identTypeToString(def->identType) 
00759                       << " defined]" << std::endl;
00760             errorFree = false;
00761           }
00762         
00763           bool ICRviolation = false;
00764           // The closure-conversion pass introduces some carefully 
00765           // crafted code using internal constructors that appear
00766           // incomplete the following restrictions. Since there cannot
00767           // be any incompleteness errors at that point,
00768           // incompleteness checking is disabled. otherwise,
00769           // incompleteness checking proceeds as usual.
00770           if (((flags & RSLV_INCOMPLETE_NO_CHK) == 0) &&
00771               ((env->getFlags(ast->s) & BF_COMPLETE) == 0)) {
00772             if ((flags & RSLV_INCOMPLETE_OK) == 0) {
00773               // If usage of an Incomplete variable is NOT OK, 
00774               // there is a violation, and we are done.
00775               ICRviolation = true;
00776             }
00777             else {                
00778               if (def->isIdentType(id_value)) {
00779                 assert(lamLevel);
00780                   
00781                 // This is a little subtle.
00782                 // In cases like:
00783                 // (define main3 (lambda () 
00784                 //                       (letrec ((x x))
00785                 //                          x))
00786                 // Usage of x in the letrec should not be allowed
00787                 // even though we are in a lambda.
00788                 // However, letrec cannot disable RSLV_INCOMPLETE_OK 
00789                 // because, it is still OK to use main3 inside
00790                 // the letrec expression
00791                 // So, here, if the RSLV_INCOMPLETE_OK is true,
00792                 // we still check that the identifier is defined at 
00793                 // the right LAMBDA LEVEL.            
00794                   
00795                 if (!lamLevel->getBinding(ast->s))
00796                   ICRviolation = true;
00797               }
00798             }
00799           }
00800 
00801           if (ICRviolation) {
00802             errStream << ast->loc << ": Usage of Identifier `"
00803                       << ast->s << "' Violates Incompleteness Restriction." 
00804                       << std::endl;
00805             errorFree = false;
00806           }
00807       
00808           if (def->flags & ID_FOR_USWITCH) {
00809             if ((flags & RSLV_SWITCHED_ID_OK) == 0) {
00810               errStream << ast->loc << ": The identifier `"
00811                         << ast->s << "' can only appear to the left of a `.'" 
00812                         << std::endl;
00813               errorFree = false;
00814             }
00815             else if (flags & RSLV_WITHIN_CATCH_MC) {
00816               errStream << ast->loc << ": The identifier `"
00817                         << ast->s << "' cannot be used while"
00818                         << " catching multiple exceptions."
00819                         << std::endl;
00820               errorFree = false;              
00821             }
00822           }
00823 
00824           ast->identType = def->identType;
00825           ast->flags  |= def->flags;
00826           ast->flags |= def->flags;
00827           ast->flags  &= ~MASK_FLAGS_FROM_USE;
00828           ast->externalName = def->externalName;
00829 
00830           /* Make sure tvars are scoped properly */
00831           if (def->isIdentType(id_tvar)) {                        
00832             assert(currLB);
00833             
00834             shared_ptr<AST> thisLB = GC_NULL;
00835             if (def->tvarLB->envs.env->isAncestor(currLB->envs.env))
00836               thisLB = currLB;
00837             else
00838               thisLB = def->tvarLB;
00839             
00840             while (thisLB->flags & LBS_PROCESSED) {
00841               thisLB = thisLB->parentLB;
00842               assert(thisLB);
00843             }
00844             
00845             def->tvarLB = thisLB;                    
00846           }
00847 
00848           //         cout << "Resolved " << ast->s << " at " << ast->loc
00849           //              << " to " << def->loc
00850           //              << " addr = " << &(*def)
00851           //              <<endl;
00852           break;
00853         }
00854 
00855       default:
00856         {
00857           assert(false);
00858           break;
00859         }
00860       }
00861 
00862       break;
00863     }
00864     
00865   case at_usesel:
00866     {
00906 
00914 
00915       shared_ptr<AST> lhs = ast->child(0);
00916       {
00917         // at_usesel can now have at_usesel as a left-hand element, in
00918         // which case we have ifName.StructTypeName.methodName and we
00919         // need to recurse on the LHS first.
00920 
00921         if (lhs->astType == at_usesel) {
00922           RESOLVE(lhs, env, lamLevel, USE_MODE, id_interface, 
00923                   GC_NULL, flags);
00924 
00925           if (!errorFree)
00926             break;
00927 
00928           // ast->astType should now be at_ident.
00929           assert(lhs->astType == at_ident);
00930         }
00931       }
00932 
00933       RESOLVE(lhs, env, lamLevel, USE_MODE, idc_usesel_lhs, 
00934               GC_NULL, flags);
00935 
00936       if (!errorFree)
00937         break;
00938 
00939       if (lhs->identType == id_interface) {
00940         shared_ptr<AST> iface = lhs;
00941       
00942         stringstream lookupStream;
00943         lookupStream << ":" << iface->s << ":";
00944         std::string lookupName = lookupStream.str();
00945         shared_ptr<AST> ifNameAst= aliasEnv->getBinding(lookupName);
00946         if (!ifNameAst) {
00947           errStream << ast->loc << ": "
00948                     << "Identifier `"
00949                     << iface->s 
00950                     << "' is undefined. Are you missing the name on an import statement?"
00951                     << std::endl;
00952           errorFree = false;
00953           break;
00954         }
00955 
00956         std::string ifName = ifNameAst->s;
00957         assert(ifName != "");
00958       
00959         shared_ptr<ASTEnvironment > ifenv = iface->symbolDef->envs.env;
00960       
00961         if (!ifenv) {
00962           errStream << ast->loc << ": "
00963                     << "Internal Compiler Error. "
00964                     << "Interface " << ifName
00965                     << " needed by "<< iface->s << " has a NULL environment"
00966                     << std::endl;
00967           errorFree = false;
00968           break;
00969         }
00970       
00971         FQName importedFQN = FQName(ifName, ast->child(1)->s);
00972       
00973         ast->s = lhs->s + FQName::LocalBindingSep + ast->child(1)->s;
00974         ast->astType = at_ident;
00975         ast->identType = ast->child(1)->identType;
00976         ast->flags = ast->child(1)->flags;
00977         ast->flags |= ID_IS_GLOBAL;
00978 
00979         ast->children.clear();
00980 
00981         // SHOULD THE PUBLIC FLAG BE TAKEN OFF HERE ??
00982         RESOLVE(ast, env, lamLevel, mode, identType, currLB,  
00983                 (flags & (~RSLV_BIND_PUBLIC)));
00984 
00985         ast->fqn = importedFQN;
00986       }
00987       else if ((lhs->identType == id_struct) ||
00988                (lhs->identType == id_object)) {
00989         ast->s = lhs->s + "." + ast->child(1)->s;
00990         ast->astType = at_ident;
00991         ast->identType = ast->child(1)->identType;
00992         ast->flags = ast->child(1)->flags;
00993         ast->flags |= ID_IS_GLOBAL;
00994 
00995         ast->children.clear();
00996 
00997         RESOLVE(ast, env, lamLevel, mode, identType, currLB, 
00998                 flags);
00999 
01000         break;
01001       }
01002       else {
01003         errStream << ast->loc << ": "
01004                   << "Required struct name or interface name to"
01005                   << " the left of this dot."
01006                   << std::endl;
01007         errorFree = false;
01008         break;
01009       }
01010 
01011       break;
01012     }
01013 
01014   case at_interface:
01015     {
01016       flags |= RSLV_IS_INTERFACE;
01017 
01018       // match agt_definition*
01019       for (size_t c = 1; c < ast->children.size(); c++)
01020         RESOLVE(ast->child(c), env, lamLevel, DEF_MODE, identType, 
01021                 GC_NULL, flags);
01022 
01023       // In an interface unit, we do not check for unresolved
01024       // references, because they will (hopefully) be satisfied by
01025       // providing modules.
01026 
01027       break;
01028     }
01029 
01030   case at_module:
01031     {
01032       // match agt_definition*
01033       for (size_t c = 0; c < ast->children.size(); c++)
01034         RESOLVE(ast->child(c), env, lamLevel, DEF_MODE, identType, 
01035                 GC_NULL, flags);
01036 
01037       if ((flags & RSLV_NO_RESOLVE_DECL) == 0)        
01038         CHKERR(errorFree, warnUnresRef(errStream, ast, env));
01039 
01040       break;
01041     }
01042 
01043   case at_defunion:
01044     {
01045       shared_ptr<ASTEnvironment > tmpEnv = env->newDefScope();
01046       ast->envs.env = tmpEnv;
01047 
01048       shared_ptr<AST> category = ast->child(2);
01049 
01050       // match at_ident
01051       RESOLVE(ast->child(0), tmpEnv, lamLevel, DEF_MODE, 
01052               id_union, ast, 
01053               (flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK)) | RSLV_BIND_PUBLIC);
01054       if (category->astType == at_boxedCat)
01055         tmpEnv->setFlags(ast->child(0)->s, BF_COMPLETE);
01056 
01057       // match at_tvlist
01058       RESOLVE(ast->child(1), tmpEnv, lamLevel, DEF_MODE, 
01059               id_tvar, ast,
01060               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01061 
01062       // category keyword at child(2)
01063 
01064       // match at_declares
01065       RESOLVE(ast->child(3), tmpEnv, lamLevel, NULL_MODE,
01066               id_unresolved, ast,              
01067               ((flags & (~RSLV_NEW_TV_OK)) & (~RSLV_INCOMPLETE_OK)) | RSLV_WITHIN_DEFUNION);
01068 
01069     
01070       // match at_constructors
01071       RESOLVE(ast->child(4), tmpEnv, lamLevel, DEF_MODE,
01072               idc_uctor, ast,               
01073               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01074 
01075       // match at_constraints
01076       RESOLVE(ast->child(5), tmpEnv, lamLevel, USE_MODE, 
01077               idc_type, ast, 
01078               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01079       
01080       env->mergeBindingsFrom(tmpEnv);
01081       break;
01082     }
01083 
01084   case at_defstruct:
01085   case at_defobject:
01086   case at_defexception:
01087     {
01088       shared_ptr<ASTEnvironment > tmpEnv = env->newDefScope();
01089       ast->envs.env = tmpEnv;
01090 
01091       shared_ptr<AST> category = ast->child(2);
01092       shared_ptr<AST> fields = ast->child(4);
01093 
01094       if (ast->astType == at_defexception &&
01095           category->astType != at_boxedCat) {
01096         errStream << ast->loc << ": "
01097                   << "exception " << ast->child(0)->s
01098                   << ": Exception definitions must be boxed."
01099                   << std::endl;
01100         errorFree = false;
01101       }              
01102 
01103       IdentType identType;
01104       switch(ast->astType) {
01105       case at_defstruct:
01106         identType = id_struct;
01107         break;
01108       case at_defobject:
01109         identType = id_object;
01110         break;
01111       case at_defexception:
01112         identType = (fields->children.size() == 0) ? id_ucon0 : id_ucon;
01113         break;
01114       }
01115 
01116       // match at_ident
01117       RESOLVE(ast->child(0), tmpEnv, lamLevel, DEF_MODE, 
01118               identType, ast,
01119               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK) | RSLV_BIND_PUBLIC);
01120       if (category->astType == at_boxedCat)
01121         tmpEnv->setFlags(ast->child(0)->s, BF_COMPLETE);
01122       
01123       // match at_tvlist
01124       RESOLVE(ast->child(1), tmpEnv, lamLevel, DEF_MODE, 
01125               id_tvar, ast, 
01126               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01127     
01128       // category keyword at child(2)
01129 
01130       // match at_declares
01131       RESOLVE(ast->child(3), tmpEnv, lamLevel, NULL_MODE, 
01132               id_unresolved, ast, 
01133               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01134       
01135       // match at_fields
01136       RESOLVE(ast->child(4), tmpEnv, lamLevel, DEF_MODE, 
01137               id_field, ast, 
01138               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01139  
01140       // match at_constraints
01141       RESOLVE(ast->child(5), tmpEnv, lamLevel, USE_MODE, 
01142               idc_type, ast, 
01143               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01144       
01145       env->mergeBindingsFrom(tmpEnv);
01146       break;
01147     }
01148     
01149   case at_declunion:
01150   case at_declstruct:
01151   case at_declrepr:
01152     {
01153       shared_ptr<ASTEnvironment > tmpEnv = env->newDefScope();
01154       ast->envs.env = tmpEnv;
01155 
01156       IdentType it = ((ast->astType == at_declstruct) ?
01157                       id_struct : id_union);
01158       
01159       // match at_ident
01160       RESOLVE(ast->child(0), tmpEnv, lamLevel, DECL_MODE, 
01161               it, ast, 
01162               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK)
01163               | RSLV_BIND_PUBLIC);
01164     
01165       // match at_tvlist
01166       RESOLVE(ast->child(1), tmpEnv, lamLevel, DEF_MODE, 
01167               id_tvar, ast, 
01168               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01169 
01170       // category keyword at child(2)
01171       // empty declares at child(3)
01172       // empty fields/ctors at child(4)
01173       
01174       // match at_constraints
01175       RESOLVE(ast->child(5), tmpEnv, lamLevel, USE_MODE, 
01176               idc_type, ast, 
01177               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01178       
01179       env->mergeBindingsFrom(tmpEnv);
01180       break;
01181     }
01182 
01183   case at_proclaim:
01184     {
01185       shared_ptr<ASTEnvironment > tmpEnv = env->newDefScope();
01186       ast->envs.env = tmpEnv;
01187 
01188       // match at_ident
01189       RESOLVE(ast->child(0), tmpEnv, lamLevel, DECL_MODE, 
01190               idc_value, ast, 
01191               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK)
01192               | RSLV_BIND_PUBLIC);
01193    
01194       // match at_type
01195       RESOLVE(ast->child(1), tmpEnv, lamLevel, USE_MODE, 
01196               idc_type, ast, 
01197               flags | (RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01198       
01199       // match at_constraints
01200       RESOLVE(ast->child(2), tmpEnv, lamLevel, USE_MODE, 
01201               idc_type, ast, 
01202               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01203       
01204       env->mergeBindingsFrom(tmpEnv);
01205       break;
01206     }
01207 
01208   case at_recdef:
01209   case at_define:
01210     {
01214 
01215       shared_ptr<ASTEnvironment > tmpEnv = env->newDefScope();
01216       ast->envs.env = tmpEnv;
01217 
01218       /* Mark the present identifier "not mutable yet". If we see a
01219       set!, this will get fixed. This must be cleared here because, the
01220       marking may not hold true after a certain pass. For example,
01221       after refization by the Closure converter, the identifier is no
01222       longer mutable. It is the thing that is pointed to, that is
01223       mutable.  */
01224       assert(ast->child(0)->astType == at_identPattern);
01225       ast->child(0)->child(0)->flags &= ~ID_IS_MUTATED;
01226       
01227       if (ast->astType == at_recdef) {
01228         // Binding patterns must be in scope.
01229         // match agt_bindingPattern
01230         RESOLVE(ast->child(0), tmpEnv, lamLevel, DEF_MODE, 
01231                 id_value, ast, 
01232                 flags | (RSLV_NEW_TV_OK) | RSLV_BIND_PUBLIC);
01233       }
01234 
01235       // match agt_expr
01236       RESOLVE(ast->child(1), tmpEnv, lamLevel, USE_MODE, 
01237               idc_value, ast, 
01238               flags | (RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01239       
01240       if (ast->astType == at_define) {
01241         // Binding patterns not in scope within expr, so handle them
01242         // later.
01243         // match agt_bindingPattern
01244         RESOLVE(ast->child(0), tmpEnv, lamLevel, DEF_MODE, 
01245                 id_value, ast, 
01246                 flags | (RSLV_NEW_TV_OK) | RSLV_BIND_PUBLIC);
01247       }
01248 
01249       // match at_constraints
01250       RESOLVE(ast->child(2), tmpEnv, lamLevel, USE_MODE, 
01251               idc_type, ast, 
01252               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));    
01253       
01254       /* Mark the present identifier closed wrt mutability */
01255       ast->child(0)->child(0)->flags |= ID_MUT_CLOSED;
01256 
01257       env->mergeBindingsFrom(tmpEnv);
01258       break;
01259     }
01260 
01261   case at_deftypeclass:
01262     {
01263       shared_ptr<ASTEnvironment > tmpEnv = env->newDefScope();
01264       ast->envs.env = tmpEnv;
01265 
01266       // match at_ident
01267       RESOLVE(ast->child(0), tmpEnv, lamLevel, DEF_MODE, 
01268               id_typeclass, ast,
01269               (flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK)
01270                | RSLV_BIND_PUBLIC));
01271       
01272       // match at_tvlist
01273       RESOLVE(ast->child(1), tmpEnv, lamLevel, DEF_MODE, 
01274               idc_type, ast, 
01275               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01276 
01277 
01278       // match at_tc_decls
01279       RESOLVE(ast->child(2), tmpEnv, lamLevel, USE_MODE, 
01280               idc_type, ast, 
01281               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01282       
01283       // Skip the open/closed node.
01284 
01285       // match at method_decls
01286       RESOLVE(ast->child(4), tmpEnv, lamLevel, USE_MODE, 
01287               idc_type, ast, 
01288               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));      
01289 
01290       // match at constraints
01291       RESOLVE(ast->child(5), tmpEnv, lamLevel, USE_MODE, 
01292               idc_type, ast, 
01293               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));      
01294 
01295       tmpEnv->setFlags(ast->child(0)->s, BF_COMPLETE);
01296       env->mergeBindingsFrom(tmpEnv);
01297       break;
01298     }
01299 
01300   case at_tcdecls:
01301     {
01302       // match at agt_tcdecl+ 
01303       for (size_t c = 0; c < ast->children.size(); c++)
01304         RESOLVE(ast->child(c), env, lamLevel, 
01305                 USE_MODE, identType, currLB,  flags);
01306       
01307       break;
01308     }
01309 
01310   case at_tyfn:
01311     {
01312       // match at_tvlist
01313       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01314               idc_type, currLB, flags);
01315       
01316       // match agt_tvar
01317       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
01318               idc_type, currLB, flags);  
01319       break;
01320     }
01321 
01322   case at_tcapp:
01323     {
01324       // match at agt_var
01325       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01326               id_typeclass, currLB, flags);
01327 
01328       // match at agt_type+
01329       for (size_t c = 1; c < ast->children.size(); c++)
01330         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
01331                 idc_type, currLB, flags);
01332 
01333       break;
01334     }
01335 
01336   case at_method_decls:
01337     {
01338       // match at at_method_decl+
01339       for (size_t c = 0; c < ast->children.size(); c++)
01340         RESOLVE(ast->child(c), env, lamLevel, 
01341                 DEF_MODE, id_tcmethod, currLB, flags);
01342       
01343       break;
01344     }
01345 
01346   case at_method_decl:
01347     {
01348       // match at at_ident
01349       RESOLVE(ast->child(0), env, lamLevel, DEF_MODE, 
01350               id_tcmethod, currLB,
01351               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK)
01352               | RSLV_BIND_PUBLIC);
01353       
01354       // match at at_fn
01355       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
01356               idc_type, currLB, flags);
01357       
01358       break;
01359     }
01360 
01361   case at_definstance:
01362     {      
01363       shared_ptr<ASTEnvironment > tmpEnv = env->newDefScope();
01364       ast->envs.env = tmpEnv;
01365 
01366       // match at at_tcapp
01367       RESOLVE(ast->child(0), tmpEnv, lamLevel, 
01368               USE_MODE, idc_type, ast, flags | RSLV_NEW_TV_OK);
01369 
01378 
01379       if (errorFree) {
01380         shared_ptr<AST> tcName = ast->child(0)->child(0);
01381         shared_ptr<AST> tcSym = tcName->symbolDef;
01382         shared_ptr<AST> tcDef = tcSym->defForm;
01383         bool isClosed = (tcDef->child(3)->astType == at_oc_closed);
01384 
01385         if (isClosed && tcSym->fqn.iface != env->uocName) {
01386           errStream << ast->loc
01387                     << ": Type class " << tcSym->fqn
01388                     << " is closed. Instances may not be defined by other"
01389                     << " modules or interfaces."
01390                     << std::endl;
01391           errorFree = false;
01392         }
01393       }
01394 
01395       // match at at_tcmethods
01396       RESOLVE(ast->child(1), tmpEnv, lamLevel, 
01397               USE_MODE, idc_value, ast, flags);
01398       
01399       // match at at_constraints
01400       RESOLVE(ast->child(2), tmpEnv, lamLevel, 
01401               USE_MODE, idc_type, ast, flags | RSLV_NEW_TV_OK);
01402       break;
01403     }
01404 
01405   case at_tcmethods:
01406     { 
01407       // match at expr+
01408       for (size_t c = 0; c < ast->children.size(); c++)
01409         RESOLVE(ast->child(c), env, lamLevel, 
01410                 USE_MODE, idc_value, currLB, flags);
01411       
01412       // Make sure that each method is defined at most once (no
01413       // duplicates). 
01414       
01415       //std::cerr << ast->loc << ": Processing :" 
01416       //            << ast->asString() << std::endl;
01417       
01418       for (size_t i = 0; i < ast->children.size(); i++) {
01419         shared_ptr<AST> ith_bind = ast->child(i);
01420 
01421         for (size_t j = i+1; j < ast->children.size(); j++) {
01422           shared_ptr<AST> jth_bind = ast->child(j);
01423 
01424           if(ith_bind->child(0)->s == jth_bind->child(0)->s) {
01425             errStream << jth_bind->loc 
01426                       << ": Duplicate method definition for "
01427                       << ith_bind->child(0)->s
01428                       << std::endl;
01429             errorFree = false;
01430             break;
01431           }
01432         }
01433       }
01434       
01435       // Checking that all methods are being defined, and that only
01436       // those methods belonging to a particular type class are
01437       // defined is done by the type system. We don't have access to
01438       // the typeclass's definition AST (the identifier's symbolDef
01439       // points to the typeclass identifier) here, and the type system
01440       // already has a readily constructed structure to handle this.
01441 
01442       break;
01443     }
01444     
01445   case at_tcmethod_binding:
01446     { 
01447       // match at expr+
01448       for (size_t c = 0; c < ast->children.size(); c++)
01449         RESOLVE(ast->child(c), env, lamLevel, 
01450                 USE_MODE, idc_value, currLB, flags);
01451       break;
01452     }
01453 
01454   case at_ifident:
01455     break;
01456     
01457   case at_provide:
01458     {
01459       shared_ptr<AST> ifAst = ast->child(0);
01460       if (!importIfBinding(errStream, aliasEnv, ifAst)) {
01461         errStream << ast->loc << ": "
01462                   << "Unable to provide interface `"
01463                   << ifAst->s
01464                   << "' - interface file not found. "
01465                   << std::endl;
01466         errorFree = false;
01467         break;
01468       }
01469 
01470       shared_ptr<ASTEnvironment > ifEnv = ifAst->envs.env;
01471 
01472       for (size_t i = 1; i < ast->children.size(); i++) {
01473         shared_ptr<AST> provideName=ast->child(i);
01474         shared_ptr<Binding<AST> > bndg = ifEnv->doGetBinding(provideName->s);
01475         if (!bndg) {
01476           errStream << ast->loc << ": "
01477                     << provideName->s
01478                     << " not found in interface "
01479                     << ifAst->s
01480                     << std::endl;
01481           
01482           errorFree = false;
01483           break;
01484         }
01485 
01486         if (!bndg->val->isDecl) {
01487           errStream << ast->loc << ": Cannot provide "
01488                     << provideName->s
01489                     << " in interface "
01490                     << ifAst->s
01491                     << ", which is defined in the interface."
01492                     << std::endl;
01493           
01494           errorFree = false;
01495           break;
01496         }
01497 
01498         bndg->flags |= BF_PROVIDING;
01499       }
01500 
01501       break;
01502     }    
01503 
01504   case at_importAs:
01505     {
01506       shared_ptr<AST> ifAst = ast->child(0); 
01507       shared_ptr<AST> idAst = ast->child(1);
01508 
01509       if (!importIfBinding(errStream, aliasEnv, ifAst)) {
01510         errStream << ast->loc << ": "
01511                   << "Unable to import interface `"
01512                   << ifAst->s
01513                   << "' - interface file not found. "
01514                   << std::endl;
01515         errorFree = false;
01516         break;
01517       }
01518 
01519       // import ident ifname
01520       shared_ptr<ASTEnvironment > tmpEnv = env->newScope();
01521         //        new ASTEnvironment(ifAst->envs.env->uocName);
01522 
01523       ast->envs.env = tmpEnv;
01524       
01525       if (ifAst->s == env->uocName) {
01526         errStream << ast->loc << ": "
01527                   << "Cannot import an undefined interface. "
01528                   << std::endl;
01529         
01530         errorFree = false;
01531         break;
01532       }
01533       
01534       RESOLVE(idAst, tmpEnv, lamLevel, DEF_MODE,
01535               id_interface, GC_NULL, flags);
01536 
01537       // For every (importAs local global) add to the alias
01538       // environment, the mapping :local: -> ifAst which 
01539       // holds the interface name. This is consulted from the
01540       // at_usesel case in order to obtain the real name of the
01541       // interface for purposes of error diagnostics, and setting the
01542       // FQN correctly.
01543       // This handling is in liu of using the now retired ifName field
01544       // on the idAst AST.
01545       stringstream ifNameMap;
01546       ifNameMap << ":" << idAst->s << ":";
01547       std::string ifNameMapStr = ifNameMap.str();
01548 
01549       aliasEnv->addBinding(ifNameMapStr, ifAst);
01550       aliasEnv->setFlags(ifNameMapStr, BF_PRIVATE);
01551 
01552       // The interface name must not be exported
01553       env->setFlags(idAst->s,
01554                     ((env->getFlags(idAst->s)) |
01555                      BF_PRIVATE)); 
01556    
01557       idAst->envs.env = ifAst->envs.env;
01558       idAst->envs.gamma = ifAst->envs.gamma;
01559       idAst->envs.instEnv = ifAst->envs.instEnv;
01560 
01561       aliasPublicBindings(idAst->s, GC_NULL, idAst->envs.env, tmpEnv);
01562       env->mergeBindingsFrom(tmpEnv);
01563       break;
01564     }
01565 
01566   case at_import:
01567     {
01568       // from ifName alias+
01569       shared_ptr<ASTEnvironment > tmpEnv = env->newScope();
01570       ast->envs.env = tmpEnv;
01571      
01572       shared_ptr<AST> ifAst = ast->child(0);
01573 
01574       if (ifAst->s == env->uocName) {
01575         errStream << ast->loc << ": "
01576                   << "Cannot import an undefined interface. "
01577                   << std::endl;
01578         
01579         errorFree = false;
01580         break;
01581       }
01582 
01583       if (!importIfBinding(errStream, aliasEnv, ifAst)) {
01584         errStream << ast->loc << ": "
01585                   << "Unable to import interface `"
01586                   << ifAst->s
01587                   << "' - interface file not found. "
01588                   << std::endl;
01589         errorFree = false;
01590         break;
01591       }
01592 
01593       if (ast->children.size() == 1) {
01594         // This is an import-all form
01595         aliasPublicBindings(std::string(), aliasEnv, ifAst->envs.env, tmpEnv);
01596       }
01597       else {
01598         // Need to import only certain bindings
01599         for (size_t c = 1; c < ast->children.size(); c++) {
01600           shared_ptr<AST> alias = ast->child(c);
01601           shared_ptr<AST> localName = alias->child(0);
01602           shared_ptr<AST> pubName = alias->child(1);
01603         
01604           RESOLVE(pubName, ifAst->envs.env, lamLevel, USE_MODE,
01605                   id_unresolved, currLB, 
01606                   ((flags & (~RSLV_NEW_TV_OK))) | RSLV_NO_CHK_USE_TYPE);
01607         
01608           if (!errorFree)
01609             break;
01610 
01611           // Enforce the "one alias" rule.
01612           shared_ptr<Binding<AST> > bndg = 
01613             ifAst->envs.env->doGetBinding(pubName->s);
01614 
01615           std::string pubFQN = bndg->val->fqn.asString();
01616 
01617           shared_ptr<AST> oldAlias = aliasEnv->getBinding(pubFQN);
01618           if (oldAlias) {
01619             errStream << alias->loc << ": The public identifier "
01620                       << pubFQN
01621                       << ", being aliased here to " 
01622                       << pubName->s
01623                       << ", was previously aliased to "
01624                       << oldAlias->s
01625                       << " at "
01626                       << oldAlias->loc
01627                       << std::endl;
01628             errorFree = false;
01629             break;
01630           }
01631             
01632           aliasEnv->addBinding(pubFQN, localName);
01633 
01634           shared_ptr<AST> oldDef = env->getBinding(localName->s);
01635           if (oldDef) {
01636             errStream << alias->loc << ": Conflict for alias definition"
01637                       << localName->s
01638                       << ". Previously defined at "
01639                       << oldDef->loc
01640                       << std::endl;
01641             errorFree = false;
01642             break;
01643           }
01644         
01645           tmpEnv->addBinding(localName->s, pubName->symbolDef);
01646           tmpEnv->setFlags(localName->s, BF_PRIVATE);
01647         }
01648       }
01649 
01650       env->mergeBindingsFrom(tmpEnv);
01651       break;
01652     }
01653     
01654   case at_ifsel:
01655     {
01656       assert(false);
01657       break;
01658     }
01659 
01660   case at_declares:
01661     {
01662       // match at_declare*
01663       for (size_t c = 0; c < ast->children.size(); c++)
01664         RESOLVE(ast->child(c), env, lamLevel, NULL_MODE, identType,  
01665                 currLB,  flags);
01666 
01667       break;
01668     }
01669 
01670   case at_declare:
01671     {
01672       // match at_ident
01673       // The first identifier has special meaning, and must be 
01674       // dealt with by hand.
01675 
01676       std::string declID = ast->child(0)->s;
01677 
01678       if (declID != "stateful"
01679           && declID != "tag") {
01680         errStream << ast->child(0)->loc 
01681                   << ": " 
01682                   << declID 
01683                   << " is not a recognized declare identifier"
01684                   << std::endl;
01685         errorFree = false;
01686       }
01687 
01688       if (declID == "stateful") {
01689         if (!(flags & RSLV_IS_INTERFACE)) {
01690           errStream << ast->child(0)->loc 
01691                     << ": Only Interfaces can be declared to be stateful"
01692                     << std::endl;
01693           errorFree = false;
01694         }
01695       }
01696 
01697       if (declID == "tag") {
01698         if (!(flags & RSLV_WITHIN_DEFUNION)) {
01699           errStream << ast->child(0)->loc 
01700                     << ": tag declaration can only occur within a defunion"
01701                     << std::endl;
01702           errorFree = false;
01703         } 
01704       }        
01705             
01706       // match agt_type?
01707       if (ast->children.size() > 1) {
01708         RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
01709                 idc_type, currLB, flags);
01710       }
01711 
01712       break;
01713     }
01714 
01715   case at_tvlist:
01716     {
01717       // match agt_tvar*
01718       for (size_t c = 0; c < ast->children.size(); c++)
01719         RESOLVE(ast->child(c), env, lamLevel, mode, identType, 
01720                 currLB, flags);
01721 
01722       break;
01723     }
01724 
01725   case at_constructors:
01726     // match at_constructor+
01727     { 
01728       std::string ifName="";
01729       bool varConst = false;
01730       
01731       // No problem with usesel here. select cannot appear in
01732       // this context.
01733       if (ast->child(0)->child(0)->astType == at_usesel) {
01734         ifName = ast->child(0)->child(0)->child(0)->s;
01735         varConst = true;
01736       }
01737       
01738       // FIX: Isn't this stale now? Aren't constructor names
01739       // now constrained to unqualified idents?
01740       for (size_t c = 0; c < ast->children.size(); c++) {
01741         if (varConst) {
01742           if (ast->child(c)->child(0)->astType != at_usesel ||
01743              ast->child(c)->child(0)->child(0)->s != ifName) {
01744             errStream << ast->child(c)->child(0)->loc << ": "
01745                       << " All Constructors of a Union declaration must "
01746                       << "belong to the same interface "
01747                       << std::endl;
01748             errorFree = false;
01749           }
01750         }
01751         else {
01752           if (ast->child(c)->child(0)->astType == at_usesel) {
01753             errStream << ast->child(c)->child(0)->loc << ": "
01754                       << " All Constructors of a Union declaration must "
01755                       << "belong to the same compilation Unit "
01756                       << std::endl;
01757             errorFree = false;
01758           }
01759         }
01760         
01761         RESOLVE(ast->child(c), env, lamLevel, NULL_MODE, identType, 
01762                 currLB, flags);
01763       }
01764       break;
01765     }
01766 
01767   case at_constructor:
01768     {
01769       // match at_ident
01770       IdentType it = ((ast->children.size() > 1) ? 
01771                       id_ucon : id_ucon0);
01772       
01773       RESOLVE(ast->child(0), env, lamLevel, DEF_MODE,
01774               it, currLB, flags | RSLV_BIND_PUBLIC);
01775             
01776       pair< set<string>::iterator, bool > pr;
01777       set<string> names;
01778 
01779       // Resolve each field name, test for collisions:
01780 
01781       for (size_t c = 1; c < ast->children.size(); c++) {
01782         shared_ptr<AST> fld = ast->child(c);
01783         RESOLVE(fld, env, lamLevel, USE_MODE, identType,
01784                 currLB, flags); 
01785 
01786         if (fld->astType != at_field)
01787           continue;
01788         
01789         pr = names.insert(fld->child(0)->s);
01790         if (!pr.second) {
01791           errStream << ast->loc << ": "
01792                     << "Duplicate field label: "
01793                     << fld->child(0)->s
01794                     << std::endl;
01795           errorFree = false;
01796         }
01797       }
01798       break;
01799     }
01800 
01801   case at_fields:
01802     {
01803       // match at_field*
01804 
01805       // Resolve each field and method name, test for collisions:
01806       pair< set<string>::iterator, bool > pr;
01807       set<string> names;
01808 
01809       for (size_t c = 0; c < ast->children.size(); c++) {
01810         shared_ptr<AST> fld = ast->child(c);
01811         RESOLVE(fld, env, lamLevel, USE_MODE, identType,
01812                 currLB, flags); 
01813 
01814         if (fld->astType == at_fill)
01815           // This entry has no name.
01816           continue;
01817         
01818         pr = names.insert(fld->child(0)->s);
01819         if (!pr.second) {
01820           errStream << ast->loc << ": "
01821                     << "Duplicate field/method name: "
01822                     << fld->child(0)->s
01823                     << std::endl;
01824           errorFree = false;
01825         }
01826       }
01827       break;
01828     }
01829 
01830   case at_field:
01831   case at_methdecl:
01832     {
01833       // match at_ident
01834       ast->child(0)->fqn = FQName(FQ_NOIF, ast->child(0)->s);
01835 
01836       // match agt_type:
01837       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
01838               idc_type, currLB, 
01839               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01840 
01841       break;
01842     }
01843 
01844   case at_fill:
01845     {
01846       // match agt_type?
01847       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01848               idc_type, currLB, 
01849               flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01850 
01851       if(ast->children.size() == 2)
01852         RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
01853                 idc_type, currLB, 
01854                 flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
01855       
01856       break;
01857     }
01858 
01859   case at_bitfieldType:
01860     {
01861       // match at_type
01862       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01863               idc_type, currLB, flags);
01864 
01865       // match at_intLiteral
01866       RESOLVE(ast->child(1), env, lamLevel, NULL_MODE, 
01867               identType, currLB,  
01868               flags & (~RSLV_INCOMPLETE_OK));
01869       break;
01870     }
01871 
01872   case at_arrayRefType:
01873   case at_byRefType:
01874     {
01875       // match agt_type
01876       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01877               idc_type, currLB, 
01878               flags | (RSLV_INCOMPLETE_OK));
01879       break;
01880     }
01881 
01882   case at_boxedType:
01883     {
01884       // match agt_type
01885       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01886               idc_type, currLB, 
01887               flags | (RSLV_INCOMPLETE_OK));
01888       break;
01889     }
01890 
01891   case at_unboxedType:
01892     {
01893       // match agt_type
01894       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01895               idc_type, currLB, 
01896               flags & (~RSLV_INCOMPLETE_OK));
01897 
01898       break;
01899     }
01900 
01901   case at_methType:
01902   case at_fn:
01903     {
01904       // match agt_type
01905       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01906               idc_type, currLB, flags);
01907 
01908       // match agt_type
01909       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
01910               idc_type, currLB, flags);
01911     
01912       break;
01913     }
01914 
01915   case at_fnargVec:
01916     {
01917       // match agt_type*
01918       for (size_t c = 0; c < ast->children.size(); c++)
01919         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
01920                 idc_type, currLB, flags);
01921 
01922       break;
01923     }
01924 
01925 
01926   case at_primaryType:
01927   case at_fieldType:
01928     {
01929       break;
01930     }
01931 
01932   case at_arrayType:
01933     {
01934       // match agt_type
01935       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01936               idc_type, currLB, flags);
01937 
01938       // match at_intLiteral
01939       RESOLVE(ast->child(1), env, lamLevel, NULL_MODE, identType,
01940               currLB, flags); 
01941       if (ast->child(1)->litValue.i < 0) {
01942         errStream << ast->child(1)->loc << ": "
01943                   << "Array index cannot be negative." 
01944                   << std::endl;
01945         errorFree = false;
01946       }
01947 
01948       break;
01949     }
01950 
01951   case at_vectorType:
01952     {
01953       // match agt_type
01954       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01955               idc_type, currLB, flags);
01956 
01957       // match at_intLiteral?
01958       if (ast->children.size() > 1) {
01959         RESOLVE(ast->child(1), env, lamLevel, NULL_MODE, identType,
01960                 currLB, flags); 
01961       }
01962 
01963       break;
01964     }
01965 
01966   case at_exceptionType:
01967     {
01968       break;
01969     }
01970 
01971   case at_dummyType:
01972     {
01973       break;
01974     }
01975 
01976   case at_mutableType:
01977   case at_constType:
01978     {
01979       // match agt_type
01980       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01981               idc_type, currLB, flags);
01982 
01983       break;
01984     }
01985 
01986   case at_typeapp:
01987     {
01988       // match agt_var agt_tvar+
01989       for (size_t c = 0; c < ast->children.size(); c++)
01990         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
01991                 idc_type, currLB, flags);
01992 
01993       break;
01994     }
01995 
01996   case at_qualType:
01997     {
01998       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
01999               idc_type, currLB, flags);      
02000       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02001               idc_type, currLB, flags);      
02002       break;
02003     }
02004 
02005   case at_constraints:
02006     {
02007       for (size_t c=0; c < ast->children.size(); c++)
02008         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
02009                 idc_type, currLB, flags);
02010       break;
02011     }    
02012     
02013   case at_identPattern:
02014     {
02015       // match agt_var
02016       RESOLVE(ast->child(0), env, lamLevel, mode, identType,
02017               currLB, flags); 
02018       
02019       // Type Qualifications ONLY in Binding Patterns
02020       // match agt_type?
02021       if (ast->children.size() > 1) {
02022         RESOLVE(ast->child(1), env, lamLevel, USE_MODE, idc_type,
02023                 currLB, flags); 
02024       }
02025     
02026       break;
02027     }
02028 
02029   case at_mixfix:
02030     {
02031       // First process the elements:
02032       for (size_t c = 0; c < ast->children.size(); c++)
02033         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, idc_value,
02034                 currLB, flags);
02035 
02036 
02037       // Now do the mixfix conversion:
02038       if (errorFree) {
02039         shared_ptr<AST> tree = ProcessMixFix(errStream, ast);
02040 
02041         if (tree) {
02042           // If we got back an at_apply node, we need to run the
02043           // resolver on the leading child, because that was inserted
02044           // by the mixfix converter and has not been resolved.
02045           //
02046           // Since it's harmless, we do this by re-running the
02047           // resolver on the resulting node so that the fixups for
02048           // builtins get run as well.
02049           if (tree->astType == at_apply)
02050             RESOLVE(tree, env, lamLevel, USE_MODE, 
02051                     idc_apply, currLB, flags);        
02052 
02053           // Finally, clobber the at_mixfix node in-place with the
02054           // processed result:
02055           REWRITE_AST_IN_PLACE(ast, tree);
02056         }
02057         else {
02058           // Mixfix layer parse error
02059           errorFree = false;
02060         }
02061       }
02062 
02063       break;
02064     }
02065 
02066   case at_typeAnnotation:
02067     {
02068       // match agt_eform
02069       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02070               idc_value, currLB, flags);
02071 
02072       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02073               idc_type, currLB, flags);
02074     
02075       break;
02076     }
02077 
02078   case at_suspend:
02079     {
02080       // match agt_var
02081       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02082               idc_value, currLB, flags);
02083       // match agt_eform
02084       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02085               idc_value, currLB, flags);
02086       break;
02087     }
02088 
02089   case at_unit:
02090     {
02091       break;
02092     }
02093 
02094   case at_allocREF:
02095     {
02096       // match at_type, at_fn+
02097       for (size_t c = 0; c < ast->children.size(); c++)
02098         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
02099                 idc_type, currLB, flags);
02100       break;
02101     }
02102 
02103   case at_mkClosure:
02104     {
02105       // match at_type, at_fn+
02106       for (size_t c = 0; c < ast->children.size(); c++)
02107         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
02108                 idc_value, currLB, 
02109                 flags | RSLV_INCOMPLETE_OK);
02110       break;
02111     }
02112 
02113   case at_mkArrayRef:
02114     {
02115       // match at_expr
02116       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02117               idc_value, currLB, flags);
02118       break;
02119     }
02120 
02121   case at_copyREF:
02122   case at_setClosure:
02123     {
02124       // match at_type, at_fn+
02125       for (size_t c = 0; c < ast->children.size(); c++)
02126         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
02127                 id_value, currLB, flags);
02128       break;
02129     }
02130     
02131 
02132   case at_MakeVector:
02133     {
02134       // match agt_expr
02135       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02136               idc_value, currLB, flags);
02137 
02138       // match agt_expr
02139       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02140               idc_value, currLB, flags);
02141 
02142       break;
02143     }
02144 
02145   case at_array:
02146   case at_vector:
02147     {
02148       // match agt_expr+
02149       for (size_t c = 0; c < ast->children.size(); c++)
02150         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, idc_value,
02151                 currLB, flags); 
02152 
02153       break;
02154     }
02155 
02156   case at_begin:
02157     {
02158       // match agt_expr*
02159       for (size_t c = 0; c < ast->children.size(); c++)
02160         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, idc_value,
02161                 currLB, flags);
02162 
02163       break;
02164     }
02165     
02166   case at_labeledBlock:
02167     {
02168       RESOLVE(ast->child(0), env, lamLevel, DEF_MODE,
02169               id_block, currLB, flags);
02170       // I suspect that LABEL needs to be treated as a let boundary,
02171       // in the sense that definitions within label must not float 
02172       // outside it. Given this, is currLB correct?
02173       RESOLVE(ast->child(1), env, lamLevel, USE_MODE,
02174               idc_value, currLB, flags);
02175       break;
02176     }
02177 
02178   case at_return_from:
02179     {
02180       RESOLVE(ast->child(0), env, lamLevel, USE_MODE,
02181               id_block, currLB, flags);
02182       RESOLVE(ast->child(1), env, lamLevel, USE_MODE,
02183               idc_value, currLB, flags);
02184       break;
02185     }
02186 
02187   case at_fqCtr:
02188     {
02189       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02190               idc_type, currLB, flags);
02191      
02192       // Second Component handled by the type checker
02193       break;
02194     }
02195     
02196   case at_sel_ctr:
02197     {
02198       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02199               idc_value, currLB, flags );
02200 
02201       // Second Component handled by the type checker
02202       break;
02203     }
02204 
02205   case at_select:
02206     {
02207       // match agt_expr
02208       shared_ptr<AST> lhs = ast->child(0);
02209       
02210       // CAREFUL: this might be a usesel
02211       if (lhs->astType == at_ident || lhs->astType == at_usesel) {
02212         // Strictly speaking, RSLV_SWITCHED_ID_OK should only be
02213         // passed if the lhs->astType is at_ident. It is harmless here
02214         // because if lhs->astType is at_usesel, we know by
02215         // construction that the LHS cannot possibly be a switched ID,
02216         // so the resolver cannot return a boogered answer in that
02217         // case.
02218         
02219         RESOLVE(lhs, env, lamLevel, USE_MODE, identType, currLB, 
02220                 flags | RSLV_NO_CHK_USE_TYPE | RSLV_SWITCHED_ID_OK);
02221         
02222         // If ast->child(0) was an at_usesel, now it would have
02223         // turned into at_ident.
02224         if (lhs->isIdentType(id_interface)) {
02225           ast->astType = at_usesel;
02226           // Recursively call RESOLVE on ourselves to process the
02227           // at_usesel
02228           RESOLVE(ast, env, lamLevel, USE_MODE, identType, currLB, flags);
02229         } 
02230         else if (lhs->isIdentType(id_union)) {
02231           // This is UNIONNAME.LEGNAME.
02232           ast->astType = at_fqCtr;
02233           RESOLVE(ast, env, lamLevel, USE_MODE, idc_type, currLB, flags);
02234         }
02235         else if (!lhs->isIdentType(id_value)) {
02236           errStream << lhs->loc 
02237                     << ": Identifier "
02238                     << " `" << lhs->s << "'" 
02239                     << " is undefined." << std::endl;
02240           errorFree = false;
02241           break;
02242         }
02243       }
02244       else {
02245         RESOLVE(lhs, env, lamLevel, USE_MODE, idc_value, currLB, flags);
02246       }
02247       
02248       // match at_ident
02249       // This cannot be resolved. Defer to typing
02250       // RESOLVE(ast->child(1), ast->child(0)->subEnv, lamLevel, 
02251       // USE_MODE, id_field, flags);
02252     
02253       break;
02254     }
02255 
02256 #ifdef HAVE_INDEXABLE_LENGTH_OPS
02257   case at_array_length:
02258   case at_array_ref_length:
02259   case at_vector_length:
02260     {
02261       // match agt_expr
02262       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02263               id_value, currLB, flags);
02264 
02265       break;
02266     }
02267 #endif
02268 
02269   case at_nth:
02270   case at_array_nth:
02271   case at_array_ref_nth:
02272   case at_vector_nth:
02273     {
02274       // match agt_expr
02275       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02276               id_value, currLB, flags);
02277 
02278       // match agt_expr
02279       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02280               id_value, currLB, flags);
02281 
02282       break;
02283     }
02284 
02285   case at_lambda:
02286     {
02287       shared_ptr<ASTEnvironment > lamEnv = env->newScope();
02288       ast->envs.env = lamEnv;
02289 
02290       // match agt_bindingPatterns
02291       shared_ptr<AST> argVec = ast->child(0);
02292       for (size_t c = 0; c < argVec->children.size(); c++) {
02293         RESOLVE(argVec->child(c), lamEnv, lamEnv, DEF_MODE, 
02294                 id_value, currLB, flags);
02295         shared_ptr<AST> id = argVec->child(c)->child(0);
02296         lamEnv->setFlags(id->s, BF_COMPLETE);
02297       }
02298       
02299       // match agt_expr
02300       RESOLVE(ast->child(1), lamEnv, lamEnv, USE_MODE, 
02301               idc_value, currLB, 
02302               flags | (RSLV_INCOMPLETE_OK));
02303       break;
02304     }
02305 
02306   case at_argVec:
02307     {
02308       assert(false);
02309       break;
02310     }
02311     
02312   case at_struct_apply:
02313   case at_object_apply:
02314   case at_ucon_apply: 
02315   case at_apply:
02316     {
02317       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02318               idc_apply, currLB, flags);        
02319       
02320       for (size_t c = 1; c < ast->children.size(); c++)
02321         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
02322                 idc_value, currLB, flags);
02323 
02324       // Special-case fixup for AND and OR:
02325       if (ast->child(0)->s == "and") {
02326         shared_ptr<AST> node = 
02327           AST::make(at_and, ast->loc, ast->child(1), ast->child(2));
02328 
02329         REWRITE_AST_IN_PLACE(ast, node);
02330       }
02331       else if (ast->child(0)->s == "or") {
02332         shared_ptr<AST> node = 
02333           AST::make(at_and, ast->loc, ast->child(1), ast->child(2));
02334 
02335         REWRITE_AST_IN_PLACE(ast, node);
02336       }
02337 
02338       break;
02339     }
02340 
02341   case at_if:
02342     {
02343       // match agt_expr
02344       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02345               idc_value, currLB, flags);
02346 
02347       // match agt_expr
02348       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02349               idc_value, currLB, flags);
02350 
02351       // match agt_expr
02352       RESOLVE(ast->child(2), env, lamLevel, USE_MODE,
02353               idc_value, currLB, flags);
02354 
02355       break;
02356     }
02357 
02358   case at_when:
02359   case at_unless:
02360   case at_and:
02361   case at_or:
02362     {
02363       // match agt_expr+
02364       for (size_t c = 0; c < ast->children.size(); c++)
02365         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
02366                 idc_value, currLB, flags);
02367 
02368       break;
02369     }
02370 
02371   case at_cond:
02372     {
02373       // match at_cond_legs
02374       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02375               idc_value, currLB, flags);
02376 
02377       //match at_condelse
02378       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02379               idc_value, currLB, flags);
02380       break;
02381     }
02382 
02383   case at_cond_legs:
02384     {
02385       // match at_cond_leg+
02386       for (size_t c = 0; c < ast->children.size(); c++)
02387         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
02388                 idc_value, currLB, flags);
02389 
02390       break;
02391     }
02392 
02393   case at_cond_leg:
02394     {
02395       // match agt_expr
02396       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02397               idc_value, currLB, flags);
02398   
02399       // match agt_expr
02400       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02401               idc_value, currLB, flags);
02402 
02403       break;
02404     }
02405 
02406   case at_condelse:
02407     {
02408       // match agt_expr
02409       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02410               idc_value, currLB, flags);
02411       break;
02412     }
02413 
02414   case at_setbang:
02415     {
02416       shared_ptr<AST> lhs = ast->child(0);
02417       shared_ptr<AST> rhs = ast->child(1);
02418 
02419       // match agt_expr
02420       RESOLVE(lhs, env, lamLevel, USE_MODE, id_value, currLB, flags); 
02421 
02422       // match agt_expr
02423       RESOLVE(rhs, env, lamLevel, USE_MODE, idc_value, currLB, flags);
02424 
02425       if (lhs->astType == at_ident)
02426         if ((lhs->symbolDef->flags & ID_MUT_CLOSED) == 0)
02427           lhs->symbolDef->flags |= ID_IS_MUTATED;
02428 
02429       break;
02430     }
02431 
02432   case at_sizeof:
02433   case at_bitsizeof:
02434     {
02435       // match agt_type
02436 
02437       // The type must be complete, because otherwise we can get
02438       // cyclically self-referencing types.
02439       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02440               idc_type, currLB, 
02441               flags | (~RSLV_INCOMPLETE_OK));
02442       break;      
02443     }    
02444 
02445   case at_dup:
02446     {
02447       // match agt_expr
02448       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02449               idc_value, currLB, flags);
02450       break;      
02451     }    
02452 
02453   case at_deref:
02454     {
02455       // match agt_expr
02456       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02457               id_value, currLB, flags);
02458 
02459       break;
02460     }
02461 
02462   case at_inner_ref:
02463     {
02464       // match agt_expr
02465       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02466               idc_value, currLB, flags);
02467 
02468       if (((ast->flags & INNER_REF_NDX) == 0) &&
02469          ast->child(1)->astType == at_ident) {
02470         // Could be a field-select
02471       }
02472       else {
02473         // match agt_expr
02474         RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02475                 id_value, currLB, flags);
02476       }
02477       break;
02478     }
02479 
02480   case at_uswitch:
02481     {
02482       // match at at_ident: ignore
02483 
02484       // match at agt_expr
02485       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02486               idc_value, currLB, flags);    
02487       
02488       // match at_case_legs or at_usw_legs
02489       RESOLVE(ast->child(2), env, lamLevel, USE_MODE, 
02490               idc_value, currLB, flags);
02491 
02492       // match at_otherwise (agt_ow)
02493       if (ast->child(3)->astType != at_Null) 
02494         RESOLVE(ast->child(3), env, lamLevel, USE_MODE, 
02495                 idc_value, currLB, flags);
02496 
02497       break;
02498     }
02499 
02500   case at_usw_legs:
02501     {
02502       // match at_case_leg+ or at_usw_leg+
02503       for (size_t c = 0; c < ast->children.size(); c++)
02504         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
02505                 idc_value, currLB, flags);
02506 
02507       break;
02508     }
02509 
02510   case at_usw_leg:
02511   case at_otherwise:
02512     {
02513       shared_ptr<ASTEnvironment > legEnv = env->newScope();
02514       ast->envs.env = legEnv;
02515 
02516       /* match at_ident -- the contents after cracking the constructor */
02517       RESOLVE(ast->child(0), legEnv, lamLevel, DEF_MODE, 
02518               id_value, currLB, flags);
02519       ASTEnvironment::iterator itr = legEnv->find(ast->child(0)->s);
02520       assert(itr != legEnv->end());
02521       itr->second->flags |= BF_COMPLETE;
02522 
02523       if (ast->astType == at_usw_leg)
02524         ast->child(0)->flags |= ID_FOR_USWITCH;
02525 
02526       /* match at_expr */
02527       if ((flags & RSLV_WITHIN_CATCH) && (ast->children.size() > 3))
02528         flags |= RSLV_WITHIN_CATCH_MC;
02529         
02530       RESOLVE(ast->child(1), legEnv, lamLevel, USE_MODE, 
02531               idc_value, currLB, flags);
02532 
02533       /* match at_ident -- the constructors (if any) */
02534       for (size_t c=2; c < ast->children.size(); c++)
02535         RESOLVE(ast->child(c), legEnv, lamLevel, USE_MODE, 
02536                 idc_uctor, currLB, flags);      
02537       
02538       break;
02539     }
02540 
02541   case at_try:
02542     {
02543       // match agt_expr
02544       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02545               id_value, currLB, flags);
02546     
02547       // match_at_ident: ignore
02548 
02549       // match at_case_legs
02550       RESOLVE(ast->child(2), env, lamLevel, USE_MODE, 
02551               idc_value, currLB, flags | RSLV_WITHIN_CATCH);
02552 
02553       // match at_otherwise
02554       if (ast->child(3)->astType != at_Null) 
02555         RESOLVE(ast->child(3), env, lamLevel, USE_MODE, 
02556                 idc_value, currLB, flags | RSLV_WITHIN_CATCH);
02557       break;
02558     }
02559 
02560   case at_throw:
02561     {
02562       ResolverFlags rf = flags;
02563 
02564       if (ast->child(0)->astType == at_ident)
02565         rf |= RSLV_SWITCHED_ID_OK;
02566 
02567       // match agt_expr
02568       RESOLVE(ast->child(0), env, lamLevel, USE_MODE, 
02569               idc_value, currLB, 
02570               rf);
02571       break;
02572     }
02573 
02574   case at_container:
02575     {
02576       RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02577               idc_value, currLB, 
02578               flags);      
02579       break;
02580     }
02581 
02582   case at_loop:
02583     {
02584       // NOTE: Do is re-written in the parser
02585       shared_ptr<ASTEnvironment > loopEnv = env->newScope();
02586       ast->envs.env = loopEnv;
02587 
02588       shared_ptr<AST> lbs = ast->child(0);
02589       
02590       // match at_loopbindings
02591       // First process the initializers.
02592       for (size_t c = 0; c < lbs->children.size(); c++) {
02593         shared_ptr<AST> lb = lbs->child(c);        
02594         shared_ptr<AST> init = lb->child(1);
02595         RESOLVE(init, loopEnv, lamLevel, USE_MODE, idc_value, 
02596                 currLB, flags);
02597       }
02598             
02599       // First add the definitions.
02600       for (size_t c = 0; c < lbs->children.size(); c++) {
02601         shared_ptr<AST> lb = lbs->child(c);        
02602         shared_ptr<AST> localDef = lb->child(0);
02603         //shared_ptr<AST> init = lb->child(1);
02604         RESOLVE(localDef, loopEnv, lamLevel, DEF_MODE, 
02605                 id_value, currLB, flags);        
02606       }
02607 
02608       // Make them complete
02609       markComplete(loopEnv);
02610       
02611       // Then process all the next step initializers
02612       for (size_t c = 0; c < lbs->children.size(); c++) {
02613         shared_ptr<AST> lb = lbs->child(c);        
02614         shared_ptr<AST> step = lb->child(2);
02615         RESOLVE(step, loopEnv, lamLevel, USE_MODE, 
02616                 idc_value, currLB, flags);        
02617       }
02618       
02619       // Process the condition/result
02620       // match at_looptest
02621       RESOLVE(ast->child(1), loopEnv, lamLevel, USE_MODE, 
02622               idc_value, currLB, flags);      
02623       
02624       // And finally process the body with a rich environment
02625       // match agt_expr, with my Parent's Incompleteness restrictions
02626       RESOLVE(ast->child(2), loopEnv, lamLevel, USE_MODE, 
02627               idc_value, currLB, flags);    
02628       break;
02629     }
02630     
02631   case at_looptest:
02632     {
02633       for (size_t c = 0; c < ast->children.size(); c++)
02634         RESOLVE(ast->child(c), env, lamLevel, USE_MODE, 
02635                 idc_value, currLB, flags);
02636       break;
02637     }
02638 
02639   case at_let:
02640     {
02641       // match at_letbindings
02642 
02643       // RESOLVE(ast->child(0), env, lamLevel, NULL_MODE, 
02644       //         identType, currLB,  flags);
02645       // Handle let bindings with care.
02646 
02647       shared_ptr<ASTEnvironment > letEnv = env->newScope();
02648       shared_ptr<AST> lbs = ast->child(0);
02649       lbs->parentLB = currLB;
02650 
02651       ast->envs.env = letEnv;
02652       lbs->envs.env = letEnv;
02653 
02654       // Begin processing let-bindings
02655       lbs->flags &= ~LBS_PROCESSED;
02656 
02657       // First Evaluate ALL the Expressions, then bind the values
02658       // match agt_expr
02659       // For each individual binding // match at_letbinding+
02660       for (size_t c = 0; c < lbs->children.size(); c++) {
02661         shared_ptr<AST> lb = lbs->child(c);
02662         
02663         RESOLVE(lb->child(1), letEnv, lamLevel, USE_MODE, 
02664                 idc_value, lbs, flags);
02665       }      
02666       
02667       // match agt_bindingPattern
02668       // For each individual binding // match at_letbinding+
02669       for (size_t c = 0; c < lbs->children.size(); c++) {
02670         shared_ptr<AST> lb = lbs->child(c);
02671         
02672         // match agt_bindingPattern
02673         RESOLVE(lb->child(0), letEnv, lamLevel, DEF_MODE, 
02674                 id_value, lbs, flags);
02675 
02676         assert(lb->child(0)->astType == at_identPattern);
02677         lb->child(0)->child(0)->flags &= ~ID_IS_MUTATED;
02678       }
02679 
02680       // Now we are done with all let-bindings
02681       lbs->flags |= LBS_PROCESSED;
02682        
02683       // Evaluate the final Expression with a rich environment
02684       // match agt_expr, with my Parent's Incompleteness restrictions
02685       markComplete(letEnv);
02686       RESOLVE(ast->child(1), letEnv, lamLevel, USE_MODE, 
02687               idc_value, currLB, flags);
02688     
02689       // match at_constraints
02690       RESOLVE(ast->child(2), letEnv, lamLevel, USE_MODE, 
02691               idc_type, currLB,  flags & (~RSLV_NEW_TV_OK) & (~RSLV_INCOMPLETE_OK));
02692       break;
02693     }
02694 
02695   case at_letStar:
02696     {
02697       // match at_letbindings
02698 
02699       // Handle let bindings with care.
02700       shared_ptr<ASTEnvironment > letEnv = env->newScope();
02701       shared_ptr<AST> lbs = ast->child(0);
02702       lbs->parentLB = currLB;
02703 
02704       ast->envs.env = letEnv;
02705       lbs->envs.env = letEnv;
02706 
02707       
02708       // Begin processing let-bindings
02709       lbs->flags &= ~LBS_PROCESSED;
02710 
02711       // First Evaluate the Expressions, then bind the values
02712       // individually
02713       // match agt_expr
02714       // For each individual binding // match at_letbinding+
02715       for (size_t c = 0; c < lbs->children.size(); c++) {
02716         shared_ptr<AST> lb = lbs->child(c);
02717         
02718         RESOLVE(lb->child(1), letEnv, lamLevel, USE_MODE, 
02719                 idc_value, lbs, flags);
02720         
02721         RESOLVE(lb->child(0), letEnv, lamLevel, DEF_MODE, 
02722                 id_value, lbs, flags);
02723         assert(lb->child(0)->astType == at_identPattern);
02724         lb->child(0)->child(0)->flags &= ~ID_IS_MUTATED;
02725         
02726         ASTEnvironment::iterator itr = 
02727           letEnv->find(lb->child(0)->child(0)->s);
02728         itr->second->flags |= BF_COMPLETE;
02729       }
02730 
02731       // Now we are done with all let-bindings
02732       lbs->flags |= LBS_PROCESSED;
02733       
02734       // Evaluate the final Expression with a rich environment
02735       RESOLVE(ast->child(1), letEnv, lamLevel, USE_MODE, 
02736               idc_value, currLB, flags);
02737       
02738       break;
02739     }
02740 
02741   case at_letrec:
02742     {
02743       // match at_letbindings
02744 
02745       // RESOLVE(ast->child(0), env, lamLevel, NULL_MODE,
02746       // identType, currLB, 
02747       // incomplete, boundVars, flags);
02748       // Handle let bindings with care.
02749 
02750       // First bind, then evaluate.
02751       
02752       shared_ptr<ASTEnvironment > letEnv = env->newScope();
02753       shared_ptr<AST> lbs = ast->child(0);
02754       lbs->parentLB = currLB;
02755 
02756       ast->envs.env = letEnv;
02757       lbs->envs.env = letEnv;      
02758 
02759       // Begin processing let-bindings
02760       lbs->flags &= ~LBS_PROCESSED;
02761 
02762       // For each individual binding // match at_letbinding+
02763       for (size_t c = 0; c < lbs->children.size(); c++) {
02764         shared_ptr<AST> lb = lbs->child(c);
02765       
02766         // match agt_bindingPattern
02767         RESOLVE(lb->child(0), letEnv, lamLevel, DEF_MODE, 
02768                 id_value, lbs, flags);        
02769         assert(lb->child(0)->astType == at_identPattern);
02770         lb->child(0)->child(0)->flags &= ~ID_IS_MUTATED;
02771       }      
02772     
02773       // For each individual binding // match at_letbinding+
02774       for (size_t c = 0; c < lbs->children.size(); c++) {
02775         shared_ptr<AST> lb = lbs->child(c);
02776 
02777         // match agt_expr
02778         RESOLVE(lb->child(1), letEnv, lamLevel, USE_MODE, 
02779                 idc_value, lbs, flags);
02780         
02781       }
02782 
02783       // Now we are done with all let-bindings
02784       lbs->flags |= LBS_PROCESSED;
02785 
02786 
02787       // Evaluate the final Expression with a rich environment, 
02788       // with my Parent's Incompleteness restrictions
02789       // match agt_expr
02790       markComplete(letEnv);
02791       RESOLVE(ast->child(1), letEnv, lamLevel, USE_MODE, 
02792               idc_value, currLB, flags);
02793 
02794       break;
02795     }
02796 
02797     // CAREFUL: CAREFUL:    
02798     //
02799     // This is *NOT* dead code, though, it appears to be so, from the
02800     // way the above let-cases are written.  this case is used by the
02801     // (new) polyinstantiator to R&T let-binding instantiations. It is
02802     // OK to use it there because we don't have any more polymorphism
02803     // at that stage.
02804     //
02805     // THIS CASE MUST NOT BE USED BY OTHER LET FORMS
02806   case at_letbinding:
02807     {
02808       // The lamLevel is bogus here, but OK only for
02809       // the sake of polyinstantiation.      
02810       if (ast->flags & LB_REC_BIND) {
02811         RESOLVE(ast->child(0), env, lamLevel, DEF_MODE, 
02812                 id_value, ast, flags);
02813 
02814         RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02815                 idc_value, ast, flags);        
02816       }        
02817       else {
02818         RESOLVE(ast->child(1), env, lamLevel, USE_MODE, 
02819                 idc_value, ast, flags);
02820         
02821         RESOLVE(ast->child(0), env, lamLevel, DEF_MODE, 
02822                 idc_value, ast, flags);
02823       }
02824 
02825       assert(ast->child(0)->astType == at_identPattern);
02826       ast->child(0)->child(0)->flags &= ~ID_IS_MUTATED;
02827       break;
02828     }
02829   }
02830   return errorFree;
02831 }
02832 
02833 static bool
02834 initEnv(std::ostream& errStream,
02835         shared_ptr<AST> ast,
02836         shared_ptr<ASTEnvironment > aliasEnv,
02837         shared_ptr<ASTEnvironment > env)
02838 {
02839   // See if I am processing the prelude or some other file.
02840   if (ast->astType == at_interface &&
02841      ast->child(0)->s == "bitc.prelude") {
02842     //    cout << "Processing Prelude " << std::endl;   
02843 
02844     return true;
02845   }
02846   
02847   //  cout << "Processing " << ast->child(0)->s << std::endl;
02848   // "use" everything in the prelude
02849   shared_ptr<ASTEnvironment > preenv = GC_NULL;
02850   UocMap::iterator itr = UocInfo::ifList.find("bitc.prelude");
02851   if (itr == UocInfo::ifList.end()) {
02852     errStream << ast->loc << ": "
02853               << "Internal Compiler Error. "
02854               << " Prelude has NOT been processed."
02855               << std::endl;
02856     ::exit(1);
02857   }
02858   preenv = itr->second->env;
02859   
02860   if (!preenv) {
02861     // GCFIX: Why does this return on error instead of exiting? This
02862     // is a FATAL compiler error!
02863     errStream << ast->loc << ": "
02864               << "Internal Compiler Error. "
02865               << " Prelude's environment is NULL "
02866               << std::endl;
02867     ::exit(1);
02868   }
02869   
02870   aliasPublicBindings(std::string(), aliasEnv, preenv, env);
02871   return true;
02872 }
02873 
02874 
02875 bool 
02876 UocInfo::DoResolve(std::ostream& errStream, bool init, 
02877                    ResolverFlags rflags)
02878 {
02879   bool errFree = true;
02880 
02881   if (Options::noPrelude)
02882     rflags |= RSLV_SYM_NO_PRELUDE;
02883   
02884   shared_ptr<ASTEnvironment > aliasEnv = ASTEnvironment::make("*aliases*");
02885 
02886   if (init) {    
02887     if (false) {
02888       assert(env);      
02889       assert(env->parent);
02890       env = env->parent->newDefScope();
02891     }
02892     else {
02893       env = ASTEnvironment::make(uocName);
02894     }      
02895 
02896     if ((rflags & RSLV_SYM_NO_PRELUDE) == 0)
02897       initEnv(std::cerr, uocAst, aliasEnv, env);
02898   }
02899   
02900   CHKERR(errFree, resolve(errStream, uocAst, aliasEnv, env, GC_NULL, 
02901                           USE_MODE, idc_type, GC_NULL, rflags));
02902 
02903   return errFree;
02904 }
02905 
02906 bool 
02907 UocInfo::Resolve(std::ostream& errStream, bool init, 
02908                  ResolverFlags rflags, std::string mesg)
02909 {
02910   bool errFree = true;
02911   errFree = DoResolve(errStream, init, rflags);
02912   if (!errFree)
02913     errStream << mesg
02914               << std::endl;
02915   return errFree;
02916 }
02917 
02918 bool
02919 UocInfo::fe_symresolve(std::ostream& errStream,
02920                        bool init, unsigned long flags)
02921 {
02922   return DoResolve(errStream, init, RSLV_NO_FLAGS);
02923 }
02924 
02925  

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