Search in sources :

Example 1 with Def_Type

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.

the class Def_Type_Visit_Handler method visitDefTypeNodes.

public void visitDefTypeNodes(IVisitableNode node) {
    Def_Type typeNode = (Def_Type) node;
    String nodeName = typeNode.getIdentifier().toString();
    myASTVisitor.currentFileName = nodeName;
    myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings);
    Type type = typeNode.getType(compilationCounter);
    if (type.getTypetype().equals(TYPE_TTCN3_SEQUENCE)) {
        // record
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "record");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_TTCN3_SET)) {
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "set");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_TTCN3_CHOICE)) {
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "union");
        parentName = nodeName;
    } else if (type instanceof Integer_Type) {
        Def_Type_Integer_Writer.getInstance(typeNode);
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "INTEGER");
        parentName = nodeName;
        isInteger = true;
    } else if (type instanceof CharString_Type) {
        Def_Type_Charstring_Writer.getInstance(typeNode);
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "CHARSTRING");
        parentName = nodeName;
    } else if (type instanceof TTCN3_Enumerated_Type) {
        Def_Type_Enum_Writer.getInstance(typeNode);
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "enum");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_SET_OF)) {
        waitForSetOfFieldType = true;
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "setof");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_SEQUENCE_OF)) {
        waitForRecordOfFieldType = true;
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "recordof");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_PORT)) {
        Def_Type_Port_Writer.getInstance(typeNode);
        waitingForPortAttriburtes = true;
        currentPortName = nodeName;
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "port");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_COMPONENT)) {
        Def_Type_Component_Writer.getInstance(typeNode);
        waitForCompReference = true;
        AstWalkerJava.componentList.add(nodeName);
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "component");
        parentName = nodeName;
    }
}
Also used : Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) Range_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) Type(org.eclipse.titan.designer.AST.Type) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type)

Example 2 with Def_Type

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.

the class Type method checkVariants.

/**
 * Checks the type's variant attributes (when using the new codec handling).
 */
