Beispiel #1
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);
        }
    }
Beispiel #2
0
void CppInstr::insertNonCompoundInstr(CXCursor cursor)
    {
    if(!clang_Cursor_isNull(cursor))
        {
        CXCursorKind cursKind = clang_getCursorKind(cursor);
// return statements that are children of if statements must be instrumented
// if not in a compound statement.
//      if(cursKind != CXCursor_CompoundStmt /*&& clang_isStatement(cursKind)*/)

        // If this is a compound statement, then it will be instrumented anyway.
        if(cursKind != CXCursor_CompoundStmt)
            {
            bool doInstr = true;
            // There is sometimes a parsing error where a null statement is returned.
            // This occurs when all headers are not included or defines are not proper?
            if(cursKind == CXCursor_NullStmt)
                {
                CXStringDisposer name(clang_getCursorSpelling(cursor));
                if(name[0] != ';')
                    {
                    SourceLocation loc(cursor);
                    fprintf(stderr, "Unable to instrument line %d\n", loc.getLine());
                    doInstr = false;
                    }
                }
            if(doInstr)
                {
#if(DEBUG_PARSE)
                debugInstr(cursor, "insertNCI", mInstrCount);
#endif
                SourceRange range(cursor);
                OovString covStr;
                makeCovInstr(covStr);
                covStr.insert(0, "{");
                insertOutputText(covStr, range.getStartLocation().getOffset());
                insertOutputText("\n}\n", range.getEndLocation().getOffset()+1);
                }
            }
        }
    }