Esempio n. 1
0
//--------------------------------------------------------------------------------------------------
void ParseComponent
(
    Component* componentPtr,            ///< The Component object to populate.
    const BuildParams_t& buildParams    ///< Build parameters obtained from the command line.
)
//--------------------------------------------------------------------------------------------------
{
    ComponentPtr = componentPtr;
    BuildParamsPtr = &buildParams;

    // Open the component's Component.cdef file for reading.
    std::string path = FindComponent(componentPtr->Path(), buildParams.SourceDirs());
    if (path == "")
    {
        throw Exception("Couldn't find component '" + componentPtr->Path() + "'.");
    }
    componentPtr->Path(path);

    std::string cdefFilePath = CombinePath(path, "/Component.cdef");
    FILE* file = fopen(cdefFilePath.c_str(), "r");
    if (file == NULL)
    {
        int error = errno;
        std::stringstream errorMessage;
        errorMessage << "Failed to open file '" << cdefFilePath << "'." <<
                        " Errno = " << error << "(" << strerror(error) << ").";
        throw Exception(errorMessage.str());
    }

    if (buildParams.IsVerbose())
    {
        std::cout << "Parsing '" << cdefFilePath << "'\n";
    }

    // Tell the parser to reset itself and connect to the new file stream for future parsing.
    cyy_FileName = cdefFilePath.c_str();
    cyy_IsVerbose = (BuildParamsPtr->IsVerbose() ? 1 : 0);
    cyy_EndOfFile = 0;
    cyy_ErrorCount = 0;
    cyy_set_lineno(1);
    cyy_restart(file);

    // Until the parsing is done,
    int parsingResult;
    do
    {
        // Start parsing.
        parsingResult = cyy_parse();
    }
    while ((parsingResult != 0) && (!cyy_EndOfFile));

    // Close the file
    fclose(file);

    // Halt if there were errors.
    if (cyy_ErrorCount > 0)
    {
        throw Exception("Errors encountered while parsing '" + cdefFilePath + "'.");
    }

    ComponentPtr = NULL;

    if (buildParams.IsVerbose())
    {
        std::cout << "Finished parsing '" << cdefFilePath << "'\n";
    }

    // Recursively, for each of the new component's sub-components,
    for (auto& mapEntry : componentPtr->SubComponents())
    {
        mapEntry.second = Component::FindComponent(mapEntry.first);

        // If the sub-component has not yet been parsed, create an object for it and parse it now.
        if (mapEntry.second == NULL)
        {
            mapEntry.second = Component::CreateComponent(mapEntry.first);

            ParseComponent(mapEntry.second, buildParams);
        }
    }
}
Esempio n. 2
0
//--------------------------------------------------------------------------------------------------
void ParseApp
(
    App& app,                           ///< The object to be populated.
    const BuildParams_t& buildParams    ///< Build parameters obtained from the command line.
)
//--------------------------------------------------------------------------------------------------
{
    AppPtr = &app;
    BuildParamsPtr = &buildParams;

    const std::string& path = app.DefFilePath();

    // Open the .adef file for reading.
    FILE* file = fopen(path.c_str(), "r");
    if (file == NULL)
    {
        int error = errno;
        std::stringstream errorMessage;
        errorMessage << "Failed to open file '" << path << "'." <<
                        " Errno = " << error << "(" << strerror(error) << ").";
        throw Exception(errorMessage.str());
    }

    if (buildParams.IsVerbose())
    {
        std::cout << "Parsing '" << path << "'\n";
    }

    // Tell the parser to reset itself and connect to the new file stream for future parsing.
    ayy_FileName = path.c_str();
    ayy_IsVerbose = (BuildParamsPtr->IsVerbose() ? 1 : 0);
    ayy_EndOfFile = 0;
    ayy_ErrorCount = 0;
    ayy_restart(file);

    // Until the parsing is done,
    int parsingResult;
    do
    {
        // Start parsing.
        parsingResult = ayy_parse();
    }
    while ((parsingResult != 0) && (!ayy_EndOfFile));

    // Close the file
    fclose(file);

    // Halt if there were errors.
    if (ayy_ErrorCount > 0)
    {
        throw Exception("Errors encountered while parsing '" + path + "'.");
    }

    AppPtr = NULL;
    BuildParamsPtr = NULL;

    if (buildParams.IsVerbose())
    {
        std::cout << "Finished parsing '" << path << "'\n";
    }
}