Search in sources :

Example 21 with TTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class Send_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct expression = new ExpressionStruct();
    portReference.generateCode(aData, expression);
    expression.expression.append(".send(");
    final TTCN3Template templateBody = parameter.getTemplateBody();
    if (parameter.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
        // optimize for value
        final IValue value = ((SpecificValue_Template) templateBody).getValue();
        // FIXME check if casting is needed
        value.generateCodeExpressionMandatory(aData, expression, true);
    } else {
        // real template, can not be optimized
        parameter.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(", ");
    if (toClause == null) {
        expression.expression.append("new TitanComponent(TitanComponent.SYSTEM_COMPREF)");
    } else {
        toClause.generateCodeExpression(aData, expression, true);
    }
    expression.expression.append(")");
    expression.mergeExpression(source);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 22 with TTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class Raise_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct expression = new ExpressionStruct();
    portReference.generateCode(aData, expression);
    expression.expression.append(".raise( new ");
    signatureReference.generateCode(aData, expression);
    expression.expression.append("_exception(");
    final TTCN3Template templateBody = parameter.getTemplateBody();
    if (parameter.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype())) {
        // the exception is a value: optimization is possible
        final IValue value = ((SpecificValue_Template) templateBody).getSpecificValue();
        // FIXME implement the case where cast is needed (if really needed)
        value.generateCodeExpressionMandatory(aData, expression, true);
    } else {
        parameter.generateCode(aData, expression, Restriction_type.TR_NONE);
    }
    expression.expression.append(')');
    if (toClause != null) {
        expression.expression.append(", ");
        toClause.generateCodeExpression(aData, expression, true);
    }
    expression.expression.append(" )");
    expression.mergeExpression(source);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 23 with TTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method calculateEditLocations.

private WorkspaceJob calculateEditLocations(final NavigableSet<ILocateableNode> nodes, final IFile file, final MultiTextEdit rootEdit) throws CoreException {
    final WorkspaceJob job = new WorkspaceJob("InsertFieldRefactoring: calculate edit locations") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            for (ILocateableNode node : nodes) {
                int vmLen = settings.getType().length() + settings.getId().getTtcnName().length();
                if (node instanceof Def_Type) {
                    Def_Type df = (Def_Type) node;
                    Type type = df.getType(CompilationTimeStamp.getBaseTimestamp());
                    if (type instanceof TTCN3_Sequence_Type || type instanceof TTCN3_Set_Type) {
                        vmLen = insertField((TTCN3_Set_Seq_Choice_BaseType) type, node, rootEdit, vmLen);
                    }
                } else if (node instanceof Sequence_Value) {
                    Sequence_Value sv = (Sequence_Value) node;
                    vmLen += 6;
                    final Location nodeLocation = node.getLocation();
                    if (settings.getPosition() < sv.getNofComponents()) {
                        final Location valueLocation = sv.getSeqValueByIndex(settings.getPosition()).getLocation();
                        Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getOffset(), valueLocation.getEndOffset() + vmLen);
                        rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
                    } else {
                        int max = sv.getNofComponents();
                        final Location valueLocation = sv.getSeqValueByIndex(max - 1).getLocation();
                        Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getEndOffset(), valueLocation.getEndOffset() + vmLen);
                        rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
                    }
                } else if (node instanceof TTCN3Template) {
                    TTCN3Template template = (TTCN3Template) node;
                    vmLen += 6;
                    if (template instanceof Named_Template_List) {
                        Named_Template_List ntl = (Named_Template_List) template;
                        final Location nodeLocation = node.getLocation();
                        if (settings.getPosition() < ntl.getNofTemplates()) {
                            final Location templateLocation = ntl.getTemplateByIndex(settings.getPosition()).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
                        } else {
                            int max = ntl.getNofTemplates();
                            final Location templateLocation = ntl.getTemplateByIndex(max - 1).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
                        }
                    } else if (template instanceof Template_List) {
                        Template_List tl = (Template_List) template;
                        final Location nodeLocation = node.getLocation();
                        if (settings.getPosition() < tl.getNofTemplates()) {
                            final Location templateLocation = tl.getTemplateByIndex(settings.getPosition()).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getValue() + ","));
                        } else {
                            int max = tl.getNofTemplates();
                            final Location templateLocation = tl.getTemplateByIndex(max - 1).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), "," + settings.getValue()));
                        }
                    }
                }
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return job;
}
Also used : Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) InsertEdit(org.eclipse.text.edits.InsertEdit) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Template_List) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) Location(org.eclipse.titan.designer.AST.Location)

