Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 907: Case expressions #1097

Merged
merged 13 commits into from
Jul 12, 2022
Merged

Issue 907: Case expressions #1097

merged 13 commits into from
Jul 12, 2022

Conversation

senier
Copy link
Member

@senier senier commented Jul 5, 2022

Part of #907

@senier senier requested review from treiher and jklmnn July 5, 2022 15:29
@senier senier changed the title Issue 907 Issue 907: Case expressions Jul 5, 2022
doc/Language-Reference.adoc Outdated Show resolved Hide resolved
doc/Language-Reference.adoc Outdated Show resolved Hide resolved
doc/Language-Reference.adoc Outdated Show resolved Hide resolved
doc/Language-Reference.adoc Outdated Show resolved Hide resolved
doc/Language-Reference.adoc Outdated Show resolved Hide resolved
tests/unit/expression_test.py Outdated Show resolved Hide resolved
tests/unit/expression_test.py Outdated Show resolved Hide resolved
tests/integration/specification_model_test.py Outdated Show resolved Hide resolved
rflx/expression.py Outdated Show resolved Hide resolved
rflx/expression.py Outdated Show resolved Hide resolved
Copy link
Member

@jklmnn jklmnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot assign values to a variable with a case expression, as in this example:

with Universal;

package Test is

   type T is range 0 .. 256 with Size => 16;

   generic
      Channel : Channel with Readable, Writable; -- §S-P-C-RW
   session Session with
      Initial => Start,
      Final => Terminated
   is
      Message : Universal::Message; -- §S-D-V-T-M, §S-D-V-E-N
      Test_Var : T;
   begin
      state Start is
      begin
         Channel'Read (Message); -- §S-S-A-RD-V
      transition
         goto Prepare
            if Message'Valid -- §S-S-T-VAT, §S-E-AT-V-V
         goto Terminated -- §S-S-T-N
      end Start;

      state Prepare is
         Recv_Type : Universal::Message_Type; -- §S-D-V-T-SC
      begin
         Recv_Type := Message.Message_Type; -- §S-S-A-A-V
         -- §S-S-A-A-MA
         Message := Universal::Message'(Message_Type => Universal::MT_Value,
                                        Length       => 1,
                                        Value        => -- §S-E-CE
                                                        (case Recv_Type is
                                                         when Universal::MT_Null | Universal::MT_Data =>   2,
                                                         when Universal::MT_Value                     =>   8,
                                                         when Universal::MT_Values                    =>  16,
                                                         when Universal::MT_Option_Types              =>  32,
                                                         when Universal::MT_Options                   =>  64,
                                                         when Universal::MT_Unconstrained_Data        => 128,
                                                         when Universal::MT_Unconstrained_Options     => 256));
         Test_Var := (case Recv_Type is
                      when Universal::MT_Null | Universal::MT_Data =>   2,
                      when Universal::MT_Value                     =>   8,
                      when Universal::MT_Values                    =>  16,
                      when Universal::MT_Option_Types              =>  32,
                      when Universal::MT_Options                   =>  64,
                      when Universal::MT_Unconstrained_Data        => 128,
                      when Universal::MT_Unconstrained_Options     => 256);
      transition
         goto Reply -- §S-S-T-N
      exception
         goto Terminated -- §S-S-E
      end Prepare;

      state Reply is
      begin
         Channel'Write (Message); -- §S-S-A-WR-V
      transition
         goto Terminated -- §S-S-T-N
      end Reply;

      state Terminated is null state; -- §S-S-N
   end Session;

end Test;

I get the following error:

------------------------------ RecordFlux Bug ------------------------------
RecordFlux 0.6.0-pre   
RecordFlux-parser 0.11.0
attrs 21.2.0             
icontract 2.6.0
pydantic 1.9.0                                               
pydotplus 2.0.2    
ruamel.yaml 0.17.20
z3-solver 4.8.14.0  
                                                                      
Optimized: True                                
                                                                      
Command: /.../rflx generate test.rflx -d out
                                                                      
Traceback (most recent call last):  
  File "/.../RecordFlux/rflx/cli.py", line 202, in main
    args.func(args)
  File "/.../RecordFlux/rflx/cli.py", line 260, in generate
    Generator(                                              
  File "/.../RecordFlux/rflx/generator/generator.py", line 143, in generate
    units = self._generate(model, integration)           
  File "/.../RecordFlux/rflx/generator/generator.py", line 266, in _generate
    units.update(self._create_session(s, integration))                                                                                      
  File "/.../RecordFlux/rflx/generator/generator.py", line 283, in _create_session
    session_generator = SessionGenerator(                         
  File "/.../RecordFlux/rflx/generator/session.py", line 221, in __init__
    self._create()                                                                                                                          
  File "/.../RecordFlux/rflx/generator/session.py", line 251, in _create    
    state_machine = self._create_state_machine()                                                                                            
  File "/.../RecordFlux/rflx/generator/session.py", line 370, in _create_state_machine
    unit += self._create_states(self._session, composite_globals, is_global)                                 
  File "/.../RecordFlux/rflx/generator/session.py", line 861, in _create_states
    *[                                                                                                                                      
  File "/.../RecordFlux/rflx/generator/session.py", line 864, in <listcomp>
    for s in self._state_action(                                                                                                            
  File "/.../RecordFlux/rflx/generator/session.py", line 1950, in _state_action
    result = self._assign(                                                                                                                  
  File "/.../RecordFlux/rflx/generator/session.py", line 2270, in _assign
    _unexpected_expression(expression, "in assignment")                                                                                     
  File "/.../RecordFlux/rflx/generator/session.py", line 4757, in _unexpected_expression
    fatal_fail(                                                                                                                             
  File "/.../RecordFlux/rflx/error.py", line 198, in fatal_fail
    _fail(FatalError(), message, subsystem, severity, location)
  File "/.../RecordFlux/rflx/error.py", line 209, in _fail
    error.propagate()             
  File "/.../RecordFlux/rflx/error.py", line 162, in propagate
    raise self
rflx.error.FatalError: test.rflx:41:22: generator: error: unexpected Case with type universal integer (2 .. 256) in assignment
                                                                      
----------------------------------------------------------------------------

@senier senier force-pushed the issue_907 branch 3 times, most recently from 4b415d2 to 22ff72d Compare July 8, 2022 11:14
@senier senier requested review from treiher and jklmnn July 8, 2022 11:46
jklmnn
jklmnn previously approved these changes Jul 8, 2022
tests/unit/expression_test.py Outdated Show resolved Hide resolved
jklmnn
jklmnn previously approved these changes Jul 11, 2022
@senier senier merged commit 37f5bff into main Jul 12, 2022
@senier senier deleted the issue_907 branch July 12, 2022 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants