Difference between revisions of "Program Defined Attributes"
(initial version) |
(release) |
||
Line 1: | Line 1: | ||
This section describes how to define attributes that can be written on entities in a program. Currently, the attributes will not have any semantics influence nor can they be accessed through reflection, so they will only be accessible to tools that parse the code itself. | This section describes how to define attributes that can be written on entities in a program. Currently, the attributes will not have any semantics influence nor can they be accessed through reflection, so they will only be accessible to tools that parse the code itself. | ||
Latest revision as of 17:13, 12 March 2019
This section describes how to define attributes that can be written on entities in a program. Currently, the attributes will not have any semantics influence nor can they be accessed through reflection, so they will only be accessible to tools that parse the code itself.
interface person supports personGenerated [meta] properties name : string [meta]. address : string [metaDisplayAs("address")]. end interface person
Without any further action the compiler will generate warnings for the attributes above. To avoid this the attributes can be defined in a functor domain which is given the attribute attribute:
namespace ns interface meta domains meta = meta; metaDisplayAs(string DisplayAs) [attribute]. end interface meta
Notice that the attributes are both in a namespace and a scope.
Using normal rules that will handle name conflicts. On the other hand the person interface will use to qualified attributes:
interface person supports personGenerated [ns\meta::meta] properties name : string [ns\meta::meta]. address : string [ns\meta::metaDisplayAs("address")]. end interface person
The qualification can be omitted by opening the scope
interface person supports personGenerated open ns\meta [meta] properties name : string [meta]. address : string [metaDisplayAs("address")]. end interface person
Given this the compiler will:
- suppress the w193 warning (for unknown attribute)
- resolve ambiguities (when everybody want to use meta and test as attribute names)
- type check the attributes
The attributes will have to follow the rules for (compile time computable) constants (i.e. cannot contain function and predicate calls).