Class ScopeFile
java.lang.Object
org.clafer.scope.ScopeFile
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 namedname, 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 entryclafer --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].
-
Method Summary
Modifier and TypeMethodDescriptionApplies the file to a scope.claferNamed(List<AstClafer> clafers, String qName) The clafer with the given UID, otherwise the clafers with the given (partially) qualified name.booleanstatic ScopeFileReads a scope file.static StringPrints 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.
-
Method Details
-
print
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 modelscope- its scope- Returns:
- the contents of the model's
.cfr-scopefile
-
parse
Reads a scope file.- Parameters:
json- the contentsfileName- the file's name, for errors- Returns:
- the scope file
- Throws:
IllegalArgumentException- if the file is malformed
-
hasIntRange
- Returns:
- whether the file gives the integers
-
applyTo
Applies the file to a scope.- Parameters:
scope- the scopemodel- 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
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__sizeorroot__size(a top-levelsizewhen another one exists). A qualified name names the clafers whose paths of names end with it:sizenames every clafer namedsize,x__sizeeverysizein anx, androot__x__sizeonly the one in a top-levelx. The older form with::is read too:x::sizeisx__size, and::x::sizeisroot__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__sizewithsize, or is the last names, e.g.,sizeofx__size, and the names before them are its parent's, and so on.- Parameters:
clafers- the clafers to look inqName- a UID or a (partially) qualified name- Returns:
- the clafers it names
-