00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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));
00076 unin->child(0)->flags |= UNION_IS_REPR;
00077 unin->addChild(AST::make(at_tvlist, ast->loc));
00078 unin->addChild(ast->child(2));
00079 unin->addChild(reprXform(ast->child(3), errStream, errFree));
00080 unin->addChild(reprXform(ast->child(4), errStream, errFree));
00081 unin->addChild(AST::make(at_constraints, ast->loc));
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));
00146 unin->addChild(AST::make(at_tvlist));
00147 unin->addChild(ast->child(1));
00148 unin->addChild(AST::make(at_declares));
00149 unin->addChild(AST::make(at_reprctrs));
00150 unin->addChild(AST::make(at_tvlist, ast->loc));
00151 ast = unin;
00152 break;
00153 }
00154
00155 default:
00156 {
00157
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