NoAllocCheck.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 "Options.hxx"
00050 #include "AST.hxx"
00051 #include "Type.hxx"
00052 #include "inter-pass.hxx"
00053 
00054 using namespace boost;
00055 using namespace sherpa;
00056 
00057 // Return whether the expression performs an allocating operation or not.
00058 static bool
00059 AllocCheck(std::ostream &errStream, shared_ptr<AST> ast)
00060 {
00061   bool errFree = true;
00062 
00063   switch (ast->astType) {
00064   case at_vector:
00065   case at_MakeVector:
00066     errStream << ast->loc << ": "
00067               << "Expression requires dynamic allocation. "
00068               << "Disallowed in NO-GC mode"
00069               << std::endl;
00070     errFree = false;
00071     break;
00072 
00073   case at_struct_apply:
00074   case at_object_apply:
00075   case at_ucon_apply:
00076     if (ast->child(0)->symType->isRefType()) {
00077       errStream << ast->loc << ": "
00078                 << "Expression requires dynamic allocation. "
00079                 << "Disallowed in NO-GC mode"
00080                 << std::endl;
00081       errFree = false;
00082     }
00083     break;
00084     
00085   default:
00086     break;
00087   }
00088   
00089   for (size_t c = 0; c < ast->children.size(); c++)
00090     CHKERR(errFree, AllocCheck(errStream, ast->child(c)));
00091   
00092   return errFree;           
00093 }
00094 
00095 bool
00096 UocInfo::fe_noAllocCheck(std::ostream& errStream, 
00097                          bool init, unsigned long flags)
00098 {
00099   /* This pass only recognizes syntactic structures that perform
00100      memory alocation. The requirement not performing closure
00101      conversion is checked in the clconv pass */
00102 
00103   bool errFree=true;
00104 
00105   if (Options::noAlloc)
00106     CHKERR(errFree, AllocCheck(errStream, uocAst));  
00107   return errFree;
00108 }
00109 

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