5.6.1. Predefined Function Call

[Tip]Description

VIATRA provides a set of predefined functions: a part of it is built-in function that is interpreted by the VIATRA engine and another part is defined as an Eclipse plug-in; these later ones are called native functions.

[Important]Syntax
PredefinedFunctionCallAST ::= BuiltInFunctionNameAST ( ArithmeticTermAST ) 
                            | ConversionFunctionNameAST ( ArithmeticTermAST ) 
	
BuiltInFunctionNameAST$BuiltInFunctionNameAST ::= 
                    ref | fqn | name | value | source | target |  
                    multiplicity | aggregation | inverse

ConversionFunctionNameAST$ConversionFunctionNameAST ::= 
    toBoolean | toString | toInteger | toDouble | toMultiplicity

The predefined functions are identified by their names and they are called with an actual parameter list.

For native functions, the name and the formal parameter list is determined by an Eclipse plug-in. The objects returned by native functions should be treated by the interpreter according to the followings:

  • for built-in types (String, Double, Boolean, Integer, IModelElement), the interpreter should recognize the type and provide auto-conversion,

  • unknown types are handled as "native function objects" that can be passed to other native functions as parameters, but if the transformation tries to use them as a normal VTCL value, a runtime exception is thrown.

Built-in functionsare the followings:

  • Element reference functions

    • ref(s)- This function returns a reference to the model element corresponding to string s, where sis the string representation of the model element name.

    • fqn(e)- Returns the fully qualified name of the model element e as string.

    • name(e)- Returns the local name of the model element e as string.

    • value(e)- Returns the value associated to the model entity e as string.

    • source(r)- Returns the source element of the relation r as model element reference.

    • target(r)- Returns the target element of the relation r as model element reference.

  • Conversion functions

    • toBoolean(r)- Converts the value r to boolean (if possible).

    • toString(r)- Converts the value r to string (if possible).

    • toInteger(r)- Converts the value r to integer number (if possible).

    • toDouble(r)- Converts the value r to double precision floating point number (if possible).

[Note]Semantics

The native function handling mechanism provides a powerful extension to the framework. Defining a native function is the way how can be extended with arbitrary functionality even by the transformation developers.

Note that currently, native functions are stateless, i.e. they do not preserve their internal state along subsequent calls.

Used By:  base arithmetic term