nasa / fpp

F Prime Prime: A modeling language for F Prime
https://fprime.jpl.nasa.gov
Apache License 2.0
49 stars 31 forks source link

Add command argument range checking #127

Open timcanham opened 2 years ago

timcanham commented 2 years ago

Add range a range check field to help the sequence tool and code generator check argument ranges. Something like:

    @ Generate a FATAL EVR
    async command SB_GEN_FATAL(
                                arg1: U32 4-6 @< First FATAL Argument
                                arg2: F32 1.1-10.5 @< Second FATAL Argument
                                arg3: U32 @< Third FATAL Argument
                              ) \
      opcode 2

where the notation is <min>-<max>

if <min> or <max> are not specified, then that end of the range is not checked.

bocchino commented 2 years ago

Looks good. I was thinking of [ <min> , <max> ] as the notation, similar to the notation for a closed interval <min> <= x <= <max> in math. One could also use ( <min> , <max> ) for an open interval <min> < x < <max>, or mix closed and open bounds.

timcanham commented 2 years ago

Sure - how would you represent one end being open, i.e. x < 10, x > 2.9?

bocchino commented 2 years ago

x < 10 could be ( , 10 ) as you said. Or maybe ( _, 10 ).

bocchino commented 2 years ago

We are working on a prototype of this that uses FPP annotations to express the constraints. The current thinking is

command C(
  a: U32 in [0,10] # >= 0 and <= 10
  b: I32 in (-10,10) # > -10 and < 10
  c: F32 in (--, 42) # No lower bound; must be < 42
)
ThibFrgsGmz commented 2 years ago

Are there any plans to add message validator generation? Would it be in the autogenerated code or in the implmentation boilerplate?

From what I understand, F´´ currently guarantees structured data types but cannot apply semantic rules for values.

The generated code should also support validation of these constraints.

I expect to have something like the protoc-gen-validate plugin made by EnvoyProxy for adding these message validators to the Google's protobuf.