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
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
00088
00089 case at_vector_nth:
00090 case at_deref:
00091 {
00092
00093
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