Example 24 with TTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class FormalParameterList method setGenName.

public void setGenName(final String prefix) {
    for (final FormalParameter parameter : parameters) {
        final String parameterName = parameter.getIdentifier().getName();
        if (!Assignment_type.A_TIMER.equals(parameter.getAssignmentType())) {
            final Type parameterType = parameter.getType(CompilationTimeStamp.getBaseTimestamp());
            if (parameterType != null) {
                parameterType.setGenName(prefix, parameterName);
            }
        }
        if (parameter.hasDefaultValue()) {
            final StringBuilder embeddedName = new StringBuilder(prefix);
            embeddedName.append('_');
            embeddedName.append(parameterName);
            embeddedName.append("_defval");
            final ActualParameter defaultValue = parameter.getDefaultValue();
            if (defaultValue instanceof Value_ActualParameter) {
                final IValue value = ((Value_ActualParameter) defaultValue).getValue();
                // value.setGenNamePrefix("const_");//currently does not need the prefix
                value.setGenNameRecursive(embeddedName.toString());
            } else if (defaultValue instanceof Template_ActualParameter) {
                final TemplateInstance instance = ((Template_ActualParameter) defaultValue).getTemplateInstance();
                final TTCN3Template template = instance.getTemplateBody();
                // template.setGenNamePrefix("template_");//currently does not need the prefix
                template.setGenNameRecursive(embeddedName.toString());
            }
        }
    }
}
Also used : Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

Example 25 with TTCN3Template

use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.

the class ExpressionUtilities method checkExpressionOperatorCompatibilityInternal.

