Search in sources :

Example 96 with IType

use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.

the class Indexed_Template_List method generateCodeExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final TemplateRestriction.Restriction_type templateRestriction) {
    if (asValue != null) {
        asValue.generateCodeExpression(aData, expression, true);
        return;
    }
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        return;
    }
    final String tempId = aData.getTemporaryVariableName();
    final String genName = governor.getGenNameTemplate(aData, expression.expression, myScope);
    expression.preamble.append(MessageFormat.format("{0} {1} = new {0}();\n", genName, tempId));
    setGenNameRecursive(genName);
    generateCodeInit(aData, expression.preamble, tempId);
    if (templateRestriction != Restriction_type.TR_NONE) {
        TemplateRestriction.generateRestrictionCheckCode(aData, expression.expression, location, tempId, templateRestriction);
    }
    expression.expression.append(tempId);
}
Also used : IType(org.eclipse.titan.designer.AST.IType)

Example 97 with IType

use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.

the class Invoke_Template method getExpressionGovernor.

@Override
public /**
 * {@inheritDoc}
 */
IType getExpressionGovernor(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (myGovernor != null) {
        return myGovernor;
    }
    if (value == null) {
        setIsErroneous(true);
        return null;
    }
    IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (type == null) {
        if (!value.getIsErroneous(timestamp)) {
            value.getLocation().reportSemanticError(VALUEXPECTED1);
        }
        setIsErroneous(true);
        return null;
    }
    type = type.getTypeRefdLast(timestamp);
    switch(type.getTypetype()) {
        case TYPE_FUNCTION:
            final Type result = ((Function_Type) type).getReturnType();
            if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) && ((Function_Type) type).returnsTemplate()) {
                location.reportSemanticError(MessageFormat.format(VALUEXPECTED2, type.getTypename(), result.getTypename()));
            }
            return result;
        case TYPE_ALTSTEP:
            setIsErroneous(true);
            return null;
        default:
            value.getLocation().reportSemanticError(MessageFormat.format(FUNCTIONEXPECTED, type.getTypename()));
    }
    return null;
}
Also used : Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 98 with IType

use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.

the class Invoke_Template method generateCodeExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final TemplateRestriction.Restriction_type templateRestriction) {
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        return;
    }
    if (lengthRestriction == null && !isIfpresent && templateRestriction == Restriction_type.TR_NONE) {
        // The single expression must be tried first because this rule might cover some referenced templates.
        if (hasSingleExpression()) {
            final String genName = governor.getGenNameTemplate(aData, expression.expression, myScope);
            expression.expression.append(MessageFormat.format("new {0}(", genName));
            if (governor.getTypetype() == Type_type.TYPE_ARRAY) {
                final Array_Type array_type = (Array_Type) governor;
                expression.expression.append(MessageFormat.format(" {0}.class, ", array_type.getElementType().getGenNameTemplate(aData, expression.expression, myScope)));
            }
            expression.expression.append(getSingleExpression(aData, true));
            expression.expression.append(')');
            return;
        }
        generateCodeExpressionInvoke(aData, expression);
        return;
    }
    final String tempId = aData.getTemporaryVariableName();
    expression.preamble.append(MessageFormat.format("{0} {1} = new {0}();\n", governor.getGenNameTemplate(aData, expression.expression, myScope), tempId));
    generateCodeInit(aData, expression.preamble, tempId);
    if (templateRestriction != Restriction_type.TR_NONE) {
        TemplateRestriction.generateRestrictionCheckCode(aData, expression.expression, location, tempId, templateRestriction);
    }
    expression.expression.append(tempId);
}
Also used : Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 99 with IType

use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.

the class Invoke_Template method checkInvoke.

public void checkInvoke(final CompilationTimeStamp timestamp) {
    if (getIsErroneous(timestamp) || actualParameterList == null || value == null) {
        return;
    }
    value.setLoweridToReference(timestamp);
    IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (type != null) {
        type = type.getTypeRefdLast(timestamp);
    }
    if (type == null) {
        if (!value.getIsErroneous(timestamp)) {
            value.getLocation().reportSemanticError("A value of type function was expected in the argument");
        }
        setIsErroneous(true);
        return;
    }
    if (!Type_type.TYPE_FUNCTION.equals(type.getTypetype())) {
        value.getLocation().reportSemanticError(MessageFormat.format("A value of type function was expected in the argument instead of `{0}''", type.getTypename()));
        setIsErroneous(true);
        return;
    }
    if (myScope == null) {
        return;
    }
    myScope.checkRunsOnScope(timestamp, type, this, "call");
    final FormalParameterList formalParameterList = ((Function_Type) type).getFormalParameters();
    actualParameter_list = new ActualParameterList();
    if (!formalParameterList.checkActualParameterList(timestamp, actualParameterList, actualParameter_list)) {
        actualParameter_list.setFullNameParent(this);
        actualParameter_list.setMyScope(getMyScope());
    }
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) IType(org.eclipse.titan.designer.AST.IType)

Example 100 with IType

use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.

the class Invoke_Template method generateCodeExpressionInvoke.

private void generateCodeExpressionInvoke(final JavaGenData aData, final ExpressionStruct expression) {
    if (value == null || actualParameter_list == null) {
        return;
    }
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last.getValuetype() == Value_type.FUNCTION_REFERENCE_VALUE) {
        final Definition function = ((Function_Reference_Value) last).getReferredFunction();
        expression.expression.append(MessageFormat.format("{0}(", function.getGenNameFromScope(aData, expression.expression, myScope, "")));
        actualParameter_list.generateCodeAlias(aData, expression);
    } else {
        value.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".invoke(");
        IType governor = value.getMyGovernor();
        if (governor == null) {
            governor = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
        }
        if (governor == null) {
            return;
        }
        actualParameter_list.generateCodeAlias(aData, expression);
    }
    expression.expression.append(')');
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Function_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Function_Reference_Value) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)414 IValue (org.eclipse.titan.designer.AST.IValue)94 ISubReference (org.eclipse.titan.designer.AST.ISubReference)82 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)65 Identifier (org.eclipse.titan.designer.AST.Identifier)49 Assignment (org.eclipse.titan.designer.AST.Assignment)40 Value (org.eclipse.titan.designer.AST.Value)34 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)33 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)27 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)21 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)21 Reference (org.eclipse.titan.designer.AST.Reference)21 Type (org.eclipse.titan.designer.AST.Type)20 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)18 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)17 ArrayList (java.util.ArrayList)16 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)15 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)14 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)14 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)13