Closed seidewitz closed 2 years ago
I'm confused that the explanation of as
operator. If we write vehicle as KerML::Feature
, I think it should be upcast to KerML::Feature
rather than SysML::PartUsage
. Or am I misunderstand it? In my understanding, as
operator is needed to resolve diamond problems in multiple inheritance. Is that right?
I'm confused that the explanation of as operator.
The static type of an expression like x
as
KerML::Feature
is KerML::Feature, and that is what is used for static type checking. However, dynamically the expression evaluates to the actual meta object for x
(as long as that is a subtype of KerML::Feature). Thus, if x
is a part usage, then the result will be an instance of SysML::PartUsage, which is an (indirect) subtype of KerML::Feature.
Other than the meta-shift, this is similar to normal up-casting, in which the dynamic runtime type of the result may be a subtype of the static type given in the cast. The important thing is that this is consistent with the static type checking.
Oh, I see. as
actually allows incompatible cast to pass static type checking. Thanks.
This pull request adds a mechanism that allows "semantic metadata" annotations to be used to specify implicit specialization of declared types. It also provides a new keyword notation for annotations in the SysML grammar.
Semantic metadata. The
SemanticMetadata
metaclass was included in the KernelMetaobjects
package added in PR #347. It is intended to be specialized with itsbaseType
feature bound to a specific reflectiveType
metaobject value. When a specialization ofSemanticMetadata
is used to annotate an appropriate type declaration, the specifiedbaseType
is used to implicitly specialize the annotated type.baseType
.baseType
is a Classifier, then annotated classifier implicitly subclassifies thebaseType
.baseType
is a Feature, then the annotated classifier implicitly subclassifies each type of thebaseType
.baseType
is a Feature, then the annotated feature implicitly subsets thebaseType
.Casting. The cast operator
as
has been added to the implemented operators for model-level evaluable expressions. In addition, if the target type of the case is a metaclass, and the argument expression evaluates to a feature whose abstract syntax metaclass conforms to the given metaclass, then the result is a "meta-upcast" to the metaobject representation of the feature. (E.g., ifvehicle
is a part usage, thenvehicle
as
KerML::Feature
evaluates, as a model-level evaluable expression, to a MetadataFeature forvehicle
with typeSysML::PartUsage
.)Note: The 2022-02 baseline did not add an expression for obtaining the metaclass of an element. Using the cast operator is a workaround at this time. It means that, currently, it is only possible to specify a feature as a
SemanticMetadata::baseType
. However, this is sufficient to also define implicit specializations for classifiers, as described above.Keywords. A user-defined keyword is a (possibly qualified) metaclass/metadata definition name or human ID preceded by the symbol
#
. Such a keyword can be used in the SysML textual notation in package, dependency, definition and usage declarations. The user-defined keyword is placed immediately before the language-defined (reserved) keyword for the declaration and specifies a metadata annotation of the declared element. For example, ifSafetyCritical
is a visible metadata definition, then#SafetyCritical
part
brakes;
is equivalent topart
brakes { @SafetyCritical; }
.Notes:
SemanticMetadata
, then the implicit specialization rules given above apply.Extended definitions and usages. The metaclasses Definition and Usage are no longer abstract in the 2022-03 baseline abstract syntax. This allows the possibility of declaring a definition or usage without a language keyword identifying a more specialized kind, as long as a user-defined keyword is given to specify
SemanticMetadata
to be used for implicit specialization. For example, ifprovider
is the human ID ofSemanticMetadata
whosebaseType
is the featureserviceProviders : ServiceProvider
, then#provider
def
BankingService;
parses to a Definition with an implicit subclassification ofServiceProvider
and#provider bankingService;
parses to a Usage with an implicit subsetting ofserviceProviders
.