Search in sources :

Example 1 with Function_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.

the class Function_Reference_Value method generateSingleExpression.

@Override
public /**
 * {@inheritDoc}
 */
StringBuilder generateSingleExpression(final JavaGenData aData) {
    final StringBuilder result = new StringBuilder();
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        governor = myLastSetGovernor;
    }
    if (governor == null || referredFunction == null) {
        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
        return result;
    }
    final IType lastGovernor = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    final Function_Type functionType = (Function_Type) lastGovernor;
    final Type returnType = functionType.getReturnType();
    final String moduleName = referredFunction.getMyScope().getModuleScope().getName();
    final String functionName = referredFunction.getIdentifier().getName();
    result.append(MessageFormat.format("new {0}(new {0}.function_pointer() '{'\n", governor.getGenNameValue(aData, result, myScope)));
    result.append("@Override\n");
    result.append("public String getModuleName() {\n");
    result.append(MessageFormat.format("return \"{0}\";\n", moduleName));
    result.append("}\n");
    result.append("@Override\n");
    result.append("public String getDefinitionName() {\n");
    result.append(MessageFormat.format("return \"{0}\";\n", functionName));
    result.append("}\n");
    result.append("@Override\n");
    result.append("public ");
    final StringBuilder actualParList = functionType.getFormalParameters().generateCodeActualParlist("");
    if (returnType == null) {
        result.append("void");
    } else {
        if (functionType.returnsTemplate()) {
            result.append(returnType.getGenNameTemplate(aData, result, myScope));
        } else {
            result.append(returnType.getGenNameValue(aData, result, myScope));
        }
    }
    result.append(" invoke(");
    functionType.getFormalParameters().generateCode(aData, result);
    result.append(") {\n");
    result.append(MessageFormat.format("{0}{1}.{2}({3});\n", returnType == null ? "" : "return ", moduleName, functionName, actualParList));
    result.append("}\n");
    if (functionType.isStartable(CompilationTimeStamp.getBaseTimestamp())) {
        aData.addBuiltinTypeImport("TitanComponent");
        result.append("@Override\n");
        result.append("public void start(final TitanComponent component_reference");
        if (functionType.getFormalParameters().getNofParameters() > 0) {
            result.append(", ");
            functionType.getFormalParameters().generateCode(aData, result);
        }
        result.append(") {\n");
        result.append(MessageFormat.format("{0}.start_{1}(component_reference", moduleName, functionName));
        if (actualParList != null && actualParList.length() > 0) {
            result.append(MessageFormat.format(", {0}", actualParList));
        }
        result.append(");\n");
        result.append("}\n");
    }
    result.append("})\n");
    return result;
}
Also used : 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 2 with Function_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.

the class ApplyExpression method getExpressionGovernor.

@Override
public /**
 * {@inheritDoc}
 */
IType getExpressionGovernor(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (myGovernor != null) {
        return myGovernor;
    }
    if (value == null) {
        return null;
    }
    IType type = value.getExpressionGovernor(timestamp, expectedValue);
    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;
        default:
            setIsErroneous(true);
            return null;
    }
}
Also used : 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 3 with Function_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.

the class Def_ModulePar method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    T3Doc.check(this.getCommentLocation(), KIND);
    isUsed = false;
    NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_MODULEPAR, identifier, this);
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
    }
    if (type == null) {
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp);
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_SIGNATURE:
            location.reportSemanticError(MessageFormat.format(SIGNATURENOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_FUNCTION:
        case TYPE_ALTSTEP:
        case TYPE_TESTCASE:
            if (((Function_Type) lastType).isRunsOnSelf()) {
                location.reportSemanticError(MessageFormat.format(RUNSONSELF_NOT_ALLOWED, lastType.getFullName()));
            }
            break;
        default:
            break;
    }
    if (defaultValue != null) {
        defaultValue.setMyGovernor(type);
        final IValue temporalValue = type.checkThisValueRef(timestamp, defaultValue);
        type.checkThisValue(timestamp, temporalValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, true, false, true, hasImplicitOmitAttribute(timestamp), false));
        defaultValue.setCodeSection(CodeSectionType.CS_PRE_INIT);
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 4 with Function_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.

the class Def_ModulePar_Template method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    T3Doc.check(this.getCommentLocation(), KIND);
    isUsed = false;
    NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_MODULEPAR, identifier, this);
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
    }
    if (type == null) {
        return;
    }
    type.setGenName("_T_", getGenName());
    type.check(timestamp);
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(Def_ModulePar.PORTNOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_SIGNATURE:
            location.reportSemanticError(MessageFormat.format(Def_ModulePar.SIGNATURENOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_FUNCTION:
        case TYPE_ALTSTEP:
        case TYPE_TESTCASE:
            if (((Function_Type) lastType).isRunsOnSelf()) {
                location.reportSemanticError(MessageFormat.format(Def_ModulePar.RUNSONSELF_NOT_ALLOWED, lastType.getFullName()));
            }
            break;
        default:
            break;
    }
    if (defaultTemplate != null) {
        realTemplate = defaultTemplate;
        // Needed in case of universal charstring templates
        if (defaultTemplate.getTemplatetype() == Template_type.CSTR_PATTERN && lastType.getTypetype() == Type.Type_type.TYPE_UCHARSTRING) {
            realTemplate = defaultTemplate.setTemplatetype(timestamp, Template_type.USTR_PATTERN);
        // FIXME implement setting the pattern type,
        // once universal charstring pattern are
        // supported.
        }
        final ITTCN3Template temporalTemplate = type.checkThisTemplateRef(timestamp, realTemplate);
        temporalTemplate.checkThisTemplateGeneric(timestamp, type, false, true, true, true, false, null);
        final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(Def_Template.CIRCULAREMBEDDEDRECURSION, true);
        tempReferenceChain.add(this);
        temporalTemplate.checkRecursions(timestamp, tempReferenceChain);
        tempReferenceChain.release();
        // defaultTemplate.setGenNamePrefix("modulepar_");//currently does not need the prefix
        defaultTemplate.setGenNameRecursive(getGenName());
        defaultTemplate.setCodeSection(CodeSectionType.CS_PRE_INIT);
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 5 with Function_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type 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)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)14 Function_Type (org.eclipse.titan.designer.AST.TTCN3.types.Function_Type)12 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)4 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)4 Type (org.eclipse.titan.designer.AST.Type)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 Expression_Value (org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value)3 IReferencingType (org.eclipse.titan.designer.AST.IReferencingType)2 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)2 Component_Type (org.eclipse.titan.designer.AST.TTCN3.types.Component_Type)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Value_Assignment (org.eclipse.titan.designer.AST.ASN1.Value_Assignment)1 Assignment (org.eclipse.titan.designer.AST.Assignment)1 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)1 IValue (org.eclipse.titan.designer.AST.IValue)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Restriction_type (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type)1 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)1 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)1