All files

src/compiler/expression_contracts.panack

Green: covered; red: known zero; amber: unavailable. Blank lines are outside the executable-start-line denominator.

    1 import "parser.panack"
    2 
    3 // Shared literal decoding and scalar rules; no nominal identity is encoded here.
    4 record InterpolatedString {
    5   parts: [Str],
    6   variables: [Str]
    7 }
    8 
    9 pure decode_string_literal(text: Str): Str {
   10   mut output: Str = ""
   11   mut cursor: Nat = 1
   12   while cursor + 1 < len(text) {
   13     character: Str = text[cursor]
   14     if character == "\\" && cursor + 2 < len(text) {
   15       escape: Str = text[cursor + 1]
   16       if escape == "n" { output = output + "\n"; }
   17       else { if escape == "r" { output = output + "\r"; }
   18       else { if escape == "t" { output = output + "\t"; }
   19       else { if escape == "b" { output = output + "\b"; }
   20       else { if escape == "f" { output = output + "\f"; }
   21       else { output = output + escape; } } } } }
   22       cursor = cursor + 2
   23     } else {
   24       output = output + character
   25       cursor = cursor + 1
   26     }
   27   }
   28   output
   29 }
   30 
   31 pure interpolation_name_start(character: Str): Bool {
   32   is_letter(character) || character == "_"
   33 }
   34 
   35 pure interpolation_name_part(character: Str): Bool {
   36   interpolation_name_start(character) || is_digit(character)
   37 }
   38 
   39 pure split_interpolated_string(text: Str): InterpolatedString {
   40   mut parts: [Str] = []
   41   mut variables: [Str] = []
   42   mut part_start: Nat = 0
   43   mut cursor: Nat = 0
   44   while cursor + 3 < len(text) {
   45     if text[cursor] == "$" && text[cursor + 1] == "{" &&
   46        interpolation_name_start(text[cursor + 2]) {
   47       mut end: Nat = cursor + 3
   48       while end < len(text) && interpolation_name_part(text[end]) {
   49         end = end + 1
   50       }
   51       if end < len(text) && text[end] == "}" {
   52         parts = append(parts, slice(text, part_start, cursor))
   53         variables = append(variables, slice(text, cursor + 2, end))
   54         cursor = end + 1
   55         part_start = cursor
   56       } else {
   57         cursor = cursor + 1
   58       }
   59     } else {
   60       cursor = cursor + 1
   61     }
   62   }
   63   if len(variables) == 0 {
   64     InterpolatedString([], [])
   65   } else {
   66     parts = append(parts, slice(text, part_start, len(text)))
   67     InterpolatedString(parts, variables)
   68   }
   69 }
   70 
   71 pure scalar_numeric(name: Str): Bool {
   72   name == "Nat" || name == "Int" || name == "Dec" || name == "Rat"
   73 }
   74 
   75 pure scalar_compatible_numeric(left: Str, right: Str): Bool {
   76   scalar_numeric(left) && scalar_numeric(right) && !((left == "Dec" || right == "Dec") && left != right)
   77 }
   78 
   79 pure scalar_arithmetic_result(operator: Str, left: Str, right: Str): Str {
   80   if left == "Dec" { "Dec" }
   81   else { if operator == "/" || left == "Rat" || right == "Rat" { "Rat" }
   82   else { if left == "Int" || right == "Int" { "Int" } else { "Nat" } } }
   83 }
   84 

Functions

[
  {
    "id": "declaration/2",
    "name": "decode_string_literal",
    "line": 9,
    "state": "covered",
    "entries": "2541"
  },
  {
    "id": "declaration/3",
    "name": "interpolation_name_start",
    "line": 31,
    "state": "covered",
    "entries": "3181"
  },
  {
    "id": "declaration/4",
    "name": "interpolation_name_part",
    "line": 35,
    "state": "covered",
    "entries": "2834"
  },
  {
    "id": "declaration/5",
    "name": "split_interpolated_string",
    "line": 39,
    "state": "covered",
    "entries": "2541"
  },
  {
    "id": "declaration/6",
    "name": "scalar_numeric",
    "line": 71,
    "state": "covered",
    "entries": "2127"
  },
  {
    "id": "declaration/7",
    "name": "scalar_compatible_numeric",
    "line": 75,
    "state": "covered",
    "entries": "1063"
  },
  {
    "id": "declaration/8",
    "name": "scalar_arithmetic_result",
    "line": 79,
    "state": "covered",
    "entries": "1057"
  }
]

Source branch outcomes

