Exemplo n.º 1
0
/// 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
        }
    }
Exemplo n.º 2
0
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");
            }
        }
    }
Exemplo n.º 3
0
void Editor::idleDebugStatusChange(eDebuggerChangeStatus st)
    {
    if(st == DCS_RunState)
        {
        getEditFiles().updateDebugMenu();
        if(mDebugger.getChildState() == DCS_ChildPaused)
            {
            auto const &loc = mDebugger.getStoppedLocation();
            mEditFiles.viewModule(loc.getFilename(), loc.getLine());
            mDebugger.startGetStack();
            }
        }
    else if(st == DCS_Stack)
        {
        GtkTextView *view = GTK_TEXT_VIEW(ControlWindow::getTabView(
            ControlWindow::CT_Stack));
        Gui::setText(view, mDebugger.getStack());
        }
    else if(st == DCS_Value)
        {
//        mVarView.appendText(GuiTreeItem(), mDebugger.getVarValue().getAsString());
        GuiTreeItem item;
        appendTree(mVarView, item, mDebugger.getVarValue());

        GuiTreeItem root;
        int numChildren = mVarView.getNumChildren(root);
        OovString numPathStr;
        numPathStr.appendInt(numChildren-1);
        GuiTreePath path(numPathStr);
        mVarView.scrollToPath(path);
        }
    }
Exemplo n.º 4
0
eDupReturn createDuplicatesFile(/*OovStringRef const projDir,*/ std::string &outFn)
    {
    eDupReturn ret = DR_NoDupFilesFound;
    DuplicateOptions options;
    std::vector<DuplicateLineInfo> dupLineInfo;
    if(getDuplicateLineInfo(options, dupLineInfo))
        {
        FilePath outPath(Project::getProjectDirectory(), FP_Dir);
        outPath.appendDir(DupsDir);
        outPath.appendFile("Dups.txt");
        File outFile;
        OovStatus status = outFile.open(outPath, "w");
        if(status.ok())
            {
            outFn = outPath;
            for(auto const &lineInfo : dupLineInfo)
                {
                OovString str = "lines ";
                str.appendInt(lineInfo.mTotalDupLines);
                str += "  :  ";
                str += lineInfo.mFile1;
                str += " ";
                str.appendInt(lineInfo.mFile1StartLine);
                str += "  :  ";
                str += lineInfo.mFile2;
                str += " ";
                str.appendInt(lineInfo.mFile2StartLine);
                str += "\n";
                status = outFile.putString(str);
                if(!status.ok())
                    {
                    break;
                    }
                }
            ret = DR_Success;
            }
        else
            {
            ret = DR_UnableToCreateDirectory;
            }
        if(status.needReport())
            {
            status.report(ET_Error, "Unable to write to duplicates file");
            }
        }
    return ret;
    }
Exemplo n.º 5
0
OovString ModelStatement::makeOverloadKeyFromOperUSR(OovStringRef operStr)
    {
    OovString sym;
#define DEBUG_KEY 0
#if(DEBUG_KEY)
    sym = operStr;
    // Remove symbols that conflict with either the CompoundValue class or
    // ModelStatement name separator characters.
    sym.replaceStrs("@", "-");
    sym.replaceStrs("#", "-");
    sym.replaceStrs(":", "-");
    sym.appendInt(makeHash(operStr), 16);
#else
    sym.appendInt(makeHash(operStr), 16);
#endif
    return sym;
    }
Exemplo n.º 6
0
// This is recursive.
// This adds items if they does not exist.  It preserves the tree
// so that the state of expanded items will not be destroyed.
// childIndex of -1 is special since the name is used to find the item.
static void appendTree(GuiTree &varView, GuiTreeItem &parentItem,
    DebugResult const &debResult, int childIndex = -1)
    {
    OovString varPrefix = debResult.getVarName();
    OovString str = varPrefix;
    if(debResult.getValue().length() > 0)
        {
        varPrefix += " : ";
        str = varPrefix;
        str += debResult.getValue();
        }

    GuiTreeItem item;
    bool foundItem = false;
    if(childIndex == -1)
        {
        if(varView.findImmediateChildPartialMatch(varPrefix, parentItem, item))
            {
            foundItem = true;
            }
        }
    else
        {
        foundItem = varView.getNthChild(parentItem, childIndex, item);
        }
    if(foundItem)
        {
        varView.setText(item, str);
        }
    else
        {
        item = varView.appendText(parentItem, str);
        }

    /// Remove items that no longer are available for the variable name.
        {
        int numDataChildren = debResult.getChildResults().size();
        int numTreeChildren = varView.getNumChildren(item);
        for(int childI=numDataChildren; childI<numTreeChildren; childI++)
            {
            varView.removeNthChild(item, childI);
            }
        }

    int callerChildIndex = 0;
    for(auto const &childRes : debResult.getChildResults())
        {
        appendTree(varView, item, *childRes.get(), callerChildIndex++);
        }
    /// @TODO - should only expand added item at parent level?
    GuiTreeItem root;
    int lastChild = varView.getNumChildren(root) - 1;
    OovString numPathStr;
    numPathStr.appendInt(lastChild);
    GuiTreePath path(numPathStr);
    varView.expandRow(path);
    }
