Datatype Editor/en

Aus expecco Wiki (Version 2.x)
(Weitergeleitet von Datatype Editor)
Wechseln zu: Navigation, Suche

Introduction

Datatypes are attached to pins and environment variables, and usually presented by name in a datatype definition pull-down menu. There are both builtin (hardwired) and user defined data types in expecco. User defined datatypes are shown in those pull-down lists at the bottom of the menu. This editor is used to define new datatypes. Builtin types cannot be modified.

There are multiple conceptional ways to define a new datatype:

  • as a subtype of an existing type (enum, range types)
  • by combining elements of existing types (tuple, array, structure or union types)
  • be explicit definition as a class or data structure (C-type, ST/X-class type)

Also, there are various syntactical representations, in which a type may be presented or imported:

  • Internal expecco Syntax
  • XML / XSD / DTD / IDL
  • C language struct syntax
  • Cobol Copybook, SUNRPC-IDL, COM-IDL, ASN1

The set of options available in the editor depends on the expecco version (basic, pro, enterprise) and the set of available plugins (SWIFT, ASN1, etc.), as some import formats are provided by additional plugins.

To define a type, first choose an appropriate representation in the "Type-Kind" list. A template showing the syntax of this type will be shown. Change the template and press "Accept" to install the type. The second tab in the editor labeled "Type Description" shows the type's definition in expecco's internal type description language, which is usually only of interest to validate a type's correctness if an alien format was used to import a type definition. This format is described below .


Datatype Editor

Type Kinds (Semantic)

Primary Types

These are builtin types (classes) of the underlying Smalltalk execution framework. For example, "String", "Array", "Set", "Btree", "Dictionary" or "Number" to name a few. There are thousands of classes available, but you will usually get along happily with only a few - if at all needed. Usually, you only need to know some of those when you want to refer to some framework inside Smalltalk. For example, there are packages and classes to support protocols such as FTP, HTTP, and others or data processing, parsing or cryptographic functionality. Also, some expecco plugins and extensions come bundled with additional useful classes.

The most common primary types are shortly listed in the "Datatype documentation" . For more details, please refer to the Smalltalk documentation, especially the "Basic Classes Introduction" and the "Online Class Documentation" (containing full lists and documentation of all classes).

A number of primary types is available directly via the datatype menus, and there is no need to define them as a user type. These predefined primary types include "Integer", "Number", "String", "Boolean" and a few other often used types. All other primary types can be defined as a user defined type in textual definition. In a textual definition, the underlying typeclass is placed in angle brackets, as in:

    <String>

or:

    <Socket>

Enumeration Types

A single symbolic value from a list of enumerated symbolic values. Unless quoted in single quotes, these names must consist of letters or digits or underline characters, and should start with a non-digit (to avoid confusion).

Typical examples are:

    enum( red | green | blue)

or:

    enum( male | female)

or:

    enum( 'foo-a' | 'foo-b' | 'foo-c' | 'bar-a' | 'bar-b' )

The last example uses quotes around the element names, as these contain a special (non-alphanumeric) character.

When used as a freeze value or environment variable value, a combo list showing only the valid enum elements is shown. By default, the values are sorted alphabetically in one single list. If your type consists of a large number of values, you may want to specify a grouping scheme. For example, the last of the above examples could be presented as either a single list with 5 items, or as a 2-item list ('foo' and 'bar') with submenus for each prefix.

The following section is only valid for expecco version starting with 2.8:

Enum values can have an associated integer value, which is useful, if the type is actually a mapping of a corresponding C or Java type.
For this, add an "= <integerValue>" after the element's name to the above definition. I.e.:

enum ( foo | bar = 20 | baz | bla = 30 )

Will assign integer values to the enum elements. If asked via "<type> integerValueOf: x", it will return the following integer values: 0 (for x = 'foo'), 20 (for x = 'bar'), 21 for (x = 'baz') and 30 (for x = 'bla')

Without explicit integer value, elements get auto-incremented values, starting with 0 (zero) or the next value from the previous enum element.