public void checkVariants(final CompilationTimeStamp timestamp) {
    if (isAsn() || ownerType != TypeOwner_type.OT_TYPE_DEF) {
        return;
    }
    WithAttributesPath globalAttributesPath;
    final Def_Type def = (Def_Type) owner;
    final Group nearest_group = def.getParentGroup();
    if (nearest_group == null) {
        // no group, use the module
        Module myModule = myScope.getModuleScope();
        globalAttributesPath = ((TTCN3Module) myModule).getAttributePath();
    } else {
        globalAttributesPath = nearest_group.getAttributePath();
    }
    if (globalAttributesPath != null) {
        // process all global variants, not just the closest group
        final List<SingleWithAttribute> realAttributes = globalAttributesPath.getRealAttributes(timestamp);
        for (int i = 0; i < realAttributes.size(); i++) {
            final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
            if (singleWithAttribute.getAttributeType() == Attribute_Type.Variant_Attribute) {
                checkThisVariant(timestamp, singleWithAttribute, true);
            }
        }
    }
    // check local variant attributes second, so they overwrite global ones if they
    // conflict with each other
    final WithAttributesPath attributePath = getAttributePath();
    if (attributePath != null) {
        final MultipleWithAttributes multipleWithAttributes = attributePath.getAttributes();
        if (multipleWithAttributes != null) {
            for (int i = 0; i < multipleWithAttributes.getNofElements(); i++) {
                final SingleWithAttribute singleWithAttribute = multipleWithAttributes.getAttribute(i);
                if (singleWithAttribute.getAttributeType() == Attribute_Type.Variant_Attribute) {
                    final Qualifiers qualifiers = singleWithAttribute.getQualifiers();
                    if (qualifiers != null && qualifiers.getNofQualifiers() > 0) {
                        for (int j = 0; j < qualifiers.getNofQualifiers(); j++) {
                            final Qualifier qualifier = qualifiers.getQualifierByIndex(j);
                            final List<ISubReference> fieldsOrArrays = new ArrayList<ISubReference>();
                            for (int k = 0; k < qualifier.getNofSubReferences(); k++) {
                                fieldsOrArrays.add(qualifier.getSubReferenceByIndex(k));
                            }
                            final Reference reference = new Reference(null, fieldsOrArrays);
                            final IType type = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_CONSTANT, false);
                            if (type != null) {
                                if (type.getMyScope() != myScope) {
                                    qualifier.getLocation().reportSemanticWarning("Variant attribute is ignored, because it refers to a type from a different type definition");
                                } else {
                                    type.checkThisVariant(timestamp, singleWithAttribute, false);
                                }
                            }
                        }
                    } else {
                        checkThisVariant(timestamp, singleWithAttribute, false);
                    }
                }
            }
        }
    }
    // check the coding attributes set by the variants
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    checkCodingAttributes(timestamp, chain);
    chain.release();
}
Also used : WithAttributesPath(org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath) Group(org.eclipse.titan.designer.AST.TTCN3.definitions.Group) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) MultipleWithAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes) Qualifier(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 3 with Def_Type

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.

the class FormalParameterList method checkActualParameterList.

/**
 * Check if a list of parsed actual parameters is semantically correct
 * according to a list of formal parameters (the called entity).
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param parsedParameters
 *                the parsed actual parameters (may contain named, and
 *                unnamed parts too).
 * @param actualParameters
 *                the list of actual parameters returned for later
 *                usage.
 *
 * @return true if a semantic error was found, false otherwise
 */
public final boolean checkActualParameterList(final CompilationTimeStamp timestamp, final ParsedActualParameters parsedParameters, final ActualParameterList actualParameters) {
    parsedParameters.setFormalParList(this);
    checkUniqueness(timestamp);
    boolean isErroneous = false;
    final TemplateInstances unnamed = parsedParameters.getInstances();
    final NamedParameters named = parsedParameters.getNamedParameters();
    int nofLocated = unnamed.getNofTis();
    final Map<FormalParameter, Integer> formalParameterMap = new HashMap<FormalParameter, Integer>();
    for (int i = 0, size = parameters.size(); i < size; i++) {
        formalParameterMap.put(parameters.get(i), Integer.valueOf(i));
    }
    final TemplateInstances finalUnnamed = new TemplateInstances(unnamed);
    for (int i = 0, size = named.getNofParams(); i < size; i++) {
        final NamedParameter namedParameter = named.getParamByIndex(i);
        if (parameterMap != null && parameterMap.containsKey(namedParameter.getName().getName())) {
            final FormalParameter formalParameter = parameterMap.get(namedParameter.getName().getName());
            final int isAt = formalParameterMap.get(formalParameter);
            if (isAt >= nofLocated) {
                for (; nofLocated < isAt; nofLocated++) {
                    final NotUsed_Template temp = new NotUsed_Template();
                    if (!parameters.get(nofLocated).hasDefaultValue()) {
                        temp.setIsErroneous(true);
                    }
                    final TemplateInstance instance = new TemplateInstance(null, null, temp);
                    instance.setLocation(parsedParameters.getLocation());
                    finalUnnamed.addTemplateInstance(instance);
                }
                finalUnnamed.addTemplateInstance(namedParameter.getInstance());
                nofLocated++;
            } else {
                isErroneous = true;
                if (isAt >= unnamed.getNofTis()) {
                    namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is out of order", namedParameter.getName().getDisplayName()));
                } else {
                    namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is assigned more than once", namedParameter.getName().getDisplayName()));
                }
            }
        } else {
            String name;
            switch(myDefinition.getAssignmentType()) {
                case A_TYPE:
                    switch(((Def_Type) myDefinition).getType(timestamp).getTypetype()) {
                        case TYPE_FUNCTION:
                            name = "Function reference";
                            break;
                        case TYPE_ALTSTEP:
                            name = "Altstep reference";
                            break;
                        case TYPE_TESTCASE:
                            name = "Testcase reference";
                            break;
                        default:
                            name = "";
                            break;
                    }
                    break;
                default:
                    name = myDefinition.getAssignmentName();
                    break;
            }
            isErroneous = true;
            namedParameter.getLocation().reportSemanticError(MessageFormat.format("{0} `{1}'' has no formal parameter with name `{2}''", name, myDefinition.getFullName(), namedParameter.getName().getDisplayName()));
        }
    }
    if (isErroneous) {
        return false;
    }
    finalUnnamed.setLocation(parsedParameters.getLocation());
    return checkActualParameterList(timestamp, finalUnnamed, actualParameters);
}
Also used : NamedParameters(org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameters) HashMap(java.util.HashMap) NamedParameter(org.eclipse.titan.designer.AST.TTCN3.templates.NamedParameter) TemplateInstances(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstances) NotUsed_Template(org.eclipse.titan.designer.AST.TTCN3.templates.NotUsed_Template) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)

