Name Resolver Specification
Introduction
The goal of the name resolver in the Clafer compiler is to determine
which clafer in the model is referred to by a given reference by name.
In a Clafer model, names can repeat as each clafer declaration includes
a new namespace. For example, there can be many clafers called
X
in various places in the model. The clafer X
can be referred to in these two ways:
- as a super clafer:
a : X
(done inResolveInheritance.hs
),a -> X
, anda ->> X
(ResolveName.hs
), and - inside expressions in constraints and goals:
[ some X ]
,X + 1
, and<< max sum X.ref >>
.
The name resolver decides which of the potentially multiple
X
s is being referred to. Clafer X
can be
resolved as
Special
–this
,parent
,children
,ref
TypeSpecial
– primitive type: integer, string, (need to add real, natural, etc.)Binding
– local variable (in constraints with quantifier)Subclafers
– in descendants (BFS)+ inheritanceReference
– same asSubclafers
+ reachable via referencesAncestor
– in ancestorsAbsClafer
– abstract , top-level claferTopClafer
– concrete, top-level clafer
Currently (Clafer 0.3.3), the name resolver applies the following
sequence of resolution strategies (in that exact order) given the
current environment env
and the clafer’s
id
:
resolve env id [resolveSpecial, resolveBind, resolveDescendants, resolveAncestor pos, resolveTopLevel pos, resolveNone pos]
The strategy resolveNone
reports an error that the
clafer with the given id
was not found.
Test Cases
Resolving Special
this
refers toS1
parent
refers toS2
children
refers toa ++ b
S3
a
b
[ children ]
results in resolver: unknown uid 'children'
Resolving TypeSpecial
integer
,string
,real
resolve to primitive types
interestRate -> real
interestRate -> double
results in resolver: real not found within
and
resolver: double not found within
Resolving Binding
b
inb.c
resolves tob
inb : B1
.c
inb.c
resolves toB1.c
via inheritance.
Resolving Subclafers
b
insome b
resolves toa.b
and not toa.b.b
Resolving Reference
a
insome a
should resolve toA5.a
B
in-> A.B
should resolve toA.B
refAB -> A.B *
[ some B ]
results in an error B
not found
Resolving Ancestor
A1
insome A1
resolves to the top-levelA1
A2
insome A2
resolves toA2.A2
and not the top-levelA2
A2 ?
A2 ?
B
[ some A2 ]
results in an unexplained compilation error.
Resolving AbsClafer
Abs
in: Abs
,-> Abs
, and->> Abs
resolves toabstract Abs
- nested abstract
Resolving TopClafer
T
insome T
resolves toT ?
Resolving Redefinition
- (this affects name resolution for inheritance)
abstract A
d 0..1
/* redefines A.d, narrows cardinality */
abstract B : A
d 1..1
b ?
refA -> A
[ refA.ref.d.b ] this should produce error 'b' not found
refB -> B
[ refB.ref.d.b ] // this should work
Related BugBot Issues
- 231 name resolver should search through nested clafers
- 217 reference to nested clafers
- 216 inheritance among concrete clafers
- 206 Parent Required when Defining Ad-Hoc Set
- 169 No match in record selector sident
- 145 Quantify over union
- 95 children clafers not visible via reference to a reference
- 65 summary working with local clafers and global
- 60 add support for hierarchy specification and instantiation
- 48 add the lookup navigation operator to clafer
Issues 48 and 65 are just proposals, we have not decided yet.