// the same as the previous but the last arg is template
private static void checkExpressionOperatorCompatibilityInternal(final CompilationTimeStamp timestamp, final Expression_Value expression, final IReferenceChain referenceChain, final Expected_Value_type expectedValue, final IValue param1, final TemplateInstance param2) {
    if (expression == null || param1 == null || param2 == null) {
        return;
    }
    if (param1.getIsErroneous(timestamp) || param2.getTemplateBody().getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    IValue operand1 = param1;
    final TemplateInstance operand2 = param2;
    final Type_type tempType1 = operand1.getExpressionReturntype(timestamp, expectedValue);
    final Type_type tempType2 = operand2.getExpressionReturntype(timestamp, expectedValue);
    ITTCN3Template temp2 = operand2.getTemplateBody();
    if (Type_type.TYPE_UNDEFINED.equals(tempType1)) {
        if (Type_type.TYPE_UNDEFINED.equals(tempType2)) {
            if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand1.getValuetype())) {
                if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype())) {
                    final Scope scope = expression.getMyScope();
                    final Module module = scope.getModuleScope();
                    final Identifier identifier = ((Undefined_LowerIdentifier_Value) operand1).getIdentifier();
                    if (scope.hasAssignmentWithId(timestamp, identifier) || module.hasImportedAssignmentWithID(timestamp, identifier)) {
                        operand1 = operand1.setLoweridToReference(timestamp);
                        checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
                        return;
                    }
                    final Identifier identifier2 = ((Undefined_LowerIdentifier_Value) ((SpecificValue_Template) temp2).getSpecificValue()).getIdentifier();
                    if (scope.hasAssignmentWithId(timestamp, identifier2) || module.hasImportedAssignmentWithID(timestamp, identifier2)) {
                        temp2 = temp2.setLoweridToReference(timestamp);
                        checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
                        return;
                    }
                } else {
                    operand1 = operand1.setLoweridToReference(timestamp);
                    checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
                    return;
                }
            } else if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype())) {
                temp2 = temp2.setLoweridToReference(timestamp);
                // To avoid infinite loop:
                final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) temp2);
                if (operand2 == tempTemplateInstance2) {
                    return;
                }
                checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
                return;
            }
            if (operand1.getIsErroneous(timestamp) || temp2.getIsErroneous(timestamp)) {
                expression.setIsErroneous(true);
                return;
            }
            expression.getLocation().reportSemanticError(UNDETERMINABLEOPERANDSERROR);
            expression.setIsErroneous(true);
            return;
        }
        if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand1.getValuetype()) && !Type_type.TYPE_TTCN3_ENUMERATED.equals(tempType2)) {
            operand1 = operand1.setLoweridToReference(timestamp);
            checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
            return;
        }
    } else if (Type_type.TYPE_UNDEFINED.equals(tempType2)) {
        if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype()) && !Type_type.TYPE_TTCN3_ENUMERATED.equals(tempType1)) {
            temp2 = temp2.setLoweridToReference(timestamp);
            // To avoid infinite loop:
            final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) temp2);
            if (operand2 == tempTemplateInstance2) {
                return;
            }
            checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
            return;
        }
    }
    final IType type1 = operand1.getExpressionGovernor(timestamp, expectedValue);
    final IType type2 = operand2.getExpressionGovernor(timestamp, expectedValue);
    if (operand1.getIsErroneous(timestamp) || temp2.getIsErroneous(timestamp)) {
        expression.setIsErroneous(true);
        return;
    }
    if (type1 != null) {
        if (type2 != null) {
            final TypeCompatibilityInfo info1 = new TypeCompatibilityInfo(type1, type2, true);
            final TypeCompatibilityInfo info2 = new TypeCompatibilityInfo(type2, type1, true);
            final boolean retVal1 = type1.isCompatible(timestamp, type2, info1, null, null);
            final boolean retVal2 = type2.isCompatible(timestamp, type1, info2, null, null);
            if (!retVal1 && !retVal2) {
                expression.getLocation().reportSemanticError(info1.toString());
                expression.setIsErroneous(true);
                return;
            }
            if (GeneralConstants.WARNING.equals(typeCompatibilitySeverity)) {
                if (info1.getNeedsConversion()) {
                    expression.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, type1.getTypename(), type2.getTypename()));
                } else if (info2.getNeedsConversion()) {
                    expression.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, type2.getTypename(), type1.getTypename()));
                }
            }
        } else {
            temp2.setMyGovernor(type1);
            final ITTCN3Template tempValue = type1.checkThisTemplateRef(timestamp, temp2);
            if (Template_type.OMIT_VALUE.equals(temp2.getTemplatetype()) || (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.OMIT_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype()))) {
                operand1.checkExpressionOmitComparison(timestamp, expectedValue);
            } else {
                type1.checkThisTemplate(timestamp, tempValue, false, false, null);
                final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) tempValue);
                if (operand2 == tempTemplateInstance2) {
                    return;
                }
                checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
                return;
            }
        }
    } else if (type2 != null) {
        operand1.setMyGovernor(type2);
        final IValue tempValue = type2.checkThisValueRef(timestamp, operand1);
        if (Value_type.OMIT_VALUE.equals(operand1.getValuetype())) {
        // temp2.check_expression_omit_comparison(timestamp,
        // expectedValue); ???
        } else {
            type2.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(expectedValue, false, false, false, false, false));
            checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, tempValue, operand2);
            return;
        }
    } else {
        if (Type_type.TYPE_UNDEFINED.equals(tempType1) || Type_type.TYPE_UNDEFINED.equals(tempType2)) {
            expression.getLocation().reportSemanticError(PLEASEUSEREFERENCES);
            expression.setIsErroneous(true);
            return;
        }
        if (!Type.isCompatible(timestamp, tempType1, tempType2, false, false) && !Type.isCompatible(timestamp, tempType2, tempType1, false, false)) {
            expression.getLocation().reportSemanticError(INCOMPATIBLEOPERANDERROR);
            expression.setIsErroneous(true);
        }
    }
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance) IType(org.eclipse.titan.designer.AST.IType) IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Scope(org.eclipse.titan.designer.AST.Scope) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) TypeCompatibilityInfo(org.eclipse.titan.designer.AST.TypeCompatibilityInfo) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) Module(org.eclipse.titan.designer.AST.Module) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Aggregations

TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)23 IValue (org.eclipse.titan.designer.AST.IValue)18 Reference (org.eclipse.titan.designer.AST.Reference)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)13 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)12 Assignment (org.eclipse.titan.designer.AST.Assignment)11 IType (org.eclipse.titan.designer.AST.IType)9 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)9 ArrayList (java.util.ArrayList)4 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)4 Type (org.eclipse.titan.designer.AST.Type)4 Identifier (org.eclipse.titan.designer.AST.Identifier)3 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)3 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)3 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)3 SetOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type)3 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)2