Class ExpressionTranslator<I extends VariableDeclaration,​R extends Resolver<I>,​E extends ExpressionStatement>

    • Constructor Detail

      • ExpressionTranslator

        public ExpressionTranslator()
        Creates an expression translator (to be used within this package only).
    • Method Detail

      • setIvmlMessageAdapter

        public IvmlMessageAdapter setIvmlMessageAdapter​(IvmlMessageAdapter adapter)
        Allows for (temporary) exchange of the IVML message adapter, e.g., to handle warnings differently.
        Parameters:
        adapter - the new message adapter
        Returns:
        the old message adapter
      • getIvmlMessageAdapter

        public IvmlMessageAdapter getIvmlMessageAdapter()
        Returns the IVML message adapter.
        Returns:
        the adapter instance
      • processExpression

        public Expression processExpression​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.Expression ex,
                                            R resolver)
                                     throws TranslatorException
        Creates the expression tree for a given expression.
        Parameters:
        ex - the expression to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression tree
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • enactIvmlWarnings

        public void enactIvmlWarnings()
        Enacts the IVML warnings not resolved by "function pointers" so far.
      • ivmlWarning

        private void ivmlWarning​(java.lang.String name,
                                 org.eclipse.emf.ecore.EObject cause,
                                 org.eclipse.emf.ecore.EStructuralFeature causingFeature)
        Creates a warning due to an unresolved IVML element.
        Parameters:
        name - the name of the element
        cause - the causing ECore element
        causingFeature - the causing ECore feature
      • processExpressionStatement

        public E processExpressionStatement​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.ExpressionStatement expr,
                                            R resolver)
                                     throws TranslatorException
        Processes an expression statement.
        Parameters:
        expr - the expression to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the expression statement
        Throws:
        TranslatorException - in case that the translation fails due to semantic reasons
        See Also:
        cannotAssignHint()
      • cannotAssignHint

        protected abstract java.lang.String cannotAssignHint()
        A hint if an assignment is not allowed.
        Returns:
        the hint (must not be null)
      • createExpressionStatement

        protected abstract E createExpressionStatement​(Expression expression,
                                                       R resolver)
        Creates an expression statement.
        Parameters:
        expression - the expression
        resolver - the resolver instance
        Returns:
        the expression statement
      • processLogicalExpression

        public Expression processLogicalExpression​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.LogicalExpression ex,
                                                   R resolver)
                                            throws TranslatorException
        Processes a logical expression.
        Parameters:
        ex - the expression to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • processEqualityExpression

        protected Expression processEqualityExpression​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.EqualityExpression ex,
                                                       R resolver)
                                                throws TranslatorException
        Processes an equality expression.
        Parameters:
        ex - the expression to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • processRelationalExpression

        protected Expression processRelationalExpression​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.RelationalExpression ex,
                                                         R resolver)
                                                  throws TranslatorException
        Processes a relational expression.
        Parameters:
        ex - the expression to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • processAdditiveExpression

        protected Expression processAdditiveExpression​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.AdditiveExpression ex,
                                                       R resolver)
                                                throws TranslatorException
        Processes an additive expression.
        Parameters:
        ex - the expression to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • processMultiplicativeExpression

        protected Expression processMultiplicativeExpression​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.MultiplicativeExpression ex,
                                                             R resolver)
                                                      throws TranslatorException
        Processes a multiplicative expression.
        Parameters:
        ex - the expression to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • processUnaryExpression

        protected Expression processUnaryExpression​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.UnaryExpression ex,
                                                    R resolver)
                                             throws TranslatorException
        Processes a unary expression.
        Parameters:
        ex - the expression to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • processPostfixExpression

        protected Expression processPostfixExpression​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.PostfixExpression ex,
                                                      R resolver)
                                               throws TranslatorException
        Processes a postfix expression.
        Parameters:
        ex - the expression to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • resolveIteratorDeclarations

        protected java.util.List<I> resolveIteratorDeclarations​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.Call call,
                                                                ExpressionTranslator.CallType type,
                                                                java.util.List<CallArgument> arguments,
                                                                R resolver)
                                                         throws TranslatorException
        Resolves the iterator declarations. Existence of iterator declarations in call is already checked to be valid.
        Parameters:
        call - the call holding the iterator declarations
        type - the type of the call (not the return type)
        Returns:
        the iterator declarations in terms of variable declarations (may be empty if there are none)
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • processDeclarators

        private java.util.ArrayList<I> processDeclarators​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.Call call,
                                                          TypeDescriptor<?> implicitType,
                                                          java.util.List<CallArgument> arguments,
                                                          R resolver)
                                                   throws TranslatorException
        Processes a declarator.
        Parameters:
        call - the actual call
        implicitType - the implicit type of the declarator to check against or to use if no explicit type is given, may be null if the underlying type declares the collection implicitly (see deleteJavaCall). In the latter case, the type must be explicitly given by the declarator.
        resolver - the resolver
        arguments - the call arguments (may be changed to enable implicit collection iterators)
        Returns:
        a list of resolved declarators (at the moment at maximum 1)
        Throws:
        TranslatorException - in case that the translation fails
      • resolveCallArguments

        protected java.lang.String resolveCallArguments​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.Call call,
                                                        java.util.List<I> iterators,
                                                        java.util.List<CallArgument> arguments,
                                                        de.uni_hildesheim.sse.vil.expressions.expressionDsl.Expression arrayEx,
                                                        R resolver)
                                                 throws TranslatorException
        Resolves call arguments.
        Parameters:
        call - the call to resolve the arguments for
        iterators - the iterators (may be changed as a side effect)
        arguments - the arguments created so far (may be the operator, list is modified as a side effect)
        arrayEx - an array access expression (may be null, but then call is required)
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the operation name
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • resolveCallArgumentExpression

        private Expression resolveCallArgumentExpression​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.NamedArgument param,
                                                         int paramIndex,
                                                         java.util.List<I> iterators,
                                                         java.util.List<CallArgument> arguments,
                                                         R resolver)
                                                  throws TranslatorException
        Tries to resolve a call argument. If it is the first argument of a container iteration and there is no iterator, implicitly try to create an iterator.
        Parameters:
        param - the parameter
        paramIndex - the 0-based index of param in the call being processed
        iterators - the iterators known so far (may be changed as a side effect)
        arguments - the call arguments
        resolver - the resolver instance
        Returns:
        the resolved expression
        Throws:
        TranslatorException - in case that resolution fails
      • tryIteratorExpression

        private ExpressionEvaluator tryIteratorExpression​(java.util.List<CallArgument> arguments,
                                                          de.uni_hildesheim.sse.vil.expressions.expressionDsl.NamedArgument param,
                                                          R resolver)
                                                   throws TranslatorException
        Tries to compose an iterator expression (ExpressionEvaluator)
        Parameters:
        arguments - the arguments to try to construct the expression from
        param - the actual parameter to do the resolution for
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the iterator expression if successful
        Throws:
        TranslatorException - in case that the expression cannot be created
      • createVariableDeclaration

        protected abstract I createVariableDeclaration​(java.lang.String name,
                                                       TypeDescriptor<?> type,
                                                       boolean isConstant,
                                                       Expression expression,
                                                       R resolver)
        Creates a new variable declaration.
        Parameters:
        name - the name of the variable
        type - the type of the variable
        isConstant - whether this variable is a constant
        expression - an expression denoting the initial value (may be null)
        resolver - the resolver instance
      • createImplicitVariableDeclaration

        protected abstract I createImplicitVariableDeclaration​(java.lang.String name,
                                                               TypeDescriptor<?> type,
                                                               boolean isConstant,
                                                               Expression expression,
                                                               R resolver)
        Creates a new implicit variable declaration.
        Parameters:
        name - the name of the variable
        type - the type of the variable
        isConstant - whether this variable is a constant
        expression - an expression denoting the initial value (may be null)
        resolver - the resolver instance
      • processCall

        protected abstract Expression processCall​(Expression firstParam,
                                                  de.uni_hildesheim.sse.vil.expressions.expressionDsl.Call call,
                                                  ExpressionTranslator.CallType type,
                                                  de.uni_hildesheim.sse.vil.expressions.expressionDsl.Expression arrayEx,
                                                  R resolver)
                                           throws TranslatorException
        Processes a function call.
        Parameters:
        firstParam - the first parameter (may be null)
        call - the function all (may be null, but then arrayEx is required)
        arrayEx - an array access expression (may be null, but then call is required)
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • checkSemantics

        protected VilException checkSemantics​(Expression expr)
        Checks the semantics of a potential call candidate.
        Parameters:
        expr - the expression to be checked
        Returns:
        the expr if ok or null
      • processSubCalls

        protected Expression processSubCalls​(Expression firstParam,
                                             org.eclipse.emf.common.util.EList<de.uni_hildesheim.sse.vil.expressions.expressionDsl.SubCall> followups,
                                             R resolver)
                                      throws TranslatorException
        Processes sub calls, i.e., calls connected by ".".
        Parameters:
        firstParam - the first parameter (the expression before the ".")
        followups - the follow-up calls
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • processPrimaryExpression

        public Expression processPrimaryExpression​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.PrimaryExpression ex,
                                                   R resolver)
                                            throws TranslatorException
        Processes a primary expression.
        Parameters:
        ex - the expression to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • processArguments

        public CallArgument[] processArguments​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.ArgumentList arguments,
                                               R resolver)
                                        throws TranslatorException
        Processes an argument list and translates them into call arguments.
        Parameters:
        arguments - the arguments to be translated
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • processConstant

        protected Expression processConstant​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.Constant arg,
                                             R resolver)
                                      throws TranslatorException
        Processes a constant argument.
        Parameters:
        arg - the constant to be processed
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason
      • normalizeStringExpression

        private Expression normalizeStringExpression​(Expression ex,
                                                     java.lang.String st)
                                              throws VilException
        Normalizes a string expression, i.e., if ex (within a CompositeExpression is not a constant, a StringExpression containing the expression is inserted instead. This allows recursive/nested variable/expression substitution without having the required string quotes being quoted within a string.
        Parameters:
        ex - the expression to check
        Returns:
        ex or a modified ex
        Throws:
        VilException - if creating the modified expression fails
      • processQualifiedValue

        protected Expression processQualifiedValue​(java.lang.String name,
                                                   de.uni_hildesheim.sse.vil.expressions.expressionDsl.Constant arg,
                                                   org.eclipse.emf.ecore.EStructuralFeature feature,
                                                   R resolver)
                                            throws TranslatorException
        Processes a qualified value and creates variable expressions.
        Parameters:
        name - the qualified name
        arg - the constant to be processed
        feature - the feature corresponding to arg
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resulting expression node
        Throws:
        TranslatorException - in case that the translation fails for some reason, in particular if ITER cannot be resolved
      • checkOclEnumCompliance

        private void checkOclEnumCompliance​(java.lang.String name,
                                            org.eclipse.emf.ecore.EObject cause,
                                            org.eclipse.emf.ecore.EStructuralFeature causeFeature)
        Checks the given enumeration literal name for OCL compliance.
        Parameters:
        name - the name
        cause - the causing object
        causeFeature - the causing feature
      • createConstant

        protected static final Expression createConstant​(TypeDescriptor<?> type,
                                                         java.lang.Object value,
                                                         org.eclipse.emf.ecore.EObject cause,
                                                         org.eclipse.emf.ecore.EStructuralFeature causingFeature,
                                                         TypeRegistry registry)
                                                  throws TranslatorException
        Creates a constant.
        Parameters:
        type - the type of the constant
        value - the value of the constant
        cause - the Ecore language model element for which the exception was caused
        causingFeature - the specific language feature within cause which caused the exception
        Returns:
        the created constant expression
        Throws:
        TranslatorException - in case that type resolution fails
      • processType

        public TypeDescriptor<?> processType​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.Type type,
                                             R resolver)
                                      throws TranslatorException
        Processes the given type and tries to resolve it to a VIL type.
        Parameters:
        type - the type to be processed
        resolver - the resolver instance
        Returns:
        the corresponding VIL type
        Throws:
        TranslatorException - in case that type resolution fails
      • resolveModelType

        private TypeDescriptor<?> resolveModelType​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.Type type,
                                                   java.lang.String typeName,
                                                   R resolver)
                                            throws TranslatorException
        Resolves a model type.
        Parameters:
        type - the type as ECore instance
        typeName - the name of the type
        resolver - the resolver
        Returns:
        the type or null if not resolved
        Throws:
        TranslatorException - in case of a serious resolution problem
      • processContainerInitializer

        private ContainerInitializerExpression processContainerInitializer​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.ContainerInitializer initializer,
                                                                           R resolver)
                                                                    throws TranslatorException
        Processes a container initializer expression.
        Parameters:
        initializer - the container initializer expression as ECore instance
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the resolved container initializer expression
        Throws:
        TranslatorException - in case that type resolution fails
      • processTypeParameter

        protected TypeDescriptor<?>[] processTypeParameter​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.TypeParameters param,
                                                           de.uni_hildesheim.sse.vil.expressions.expressionDsl.Type type,
                                                           R resolver)
                                                    throws TranslatorException
        Processes the type parameter.
        Parameters:
        param - the ECore instance containing the type parameter
        type - the type the parameter are assigned to
        resolver - the resolver instance
        Returns:
        the processed parameter in terms of VIL type descriptors
        Throws:
        TranslatorException - in case that type resolution fails
      • processAssignment

        public Expression processAssignment​(org.eclipse.emf.ecore.EObject cause,
                                            TypeDescriptor<?> type,
                                            de.uni_hildesheim.sse.vil.expressions.expressionDsl.Expression ex,
                                            R resolver)
                                     throws TranslatorException
        Processes an assignment.
        Parameters:
        decl - the variable declaration to assign to
        type - the type of the variable
        ex - the expression defining the right side of the assignment (may be null)
        text - a text describing the left side in case of an error
        resolver - the resolver instance
        Returns:
        the resolved initialization expression or null if ex was null
        Throws:
        TranslatorException - in case that type resolution / compliance fails
      • processVariableDeclaration

        public I processVariableDeclaration​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.VariableDeclaration decl,
                                            R resolver)
                                     throws TranslatorException
        Processes a variable declaration.
        Parameters:
        decl - the declaration
        resolver - a resolver instance for resolving variables etc.
        Returns:
        the created model instance
        Throws:
        TranslatorException - in case that the translation fails
      • throwVariableCannotBeInitialized

        private void throwVariableCannotBeInitialized​(org.eclipse.emf.ecore.EObject cause,
                                                      java.lang.String name,
                                                      TypeDescriptor<?> declType,
                                                      TypeDescriptor<?> initType)
                                               throws TranslatorException
        Throws a TranslatorException that a variable cannot be initialized.
        Parameters:
        cause - the causing ECore object
        name - the name of the object (inferred from cause if null if possible)
        declType - the declaration VIL type
        initType - the init expression VIL type
        Throws:
        TranslatorException - the created exception
      • getName

        private static java.lang.String getName​(org.eclipse.emf.ecore.EObject cause)
        Tries to obtain the name of cause.
        Parameters:
        cause - the cause
        Returns:
        the name or "?"
      • continueResolution

        protected boolean continueResolution​(VilException semanticException)
        Returns whether resolution shall be continued in case of multiple similar call expressions.
        Parameters:
        semanticException - the exception being thrown by the (partial) call resolution
        Returns:
        true if resolution shall be continued (there was an exception and it points to a resolution or a semantic problem), false else
      • error

        public void error​(AbstractException exception,
                          org.eclipse.emf.ecore.EObject cause,
                          org.eclipse.emf.ecore.EStructuralFeature causeFeature)
        Turns a buildlang exception into a xText error.
        Parameters:
        exception - the exception to used
        cause - the cause (as instance of the EMF grammar model)
        causeFeature - the cause of the feature as an appropriate constant from IvmlPackage.Literals
      • warning

        public void warning​(AbstractException exception,
                            org.eclipse.emf.ecore.EObject cause,
                            org.eclipse.emf.ecore.EStructuralFeature causeFeature)
        Turns a buildlang exception into a xText warning.
        Parameters:
        exception - the exception to used
        cause - the cause (as instance of the EMF grammar model)
        causeFeature - the cause of the feature as an appropriate constant from IvmlPackage.Literals
      • warnVersionRestrictions

        public void warnVersionRestrictions​(de.uni_hildesheim.sse.vil.expressions.expressionDsl.VersionSpec spec)
        Issues implementation warnings about version restrictions.
        Parameters:
        spec - the version specification (may be null)
      • processRestriction

        public IVersionRestriction processRestriction​(java.lang.String name,
                                                      de.uni_hildesheim.sse.vil.expressions.expressionDsl.VersionSpec spec,
                                                      R resolver)
                                               throws TranslatorException
        Processes an import restriction.
        Parameters:
        name - the name of the import
        spec - the version specification to be processed
        Returns:
        the created restriction
        Throws:
        TranslatorException - in case of any translation problem
      • createExpressionVersionRestriction

        protected abstract ExpressionVersionRestriction createExpressionVersionRestriction​(Expression expr,
                                                                                           VariableDeclaration decl,
                                                                                           org.eclipse.emf.ecore.EObject cause,
                                                                                           org.eclipse.emf.ecore.EStructuralFeature feature)
                                                                                    throws RestrictionEvaluationException
        Creates an expression version restriction matching this class.
        Parameters:
        expr - the expression for the restriction
        decl - the version variable
        cause - the grammar cause for this call
        feature - the causing feature
        Returns:
        the created instance
        Throws:
        RestrictionEvaluationException - in case of any type related problems
      • assertBooleanExpression

        public Expression assertBooleanExpression​(Expression expression,
                                                  org.eclipse.emf.ecore.EObject cause,
                                                  org.eclipse.emf.ecore.EStructuralFeature causingFeature)
                                           throws TranslatorException
        Asserts the given expression to be of Boolean type.
        Parameters:
        expression - the expression to check
        cause - the causing ECore AST object
        causingFeature - the causing feature
        Returns:
        expression or a converted expression
        Throws:
        TranslatorException - thrown if the expression is not of type Boolean