Esempio n. 1
0
void TclWriter::writeClass(UMLClassifier * c)
{
    if (!c) {
        uDebug() << "Cannot write class of NULL concept!";
        return;
    }
    QFile fileh, filetcl;

    // find an appropriate name for our file
    fileName_ = findFileName(c, ".tcl");
    if (fileName_.isEmpty()) {
        emit codeGenerated(c, false);
        return;
    }

    if (!openFile(fileh, fileName_)) {
        emit codeGenerated(c, false);
        return;
    }
    // preparations
    className_ = cleanName(c->name());
    if (!c->package().isEmpty()) {
        mNamespace = "::" + cleanName(c->package());
        mClassGlobal = mNamespace + "::" + className_;
    } else {
        mNamespace = "::";
        mClassGlobal = "::" + className_;
    }

    // write Header file
    writeHeaderFile(c, fileh);
    fileh.close();

    // Determine whether the implementation file is required.
    // (It is not required if the class is an enumeration.)
    bool need_impl = true;
    if (!c->isInterface()) {
        if (c->baseType() == UMLObject::ot_Enum)
            need_impl = false;
    }
    if (need_impl) {
        if (!openFile(filetcl, fileName_ + "body")) {
            emit codeGenerated(c, false);
            return;
        }
        // write Source file
        writeSourceFile(c, filetcl);
        filetcl.close();
    }
    // emit done code
    emit codeGenerated(c, true);
}
Esempio n. 2
0
/**
 * Call this method to generate cpp code for a UMLClassifier.
 * @param c   the class to generate code for
 */
void CppWriter::writeClass(UMLClassifier *c)
{
    if (!c) {
        uDebug() << "Cannot write class of NULL concept!";
        return;
    }

    QFile fileh, filecpp;

    // find an appropriate name for our file
    fileName_ = findFileName(c, ".h");
    if (fileName_.isEmpty()) {
        emit codeGenerated(c, false);
        return;
    }

    className_ = cleanName(c->name());

    if (c->visibility() != Uml::Visibility::Implementation) {
        if( !openFile(fileh, fileName_)) {
            emit codeGenerated(c, false);
            return;
        }
        // write Header file
        writeHeaderFile(c, fileh);
        fileh.close();
    }

    // Determine whether the implementation file is required.
    // (It is not required if the class is an enumeration.)
    bool need_impl = true;
    if (c->baseType() == Uml::ot_Enum) {
        need_impl = false;
    }
    if (need_impl) {
        fileName_.replace( QRegExp(".h$"), ".cpp");
        if( !openFile(filecpp, fileName_)) {
            emit codeGenerated(c, false);
            return;
        }
        // write Source file
        writeSourceFile(c, filecpp);
        filecpp.close();
    }

    emit codeGenerated(c, true);
}
Esempio n. 3
0
void createSourceFile(const char * dirname)
{
    std::multimap<std::string, std::string> sorted_paths;

    //Step 1: Open source file
    std::string header_name(dirname);
    std::ofstream source_file(("@PROJECT_BINARY_DIR@/viennacl/linalg/kernels/" + header_name + "_source.h").c_str());

    //Step 2: Write source header file preamble
    std::string dirname_uppercase(dirname);
    std::transform(dirname_uppercase.begin(), dirname_uppercase.end(), dirname_uppercase.begin(), toupper);
    source_file << "#ifndef VIENNACL_LINALG_KERNELS_" << dirname_uppercase << "_SOURCE_HPP_" << std::endl;
    source_file << "#define VIENNACL_LINALG_KERNELS_" << dirname_uppercase << "_SOURCE_HPP_" << std::endl;
    source_file << "//Automatically generated file from auxiliary-directory, do not edit manually!" << std::endl;
    source_file << "/** @file " << header_name << "_source.h" << std::endl;
    source_file << " *  @brief OpenCL kernel source file, generated automatically from scripts in auxiliary/. */" << std::endl;
    source_file << "namespace viennacl" << std::endl;
    source_file << "{" << std::endl;
    source_file << " namespace linalg" << std::endl;
    source_file << " {" << std::endl;
    source_file << "  namespace kernels" << std::endl;
    source_file << "  {" << std::endl;

    //Step 3: Write all OpenCL kernel sources into header file
    fs::path filepath = fs::system_complete( fs::path( dirname ) );
    if ( fs::is_directory( filepath ) )
    {
        //std::cout << "\n In directory " << filepath.directory_string() << std::endl;

        fs::directory_iterator end_iter;
        //write and register single precision sources:
        for ( fs::directory_iterator alignment_itr( filepath );
              alignment_itr != end_iter;
              ++alignment_itr )
        {
            if (fs::is_directory( alignment_itr->path() ))
            {
                std::cout << "\nGenerating kernels from directory " << alignment_itr->path().string() << std::endl;

                //write and register single precision sources:
                for ( fs::directory_iterator cl_itr( alignment_itr->path() );
                      cl_itr != end_iter;
                      ++cl_itr )
                {
#ifdef USE_OLD_BOOST_FILESYSTEM_VERSION
                    std::string fname = cl_itr->path().filename();
                    std::string alignment = alignment_itr->path().filename();
#else
                    std::string fname = cl_itr->path().filename().string();
                    std::string alignment = alignment_itr->path().filename().string();
#endif

                    size_t pos = fname.find(".cl");
                    if ( pos == std::string::npos )
                      continue;

                    if (fname.substr(fname.size()-3, 3) == ".cl")
                        sorted_paths.insert(std::make_pair(fname,alignment));
                        //std::cout << alignment_itr->path().filename() << "/" << fname << std::endl;
                } //for
            } //if is_directory
        } //for alignment_iterator
    } //if is_directory
    else
        std::cerr << "Cannot access directory " << dirname << std::endl;

    for(std::multimap<std::string,std::string>::const_iterator it = sorted_paths.begin() ; it != sorted_paths.end() ; ++it){
      writeSourceFile(source_file, it->first, dirname, it->second.c_str());
    }
    //Final Step: Write file tail:
    source_file << "  }  //namespace kernels" << std::endl;
    source_file << " }  //namespace linalg" << std::endl;
    source_file << "}  //namespace viennacl" << std::endl;
    source_file << "#endif" << std::endl;
    source_file << std::endl;
    source_file.close();
}