///////////////////////////////////////////////////////////////////// // callsProc.h - Defines processing for Calls program // // ver 1.3 // // // // Language: Visual C++, ver 7.0 // // Platfrom: Dell Dimension 8100, Windows 2000, SP 2.0 // // Application: Prototype for CSE687 Pr#2, Spring 2003 // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////// #include #include "callsProc.h" #include "grammar.h" #include "display.h" //----< initializes callsProc with scanner reference >--------- callsProc::callsProc(scanner &s) : _scanner(s) {} //----< remove <> or "" from include name >-------------------- std::string callsProc::extractFileName(semiExp &se) { size_t i; for(i=0; i-------------------------------------- void display(semiExp& se) { size_t k; for(k=0; k--------------------------------- void processFuncDefs(semiExp &se) { grammar gr(se); typeTable funcTab; std::cout << "\n " /* << gr.context() */ << display::functionName(se); std::set invoked; while(gr.scopeType() == "function") { gr.saveParamsAndTypes(funcTab); se.get(); // read semiExp's to process function grammar(se).processScope(); if(gr.declar()) { gr.saveIdAndType(funcTab); } size_t len = 0; do // find function invocations { len = grammar(se).invocation(len); if(len < se.length()) { invoked.insert(grammar(se).getQualifiedIdentifier(len-1)); ////////////////////////////////////////////////////////////// // replace previous statement with these if you want to see // duplicate calls with all calls in calling order // // std::cout << "\n " // << (grammar(se).getQualifiedIdentifier(len-1)); ++len; } else break; } while(true); } std::set::iterator iter; for(iter=invoked.begin(); iter != invoked.end(); ++iter) std::cout << "\n " << *iter; if(funcTab.size() > 0) { std::cout << "\n - declarations -"; std::cout << funcTab.show(4); } } // //----< define processing done for each file scan >------------ bool callsProc::process(semiExp &se) { std::string name = _scanner.fileName(); while(se.get()) { grammar gr(se); gr.processScope(); if(gr.intoScope()) { if(gr.qualifiedType(gr.scopeType())) classTab.push(gr.scopeName(),gr.scopeType()); } gr.saveType(); if(gr.functionDec()) { gr.saveIdAndType(classFuncsTab); } if(gr.declar()) { if(!gr.functionDec()) gr.saveIdAndType(classDecsTab); } if(gr.include()) { // found a header file, so call recursively if not seen before std::string newName = extractFileName(se); if(headersSeen.find(newName) == headersSeen.end()) { headersSeen.insert(newName); if(_scanner.scan(newName)) { sstr temp = sstr("Processing ") + name + " again"; std::cout << display::title<'='>(temp); } } } else if(gr.functionDef()) processFuncDefs(se); } return true; } // #ifdef TEST_CALLSPROC int main(int argc, char *argv[]) { if(argc==1) { std::cout << "\n please enter names of files or file patterns" << " to process on the command line\n\n"; return 1; } scanner s; callsProc cp(s); s.Register(&cp); for(int i=1; i