Search in sources :

Example 11 with Template_List

use of org.eclipse.titan.designer.AST.TTCN3.templates.Template_List 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 12 with Template_List

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

the class ReplaceExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    Type_type tempType1 = null;
    IValue value1 = null;
    if (templateInstance1 != null) {
        final ITTCN3Template temp = templateInstance1.getTemplateBody();
        switch(temp.getTemplatetype()) {
            case SPECIFIC_VALUE:
                break;
            case TEMPLATE_LIST:
            case NAMED_TEMPLATE_LIST:
            case INDEXED_TEMPLATE_LIST:
                templateInstance1.getLocation().reportSemanticError(OPERANDERROR13);
                setIsErroneous(true);
                return;
            default:
                templateInstance1.getLocation().reportSemanticError(OPERANDERROR5);
                setIsErroneous(true);
                return;
        }
        // temp is specific value:
        value1 = ((SpecificValue_Template) temp).getSpecificValue();
        value1.setLoweridToReference(timestamp);
        tempType1 = value1.getExpressionReturntype(timestamp, internalExpectation);
        switch(tempType1) {
            case TYPE_BITSTRING:
            case TYPE_HEXSTRING:
            case TYPE_OCTETSTRING:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
            case TYPE_SET_OF:
            case TYPE_SEQUENCE_OF:
                value1.getValueRefdLast(timestamp, internalExpectation, referenceChain);
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                templateInstance1.getLocation().reportSemanticError(OPERANDERROR5);
                setIsErroneous(true);
                break;
        }
    }
    if (value2 != null) {
        value2.setLoweridToReference(timestamp);
        final Type_type tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType2) {
            case TYPE_INTEGER:
                final IValue last2 = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (!last2.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last2.getValuetype())) {
                    if (((Integer_Value) last2).isNative()) {
                        final long i = ((Integer_Value) last2).getValue();
                        if (i < 0) {
                            value2.getLocation().reportSemanticError(OPERANDERROR3);
                            setIsErroneous(true);
                        }
                    } else {
                        value2.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR11, ((Integer_Value) last2).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                value2.getLocation().reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
                break;
        }
    }
    if (value3 != null) {
        value3.setLoweridToReference(timestamp);
        final Type_type tempType3 = value3.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType3) {
            case TYPE_INTEGER:
                final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (!last3.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last3.getValuetype())) {
                    if (((Integer_Value) last3).isNative()) {
                        final long i = ((Integer_Value) last3).getValue();
                        if (i < 0) {
                            value3.getLocation().reportSemanticError(OPERANDERROR4);
                            setIsErroneous(true);
                        }
                    } else {
                        value3.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR12, ((Integer_Value) last3).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                value3.getLocation().reportSemanticError(OPERANDERROR2);
                setIsErroneous(true);
                break;
        }
    }
    Type_type tempType4 = null;
    IValue value4 = null;
    if (templateInstance4 != null) {
        final ITTCN3Template temp = templateInstance4.getTemplateBody();
        switch(temp.getTemplatetype()) {
            case SPECIFIC_VALUE:
                value4 = ((SpecificValue_Template) temp).getSpecificValue();
                break;
            case TEMPLATE_LIST:
                if (!((Template_List) temp).isValue(timestamp)) {
                    templateInstance4.getLocation().reportSemanticError(OPERANDERROR6);
                    setIsErroneous(true);
                    return;
                }
            case NAMED_TEMPLATE_LIST:
            case INDEXED_TEMPLATE_LIST:
                tempType4 = templateInstance4.getExpressionReturntype(timestamp, expectedValue);
                if (Type_type.TYPE_UNDEFINED.equals(tempType4)) {
                    templateInstance4.getLocation().reportSemanticError(OPERANDERROR13);
                }
                return;
            default:
                templateInstance4.getLocation().reportSemanticError(OPERANDERROR6);
                setIsErroneous(true);
                return;
        }
        value4.setLoweridToReference(timestamp);
        tempType4 = value4.getExpressionReturntype(timestamp, internalExpectation);
        switch(tempType4) {
            case TYPE_BITSTRING:
            case TYPE_HEXSTRING:
            case TYPE_OCTETSTRING:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
            case TYPE_SET_OF:
            case TYPE_SEQUENCE_OF:
                value4.getValueRefdLast(timestamp, internalExpectation, referenceChain);
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR6);
                setIsErroneous(true);
                break;
        }
    }
    if (tempType1 != null && tempType4 != null && !tempType1.equals(tempType4) && !getIsErroneous(timestamp)) {
        location.reportSemanticError(OPERANDERROR7);
        setIsErroneous(true);
    }
    checkExpressionOperandsHelper(timestamp, value1, expectedValue, referenceChain);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)7 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)7 Named_Template_List (org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List)5 Assignment (org.eclipse.titan.designer.AST.Assignment)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)4 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)4 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)3 Reference (org.eclipse.titan.designer.AST.Reference)3 Template_List (org.eclipse.titan.designer.AST.TTCN3.templates.Template_List)3 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 IType (org.eclipse.titan.designer.AST.IType)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)2 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)2 SubsetMatch_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SubsetMatch_Template)2 SupersetMatch_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SupersetMatch_Template)2 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)2 Stack (java.util.Stack)1