1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #include <precomp.h> 23 #include "cmd_run.hxx" 24 25 26 // NOT FULLY DEFINED SERVICES 27 #include <cosv/file.hxx> 28 #include <cosv/x.hxx> 29 #include <ary/ary.hxx> 30 #include <ary/cpp/c_gate.hxx> 31 #include <ary/idl/i_ce.hxx> 32 #include <ary/idl/i_gate.hxx> 33 #include <ary/idl/i_module.hxx> 34 #include <ary/idl/ip_ce.hxx> 35 #include <autodoc/filecoli.hxx> 36 #include <autodoc/parsing.hxx> 37 #include <autodoc/prs_code.hxx> 38 #include <autodoc/prs_docu.hxx> 39 #include <parser/unoidl.hxx> 40 #include <adc_cl.hxx> 41 #include "adc_cmd_parse.hxx" 42 #include "adc_cmds.hxx" 43 44 namespace autodoc 45 { 46 namespace command 47 { 48 namespace run 49 { 50 51 Parser::Parser( const Parse & i_command ) 52 : rCommand(i_command), 53 pCppParser(), 54 pCppDocuInterpreter(), 55 pIdlParser() 56 { 57 } 58 59 Parser::~Parser() 60 { 61 } 62 63 bool 64 Parser::Perform() 65 { 66 Cout() << "Parsing the repository " 67 << rCommand.ReposyName() 68 << " ..." 69 << Endl(); 70 try 71 { 72 ::ary::Repository & 73 rAry = CommandLine::Get_().TheRepository(); 74 rAry.Set_Title(rCommand.ReposyName()); 75 76 Dyn< FileCollector_Ifc > 77 pFiles( ParseToolsFactory().Create_FileCollector(6000) ); 78 79 bool bIDL = false; 80 bool bCpp = false; 81 82 command::Parse::ProjectIterator 83 itEnd = rCommand.ProjectsEnd(); 84 for ( command::Parse::ProjectIterator it = rCommand.ProjectsBegin(); 85 it != itEnd; 86 ++it ) 87 { 88 uintt nCount = GatherFiles( *pFiles, *(*it) ); 89 Cout() << nCount 90 << " files found to parse in project " 91 << (*it)->Name() 92 << "." 93 << Endl(); 94 95 switch ( (*it)->Language().eLanguage ) 96 { 97 case command::S_LanguageInfo::idl: 98 { 99 Get_IdlParser().Run(*pFiles); 100 bIDL = true; 101 } break; 102 case command::S_LanguageInfo::cpp: 103 { 104 Get_CppParser().Run( *pFiles ); 105 bCpp = true; 106 } break; 107 default: 108 Cerr() << "Project in yet unimplemented language skipped." 109 << Endl(); 110 } 111 } // end for 112 113 if (bCpp) 114 { 115 rAry.Gate_Cpp().Calculate_AllSecondaryInformation(); 116 } 117 if (bIDL) 118 { 119 rAry.Gate_Idl().Calculate_AllSecondaryInformation( 120 rCommand.DevelopersManual_RefFilePath() ); 121 122 // ::ary::idl::SecondariesPilot & 123 // rIdl2sPilot = rAry.Gate_Idl().Secondaries(); 124 // 125 // rIdl2sPilot.CheckAllInterfaceBases( rAry.Gate_Idl() ); 126 // rIdl2sPilot.Connect_Types2Ces(); 127 // rIdl2sPilot.Gather_CrossReferences(); 128 // 129 // if (NOT rCommand.DevelopersManual_RefFilePath().empty()) 130 // { 131 // csv::File 132 // aFile(rCommand.DevelopersManual_RefFilePath(), csv::CFM_READ); 133 // if ( aFile.open() ) 134 // { 135 // rIdl2sPilot.Read_Links2DevManual(aFile); 136 // aFile.close(); 137 // } 138 // } 139 } // endif (bIDL) 140 141 return true; 142 143 } // end try 144 catch (csv::Exception & xx) 145 { 146 xx.GetInfo(Cerr()); 147 Cerr() << " program will exit." << Endl(); 148 149 return false; 150 } 151 } 152 153 CodeParser_Ifc & 154 Parser::Get_CppParser() 155 { 156 if ( NOT pCppParser ) 157 Create_CppParser(); 158 return *pCppParser; 159 } 160 161 IdlParser & 162 Parser::Get_IdlParser() 163 { 164 if ( NOT pIdlParser ) 165 Create_IdlParser(); 166 return *pIdlParser; 167 } 168 169 void 170 Parser::Create_CppParser() 171 { 172 pCppParser = ParseToolsFactory().Create_Parser_Cplusplus(); 173 pCppDocuInterpreter = ParseToolsFactory().Create_DocuParser_AutodocStyle(); 174 175 pCppParser->Setup( CommandLine::Get_().TheRepository(), 176 *pCppDocuInterpreter ); 177 } 178 179 void 180 Parser::Create_IdlParser() 181 { 182 pIdlParser = new IdlParser(CommandLine::Get_().TheRepository()); 183 } 184 185 const ParseToolsFactory_Ifc & 186 Parser::ParseToolsFactory() 187 { 188 return ParseToolsFactory_Ifc::GetIt_(); 189 } 190 191 uintt 192 Parser::GatherFiles( FileCollector_Ifc & o_rFiles, 193 const S_ProjectData & i_rProject ) 194 { 195 uintt ret = 0; 196 o_rFiles.EraseAll(); 197 198 typedef StringVector StrVector; 199 typedef StrVector::const_iterator StrIterator; 200 const S_Sources & 201 rSources = i_rProject.Sources(); 202 const StrVector & 203 rExtensions = i_rProject.Language().aExtensions; 204 205 StrIterator it; 206 StrIterator itTreesEnd = rSources.aTrees.end(); 207 StrIterator itDirsEnd = rSources.aDirectories.end(); 208 StrIterator itFilesEnd = rSources.aFiles.end(); 209 StrIterator itExt; 210 StrIterator itExtEnd = rExtensions.end(); 211 212 csv::StreamStr aDir(500); 213 i_rProject.RootDirectory().Get( aDir ); 214 215 uintt nProjectDir_AddPosition = 216 ( strcmp(aDir.c_str(),".\\") == 0 OR strcmp(aDir.c_str(),"./") == 0 ) 217 ? 0 218 : uintt( aDir.tellp() ); 219 220 for ( it = rSources.aDirectories.begin(); 221 it != itDirsEnd; 222 ++it ) 223 { 224 aDir.seekp( nProjectDir_AddPosition ); 225 aDir << *it; 226 227 for ( itExt = rExtensions.begin(); 228 itExt != itExtEnd; 229 ++itExt ) 230 { 231 ret += o_rFiles.AddFilesFrom( aDir.c_str(), 232 *itExt, 233 FileCollector_Ifc::flat ); 234 } // end for itExt 235 } // end for it 236 for ( it = rSources.aTrees.begin(); 237 it != itTreesEnd; 238 ++it ) 239 { 240 aDir.seekp( nProjectDir_AddPosition ); 241 aDir << *it; 242 243 for ( itExt = rExtensions.begin(); 244 itExt != itExtEnd; 245 ++itExt ) 246 { 247 ret += o_rFiles.AddFilesFrom( aDir.c_str(), 248 *itExt, 249 FileCollector_Ifc::recursive ); 250 } // end for itExt 251 } // end for it 252 for ( it = rSources.aFiles.begin(); 253 it != itFilesEnd; 254 ++it ) 255 { 256 aDir.seekp( nProjectDir_AddPosition ); 257 aDir << *it; 258 259 o_rFiles.AddFile( aDir.c_str() ); 260 } // end for it 261 ret += rSources.aFiles.size(); 262 263 return ret; 264 } 265 266 267 } // namespace run 268 } // namespace command 269 270 271 #if 0 272 inline const ParseToolsFactory_Ifc & 273 CommandRunner::ParseToolsFactory() 274 { return ParseToolsFactory_Ifc::GetIt_(); } 275 276 277 inline const command::S_LanguageInfo & 278 CommandRunner::Get_ProjectLanguage( const command::Parse & i_rCommand, 279 const command::S_ProjectData & i_rProject ) 280 { 281 if ( i_rProject.pLanguage ) 282 return *i_rProject.pLanguage; 283 return *i_rCommand.GlobalLanguageInfo(); 284 } 285 286 inline bool 287 CommandRunner::HasParsedCpp() const 288 { return pCppParser; } 289 inline bool 290 CommandRunner::HasParsedIdl() const 291 { return pIdlParser; } 292 293 294 295 296 297 CommandRunner::CommandRunner() 298 : pCommandLine(0), 299 pReposy(0), 300 pNewReposy(0), 301 nResultCode(0) 302 { 303 Cout() << "\nAutodoc version 2.2.1" 304 << "\n-------------------" 305 << "\n" << Endl(); 306 } 307 308 CommandRunner::~CommandRunner() 309 { 310 ary::Repository::Destroy_(); 311 Cout() << "\n" << Endl(); 312 } 313 314 void 315 CommandRunner::Run( const CommandLine & i_rCL ) 316 { 317 ary::Repository::Destroy_(); 318 // ary::Repository::Destroy_(); 319 pReposy = 0; 320 pNewReposy = 0; 321 nResultCode = 0; 322 pCommandLine = &i_rCL; 323 324 pCommandLine->Run(); 325 } 326 327 void 328 CommandRunner::Parse() 329 { 330 try 331 { 332 333 csv_assert( pCommandLine->Cmd_Parse() != 0 ); 334 const command::Parse & 335 rCmd = *pCommandLine->Cmd_Parse(); 336 337 Cout() << "Parsing the repository " 338 << rCmd.ReposyName() 339 << " ..." 340 << Endl(); 341 342 if ( pReposy == 0 ) 343 pReposy = & ary::Repository::Create_( rCmd.ReposyName(), 0 ); 344 if ( pNewReposy == 0 ) 345 pNewReposy = & ary::Repository::Create_( rCmd.ReposyName() ); 346 347 Dyn< FileCollector_Ifc > pFiles; 348 pFiles = ParseToolsFactory().Create_FileCollector(6000); 349 350 bool bCpp = false; 351 bool bIDL = false; 352 353 command::Parse::ProjectIterator itEnd = rCmd.ProjectsEnd(); 354 for ( command::Parse::ProjectIterator it = rCmd.ProjectsBegin(); 355 it != itEnd; 356 ++it ) 357 { 358 359 uintt nCount = GatherFiles( *pFiles, rCmd, *(*it) ); 360 Cout() << nCount 361 << " files found to parse in project " 362 << (*it)->Name() 363 << "." 364 << Endl(); 365 366 367 switch ( Get_ProjectLanguage(rCmd, *(*it)).eLanguage ) 368 { 369 case command::S_LanguageInfo::cpp: 370 { 371 Get_CppParser().Run( (*it)->Name(), 372 (*it)->RootDirectory(), 373 *pFiles ); 374 bCpp = true; 375 } break; 376 case command::S_LanguageInfo::idl: 377 { 378 Get_IdlParser().Run(*pFiles); 379 bIDL = true; 380 } break; 381 default: 382 Cerr() << "Project in yet unimplemented language skipped." 383 << Endl(); 384 } 385 } // end for 386 387 if (bCpp) 388 pReposy->RwGate_Cpp().Connect_AllTypes_2_TheirRelated_CodeEntites(); 389 if (bIDL) 390 { 391 pNewReposy->Gate_Idl().Secondaries().Connect_Types2Ces(); 392 pNewReposy->Gate_Idl().Secondaries().Gather_CrossReferences(); 393 } 394 395 } // end try 396 catch (csv::Exception & xx) 397 { 398 xx.GetInfo(Cerr()); 399 Cerr() << " program will exit." << Endl(); 400 nResultCode = 1; 401 } 402 catch (...) 403 { 404 Cerr() << "Unknown exception - program will exit." << Endl(); 405 nResultCode = 1; 406 } 407 } 408 409 void 410 CommandRunner::Load() 411 { 412 Cout() << "This would load the repository from the directory " 413 << pCommandLine->Cmd_Load()->ReposyDir() 414 << "." 415 << Endl(); 416 } 417 418 419 void 420 CommandRunner::Save() 421 { 422 Cout() << "This would save the repository into the directory " 423 << pCommandLine->Cmd_Save()->ReposyDir() 424 << "." 425 << Endl(); 426 } 427 428 429 void 430 CommandRunner::CreateHtml() 431 { 432 Cout() << "Creating HTML-output into the directory " 433 << pCommandLine->Cmd_CreateHtml()->OutputDir() 434 << "." 435 << Endl(); 436 437 if ( HasParsedCpp() ) 438 CreateHtml_NewStyle(); 439 if ( HasParsedIdl() ) 440 CreateHtml_OldIdlStyle(); 441 } 442 443 444 445 void 446 CommandRunner::CreateXml() 447 { 448 Cout() << "This would create the XML-output into the directory " 449 << pCommandLine->Cmd_CreateXml()->OutputDir() 450 << "." 451 << Endl(); 452 } 453 454 CodeParser_Ifc & 455 CommandRunner::Get_CppParser() 456 { 457 if ( NOT pCppParser ) 458 Create_CppParser(); 459 return *pCppParser; 460 } 461 462 IdlParser & 463 CommandRunner::Get_IdlParser() 464 { 465 if ( NOT pIdlParser ) 466 Create_IdlParser(); 467 return *pIdlParser; 468 } 469 470 void 471 CommandRunner::Create_CppParser() 472 { 473 pCppParser = ParseToolsFactory().Create_Parser_Cplusplus(); 474 pCppDocuInterpreter = ParseToolsFactory().Create_DocuParser_AutodocStyle(); 475 476 pCppParser->Setup( *pReposy, 477 *pCppDocuInterpreter ); 478 } 479 480 void 481 CommandRunner::Create_IdlParser() 482 { 483 pIdlParser = new IdlParser(*pNewReposy); 484 } 485 486 uintt 487 CommandRunner::GatherFiles( FileCollector_Ifc & o_rFiles, 488 const command::Parse & i_rCommand, 489 const command::S_ProjectData & i_rProject ) 490 { 491 uintt ret = 0; 492 o_rFiles.EraseAll(); 493 494 typedef StringVector StrVector; 495 typedef StrVector::const_iterator StrIterator; 496 const command::S_Sources & 497 rSources = i_rProject.aFiles; 498 const StrVector & 499 rExtensions = Get_ProjectLanguage(i_rCommand,i_rProject).aExtensions; 500 501 StrIterator it; 502 StrIterator itDirsEnd = rSources.aDirectories.end(); 503 StrIterator itTreesEnd = i_rProject.aFiles.aTrees.end(); 504 StrIterator itFilesEnd = i_rProject.aFiles.aFiles.end(); 505 StrIterator itExt; 506 StrIterator itExtEnd = rExtensions.end(); 507 508 csv::StreamStr aDir(500); 509 i_rProject.aRootDirectory.Get( aDir ); 510 511 uintt nProjectDir_AddPosition = 512 ( strcmp(aDir.c_str(),".\\") == 0 OR strcmp(aDir.c_str(),"./") == 0 ) 513 ? 0 514 : uintt( aDir.tellp() ); 515 516 for ( it = rSources.aDirectories.begin(); 517 it != itDirsEnd; 518 ++it ) 519 { 520 aDir.seekp( nProjectDir_AddPosition ); 521 aDir << *it; 522 523 for ( itExt = rExtensions.begin(); 524 itExt != itExtEnd; 525 ++itExt ) 526 { 527 ret += o_rFiles.AddFilesFrom( aDir.c_str(), 528 *itExt, 529 FileCollector_Ifc::flat ); 530 } // end for itExt 531 } // end for it 532 for ( it = rSources.aTrees.begin(); 533 it != itTreesEnd; 534 ++it ) 535 { 536 aDir.seekp( nProjectDir_AddPosition ); 537 aDir << *it; 538 539 for ( itExt = rExtensions.begin(); 540 itExt != itExtEnd; 541 ++itExt ) 542 { 543 ret += o_rFiles.AddFilesFrom( aDir.c_str(), 544 *itExt, 545 FileCollector_Ifc::recursive ); 546 } // end for itExt 547 } // end for it 548 for ( it = rSources.aFiles.begin(); 549 it != itFilesEnd; 550 ++it ) 551 { 552 aDir.seekp( nProjectDir_AddPosition ); 553 aDir << *it; 554 555 o_rFiles.AddFile( aDir.c_str() ); 556 } // end for it 557 ret += rSources.aFiles.size(); 558 559 return ret; 560 } 561 562 void 563 CommandRunner::CreateHtml_NewStyle() 564 { 565 const ary::cpp::DisplayGate & 566 rGate = pReposy->DisplayGate_Cpp(); 567 568 Dyn< autodoc::HtmlDisplay_UdkStd > pHtmlDisplay; 569 pHtmlDisplay = DisplayToolsFactory_Ifc::GetIt_() 570 .Create_HtmlDisplay_UdkStd(); 571 572 pHtmlDisplay->Run( pCommandLine->Cmd_CreateHtml()->OutputDir(), 573 rGate, 574 DisplayToolsFactory_Ifc::GetIt_().Create_StdFrame() ); 575 } 576 577 void 578 CommandRunner::CreateHtml_OldIdlStyle() 579 { 580 ary::idl::Gate & 581 rAryGate = pNewReposy->Gate_Idl(); 582 583 // Read DevManualLinkFile: 584 // KORR_FUTURE 585 csv::File 586 aFile("devmanref.txt", csv::CFM_READ); 587 if ( aFile.open() ) 588 { 589 rAryGate.Secondaries().Read_Links2DevManual(aFile); 590 aFile.close(); 591 } 592 593 // New Style Output 594 Dyn<autodoc::HtmlDisplay_Idl_Ifc> pNewDisplay; 595 pNewDisplay = DisplayToolsFactory_Ifc::GetIt_() 596 .Create_HtmlDisplay_Idl(); 597 pNewDisplay->Run( pCommandLine->Cmd_CreateHtml()->OutputDir(), 598 rAryGate, 599 DisplayToolsFactory_Ifc::GetIt_().Create_StdFrame() ); 600 } 601 #endif // 0 602 603 } // namespace autodoc 604 605 606 607 608