LocChk.cxx

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright (C) 2008, Johns Hopkins University.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or
00007  * without modification, are permitted provided that the following
00008  * conditions are met:
00009  *
00010  *   - Redistributions of source code must contain the above 
00011  *     copyright notice, this list of conditions, and the following
00012  *     disclaimer. 
00013  *
00014  *   - Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions, and the following
00016  *     disclaimer in the documentation and/or other materials 
00017  *     provided with the distribution.
00018  *
00019  *   - Neither the names of the copyright holders nor the names of any
00020  *     of any contributors may be used to endorse or promote products
00021  *     derived from this software without specific prior written
00022  *     permission. 
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00027  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00028  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00029  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00030  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00032  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00033  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  **************************************************************************/
00037 
00038 #include <assert.h>
00039 #include <stdint.h>
00040 #include <stdlib.h>
00041 #include <dirent.h>
00042 #include <fstream>
00043 #include <iostream>
00044 #include <string>
00045 #include <sstream>
00046 
00047 #include <libsherpa/UExcept.hxx>
00048 
00049 #include "AST.hxx"
00050 #include "Type.hxx"
00051 #include "inter-pass.hxx"
00052 
00053 using namespace boost;
00054 using namespace sherpa;
00055 
00078 static bool
00079 LocChk(std::ostream &errStream, bool &errFree, shared_ptr<AST> ast, bool inSET)
00080 {
00081   switch (ast->astType) {
00082   case at_ident:
00083     {
00084       return true;
00085     }
00086     
00087     //case at_array:
00088     //case at_vector:
00089   case at_vector_nth:
00090   case at_deref:
00091     {
00092       // Need to recurse because we need to perform the location check
00093       // within the expression that produces the value.
00094       for (size_t c = 0; c < ast->children.size(); c++)
00095         LocChk(errStream, errFree, ast->child(c), false);
00096        
00097       return true;
00098     }
00099 
00100   case at_setbang:
00101     {
00102       bool isLoc = LocChk(errStream, errFree, ast->child(0), true);
00103       LocChk(errStream, errFree, ast->child(1), inSET);
00104 
00105       if (!isLoc) {
00106         errStream << ast->child(0)->loc << ": "
00107                   << "Non-location in set! context"
00108                   << std::endl;
00109         errFree = false;
00110       }
00111 
00112       return false;
00113     }
00114 
00115   case at_array_nth:
00116     {
00117       bool isLoc = LocChk(errStream, errFree, ast->child(0), inSET);
00118       if (inSET && !isLoc) {
00119         errStream << ast->child(0)->loc << ": "
00120                   << "Non-location in set! context"
00121                   << std::endl;
00122         errFree = false;
00123       }
00124 
00125       return true;
00126     }
00127 
00129   case at_fqCtr:
00130     {
00131       return true;
00132     }
00133 
00134   case at_select:
00135     {
00136       bool isLoc = LocChk(errStream, errFree, ast->child(0), inSET);
00137       
00138       if (inSET && !isLoc && !ast->child(0)->symType->isRefType()) {
00139         errStream << ast->child(0)->loc << ": "
00140                   << "Non-location in set! context"
00141                   << std::endl;
00142         errFree = false;
00143       }
00144       
00145       return true;
00146     }
00147 
00148   case at_sel_ctr:
00149     {
00150       LocChk(errStream, errFree, ast->child(0), inSET);
00151       return false;
00152     }
00153 
00154   case at_uswitch:
00155   case at_try:
00156     {
00157       for (size_t c = 0; c < ast->children.size(); c++)
00158         if (c != IGNORE(ast))
00159           LocChk(errStream, errFree, ast->child(c), inSET);
00160       
00161       return false;
00162     }
00163     
00164   default:
00165     {
00166       for (size_t c = 0; c < ast->children.size(); c++)
00167         LocChk(errStream, errFree, ast->child(c), inSET);
00168 
00169       return false;
00170     }
00171   }
00172 }
00173 
00174 bool
00175 UocInfo::fe_locCheck(std::ostream& errStream, 
00176                      bool init, unsigned long flags)
00177 {
00178   bool errFree = true;  
00179   LocChk(errStream, errFree, uocAst, false);  
00180   return errFree;
00181 }
00182 

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