Download Contract Wizard II - ETH E-Collection

Transcript
4.4.2 The feature cw_type
cw_type (a_type: TYPE): CW_TYPE is (1)
-- Contract Wizard type (AST node) created from .NET
-- type a_type
require
a_type_not_void: a_type /= Void
type_name_not_void: a_type.name /= Void
local
a_type_name: CW_NAME
…
do
...
a_type_name := cw_type_name (a_type.name.to_string)
create Result.make (a_type_name) (2)
Result.set_deferred (a_type.is_abstract or a_type.is_interface) (3)
Result.set_expanded (a_type.is_value_type)
Result.set_array (a_type.is_array)
Result.set_enum (a_type.is_enum)
Result.set_namespace (a_namespace) (4)
…
-- Add interfaces this type implements. (5)
…
ensure (6)
result_not_void: Result /= Void
deferred_set: Result.is_deferred = a_type.is_abstract or
a_type.is_interface
array_set: Result.is_array = a_type.is_array
enum_set: Result.is_enum = a_type.is_enum
expanded_set: Result.is_expanded = a_type.is_value_type
end
Table 12: Feature cw_type: Generating a Contract Wizard type
The feature cw_type creates a Contract Wizard type (CW_TYPE) from a .NET type (TYPE)
(1). The creation of a Contract Wizard type requires a Contract Wizard type name
(CW_NAME); therefore, it creates a Contract Wizard type name and generates a Contract
Wizard type with it (2).
To create proxy classes we have to distinguish between the following types: A type can be an
array, an enumeration type, an expanded type or a deferred type. The feature cw_type sets the
following features for the created Contract Wizard type depending on the parsed .NET type:
is_deferred, is_expanded, is_array and is_enum (3). The feature is_deferred is set to true if
the parsed type is abstract, is_expanded is set to true if the parsed type is a value type,
is_array is set to true if the parsed type is an array and is_enum is set to true if the parsed type
is an enumerated type. The namespace is set because it is required for the class description of
the proxy classes later (4). We also have to set all CLS compliant interfaces the type
implements. (5)
The postcondition of cw_type ensures that all Contract Wizard type features are set (6).
38