Skip to content

Commit

Permalink
Handle the redeclare replaceable short class definition (#12047)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Feb 29, 2024
1 parent a941258 commit 3b7ae01
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions OMEdit/OMEditLIB/FlatModelica/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ QString FlatModelica::Parser::getModelicaComment(QString element)
* \param comment
* Parses the code like,
* redeclare ClassA classA "A"
* and returns ClassA, the type of the component and modifier if any and comment.
* and returns ClassA, the type of the component and modifier (if any) and comment.
*/
void FlatModelica::Parser::getTypeFromElementRedeclaration(const QString &elmentRedeclaration, QString &type, QString &modifier, QString &comment)
{
Expand Down Expand Up @@ -106,7 +106,8 @@ void FlatModelica::Parser::getTypeFromElementRedeclaration(const QString &elment
* \param comment
* Parses the code like,
* redeclare model M = C
* and returns M, the type of the short class specifier and modification if any and comment.
* redeclare replaceable model M = C
* and returns the type of the short class specifier and modification (if any) and comment.
*/
void FlatModelica::Parser::getShortClassTypeFromElementRedeclaration(const QString &elmentRedeclaration, QString &type, QString &modifier, QString &comment)
{
Expand All @@ -115,15 +116,24 @@ void FlatModelica::Parser::getShortClassTypeFromElementRedeclaration(const QStri
antlr4::CommonTokenStream tokens(&lexer);
openmodelica::modelicaParser parser(&tokens);
openmodelica::modelicaParser::Element_redeclarationContext *pElement_redeclarationContext = parser.element_redeclaration();
if (pElement_redeclarationContext && pElement_redeclarationContext->short_class_definition()) {
type = QString::fromStdString(pElement_redeclarationContext->short_class_definition()->short_class_specifier()->type_specifier()->getText());
if (pElement_redeclarationContext->short_class_definition()->short_class_specifier()->class_modification()) {
modifier = getModificationFromStartAndStopInterval(pElement_redeclarationContext->short_class_definition()->short_class_specifier()->class_modification()->start,
pElement_redeclarationContext->short_class_definition()->short_class_specifier()->class_modification()->stop);
} else {
modifier = "";
openmodelica::modelicaParser::Short_class_definitionContext *pShort_class_definitionContext = 0;
if (pElement_redeclarationContext) {
if (pElement_redeclarationContext->short_class_definition()) {
pShort_class_definitionContext = pElement_redeclarationContext->short_class_definition();
} else if (pElement_redeclarationContext->element_replaceable()) {
pShort_class_definitionContext = pElement_redeclarationContext->element_replaceable()->short_class_definition();
}

if (pShort_class_definitionContext) {
type = QString::fromStdString(pShort_class_definitionContext->short_class_specifier()->type_specifier()->getText());
if (pShort_class_definitionContext->short_class_specifier()->class_modification()) {
modifier = getModificationFromStartAndStopInterval(pShort_class_definitionContext->short_class_specifier()->class_modification()->start,
pShort_class_definitionContext->short_class_specifier()->class_modification()->stop);
} else {
modifier = "";
}
comment = QString::fromStdString(pShort_class_definitionContext->short_class_specifier()->comment()->getText());
}
comment = QString::fromStdString(pElement_redeclarationContext->short_class_definition()->short_class_specifier()->comment()->getText());
}
}

Expand Down

0 comments on commit 3b7ae01

Please sign in to comment.