/// For every includer file that is run across during parsing, this means that /// the includer file was fully parsed, and that no old included information /// needs to be kept, except to check if the old included information has not /// changed. /// /// This code assumes that no tricks are played with ifdef values, and /// ifdef values must be the same every time a the same file is included. void IncDirDependencyMap::write() { bool anyChanges = false; time_t curTime; time_t changedTime = 0; time(&curTime); #if(SHARED_FILE) SharedFile file; if(!writeFileExclusiveReadUpdate(file)) { fprintf(stderr, "\nOovCppParser - Write file sharing error %s\n", getFilename().c_str()); } #endif // Append new values from parsed includes into the original NameValueFile. // Update existing values times and make new dependencies. for(const auto &newMapItem : mParsedIncludeDependencies) { bool changed = includedPathsChanged(newMapItem.first, newMapItem.second); if(changed) { // Cheat and say updated time and checked time are the same. changedTime = curTime; CompoundValue newIncludedInfoCompVal; OovString changeStr; changeStr.appendInt(changedTime); newIncludedInfoCompVal.addArg(changeStr); OovString checkedStr; checkedStr.appendInt(curTime); newIncludedInfoCompVal.addArg(checkedStr); for(const auto &str : newMapItem.second) { size_t pos = newIncludedInfoCompVal.find(str); if(pos == CompoundValue::npos) { newIncludedInfoCompVal.addArg(str); } } setNameValue(newMapItem.first, newIncludedInfoCompVal.getAsString()); anyChanges = true; } } if(file.isOpen() && anyChanges) { #if(SHARED_FILE) if(!writeFileExclusive(file)) { OovString str = "Unable to write include map file"; OovError::report(ET_Error, str); } #else writeFile(); #endif } }
void CoverageHeader::write(SharedFile &outDefFile, OovStringRef const /*srcFn*/, int numInstrLines) { std::string fnDef = getFileDefine(); mInstrDefineMap[fnDef] = numInstrLines; int totalCount = 0; for(auto const &defItem : mInstrDefineMap) { totalCount += defItem.second; } if(outDefFile.isOpen()) { OovString buf; static char const *lines[] = { "// Automatically generated file by OovCovInstr\n", "// This file should not normally be edited manually.\n", "#define COV_IN(fileIndex, instrIndex) gCoverage[fileIndex+instrIndex]++;\n", }; for(size_t i=0; i<sizeof(lines)/sizeof(lines[0]); i++) { buf += lines[i]; } buf += "#define COV_TOTAL_INSTRS "; buf.appendInt(totalCount); buf += "\n"; buf += "extern unsigned short gCoverage[COV_TOTAL_INSTRS];\n"; int coverageCount = 0; for(auto const &defItem : mInstrDefineMap) { OovString def = "#define "; def += defItem.first; def += " "; def.appendInt(coverageCount); coverageCount += defItem.second; def += " // "; def.appendInt(defItem.second); def += "\n"; buf += def; } outDefFile.truncate(); OovStatus status = outDefFile.seekBegin(); if(status.ok()) { status = outDefFile.write(&buf[0], static_cast<int>(buf.size())); } if(status.needReport()) { status.report(ET_Error, "Unable to write coverage source"); } } }