Example 4 with Def_Type

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.

the class Port_Utility method checkSignatureReference.

/**
 * Checks a reference to see if it really references a valid signature
 * type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param reference
 *                the reference to check.
 *
 * @return the referenced signature type, or null if there were
 *         problems.
 */
public static Signature_Type checkSignatureReference(final CompilationTimeStamp timestamp, final Reference reference) {
    if (reference == null) {
        return null;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return null;
    }
    if (!Assignment_type.A_TYPE.semanticallyEquals(assignment.getAssignmentType())) {
        reference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED1, assignment.getAssignmentName()));
        return null;
    }
    IType result = ((Def_Type) assignment).getType(timestamp);
    if (result == null) {
        return null;
    }
    result = result.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (result == null) {
        return null;
    }
    result = result.getTypeRefdLast(timestamp);
    switch(result.getTypetype()) {
        case TYPE_SIGNATURE:
            return (Signature_Type) result;
        case TYPE_PORT:
            reference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED2, result.getTypename()));
            return null;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXPECTED3, result.getTypename()));
            return null;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 5 with Def_Type

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method createFileChange.

private Change createFileChange(final IFile toVisit) {
    if (toVisit == null) {
        return null;
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
    final Module module = sourceParser.containedModule(toVisit);
    if (module == null) {
        return null;
    }
    if (selection instanceof Def_Type) {
        final Def_Type df = (Def_Type) selection;
        type = df.getType(CompilationTimeStamp.getBaseTimestamp());
    }
    final DefinitionVisitor vis = new DefinitionVisitor(type);
    module.accept(vis);
    final NavigableSet<ILocateableNode> nodes = vis.getLocations();
    if (nodes.isEmpty()) {
        return null;
    }
    final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
    final MultiTextEdit rootEdit = new MultiTextEdit();
    try {
        final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, rootEdit);
        job1.join();
    } catch (InterruptedException ie) {
        ErrorReporter.logExceptionStackTrace(ie);
    } catch (CoreException ce) {
        ErrorReporter.logError("InsertFieldRefactoring/CreateChange.createFileChange(): " + "CoreException while calculating edit locations. ");
        ErrorReporter.logExceptionStackTrace(ce);
    }
    if (!rootEdit.hasChildren()) {
        return null;
    }
    tfc.setEdit(rootEdit);
    return tfc;
}
Also used : Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) CoreException(org.eclipse.core.runtime.CoreException) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Module(org.eclipse.titan.designer.AST.Module) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Aggregations

Def_Type (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type)9 Type (org.eclipse.titan.designer.AST.Type)3 ArrayList (java.util.ArrayList)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 ILocateableNode (org.eclipse.titan.designer.AST.ILocateableNode)2 MultipleWithAttributes (org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes)2 Qualifier (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier)2 Qualifiers (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)2 SingleWithAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)2 WithAttributesPath (org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath)2 Def_Extfunction (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction)2 FormalParameter (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter)2 Group (org.eclipse.titan.designer.AST.TTCN3.definitions.Group)2 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)2 CharString_Type (org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type)2 Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)2 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)2 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)2 SetOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type)2 TTCN3_Enumerated_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type)2