ScopeNameUsage(AST* node, ScopeNameUsage* parent, ScopingAnalysis* scoping) : node(node), parent(parent), scoping(scoping), nameForcingNodeImportStar(NULL), nameForcingNodeBareExec(NULL), free(false), child_free(false) { if (node->type == AST_TYPE::ClassDef) { AST_ClassDef* classdef = ast_cast<AST_ClassDef>(node); // classes have an implicit write to "__module__" written.insert(scoping->getInternedStrings().get("__module__")); if (classdef->body.size() && classdef->body[0]->type == AST_TYPE::Expr) { AST_Expr* first_expr = ast_cast<AST_Expr>(classdef->body[0]); if (first_expr->value->type == AST_TYPE::Str) { written.insert(scoping->getInternedStrings().get("__doc__")); } } } if (node->type == AST_TYPE::ClassDef) { private_name = ast_cast<AST_ClassDef>(node)->name; } else if (parent) { private_name = parent->private_name; } else { private_name = llvm::StringRef(); } }
VarScopeType getScopeTypeOfName(InternedString name) override { if (isCompilerCreatedName(name)) return VarScopeType::FAST; else if (forced_globals.find(name) != forced_globals.end()) return VarScopeType::GLOBAL; else return VarScopeType::NAME; }
void DirInstaller::doMovesDeletes(const StrMap &moves, const HashDir &del) { DirMap created; StrSet removed; for(StrMap::const_iterator it = moves.begin(); it != moves.end(); it++) { ptr->owner->moveFile(it->first, it->second); created[it->second] = Hash(); removed.insert(it->first); } for(HashDir::const_iterator it = del.begin(); it != del.end(); it++) { ptr->owner->deleteFile(it->second); removed.insert(it->second); } index.addMany(created, removed); }
void append(const std::string& word) { std::string lower; cybozu::ToLower(lower, word); std::pair<Str2Int::iterator, bool> ret = word2id_.insert(Str2Int::value_type(lower, (int)id2word_.size())); //printf("word=%s, id=%d, ret=%d\n", ret.first->first.c_str(), ret.first->second, ret.second); if (ret.second) { id2word_.push_back(lower); df_.resize(id2word_.size()); } if (set_.insert(word).second) { df_[ret.first->second]++; } }
void append(const std::string& word) { std::string lower; cybozu::ToLower(lower, word); Str2Int::const_iterator i = word2id_.find(lower); if (i == word2id_.end()) return; const int id = i->second; if (curTf_ == 0) { tf_.push_back(Int2Int()); curTf_ = &tf_.back(); } (*curTf_)[id]++; if (set_.insert(lower).second) { df_[id]++; } }
void _doStore(const std::string& name) { if (_loads.count(name)) return; _stores.insert(name); }
void endDoc() { docNum_++; set_.clear(); }
void endDoc() { curTf_ = 0; set_.clear(); }
bool ProcessComponent(const char* comp_name, const string& vc_name, const string& filter_modules, const string& filter_disabled, const string& filter_headers, const char* define) { ProjLines.clear(); ProjAssoc.clear(); int comp_len=strlen(comp_name); char buf[1024]; printf("Processing %s...\n",comp_name); FILE* vc_file=fopen(vc_name.c_str(),"r"); if(!vc_file) { printf("Couldn't open %s for reading.\n",vc_name.c_str()); return false; } BufState=0; while(fgets(buf,1024,vc_file)) { ParseBufVC(buf,filter_modules,filter_disabled,filter_headers); } fclose(vc_file); string script_name=Map["ScriptsDirectory"]; script_name+="scripts.cfg"; FILE* script_file=fopen(script_name.c_str(),"r"); if(!script_file) { printf("Couldn't open %s for reading.\n",script_name.c_str()); return false; } Modules.clear(); DisabledModules.clear(); Headers.clear(); while(fgets(buf,1024,vc_file)) { int pos=0; bool enabled=false; string line(buf); StrVec vec; int tok=strsplit(line,vec); if(!tok) continue; if(!vec[0].compare("@")) { pos++; enabled=true; }; if(tok<pos+3) continue; if(!vec[pos].compare(comp_name) && !vec[pos+1].compare("module")) { if(enabled) Modules.insert(stolower(vec[pos+2]+".fos")); else DisabledModules.insert(stolower(vec[pos+2]+".fos")); } } fclose(script_file); for(StrSet::iterator it=Modules.begin(),end=Modules.end(); it!=end; ++it) { Defines.clear(); Defines.insert(string(define)); IgnoreDepth=0; Depth=0; string name=*it; printf("Preprocessing %s...\n",name.c_str()); int idx=name.find_last_of("/"); string dir=""; if(idx!=-1) { dir=name.substr(0,idx+1); name=name.substr(idx+1,name.length()-idx-1); } if(!RecursiveParse(name,dir)) { printf("Failed to preprocess %s.\n",name.c_str()); return false; } } // write the project file vc_file=fopen(vc_name.c_str(),"w"); if(!vc_file) { printf("Couldn't open %s for writing.\n","test.log"); return false; } for(int i=0,j=ProjLines.size(); i<j; i++) { if(ProjAssoc.count(i)) { string name=ProjAssoc[i]; StrSet* the_set=NULL; if(!name.compare(filter_modules)) the_set=&Modules; else if(!name.compare(filter_disabled)) the_set=&DisabledModules; else if(!name.compare(filter_headers)) { the_set=&Headers; fprintf(vc_file, "\t\t\t<File\n" "\t\t\t\tRelativePath=\".\\intellisense"); if(!strcmp(comp_name,"client")) fprintf(vc_file,"_client"); else if(!strcmp(comp_name,"mapper")) fprintf(vc_file,"_mapper"); fprintf(vc_file,".h\"\n" "\t\t\t\t>\n" "\t\t\t</File>\n"); } for(StrSet::iterator it=the_set->begin(),end=the_set->end(); it!=end; ++it) { fprintf(vc_file, "\t\t\t<File\n" "\t\t\t\tRelativePath=\"%s%s\"\n" "\t\t\t\t>\n" "\t\t\t</File>\n", Map["FilesRelativePath"].c_str(),it->c_str()); } } fprintf(vc_file,"%s",ProjLines[i].c_str()); } fclose(vc_file); printf("Processing %s complete.\n",comp_name); return true; }
bool RecursiveParse(string& file_name, string& dir) { static char buf[4096]; file_name=Map["ScriptsDirectory"]+dir+file_name; FILE* f=fopen(file_name.c_str(),"r"); if(!f) { printf("Couldn't open %s for reading.\n",file_name.c_str()); return false; } while(fgets(buf,4096,f)) { int pre=0; while(buf[pre] && isSpace(buf[pre])) pre++; if(!buf[pre] || buf[pre]!='#') continue; // buf[pre] == '#' int post = pre + 1; while(buf[post] && isSpace(buf[post])) post++; if(!buf[post]) continue; string line(buf); line.erase(pre, post - pre); StrVec vec; strsplit(line,vec); if(!vec[0].compare("define") && !IGNORING) { if(vec.size()<1) continue; // err string def=vec[1]; int pos=def.find("@"); if(pos>=0) def=def.substr(0,pos); Defines.insert(def); continue; } else if(!vec[0].compare("include") && !IGNORING) { if(vec.size()<1) continue; // err string incname=vec[1]; if(incname[0]!='\"' || incname[incname.size()-1]!='\"') continue; incname=stolower(incname.substr(1,incname.size()-2)); int idx=incname.find_last_of("/"); string sdir = dir; if(idx!=-1) { sdir = dir + incname.substr(0,idx+1); incname = incname.substr(idx+1,incname.length()-idx-1); } if(!Headers.count(trimmedName(sdir+incname))) { Headers.insert(trimmedName(sdir+incname)); printf("\tFound new header: '%s'\n",incname.c_str()); } if(!RecursiveParse(incname, sdir)) printf("Ignoring the include file %s.\n", incname.c_str()); continue; } else if(!vec[0].compare("ifdef")) { if(vec.size()<1) continue; // err string def=vec[1]; int pos=def.find("@"); if(pos>=0) def=def.substr(0,pos); if(Defines.count(def)) IgnoreDepth++; Depth++; continue; } else if(!vec[0].compare("ifndef")) { if(vec.size()<1) continue; // err string def=vec[1]; int pos=def.find("@"); if(pos>=0) def=def.substr(0,pos); if(!Defines.count(def)) IgnoreDepth++; Depth++; continue; } else if(!vec[0].compare("endif")) { Depth--; if(Depth<0) Depth=0; // err if(Depth<IgnoreDepth) IgnoreDepth--; } else if(!vec[0].compare("undef") && !IGNORING) { if(vec.size()<1) continue; // err string def=vec[1]; int pos=def.find("@"); if(pos>=0) def=def.substr(0,pos); Defines.erase(def); continue; } } fclose(f); return true; }
bool livestats::refresh_stats(Vtraf_stat_samples &s, reltimes & times) { std::set<std::string> ::iterator devidx,ruleidx,addridx; std::vector<std::string> ::iterator classidx; Vtraf_iterator ia,ib; unsigned int numsamples = s.size(); if(numsamples < 2) { return false; // not enough samples yet } traf_stat_collection_item & last = s[s.size()-1]; traf_stat_collection_item & prev = s[s.size()-2]; std::vector<std::string> range = times.in_range(last.collection_start); // now update timestamp as being the most recent sample // before we update the timestamp check_rollovers(last.collection_end,times); last_update = times.now; // populate our idea of what devs are present etc. ext_devs = last.ext_devs; int_devs = last.int_devs; classes = last.class_indexes_in_order(); rules = last.rules; addresses = last.addresses; // whole interface stats first - external incomming for (devidx = ext_devs.begin(); devidx != ext_devs.end(); devidx++) { refresh_helper(*devidx + "_ext_in", "_inc_total_" + *devidx, "cur_inc_rate_" + *devidx, last, prev, range, s); refresh_helper(*devidx + "_ext_out", "_out_total_" + *devidx, "cur_out_rate_" + *devidx, last, prev, range, s); for (classidx = classes.begin(); classidx != classes.end(); classidx++) { // take a ref to this particular item refresh_helper(*devidx + "_dn_class_" + *classidx, "_inc_total_" + *devidx + "_class_" + *classidx, "cur_inc_rate_" + *devidx + "_class_" + *classidx, last, prev, range, s); refresh_helper(*devidx + "_up_class_" + *classidx, "_out_total_" + *devidx + "_class_" + *classidx, "cur_out_rate_" + *devidx + "_class_" + *classidx, last, prev, range, s); } // and rules for (ruleidx = rules.begin(); ruleidx != rules.end(); ruleidx++) { // take a ref to this particular item refresh_helper(*devidx + "_dn_rule_" + *ruleidx, "_inc_total_" + *devidx + "_rule_" + *ruleidx, "cur_inc_rate_" + *devidx + "_rule_" + *ruleidx , last, prev, range, s); refresh_helper(*devidx + "_up_rule_" + *ruleidx, "_out_total_" + *devidx + "_rule_" + *ruleidx, "cur_out_rate_" + *devidx + "_rule_" + *ruleidx , last, prev, range, s); } } // now internal devs for (devidx = int_devs.begin(); devidx != int_devs.end(); devidx++) { refresh_helper(*devidx + "_int_in", "_inc_total_" + *devidx, "cur_inc_rate_" + *devidx, last, prev, range, s); refresh_helper(*devidx + "_int_out", "_out_total_" + *devidx, "cur_out_rate_" + *devidx, last, prev, range, s); for (classidx = classes.begin(); classidx != classes.end(); classidx++) { // take a ref to this particular item refresh_helper(*devidx + "_dn_class_" + *classidx, "_inc_total_" + *devidx + "_class_" + *classidx, "cur_inc_rate_" + *devidx + "_class_" + *classidx, last, prev, range, s); refresh_helper(*devidx + "_up_class_" + *classidx, "_out_total_" + *devidx + "_class_" + *classidx, "cur_out_rate_" + *devidx + "_class_" + *classidx, last, prev, range, s); } // and rules for (ruleidx = rules.begin(); ruleidx != rules.end(); ruleidx++) { refresh_helper(*devidx + "_dn_rule_" + *ruleidx, "_inc_total_" + *devidx + "_rule_" + *ruleidx, "cur_inc_rate_" + *devidx + "_rule_" + *ruleidx , last, prev, range, s); refresh_helper(*devidx + "_up_rule_" + *ruleidx, "_out_total_" + *devidx + "_rule_" + *ruleidx, "cur_out_rate_" + *devidx + "_rule_" + *ruleidx , last, prev, range, s); } } // now addresses for(addridx = addresses.begin(); addridx != addresses.end(); addridx++) { const std::string &address = *addridx; std::string direction = "(dn)"; std::string addr = "0.0.0.0"; std::string::size_type pos = address.find("("); if(pos != std::string::npos) { direction = address.substr(pos); addr = address.substr(0,pos); } refresh_helper(address, std::string((direction == "(dn)" ? "_inc_total_" : "_out_total_")) + addr, std::string((direction == "(dn)" ? "cur_inc_rate_" : "cur_out_rate_")) + addr, last,prev,range,s); } return true; }
bool livestats::save(FILE *fd, reltimes & times) { // these are the time periods we store data for std::vector<std::string> range = times.all_range(); std::map<std::string,int> ::iterator h; std::map<std::string,bytecount_t> ::iterator i; std::set<std::string> ::iterator devidx,ruleidx, addridx; // classes need to be kept in specific - non sorted order std::vector<std::string> ::iterator classidx; std::set<std::string> ::iterator j; std::map<std::string, int> &nc_current_rates = const_cast<std::map<std::string, int> &>(current_rates); // only do stuff if we have some fresh data to save yet if(nc_current_rates.size() == 0) return false; // lock this file rewind(fd); lockf(fileno(fd), F_LOCK, 0); // timestamp first fprintf(fd,"last_update=%ld\n", last_update.t.tv_sec); // then whole interface stats, only now save for devs that are present - this is a bug, needs to be fixed if(ext_devs.size() > 0) { for(j = ext_devs.begin(); j != ext_devs.end(); j++) { save_rate_helper(fd, "cur_inc_rate_" + *j); save_rate_helper(fd, "cur_out_rate_" + *j); // and for each time period, totals are scaled down to kbytes save_period_helper(fd, "_inc_total_" + *j, range); save_period_helper(fd, "_out_total_" + *j, range); // then class stats for (classidx = classes.begin(); classidx != classes.end(); classidx++) { save_rate_helper(fd, "cur_out_rate_" + *j + "_class_" + *classidx); save_period_helper(fd, "_out_total_" + *j + "_class_" + *classidx, range); save_rate_helper(fd, "cur_inc_rate_" + *j + "_class_" + *classidx); save_period_helper(fd, "_inc_total_" + *j + "_class_" + *classidx, range); } // then rule stats for (ruleidx = rules.begin(); ruleidx != rules.end(); ruleidx++) { save_rate_helper(fd, "cur_out_rate_" + *j + "_rule_" + *ruleidx); save_period_helper(fd, "_out_total_" + *j + "_rule_" + *ruleidx, range); save_rate_helper(fd, "cur_inc_rate_" + *j + "_rule_" + *ruleidx); save_period_helper(fd, "_inc_total_" + *j + "_rule_" + *ruleidx, range); } } // dev loop } // ext devs if(int_devs.size() > 0) { for(j = int_devs.begin(); j != int_devs.end(); j++) { save_rate_helper(fd, "cur_inc_rate_" + *j); save_rate_helper(fd, "cur_out_rate_" + *j); // and for each time period, totals are scaled down to kbytes save_period_helper(fd, "_inc_total_" + *j, range); save_period_helper(fd, "_out_total_" + *j, range); // then class stats for (classidx = classes.begin(); classidx != classes.end(); classidx++) { save_rate_helper(fd, "cur_out_rate_" + *j + "_class_" + *classidx); save_period_helper(fd, "_out_total_" + *j + "_class_" + *classidx, range); save_rate_helper(fd, "cur_inc_rate_" + *j + "_class_" + *classidx); save_period_helper(fd, "_inc_total_" + *j + "_class_" + *classidx, range); } // then rule stats for (ruleidx = rules.begin(); ruleidx != rules.end(); ruleidx++) { save_rate_helper(fd, "cur_out_rate_" + *j + "_rule_" + *ruleidx); save_period_helper(fd, "_out_total_" + *j + "_rule_" + *ruleidx, range); save_rate_helper(fd, "cur_inc_rate_" + *j + "_rule_" + *ruleidx); save_period_helper(fd, "_inc_total_" + *j + "_rule_" + *ruleidx, range); } } } for(addridx = addresses.begin(); addridx != addresses.end(); addridx++) { const std::string & address = *addridx; std::string direction = "(dn)"; std::string addr = "0.0.0.0"; std::string::size_type pos = address.find("("); if(pos != std::string::npos) { direction = address.substr(pos); addr = address.substr(0,pos); } if(direction == "(dn)") { save_rate_helper(fd, "cur_inc_rate_" + addr); save_period_helper(fd, "_inc_total_" + addr, range); } else { save_rate_helper(fd, "cur_out_rate_" + addr); save_period_helper(fd, "_out_total_" + addr, range); } } // truncate the file at this point ftruncate(fileno(fd), ftell(fd)); fflush(fd); // now unlock rewind(fd); lockf(fileno(fd), F_ULOCK, 0); return true; }