Be aware that the enum-values are always string-like objects (actually: instances of Smalltalk's Symbol class. Thus, although the elements look like integers in a definition like "(1 | 2 | 3)", they are actually string like. Consider using a subrange or subset type, as described below, if you need integer values.

Range Types

A subrange of Integer, Character or Enum values. Used to limit the set of valid elements, given a previously defined or buitin base type. For example, a byte could be defined as:

    range( <Integer> : 0 .. 255 )

and the set of lowercase letters can be defined as:

    range( <Character> : $a .. $z )

Subset Types

A subset of Integer, Character or Enum values. This is similar to a subrange, but allows for multiple ranges or individual elements to be listed.

For example, the set of alphanumeric characters plus underline could be defined as:

    subset( <Character> : $a .. %z , $A .. $Z , $_ , $0 .. $9 )

A type which can take character values limited to the set of English vowels could be defined as:

    subset( <Character> : $A , $E , $I , $O , $U , $a , $e , $i , $o , $u )

Notice the dollar prefix, which designates a character constant.

Array Types

Are defined as a homogeneous collection of a elements, which are all of the same baseType. The number of elements is variable among instances. The elements are accessible by a numeric index which is 1 based (both for Smalltalk and JavaScript elementary blocks). The standard library also provides 0-based indexing blocks, which is sometimes more convenient for C/Java programmers.
For compatibility to other JavaScript systems, a few builtin functions behave differently, depending on the language context inside an elementary block's code; most notably, these are the indexOf/lastIndexOf functions.

In a textual definition, array types consist of a basetype followed by "[]", as in:

    <String>[]    -- an array of Strings

or:

    <Number>[]    -- an array of Numbers

Tuple Types

Are defined as a non-homogeneous, fixed size vector of a elements. Each element has a predefined type. The types may be different among elements, but all instances of the tuple type have the same type of element at corresponding positions. The elements are accessible by index (1..). Tuples are similar to compound types as described below. The difference is that tuples address the elements by index, whereas compounds address them by name. Tuples are also similar to array types, however, the number of elements is fixed in a tuple, whereas arrays can have an arbitrary number of elements, and the element types may be different, whereas in an array, all elements are of the same type.

In a textual description, a tuple is defined by listing the individual element types in parenthesis. For example, a tuple which might represent a 3D coordinate, could be defined as:

    [ <Number> , <Number> , <Number> ]

or, a tuple which associates a name with an age and gender might be:

    [ <String> , <Integer> , enum(M | F) ]

For the last example, it would probably be better to use a compound, which names the slots.

Notice, in previous versions of expecco, tuple types could also be defined in parenthesis "(...)", as opposed to brackets "[...]". This is still supported in future versions, but not recommended for new type definitions (read the documentation on union types for an explanation).

Class Types

A user defined class. Includes the instance's private slots (also called "instance variables"), and a set of operations (usually called "methods" or "virtual functions"). All of this information is stored with the test suite. Instance slots are accessible by getter/setter method invocations. Class types are defined by entering the class definition in a programming language (either the JavaScript-like dialect or Smalltalk).

Private class definitions allow for almost any functionality to be defined, but require some programming skills. For an introduction to programming, please refer to the "Online Documentation", the "Beginners Introduction & Tutorial", and the "Smalltalk Tutorial",.

Compound Types

A collection of named slots. Is similar to a Class Type without operations (actually, that is how the system represents them internally). The elements are accessible by name or keyed access, using the name as key (i.e. like a dictionary/hashtable).

In a textual definition, list the names and types of the individual elements in braces; for example, a person record might be defined as:

    {
        firstame : String
        lastName : String
        age      : Integer
        gender   : enum(M | F)
    }

The fields of an instance named "c" can be accessed as "c lastName" (Smalltalk) or "c.lastName" (JavaScript). Alternatively, using the dictionary protocol as "c at:'lastName'" / "c[ 'lastName' ]". Compound object instances can be passed to input pins with Dictionary-type. Compound type definitions can also be imported from various other formats, such as DTD, XML, C-header files etc.


Field definitions may optionally be terminated by a ";" (semicolon) character to make the definition more readable. I.e. the following defines the same type as the above:

    {
        firstame : String;
        lastName : String;
        age      : Integer;
        gender   : enum(M | F);
    }

Also, for backward compatibility, a terminating "," (comma) character is allowed, but no longer recommended.

Union Types

The instance can be an instance from a number of other types. In a textual definition, list the possible element types, separated by a vetical bar, as in:

    ( <Filename> | <String> | <URL> )

there is no explicit discriminator stored with the value. However, due to the run-time type information, it is possible in an elementary block to determine the type of value passed in, via the class or isXXX or isKindOf: protocols.

Notice that for a single element union type (eg. "( String )") the interpretation was ambiguous in previous expecco versions, as it could also be interpreted as a tuple with a single String element. Therefore, the syntax for tuple types was changed to use square brackets, but still supporting the previous regular parentheses syntax. There is no ambiguity when more than one element is present; however, for single element types, the datatype parser will (currently) read this as a single-type union type.

To avoid this ambiguity, the old parenthesis-syntax should no longer be used for tuples.

Additional Special Types

Datatype Type

Instances are datatypes known to the project. Datatype-types are typically used as input pin type of collection-instantiation blocks. As a freeze value, the list of known types is presented in a combolist. In a textual definition, the keyword "datatype" is used:

datatype

Constraint Datatype Type

Starting with expecco 2.8, a datatype type can be constraint to a subset of types, by defining it as:

datatype ( <constraint> )

where constraint a selector from one of:

  • isArrayType - for types which have integer-indexable slots
  • isCTypeType - for C-defined types
  • isCEnumType - for C enum types (2.12)
  • isCStructType - for C-defined struct types (2.12)
  • isCUnionType - for C-defined union types (2.12)
  • isCollectionPrimaryType - for subtypes of Collection (i.e. Dictionary, Set, OrderedCollection etc.)
  • isCompoundType - for compound types
  • isEnumType - for enum types
  • isNumberPrimaryType - for subtypes of Number (i.e. Float, Integer, Fraction, FixedPoint)
  • isPrimaryType - for any primary type
  • isStreamPrimaryType - for subtypes of Stream
  • isTupleType - for any tuple type
  • isUnionType - for any union type
  • isUserDefinedDatatype - for all user defined types
  • isWellKnownDatatype - for all builtin (i.e. not user defined) type

or a selector plus string argument from one of (expecco vsn >= 2.12):

  • nameMatches: 'globPattern'
  • nameMatchesRegex: 'regexPattern'

Constrained datatypes should be used by the StandardLibraries only, and are used to limit the input values of some instance creation actions. For example, the "New Collection" action has an input pin, which defines the type of collection to be created. This pin has the type: "datatype( isCollectionPrimaryType )".

Examples:

datatype ( Integer ) -- a type whose instances are all datatypes which are compatible with the Integer class
datatype ( isCTypeType ) -- a type whose instances are all known C-types
datatype ( isCStructType ) -- a type representing all known C struct types
datatype ( nameMatches: 'DPU*' ) -- a type representing all types which match this name

Monitor Types

A monitor is a special builtin object which observes an object and sends out change notifications to interested stakeholders when it changes its contents. Monitors are used to allow external QA systems (such as expecco ALM) to monitor and display changing expecco variables in real time.

Port Types

These are not yet used but present for future TTCN3 support.

Type Representation (Syntax)

Various textual representations are possible; some are already built into the base expecco system, others are addons and present if certain plugins are installed.

Formal BNF Description of the Expecco Type Syntax

Expecco provides its own native type-description language, with an easy to understand and use syntax:


type ::= <nonArrayType> | <arrayType>
arrayType ::= <nonArrayType> '[' ']'
nonArrayType ::= <tupleType> | <unionType> | <compoundType> 
                             | <enumType> | <rangeType>  
                             | <primaryType> | <simpleType> | <specialType>
tupleType ::= '[' <elementType1> [','] <elementType2> .. <elementTypeN> ']'
elementType ::= <type>
unionType ::= '(' <alternativeType1> '|' <alternativeType2 > '|' .. <alternativeTypeN> ')'
alternativeType ::= <type>
enumType ::= 'enum' '(' <enumValue1> '|' <enumValue2> '|' ... <enumValueN> ')'
enumValue ::= ( <identifier> | <quoted-string> | <dquoted-string> ) [ '=' <integer-constant> ]
rangeType ::= 'range' '(' <baseType> ':' <minValue> '..' <maxValue> ')'
minValue ::= <constant>
maxValue ::= <constant>
subsetType ::= 'subset' '(' <baseType> ':' <range1> [',' <range2>]... ')'
range ::= <minValue> '..' <maxValue> | <constant>
compoundType ::= '{' <fieldSpec1> <fieldSpec2> ... <fieldSpecN> '}'
fieldSpec ::= <fieldIdentifier> ':' <fieldType> [ '=' <defaultValue> ] [';']
fieldType ::= <type>
primaryType ::= '<' <BuiltIn-Classname> '>'
BuiltIn-Classname ::= <identifier>
simpleType ::= <anyType> | <templateType> | <constraintTemplateType> | <namedType>
anyType ::= '*'
templateType ::= '#' <templateIdentifier>

constraintTemplateType ::= '#' <templateIdentifier> <setOfConstraintTypes>
setOfConstraintTypes ::= <unionType>
<namedType> ::= 'any' | 'struct' | <typeName_in_project> | <Smalltalk-Classname>
typeName_in_project ::= <identifier>
specialType ::= <monitorType> | <portType> | <datatypeType>
monitorType ::= 'monitor' '(' <baseType>')'
portType ::= 'port' '(' <baseType>')'
datatypeType ::= 'datatype' [ '(' <constraint> ')' ]
constraint ::= 'isUserDefinedType' | 'isWellKnownType' | 
               'isPrimaryType' | 
               'isNumberPrimaryType' | 'isCollectionPrimaryType' | 'isStreamPrimaryType'
               'isArrayType' | 'isCTypeType'
               'isCompoundType' | 'isEnumType' | 'isTupleType' | 'isUnionType'

Notes:
The separating commas in the tuple- and compound definitions are optional (vsn 2.1).
The "struct" named type is only supported by vsn 2.1 and newer.
Constraint datatypes are only supported in vsn 2.8 and newer.
This format is used if you select "Defined" type in the editor. It is also expected if you select "Define..." in one of the type menus (Pin-Type, Veriable-Type, Skill-Type). Support for this representation is part of the base expecco system.

DTD Type Definition

A DTD definition can also be used to specify a compound type. For this, choose "Compound (DTD-Defined)", and paste the DTD into the text area. Support for this representation is part of the base expecco system.

C Language Type Definition

A C language code fragment can also be used to specify a compound or union type. For this, choose "CType (C-Defined)", and paste the C type definition into the text area. Instances of this type are especially useful when calling external DLL functions. Support for this representation is part of the base expecco system.

A typical C language definition looks like:

struct {
    int i1;
    float f1;
    double d1;
    char c[20];
};

For more details, please refer to the Datatype - CTypes document .

XSD Type Definition

A definition in XSD-XML. An XSD definition can also be used to specify a type. This is an extension provided by a plugin. Please read the corresponding plugin documentation.

<usage: to be documented>

COBOL CopyBook Definition

Parses a Cobol-CopyBook type-definition. This is only available as plugin. Please read the corresponding plugin documentation for details.

ASN1 Type Definiton

Parses an ASN1 type-definition. This is only available as plugin. Please read the corresponding plugin documentation for details.

SunRPC-IDL Type Definiton

Parses a SunRPC type-definition, which is used for example in the NFS file-system or in VISA lab equipment interfaces. This is only available as plugin. Please read the corresponding plugin documentation for details.

Microsoft COM/DCOM-IDL Type Definition

Parses a COM/DCOM IDL type-definition.

This is only available as plugin. Please read the corresponding plugin documentation for details.



Copyright © 2014-2016 eXept Software AG