Class IfBlockSafeGenericAccessMarker

java.lang.Object
org.ek9lang.compiler.phase5.IfBlockSafeGenericAccessMarker
All Implemented Interfaces:
Consumer<EK9Parser.IfControlBlockContext>

final class IfBlockSafeGenericAccessMarker extends Object implements Consumer<EK9Parser.IfControlBlockContext>
Does basic checks on the if condition to see if a Result/Optional access has been made safe. This is a bit basic at present and could be made more sophisticated - but let's get something working first. The idea is to mark the block safe for ok(), error() and get() calls if and only if the controlling logic in the if statement guarantees that access is safe now in that block. This code just uses the ANTLR AST and symbols that have been annotated. It maybe that his simple check is enough for now, but before building a whole 'IR' and then analysing that we should be able to 'fail early' before doing too much.
  • Constructor Details

    • IfBlockSafeGenericAccessMarker

      IfBlockSafeGenericAccessMarker(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener)
      Constructor to provided typed access.
  • Method Details

    • accept

      public void accept(EK9Parser.IfControlBlockContext ctx)
      This is the expression we have to assess. Now to keep this simple we only allow 'and' when working with Result/Optional and specific methods that way we can keep it both simple for the compiler and also the error messages for the EK9 developer So we want to support 'r1.isOk() and r2.isOK() and o1? and o2?' or more idiomatically 'r1? and r2? and o1? and o2?' For error conditions we also need to support 'r1.isError() and r2.isOk()' for example Then r1.error() can be called and r2.ok() can also be called.
      Specified by:
      accept in interface Consumer<EK9Parser.IfControlBlockContext>