void testFuncParser(char *buf) { printf("===== Testing function parser ======\n"); // time_t start = GetTickCount(); FunctionList li; //fflush(stdout); std::map<std::string, std::string> ignoreTokens; get_functions(buf, li, ignoreTokens); // time_t end = GetTickCount(); for (FunctionList::iterator iter = li.begin(); iter != li.end(); iter++) { //test the var parser on the function argument list: clFunction f = (*iter); f.Print(); //testVarParser((char*)f.m_signature.c_str()); printf("%s\n", f.m_name.c_str()); } // printf("total time: %d\n", end-start); printf("matches found: %d\n", li.size()); }
int main(int argc,const char **argv) { int returnVal = 0; g_Logger.Start("gmParser.log", true); LOG("gmParser"); if(argc < 2) { PrintUsage(); ERROR_RETURN; } Timer tme, totaltime; const char *FolderIn = argv[1]; //const char *FolderOut = argv[2]; if(!FileSystem::InitRawFileSystem(FolderIn)) { std::cout << "Unable to Initialize File System." << std::endl; ERROR_RETURN; } if(!FileSystem::Mount(FolderIn,"")) { std::cout << "Unable to Mount Root Folder." << std::endl; ERROR_RETURN; } if(!FileSystem::SetWriteDirectory(fs::path(FolderIn,fs::native))) { std::cout << "Unable to Set Write Folder." << std::endl; ERROR_RETURN; } // find all files to parse tme.Reset(); boost::regex ex("test.*.cpp"); DirectoryList dl; FileSystem::FindAllFiles("",dl,ex,true); std::cout << "Found " << dl.size() << " files in " << tme.GetElapsedSeconds() << " seconds." << std::endl;; // parse files tme.Reset(); typedef std::vector<FileParser> FileParserList; FileParserList parsers; parsers.reserve(dl.size()); for(obuint32 i = 0; i < dl.size(); ++i) { parsers.push_back(FileParser(dl[i].string())); } const int numParsers = parsers.size(); #pragma omp parallel for for(int i = 0; i < numParsers; ++i) { parsers[i].ParseFile(); std::cout << "*"; } std::cout << std::endl; std::cout << "Parsed " << numParsers << " files in " << tme.GetElapsedSeconds() << " seconds." << std::endl; // merge all to a master function list FunctionList allFunctions; allFunctions.reserve(2048); for(obuint32 i = 0; i < (obuint32)numParsers; ++i) { allFunctions.insert(allFunctions.end(),parsers[i].Functions.begin(),parsers[i].Functions.end()); for(obuint32 e = 0; e < parsers[i].Info.size(); ++e) { std::cout << parsers[i].Info[e] << std::endl; } } std::cout << "Found " << allFunctions.size() << " functions..." << std::endl; // write the function bindings out to files. tme.Reset(); const int numFiles = WriteFunctions(allFunctions); std::cout << "Wrote " << numFiles << " files in " << tme.GetElapsedSeconds() << " seconds." << std::endl; std::cout << "Finished in " << totaltime.GetElapsedSeconds() << " seconds." << std::endl; return 0; }
int WriteFunctions(const FunctionList &functions) { // separate the master function list into namespaces OutFileMap fileMap; fileMap.insert(std::make_pair("","Globals")); for(obuint32 i = 0; i < functions.size(); ++i) { OutFileMap::iterator it = fileMap.find(functions[i].ClassName); if(it == fileMap.end()) { OutFileMap::_Pairib ins = fileMap.insert(std::make_pair(functions[i].ClassName,NameSpaces(functions[i].ClassName))); it = ins.first; } it->second.Functions.push_back(functions[i]); } // write out each file. for(OutFileMap::iterator it = fileMap.begin(); it != fileMap.end(); ++it) { File outFile; // write out each function const String FileName = Utils::VA("%s.cpp", it->second.FileName.c_str()); if(outFile.OpenForWrite(FileName.c_str(),File::Text,false)) { outFile.Printf("#include \"gmThread.h\"\n\n"); WriteUserTypeVars(outFile,it->second); // write the function implementations WriteFunctionImplementations(outFile,it->second); // write the binding block WriteFunctionBindBlock(outFile,it->second); } } // write table of contents file, where all bindings are registered. File tocFile; if(tocFile.OpenForWrite("ScriptBindAll.cpp",File::Text)) { tocFile.Printf("#include \"gmThread.h\"\n\n"); tocFile.Printf("// declarations\n"); for(OutFileMap::iterator it = fileMap.begin(); it != fileMap.end(); ++it) { if(!it->second.Functions.empty()) { tocFile.Printf("void gmBind%sLib(gmMachine * a_machine);\n",it->second.FileName.c_str()); } } tocFile.Printf("\n\n// bind libraries\n"); tocFile.Printf("void gmBindAllAutogenLibs(gmMachine * a_machine)\n"); tocFile.Printf("{\n"); for(OutFileMap::iterator it = fileMap.begin(); it != fileMap.end(); ++it) { if(!it->second.Functions.empty()) { tocFile.Printf("\tgmBind%sLib(a_machine);\n",it->second.FileName.c_str()); } } tocFile.Printf("}\n"); } return fileMap.size(); }