diff options
Diffstat (limited to 'Source')
31 files changed, 1634 insertions, 795 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index a2dead6..5e136e4 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -789,6 +789,7 @@ target_link_libraries(cmake CMakeLib) if(CMake_HAVE_SERVER_MODE) add_library(CMakeServerLib cmServer.cxx cmServer.h + cmServerConnection.cxx cmServerConnection.h cmServerProtocol.cxx cmServerProtocol.h ) target_link_libraries(CMakeServerLib CMakeLib) diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 90d0d0e..68c9a6d 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 6) -set(CMake_VERSION_PATCH 20160920) +set(CMake_VERSION_PATCH 20160922) #set(CMake_VERSION_RC 1) diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 2eb64bf..f2cd67e 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -929,8 +929,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( std::string gcovCommand = this->CTest->GetCTestConfiguration("CoverageCommand"); if (gcovCommand.empty()) { - cmCTestLog(this->CTest, ERROR_MESSAGE, "Could not find gcov." - << std::endl); + cmCTestLog(this->CTest, WARNING, "Could not find gcov." << std::endl); return 0; } std::string gcovExtraFlags = diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index e8e2956..19d8595 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -31,6 +31,7 @@ cmCTestHandlerCommand::cmCTestHandlerCommand() this->Arguments.push_back(CM_NULLPTR); } this->Arguments[ct_RETURN_VALUE] = "RETURN_VALUE"; + this->Arguments[ct_CAPTURE_CMAKE_ERROR] = "CAPTURE_CMAKE_ERROR"; this->Arguments[ct_SOURCE] = "SOURCE"; this->Arguments[ct_BUILD] = "BUILD"; this->Arguments[ct_SUBMIT_INDEX] = "SUBMIT_INDEX"; @@ -39,15 +40,71 @@ cmCTestHandlerCommand::cmCTestHandlerCommand() this->Quiet = false; } +namespace { +// class to save and restore the error state for ctest_* commands +// if a ctest_* command has a CAPTURE_CMAKE_ERROR then put the error +// state into there and restore the system wide error to what +// it was before the command ran +class SaveRestoreErrorState +{ +public: + SaveRestoreErrorState() + { + this->InitialErrorState = cmSystemTools::GetErrorOccuredFlag(); + cmSystemTools::ResetErrorOccuredFlag(); // rest the error state + this->CaptureCMakeErrorValue = false; + } + // if the function has a CAPTURE_CMAKE_ERROR then we should restore + // the error state to what it was before the function was run + // if not then let the error state be what it is + void CaptureCMakeError() { this->CaptureCMakeErrorValue = true; } + ~SaveRestoreErrorState() + { + // if we are not saving the return value then make sure + // if it was in error it goes back to being in error + // otherwise leave it be what it is + if (!this->CaptureCMakeErrorValue) { + if (this->InitialErrorState) { + cmSystemTools::SetErrorOccured(); + } + return; + } + // if we have saved the error in a return variable + // then put things back exactly like they were + bool currentState = cmSystemTools::GetErrorOccuredFlag(); + // if the state changed during this command we need + // to handle it, if not then nothing needs to be done + if (currentState != this->InitialErrorState) { + // restore the initial error state + if (this->InitialErrorState) { + cmSystemTools::SetErrorOccured(); + } else { + cmSystemTools::ResetErrorOccuredFlag(); + } + } + } + +private: + bool InitialErrorState; + bool CaptureCMakeErrorValue; +}; +} + bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus& /*unused*/) { + // save error state and restore it if needed + SaveRestoreErrorState errorState; // Allocate space for argument values. this->Values.clear(); this->Values.resize(this->Last, CM_NULLPTR); // Process input arguments. this->ArgumentDoing = ArgumentDoingNone; + // look at all arguments and do not short circuit on the first + // bad one so that CAPTURE_CMAKE_ERROR can override setting the + // global error state + bool foundBadArgument = false; for (unsigned int i = 0; i < args.size(); ++i) { // Check this argument. if (!this->CheckArgumentKeyword(args[i]) && @@ -55,14 +112,36 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, std::ostringstream e; e << "called with unknown argument \"" << args[i] << "\"."; this->SetError(e.str()); - return false; + foundBadArgument = true; } - - // Quit if an argument is invalid. + // note bad argument if (this->ArgumentDoing == ArgumentDoingError) { - return false; + foundBadArgument = true; } } + bool capureCMakeError = (this->Values[ct_CAPTURE_CMAKE_ERROR] && + *this->Values[ct_CAPTURE_CMAKE_ERROR]); + // now that arguments are parsed check to see if there is a + // CAPTURE_CMAKE_ERROR specified let the errorState object know. + if (capureCMakeError) { + errorState.CaptureCMakeError(); + } + // if we found a bad argument then exit before running command + if (foundBadArgument) { + // store the cmake error + if (capureCMakeError) { + this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR], + "-1"); + const char* err = this->GetError(); + if (err && !cmSystemTools::FindLastString(err, "unknown error.")) { + cmCTestLog(this->CTest, ERROR_MESSAGE, err << " error from command\n"); + } + // return success because failure is recorded in CAPTURE_CMAKE_ERROR + return true; + } + // return failure because of bad argument + return false; + } // Set the config type of this ctest to the current value of the // CTEST_CONFIGURATION_TYPE script variable if it is defined. @@ -117,6 +196,15 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, if (!handler) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot instantiate test handler " << this->GetName() << std::endl); + if (capureCMakeError) { + this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR], + "-1"); + const char* err = this->GetError(); + if (err && !cmSystemTools::FindLastString(err, "unknown error.")) { + cmCTestLog(this->CTest, ERROR_MESSAGE, err << " error from command\n"); + } + return true; + } return false; } @@ -147,6 +235,22 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args, this->Makefile->AddDefinition(this->Values[ct_RETURN_VALUE], str.str().c_str()); } + // log the error message if there was an error + if (capureCMakeError) { + const char* returnString = "0"; + if (cmSystemTools::GetErrorOccuredFlag()) { + returnString = "-1"; + const char* err = this->GetError(); + // print out the error if it is not "unknown error" which means + // there was no message + if (err && !cmSystemTools::FindLastString(err, "unknown error.")) { + cmCTestLog(this->CTest, ERROR_MESSAGE, err); + } + } + // store the captured cmake error state 0 or -1 + this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR], + returnString); + } cmSystemTools::ChangeDirectory(current_dir); return true; } diff --git a/Source/CTest/cmCTestHandlerCommand.h b/Source/CTest/cmCTestHandlerCommand.h index 7c9fd50..95a1581 100644 --- a/Source/CTest/cmCTestHandlerCommand.h +++ b/Source/CTest/cmCTestHandlerCommand.h @@ -47,6 +47,7 @@ public: { ct_NONE, ct_RETURN_VALUE, + ct_CAPTURE_CMAKE_ERROR, ct_BUILD, ct_SOURCE, ct_SUBMIT_INDEX, diff --git a/Source/CTest/cmCTestUploadCommand.cxx b/Source/CTest/cmCTestUploadCommand.cxx index 5ea637e..c4458dd 100644 --- a/Source/CTest/cmCTestUploadCommand.cxx +++ b/Source/CTest/cmCTestUploadCommand.cxx @@ -45,11 +45,19 @@ bool cmCTestUploadCommand::CheckArgumentKeyword(std::string const& arg) this->Quiet = true; return true; } + if (arg == "CAPTURE_CMAKE_ERROR") { + this->ArgumentDoing = ArgumentDoingCaptureCMakeError; + return true; + } return false; } bool cmCTestUploadCommand::CheckArgumentValue(std::string const& arg) { + if (this->ArgumentDoing == ArgumentDoingCaptureCMakeError) { + this->Values[ct_CAPTURE_CMAKE_ERROR] = arg.c_str(); + return true; + } if (this->ArgumentDoing == ArgumentDoingFiles) { if (cmSystemTools::FileExists(arg.c_str())) { this->Files.insert(arg); diff --git a/Source/CTest/cmCTestUploadCommand.h b/Source/CTest/cmCTestUploadCommand.h index da291f3..3a5bdef 100644 --- a/Source/CTest/cmCTestUploadCommand.h +++ b/Source/CTest/cmCTestUploadCommand.h @@ -61,6 +61,7 @@ protected: enum { ArgumentDoingFiles = Superclass::ArgumentDoingLast1, + ArgumentDoingCaptureCMakeError, ArgumentDoingLast2 }; diff --git a/Source/cmFortranLexer.cxx b/Source/cmFortranLexer.cxx index 7bcd993..60d5591 100644 --- a/Source/cmFortranLexer.cxx +++ b/Source/cmFortranLexer.cxx @@ -347,8 +347,8 @@ static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner ); *yy_cp = '\0'; \ yyg->yy_c_buf_p = yy_cp; -#define YY_NUM_RULES 50 -#define YY_END_OF_BUFFER 51 +#define YY_NUM_RULES 54 +#define YY_END_OF_BUFFER 55 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -356,30 +356,31 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[199] = +static yyconst flex_int16_t yy_accept[210] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 51, 45, 47, 46, 49, 1, 45, 33, 2, 35, - 45, 46, 38, 45, 44, 44, 44, 44, 44, 45, - 44, 47, 45, 46, 45, 44, 9, 8, 9, 4, - 3, 45, 0, 10, 0, 0, 0, 0, 0, 33, - 33, 34, 36, 38, 45, 44, 44, 44, 44, 44, - 0, 48, 44, 0, 0, 0, 12, 0, 0, 0, - 0, 0, 0, 45, 0, 11, 44, 0, 0, 5, - 0, 0, 0, 29, 0, 0, 33, 33, 33, 33, - 0, 0, 39, 44, 44, 44, 43, 12, 12, 0, - - 0, 0, 23, 0, 0, 0, 0, 0, 0, 6, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, - 44, 44, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 30, 31, 0, 0, 0, 0, - 0, 0, 44, 44, 44, 0, 24, 25, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 32, 27, 0, - 0, 20, 0, 44, 44, 42, 0, 26, 21, 0, - 0, 0, 19, 0, 0, 18, 28, 0, 0, 40, - 44, 17, 22, 0, 7, 37, 7, 15, 0, 44, - 14, 16, 41, 0, 0, 0, 13, 0 - + 55, 49, 51, 50, 53, 1, 49, 33, 2, 47, + 48, 35, 37, 50, 39, 49, 46, 46, 46, 46, + 46, 46, 49, 46, 51, 49, 50, 49, 46, 9, + 8, 9, 4, 3, 49, 0, 10, 0, 0, 0, + 0, 0, 33, 33, 34, 36, 39, 49, 46, 46, + 46, 46, 46, 46, 0, 52, 46, 0, 0, 0, + 12, 0, 0, 0, 0, 0, 0, 49, 0, 11, + 46, 0, 0, 5, 0, 0, 0, 29, 0, 0, + 33, 33, 33, 33, 0, 0, 40, 46, 46, 46, + + 46, 45, 12, 12, 0, 0, 0, 23, 0, 0, + 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 46, 46, 46, 46, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 30, 31, 0, 0, 0, 0, 0, 0, 46, 46, + 46, 46, 0, 24, 25, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 32, 27, 0, 0, 20, 0, + 46, 46, 43, 46, 0, 26, 21, 0, 0, 0, + 19, 0, 0, 18, 28, 0, 0, 41, 46, 46, + 17, 22, 0, 7, 38, 7, 15, 0, 46, 46, + + 14, 16, 42, 44, 0, 0, 0, 13, 0 } ; static yyconst YY_CHAR yy_ec[256] = @@ -387,17 +388,17 @@ static yyconst YY_CHAR yy_ec[256] = 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 5, 6, 7, 8, 9, 1, 10, 11, 1, - 1, 12, 1, 13, 1, 1, 1, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 15, 16, 17, - 18, 19, 20, 1, 21, 22, 23, 24, 25, 26, - 22, 22, 27, 22, 22, 28, 29, 30, 31, 22, - 22, 32, 33, 34, 35, 22, 22, 22, 22, 22, - 1, 36, 1, 1, 37, 1, 21, 22, 38, 39, - - 40, 41, 22, 22, 42, 22, 22, 43, 29, 44, - 31, 22, 22, 32, 45, 34, 46, 22, 22, 22, - 22, 22, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 5, 6, 7, 8, 9, 1, 10, 11, 12, + 13, 14, 1, 15, 1, 1, 1, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 17, 18, 19, + 20, 21, 22, 1, 23, 24, 25, 26, 27, 28, + 29, 29, 30, 29, 29, 31, 32, 33, 34, 29, + 29, 35, 36, 37, 38, 29, 29, 29, 29, 29, + 1, 39, 1, 1, 40, 1, 23, 24, 41, 42, + + 43, 44, 29, 29, 45, 29, 29, 46, 32, 47, + 34, 29, 29, 35, 48, 37, 49, 29, 29, 29, + 29, 29, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -414,211 +415,217 @@ static yyconst YY_CHAR yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst YY_CHAR yy_meta[47] = +static yyconst YY_CHAR yy_meta[50] = { 0, 1, 2, 2, 3, 4, 3, 3, 1, 1, 3, - 3, 1, 3, 5, 1, 3, 1, 3, 6, 1, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 1, 5, 7, 7, 7, - 7, 7, 7, 7, 7, 7 + 3, 3, 3, 1, 3, 5, 3, 3, 1, 3, + 6, 1, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 1, 5, + 7, 7, 7, 7, 7, 7, 7, 7, 7 } ; -static yyconst flex_uint16_t yy_base[208] = +static yyconst flex_uint16_t yy_base[219] = { 0, - 0, 45, 0, 46, 392, 53, 49, 59, 61, 71, - 392, 0, 572, 572, 364, 572, 91, 77, 572, 572, - 342, 572, 317, 232, 0, 19, 42, 218, 40, 92, - 137, 96, 174, 240, 220, 257, 572, 238, 97, 572, - 572, 0, 205, 572, 302, 50, 77, 83, 59, 137, - 156, 572, 0, 572, 123, 0, 84, 130, 90, 92, - 167, 572, 0, 176, 347, 0, 190, 94, 175, 200, - 121, 92, 201, 393, 193, 572, 0, 162, 222, 175, - 171, 209, 176, 281, 184, 207, 307, 313, 328, 348, - 338, 111, 0, 205, 213, 125, 0, 354, 185, 280, - - 336, 300, 340, 309, 278, 321, 139, 130, 245, 572, - 335, 347, 351, 356, 360, 375, 375, 379, 383, 300, - 80, 381, 384, 390, 392, 393, 397, 399, 397, 402, - 403, 106, 105, 284, 572, 572, 407, 408, 411, 320, - 413, 413, 420, 419, 421, 420, 572, 572, 421, 426, - 428, 420, 467, 432, 101, 83, 438, 572, 572, 439, - 446, 572, 436, 449, 63, 0, 450, 572, 572, 450, - 453, 481, 572, 64, 0, 572, 572, 454, 460, 0, - 464, 572, 572, 463, 572, 572, 572, 572, 468, 471, - 495, 572, 0, 496, 0, 38, 572, 572, 513, 520, - - 526, 529, 536, 543, 550, 557, 564 + 0, 48, 0, 49, 513, 56, 52, 57, 62, 68, + 515, 0, 583, 583, 509, 583, 97, 74, 583, 583, + 583, 583, 491, 583, 423, 421, 0, 19, 40, 392, + 36, 47, 86, 146, 88, 186, 413, 235, 275, 583, + 407, 98, 583, 583, 0, 386, 583, 323, 65, 73, + 81, 74, 127, 146, 583, 583, 583, 108, 0, 89, + 120, 92, 362, 116, 161, 583, 0, 167, 371, 0, + 168, 131, 146, 171, 81, 89, 352, 420, 353, 583, + 0, 349, 178, 196, 175, 197, 188, 208, 196, 197, + 256, 262, 324, 330, 337, 143, 0, 151, 220, 56, + + 305, 0, 336, 139, 225, 315, 305, 322, 318, 163, + 320, 268, 266, 369, 583, 340, 347, 350, 350, 351, + 357, 350, 357, 363, 140, 235, 359, 218, 362, 375, + 379, 380, 381, 385, 384, 404, 405, 243, 235, 213, + 583, 583, 405, 407, 410, 171, 410, 409, 419, 418, + 423, 426, 311, 583, 583, 428, 429, 431, 173, 462, + 435, 166, 145, 438, 583, 583, 441, 444, 583, 433, + 448, 89, 0, 438, 450, 583, 583, 452, 457, 487, + 583, 114, 0, 583, 583, 457, 462, 0, 465, 463, + 583, 583, 468, 583, 583, 583, 583, 470, 471, 474, + + 500, 583, 0, 0, 505, 0, 65, 583, 583, 524, + 531, 537, 540, 547, 554, 561, 568, 575 } ; -static yyconst flex_int16_t yy_def[208] = +static yyconst flex_int16_t yy_def[219] = { 0, - 198, 1, 1, 1, 1, 1, 199, 199, 199, 199, - 198, 200, 198, 198, 201, 198, 200, 198, 198, 198, - 200, 198, 198, 200, 202, 202, 202, 202, 202, 200, - 202, 198, 198, 198, 203, 198, 198, 198, 198, 198, - 198, 200, 201, 198, 198, 198, 198, 198, 198, 198, - 204, 198, 200, 198, 200, 202, 202, 202, 202, 202, - 198, 198, 31, 198, 198, 65, 200, 198, 198, 198, - 198, 198, 198, 203, 203, 198, 36, 198, 198, 198, - 198, 198, 198, 198, 198, 198, 204, 204, 204, 204, - 198, 198, 202, 202, 202, 202, 202, 198, 198, 198, - - 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, - 198, 198, 198, 198, 198, 198, 198, 198, 198, 202, - 202, 202, 198, 198, 198, 198, 198, 198, 198, 198, - 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, - 198, 198, 202, 202, 202, 198, 198, 198, 198, 198, - 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, - 198, 198, 198, 202, 202, 202, 198, 198, 198, 198, - 198, 198, 198, 205, 206, 198, 198, 198, 198, 202, - 202, 198, 198, 198, 198, 198, 198, 198, 198, 202, - 198, 198, 202, 198, 207, 207, 198, 0, 198, 198, - - 198, 198, 198, 198, 198, 198, 198 + 209, 1, 1, 1, 1, 1, 210, 210, 210, 210, + 209, 211, 209, 209, 212, 209, 211, 209, 209, 209, + 209, 209, 209, 209, 209, 211, 213, 213, 213, 213, + 213, 213, 211, 213, 209, 209, 209, 214, 209, 209, + 209, 209, 209, 209, 211, 212, 209, 209, 209, 209, + 209, 209, 209, 215, 209, 209, 209, 211, 213, 213, + 213, 213, 213, 213, 209, 209, 34, 209, 209, 69, + 211, 209, 209, 209, 209, 209, 209, 214, 214, 209, + 39, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 215, 215, 215, 215, 209, 209, 213, 213, 213, 213, + + 213, 213, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 213, 213, 213, 213, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 213, 213, + 213, 213, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 213, 213, 213, 213, 209, 209, 209, 209, 209, 209, + 209, 216, 217, 209, 209, 209, 209, 213, 213, 213, + 209, 209, 209, 209, 209, 209, 209, 209, 213, 213, + + 209, 209, 213, 213, 209, 218, 218, 209, 0, 209, + 209, 209, 209, 209, 209, 209, 209, 209 } ; -static yyconst flex_uint16_t yy_nxt[619] = +static yyconst flex_uint16_t yy_nxt[633] = { 0, 12, 13, 14, 13, 13, 15, 16, 12, 17, 18, - 19, 12, 20, 12, 21, 22, 12, 23, 12, 24, - 25, 25, 25, 25, 26, 25, 27, 25, 28, 25, - 25, 25, 25, 25, 29, 30, 31, 25, 25, 26, - 25, 27, 25, 25, 25, 29, 32, 32, 57, 32, - 32, 38, 33, 33, 32, 34, 197, 32, 39, 40, - 33, 38, 57, 38, 35, 186, 186, 41, 39, 40, - 39, 58, 60, 38, 81, 36, 36, 41, 50, 50, - 39, 50, 51, 181, 60, 58, 52, 175, 86, 81, - 36, 36, 45, 61, 62, 45, 61, 64, 79, 80, - - 64, 79, 86, 65, 82, 174, 83, 93, 84, 156, - 155, 144, 85, 96, 46, 47, 97, 48, 100, 82, - 83, 106, 93, 84, 91, 49, 85, 91, 96, 46, - 47, 97, 48, 100, 133, 106, 49, 42, 50, 50, - 119, 50, 51, 132, 42, 42, 52, 105, 42, 92, - 63, 42, 94, 42, 119, 42, 42, 88, 50, 122, - 88, 89, 105, 95, 92, 90, 108, 94, 61, 62, - 122, 61, 42, 63, 42, 66, 109, 64, 66, 109, - 64, 42, 42, 65, 110, 42, 99, 67, 42, 99, - 42, 99, 42, 42, 99, 76, 111, 68, 69, 114, - - 70, 71, 101, 67, 102, 107, 117, 44, 72, 42, - 42, 111, 68, 69, 114, 70, 71, 101, 102, 72, - 74, 117, 76, 79, 80, 103, 79, 74, 74, 104, - 118, 74, 120, 74, 74, 112, 74, 121, 74, 74, - 103, 113, 78, 104, 73, 118, 109, 120, 59, 109, - 112, 55, 121, 113, 110, 74, 74, 75, 75, 76, - 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, - 77, 75, 75, 75, 75, 75, 75, 77, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 75, 77, 77, 77, 77, 77, 77, 77, - - 77, 77, 77, 45, 115, 123, 45, 130, 88, 50, - 116, 88, 89, 157, 88, 50, 90, 88, 89, 115, - 123, 130, 90, 126, 116, 46, 47, 157, 48, 88, - 50, 129, 88, 89, 143, 54, 49, 90, 126, 91, - 46, 47, 91, 48, 131, 143, 129, 49, 66, 88, - 50, 66, 88, 89, 161, 99, 53, 90, 99, 131, - 98, 134, 124, 127, 92, 161, 44, 98, 125, 128, - 68, 69, 135, 70, 71, 136, 134, 124, 127, 92, - 125, 72, 137, 128, 138, 68, 69, 135, 70, 71, - 136, 198, 72, 74, 34, 76, 198, 137, 139, 138, - - 74, 74, 140, 141, 74, 142, 74, 74, 145, 74, - 146, 74, 74, 139, 198, 147, 148, 140, 141, 149, - 142, 150, 151, 145, 152, 146, 153, 154, 74, 74, - 147, 148, 158, 159, 149, 160, 150, 151, 162, 152, - 163, 153, 154, 164, 165, 166, 168, 158, 159, 167, - 160, 169, 170, 162, 171, 163, 198, 173, 164, 165, - 166, 168, 176, 167, 177, 171, 169, 170, 172, 178, - 179, 172, 173, 180, 182, 183, 184, 176, 188, 177, - 98, 179, 172, 189, 178, 172, 190, 191, 180, 182, - 183, 184, 192, 188, 98, 193, 194, 194, 189, 194, - - 194, 190, 191, 198, 198, 198, 198, 192, 198, 198, - 193, 195, 195, 37, 37, 37, 37, 37, 37, 37, - 42, 198, 198, 198, 42, 42, 43, 43, 43, 43, - 43, 43, 43, 56, 198, 56, 75, 75, 75, 75, - 75, 75, 75, 87, 87, 87, 87, 87, 87, 87, - 185, 185, 185, 198, 185, 185, 185, 187, 198, 187, - 198, 187, 187, 187, 196, 196, 196, 196, 196, 198, - 196, 11, 198, 198, 198, 198, 198, 198, 198, 198, - 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, - 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, - - 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, - 198, 198, 198, 198, 198, 198, 198, 198 + 19, 20, 21, 12, 22, 12, 23, 24, 12, 25, + 12, 26, 27, 27, 27, 27, 28, 27, 27, 29, + 27, 30, 27, 27, 27, 31, 27, 32, 33, 34, + 27, 27, 28, 27, 29, 27, 27, 31, 32, 35, + 35, 60, 35, 35, 41, 36, 36, 35, 37, 41, + 35, 42, 43, 36, 41, 60, 42, 43, 44, 38, + 41, 42, 61, 63, 44, 53, 53, 42, 53, 54, + 39, 39, 64, 55, 63, 208, 61, 65, 66, 68, + 65, 85, 68, 127, 64, 69, 39, 39, 48, 83, + + 84, 48, 83, 86, 127, 87, 90, 85, 88, 95, + 110, 189, 95, 89, 97, 195, 195, 100, 86, 87, + 90, 111, 49, 50, 88, 110, 51, 89, 53, 53, + 97, 53, 54, 100, 52, 111, 55, 96, 49, 50, + 104, 51, 102, 104, 98, 52, 45, 92, 53, 183, + 92, 93, 96, 45, 45, 94, 99, 105, 102, 45, + 98, 67, 65, 66, 45, 65, 45, 45, 68, 104, + 182, 68, 104, 105, 69, 124, 106, 149, 107, 83, + 84, 125, 83, 71, 45, 67, 45, 70, 149, 124, + 70, 106, 107, 45, 45, 136, 125, 114, 108, 45, + + 114, 71, 116, 109, 45, 115, 45, 45, 168, 136, + 179, 72, 73, 119, 108, 74, 75, 109, 116, 168, + 122, 179, 123, 76, 45, 45, 117, 72, 73, 119, + 74, 75, 118, 120, 76, 78, 122, 80, 123, 163, + 121, 117, 78, 78, 118, 164, 126, 162, 78, 120, + 78, 152, 129, 78, 121, 78, 78, 92, 53, 164, + 92, 93, 126, 92, 53, 94, 92, 93, 129, 150, + 139, 94, 138, 78, 78, 79, 79, 80, 79, 79, + 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, + 81, 79, 79, 79, 79, 79, 79, 81, 81, 81, + + 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, + 81, 81, 81, 79, 81, 81, 81, 81, 81, 81, + 81, 81, 81, 81, 48, 92, 53, 48, 92, 93, + 132, 92, 53, 94, 92, 93, 128, 104, 95, 94, + 104, 95, 135, 175, 130, 137, 132, 133, 49, 50, + 131, 103, 51, 113, 134, 80, 112, 175, 135, 130, + 52, 137, 131, 133, 49, 50, 96, 51, 134, 140, + 114, 52, 70, 114, 141, 70, 142, 144, 115, 143, + 146, 96, 145, 147, 140, 101, 103, 148, 47, 151, + 141, 153, 142, 144, 143, 146, 72, 73, 145, 147, + + 74, 75, 154, 148, 151, 155, 153, 157, 76, 156, + 158, 82, 72, 73, 159, 74, 75, 77, 154, 76, + 78, 155, 80, 157, 156, 62, 158, 78, 78, 159, + 160, 161, 165, 78, 166, 78, 167, 169, 78, 170, + 78, 78, 58, 57, 171, 172, 160, 161, 165, 173, + 166, 174, 167, 169, 170, 176, 177, 178, 78, 78, + 171, 172, 181, 180, 184, 173, 180, 174, 185, 186, + 187, 176, 177, 178, 188, 190, 191, 103, 181, 192, + 184, 187, 193, 197, 185, 186, 190, 198, 180, 199, + 188, 180, 191, 200, 201, 192, 202, 203, 193, 197, + + 204, 205, 103, 198, 205, 199, 205, 56, 200, 205, + 201, 47, 202, 203, 209, 37, 204, 209, 206, 209, + 209, 209, 209, 206, 40, 40, 40, 40, 40, 40, + 40, 45, 209, 209, 209, 45, 45, 46, 46, 46, + 46, 46, 46, 46, 59, 209, 59, 79, 79, 79, + 79, 79, 79, 79, 91, 91, 91, 91, 91, 91, + 91, 194, 194, 194, 209, 194, 194, 194, 196, 209, + 196, 209, 196, 196, 196, 207, 207, 207, 207, 207, + 209, 207, 11, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209 } ; -static yyconst flex_int16_t yy_chk[619] = +static yyconst flex_int16_t yy_chk[633] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 2, 4, 26, 2, - 4, 7, 2, 4, 6, 6, 196, 6, 7, 7, - 6, 8, 26, 9, 6, 174, 174, 9, 8, 8, - 9, 27, 29, 10, 46, 6, 6, 10, 18, 18, - 10, 18, 18, 165, 29, 27, 18, 156, 49, 46, - 6, 6, 17, 30, 30, 17, 30, 32, 39, 39, - - 32, 39, 49, 32, 47, 155, 47, 57, 48, 133, - 132, 121, 48, 59, 17, 17, 60, 17, 68, 47, - 47, 72, 57, 48, 55, 17, 48, 55, 59, 17, - 17, 60, 17, 68, 108, 72, 17, 31, 50, 50, - 92, 50, 50, 107, 31, 31, 50, 71, 31, 55, - 31, 31, 58, 31, 92, 31, 31, 51, 51, 96, - 51, 51, 71, 58, 55, 51, 78, 58, 61, 61, - 96, 61, 31, 31, 33, 33, 80, 64, 33, 80, - 64, 33, 33, 64, 80, 33, 99, 33, 33, 99, - 33, 67, 33, 33, 67, 75, 81, 33, 33, 83, - - 33, 33, 69, 67, 69, 73, 85, 43, 33, 33, - 33, 81, 33, 33, 83, 33, 33, 69, 69, 33, - 35, 85, 35, 79, 79, 70, 79, 35, 35, 70, - 86, 35, 94, 35, 35, 82, 35, 95, 35, 35, - 70, 82, 38, 70, 34, 86, 109, 94, 28, 109, - 82, 24, 95, 82, 109, 35, 35, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, - - 36, 36, 36, 45, 84, 100, 45, 105, 87, 87, - 84, 87, 87, 134, 88, 88, 87, 88, 88, 84, - 100, 105, 88, 102, 84, 45, 45, 134, 45, 89, - 89, 104, 89, 89, 120, 23, 45, 89, 102, 91, - 45, 45, 91, 45, 106, 120, 104, 45, 65, 90, - 90, 65, 90, 90, 140, 98, 21, 90, 98, 106, - 65, 111, 101, 103, 91, 140, 15, 98, 101, 103, - 65, 65, 112, 65, 65, 113, 111, 101, 103, 91, - 101, 65, 114, 103, 115, 65, 65, 112, 65, 65, - 113, 11, 65, 74, 5, 74, 0, 114, 116, 115, - - 74, 74, 117, 118, 74, 119, 74, 74, 122, 74, - 123, 74, 74, 116, 0, 124, 125, 117, 118, 126, - 119, 127, 128, 122, 129, 123, 130, 131, 74, 74, - 124, 125, 137, 138, 126, 139, 127, 128, 141, 129, - 142, 130, 131, 143, 144, 145, 149, 137, 138, 146, - 139, 150, 151, 141, 152, 142, 0, 154, 143, 144, - 145, 149, 157, 146, 160, 152, 150, 151, 153, 161, - 163, 153, 154, 164, 167, 170, 171, 157, 178, 160, - 153, 163, 172, 179, 161, 172, 181, 184, 164, 167, - 170, 171, 189, 178, 172, 190, 191, 194, 179, 191, - - 194, 181, 184, 0, 0, 0, 0, 189, 0, 0, - 190, 191, 194, 199, 199, 199, 199, 199, 199, 199, - 200, 0, 0, 0, 200, 200, 201, 201, 201, 201, - 201, 201, 201, 202, 0, 202, 203, 203, 203, 203, - 203, 203, 203, 204, 204, 204, 204, 204, 204, 204, - 205, 205, 205, 0, 205, 205, 205, 206, 0, 206, - 0, 206, 206, 206, 207, 207, 207, 207, 207, 0, - 207, 198, 198, 198, 198, 198, 198, 198, 198, 198, - 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, - 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, - - 198, 198, 198, 198, 198, 198, 198, 198, 198, 198, - 198, 198, 198, 198, 198, 198, 198, 198 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 4, 28, 2, 4, 7, 2, 4, 6, 6, 8, + 6, 7, 7, 6, 9, 28, 8, 8, 9, 6, + 10, 9, 29, 31, 10, 18, 18, 10, 18, 18, + 6, 6, 32, 18, 31, 207, 29, 33, 33, 35, + 33, 49, 35, 100, 32, 35, 6, 6, 17, 42, + + 42, 17, 42, 50, 100, 50, 52, 49, 51, 58, + 75, 172, 58, 51, 60, 182, 182, 62, 50, 50, + 52, 76, 17, 17, 51, 75, 17, 51, 53, 53, + 60, 53, 53, 62, 17, 76, 53, 58, 17, 17, + 104, 17, 64, 104, 61, 17, 34, 54, 54, 163, + 54, 54, 58, 34, 34, 54, 61, 72, 64, 34, + 61, 34, 65, 65, 34, 65, 34, 34, 68, 71, + 162, 68, 71, 72, 68, 96, 73, 125, 73, 83, + 83, 98, 83, 71, 34, 34, 36, 36, 125, 96, + 36, 73, 73, 36, 36, 110, 98, 84, 74, 36, + + 84, 36, 85, 74, 36, 84, 36, 36, 146, 110, + 159, 36, 36, 87, 74, 36, 36, 74, 85, 146, + 89, 159, 90, 36, 36, 36, 86, 36, 36, 87, + 36, 36, 86, 88, 36, 38, 89, 38, 90, 139, + 88, 86, 38, 38, 86, 140, 99, 138, 38, 88, + 38, 128, 105, 38, 88, 38, 38, 91, 91, 140, + 91, 91, 99, 92, 92, 91, 92, 92, 105, 126, + 113, 92, 112, 38, 38, 39, 39, 39, 39, 39, + 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, + 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, + + 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, + 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, + 39, 39, 39, 39, 48, 93, 93, 48, 93, 93, + 107, 94, 94, 93, 94, 94, 101, 103, 95, 94, + 103, 95, 109, 153, 106, 111, 107, 108, 48, 48, + 106, 103, 48, 82, 108, 79, 77, 153, 109, 106, + 48, 111, 106, 108, 48, 48, 95, 48, 108, 116, + 114, 48, 69, 114, 117, 69, 118, 120, 114, 119, + 122, 95, 121, 123, 116, 63, 69, 124, 46, 127, + 117, 129, 118, 120, 119, 122, 69, 69, 121, 123, + + 69, 69, 130, 124, 127, 131, 129, 133, 69, 132, + 134, 41, 69, 69, 135, 69, 69, 37, 130, 69, + 78, 131, 78, 133, 132, 30, 134, 78, 78, 135, + 136, 137, 143, 78, 144, 78, 145, 147, 78, 148, + 78, 78, 26, 25, 149, 150, 136, 137, 143, 151, + 144, 152, 145, 147, 148, 156, 157, 158, 78, 78, + 149, 150, 161, 160, 164, 151, 160, 152, 167, 168, + 170, 156, 157, 158, 171, 174, 175, 160, 161, 178, + 164, 170, 179, 186, 167, 168, 174, 187, 180, 189, + 171, 180, 175, 190, 193, 178, 198, 199, 179, 186, + + 200, 201, 180, 187, 201, 189, 205, 23, 190, 205, + 193, 15, 198, 199, 11, 5, 200, 0, 201, 0, + 0, 0, 0, 205, 210, 210, 210, 210, 210, 210, + 210, 211, 0, 0, 0, 211, 211, 212, 212, 212, + 212, 212, 212, 212, 213, 0, 213, 214, 214, 214, + 214, 214, 214, 214, 215, 215, 215, 215, 215, 215, + 215, 216, 216, 216, 0, 216, 216, 216, 217, 0, + 217, 0, 217, 217, 217, 218, 218, 218, 218, 218, + 0, 218, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209 } ; /* The intent behind this definition is that it'll catch @@ -685,7 +692,7 @@ Modify cmFortranLexer.cxx: /*--------------------------------------------------------------------------*/ -#line 689 "cmFortranLexer.cxx" +#line 696 "cmFortranLexer.cxx" #define INITIAL 0 #define free_fmt 1 @@ -956,7 +963,7 @@ YY_DECL #line 65 "cmFortranLexer.in.l" -#line 960 "cmFortranLexer.cxx" +#line 967 "cmFortranLexer.cxx" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -984,13 +991,13 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 199 ) + if ( yy_current_state >= 210 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; ++yy_cp; } - while ( yy_base[yy_current_state] != 572 ); + while ( yy_base[yy_current_state] != 583 ); yy_find_action: yy_act = yy_accept[yy_current_state]; @@ -1201,71 +1208,87 @@ YY_RULE_SETUP #line 148 "cmFortranLexer.in.l" { return DCOLON; } case 37: -/* rule 37 can match eol */ YY_RULE_SETUP -#line 150 "cmFortranLexer.in.l" -{ return GARBAGE; } +#line 149 "cmFortranLexer.in.l" +{ return COLON; } case 38: +/* rule 38 can match eol */ YY_RULE_SETUP -#line 152 "cmFortranLexer.in.l" -{ return ASSIGNMENT_OP; } +#line 151 "cmFortranLexer.in.l" +{ return GARBAGE; } case 39: YY_RULE_SETUP -#line 154 "cmFortranLexer.in.l" -{ return END; } +#line 153 "cmFortranLexer.in.l" +{ return ASSIGNMENT_OP; } case 40: YY_RULE_SETUP #line 155 "cmFortranLexer.in.l" -{ return INCLUDE; } +{ return END; } case 41: YY_RULE_SETUP #line 156 "cmFortranLexer.in.l" -{ return INTERFACE; } +{ return INCLUDE; } case 42: YY_RULE_SETUP #line 157 "cmFortranLexer.in.l" -{ return MODULE; } +{ return INTERFACE; } case 43: YY_RULE_SETUP #line 158 "cmFortranLexer.in.l" -{ return USE; } +{ return MODULE; } case 44: YY_RULE_SETUP +#line 159 "cmFortranLexer.in.l" +{ return SUBMODULE; } +case 45: +YY_RULE_SETUP #line 160 "cmFortranLexer.in.l" +{ return USE; } +case 46: +YY_RULE_SETUP +#line 162 "cmFortranLexer.in.l" { yylvalp->string = strdup(yytext); return WORD; } -case 45: +case 47: +YY_RULE_SETUP +#line 167 "cmFortranLexer.in.l" +{ return LPAREN; } +case 48: +YY_RULE_SETUP +#line 168 "cmFortranLexer.in.l" +{ return RPAREN; } +case 49: YY_RULE_SETUP -#line 165 "cmFortranLexer.in.l" +#line 170 "cmFortranLexer.in.l" { return GARBAGE; } -case 46: -/* rule 46 can match eol */ +case 50: +/* rule 50 can match eol */ YY_RULE_SETUP -#line 167 "cmFortranLexer.in.l" +#line 172 "cmFortranLexer.in.l" { return EOSTMT; } -case 47: +case 51: YY_RULE_SETUP -#line 170 "cmFortranLexer.in.l" +#line 175 "cmFortranLexer.in.l" /* Ignore */ YY_BREAK -case 48: -/* rule 48 can match eol */ +case 52: +/* rule 52 can match eol */ YY_RULE_SETUP -#line 171 "cmFortranLexer.in.l" +#line 176 "cmFortranLexer.in.l" /* Ignore line-endings preceded by \ */ YY_BREAK -case 49: +case 53: YY_RULE_SETUP -#line 173 "cmFortranLexer.in.l" +#line 178 "cmFortranLexer.in.l" { return *yytext; } case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(free_fmt): case YY_STATE_EOF(fixed_fmt): case YY_STATE_EOF(str_sq): case YY_STATE_EOF(str_dq): -#line 175 "cmFortranLexer.in.l" +#line 180 "cmFortranLexer.in.l" { if(!cmFortranParser_FilePop(yyextra) ) { @@ -1273,12 +1296,12 @@ case YY_STATE_EOF(str_dq): } } YY_BREAK -case 50: +case 54: YY_RULE_SETUP -#line 182 "cmFortranLexer.in.l" +#line 187 "cmFortranLexer.in.l" ECHO; YY_BREAK -#line 1320 "cmFortranLexer.cxx" +#line 1347 "cmFortranLexer.cxx" case YY_END_OF_BUFFER: { @@ -1572,7 +1595,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 199 ) + if ( yy_current_state >= 210 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; @@ -1601,11 +1624,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 199 ) + if ( yy_current_state >= 210 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; - yy_is_jam = (yy_current_state == 198); + yy_is_jam = (yy_current_state == 209); (void)yyg; return yy_is_jam ? 0 : yy_current_state; @@ -2447,7 +2470,7 @@ void cmFortran_yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 182 "cmFortranLexer.in.l" +#line 187 "cmFortranLexer.in.l" diff --git a/Source/cmFortranLexer.h b/Source/cmFortranLexer.h index cb175ec..851f37f 100644 --- a/Source/cmFortranLexer.h +++ b/Source/cmFortranLexer.h @@ -337,7 +337,7 @@ extern int cmFortran_yylex (yyscan_t yyscanner); #undef YY_DECL #endif -#line 182 "cmFortranLexer.in.l" +#line 187 "cmFortranLexer.in.l" #line 344 "cmFortranLexer.h" diff --git a/Source/cmFortranLexer.in.l b/Source/cmFortranLexer.in.l index 6870f7c..ea3c132 100644 --- a/Source/cmFortranLexer.in.l +++ b/Source/cmFortranLexer.in.l @@ -146,6 +146,7 @@ $[ \t]*endif { return F90PPR_ENDIF; } , { return COMMA; } :: { return DCOLON; } +: { return COLON; } <fixed_fmt>\n[ ]{5}[^ ] { return GARBAGE; } @@ -155,6 +156,7 @@ $[ \t]*endif { return F90PPR_ENDIF; } [Ii][Nn][Cc][Ll][Uu][Dd][Ee] { return INCLUDE; } [Ii][Nn][Tt][Ee][Rr][Ff][Aa][Cc][Ee] { return INTERFACE; } [Mm][Oo][Dd][Uu][Ll][Ee] { return MODULE; } +[Ss][Uu][bb][Mm][Oo][Dd][Uu][Ll][Ee] { return SUBMODULE; } [Uu][Ss][Ee] { return USE; } [a-zA-Z_][a-zA-Z_0-9]* { @@ -162,7 +164,10 @@ $[ \t]*endif { return F90PPR_ENDIF; } return WORD; } -[^ \t\n\r;,!'"a-zA-Z=&]+ { return GARBAGE; } +\( { return LPAREN; } +\) { return RPAREN; } + +[^ \t\n\r:;,!'"a-zA-Z=&()]+ { return GARBAGE; } ;|\n { return EOSTMT; } diff --git a/Source/cmFortranParser.cxx b/Source/cmFortranParser.cxx index bf4e7c4..2b3e22d 100644 --- a/Source/cmFortranParser.cxx +++ b/Source/cmFortranParser.cxx @@ -192,16 +192,20 @@ extern int cmFortran_yydebug; F90PPR_ELIF = 279, F90PPR_ENDIF = 280, COMMA = 281, - DCOLON = 282, - UNTERMINATED_STRING = 283, - STRING = 284, - WORD = 285, - CPP_INCLUDE_ANGLE = 286, - END = 287, - INCLUDE = 288, - INTERFACE = 289, - MODULE = 290, - USE = 291 + COLON = 282, + DCOLON = 283, + LPAREN = 284, + RPAREN = 285, + UNTERMINATED_STRING = 286, + STRING = 287, + WORD = 288, + CPP_INCLUDE_ANGLE = 289, + END = 290, + INCLUDE = 291, + INTERFACE = 292, + MODULE = 293, + SUBMODULE = 294, + USE = 295 }; #endif /* Tokens. */ @@ -229,16 +233,20 @@ extern int cmFortran_yydebug; #define F90PPR_ELIF 279 #define F90PPR_ENDIF 280 #define COMMA 281 -#define DCOLON 282 -#define UNTERMINATED_STRING 283 -#define STRING 284 -#define WORD 285 -#define CPP_INCLUDE_ANGLE 286 -#define END 287 -#define INCLUDE 288 -#define INTERFACE 289 -#define MODULE 290 -#define USE 291 +#define COLON 282 +#define DCOLON 283 +#define LPAREN 284 +#define RPAREN 285 +#define UNTERMINATED_STRING 286 +#define STRING 287 +#define WORD 288 +#define CPP_INCLUDE_ANGLE 289 +#define END 290 +#define INCLUDE 291 +#define INTERFACE 292 +#define MODULE 293 +#define SUBMODULE 294 +#define USE 295 /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED @@ -249,7 +257,7 @@ union YYSTYPE char* string; -#line 253 "cmFortranParser.cxx" /* yacc.c:355 */ +#line 261 "cmFortranParser.cxx" /* yacc.c:355 */ }; typedef union YYSTYPE YYSTYPE; @@ -265,7 +273,7 @@ int cmFortran_yyparse (yyscan_t yyscanner); /* Copy the second part of user declarations. */ -#line 269 "cmFortranParser.cxx" /* yacc.c:358 */ +#line 277 "cmFortranParser.cxx" /* yacc.c:358 */ #ifdef short # undef short @@ -507,21 +515,21 @@ union yyalloc /* YYFINAL -- State number of the termination state. */ #define YYFINAL 2 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 469 +#define YYLAST 593 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 37 +#define YYNTOKENS 41 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 14 /* YYNRULES -- Number of rules. */ -#define YYNRULES 57 +#define YYNRULES 63 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 109 +#define YYNSTATES 126 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned by yylex, with out-of-bounds checking. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 291 +#define YYMAXUTOK 295 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) @@ -559,19 +567,20 @@ static const yytype_uint8 yytranslate[] = 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36 + 35, 36, 37, 38, 39, 40 }; #if YYDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 102, 102, 102, 105, 109, 114, 119, 124, 128, - 133, 141, 146, 151, 156, 161, 166, 171, 176, 181, - 185, 189, 193, 197, 198, 203, 203, 203, 204, 204, - 205, 205, 206, 206, 207, 207, 208, 208, 209, 209, - 210, 210, 211, 211, 212, 212, 215, 216, 217, 218, - 219, 220, 221, 222, 223, 224, 225, 226 + 0, 103, 103, 103, 106, 110, 115, 124, 130, 137, + 142, 146, 151, 159, 164, 169, 174, 179, 184, 189, + 194, 199, 203, 207, 211, 215, 216, 221, 221, 221, + 222, 222, 223, 223, 224, 224, 225, 225, 226, 226, + 227, 227, 228, 228, 229, 229, 230, 230, 233, 234, + 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, + 245, 246, 247, 248 }; #endif @@ -585,10 +594,11 @@ static const char *const yytname[] = "F90PPR_DEFINE", "CPP_DEFINE", "F90PPR_UNDEF", "CPP_UNDEF", "CPP_IFDEF", "CPP_IFNDEF", "CPP_IF", "CPP_ELSE", "CPP_ELIF", "CPP_ENDIF", "F90PPR_IFDEF", "F90PPR_IFNDEF", "F90PPR_IF", "F90PPR_ELSE", - "F90PPR_ELIF", "F90PPR_ENDIF", "COMMA", "DCOLON", "UNTERMINATED_STRING", - "STRING", "WORD", "CPP_INCLUDE_ANGLE", "END", "INCLUDE", "INTERFACE", - "MODULE", "USE", "$accept", "code", "stmt", "include", "define", "undef", - "ifdef", "ifndef", "if", "elif", "else", "endif", "other", "misc_code", YY_NULLPTR + "F90PPR_ELIF", "F90PPR_ENDIF", "COMMA", "COLON", "DCOLON", "LPAREN", + "RPAREN", "UNTERMINATED_STRING", "STRING", "WORD", "CPP_INCLUDE_ANGLE", + "END", "INCLUDE", "INTERFACE", "MODULE", "SUBMODULE", "USE", "$accept", + "code", "stmt", "include", "define", "undef", "ifdef", "ifndef", "if", + "elif", "else", "endif", "other", "misc_code", YY_NULLPTR }; #endif @@ -600,14 +610,15 @@ static const yytype_uint16 yytoknum[] = 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, 287, 288, 289, 290, 291 + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + 295 }; # endif -#define YYPACT_NINF -38 +#define YYPACT_NINF -39 #define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-38))) + (!!((Yystate) == (-39))) #define YYTABLE_NINF -1 @@ -618,17 +629,19 @@ static const yytype_uint16 yytoknum[] = STATE-NUM. */ static const yytype_int16 yypact[] = { - -38, 39, -38, 3, -38, -20, -38, -38, -38, -38, - -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, - -38, -38, -38, -38, -38, -38, -22, -16, 1, -8, - -6, -38, -4, -7, -3, -2, -1, -38, -38, -38, - -38, -38, -38, 62, -38, -38, -38, -38, -38, 0, - 2, -38, -38, -38, -38, -38, -38, 73, 107, 118, - 152, 163, -38, -38, -38, -38, -38, -38, -38, -38, - -38, -38, -38, -38, -38, -38, 197, 208, 242, 253, - 6, -38, 287, 298, 332, 343, 377, 388, -38, -38, - -38, -38, -38, -38, -38, -38, -38, 4, 422, -38, - -38, -38, -38, -38, -38, -38, -38, 433, -38 + -39, 21, -39, 1, -39, -20, -39, -39, -39, -39, + -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, + -39, -39, -39, -39, -39, -39, -24, -18, 20, -8, + -3, 39, -39, 15, 16, 18, 19, 33, -39, -39, + -39, -39, -39, -39, 59, -39, -39, -39, -39, -39, + 35, 36, 37, -39, -39, -39, -39, -39, -39, 76, + 114, 129, 167, 182, -39, -39, -39, -39, -39, -39, + -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, + -39, -39, 220, 235, 273, 288, -21, 26, -39, 326, + 341, 379, 394, 432, 447, -39, -39, -39, -39, -39, + -39, -39, -39, -39, 38, 40, 41, 485, -39, -39, + -39, -39, -39, -39, 45, -39, -39, -39, 43, 500, + 538, -39, -39, -39, 553, -39 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. @@ -636,31 +649,33 @@ static const yytype_int16 yypact[] = means the default is an error. */ static const yytype_uint8 yydefact[] = { - 2, 0, 1, 0, 23, 0, 25, 26, 27, 29, - 28, 31, 30, 32, 34, 36, 40, 38, 42, 33, - 35, 37, 41, 39, 43, 44, 0, 0, 0, 0, - 0, 3, 0, 0, 0, 0, 0, 44, 44, 44, - 44, 24, 44, 0, 44, 44, 4, 44, 44, 0, - 0, 44, 44, 44, 44, 44, 44, 0, 0, 0, - 0, 0, 13, 54, 53, 56, 55, 57, 52, 46, - 47, 48, 49, 50, 51, 45, 0, 0, 0, 0, - 0, 44, 0, 0, 0, 0, 0, 0, 19, 20, - 21, 22, 12, 8, 11, 7, 6, 0, 0, 5, - 14, 15, 16, 17, 18, 44, 9, 0, 10 + 2, 0, 1, 0, 25, 0, 27, 28, 29, 31, + 30, 33, 32, 34, 36, 38, 42, 40, 44, 35, + 37, 39, 43, 41, 45, 46, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, 0, 0, 46, 46, + 46, 46, 26, 46, 0, 46, 46, 4, 46, 46, + 0, 0, 0, 46, 46, 46, 46, 46, 46, 0, + 0, 0, 0, 0, 15, 57, 56, 62, 58, 59, + 60, 61, 63, 55, 48, 49, 50, 51, 52, 53, + 54, 47, 0, 0, 0, 0, 0, 0, 46, 0, + 0, 0, 0, 0, 0, 21, 22, 23, 24, 14, + 10, 13, 9, 6, 0, 0, 0, 0, 5, 16, + 17, 18, 19, 20, 0, 46, 46, 11, 0, 0, + 0, 46, 7, 12, 0, 8 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { - -38, -38, -38, -38, -38, -38, -38, -38, -38, -38, - -38, -38, -37, -38 + -39, -39, -39, -39, -39, -39, -39, -39, -39, -39, + -39, -39, -38, -39 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int8 yydefgoto[] = { - -1, 1, 31, 32, 33, 34, 35, 36, 37, 38, - 39, 40, 43, 75 + -1, 1, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 44, 81 }; /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If @@ -668,143 +683,173 @@ static const yytype_int8 yydefgoto[] = number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_uint8 yytable[] = { - 57, 58, 59, 60, 46, 61, 41, 76, 77, 42, - 78, 79, 44, 45, 82, 83, 84, 85, 86, 87, - 49, 50, 48, 53, 51, 52, 0, 54, 55, 56, - 80, 47, 81, 97, 105, 0, 0, 0, 0, 2, - 3, 0, 4, 0, 98, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 62, 63, 64, 107, 0, - 25, 26, 27, 28, 29, 30, 88, 63, 64, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 65, 66, - 67, 68, 69, 0, 70, 71, 72, 73, 74, 65, - 66, 67, 68, 69, 0, 70, 71, 72, 73, 74, - 89, 63, 64, 0, 0, 0, 0, 0, 0, 0, - 0, 90, 63, 64, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 65, 66, 67, 68, 69, 0, 70, - 71, 72, 73, 74, 65, 66, 67, 68, 69, 0, - 70, 71, 72, 73, 74, 91, 63, 64, 0, 0, - 0, 0, 0, 0, 0, 0, 92, 63, 64, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 65, 66, - 67, 68, 69, 0, 70, 71, 72, 73, 74, 65, - 66, 67, 68, 69, 0, 70, 71, 72, 73, 74, - 93, 63, 64, 0, 0, 0, 0, 0, 0, 0, - 0, 94, 63, 64, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 65, 66, 67, 68, 69, 0, 70, - 71, 72, 73, 74, 65, 66, 67, 68, 69, 0, - 70, 71, 72, 73, 74, 95, 63, 64, 0, 0, - 0, 0, 0, 0, 0, 0, 96, 63, 64, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 65, 66, - 67, 68, 69, 0, 70, 71, 72, 73, 74, 65, - 66, 67, 68, 69, 0, 70, 71, 72, 73, 74, - 99, 63, 64, 0, 0, 0, 0, 0, 0, 0, - 0, 100, 63, 64, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 65, 66, 67, 68, 69, 0, 70, - 71, 72, 73, 74, 65, 66, 67, 68, 69, 0, - 70, 71, 72, 73, 74, 101, 63, 64, 0, 0, - 0, 0, 0, 0, 0, 0, 102, 63, 64, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 65, 66, - 67, 68, 69, 0, 70, 71, 72, 73, 74, 65, - 66, 67, 68, 69, 0, 70, 71, 72, 73, 74, - 103, 63, 64, 0, 0, 0, 0, 0, 0, 0, - 0, 104, 63, 64, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 65, 66, 67, 68, 69, 0, 70, - 71, 72, 73, 74, 65, 66, 67, 68, 69, 0, - 70, 71, 72, 73, 74, 106, 63, 64, 0, 0, - 0, 0, 0, 0, 0, 0, 108, 63, 64, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 65, 66, - 67, 68, 69, 0, 70, 71, 72, 73, 74, 65, - 66, 67, 68, 69, 0, 70, 71, 72, 73, 74 + 59, 60, 61, 62, 42, 63, 104, 82, 83, 105, + 84, 85, 43, 45, 46, 89, 90, 91, 92, 93, + 94, 2, 3, 47, 4, 49, 50, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 54, 0, 55, + 107, 56, 57, 48, 106, 25, 26, 27, 28, 29, + 30, 31, 64, 65, 66, 51, 58, 52, 86, 87, + 88, 114, 53, 115, 116, 118, 121, 119, 120, 95, + 65, 66, 0, 124, 0, 67, 68, 69, 70, 71, + 72, 73, 74, 0, 75, 76, 77, 78, 79, 80, + 0, 0, 67, 68, 69, 70, 71, 72, 73, 74, + 0, 75, 76, 77, 78, 79, 80, 96, 65, 66, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 97, 65, 66, 0, 0, 0, 0, 0, + 67, 68, 69, 70, 71, 72, 73, 74, 0, 75, + 76, 77, 78, 79, 80, 67, 68, 69, 70, 71, + 72, 73, 74, 0, 75, 76, 77, 78, 79, 80, + 98, 65, 66, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 99, 65, 66, 0, 0, + 0, 0, 0, 67, 68, 69, 70, 71, 72, 73, + 74, 0, 75, 76, 77, 78, 79, 80, 67, 68, + 69, 70, 71, 72, 73, 74, 0, 75, 76, 77, + 78, 79, 80, 100, 65, 66, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 101, 65, + 66, 0, 0, 0, 0, 0, 67, 68, 69, 70, + 71, 72, 73, 74, 0, 75, 76, 77, 78, 79, + 80, 67, 68, 69, 70, 71, 72, 73, 74, 0, + 75, 76, 77, 78, 79, 80, 102, 65, 66, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 103, 65, 66, 0, 0, 0, 0, 0, 67, + 68, 69, 70, 71, 72, 73, 74, 0, 75, 76, + 77, 78, 79, 80, 67, 68, 69, 70, 71, 72, + 73, 74, 0, 75, 76, 77, 78, 79, 80, 108, + 65, 66, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 109, 65, 66, 0, 0, 0, + 0, 0, 67, 68, 69, 70, 71, 72, 73, 74, + 0, 75, 76, 77, 78, 79, 80, 67, 68, 69, + 70, 71, 72, 73, 74, 0, 75, 76, 77, 78, + 79, 80, 110, 65, 66, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 111, 65, 66, + 0, 0, 0, 0, 0, 67, 68, 69, 70, 71, + 72, 73, 74, 0, 75, 76, 77, 78, 79, 80, + 67, 68, 69, 70, 71, 72, 73, 74, 0, 75, + 76, 77, 78, 79, 80, 112, 65, 66, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 113, 65, 66, 0, 0, 0, 0, 0, 67, 68, + 69, 70, 71, 72, 73, 74, 0, 75, 76, 77, + 78, 79, 80, 67, 68, 69, 70, 71, 72, 73, + 74, 0, 75, 76, 77, 78, 79, 80, 117, 65, + 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 122, 65, 66, 0, 0, 0, 0, + 0, 67, 68, 69, 70, 71, 72, 73, 74, 0, + 75, 76, 77, 78, 79, 80, 67, 68, 69, 70, + 71, 72, 73, 74, 0, 75, 76, 77, 78, 79, + 80, 123, 65, 66, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 125, 65, 66, 0, + 0, 0, 0, 0, 67, 68, 69, 70, 71, 72, + 73, 74, 0, 75, 76, 77, 78, 79, 80, 67, + 68, 69, 70, 71, 72, 73, 74, 0, 75, 76, + 77, 78, 79, 80 }; static const yytype_int8 yycheck[] = { - 37, 38, 39, 40, 3, 42, 3, 44, 45, 29, - 47, 48, 34, 29, 51, 52, 53, 54, 55, 56, - 26, 27, 30, 30, 30, 29, -1, 30, 30, 30, - 30, 30, 30, 27, 30, -1, -1, -1, -1, 0, - 1, -1, 3, -1, 81, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 3, 4, 5, 105, -1, - 31, 32, 33, 34, 35, 36, 3, 4, 5, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, - 28, 29, 30, -1, 32, 33, 34, 35, 36, 26, - 27, 28, 29, 30, -1, 32, 33, 34, 35, 36, - 3, 4, 5, -1, -1, -1, -1, -1, -1, -1, - -1, 3, 4, 5, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 26, 27, 28, 29, 30, -1, 32, - 33, 34, 35, 36, 26, 27, 28, 29, 30, -1, - 32, 33, 34, 35, 36, 3, 4, 5, -1, -1, - -1, -1, -1, -1, -1, -1, 3, 4, 5, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, - 28, 29, 30, -1, 32, 33, 34, 35, 36, 26, - 27, 28, 29, 30, -1, 32, 33, 34, 35, 36, - 3, 4, 5, -1, -1, -1, -1, -1, -1, -1, - -1, 3, 4, 5, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 26, 27, 28, 29, 30, -1, 32, - 33, 34, 35, 36, 26, 27, 28, 29, 30, -1, - 32, 33, 34, 35, 36, 3, 4, 5, -1, -1, - -1, -1, -1, -1, -1, -1, 3, 4, 5, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, - 28, 29, 30, -1, 32, 33, 34, 35, 36, 26, - 27, 28, 29, 30, -1, 32, 33, 34, 35, 36, + 38, 39, 40, 41, 3, 43, 27, 45, 46, 30, + 48, 49, 32, 37, 32, 53, 54, 55, 56, 57, + 58, 0, 1, 3, 3, 33, 29, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 32, -1, 33, + 88, 33, 33, 33, 28, 34, 35, 36, 37, 38, + 39, 40, 3, 4, 5, 26, 33, 28, 33, 33, + 33, 33, 33, 33, 33, 30, 33, 115, 116, 3, + 4, 5, -1, 121, -1, 26, 27, 28, 29, 30, + 31, 32, 33, -1, 35, 36, 37, 38, 39, 40, + -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, + -1, 35, 36, 37, 38, 39, 40, 3, 4, 5, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 3, 4, 5, -1, -1, -1, -1, -1, + 26, 27, 28, 29, 30, 31, 32, 33, -1, 35, + 36, 37, 38, 39, 40, 26, 27, 28, 29, 30, + 31, 32, 33, -1, 35, 36, 37, 38, 39, 40, 3, 4, 5, -1, -1, -1, -1, -1, -1, -1, - -1, 3, 4, 5, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 26, 27, 28, 29, 30, -1, 32, - 33, 34, 35, 36, 26, 27, 28, 29, 30, -1, - 32, 33, 34, 35, 36, 3, 4, 5, -1, -1, + -1, -1, -1, -1, -1, 3, 4, 5, -1, -1, + -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, + 33, -1, 35, 36, 37, 38, 39, 40, 26, 27, + 28, 29, 30, 31, 32, 33, -1, 35, 36, 37, + 38, 39, 40, 3, 4, 5, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 3, 4, + 5, -1, -1, -1, -1, -1, 26, 27, 28, 29, + 30, 31, 32, 33, -1, 35, 36, 37, 38, 39, + 40, 26, 27, 28, 29, 30, 31, 32, 33, -1, + 35, 36, 37, 38, 39, 40, 3, 4, 5, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 3, 4, 5, -1, -1, -1, -1, -1, 26, + 27, 28, 29, 30, 31, 32, 33, -1, 35, 36, + 37, 38, 39, 40, 26, 27, 28, 29, 30, 31, + 32, 33, -1, 35, 36, 37, 38, 39, 40, 3, + 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 3, 4, 5, -1, -1, -1, + -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, + -1, 35, 36, 37, 38, 39, 40, 26, 27, 28, + 29, 30, 31, 32, 33, -1, 35, 36, 37, 38, + 39, 40, 3, 4, 5, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 3, 4, 5, + -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, + 31, 32, 33, -1, 35, 36, 37, 38, 39, 40, + 26, 27, 28, 29, 30, 31, 32, 33, -1, 35, + 36, 37, 38, 39, 40, 3, 4, 5, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 3, 4, 5, -1, -1, -1, -1, -1, 26, 27, + 28, 29, 30, 31, 32, 33, -1, 35, 36, 37, + 38, 39, 40, 26, 27, 28, 29, 30, 31, 32, + 33, -1, 35, 36, 37, 38, 39, 40, 3, 4, + 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 3, 4, 5, -1, -1, -1, -1, + -1, 26, 27, 28, 29, 30, 31, 32, 33, -1, + 35, 36, 37, 38, 39, 40, 26, 27, 28, 29, + 30, 31, 32, 33, -1, 35, 36, 37, 38, 39, + 40, 3, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 4, 5, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, - 28, 29, 30, -1, 32, 33, 34, 35, 36, 26, - 27, 28, 29, 30, -1, 32, 33, 34, 35, 36, - 3, 4, 5, -1, -1, -1, -1, -1, -1, -1, - -1, 3, 4, 5, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 26, 27, 28, 29, 30, -1, 32, - 33, 34, 35, 36, 26, 27, 28, 29, 30, -1, - 32, 33, 34, 35, 36, 3, 4, 5, -1, -1, - -1, -1, -1, -1, -1, -1, 3, 4, 5, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, - 28, 29, 30, -1, 32, 33, 34, 35, 36, 26, - 27, 28, 29, 30, -1, 32, 33, 34, 35, 36 + -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, + 32, 33, -1, 35, 36, 37, 38, 39, 40, 26, + 27, 28, 29, 30, 31, 32, 33, -1, 35, 36, + 37, 38, 39, 40 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { - 0, 38, 0, 1, 3, 6, 7, 8, 9, 10, + 0, 42, 0, 1, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 31, 32, 33, 34, 35, - 36, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 3, 29, 49, 34, 29, 3, 30, 30, 26, - 27, 30, 29, 30, 30, 30, 30, 49, 49, 49, - 49, 49, 3, 4, 5, 26, 27, 28, 29, 30, - 32, 33, 34, 35, 36, 50, 49, 49, 49, 49, - 30, 30, 49, 49, 49, 49, 49, 49, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 27, 49, 3, - 3, 3, 3, 3, 3, 30, 3, 49, 3 + 21, 22, 23, 24, 25, 34, 35, 36, 37, 38, + 39, 40, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 3, 32, 53, 37, 32, 3, 33, 33, + 29, 26, 28, 33, 32, 33, 33, 33, 33, 53, + 53, 53, 53, 53, 3, 4, 5, 26, 27, 28, + 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, + 40, 54, 53, 53, 53, 53, 33, 33, 33, 53, + 53, 53, 53, 53, 53, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 27, 30, 28, 53, 3, 3, + 3, 3, 3, 3, 33, 33, 33, 3, 30, 53, + 53, 33, 3, 3, 53, 3 }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint8 yyr1[] = { - 0, 37, 38, 38, 39, 39, 39, 39, 39, 39, - 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, - 39, 39, 39, 39, 39, 40, 40, 40, 41, 41, - 42, 42, 43, 43, 44, 44, 45, 45, 46, 46, - 47, 47, 48, 48, 49, 49, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50 + 0, 41, 42, 42, 43, 43, 43, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 43, 44, 44, 44, + 45, 45, 46, 46, 47, 47, 48, 48, 49, 49, + 50, 50, 51, 51, 52, 52, 53, 53, 54, 54, + 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, + 54, 54, 54, 54 }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ static const yytype_uint8 yyr2[] = { - 0, 2, 0, 2, 2, 4, 4, 4, 4, 5, - 7, 4, 4, 3, 4, 4, 4, 4, 4, 3, - 3, 3, 3, 1, 2, 1, 1, 1, 1, 1, + 0, 2, 0, 2, 2, 4, 4, 7, 9, 4, + 4, 5, 7, 4, 4, 3, 4, 4, 4, 4, + 4, 3, 3, 3, 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 0, 2, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1 + 1, 1, 1, 1, 1, 1, 0, 2, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1 }; @@ -1487,65 +1532,92 @@ yyreduce: switch (yyn) { case 4: -#line 105 "cmFortranParser.y" /* yacc.c:1646 */ +#line 106 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_SetInInterface(parser, true); } -#line 1496 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1541 "cmFortranParser.cxx" /* yacc.c:1646 */ break; case 5: -#line 109 "cmFortranParser.y" /* yacc.c:1646 */ +#line 110 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleUse(parser, (yyvsp[-2].string)); free((yyvsp[-2].string)); } -#line 1506 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1551 "cmFortranParser.cxx" /* yacc.c:1646 */ break; case 6: -#line 114 "cmFortranParser.y" /* yacc.c:1646 */ +#line 115 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); - cmFortranParser_RuleModule(parser, (yyvsp[-2].string)); + if (cmsysString_strcasecmp((yyvsp[-2].string), "function") != 0 && + cmsysString_strcasecmp((yyvsp[-2].string), "procedure") != 0 && + cmsysString_strcasecmp((yyvsp[-2].string), "subroutine") != 0) { + cmFortranParser_RuleModule(parser, (yyvsp[-2].string)); + } free((yyvsp[-2].string)); } -#line 1516 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1565 "cmFortranParser.cxx" /* yacc.c:1646 */ break; case 7: -#line 119 "cmFortranParser.y" /* yacc.c:1646 */ +#line 124 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); - cmFortranParser_SetInInterface(parser, true); + cmFortranParser_RuleUse(parser, (yyvsp[-4].string)); + free((yyvsp[-4].string)); free((yyvsp[-2].string)); } -#line 1526 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1576 "cmFortranParser.cxx" /* yacc.c:1646 */ break; case 8: -#line 124 "cmFortranParser.y" /* yacc.c:1646 */ +#line 130 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); - cmFortranParser_SetInInterface(parser, false); + cmFortranParser_RuleUse(parser, (yyvsp[-6].string)); + free((yyvsp[-6].string)); + free((yyvsp[-4].string)); + free((yyvsp[-2].string)); } -#line 1535 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1588 "cmFortranParser.cxx" /* yacc.c:1646 */ break; case 9: -#line 128 "cmFortranParser.y" /* yacc.c:1646 */ +#line 137 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); - cmFortranParser_RuleUse(parser, (yyvsp[-2].string)); + cmFortranParser_SetInInterface(parser, true); free((yyvsp[-2].string)); } -#line 1545 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1598 "cmFortranParser.cxx" /* yacc.c:1646 */ break; case 10: -#line 133 "cmFortranParser.y" /* yacc.c:1646 */ +#line 142 "cmFortranParser.y" /* yacc.c:1646 */ + { + cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); + cmFortranParser_SetInInterface(parser, false); + } +#line 1607 "cmFortranParser.cxx" /* yacc.c:1646 */ + break; + + case 11: +#line 146 "cmFortranParser.y" /* yacc.c:1646 */ + { + cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); + cmFortranParser_RuleUse(parser, (yyvsp[-2].string)); + free((yyvsp[-2].string)); + } +#line 1617 "cmFortranParser.cxx" /* yacc.c:1646 */ + break; + + case 12: +#line 151 "cmFortranParser.y" /* yacc.c:1646 */ { if (cmsysString_strcasecmp((yyvsp[-4].string), "non_intrinsic") == 0) { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); @@ -1554,139 +1626,139 @@ yyreduce: free((yyvsp[-4].string)); free((yyvsp[-2].string)); } -#line 1558 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1630 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 11: -#line 141 "cmFortranParser.y" /* yacc.c:1646 */ + case 13: +#line 159 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleInclude(parser, (yyvsp[-2].string)); free((yyvsp[-2].string)); } -#line 1568 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1640 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 12: -#line 146 "cmFortranParser.y" /* yacc.c:1646 */ + case 14: +#line 164 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleLineDirective(parser, (yyvsp[-2].string)); free((yyvsp[-2].string)); } -#line 1578 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1650 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 13: -#line 151 "cmFortranParser.y" /* yacc.c:1646 */ + case 15: +#line 169 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleInclude(parser, (yyvsp[-2].string)); free((yyvsp[-2].string)); } -#line 1588 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1660 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 14: -#line 156 "cmFortranParser.y" /* yacc.c:1646 */ + case 16: +#line 174 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleInclude(parser, (yyvsp[-2].string)); free((yyvsp[-2].string)); } -#line 1598 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1670 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 15: -#line 161 "cmFortranParser.y" /* yacc.c:1646 */ + case 17: +#line 179 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleDefine(parser, (yyvsp[-2].string)); free((yyvsp[-2].string)); } -#line 1608 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1680 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 16: -#line 166 "cmFortranParser.y" /* yacc.c:1646 */ + case 18: +#line 184 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleUndef(parser, (yyvsp[-2].string)); free((yyvsp[-2].string)); } -#line 1618 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1690 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 17: -#line 171 "cmFortranParser.y" /* yacc.c:1646 */ + case 19: +#line 189 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleIfdef(parser, (yyvsp[-2].string)); free((yyvsp[-2].string)); } -#line 1628 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1700 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 18: -#line 176 "cmFortranParser.y" /* yacc.c:1646 */ + case 20: +#line 194 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleIfndef(parser, (yyvsp[-2].string)); free((yyvsp[-2].string)); } -#line 1638 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1710 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 19: -#line 181 "cmFortranParser.y" /* yacc.c:1646 */ + case 21: +#line 199 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleIf(parser); } -#line 1647 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1719 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 20: -#line 185 "cmFortranParser.y" /* yacc.c:1646 */ + case 22: +#line 203 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleElif(parser); } -#line 1656 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1728 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 21: -#line 189 "cmFortranParser.y" /* yacc.c:1646 */ + case 23: +#line 207 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleElse(parser); } -#line 1665 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1737 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 22: -#line 193 "cmFortranParser.y" /* yacc.c:1646 */ + case 24: +#line 211 "cmFortranParser.y" /* yacc.c:1646 */ { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_RuleEndif(parser); } -#line 1674 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1746 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 46: -#line 215 "cmFortranParser.y" /* yacc.c:1646 */ + case 48: +#line 233 "cmFortranParser.y" /* yacc.c:1646 */ { free ((yyvsp[0].string)); } -#line 1680 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1752 "cmFortranParser.cxx" /* yacc.c:1646 */ break; - case 52: -#line 221 "cmFortranParser.y" /* yacc.c:1646 */ + case 55: +#line 240 "cmFortranParser.y" /* yacc.c:1646 */ { free ((yyvsp[0].string)); } -#line 1686 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1758 "cmFortranParser.cxx" /* yacc.c:1646 */ break; -#line 1690 "cmFortranParser.cxx" /* yacc.c:1646 */ +#line 1762 "cmFortranParser.cxx" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1916,6 +1988,6 @@ yyreturn: #endif return yyresult; } -#line 229 "cmFortranParser.y" /* yacc.c:1906 */ +#line 251 "cmFortranParser.y" /* yacc.c:1906 */ /* End of grammar */ diff --git a/Source/cmFortranParser.y b/Source/cmFortranParser.y index b856a1a..d3327e9 100644 --- a/Source/cmFortranParser.y +++ b/Source/cmFortranParser.y @@ -85,7 +85,7 @@ static void cmFortran_yyerror(yyscan_t yyscanner, const char* message) %token CPP_IFDEF CPP_IFNDEF CPP_IF CPP_ELSE CPP_ELIF CPP_ENDIF %token F90PPR_IFDEF F90PPR_IFNDEF F90PPR_IF %token F90PPR_ELSE F90PPR_ELIF F90PPR_ENDIF -%token COMMA DCOLON +%token COMMA COLON DCOLON LPAREN RPAREN %token <number> UNTERMINATED_STRING %token <string> STRING WORD %token <string> CPP_INCLUDE_ANGLE @@ -93,6 +93,7 @@ static void cmFortran_yyerror(yyscan_t yyscanner, const char* message) %token INCLUDE %token INTERFACE %token MODULE +%token SUBMODULE %token USE /*-------------------------------------------------------------------------*/ @@ -113,9 +114,26 @@ stmt: } | MODULE WORD other EOSTMT { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); - cmFortranParser_RuleModule(parser, $2); + if (cmsysString_strcasecmp($2, "function") != 0 && + cmsysString_strcasecmp($2, "procedure") != 0 && + cmsysString_strcasecmp($2, "subroutine") != 0) { + cmFortranParser_RuleModule(parser, $2); + } free($2); } +| SUBMODULE LPAREN WORD RPAREN WORD other EOSTMT { + cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); + cmFortranParser_RuleUse(parser, $3); + free($3); + free($5); + } +| SUBMODULE LPAREN WORD COLON WORD RPAREN WORD other EOSTMT { + cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); + cmFortranParser_RuleUse(parser, $3); + free($3); + free($5); + free($7); + } | INTERFACE WORD other EOSTMT { cmFortranParser* parser = cmFortran_yyget_extra(yyscanner); cmFortranParser_SetInInterface(parser, true); @@ -217,11 +235,15 @@ misc_code: | INCLUDE | INTERFACE | MODULE +| SUBMODULE | USE | STRING { free ($1); } | GARBAGE | ASSIGNMENT_OP +| COLON | DCOLON +| LPAREN +| RPAREN | COMMA | UNTERMINATED_STRING ; diff --git a/Source/cmFortranParserTokens.h b/Source/cmFortranParserTokens.h index e988df4..18b9e0a 100644 --- a/Source/cmFortranParserTokens.h +++ b/Source/cmFortranParserTokens.h @@ -69,16 +69,20 @@ extern int cmFortran_yydebug; F90PPR_ELIF = 279, F90PPR_ENDIF = 280, COMMA = 281, - DCOLON = 282, - UNTERMINATED_STRING = 283, - STRING = 284, - WORD = 285, - CPP_INCLUDE_ANGLE = 286, - END = 287, - INCLUDE = 288, - INTERFACE = 289, - MODULE = 290, - USE = 291 + COLON = 282, + DCOLON = 283, + LPAREN = 284, + RPAREN = 285, + UNTERMINATED_STRING = 286, + STRING = 287, + WORD = 288, + CPP_INCLUDE_ANGLE = 289, + END = 290, + INCLUDE = 291, + INTERFACE = 292, + MODULE = 293, + SUBMODULE = 294, + USE = 295 }; #endif /* Tokens. */ @@ -106,16 +110,20 @@ extern int cmFortran_yydebug; #define F90PPR_ELIF 279 #define F90PPR_ENDIF 280 #define COMMA 281 -#define DCOLON 282 -#define UNTERMINATED_STRING 283 -#define STRING 284 -#define WORD 285 -#define CPP_INCLUDE_ANGLE 286 -#define END 287 -#define INCLUDE 288 -#define INTERFACE 289 -#define MODULE 290 -#define USE 291 +#define COLON 282 +#define DCOLON 283 +#define LPAREN 284 +#define RPAREN 285 +#define UNTERMINATED_STRING 286 +#define STRING 287 +#define WORD 288 +#define CPP_INCLUDE_ANGLE 289 +#define END 290 +#define INCLUDE 291 +#define INTERFACE 292 +#define MODULE 293 +#define SUBMODULE 294 +#define USE 295 /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED @@ -126,7 +134,7 @@ union YYSTYPE char* string; -#line 130 "cmFortranParserTokens.h" /* yacc.c:1909 */ +#line 138 "cmFortranParserTokens.h" /* yacc.c:1909 */ }; typedef union YYSTYPE YYSTYPE; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 1e21ac4..f181cf6 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3883,23 +3883,35 @@ void cmGeneratorTarget::GetTargetVersion(bool soversion, int& major, } } -std::string cmGeneratorTarget::GetFortranModuleDirectory() const +std::string cmGeneratorTarget::GetFortranModuleDirectory( + std::string const& working_dir) const { if (!this->FortranModuleDirectoryCreated) { this->FortranModuleDirectory = true; - this->FortranModuleDirectory = this->CreateFortranModuleDirectory(); + this->FortranModuleDirectory = + this->CreateFortranModuleDirectory(working_dir); } return this->FortranModuleDirectory; } -std::string cmGeneratorTarget::CreateFortranModuleDirectory() const +std::string cmGeneratorTarget::CreateFortranModuleDirectory( + std::string const& working_dir) const { std::string mod_dir; - const char* target_mod_dir = this->GetProperty("Fortran_MODULE_DIRECTORY"); + std::string target_mod_dir; + if (const char* prop = this->GetProperty("Fortran_MODULE_DIRECTORY")) { + target_mod_dir = prop; + } else { + std::string const& default_mod_dir = + this->LocalGenerator->GetCurrentBinaryDirectory(); + if (default_mod_dir != working_dir) { + target_mod_dir = default_mod_dir; + } + } const char* moddir_flag = this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG"); - if (target_mod_dir && moddir_flag) { + if (!target_mod_dir.empty() && moddir_flag) { // Compute the full path to the module directory. if (cmSystemTools::FileIsFullPath(target_mod_dir)) { // Already a full path. diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 715220e..8e17b8f 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -537,12 +537,13 @@ public: void GetTargetVersion(bool soversion, int& major, int& minor, int& patch) const; - std::string GetFortranModuleDirectory() const; + std::string GetFortranModuleDirectory(std::string const& working_dir) const; private: void AddSourceCommon(const std::string& src); - std::string CreateFortranModuleDirectory() const; + std::string CreateFortranModuleDirectory( + std::string const& working_dir) const; mutable bool FortranModuleDirectoryCreated; mutable std::string FortranModuleDirectory; diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index bd65366..b913621 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -140,10 +140,10 @@ std::string cmGlobalNinjaGenerator::EncodeDepfileSpace(const std::string& path) void cmGlobalNinjaGenerator::WriteBuild( std::ostream& os, const std::string& comment, const std::string& rule, - const cmNinjaDeps& outputs, const cmNinjaDeps& explicitDeps, - const cmNinjaDeps& implicitDeps, const cmNinjaDeps& orderOnlyDeps, - const cmNinjaVars& variables, const std::string& rspfile, int cmdLineLimit, - bool* usedResponseFile) + const cmNinjaDeps& outputs, const cmNinjaDeps& implicitOuts, + const cmNinjaDeps& explicitDeps, const cmNinjaDeps& implicitDeps, + const cmNinjaDeps& orderOnlyDeps, const cmNinjaVars& variables, + const std::string& rspfile, int cmdLineLimit, bool* usedResponseFile) { // Make sure there is a rule. if (rule.empty()) { @@ -204,6 +204,13 @@ void cmGlobalNinjaGenerator::WriteBuild( this->CombinedBuildOutputs.insert(EncodePath(*i)); } } + if (!implicitOuts.empty()) { + build += " |"; + for (cmNinjaDeps::const_iterator i = implicitOuts.begin(); + i != implicitOuts.end(); ++i) { + build += " " + EncodeIdent(EncodePath(*i), os); + } + } build += ":"; // Write the rule. @@ -244,7 +251,8 @@ void cmGlobalNinjaGenerator::WritePhonyBuild( const cmNinjaDeps& explicitDeps, const cmNinjaDeps& implicitDeps, const cmNinjaDeps& orderOnlyDeps, const cmNinjaVars& variables) { - this->WriteBuild(os, comment, "phony", outputs, explicitDeps, implicitDeps, + this->WriteBuild(os, comment, "phony", outputs, + /*implicitOuts=*/cmNinjaDeps(), explicitDeps, implicitDeps, orderOnlyDeps, variables); } @@ -288,7 +296,8 @@ void cmGlobalNinjaGenerator::WriteCustomCommandBuild( vars["depfile"] = depfile; } this->WriteBuild(*this->BuildFileStream, comment, "CUSTOM_COMMAND", outputs, - deps, cmNinjaDeps(), orderOnly, vars); + /*implicitOuts=*/cmNinjaDeps(), deps, cmNinjaDeps(), + orderOnly, vars); if (this->ComputingUnknownDependencies) { // we need to track every dependency that comes in, since we are trying @@ -330,7 +339,8 @@ void cmGlobalNinjaGenerator::WriteMacOSXContentBuild(const std::string& input, cmNinjaVars vars; this->WriteBuild(*this->BuildFileStream, "", "COPY_OSX_CONTENT", outputs, - deps, cmNinjaDeps(), cmNinjaDeps(), cmNinjaVars()); + /*implicitOuts=*/cmNinjaDeps(), deps, cmNinjaDeps(), + cmNinjaDeps(), cmNinjaVars()); } void cmGlobalNinjaGenerator::WriteRule( @@ -1271,6 +1281,7 @@ void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os) this->WriteBuild(os, "Re-run CMake if any of its inputs changed.", "RERUN_CMAKE", /*outputs=*/cmNinjaDeps(1, ninjaBuildFile), + /*implicitOuts=*/cmNinjaDeps(), /*explicitDeps=*/cmNinjaDeps(), implicitDeps, /*orderOnlyDeps=*/cmNinjaDeps(), variables); @@ -1295,6 +1306,13 @@ bool cmGlobalNinjaGenerator::SupportsConsolePool() const RequiredNinjaVersionForConsolePool().c_str()); } +bool cmGlobalNinjaGenerator::SupportsImplicitOuts() const +{ + return !cmSystemTools::VersionCompare( + cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), + this->RequiredNinjaVersionForImplicitOuts().c_str()); +} + void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) { WriteRule(*this->RulesFileStream, "CLEAN", ninjaCmd() + " -t clean", @@ -1308,6 +1326,7 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) /*generator=*/false); WriteBuild(os, "Clean all the built files.", "CLEAN", /*outputs=*/cmNinjaDeps(1, this->NinjaOutputPath("clean")), + /*implicitOuts=*/cmNinjaDeps(), /*explicitDeps=*/cmNinjaDeps(), /*implicitDeps=*/cmNinjaDeps(), /*orderOnlyDeps=*/cmNinjaDeps(), @@ -1327,6 +1346,7 @@ void cmGlobalNinjaGenerator::WriteTargetHelp(std::ostream& os) /*generator=*/false); WriteBuild(os, "Print all primary targets available.", "HELP", /*outputs=*/cmNinjaDeps(1, this->NinjaOutputPath("help")), + /*implicitOuts=*/cmNinjaDeps(), /*explicitDeps=*/cmNinjaDeps(), /*implicitDeps=*/cmNinjaDeps(), /*orderOnlyDeps=*/cmNinjaDeps(), diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index a0fad64..0201685 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -106,6 +106,7 @@ public: */ void WriteBuild(std::ostream& os, const std::string& comment, const std::string& rule, const cmNinjaDeps& outputs, + const cmNinjaDeps& implicitOuts, const cmNinjaDeps& explicitDeps, const cmNinjaDeps& implicitDeps, const cmNinjaDeps& orderOnlyDeps, @@ -338,7 +339,9 @@ public: // Ninja generator uses 'deps' and 'msvc_deps_prefix' introduced in 1.3 static std::string RequiredNinjaVersion() { return "1.3"; } static std::string RequiredNinjaVersionForConsolePool() { return "1.5"; } + static std::string RequiredNinjaVersionForImplicitOuts() { return "1.7"; } bool SupportsConsolePool() const; + bool SupportsImplicitOuts() const; std::string NinjaOutputPath(std::string const& path); bool HasOutputPathPrefix() const { return !this->OutputPathPrefix.empty(); } diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx index 97323c9..b75ce62 100644 --- a/Source/cmLocalCommonGenerator.cxx +++ b/Source/cmLocalCommonGenerator.cxx @@ -54,7 +54,8 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags( } // Add a module output directory flag if necessary. - std::string mod_dir = target->GetFortranModuleDirectory(); + std::string mod_dir = + target->GetFortranModuleDirectory(this->WorkingDirectory); if (!mod_dir.empty()) { mod_dir = this->ConvertToOutputFormat( this->ConvertToRelativePath(this->WorkingDirectory, mod_dir), diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 014feb9..e0d9fda 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -993,12 +993,16 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() *this->InfoFileStream << " )\n"; } + std::string const& working_dir = + this->LocalGenerator->GetCurrentBinaryDirectory(); + /* clang-format off */ *this->InfoFileStream << "\n" << "# Fortran module output directory.\n" << "set(CMAKE_Fortran_TARGET_MODULE_DIR \"" - << this->GeneratorTarget->GetFortranModuleDirectory() << "\")\n"; + << this->GeneratorTarget->GetFortranModuleDirectory(working_dir) + << "\")\n"; /* clang-format on */ // and now write the rule to use it diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index f87a788..dbd84cb 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -691,7 +691,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() // Write the build statement for this target. bool usedResponseFile = false; globalGen.WriteBuild(this->GetBuildFileStream(), comment.str(), - this->LanguageLinkerRule(), outputs, explicitDeps, + this->LanguageLinkerRule(), outputs, + /*implicitOuts=*/cmNinjaDeps(), explicitDeps, implicitDeps, orderOnlyDeps, vars, rspfile, commandLineLengthLimit, &usedResponseFile); this->WriteLinkRule(usedResponseFile); @@ -702,7 +703,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() this->GetBuildFileStream(), "Create executable symlink " + targetOutput, "CMAKE_SYMLINK_EXECUTABLE", cmNinjaDeps(1, targetOutput), - cmNinjaDeps(1, targetOutputReal), emptyDeps, emptyDeps, symlinkVars); + /*implicitOuts=*/cmNinjaDeps(), cmNinjaDeps(1, targetOutputReal), + emptyDeps, emptyDeps, symlinkVars); } else { cmNinjaDeps symlinks; std::string const soName = @@ -717,7 +719,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() symlinks.push_back(targetOutput); globalGen.WriteBuild( this->GetBuildFileStream(), "Create library symlink " + targetOutput, - "CMAKE_SYMLINK_LIBRARY", symlinks, cmNinjaDeps(1, targetOutputReal), + "CMAKE_SYMLINK_LIBRARY", symlinks, + /*implicitOuts=*/cmNinjaDeps(), cmNinjaDeps(1, targetOutputReal), emptyDeps, emptyDeps, symlinkVars); } } diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 6ac59d5..fb09bfe 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -607,8 +607,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( std::string const rspfile = objectFileName + ".rsp"; this->GetGlobalGenerator()->WriteBuild( - this->GetBuildFileStream(), comment, rule, outputs, explicitDeps, - implicitDeps, orderOnlyDeps, vars, rspfile, commandLineLengthLimit); + this->GetBuildFileStream(), comment, rule, outputs, + /*implicitOuts=*/cmNinjaDeps(), explicitDeps, implicitDeps, orderOnlyDeps, + vars, rspfile, commandLineLengthLimit); if (const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) { std::vector<std::string> outputList; diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index 208fac6..56cd7ba 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -13,7 +13,9 @@ #include "cmServer.h" +#include "cmServerConnection.h" #include "cmServerProtocol.h" +#include "cmSystemTools.h" #include "cmVersionMacros.h" #include "cmake.h" @@ -22,72 +24,42 @@ #include "cm_jsoncpp_value.h" #endif -const char kTYPE_KEY[] = "type"; -const char kCOOKIE_KEY[] = "cookie"; -const char REPLY_TO_KEY[] = "inReplyTo"; -const char ERROR_MESSAGE_KEY[] = "errorMessage"; +#include <fstream> +#include <iostream> +#include <memory> -const char ERROR_TYPE[] = "error"; -const char REPLY_TYPE[] = "reply"; -const char PROGRESS_TYPE[] = "progress"; +static const std::string kTYPE_KEY = "type"; +static const std::string kCOOKIE_KEY = "cookie"; +static const std::string kREPLY_TO_KEY = "inReplyTo"; +static const std::string kERROR_MESSAGE_KEY = "errorMessage"; -const char START_MAGIC[] = "[== CMake Server ==["; -const char END_MAGIC[] = "]== CMake Server ==]"; +static const std::string kERROR_TYPE = "error"; +static const std::string kREPLY_TYPE = "reply"; +static const std::string kPROGRESS_TYPE = "progress"; +static const std::string kMESSAGE_TYPE = "message"; -typedef struct -{ - uv_write_t req; - uv_buf_t buf; -} write_req_t; - -void alloc_buffer(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) -{ - (void)handle; - *buf = uv_buf_init(static_cast<char*>(malloc(suggested_size)), - static_cast<unsigned int>(suggested_size)); -} - -void free_write_req(uv_write_t* req) -{ - write_req_t* wr = reinterpret_cast<write_req_t*>(req); - free(wr->buf.base); - free(wr); -} - -void on_stdout_write(uv_write_t* req, int status) -{ - (void)status; - auto server = reinterpret_cast<cmServer*>(req->data); - free_write_req(req); - server->PopOne(); -} - -void write_data(uv_stream_t* dest, std::string content, uv_write_cb cb) -{ - write_req_t* req = static_cast<write_req_t*>(malloc(sizeof(write_req_t))); - req->req.data = dest->data; - req->buf = uv_buf_init(static_cast<char*>(malloc(content.size())), - static_cast<unsigned int>(content.size())); - memcpy(req->buf.base, content.c_str(), content.size()); - uv_write(reinterpret_cast<uv_write_t*>(req), static_cast<uv_stream_t*>(dest), - &req->buf, 1, cb); -} +static const std::string kSTART_MAGIC = "[== CMake Server ==["; +static const std::string kEND_MAGIC = "]== CMake Server ==]"; -void read_stdin(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) +class cmServer::DebugInfo { - if (nread > 0) { - auto server = reinterpret_cast<cmServer*>(stream->data); - std::string result = std::string(buf->base, buf->base + nread); - server->handleData(result); +public: + DebugInfo() + : StartTime(uv_hrtime()) + { } - if (buf->base) - free(buf->base); -} + bool PrintStatistics = false; -cmServer::cmServer(bool supportExperimental) - : SupportExperimental(supportExperimental) + std::string OutputFile; + uint64_t StartTime; +}; + +cmServer::cmServer(cmServerConnection* conn, bool supportExperimental) + : Connection(conn) + , SupportExperimental(supportExperimental) { + this->Connection->SetServer(this); // Register supported protocols: this->RegisterProtocol(new cmServerProtocol1_0); } @@ -98,18 +70,15 @@ cmServer::~cmServer() return; } - uv_close(reinterpret_cast<uv_handle_t*>(this->InputStream), NULL); - uv_close(reinterpret_cast<uv_handle_t*>(this->OutputStream), NULL); - uv_loop_close(this->Loop); - for (cmServerProtocol* p : this->SupportedProtocols) { delete p; } + + delete this->Connection; } void cmServer::PopOne() { - this->Writing = false; if (this->Queue.empty()) { return; } @@ -124,50 +93,32 @@ void cmServer::PopOne() return; } + std::unique_ptr<DebugInfo> debug; + Json::Value debugValue = value["debug"]; + if (!debugValue.isNull()) { + debug = std::make_unique<DebugInfo>(); + debug->OutputFile = debugValue["dumpToFile"].asString(); + debug->PrintStatistics = debugValue["showStats"].asBool(); + } + const cmServerRequest request(this, value[kTYPE_KEY].asString(), value[kCOOKIE_KEY].asString(), value); if (request.Type == "") { cmServerResponse response(request); response.SetError("No type given in request."); - this->WriteResponse(response); + this->WriteResponse(response, nullptr); return; } - this->WriteResponse(this->Protocol ? this->Protocol->Process(request) - : this->SetProtocolVersion(request)); -} - -void cmServer::handleData(const std::string& data) -{ - this->DataBuffer += data; - - for (;;) { - auto needle = this->DataBuffer.find('\n'); - - if (needle == std::string::npos) { - return; - } - std::string line = this->DataBuffer.substr(0, needle); - const auto ls = line.size(); - if (ls > 1 && line.at(ls - 1) == '\r') - line.erase(ls - 1, 1); - this->DataBuffer.erase(this->DataBuffer.begin(), - this->DataBuffer.begin() + needle + 1); - if (line == START_MAGIC) { - this->JsonData.clear(); - continue; - } - if (line == END_MAGIC) { - this->Queue.push_back(this->JsonData); - this->JsonData.clear(); - if (!this->Writing) { - this->PopOne(); - } - } else { - this->JsonData += line; - this->JsonData += "\n"; - } + cmSystemTools::SetMessageCallback(reportMessage, + const_cast<cmServerRequest*>(&request)); + if (this->Protocol) { + this->Protocol->CMakeInstance()->SetProgressCallback( + reportProgress, const_cast<cmServerRequest*>(&request)); + this->WriteResponse(this->Protocol->Process(request), debug.get()); + } else { + this->WriteResponse(this->SetProtocolVersion(request), debug.get()); } } @@ -207,7 +158,37 @@ void cmServer::PrintHello() const protocolVersions.append(tmp); } - this->WriteJsonObject(hello); + this->WriteJsonObject(hello, nullptr); +} + +void cmServer::QueueRequest(const std::string& request) +{ + this->Queue.push_back(request); + this->PopOne(); +} + +void cmServer::reportProgress(const char* msg, float progress, void* data) +{ + const cmServerRequest* request = static_cast<const cmServerRequest*>(data); + assert(request); + if (progress < 0.0 || progress > 1.0) { + request->ReportMessage(msg, ""); + } else { + request->ReportProgress(0, static_cast<int>(progress * 1000), 1000, msg); + } +} + +void cmServer::reportMessage(const char* msg, const char* title, + bool& /* cancel */, void* data) +{ + const cmServerRequest* request = static_cast<const cmServerRequest*>(data); + assert(request); + assert(msg); + std::string titleString; + if (title) { + titleString = title; + } + request->ReportMessage(std::string(msg), titleString); } cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request) @@ -253,55 +234,54 @@ cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request) return request.Reply(Json::objectValue); } -bool cmServer::Serve() +bool cmServer::Serve(std::string* errorMessage) { if (this->SupportedProtocols.empty()) { + *errorMessage = + "No protocol versions defined. Maybe you need --experimental?"; return false; } assert(!this->Protocol); - this->Loop = uv_default_loop(); + return Connection->ProcessEvents(errorMessage); +} - if (uv_guess_handle(1) == UV_TTY) { - uv_tty_init(this->Loop, &this->Input.tty, 0, 1); - uv_tty_set_mode(&this->Input.tty, UV_TTY_MODE_NORMAL); - this->Input.tty.data = this; - InputStream = reinterpret_cast<uv_stream_t*>(&this->Input.tty); +void cmServer::WriteJsonObject(const Json::Value& jsonValue, + const DebugInfo* debug) const +{ + Json::FastWriter writer; - uv_tty_init(this->Loop, &this->Output.tty, 1, 0); - uv_tty_set_mode(&this->Output.tty, UV_TTY_MODE_NORMAL); - this->Output.tty.data = this; - OutputStream = reinterpret_cast<uv_stream_t*>(&this->Output.tty); - } else { - uv_pipe_init(this->Loop, &this->Input.pipe, 0); - uv_pipe_open(&this->Input.pipe, 0); - this->Input.pipe.data = this; - InputStream = reinterpret_cast<uv_stream_t*>(&this->Input.pipe); - - uv_pipe_init(this->Loop, &this->Output.pipe, 0); - uv_pipe_open(&this->Output.pipe, 1); - this->Output.pipe.data = this; - OutputStream = reinterpret_cast<uv_stream_t*>(&this->Output.pipe); - } + auto beforeJson = uv_hrtime(); + std::string result = writer.write(jsonValue); - this->PrintHello(); + if (debug) { + Json::Value copy = jsonValue; + if (debug->PrintStatistics) { + Json::Value stats = Json::objectValue; + auto endTime = uv_hrtime(); - uv_read_start(this->InputStream, alloc_buffer, read_stdin); + stats["jsonSerialization"] = double(endTime - beforeJson) / 1000000.0; + stats["totalTime"] = double(endTime - debug->StartTime) / 1000000.0; + stats["size"] = static_cast<int>(result.size()); + if (!debug->OutputFile.empty()) { + stats["dumpFile"] = debug->OutputFile; + } - uv_run(this->Loop, UV_RUN_DEFAULT); - return true; -} + copy["zzzDebug"] = stats; -void cmServer::WriteJsonObject(const Json::Value& jsonValue) const -{ - Json::FastWriter writer; + result = writer.write(copy); // Update result to include debug info + } - std::string result = std::string("\n") + std::string(START_MAGIC) + - std::string("\n") + writer.write(jsonValue) + std::string(END_MAGIC) + - std::string("\n"); + if (!debug->OutputFile.empty()) { + std::ofstream myfile; + myfile.open(debug->OutputFile); + myfile << result; + myfile.close(); + } + } - this->Writing = true; - write_data(this->OutputStream, result, on_stdout_write); + Connection->WriteData(std::string("\n") + kSTART_MAGIC + std::string("\n") + + result + kEND_MAGIC + std::string("\n")); } cmServerProtocol* cmServer::FindMatchingProtocol( @@ -328,39 +308,59 @@ void cmServer::WriteProgress(const cmServerRequest& request, int min, assert(message.length() != 0); Json::Value obj = Json::objectValue; - obj[kTYPE_KEY] = PROGRESS_TYPE; - obj[REPLY_TO_KEY] = request.Type; + obj[kTYPE_KEY] = kPROGRESS_TYPE; + obj[kREPLY_TO_KEY] = request.Type; obj[kCOOKIE_KEY] = request.Cookie; obj["progressMessage"] = message; obj["progressMinimum"] = min; obj["progressMaximum"] = max; obj["progressCurrent"] = current; - this->WriteJsonObject(obj); + this->WriteJsonObject(obj, nullptr); +} + +void cmServer::WriteMessage(const cmServerRequest& request, + const std::string& message, + const std::string& title) const +{ + if (message.empty()) + return; + + Json::Value obj = Json::objectValue; + obj[kTYPE_KEY] = kMESSAGE_TYPE; + obj[kREPLY_TO_KEY] = request.Type; + obj[kCOOKIE_KEY] = request.Cookie; + obj["message"] = message; + if (!title.empty()) { + obj["title"] = title; + } + + WriteJsonObject(obj, nullptr); } void cmServer::WriteParseError(const std::string& message) const { Json::Value obj = Json::objectValue; - obj[kTYPE_KEY] = ERROR_TYPE; - obj[ERROR_MESSAGE_KEY] = message; - obj[REPLY_TO_KEY] = ""; + obj[kTYPE_KEY] = kERROR_TYPE; + obj[kERROR_MESSAGE_KEY] = message; + obj[kREPLY_TO_KEY] = ""; obj[kCOOKIE_KEY] = ""; - this->WriteJsonObject(obj); + this->WriteJsonObject(obj, nullptr); } -void cmServer::WriteResponse(const cmServerResponse& response) const +void cmServer::WriteResponse(const cmServerResponse& response, + const DebugInfo* debug) const { assert(response.IsComplete()); Json::Value obj = response.Data(); obj[kCOOKIE_KEY] = response.Cookie; - obj[kTYPE_KEY] = response.IsError() ? ERROR_TYPE : REPLY_TYPE; - obj[REPLY_TO_KEY] = response.Type; + obj[kTYPE_KEY] = response.IsError() ? kERROR_TYPE : kREPLY_TYPE; + obj[kREPLY_TO_KEY] = response.Type; if (response.IsError()) { - obj[ERROR_MESSAGE_KEY] = response.ErrorMessage(); + obj[kERROR_MESSAGE_KEY] = response.ErrorMessage(); } - this->WriteJsonObject(obj); + this->WriteJsonObject(obj, debug); } diff --git a/Source/cmServer.h b/Source/cmServer.h index 4a9c3f5..dde5333 100644 --- a/Source/cmServer.h +++ b/Source/cmServer.h @@ -24,6 +24,7 @@ #include <string> #include <vector> +class cmServerConnection; class cmServerProtocol; class cmServerRequest; class cmServerResponse; @@ -31,18 +32,24 @@ class cmServerResponse; class cmServer { public: - cmServer(bool supportExperimental); - ~cmServer(); + class DebugInfo; - bool Serve(); + cmServer(cmServerConnection* conn, bool supportExperimental); + ~cmServer(); - // for callbacks: - void PopOne(); - void handleData(std::string const& data); + bool Serve(std::string* errorMessage); private: void RegisterProtocol(cmServerProtocol* protocol); + // Callbacks from cmServerConnection: + void PopOne(); + void QueueRequest(const std::string& request); + + static void reportProgress(const char* msg, float progress, void* data); + static void reportMessage(const char* msg, const char* title, bool& cancel, + void* data); + // Handle requests: cmServerResponse SetProtocolVersion(const cmServerRequest& request); @@ -51,14 +58,19 @@ private: // Write responses: void WriteProgress(const cmServerRequest& request, int min, int current, int max, const std::string& message) const; - void WriteResponse(const cmServerResponse& response) const; + void WriteMessage(const cmServerRequest& request, const std::string& message, + const std::string& title) const; + void WriteResponse(const cmServerResponse& response, + const DebugInfo* debug) const; void WriteParseError(const std::string& message) const; - void WriteJsonObject(Json::Value const& jsonValue) const; + void WriteJsonObject(Json::Value const& jsonValue, + const DebugInfo* debug) const; static cmServerProtocol* FindMatchingProtocol( const std::vector<cmServerProtocol*>& protocols, int major, int minor); + cmServerConnection* Connection = nullptr; const bool SupportExperimental; cmServerProtocol* Protocol = nullptr; @@ -84,4 +96,5 @@ private: mutable bool Writing = false; friend class cmServerRequest; + friend class cmServerConnection; }; diff --git a/Source/cmServerConnection.cxx b/Source/cmServerConnection.cxx new file mode 100644 index 0000000..398e250 --- /dev/null +++ b/Source/cmServerConnection.cxx @@ -0,0 +1,307 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2015 Stephen Kelly <steveire@gmail.com> + Copyright 2016 Tobias Hunger <tobias.hunger@qt.io> + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#include "cmServerConnection.h" + +#include <cmServer.h> + +#include <assert.h> + +namespace { + +static const std::string kSTART_MAGIC = "[== CMake Server ==["; +static const std::string kEND_MAGIC = "]== CMake Server ==]"; + +struct write_req_t +{ + uv_write_t req; + uv_buf_t buf; +}; + +void on_alloc_buffer(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) +{ + (void)(handle); + char* rawBuffer = new char[suggested_size]; + *buf = uv_buf_init(rawBuffer, static_cast<unsigned int>(suggested_size)); +} + +void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) +{ + auto conn = reinterpret_cast<cmServerConnection*>(stream->data); + if (nread >= 0) { + conn->ReadData(std::string(buf->base, buf->base + nread)); + } else { + conn->HandleEof(); + } + + delete[](buf->base); +} + +void on_write(uv_write_t* req, int status) +{ + (void)(status); + auto conn = reinterpret_cast<cmServerConnection*>(req->data); + + // Free req and buffer + write_req_t* wr = reinterpret_cast<write_req_t*>(req); + delete[](wr->buf.base); + delete wr; + + conn->ProcessNextRequest(); +} + +void on_new_connection(uv_stream_t* stream, int status) +{ + (void)(status); + auto conn = reinterpret_cast<cmServerConnection*>(stream->data); + conn->Connect(stream); +} + +} // namespace + +class LoopGuard +{ +public: + LoopGuard(cmServerConnection* connection) + : Connection(connection) + { + Connection->mLoop = uv_default_loop(); + } + + ~LoopGuard() + { + uv_loop_close(Connection->mLoop); + Connection->mLoop = nullptr; + } + +private: + cmServerConnection* Connection; +}; + +cmServerConnection::cmServerConnection() +{ +} + +cmServerConnection::~cmServerConnection() +{ +} + +void cmServerConnection::SetServer(cmServer* s) +{ + this->Server = s; +} + +bool cmServerConnection::ProcessEvents(std::string* errorMessage) +{ + assert(this->Server); + errorMessage->clear(); + + this->RawReadBuffer.clear(); + this->RequestBuffer.clear(); + + LoopGuard guard(this); + (void)(guard); + if (!this->mLoop) { + *errorMessage = "Internal Error: Failed to create event loop."; + return false; + } + + if (!DoSetup(errorMessage)) { + return false; + } + + if (uv_run(this->mLoop, UV_RUN_DEFAULT) != 0) { + *errorMessage = "Internal Error: Event loop stopped in unclean state."; + return false; + } + + // These need to be cleaned up by now: + assert(!this->ReadStream); + assert(!this->WriteStream); + + this->RawReadBuffer.clear(); + this->RequestBuffer.clear(); + + return true; +} + +void cmServerConnection::ReadData(const std::string& data) +{ + this->RawReadBuffer += data; + + for (;;) { + auto needle = this->RawReadBuffer.find('\n'); + + if (needle == std::string::npos) { + return; + } + std::string line = this->RawReadBuffer.substr(0, needle); + const auto ls = line.size(); + if (ls > 1 && line.at(ls - 1) == '\r') + line.erase(ls - 1, 1); + this->RawReadBuffer.erase(this->RawReadBuffer.begin(), + this->RawReadBuffer.begin() + + static_cast<long>(needle) + 1); + if (line == kSTART_MAGIC) { + this->RequestBuffer.clear(); + continue; + } + if (line == kEND_MAGIC) { + this->Server->QueueRequest(this->RequestBuffer); + this->RequestBuffer.clear(); + } else { + this->RequestBuffer += line; + this->RequestBuffer += "\n"; + } + } +} + +void cmServerConnection::HandleEof() +{ + this->TearDown(); +} + +void cmServerConnection::WriteData(const std::string& data) +{ + assert(this->WriteStream); + + auto ds = data.size(); + + write_req_t* req = new write_req_t; + req->req.data = this; + req->buf = uv_buf_init(new char[ds], static_cast<unsigned int>(ds)); + memcpy(req->buf.base, data.c_str(), ds); + + uv_write(reinterpret_cast<uv_write_t*>(req), + static_cast<uv_stream_t*>(this->WriteStream), &req->buf, 1, + on_write); +} + +void cmServerConnection::ProcessNextRequest() +{ + Server->PopOne(); +} + +void cmServerConnection::SendGreetings() +{ + Server->PrintHello(); +} + +bool cmServerStdIoConnection::DoSetup(std::string* errorMessage) +{ + (void)(errorMessage); + + if (uv_guess_handle(1) == UV_TTY) { + uv_tty_init(this->Loop(), &this->Input.tty, 0, 1); + uv_tty_set_mode(&this->Input.tty, UV_TTY_MODE_NORMAL); + Input.tty.data = this; + this->ReadStream = reinterpret_cast<uv_stream_t*>(&this->Input.tty); + + uv_tty_init(this->Loop(), &this->Output.tty, 1, 0); + uv_tty_set_mode(&this->Output.tty, UV_TTY_MODE_NORMAL); + Output.tty.data = this; + this->WriteStream = reinterpret_cast<uv_stream_t*>(&this->Output.tty); + } else { + uv_pipe_init(this->Loop(), &this->Input.pipe, 0); + uv_pipe_open(&this->Input.pipe, 0); + Input.pipe.data = this; + this->ReadStream = reinterpret_cast<uv_stream_t*>(&this->Input.pipe); + + uv_pipe_init(this->Loop(), &this->Output.pipe, 0); + uv_pipe_open(&this->Output.pipe, 1); + Output.pipe.data = this; + this->WriteStream = reinterpret_cast<uv_stream_t*>(&this->Output.pipe); + } + + SendGreetings(); + uv_read_start(this->ReadStream, on_alloc_buffer, on_read); + + return true; +} + +void cmServerStdIoConnection::TearDown() +{ + uv_close(reinterpret_cast<uv_handle_t*>(this->ReadStream), nullptr); + this->ReadStream = nullptr; + uv_close(reinterpret_cast<uv_handle_t*>(this->WriteStream), nullptr); + this->WriteStream = nullptr; +} + +cmServerPipeConnection::cmServerPipeConnection(const std::string& name) + : PipeName(name) +{ + this->ServerPipe.data = nullptr; + this->ClientPipe.data = nullptr; +} + +bool cmServerPipeConnection::DoSetup(std::string* errorMessage) +{ + uv_pipe_init(this->Loop(), &this->ServerPipe, 0); + this->ServerPipe.data = this; + + int r; + if ((r = uv_pipe_bind(&this->ServerPipe, this->PipeName.c_str())) != 0) { + *errorMessage = std::string("Internal Error with ") + this->PipeName + + ": " + uv_err_name(r); + return false; + } + auto serverStream = reinterpret_cast<uv_stream_t*>(&this->ServerPipe); + serverStream->data = this; + if ((r = uv_listen(serverStream, 1, on_new_connection)) != 0) { + *errorMessage = std::string("Internal Error with ") + this->PipeName + + ": " + uv_err_name(r); + return false; + } + + return true; +} + +void cmServerPipeConnection::TearDown() +{ + if (this->WriteStream->data) { + uv_close(reinterpret_cast<uv_handle_t*>(this->WriteStream), nullptr); + this->WriteStream->data = nullptr; + } + uv_close(reinterpret_cast<uv_handle_t*>(&this->ServerPipe), nullptr); + + this->WriteStream = nullptr; + this->ReadStream = nullptr; +} + +void cmServerPipeConnection::Connect(uv_stream_t* server) +{ + if (this->ClientPipe.data == this) { + // Accept and close all pipes but the first: + uv_pipe_t rejectPipe; + + uv_pipe_init(this->Loop(), &rejectPipe, 0); + auto rejecter = reinterpret_cast<uv_stream_t*>(&rejectPipe); + uv_accept(server, rejecter); + uv_close(reinterpret_cast<uv_handle_t*>(rejecter), nullptr); + return; + } + + uv_pipe_init(this->Loop(), &this->ClientPipe, 0); + this->ClientPipe.data = this; + auto client = reinterpret_cast<uv_stream_t*>(&this->ClientPipe); + if (uv_accept(server, client) != 0) { + uv_close(reinterpret_cast<uv_handle_t*>(client), nullptr); + return; + } + this->ReadStream = client; + this->WriteStream = client; + + uv_read_start(this->ReadStream, on_alloc_buffer, on_read); + + this->SendGreetings(); +} diff --git a/Source/cmServerConnection.h b/Source/cmServerConnection.h new file mode 100644 index 0000000..fa86e71 --- /dev/null +++ b/Source/cmServerConnection.h @@ -0,0 +1,97 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2015 Stephen Kelly <steveire@gmail.com> + Copyright 2016 Tobias Hunger <tobias.hunger@qt.io> + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#pragma once + +#include <string> +#include <vector> + +#if defined(CMAKE_BUILD_WITH_CMAKE) +#include "cm_uv.h" +#endif + +class cmServer; +class LoopGuard; + +class cmServerConnection +{ +public: + cmServerConnection(); + virtual ~cmServerConnection(); + + void SetServer(cmServer* s); + + bool ProcessEvents(std::string* errorMessage); + + void ReadData(const std::string& data); + void HandleEof(); + void WriteData(const std::string& data); + void ProcessNextRequest(); + + virtual void Connect(uv_stream_t* server) { (void)(server); } + +protected: + virtual bool DoSetup(std::string* errorMessage) = 0; + virtual void TearDown() = 0; + + void SendGreetings(); + + uv_loop_t* Loop() const { return mLoop; } + +protected: + std::string RawReadBuffer; + std::string RequestBuffer; + + uv_stream_t* ReadStream = nullptr; + uv_stream_t* WriteStream = nullptr; + +private: + uv_loop_t* mLoop = nullptr; + cmServer* Server = nullptr; + + friend class LoopGuard; +}; + +class cmServerStdIoConnection : public cmServerConnection +{ +public: + bool DoSetup(std::string* errorMessage) override; + + void TearDown() override; + +private: + typedef union + { + uv_tty_t tty; + uv_pipe_t pipe; + } InOutUnion; + + InOutUnion Input; + InOutUnion Output; +}; + +class cmServerPipeConnection : public cmServerConnection +{ +public: + cmServerPipeConnection(const std::string& name); + bool DoSetup(std::string* errorMessage) override; + + void TearDown() override; + + void Connect(uv_stream_t* server) override; + +private: + const std::string PipeName; + uv_pipe_t ServerPipe; + uv_pipe_t ClientPipe; +}; diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx index d53ac28..26942d3 100644 --- a/Source/cmServerProtocol.cxx +++ b/Source/cmServerProtocol.cxx @@ -22,17 +22,14 @@ #include "cm_jsoncpp_value.h" #endif -namespace { // Vocabulary: -const std::string kBUILD_DIRECTORY_KEY = "buildDirectory"; -const std::string kCOOKIE_KEY = "cookie"; -const std::string kEXTRA_GENERATOR_KEY = "extraGenerator"; -const std::string kGENERATOR_KEY = "generator"; -const std::string kSOURCE_DIRECTORY_KEY = "sourceDirectory"; -const std::string kTYPE_KEY = "type"; - -} // namespace +static const std::string kBUILD_DIRECTORY_KEY = "buildDirectory"; +static const std::string kCOOKIE_KEY = "cookie"; +static const std::string kEXTRA_GENERATOR_KEY = "extraGenerator"; +static const std::string kGENERATOR_KEY = "generator"; +static const std::string kSOURCE_DIRECTORY_KEY = "sourceDirectory"; +static const std::string kTYPE_KEY = "type"; cmServerRequest::cmServerRequest(cmServer* server, const std::string& t, const std::string& c, const Json::Value& d) @@ -49,6 +46,12 @@ void cmServerRequest::ReportProgress(int min, int current, int max, this->m_Server->WriteProgress(*this, min, current, max, message); } +void cmServerRequest::ReportMessage(const std::string& message, + const std::string& title) const +{ + m_Server->WriteMessage(*this, message, title); +} + cmServerResponse cmServerRequest::Reply(const Json::Value& data) const { cmServerResponse response(*this); diff --git a/Source/cmServerProtocol.h b/Source/cmServerProtocol.h index e95c2f1..bab949b 100644 --- a/Source/cmServerProtocol.h +++ b/Source/cmServerProtocol.h @@ -57,9 +57,6 @@ private: class cmServerRequest { public: - void ReportProgress(int min, int current, int max, - const std::string& message) const; - cmServerResponse Reply(const Json::Value& data) const; cmServerResponse ReportError(const std::string& message) const; @@ -71,6 +68,11 @@ private: cmServerRequest(cmServer* server, const std::string& t, const std::string& c, const Json::Value& d); + void ReportProgress(int min, int current, int max, + const std::string& message) const; + void ReportMessage(const std::string& message, + const std::string& title) const; + cmServer* m_Server; friend class cmServer; @@ -95,6 +97,8 @@ protected: private: std::unique_ptr<cmake> m_CMakeInstance; + + friend class cmServer; }; class cmServerProtocol1_0 : public cmServerProtocol diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 38f00e6..9daed4b 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -25,6 +25,7 @@ #if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE #include "cmServer.h" +#include "cmServerConnection.h" #endif #if defined(CMAKE_BUILD_WITH_CMAKE) @@ -913,32 +914,49 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) } return 0; } else if (args[1] == "server") { - if (args.size() > 3) { - cmSystemTools::Error("Too many arguments to start server mode"); - return 1; - } + const std::string pipePrefix = "--pipe="; bool supportExperimental = false; - if (args.size() == 3) { - if (args[2] == "--experimental") { + bool isDebug = false; + std::string pipe; + + for (size_t i = 2; i < args.size(); ++i) { + const std::string& a = args[i]; + + if (a == "--experimental") { supportExperimental = true; + } else if (a == "--debug") { + pipe.clear(); + isDebug = true; + } else if (a.substr(0, pipePrefix.size()) == pipePrefix) { + isDebug = false; + pipe = a.substr(pipePrefix.size()); + if (pipe.empty()) { + cmSystemTools::Error("No pipe given after --pipe="); + return 2; + } } else { cmSystemTools::Error("Unknown argument for server mode"); return 1; } } #if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE - cmServer server(supportExperimental); - if (server.Serve()) { + cmServerConnection* conn; + if (isDebug) { + conn = new cmServerStdIoConnection; + } else { + conn = new cmServerPipeConnection(pipe); + } + cmServer server(conn, supportExperimental); + std::string errorMessage; + if (server.Serve(&errorMessage)) { return 0; } else { - cmSystemTools::Error( - "CMake server could not find any supported protocol. " - "Try with \"--experimental\" to enable " - "experimental support."); + cmSystemTools::Error(errorMessage.c_str()); return 1; } #else static_cast<void>(supportExperimental); + static_cast<void>(isDebug); cmSystemTools::Error("CMake was not built with server mode enabled"); return 1; #endif diff --git a/Source/kwsys/testConsoleBuf.cxx b/Source/kwsys/testConsoleBuf.cxx index 3dec0973..3dc3337 100644 --- a/Source/kwsys/testConsoleBuf.cxx +++ b/Source/kwsys/testConsoleBuf.cxx @@ -31,6 +31,7 @@ #include <string.h> #include <wchar.h> #include <iostream> +#include <iomanip> #include <stdexcept> #include "testConsoleBuf.hxx" @@ -44,10 +45,67 @@ static UINT TestCodepage = KWSYS_ENCODING_DEFAULT_CODEPAGE; static const DWORD waitTimeout = 10 * 1000; static STARTUPINFO startupInfo; static PROCESS_INFORMATION processInfo; -static HANDLE syncEvent; +static HANDLE beforeInputEvent; +static HANDLE afterOutputEvent; static std::string encodedInputTestString; static std::string encodedTestString; +static void displayError(DWORD errorCode) { + std::cerr.setf(std::ios::hex, std::ios::basefield); + std::cerr << "Failed with error: 0x" << errorCode << "!" << std::endl; + LPWSTR message; + if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + errorCode, + 0, + (LPWSTR)&message, 0, + NULL) + ) { + std::cerr << "Error message: " << kwsys::Encoding::ToNarrow(message) << std::endl; + HeapFree(GetProcessHeap(), 0, message); + } else { + std::cerr << "FormatMessage() failed with error: 0x" << GetLastError() << "!" << std::endl; + } + std::cerr.unsetf(std::ios::hex); +} + +std::basic_streambuf<char> *errstream(const char *unused) { + static_cast<void>(unused); + return std::cerr.rdbuf(); +} + +std::basic_streambuf<wchar_t> *errstream(const wchar_t *unused) { + static_cast<void>(unused); + return std::wcerr.rdbuf(); +} + +//---------------------------------------------------------------------------- +template<typename T> +static void dumpBuffers(const T *expected, const T *received, size_t size) { + std::basic_ostream<T> err(errstream(expected)); + err << "Expected output: '" << std::basic_string<T>(expected, size) << "'" << std::endl; + if (err.fail()) { + err.clear(); + err << "--- Error while outputting ---" << std::endl; + } + err << "Received output: '" << std::basic_string<T>(received, size) << "'" << std::endl; + if (err.fail()) { + err.clear(); + err << "--- Error while outputting ---" << std::endl; + } + std::cerr << "Expected output | Received output" << std::endl; + for (size_t i = 0; i < size; i++) { + std::cerr << std::setbase(16) << std::setfill('0') << " " << + "0x" << std::setw(8) << static_cast<unsigned int>(expected[i]) << " | " << + "0x" << std::setw(8) << static_cast<unsigned int>(received[i]); + if (static_cast<unsigned int>(expected[i]) != static_cast<unsigned int>(received[i])) { + std::cerr << " MISMATCH!"; + } + std::cerr << std::endl; + } + std::cerr << std::endl << std::flush; +} + //---------------------------------------------------------------------------- static bool createProcess(HANDLE hIn, HANDLE hOut, HANDLE hErr) { @@ -89,23 +147,8 @@ static bool createProcess(HANDLE hIn, HANDLE hOut, HANDLE hErr) &processInfo) != 0; // Pointer to PROCESS_INFORMATION structure if (!success) { DWORD lastError = GetLastError(); - std::cerr.setf(std::ios::hex, std::ios::basefield); - std::cerr << "CreateProcess(" << kwsys::Encoding::ToNarrow(cmd) - << ") failed with error: 0x" << lastError << "!" << std::endl; - LPWSTR message; - if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - lastError, - 0, - (LPWSTR)&message, 0, - NULL) - ) { - std::cerr << "Error message: " << kwsys::Encoding::ToNarrow(message) << std::endl; - HeapFree(GetProcessHeap(), 0, message); - } else { - std::cerr << "FormatMessage() failed with error: 0x" << GetLastError() << "!" << std::endl; - } - std::cerr.unsetf(std::ios::hex); + std::cerr << "CreateProcess(" << kwsys::Encoding::ToNarrow(cmd) << ")" << std::endl; + displayError(lastError); } return success; } @@ -162,8 +205,9 @@ static HANDLE createFile(LPCWSTR fileName) FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL); // no template if (file == INVALID_HANDLE_VALUE) { - std::cerr << "CreateFile(" << kwsys::Encoding::ToNarrow(fileName) - << ") failed!" << std::endl; + DWORD lastError = GetLastError(); + std::cerr << "CreateFile(" << kwsys::Encoding::ToNarrow(fileName) << ")" << std::endl; + displayError(lastError); } return file; } @@ -232,6 +276,7 @@ static int testPipe() HANDLE errPipeWrite = INVALID_HANDLE_VALUE; UINT currentCodepage = GetConsoleCP(); char buffer[200]; + char buffer2[200]; try { if (!createPipe(&inPipeRead, &inPipeWrite) || !createPipe(&outPipeRead, &outPipeWrite) || @@ -254,20 +299,23 @@ static int testPipe() if (createProcess(inPipeRead, outPipeWrite, errPipeWrite)) { try { - Sleep(100); - if (WaitForSingleObject(syncEvent, waitTimeout) != WAIT_OBJECT_0) { + DWORD status; + if ((status = WaitForSingleObject(afterOutputEvent, waitTimeout)) != WAIT_OBJECT_0) { + std::cerr.setf(std::ios::hex, std::ios::basefield); + std::cerr << "WaitForSingleObject returned unexpected status 0x" << status << std::endl; + std::cerr.unsetf(std::ios::hex); throw std::runtime_error("WaitForSingleObject failed!"); } DWORD bytesRead = 0; if (!ReadFile(outPipeRead, buffer, sizeof(buffer), &bytesRead, NULL) || bytesRead == 0) { - throw std::runtime_error("ReadFile failed!"); + throw std::runtime_error("ReadFile#1 failed!"); } if ((bytesRead < encodedTestString.size() + 1 + encodedInputTestString.size() && !ReadFile(outPipeRead, buffer + bytesRead, sizeof(buffer) - bytesRead, &bytesRead, NULL)) || bytesRead == 0) { - throw std::runtime_error("ReadFile failed!"); + throw std::runtime_error("ReadFile#2 failed!"); } if (memcmp(buffer, encodedTestString.c_str(), encodedTestString.size()) == 0 && @@ -275,23 +323,30 @@ static int testPipe() encodedInputTestString.c_str(), encodedInputTestString.size()) == 0) { bytesRead = 0; - if (!ReadFile(errPipeRead, buffer, sizeof(buffer), &bytesRead, NULL) + if (!ReadFile(errPipeRead, buffer2, sizeof(buffer2), &bytesRead, NULL) || bytesRead == 0) { - throw std::runtime_error("ReadFile failed!"); + throw std::runtime_error("ReadFile#3 failed!"); } - buffer[bytesRead - 1] = 0; - didFail = encodedTestString.compare(buffer) == 0 ? 0 : 1; + buffer2[bytesRead - 1] = 0; + didFail = encodedTestString.compare(buffer2) == 0 ? 0 : 1; } if (didFail != 0) { std::cerr << "Pipe's output didn't match expected output!" << std::endl << std::flush; + dumpBuffers<char>(encodedTestString.c_str(), buffer, encodedTestString.size()); + dumpBuffers<char>(encodedInputTestString.c_str(), buffer + encodedTestString.size() + 1, encodedInputTestString.size()); + dumpBuffers<char>(encodedTestString.c_str(), buffer2, encodedTestString.size()); } } catch (const std::runtime_error &ex) { - std::cerr << ex.what() << std::endl << std::flush; + DWORD lastError = GetLastError(); + std::cerr << "In function " << __FUNCTION__ << ":" << ex.what() << std::endl << std::flush; + displayError(lastError); } finishProcess(didFail == 0); } } catch (const std::runtime_error &ex) { - std::cerr << ex.what() << std::endl << std::flush; + DWORD lastError = GetLastError(); + std::cerr << "In function " << __FUNCTION__ << ":" << ex.what() << std::endl << std::flush; + displayError(lastError); } finishPipe(inPipeRead, inPipeWrite); finishPipe(outPipeRead, outPipeWrite); @@ -316,6 +371,7 @@ static int testFile() int length = 0; DWORD bytesWritten = 0; char buffer[200]; + char buffer2[200]; if ((length = WideCharToMultiByte(TestCodepage, 0, UnicodeInputTestString, -1, buffer, sizeof(buffer), @@ -334,17 +390,20 @@ static int testFile() if (createProcess(inFile, outFile, errFile)) { DWORD bytesRead = 0; try { - Sleep(100); - if (WaitForSingleObject(syncEvent, waitTimeout) != WAIT_OBJECT_0) { + DWORD status; + if ((status = WaitForSingleObject(afterOutputEvent, waitTimeout)) != WAIT_OBJECT_0) { + std::cerr.setf(std::ios::hex, std::ios::basefield); + std::cerr << "WaitForSingleObject returned unexpected status 0x" << status << std::endl; + std::cerr.unsetf(std::ios::hex); throw std::runtime_error("WaitForSingleObject failed!"); } if (SetFilePointer(outFile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { - throw std::runtime_error("SetFilePointer failed!"); + throw std::runtime_error("SetFilePointer#1 failed!"); } if (!ReadFile(outFile, buffer, sizeof(buffer), &bytesRead, NULL) || bytesRead == 0) { - throw std::runtime_error("ReadFile failed!"); + throw std::runtime_error("ReadFile#1 failed!"); } buffer[bytesRead - 1] = 0; if (memcmp(buffer, encodedTestString.c_str(), @@ -355,25 +414,32 @@ static int testFile() bytesRead = 0; if (SetFilePointer(errFile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { - throw std::runtime_error("SetFilePointer failed!"); + throw std::runtime_error("SetFilePointer#2 failed!"); } - if (!ReadFile(errFile, buffer, sizeof(buffer), &bytesRead, NULL) + if (!ReadFile(errFile, buffer2, sizeof(buffer2), &bytesRead, NULL) || bytesRead == 0) { - throw std::runtime_error("ReadFile failed!"); + throw std::runtime_error("ReadFile#2 failed!"); } - buffer[bytesRead - 1] = 0; - didFail = encodedTestString.compare(buffer) == 0 ? 0 : 1; + buffer2[bytesRead - 1] = 0; + didFail = encodedTestString.compare(buffer2) == 0 ? 0 : 1; } if (didFail != 0) { std::cerr << "File's output didn't match expected output!" << std::endl << std::flush; + dumpBuffers<char>(encodedTestString.c_str(), buffer, encodedTestString.size()); + dumpBuffers<char>(encodedInputTestString.c_str(), buffer + encodedTestString.size() + 1, encodedInputTestString.size() - 1); + dumpBuffers<char>(encodedTestString.c_str(), buffer2, encodedTestString.size()); } } catch (const std::runtime_error &ex) { - std::cerr << ex.what() << std::endl << std::flush; + DWORD lastError = GetLastError(); + std::cerr << "In function " << __FUNCTION__ << ":" << ex.what() << std::endl << std::flush; + displayError(lastError); } finishProcess(didFail == 0); } } catch (const std::runtime_error &ex) { - std::cerr << ex.what() << std::endl << std::flush; + DWORD lastError = GetLastError(); + std::cerr << "In function " << __FUNCTION__ << ":" << ex.what() << std::endl << std::flush; + displayError(lastError); } finishFile(inFile); finishFile(outFile); @@ -403,6 +469,7 @@ static int testConsole() const DWORD TestFontSize = 0x000c0000; HKEY hConsoleKey; WCHAR FaceName[200]; + FaceName[0] = 0; DWORD FaceNameSize = sizeof(FaceName); DWORD FontFamily = TestFontFamily; DWORD FontSize = TestFontSize; @@ -459,10 +526,20 @@ static int testConsole() securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); securityAttributes.bInheritHandle = TRUE; securityAttributes.lpSecurityDescriptor = NULL; - hIn = CreateFileW(L"CONIN$", GENERIC_READ | GENERIC_WRITE, 0, + hIn = CreateFileW(L"CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &securityAttributes, OPEN_EXISTING, 0, NULL); - hOut = CreateFileW(L"CONOUT$", GENERIC_READ | GENERIC_WRITE, 0, + if (hIn == INVALID_HANDLE_VALUE) { + DWORD lastError = GetLastError(); + std::cerr << "CreateFile(CONIN$)" << std::endl; + displayError(lastError); + } + hOut = CreateFileW(L"CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &securityAttributes, OPEN_EXISTING, 0, NULL); + if (hOut == INVALID_HANDLE_VALUE) { + DWORD lastError = GetLastError(); + std::cerr << "CreateFile(CONOUT$)" << std::endl; + displayError(lastError); + } SetStdHandle(STD_INPUT_HANDLE, hIn); SetStdHandle(STD_OUTPUT_HANDLE, hOut); SetStdHandle(STD_ERROR_HANDLE, hOut); @@ -496,8 +573,12 @@ static int testConsole() KEY_WRITE, &hConsoleKey) == ERROR_SUCCESS) { RegSetValueExW(hConsoleKey, L"FontFamily", 0, REG_DWORD, (BYTE *)&FontFamily, sizeof(FontFamily)); - RegSetValueExW(hConsoleKey, L"FaceName", 0, REG_SZ, - (BYTE *)FaceName, FaceNameSize); + if (FaceName[0] != 0) { + RegSetValueExW(hConsoleKey, L"FaceName", 0, REG_SZ, + (BYTE *)FaceName, FaceNameSize); + } else { + RegDeleteValueW(hConsoleKey, L"FaceName"); + } RegSetValueExW(hConsoleKey, L"FontSize", 0, REG_DWORD, (BYTE *)&FontSize, sizeof(FontSize)); RegCloseKey(hConsoleKey); @@ -508,8 +589,12 @@ static int testConsole() if (createProcess(NULL, NULL, NULL)) { try { - if (WaitForSingleObject(syncEvent, waitTimeout) != WAIT_OBJECT_0) { - throw std::runtime_error("WaitForSingleObject failed!"); + DWORD status; + if ((status = WaitForSingleObject(beforeInputEvent, waitTimeout)) != WAIT_OBJECT_0) { + std::cerr.setf(std::ios::hex, std::ios::basefield); + std::cerr << "WaitForSingleObject returned unexpected status 0x" << status << std::endl; + std::cerr.unsetf(std::ios::hex); + throw std::runtime_error("WaitForSingleObject#1 failed!"); } INPUT_RECORD inputBuffer[(sizeof(UnicodeInputTestString) / sizeof(UnicodeInputTestString[0])) * 2]; @@ -521,13 +606,18 @@ static int testConsole() } writeInputKeyEvent(&inputBuffer[i*2], VK_RETURN); DWORD eventsWritten = 0; + // We need to wait a bit before writing to console so child process have started waiting for input on stdin. + Sleep(300); if (!WriteConsoleInputW(hIn, inputBuffer, sizeof(inputBuffer) / sizeof(inputBuffer[0]), &eventsWritten) || eventsWritten == 0) { throw std::runtime_error("WriteConsoleInput failed!"); } - if (WaitForSingleObject(syncEvent, waitTimeout) != WAIT_OBJECT_0) { - throw std::runtime_error("WaitForSingleObject failed!"); + if ((status = WaitForSingleObject(afterOutputEvent, waitTimeout)) != WAIT_OBJECT_0) { + std::cerr.setf(std::ios::hex, std::ios::basefield); + std::cerr << "WaitForSingleObject returned unexpected status 0x" << status << std::endl; + std::cerr.unsetf(std::ios::hex); + throw std::runtime_error("WaitForSingleObject#2 failed!"); } CONSOLE_SCREEN_BUFFER_INFO screenBufferInfo; if (!GetConsoleScreenBufferInfo(hOut, &screenBufferInfo)) { @@ -547,22 +637,30 @@ static int testConsole() } std::wstring wideTestString = kwsys::Encoding::ToWide(encodedTestString); std::wstring wideInputTestString = kwsys::Encoding::ToWide(encodedInputTestString); - if (memcmp(outputBuffer, wideTestString.c_str(), wideTestString.size()) == 0 && + if (memcmp(outputBuffer, wideTestString.c_str(), + wideTestString.size() * sizeof(wchar_t)) == 0 && memcmp(outputBuffer + screenBufferInfo.dwSize.X * 1, - wideTestString.c_str(), wideTestString.size()) == 0 && + wideTestString.c_str(), wideTestString.size() * sizeof(wchar_t)) == 0 && memcmp(outputBuffer + screenBufferInfo.dwSize.X * 2, UnicodeInputTestString, sizeof(UnicodeInputTestString) - sizeof(WCHAR)) == 0 && memcmp(outputBuffer + screenBufferInfo.dwSize.X * 3, - wideInputTestString.c_str(), wideInputTestString.size() - 1) == 0 + wideInputTestString.c_str(), + (wideInputTestString.size() - 1) * sizeof(wchar_t)) == 0 ) { didFail = 0; } else { std::cerr << "Console's output didn't match expected output!" << std::endl << std::flush; + dumpBuffers<wchar_t>(wideTestString.c_str(), outputBuffer, wideTestString.size()); + dumpBuffers<wchar_t>(wideTestString.c_str(), outputBuffer + screenBufferInfo.dwSize.X * 1, wideTestString.size()); + dumpBuffers<wchar_t>(UnicodeInputTestString, outputBuffer + screenBufferInfo.dwSize.X * 2, (sizeof(UnicodeInputTestString) - 1) / sizeof(WCHAR)); + dumpBuffers<wchar_t>(wideInputTestString.c_str(), outputBuffer + screenBufferInfo.dwSize.X * 3, wideInputTestString.size() - 1); } delete[] outputBuffer; } catch (const std::runtime_error &ex) { - std::cerr << ex.what() << std::endl << std::flush; + DWORD lastError = GetLastError(); + std::cerr << "In function " << __FUNCTION__ << ":" << ex.what() << std::endl << std::flush; + displayError(lastError); } finishProcess(didFail == 0); } @@ -585,12 +683,18 @@ int testConsoleBuf(int, char*[]) int ret = 0; #if defined(_WIN32) - syncEvent = CreateEventW(NULL, - FALSE, // auto-reset event - FALSE, // initial state is nonsignaled - SyncEventName); // object name - if (!syncEvent) { - std::cerr << "CreateEvent failed " << GetLastError() << std::endl; + beforeInputEvent = CreateEventW(NULL, + FALSE, // auto-reset event + FALSE, // initial state is nonsignaled + BeforeInputEventName); // object name + if (!beforeInputEvent) { + std::cerr << "CreateEvent#1 failed " << GetLastError() << std::endl; + return 1; + } + + afterOutputEvent = CreateEventW(NULL, FALSE, FALSE, AfterOutputEventName); + if (!afterOutputEvent) { + std::cerr << "CreateEvent#2 failed " << GetLastError() << std::endl; return 1; } @@ -602,7 +706,8 @@ int testConsoleBuf(int, char*[]) ret |= testFile(); ret |= testConsole(); - CloseHandle(syncEvent); + CloseHandle(beforeInputEvent); + CloseHandle(afterOutputEvent); #endif return ret; diff --git a/Source/kwsys/testConsoleBuf.hxx b/Source/kwsys/testConsoleBuf.hxx index 855028b..7c2f4c6 100644 --- a/Source/kwsys/testConsoleBuf.hxx +++ b/Source/kwsys/testConsoleBuf.hxx @@ -14,7 +14,8 @@ static const wchar_t cmdConsoleBufChild[] = L"testConsoleBufChild"; -static const wchar_t SyncEventName[] = L"SyncEvent"; +static const wchar_t BeforeInputEventName[] = L"BeforeInputEvent"; +static const wchar_t AfterOutputEventName[] = L"AfterOutputEvent"; // यूनिकोड είναι здорово! static const wchar_t UnicodeTestString[] = L"\u092F\u0942\u0928\u093F\u0915\u094B\u0921 " diff --git a/Source/kwsys/testConsoleBufChild.cxx b/Source/kwsys/testConsoleBufChild.cxx index 3b9ab71..2da39f2 100644 --- a/Source/kwsys/testConsoleBufChild.cxx +++ b/Source/kwsys/testConsoleBufChild.cxx @@ -42,16 +42,18 @@ int main(int argc, const char* argv[]) } std::string input; - HANDLE syncEvent = OpenEventW(EVENT_MODIFY_STATE, FALSE, SyncEventName); - if (syncEvent) { - SetEvent(syncEvent); + HANDLE event = OpenEventW(EVENT_MODIFY_STATE, FALSE, BeforeInputEventName); + if (event) { + SetEvent(event); + CloseHandle(event); } std::cin >> input; std::cout << input << std::endl; - if (syncEvent) { - SetEvent(syncEvent); - CloseHandle(syncEvent); + event = OpenEventW(EVENT_MODIFY_STATE, FALSE, AfterOutputEventName); + if (event) { + SetEvent(event); + CloseHandle(event); } #else static_cast<void>(argc); |