Opened 10 years ago

Last modified 8 years ago

#3020 assigned defect

Custom annotation cannot be read and proposed code changes to interactive.mo

Reported by: anonymous Owned by: Adrian Pop
Priority: normal Milestone: Future
Component: Interactive Environment Version: 1.8.0
Keywords: component annotation Cc:

Description

The functions to read the component annotations try to parse the content of said annotation and fail if the format is different than the one expected.

Example OMShell commands demonstrating the problem follows. The first commands creates the problematic annotation. The second tries to read it.

loadString("model Test parameter Real v = 0 annotation(__MyTag(name = \"<String>\")); end Test;");
getComponentAnnotations(Test);
-> {{__MyTag(error)}}

The proposed modifications to “interactive.mo” allow to get the raw (unparsed) annotation circumventing the current annotation interpretation code.

Note: the modifications to interactive.mo were made to version 10683 of OpenModelica but the added code could probably be used almost unmodified in the current versions. The reference interactive.mo version 10683 and the modified version are both provided to enable a diff between the two.

Here’s a resume of the changes to interactive.mo version 10683

1) The following functions were added to interactive.mo:


getComponentAnnotationsAsStr
getComponentAnnotationsFromEltsAsStr
getComponentitemsAnnotationsAsStr
getComponentitemsAnnotationsFromItemsAsStr
getNthComponentAnnotationAsStr
getComponentAnnotationAsStr

2) New case items to handle calls to getComponentAnnotationsAsStr and getNthComponentAnnotationAsStr were added to function
evaluateGraphicalApi_dispatch():

    // CSA Addons: Dec 14, 2011. C.Adourian        
    case (istmts, st as SYMBOLTABLE(ast = p))
      equation
        matchApiFunction(istmts, "getComponentAnnotationsAsStr");
        {Absyn.CREF(componentRef = cr)} = getApiFunctionArgs(istmts);
        ErrorExt.setCheckpoint("getComponentAnnotationsAsStr");
        Config.setEvaluateParametersInAnnotations(true);
        resstr = getComponentAnnotationsAsStr(cr, p);
        Config.setEvaluateParametersInAnnotations(false);
        ErrorExt.rollBack("getComponentAnnotationsAsStr");
      then
        (resstr,st);

    // CSA Addons: Dec 14, 2011. C.Adourian
    case (istmts, st as SYMBOLTABLE(ast = p))
      equation
       matchApiFunction(istmts, "getNthComponentAnnotationAsStr");
        {Absyn.CREF(componentRef = cr),Absyn.INTEGER(value = n)} = getApiFunctionArgs(istmts);
        ErrorExt.setCheckpoint("getNthComponentAnnotationAsStr");
        Config.setEvaluateParametersInAnnotations(true);
        resstr = getNthComponentAnnotationAsStr(cr, p, n);
        Config.setEvaluateParametersInAnnotations(false);
        ErrorExt.rollBack("getNthComponentAnnotationAsStr");
      then
        (resstr,st);

Attachments (1)

Code.zip (208.0 KB ) - added by anonymous 10 years ago.
Original and modified "interactive.mo" file

Download all attachments as: .zip

Change History (4)

by anonymous, 10 years ago

Attachment: Code.zip added

Original and modified "interactive.mo" file

comment:1 by Martin Sjölund, 10 years ago

We should not have even more functions added to Interactive.mo. Any new functionality should be implemented in CevalScript.mo.

comment:2 by chahe.adourian@…, 10 years ago

Hi,

any plans to add these suggested modifications to OpenModelica main branch. We've been adding those changes manually, compiling and using the OMC. It would be nice if this ends up in the default maintained OpenModelica code.

Chahé / CSA

comment:3 by Adeel Asghar, 8 years ago

Component: *unknown*Interactive Environment
Owner: changed from somebody to Adrian Pop
Status: newassigned
Note: See TracTickets for help on using tickets.