Exemplo n.º 7
0
/// Copy a single source file and make a comment that contains the hit count
/// for each instrumented line.
static void updateCovSourceCounts(OovStringRef const relSrcFn,
        std::vector<int> &counts)
    {
    FilePath srcFn(Project::getCoverageSourceDirectory(), FP_Dir);
    srcFn.appendFile(relSrcFn);
    FilePath dstFn(Project::getCoverageProjectDirectory(), FP_Dir);
    dstFn.appendFile(relSrcFn);
    File srcFile;
    OovStatus status = srcFile.open(srcFn, "r");
    if(status.ok())
        {
        status = FileEnsurePathExists(dstFn);
        if(status.ok())
            {
            File dstFile;
            status = dstFile.open(dstFn, "w");
            if(status.ok())
                {
                char buf[1000];
                size_t instrCount = 0;
                while(srcFile.getString(buf, sizeof(buf), status))
                    {
                    if(strstr(buf, "COV_IN("))
                        {
                        if(instrCount < counts.size())
                            {
                            OovString countStr = "    // ";
                            countStr.appendInt(counts[instrCount]);
                            OovString newStr = buf;
                            size_t pos = newStr.find('\n');
                            newStr.insert(pos, countStr);
                            if(newStr.length() < sizeof(buf)-1)
                                {
                                strcpy(buf, newStr.getStr());
                                }
                            }
                        instrCount++;
                        }
                    status = dstFile.putString(buf);
                    if(!status.ok())
                        {
                        break;
                        }
                    }
                }
            }
        }
    if(status.needReport())
        {
        OovString err = "Unable to transfer coverage ";
        err += srcFn;
        err += " ";
        err += dstFn;
        status.report(ET_Error, err);
        }
    }
Exemplo n.º 8
0
void CppInstr::makeCovInstr(OovString &covStr)
    {
    appendLineEnding(covStr);
    covStr += "COV_IN(";
    covStr += getFileDefine();
    covStr += ", ";
    covStr.appendInt(mInstrCount++);
    covStr += ");";
    appendLineEnding(covStr);
    }
Exemplo n.º 9
0
OovStatusReturn ClassDiagram::saveDiagram(File &file)
    {
    OovStatus status(true, SC_File);
    NameValueFile nameValFile;

    CompoundValue names;
    CompoundValue xPositions;
    CompoundValue yPositions;
    OovString drawingName;
    for(auto const &node : mClassGraph.getNodes())
        {
        if(node.getType())
            {
            if(drawingName.length() == 0)
                {
                drawingName = node.getType()->getName();
                }
            names.addArg(node.getType()->getName());
            }
        else
            {
            names.addArg("Oov-Key");
            }
        OovString num;
        num.appendInt(node.getPosition().x);
        xPositions.addArg(num);

        num.clear();
        num.appendInt(node.getPosition().y);
        yPositions.addArg(num);
        }

    if(drawingName.length() > 0)
        {
        DiagramStorage::setDrawingHeader(nameValFile, DST_Class, drawingName);
        nameValFile.setNameValue("Names", names.getAsString());
        nameValFile.setNameValue("XPositions", xPositions.getAsString());
        nameValFile.setNameValue("YPositions", yPositions.getAsString());
        status = nameValFile.writeFile(file);
        }
    return status;
    }
Exemplo n.º 10
0
void Editor::findInFiles(char const * const srchStr, char const * const path,
        bool caseSensitive, bool sourceOnly, GtkTextView *view)
    {
    FindFiles findFiles(srchStr, caseSensitive, sourceOnly, view);
    OovStatus status = findFiles.recurseDirs(path);
    if(status.needReport())
        {
        OovString err = "Unable to search path ";
        err += path;
        status.report(ET_Error, err);
        }
    OovString matchStr = "Found ";
    matchStr.appendInt(findFiles.getNumMatches());
    matchStr += " matches";
    Gui::appendText(view, matchStr);
    }
Exemplo n.º 11
0
// Return true while success.
bool FindFiles::processFile(OovStringRef const filePath)
    {
    bool success = true;
    FilePath ext(filePath, FP_File);

    bool isSource = (isCppHeader(ext) || isCppSource(ext) || isJavaSource(ext));
    if(mSourceFilesOnly ? isSource : true)
        {
        FILE *fp = fopen(filePath.getStr(), "r");
        if(fp)
            {
            char buf[1000];
            int lineNum = 0;
            while(fgets(buf, sizeof(buf), fp))
                {
                lineNum++;
                char const *match=NULL;
                if(mCaseSensitive)
                    {
                    match = strstr(buf, mSrchStr.c_str());
                    }
                else
                    {
                    match = strcasestr(buf, mSrchStr.c_str());
                    }
                if(match)
                    {
                    mNumMatches++;
                    OovString matchStr = filePath;
                    matchStr += ':';
                    matchStr.appendInt(lineNum);
                    matchStr += "   ";
                    matchStr += buf;
//                  matchStr += '\n';
                    Gui::appendText(mView, matchStr);
                    }
                }
            fclose(fp);
            }
        }
    return success;
    }
Exemplo n.º 12
0
void EditOptions::setScreenCoord(char const * const tag, int val)
    {
    OovString str;
    str.appendInt(val);
    setNameValue(tag, str);
    }