Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Abstract Syntax Tree; accessing correct datastructure

Abstract Syntax Tree; accessing correct datastructure

Hello everyone,

100th thread current/smile

I am writing a new Template for Codegeneration and i have a Question about the omc datastructure.
I am able to abstract the name of vars, functions , etc and annotations from a single model in a single file like:

model test1
Real x(start=1);
equation
der(x)= -x;
end test1;



I would like to be able to access more models which resists one file like the model below and to be able to get
,for example, for  each submodel the name and annotation info.



model test2

model test21 "test 22" annotation(/.../);   
    Real y(start = 1);
    equation
    der( y)=y *34;
end test21;

model test22 "test 22 "annotation(/.../);
    Real z(start=5.0);
    equation
    der(z) = - z
end test22;


end test2;


I thought the PARTS record within the ClassDef uniontype holds all the information i need. But all the lists of parts are not accessable, or rather  get a segmentation dump.
Does anyone know which datastructure in  i have to acess?

Kind regarts,
TIm

Re: Abstract Syntax Tree; accessing correct datastructure

Hi,

I assume you're talking about Absyn.mo.
I suggest you look at Dump.dump or Dump.unparseStr on how to walk the Absyn data structure starting from Absyn.Program.

How do you get segmentation dumps? That should not happen if you use MetaModelica (in general only if
you do something fishy in external functions) or you try to append strings more than 16MB on 32 bit.

Cheers,
Adrian Pop/

Re: Abstract Syntax Tree; accessing correct datastructure

Hi,
thanks for your fast reply.
I get the seg dump in this template function getAnnotations. Without the listLength functioncall the model compiles just fine.
The idea was to get  the number of submodels.

template getAnnotations(SCode.ClassDef  cd)::=
match cd
case PARTS(__) then <<    <%listLength(elementLst)%> >>
...
end getAnnotations;


I will have a closer look at the Dump class but i still have problems understanding the relation between the modules.
Absyn contains all the data structure of a translated modelica model and SCode includes a more readable version. And SimCode just contains snippets sorted by their membership( e.g. all linear equation in one list)?
Can i use the dumpProgram function in the SCode structure as well for printing the AST?
And how can in import the Dump.mo in my Template? Is this possible at all ?

Greeting
Tim

Re: Abstract Syntax Tree; accessing correct datastructure

Hi,

Ok, now I get it. You use Susan templates to walk the SCode structure as far as I can see. Then you shouldn't mix it with the Dump package.
We do have a dumper for SCode, see Templates/SCodeDumpTpl.tpl so have a look how we walk the structure there.

In general if you get crashes I suggest to try make clean and make omc again. Also, do make omc twice so the new templates are used.
So, as a rule if you change templates:
> make clean
> make omc
> make omc

Cheers,
Adrian Pop/

There are 0 guests and 0 other users also viewing this topic
You are here: