///////////////////////////////////////////////////////////////////// // display.cpp - generates formatted strings from semiExp objects // // ver 1.4 // // // // 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 "display.h" using namespace Scanner; using namespace CodeAnal; //----< pull class::name from CSemiExp >------------------------ std::string display::functionName(CSemiExp &se) { size_t last = se.find("(") - 1; if(last == se.length()) return "error in display::functionName"; size_t first = last; // if this is operator collect operator parens size_t len = se.find("operator"); if(len < se.length()-1) { first = len; if(se[len+1] == "(") last = se.find(")",last+1); else last = se.find("(") - 1; } // if this is a member function collect class name if(first > 0 && se[first-1]=="~") --first; if(first > 1 && se[first-1]=="::") first -= 2; // if this is a template collect complete class name if(se[first] == ">") { while(first != 0 && se[first] != "<") --first; // find < --first; // find class name } if(first < 0 || se.length() <= last) return "error in display::functionName"; // ok, now collect std::string temp; for(size_t i=first; i<=last; ++i) temp += se[i]; return temp; } // ///////////////////////////////////////////////////////////////////// // test stub // ///////////////////////////////////////////////////////////////////// #ifdef TEST_DISPLAY #include #include #include "grammar.h" int main(int argc, char* argv[]) { if(argc==1) { std::cout << "\n please enter name of file to process on command line\n\n"; return 1; } std::ifstream in(argv[1]); if(!in.good()) { std::cout << "\n can't read file " << argv[1] << "\n\n"; return 1; } Scanner::CToker toker(&in); toker.registerDefaultFilters(); Scanner::CSemiExp se(&toker); se.registerDefaultFilters(); display d; std::cout << "\n processing file " << argv[1]; std::cout << "\n -----------------" << std::string(strlen(argv[1])+1,'-') << '\n'; while(se.get()) { if(grammar(se).functionDef()) { std::cout << "\n " << (d.functionName(se).c_str()); } } std::cout << "\n\n"; } #endif