Пример #1
0
/*
class OovMonitorWriter
        {
        public:
                OovMonitorWriter():
                        mFp(0)
                        {}
                ~OovMonitorWriter()
                        {
                        fclose(mFp);
                        }
                void append(int fileIndex, int instrIndex)
                        {
                        if(!mFp)
                                {
                                mFp = fopen("OovMonitor.txt", "a");
                                }
                                {
//                              std::lock_guard<std::mutex> writeMutexLock(mWriteMutex);
                                std::stringstream id;
                                id << std::this_thread::get_id();
                                fprintf(mFp, "%s %d %d\n", id.str().c_str(), fileIndex, instrIndex);
                                fflush(mFp);
                                }
                        }

        private:
                FILE *mFp;
//              std::mutex mWriteMutex;
        };

OovMonitorWriter sOovMonitor;

void OovMonitor(int fileIndex, int instrIndex)
        {
        sOovMonitor.append(fileIndex, instrIndex);
        }
*/
void CppInstr::updateCoverageSource(OovStringRef const /*fn*/, OovStringRef const covDir)
    {
    FilePath outFn(covDir, FP_Dir);
    outFn.appendDir("covLib");
    OovStatus status = FileEnsurePathExists(outFn);
    if(status.ok())
        {
        outFn.appendFile("OovCoverage.cpp");

            if(!FileIsFileOnDisk(outFn, status))
            {
            File file;
            status = file.open(outFn, "w");

                static char const *lines[] = {
                "// Automatically generated file by OovCovInstr\n",
                "// This appends coverage data to either a new or existing file,\n"
                "// although the number of instrumented lines in the project must match.\n"
                "// This file must be compiled and linked into the project.\n",
                "#include <stdio.h>\n",
                "#include \"OovCoverage.h\"\n",
                "\n",
                "unsigned short gCoverage[COV_TOTAL_INSTRS];\n",
                "\n",
                "class cCoverageOutput\n",
                "  {\n",
                "  public:\n",
                "  cCoverageOutput()\n",
                "    {\n",
                "    // Initialize because some compilers may not initialize statics (TI)\n",
                "    for(int i=0; i<COV_TOTAL_INSTRS; i++)\n",
                "      gCoverage[i] = 0;\n",
                "    }\n",
                "  ~cCoverageOutput()\n",
                "    {\n",
                "      update();\n",
                "    }\n",
                "  void update()\n",
                "    {\n",
                "    read();\n",
                "    write();\n",
                "    }\n",
                "\n",
                "  private:\n",
                "  int getFirstIntFromLine(FILE *fp)\n",
                "    {\n",
                "   char buf[80];\n",
                "   fgets(buf, sizeof(buf), fp);\n",
                "   unsigned int tempInt = 0;\n",
                "           sscanf(buf, \"%u\", &tempInt);\n",
                "   return tempInt;\n",
                "    }\n",
                "  void read()\n",
                "    {\n",
                "    FILE *fp = fopen(\"OovCoverageCounts.txt\", \"r\");\n",
                "    if(fp)\n",
                "      {\n",
                "      int numInstrs = getFirstIntFromLine(fp);\n",
                "      if(numInstrs == COV_TOTAL_INSTRS)\n",
                "        {\n",
                "        for(int i=0; i<COV_TOTAL_INSTRS; i++)\n",
                "          {\n",
                "          gCoverage[i] += getFirstIntFromLine(fp);\n",
                "          }\n",
                "        }\n",
                "      fclose(fp);\n",
                "      }\n",
                "    }\n",
                "  void write()\n",
                "    {\n",
                "    FILE *fp = fopen(\"OovCoverageCounts.txt\", \"w\");\n",
                "    if(fp)\n",
                "      {\n",
                "      fprintf(fp, \"%d   # Number of instrumented lines\\n\", COV_TOTAL_INSTRS);\n",
                "      for(int i=0; i<COV_TOTAL_INSTRS; i++)\n",
                "        {\n",
                "        fprintf(fp, \"%u\", gCoverage[i]);\n",
                "        gCoverage[i] = 0;\n",
                "        fprintf(fp, \"\\n\");\n",
                "        }\n",
                "      fclose(fp);\n",
                "      }\n",
                "    }\n",
                "  };\n",
                "\n",
                "cCoverageOutput coverageOutput;\n"
                "\n",
                "void updateCoverage()\n",
                "  { coverageOutput.update(); }\n"

                };
            for(size_t i=0; i<sizeof(lines)/sizeof(lines[0]) && status.ok(); i++)
                {
                status = file.putString(lines[i]);
                if(!status.ok())
                    {
                    break;
                    }
                }
            }
        }
    if(!status.ok())
        {
        OovString err = "Unable to update coverage source ";
        err += outFn;
        status.report(ET_Error, err);
        }
    }
Пример #2
0
OovStatusReturn ClassDiagram::loadDiagram(File &file)
    {
    NameValueFile nameValFile;
    OovStatus status = nameValFile.readFile(file);
    if(status.ok())
        {
        CompoundValue names;
        names.parseString(nameValFile.getValue("Names"));
        CompoundValue xPositions;
        xPositions.parseString(nameValFile.getValue("XPositions"));
        CompoundValue yPositions;
        yPositions.parseString(nameValFile.getValue("YPositions"));
        std::vector<ClassNode> &nodes = getNodes();
        for(size_t i=0; i<names.size(); i++)
            {
            OovString name = names[i];
            if(i == 0)
                {
                // The node at index zero is the graph key, and is not stored in
                // the graph with a name or type.
                // The node at index one is the first class, which is typically the
                // same as the drawing name.
                eDiagramStorageTypes drawingType;
                OovString drawingName;
                DiagramStorage::getDrawingHeader(nameValFile, drawingType, drawingName);
                // This adds the key automatically as item index zero.
                // Call this function to set the last selected class name for the journal.
                clearGraphAndAddClass(drawingName, ClassGraph::AN_All,
                        ClassDiagram::DEPTH_SINGLE_CLASS, false);
                int x=0;
                int y=0;
                xPositions[i].getInt(0, INT_MAX, x);
                yPositions[i].getInt(0, INT_MAX, y);
                if(nodes.size() > 0)
                    {
                    nodes[0].setPosition(GraphPoint(x, y));
                    }
                }
            else
                {
                // This will not add duplicates, so if the name is different
                // from the drawingName, it will be added.
                addClass(name, ClassGraph::AN_All,
                    ClassDiagram::DEPTH_SINGLE_CLASS, false);
                }

            auto nodeIter = std::find_if(nodes.begin(), nodes.end(),
                [&name](ClassNode &node)
                { return(node.getType() && name == node.getType()->getName()); });
            if(nodeIter != nodes.end())
                {
                int x=0;
                int y=0;
                xPositions[i].getInt(0, INT_MAX, x);
                yPositions[i].getInt(0, INT_MAX, y);
                nodeIter->setPosition(GraphPoint(x, y));
                }
            }
        }
    return status;
    }