Class ScopeFile

java.lang.Object
org.clafer.scope.ScopeFile

public final class ScopeFile extends Object
A .cfr-scope file: the scopes of a model, kept apart from the model. It is a JSON array of entries, each an object of one kind:
  • {"lpqName": name, "scope": n}: the scope of the clafers named name, a UID (c0_Cfeatures) or a (partially) qualified name (Cfeatures, Component::Cfeatures, ::Component::Cfeatures) that names all the clafers whose containment paths end with it. The empty name is the root, whose scope is always 1. This is the entry clafer --meta-data, claferIG and the REPL write.
  • {"defaultScope": n}: the scope of the clafers without their own. It also matters when every clafer has its own: the scope analysis of a recursive structure uses it.
  • {"int": [low, high]}: the integers.
  • {"mul": [low, high]}: the products of multiplications.
  • {"stringLength": n}: the longest string.
  • {"chars": [low, high]}: the characters of strings, as code points.
  • {"decimalDigits": n}: the fractional digits of decimals.
  • {"decimal": [low, high]}: the decimals, e.g., [-21474.83648, 21474.83647].
Anything not in the file keeps the scope it had.
  • Method Details

    • print

      public static String print(AstModel model, Scope scope)
      Prints every scope of a model: the scope of every clafer by its UID, sorted, whether it was given or is the default, then the default scope and every range.
      Parameters:
      model - the model
      scope - its scope
      Returns:
      the contents of the model's .cfr-scope file
    • parse

      public static ScopeFile parse(String json, String fileName)
      Reads a scope file.
      Parameters:
      json - the contents
      fileName - the file's name, for errors
      Returns:
      the scope file
      Throws:
      IllegalArgumentException - if the file is malformed
    • hasIntRange

      public boolean hasIntRange()
      Returns:
      whether the file gives the integers
    • applyTo

      public Scope applyTo(Scope scope, AstModel model)
      Applies the file to a scope.
      Parameters:
      scope - the scope
      model - the model, whose clafers the file names
      Returns:
      the scope with the file's scopes and ranges
      Throws:
      IllegalArgumentException - if a name is not of a clafer in the model
    • claferNamed

      public static List<AstClafer> claferNamed(List<AstClafer> clafers, String qName)
      The clafer with the given UID, otherwise the clafers with the given (partially) qualified name. A UID is the clafer's least-partially-qualified name, with __ between the names, e.g., size, x__size or root__size (a top-level size when another one exists). A qualified name names the clafers whose paths of names end with it: size names every clafer named size, x__size every size in an x, and root__x__size only the one in a top-level x. The older form with :: is read too: x::size is x__size, and ::x::size is root__x__size. An apostrophe is _prime, as in the UIDs.

      The names are matched from the end, a UID at a time: the clafer's UID ends with the names, e.g., x__size with size, or is the last names, e.g., size of x__size, and the names before them are its parent's, and so on.

      Parameters:
      clafers - the clafers to look in
      qName - a UID or a (partially) qualified name
      Returns:
      the clafers it names