Невозможно преобразовать 'bool' в 'NEDElement *' - PullRequest
1 голос
/ 15 апреля 2020

Во время установки Omnetpp, на последнем шаге "make", я обнаружил ошибку, которая говорит

**`cannot convert ‘bool’ to ‘NEDElement`**  
 in return  np->getErrors()->addError("", "unable to allocate work memory"); return false;}
Makefile:51: recipe for target '/home/shivanshu/Desktop/FinalProject/omnetpp-4.2.2/out/gcc-release/src/nedxml/ned2.tab.o' failed
make[2]: *** [/home/shivanshu/Desktop/FinalProject/omnetpp-4.2.2/out/gcc-release/src/nedxml/ned2.tab.o] Error 1
make[2]: Leaving directory '/home/shivanshu/Desktop/FinalProject/omnetpp-4.2.2/src/nedxml'
Makefile:96: recipe for target 'nedxml' failed
make[1]: *** [nedxml] Error 2
make[1]: Leaving directory '/home/shivanshu/Desktop/FinalProject/omnetpp-4.2.2'
Makefile:19: recipe for target 'allmodes' failed
make: *** [allmodes] Error 2

Соответствующая функция, как показано ниже, иногда возвращает тип NEDElement *, а иногда возвращение bool.

NEDElement *doParseNED2(NEDParser *p, const char *nedtext)
{
#if YYDEBUG != 0      /* #if added --VA */
    yydebug = YYDEBUGGING_ON;
#endif

    NONREENTRANT_NED_PARSER(p);

    // reset the lexer
    pos.co = 0;
    pos.li = 1;
    prevpos = pos;

    yyin = NULL;
    yyout = stderr; // not used anyway

    // alloc buffer
    struct yy_buffer_state *handle = yy_scan_string(nedtext);
    if (!handle)
        {np->getErrors()->addError("", "unable to allocate work memory"); return false;}

    // create parser state and NEDFileElement
    resetParserState();
    ps.nedfile = new NedFileElement();

    // store file name with slashes always, even on Windows -- neddoc relies on that
    ps.nedfile->setFilename(slashifyFilename(np->getFileName()).c_str());
    ps.nedfile->setVersion("2");

    // storing the start and end position of the whole file for the NedFileElement
    // NOTE: we cannot use storePos() because it strips off the leading spaces
    // and comments from the element.
    YYLTYPE pos = np->getSource()->getFullTextPos();
    NEDSourceRegion region;
    region.startLine = pos.first_line;
    region.startColumn = pos.first_column;
    region.endLine = pos.last_line;
    region.endColumn = pos.last_column;
    ps.nedfile->setSourceRegion(region);

    // store file comment
    storeFileComment(ps.nedfile);

    ps.propertyscope.push(ps.nedfile);

    globalps = ps; // remember this for error recovery

    if (np->getStoreSourceFlag())
        storeSourceCode(ps.nedfile, np->getSource()->getFullTextPos());

    // parse
    try
    {
        yyparse();
    }
    catch (NEDException& e)
    {
        yyerror((std::string("error during parsing: ")+e.what()).c_str());
        yy_delete_buffer(handle);
        return 0;
    }

    if (np->getErrors()->empty())
    {
        // more sanity checks
        if (ps.propertyscope.size()!=1 || ps.propertyscope.top()!=ps.nedfile)
            INTERNAL_ERROR0(NULL, "error during parsing: imbalanced propertyscope");
        if (!ps.blockscope.empty() || !ps.typescope.empty())
            INTERNAL_ERROR0(NULL, "error during parsing: imbalanced blockscope or typescope");
    }
    yy_delete_buffer(handle);

    return ps.nedfile;
}

Я искал его на inte rnet, но обнаружил, что у вас должна быть последняя версия g cc, но у меня уже есть g cc версия 7.5.

Пожалуйста, помогите.

1 Ответ

2 голосов
/ 15 апреля 2020

Проблема в том, что он пытается преобразовать логическое значение в указатель. Вы можете вызвать его с помощью приведения, но я бы предложил сделать то же, что и в других случаях неудачи: изменить return false; на return 0; (или лучше, но немного отличаться от других, return nullptr;).

...