Skip to content

Commit

Permalink
Use choice comment in dropdown #7488 (#8382)
Browse files Browse the repository at this point in the history
- parse the choice using the antlr4 OMParser to fetch the comment
- populate the dropdown with the choice comment instead of the full redeclare
- todo: do not add the choicesAllMatching if there are choices (or put it on a flag)
- fix TestChoices.mo to be valid Modelica
- rename libomcparseantlr4 to libOMParser to make it more clear where it comes from
  • Loading branch information
adrpo committed Jan 9, 2022
1 parent 8291efd commit a499198
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .CI/common.groovy
Expand Up @@ -378,9 +378,9 @@ void buildGUI(stash, isQt5) {
sh 'echo ./configure `./config.status --config` > config.status.2 && bash ./config.status.2'
// compile OMSens_Qt for Qt5
if (isQt5) {
sh "touch omc.skip omc-diff.skip ReferenceFiles.skip omsimulator.skip && ${makeCommand()} -q -j${numPhysicalCPU()} omc omc-diff ReferenceFiles omsimulator" // Pretend we already built omc since we already did so
sh "touch omc.skip omc-diff.skip ReferenceFiles.skip omsimulator.skip && ${makeCommand()} -j${numPhysicalCPU()} omc omc-diff ReferenceFiles omsimulator omparser omsens_qt" // Pretend we already built omc since we already did so
} else {
sh "touch omc.skip omc-diff.skip ReferenceFiles.skip omsimulator.skip omsens_qt.skip && ${makeCommand()} -j${numPhysicalCPU()} -q omc omc-diff ReferenceFiles omsimulator omsens_qt" // Pretend we already built omc since we already did so
sh "touch omc.skip omc-diff.skip ReferenceFiles.skip omsimulator.skip omsens_qt.skip && ${makeCommand()} -j${numPhysicalCPU()} omc omc-diff ReferenceFiles omsimulator omparser omsens_qt" // Pretend we already built omc since we already did so
}
sh "${makeCommand()} -j${numPhysicalCPU()} ${outputSync()}" // Builds the GUI files

Expand Down Expand Up @@ -421,7 +421,7 @@ void buildAndRunOMEditTestsuite(stash) {
patchConfigStatus()
}
sh 'echo ./configure `./config.status --config` > config.status.2 && bash ./config.status.2'
sh "touch omc.skip omc-diff.skip ReferenceFiles.skip omsimulator.skip omedit.skip omplot.skip omparser.skip && ${makeCommand()} -q omc omc-diff ReferenceFiles omsimulator omedit omplot omparser" // Pretend we already built omc since we already did so
sh "touch omc.skip omc-diff.skip ReferenceFiles.skip omsimulator.skip omedit.skip omplot.skip && ${makeCommand()} omc omc-diff ReferenceFiles omsimulator omedit omplot omparser" // Pretend we already built omc since we already did so
sh "${makeCommand()} -j${numPhysicalCPU()} --output-sync=recurse omedit-testsuite" // Builds the OMEdit testsuite
sh label: 'RunOMEditTestsuite', script: '''
HOME="\$PWD/testsuite/libraries-for-testing"
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/OMEditGUI.unix.config.pri.in
Expand Up @@ -7,7 +7,7 @@ QMAKE_LINK = @CXX@
OPENMODELICAHOME = @OPENMODELICAHOME@
host_short = @host_short@

LIBS += -L@OPENMODELICAHOME@/lib/$$host_short/omc -lOMPlot -lomqwt -lfmilib_shared -L$$OMEDIT_ROOT/OMEditLIB/Debugger/Parser -lGDBMIParser -lomcparserantlr4 -lomantlr3 @RPATH_QMAKE@ -lOpenModelicaCompiler -lOpenModelicaRuntimeC -lomcruntime -lomcgc -L@OMBUILDDIR@/lib/$$host_short/omc @LIBOSG@ -lomopcua -lzmq -L@OMBUILDDIR@/lib -lOMSimulator @LIB_BOOST_REGEX@
LIBS += -L@OPENMODELICAHOME@/lib/$$host_short/omc -lOMPlot -lomqwt -lfmilib_shared -L$$OMEDIT_ROOT/OMEditLIB/Debugger/Parser -lGDBMIParser -L@OMBUILDDIR@/../OMParser/install/lib -Wl,-Bstatic -lOMParser -lantlr4-runtime -Wl,-Bdynamic -lomantlr3 @RPATH_QMAKE@ -lOpenModelicaCompiler -lOpenModelicaRuntimeC -lomcruntime -lomcgc -L@OMBUILDDIR@/lib/$$host_short/omc @LIBOSG@ -lomopcua -lzmq -L@OMBUILDDIR@/lib -lOMSimulator @LIB_BOOST_REGEX@

QMAKE_CXXFLAGS_RELEASE -= -O1
QMAKE_CXXFLAGS_RELEASE -= -O2
Expand Down
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/OMEditGUI.win.config.pri
Expand Up @@ -58,10 +58,10 @@ CONFIG(release, debug|release) { # release
} else { # 64-bit
LIBS += -L$$(OMDEV)/tools/msys/mingw64/bin
}
LIBS += -llibosgd.dll -llibosgViewerd.dll -llibOpenThreadsd.dll -llibosgDBd.dll -llibosgGAd.dll
LIBS += -llibosg.dll -llibosgViewer.dll -llibOpenThreads.dll -llibosgDB.dll -llibosgGA.dll
}
LIBS += -L$$OMEDIT_ROOT/OMEditLIB/Debugger/Parser -lGDBMIParser \
-L$$(OMBUILDDIR)/lib/omc -lomcparserantlr4 -lomantlr3 -lOMPlot -lomqwt -lomopcua -lzmq \
LIBS += -L$$(OMBUILDDIR)/../OMEdit/OMEditLIB/Debugger/Parser -lGDBMIParser \
-L$$(OMBUILDDIR)/lib/omc -L$$(OMBUILDDIR)/../OMParser/install/lib -Wl,-Bstatic -lOMParser -lantlr4-runtime -Wl,-Bdynamic -lomantlr3 -lOMPlot -lomqwt -lomopcua -lzmq \
-lOpenModelicaCompiler -lomcruntime -lOpenModelicaRuntimeC -lfmilib -lzlib -lModelicaExternalC -lomcgc -lpthread -lshlwapi \
-lws2_32 \
-L$$(OMBUILDDIR)/bin -lOMSimulator
6 changes: 5 additions & 1 deletion OMEdit/OMEditLIB/CMakeLists.txt
Expand Up @@ -258,6 +258,7 @@ target_include_directories(OMEditLib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(OMEditLib PUBLIC omedit::config)
target_link_libraries(OMEditLib PUBLIC libOMSimulator)
target_link_libraries(OMEditLib PUBLIC OMParser)
target_link_libraries(OMEditLib PUBLIC omedit::debugger::parser)
target_link_libraries(OMEditLib PUBLIC Qt5::Xml)
target_link_libraries(OMEditLib PUBLIC Qt5::Widgets)
Expand All @@ -284,7 +285,10 @@ target_link_libraries(OMEditLib PUBLIC ${OPENSCENEGRAPH_LIBRARIES})
set_target_properties(OMEditLib PROPERTIES
NO_SYSTEM_FROM_IMPORTED ON)

target_include_directories(OMEditLib PRIVATE ${OMCompiler_SOURCE_DIR}/Compiler/Script)
target_include_directories(OMEditLib PRIVATE
${OMCompiler_SOURCE_DIR}/Compiler/Script
${OMParser_BINARY_DIR}/
${OMParser_SOURCE_DIR}/3rdParty/antlr4/runtime/Cpp/runtime/src/)

target_link_options(OMEditLib PRIVATE -Wl,--no-undefined)

Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditLIB/Element/ElementProperties.cpp
Expand Up @@ -377,7 +377,8 @@ void Parameter::createValueWidget()
QStringList choices = mpComponent->getChoices();
for (i = 0; i < choices.size(); i++) {
QString choice = choices[i];
mpValueComboBox->addItem(choice, choice);
QString comment = StringHandler::getModelicaComment(choice);
mpValueComboBox->addItem(comment, choice);
}
}

Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditLIB/OMEditLIB.pro
Expand Up @@ -91,7 +91,9 @@ INCLUDEPATH += . ../ \
$$OPENMODELICAHOME/include/omc/scripting-API \
$$OPENMODELICAHOME/include/omc/c \
$$OPENMODELICAHOME/include/omc/c/util \
$$OPENMODELICAHOME/include/omc/fmil
$$OPENMODELICAHOME/include/omc/fmil \
$$OPENMODELICAHOME/../OMParser/ \
$$OPENMODELICAHOME/../OMParser/install/include/antlr4-runtime/

# Don't show the warnings from included headers.
# Don't add a space between for and open parenthesis below. Qt4 complains about it.
Expand Down
40 changes: 40 additions & 0 deletions OMEdit/OMEditLIB/Util/StringHandler.cpp
Expand Up @@ -34,6 +34,12 @@

//! @brief Contains functions used for parsing results obtained from OpenModelica Compiler.

#define ANTLR4CPP_STATIC
#include "antlr4-runtime.h"
#include "modelicaLexer.h"
#include "modelicaParser.h"
#include "modelicaBaseListener.h"

#include "StringHandler.h"
#include "Helper.h"
#include "Utilities.h"
Expand Down Expand Up @@ -1960,3 +1966,37 @@ QString StringHandler::number(double value, char format, int precision)
{
return QString::number(value, format, precision);
}

static std::string cmt = "";

class ModelicaCommentListener : public openmodelica::modelicaBaseListener {
void exitComment(openmodelica::modelicaParser::CommentContext *ctx) override {
cmt = ctx->getText();
}
};

/*!
* \brief StringHandler::getModelicaComment
* Helper for QString::getModelicaComment
* \param element
* \return comment
*/
QString StringHandler::getModelicaComment(QString element)
{
cmt = "";
std::string s = element.toStdString();
antlr4::ANTLRInputStream input(s);
openmodelica::modelicaLexer lexer(&input);
antlr4::CommonTokenStream tokens(&lexer);
openmodelica::modelicaParser parser(&tokens);
antlr4::tree::ParseTree* tree = parser.argument();
ModelicaCommentListener listener;
antlr4::tree::ParseTreeWalker::DEFAULT.walk(&listener, tree);
if (cmt.size() > 1)
{
QString q;
q = q.fromStdString(cmt);
return removeFirstLastQuotes(q);
}
return element;
}
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Util/StringHandler.h
Expand Up @@ -171,6 +171,7 @@ class StringHandler : public QObject
static QString removeLine(QString text, QString lineToRemove);
static QString insertClassAtPosition(QString parentClassText, QString childClassText, int linePosition, int nestedLevel);
static QString number(double value, char format = 'g', int precision = 16);
static QString getModelicaComment(QString element);
protected:
static QString mLastOpenDir;
};
Expand Down
5 changes: 4 additions & 1 deletion OMParser/.gitignore
Expand Up @@ -19,4 +19,7 @@ modelicaVisitor.cpp
modelicaVisitor.h
*.o
*.a
test/
test/mp
test/mp.exe
test/*.o

23 changes: 15 additions & 8 deletions OMParser/CMakeLists.txt
Expand Up @@ -36,12 +36,19 @@ add_custom_command(
)


add_library(omcparserantlr4 STATIC)
target_sources(omcparserantlr4 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/modelicaBaseListener.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaBaseVisitor.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaLexer.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaListener.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaParser.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaVisitor.cpp)
add_library(OMParser STATIC)
target_sources(OMParser PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/modelicaBaseListener.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaBaseVisitor.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaLexer.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaListener.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaParser.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaVisitor.cpp
${CMAKE_CURRENT_BINARY_DIR}/modelicaBaseListener.h
${CMAKE_CURRENT_BINARY_DIR}/modelicaBaseVisitor.h
${CMAKE_CURRENT_BINARY_DIR}/modelicaLexer.h
${CMAKE_CURRENT_BINARY_DIR}/modelicaListener.h
${CMAKE_CURRENT_BINARY_DIR}/modelicaParser.h
${CMAKE_CURRENT_BINARY_DIR}/modelicaVisitor.h)

target_link_libraries(omcparserantlr4 PUBLIC antlr4_static)
target_link_libraries(OMParser PUBLIC antlr4_static)
target_include_directories(OMParser PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
8 changes: 4 additions & 4 deletions OMParser/Makefile
Expand Up @@ -20,9 +20,9 @@ CPP_FILES=modelicaBaseListener.cpp modelicaBaseVisitor.cpp modelicaLexer.cpp
H_FILES=$(patsubst %.cpp,%.h,$(CPP_FILES))
OBJS=$(patsubst %.cpp,%.o,$(CPP_FILES))

all: libomcparserantlr4.a
all: libOMParser.a

libomcparserantlr4.a: $(OBJS)
libOMParser.a: $(OBJS)
$(AR) -s -r $@ $(OBJS)
mkdir -p $(OMBUILDDIR)/lib/$(host_short)/omc/ $(OMBUILDDIR)/include/omc/
cp -pR $@ $(OMBUILDDIR)/lib/$(host_short)/omc/
Expand All @@ -43,11 +43,11 @@ $(CPP_FILES): runtool
runtool: modelica.g4
java -cp 3rdParty/antlr4/tool/antlr-4.8-complete.jar org.antlr.v4.Tool -Dlanguage=Cpp -package openmodelica -listener -visitor modelica.g4

test: libomcparserantlr4.a
test: libOMParser.a
$(MAKE) -C test

clean-local:
rm -rf libomcparserantlr4.a $(OBJS) $(CPP_FILES) $(H_FILES) *.interp *.tokens
rm -rf libOMParser.a $(OBJS) $(CPP_FILES) $(H_FILES) *.interp *.tokens
$(MAKE) -C test clean

clean-runtime:
Expand Down
2 changes: 1 addition & 1 deletion OMParser/test/Makefile
Expand Up @@ -3,7 +3,7 @@ EXT=.exe

CFLAGS=-O3
CXXFLAGS=$(CFLAGS) -I../install/include/antlr4-runtime -I../ -std=c++11 -DANTLR4CPP_STATIC
LDFLAGS=-L../install/lib -L../ -lomcparserantlr4 -Bstatic -lantlr4-runtime -lstdc++ -Bdynamic -static-libgcc
LDFLAGS=-L../install/lib -L../ -Bstatic -lOMParser -lantlr4-runtime -lstdc++ -Bdynamic -static-libgcc

all: mp$(EXT) runtest

Expand Down
2 changes: 1 addition & 1 deletion testsuite/openmodelica/interactive-API/TestChoices.mo
Expand Up @@ -15,7 +15,7 @@ model TestChoices "..."
Real z;
end MyModel3;

replaceable MyModel m
replaceable MyModel c
annotation(
choices(
choice(redeclare MyModel1 m "MyModel1"),
Expand Down

0 comments on commit a499198

Please sign in to comment.