From 0956bd24f0deb968910c4e453a72b16b30093651 Mon Sep 17 00:00:00 2001 From: nemu Date: Thu, 2 Oct 2008 11:59:14 +0000 Subject: [PATCH] added an additional check which inspects if map's and fun's given somewhere are really declared --- src/classes/PMsrHandler.cpp | 204 ++++++++++++++++++++++++++++++++++++ src/include/PMsrHandler.h | 2 + 2 files changed, 206 insertions(+) diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index 254b30ef..081e70da 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -233,6 +233,19 @@ int PMsrHandler::ReadMsrFile() } } + // check that if maps are present in the theory- and/or function-block, + // that there are really present in the run block + if (result == PMUSR_SUCCESS) + if (!CheckMaps()) + result = PMUSR_MSR_SYNTAX_ERROR; + + + // check that if functions are present in the theory- and/or run-block, that they + // are really present in the function block + if (result == PMUSR_SUCCESS) + if (!CheckFuncs()) + result = PMUSR_MSR_SYNTAX_ERROR; + // clean up fit_parameter.clear(); theory.clear(); @@ -2414,6 +2427,197 @@ bool PMsrHandler::CheckUniquenessOfParamNames(unsigned int &parX, unsigned int & return unique; } +//-------------------------------------------------------------------------- +// CheckMaps (private) +//-------------------------------------------------------------------------- +/** + *

Checks if map entries found in the theory- or function-block are also + * present in the run-block, if yes return true otherwise return false. + */ +bool PMsrHandler::CheckMaps() +{ + bool result = true; + + PIntVector mapVec; + PIntVector mapBlock; + PIntVector mapLineNo; + + TObjArray *tokens = 0; + TObjString *ostr = 0; + TString str; + + int no; + + // check if map is present in the theory-block + for (unsigned int i=0; iGetEntries(); j++) { + ostr = dynamic_cast(tokens->At(j)); + str = ostr->GetString(); + if (str.Contains("map", TString::kIgnoreCase)) { + if (FilterFunMapNumber(str, "map", no)) { + mapVec.push_back(no); + mapBlock.push_back(0); // 0 = theory-block + mapLineNo.push_back(fTheory[i].fLineNo); + } + } + } + // clean up tokens + if (tokens) { + delete tokens; + tokens = 0; + } + } + } + + // check if map is present in the function-block + for (unsigned int i=0; iGetEntries(); j++) { + ostr = dynamic_cast(tokens->At(j)); + str = ostr->GetString(); + if (str.Contains("map", TString::kIgnoreCase)) { + if (FilterFunMapNumber(str, "map", no)) { + mapVec.push_back(no); + mapBlock.push_back(1); // 1 = theory-block + mapLineNo.push_back(fTheory[i].fLineNo); + } + } + } + // clean up tokens + if (tokens) { + delete tokens; + tokens = 0; + } + } + } + + // check if present maps are found in the run-block + bool found; + for (unsigned int i=0; i= 0)) { // map value smaller than run-block map length + if (fRuns[j].fMap[mapVec[i]-MSR_PARAM_MAP_OFFSET-1] != 0) { // map value in the run-block != 0 + found = true; + break; + } + } + } + if (!found) { // map not found + result = false; + cout << endl << ">> PMsrHandler::CheckMaps: **ERROR** map" << mapVec[i]-MSR_PARAM_MAP_OFFSET << " found in the "; + if (mapBlock[i] == 0) + cout << "theory-block "; + else + cout << "functions-block "; + cout << "in line " << mapLineNo[i] << " is not present in the run-block!"; + if (mapVec[i]-MSR_PARAM_MAP_OFFSET == 0) { + cout << endl << ">> by the way: map must be > 0 ..."; + } + } + } + + // clean up + mapVec.clear(); + mapBlock.clear(); + mapLineNo.clear(); + + return result; +} + +//-------------------------------------------------------------------------- +// CheckFuncs (private) +//-------------------------------------------------------------------------- +/** + *

Checks if fun entries found in the theory- and run-block are also + * present in the functions-block, if yes return true otherwise return false. + */ +bool PMsrHandler::CheckFuncs() +{ + bool result = true; + + PIntVector funVec; + PIntVector funBlock; + PIntVector funLineBlockNo; + + TObjArray *tokens = 0; + TObjString *ostr = 0; + TString str; + + int no; + + // check if func is present in the theory-block + for (unsigned int i=0; iGetEntries(); j++) { + ostr = dynamic_cast(tokens->At(j)); + str = ostr->GetString(); + if (str.Contains("fun", TString::kIgnoreCase)) { + if (FilterFunMapNumber(str, "fun", no)) { + funVec.push_back(no); + funBlock.push_back(0); // 0 = theory-block + funLineBlockNo.push_back(fTheory[i].fLineNo); + } + } + } + // clean up tokens + if (tokens) { + delete tokens; + tokens = 0; + } + } + } + + // check if func is present in the run-block + for (unsigned int i=0; i= MSR_PARAM_FUN_OFFSET) { // function found + funVec.push_back(fRuns[i].fNormParamNo); + funBlock.push_back(1); // 1 = run-block + funLineBlockNo.push_back(i+1); + } + } + + // check if present funcs are found in the functions-block + bool found; + for (unsigned int i=0; i> PMsrHandler::CheckFuncs: **ERROR** fun" << funVec[i]-MSR_PARAM_FUN_OFFSET << " found in the "; + if (funBlock[i] == 0) + cout << "theory-block in line " << funLineBlockNo[i] << " is not present in the functions-block!"; + else + cout << "run-block No " << funLineBlockNo[i] << " (norm) is not present in the functions-block!"; + } + } + + // clean up + funVec.clear(); + funBlock.clear(); + funLineBlockNo.clear(); + + return result; +} + //-------------------------------------------------------------------------- // CheckAndWriteComment //-------------------------------------------------------------------------- diff --git a/src/include/PMsrHandler.h b/src/include/PMsrHandler.h index a255cd67..98174905 100644 --- a/src/include/PMsrHandler.h +++ b/src/include/PMsrHandler.h @@ -83,6 +83,8 @@ class PMsrHandler virtual int ParameterInUse(unsigned int paramNo); virtual bool CheckUniquenessOfParamNames(unsigned int &parX, unsigned int &parY); + virtual bool CheckMaps(); + virtual bool CheckFuncs(); private: PMsrLines fComments; ///< holds the comments of the msr-file