예제 #1
0
    ///////////////////////////////////////////////////////////
    // Helper functions
    //
    ///////////////////////////////////////////////////////////
    const QString convertRaw(UInt32 number)
    {
        // Prepares the conversion
        QString rawString("{raw:{0}}");
        QString replace = QString::number(number, 16);

        // Performs the conversion
        return QString(rawString.replace("{0}", replace.toUpper()));
    }
예제 #2
0
void CommentHandler::handleComment(Annotator &A, Generator& generator, clang::Sema &Sema,
                                   const char *bufferStart, int commentStart, int len,
                                   clang::SourceLocation searchLocBegin, clang::SourceLocation searchLocEnd,
                                   clang::SourceLocation commentLoc)
{
    llvm::StringRef rawString(bufferStart+commentStart, len);
    std::string attributes;
    std::string DeclRef;


    if ((rawString.ltrim().startswith("/**") && !rawString.ltrim().startswith("/***"))
            || rawString.ltrim().startswith("/*!") || rawString.ltrim().startswith("//!")
            || (rawString.ltrim().startswith("///") && !rawString.ltrim().startswith("////")))
#if CLANG_VERSION_MAJOR==3 && CLANG_VERSION_MINOR<=4
        if (rawString.find("deprecated") == rawString.npos) // workaround crash in comments::Sema::checkDeprecatedCommand
#endif
    {
        attributes = "class=\"doc\"";

        clang::Preprocessor &PP = Sema.getPreprocessor();
        clang::comments::CommandTraits traits(PP.getPreprocessorAllocator(), clang::CommentOptions());
#if CLANG_VERSION_MAJOR==3 && CLANG_VERSION_MINOR<=4
        traits.registerBlockCommand("deprecated"); // avoid typo correction leading to crash.
#endif
        clang::comments::Lexer lexer(PP.getPreprocessorAllocator(), PP.getDiagnostics(), traits,
                                     clang::SourceLocation::getFromRawEncoding(commentStart), bufferStart + commentStart, bufferStart + commentStart + len);
        clang::comments::Sema sema(PP.getPreprocessorAllocator(), PP.getSourceManager(), PP.getDiagnostics(), traits, &PP);
        clang::comments::Parser parser(lexer, sema, PP.getPreprocessorAllocator(), PP.getSourceManager(),
                                       PP.getDiagnostics(), traits);
        auto fullComment = parser.parseFullComment();
        CommentVisitor visitor{A, generator, traits, Sema};
        visitor.visit(fullComment);
        DeclRef = visitor.DeclRef;
    }

    if (!DeclRef.empty()) {
        docs.insert({std::move(DeclRef), { rawString.str() , commentLoc }});
        generator.addTag("i", attributes, commentStart, len);
        return;
    }

    // Try to find a matching declaration
    const auto &dof = decl_offsets;
    //is there one and one single decl in that range.
    auto it_before = dof.lower_bound(searchLocBegin);
    auto it_after = dof.upper_bound(searchLocEnd);
    if (it_before != dof.end() && it_after != dof.begin() && it_before == (--it_after)) {
        if (it_before->second.second) {
            docs.insert({it_before->second.first, { rawString.str() , commentLoc }});
        } else {
            attributes %= " data-doc=\"" % it_before->second.first % "\"";
        }
    }

    generator.addTag("i", attributes, commentStart, len);
}
예제 #3
0
/**
 * Constructor method of the class. Creates child processes and waits for each
 * of the created child process. When they all terminate, it returns.
 */
MainProcess::MainProcess()
{
    // log the main process' start event.
    Logger::writeToLogFile("Main process started!");
    
    // calculate the number of child processes to be created.
    int processCount = this->getNumberOfChildren(Config::readValue("numberOfChildren", "main"));
    
    // store the process ids of all child processes. it will be used for waiting
    // for their termination.
    int processIds[processCount];

    // create a random seed.
    srand((unsigned) time(NULL));
    // create the key.
    std::vector<unsigned char> key(56, '0');
    // generate the key randomly.

    for (int i = 40; i < 56; i++) {
        int ran = (((((rand()) % 65536) + 1) >> i) & 1);
        if (0 == ran) {
            key.at(i) = '0';
        } else {
            key.at(i) = '1';
        }
    }

    // generate the random key.
    Logger::writeToLogFile("Key is: %s", (const char*) key.data());
    
    // -------------------------------------------------------------------------
    // @todo
    AlgorithmDES algoDES;
    std::string rawString("This is the raw string!");
    std::string encryptedString;
    encryptedString = algoDES.encrpyt(rawString, (const char*) key.data(), 56);
    
    // create child processes.
    for (int i = 0; i < processCount; i++) {
        // store the child process id in the local variable.
        processIds[i] = this->createChild(rawString, encryptedString, 1, 56, i, processCount);
    }
    // -------------------------------------------------------------------------
    
    // wait for each child to exit.
    for (int i = 0; i < processCount; i++) {
        // create a local variable for the exit status of the child process.
        int status;
        
        // wait for the ith child to terminate.
        while (-1 == waitpid(processIds[i], &status, 0));
        
        // log the child process' terminate event.
        Logger::writeToLogFile("Child process %s is terminated!",
            this->generateChildName(processIds[i])
        );
        
        if (WIFEXITED(status)) {
            // if the key is found;
            if (2 == WEXITSTATUS(status)) {
                Logger::writeToLogFile("All child processes will be terminated now!");

                // kill all child processes.
                for (int i = 0; i < processCount; i++) {
                    kill(processIds[i], SIGTERM);
                }
            }
        }
    }
    
    // log the main process' terminate event.
    Logger::writeToLogFile("Main process ended!");
}