DefreprXform.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 
00046 
00047 #include <stdint.h>
00048 #include <stdlib.h>
00049 #include <dirent.h>
00050 #include <fstream>
00051 #include <iostream>
00052 #include <string>
00053 #include <sstream>
00054 #include <errno.h>
00055 #include "Version.hxx"
00056 #include "UocInfo.hxx"
00057 #include "AST.hxx"
00058 #include "Environment.hxx"
00059 #include "inter-pass.hxx"
00060 #include "backend.hxx"
00061 
00062 using namespace boost;
00063 using namespace sherpa;
00064 
00065 shared_ptr<AST>
00066 reprXform(shared_ptr<AST> ast, std::ostream& errStream, bool &errFree)
00067 {
00068   switch(ast->astType) {
00069   case at_defrepr:
00070     {
00071       shared_ptr<AST> unin = AST::make(ast, false);
00072 
00073       unin->astType = at_defunion;
00074       unin->flags |= UNION_IS_REPR;
00075       unin->addChild(ast->child(0)); // identifier
00076       unin->child(0)->flags |= UNION_IS_REPR;
00077       unin->addChild(AST::make(at_tvlist, ast->loc)); // empty tvlist
00078       unin->addChild(ast->child(2));  // category
00079       unin->addChild(reprXform(ast->child(3), errStream, errFree));  // declares
00080       unin->addChild(reprXform(ast->child(4), errStream, errFree)); // constructors
00081       unin->addChild(AST::make(at_constraints, ast->loc)); // constraints
00082       ast = unin;
00083 
00084       break;
00085     }
00086 
00087   case at_reprctrs:
00088     {
00089       shared_ptr<AST> ctrs = AST::make(at_constructors, ast->loc);
00090       for (size_t c=0; c < ast->children.size(); c++)
00091         ctrs->addChild(reprXform(ast->child(c), errStream, errFree));
00092       ast = ctrs;
00093       break;
00094     }
00095 
00096   case at_reprctr:
00097     {
00098       shared_ptr<AST> ctr = ast->child(0);
00099 
00100       for (size_t i=1; i < ast->children.size(); i++) {
00101         shared_ptr<AST> where = ast->child(i);
00102         bool found = false;
00103 
00104         for (size_t j=1; j < ctr->children.size(); j++) {
00105           shared_ptr<AST> fld = ctr->child(j);
00106                 
00107           if (where->child(0)->s == fld->child(0)->s) {
00108             found = true;
00109         
00110             if (fld->flags & FLD_IS_DISCM) {
00111               errStream << where->loc << ": "
00112                         << " Duplicate `where' label for "
00113                         << where->child(0)->s
00114                         << std::endl;
00115         
00116               errFree = false;
00117               break;
00118             }
00119         
00120             fld->flags |= FLD_IS_DISCM;        
00121             fld->unin_discm = (size_t)(where->child(1)->litValue.i.as_uint64());
00122           }
00123         }
00124 
00125         if (!found) {
00126           errStream << where->loc << ": "
00127                     << " Unknown Field: "
00128                     << where->child(0)->s
00129                     << std::endl;
00130         
00131           errFree = false;
00132         }
00133       }
00134 
00135       ast = ctr;
00136       break;
00137     }
00138 
00139   case at_declrepr:
00140     {
00141       shared_ptr<AST> unin = AST::make(ast, false);
00142 
00143       unin->astType = at_declunion;
00144       unin->flags |= UNION_IS_REPR;
00145       unin->addChild(ast->child(0)); // identifier
00146       unin->addChild(AST::make(at_tvlist)); // empty tvlist
00147       unin->addChild(ast->child(1));  // category
00148       unin->addChild(AST::make(at_declares));  // empty declares
00149       unin->addChild(AST::make(at_reprctrs));  // empty repr constructors
00150       unin->addChild(AST::make(at_tvlist, ast->loc)); // constraints
00151       ast = unin;
00152       break;
00153     }
00154 
00155   default:
00156     {
00157       // value definitions are ignored
00158       for (size_t c=0; c < ast->children.size(); c++)
00159         ast->child(c) = reprXform(ast->child(c), errStream, errFree);
00160       break;
00161     }
00162   }
00163   return ast;
00164 }
00165 
00166 bool
00167 UocInfo::fe_reprSimp(std::ostream& errStream,
00168                      bool init, unsigned long flags)
00169 {
00170   bool errFree = true;
00171   uocAst = reprXform(uocAst, errStream, errFree);
00172   return errFree;
00173 }
00174 

Generated on Fri Feb 10 07:59:20 2012 for BitC Compiler by  doxygen 1.4.7