[
  {
    "id": "declaration/2/statement/2/decision/body",
    "outcome": "body",
    "line": 12,
    "state": "covered",
    "hits": "31596"
  },
  {
    "id": "declaration/2/statement/2/decision/exit",
    "outcome": "exit",
    "line": 12,
    "state": "covered",
    "hits": "2541"
  },
  {
    "id": "declaration/2/statement/2/body/tail/decision/true",
    "outcome": "true",
    "line": 14,
    "state": "covered",
    "hits": "138"
  },
  {
    "id": "declaration/2/statement/2/body/tail/decision/false",
    "outcome": "false",
    "line": 14,
    "state": "covered",
    "hits": "31458"
  },
  {
    "id": "declaration/2/statement/2/body/tail/condition/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 14,
    "state": "covered",
    "hits": "138"
  },
  {
    "id": "declaration/2/statement/2/body/tail/condition/decision/skip-right",
    "outcome": "skip-right",
    "line": 14,
    "state": "covered",
    "hits": "31458"
  },
  {
    "id": "declaration/2/statement/2/body/tail/true/statement/1/value/decision/true",
    "outcome": "true",
    "line": 16,
    "state": "covered",
    "hits": "106"
  },
  {
    "id": "declaration/2/statement/2/body/tail/true/statement/1/value/decision/false",
    "outcome": "false",
    "line": 16,
    "state": "covered",
    "hits": "32"
  },
  {
    "id": "declaration/2/statement/2/body/tail/true/statement/1/value/false/tail/decision/true",
    "outcome": "true",
    "line": 17,
    "state": "covered",
    "hits": "2"
  },
  {
    "id": "declaration/2/statement/2/body/tail/true/statement/1/value/false/tail/decision/false",
    "outcome": "false",
    "line": 17,
    "state": "covered",
    "hits": "30"
  },
  {
    "id": "declaration/2/statement/2/body/tail/true/statement/1/value/false/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 18,
    "state": "covered",
    "hits": "16"
  },
  {
    "id": "declaration/2/statement/2/body/tail/true/statement/1/value/false/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 18,
    "state": "covered",
    "hits": "14"
  },
  {
    "id": "declaration/2/statement/2/body/tail/true/statement/1/value/false/tail/false/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 19,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/2/statement/2/body/tail/true/statement/1/value/false/tail/false/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 19,
    "state": "covered",
    "hits": "13"
  },
  {
    "id": "declaration/2/statement/2/body/tail/true/statement/1/value/false/tail/false/tail/false/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 20,
    "state": "covered",
    "hits": "1"
  },
  {
    "id": "declaration/2/statement/2/body/tail/true/statement/1/value/false/tail/false/tail/false/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 20,
    "state": "covered",
    "hits": "12"
  },
  {
    "id": "declaration/3/tail/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 32,
    "state": "covered",
    "hits": "496"
  },
  {
    "id": "declaration/3/tail/decision/skip-right",
    "outcome": "skip-right",
    "line": 32,
    "state": "covered",
    "hits": "2685"
  },
  {
    "id": "declaration/4/tail/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 36,
    "state": "covered",
    "hits": "347"
  },
  {
    "id": "declaration/4/tail/decision/skip-right",
    "outcome": "skip-right",
    "line": 36,
    "state": "covered",
    "hits": "2487"
  },
  {
    "id": "declaration/5/statement/4/decision/body",
    "outcome": "body",
    "line": 44,
    "state": "covered",
    "hits": "22287"
  },
  {
    "id": "declaration/5/statement/4/decision/exit",
    "outcome": "exit",
    "line": 44,
    "state": "covered",
    "hits": "2541"
  },
  {
    "id": "declaration/5/statement/4/body/tail/decision/true",
    "outcome": "true",
    "line": 45,
    "state": "covered",
    "hits": "347"
  },
  {
    "id": "declaration/5/statement/4/body/tail/decision/false",
    "outcome": "false",
    "line": 45,
    "state": "covered",
    "hits": "21940"
  },
  {
    "id": "declaration/5/statement/4/body/tail/condition/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 45,
    "state": "covered",
    "hits": "347"
  },
  {
    "id": "declaration/5/statement/4/body/tail/condition/decision/skip-right",
    "outcome": "skip-right",
    "line": 45,
    "state": "covered",
    "hits": "21940"
  },
  {
    "id": "declaration/5/statement/4/body/tail/condition/left/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 45,
    "state": "covered",
    "hits": "437"
  },
  {
    "id": "declaration/5/statement/4/body/tail/condition/left/decision/skip-right",
    "outcome": "skip-right",
    "line": 45,
    "state": "covered",
    "hits": "21850"
  },
  {
    "id": "declaration/5/statement/4/body/tail/true/statement/1/decision/body",
    "outcome": "body",
    "line": 48,
    "state": "covered",
    "hits": "2487"
  },
  {
    "id": "declaration/5/statement/4/body/tail/true/statement/1/decision/exit",
    "outcome": "exit",
    "line": 48,
    "state": "covered",
    "hits": "347"
  },
  {
    "id": "declaration/5/statement/4/body/tail/true/statement/1/condition/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 48,
    "state": "covered",
    "hits": "2834"
  },
  {
    "id": "declaration/5/statement/4/body/tail/true/statement/1/condition/decision/skip-right",
    "outcome": "skip-right",
    "line": 48,
    "state": "zero",
    "hits": "0"
  },
  {
    "id": "declaration/5/statement/4/body/tail/true/tail/decision/true",
    "outcome": "true",
    "line": 51,
    "state": "covered",
    "hits": "347"
  },
  {
    "id": "declaration/5/statement/4/body/tail/true/tail/decision/false",
    "outcome": "false",
    "line": 51,
    "state": "zero",
    "hits": "0"
  },
  {
    "id": "declaration/5/statement/4/body/tail/true/tail/condition/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 51,
    "state": "covered",
    "hits": "347"
  },
  {
    "id": "declaration/5/statement/4/body/tail/true/tail/condition/decision/skip-right",
    "outcome": "skip-right",
    "line": 51,
    "state": "zero",
    "hits": "0"
  },
  {
    "id": "declaration/5/tail/decision/true",
    "outcome": "true",
    "line": 63,
    "state": "covered",
    "hits": "2316"
  },
  {
    "id": "declaration/5/tail/decision/false",
    "outcome": "false",
    "line": 63,
    "state": "covered",
    "hits": "225"
  },
  {
    "id": "declaration/6/tail/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 72,
    "state": "covered",
    "hits": "31"
  },
  {
    "id": "declaration/6/tail/decision/skip-right",
    "outcome": "skip-right",
    "line": 72,
    "state": "covered",
    "hits": "2096"
  },
  {
    "id": "declaration/6/tail/left/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 72,
    "state": "covered",
    "hits": "44"
  },
  {
    "id": "declaration/6/tail/left/decision/skip-right",
    "outcome": "skip-right",
    "line": 72,
    "state": "covered",
    "hits": "2083"
  },
  {
    "id": "declaration/6/tail/left/left/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 72,
    "state": "covered",
    "hits": "157"
  },
  {
    "id": "declaration/6/tail/left/left/decision/skip-right",
    "outcome": "skip-right",
    "line": 72,
    "state": "covered",
    "hits": "1970"
  },
  {
    "id": "declaration/7/tail/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 76,
    "state": "covered",
    "hits": "1046"
  },
  {
    "id": "declaration/7/tail/decision/skip-right",
    "outcome": "skip-right",
    "line": 76,
    "state": "covered",
    "hits": "17"
  },
  {
    "id": "declaration/7/tail/left/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 76,
    "state": "covered",
    "hits": "1047"
  },
  {
    "id": "declaration/7/tail/left/decision/skip-right",
    "outcome": "skip-right",
    "line": 76,
    "state": "covered",
    "hits": "16"
  },
  {
    "id": "declaration/7/tail/right/operand/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 76,
    "state": "covered",
    "hits": "12"
  },
  {
    "id": "declaration/7/tail/right/operand/decision/skip-right",
    "outcome": "skip-right",
    "line": 76,
    "state": "covered",
    "hits": "1034"
  },
  {
    "id": "declaration/7/tail/right/operand/left/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 76,
    "state": "covered",
    "hits": "1040"
  },
  {
    "id": "declaration/7/tail/right/operand/left/decision/skip-right",
    "outcome": "skip-right",
    "line": 76,
    "state": "covered",
    "hits": "6"
  },
  {
    "id": "declaration/8/tail/decision/true",
    "outcome": "true",
    "line": 80,
    "state": "covered",
    "hits": "5"
  },
  {
    "id": "declaration/8/tail/decision/false",
    "outcome": "false",
    "line": 80,
    "state": "covered",
    "hits": "1052"
  },
  {
    "id": "declaration/8/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 81,
    "state": "covered",
    "hits": "63"
  },
  {
    "id": "declaration/8/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 81,
    "state": "covered",
    "hits": "989"
  },
  {
    "id": "declaration/8/tail/false/tail/condition/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 81,
    "state": "covered",
    "hits": "990"
  },
  {
    "id": "declaration/8/tail/false/tail/condition/decision/skip-right",
    "outcome": "skip-right",
    "line": 81,
    "state": "covered",
    "hits": "62"
  },
  {
    "id": "declaration/8/tail/false/tail/condition/left/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 81,
    "state": "covered",
    "hits": "995"
  },
  {
    "id": "declaration/8/tail/false/tail/condition/left/decision/skip-right",
    "outcome": "skip-right",
    "line": 81,
    "state": "covered",
    "hits": "57"
  },
  {
    "id": "declaration/8/tail/false/tail/false/tail/decision/true",
    "outcome": "true",
    "line": 82,
    "state": "covered",
    "hits": "62"
  },
  {
    "id": "declaration/8/tail/false/tail/false/tail/decision/false",
    "outcome": "false",
    "line": 82,
    "state": "covered",
    "hits": "927"
  },
  {
    "id": "declaration/8/tail/false/tail/false/tail/condition/decision/evaluate-right",
    "outcome": "evaluate-right",
    "line": 82,
    "state": "covered",
    "hits": "931"
  },
  {
    "id": "declaration/8/tail/false/tail/false/tail/condition/decision/skip-right",
    "outcome": "skip-right",
    "line": 82,
    "state": "covered",
    "hits": "58"
  }
]

Reviewed declaration exclusions

[
  {
    "id": "declaration/0",
    "reason": "import",
    "line": 1
  },
  {
    "id": "declaration/1",
    "reason": "record-declaration",
    "line": 4
  }
]