Search in sources :

Example 1 with Referenced_Type

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

the class Def_Type_Visit_Handler method visitDefTypeChildrenNodes.

public void visitDefTypeChildrenNodes(IVisitableNode node) {
    if (node instanceof Def_Port) {
        Def_Port port = (Def_Port) node;
        componentPortNames.add(port.getIdentifier().toString());
    }
    if (node instanceof Def_Var) {
        Def_Var var = (Def_Var) node;
        componentVarNames.add(var.getIdentifier().toString());
        if (var.getType(compilationCounter) instanceof Integer_Type) {
            componentVarTypes.add("INTEGER");
        }
    }
    if (waitForCompReference && (node instanceof Reference)) {
        componentPortTypes.add(((Reference) node).getId().toString());
    }
    if (waitForSetOfFieldType) {
        if (node instanceof Reference) {
            setOfFieldType = node.toString();
            myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType);
            waitForSetOfFieldType = false;
        } else if (node instanceof Type && !(node instanceof Referenced_Type) && !(node instanceof SetOf_Type)) {
            Type type = (Type) node;
            setOfFieldType = TypeMapper.map(type.getTypename());
            myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType);
            waitForSetOfFieldType = false;
        }
    }
    if (waitForRecordOfFieldType) {
        if (node instanceof Reference) {
            recordOfFieldType = node.toString();
            myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType);
            waitForRecordOfFieldType = false;
        } else if (node instanceof Type && !(node instanceof Referenced_Type) && !(node instanceof SequenceOf_Type)) {
            Type type = (Type) node;
            recordOfFieldType = TypeMapper.map(type.getTypename());
            myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType);
            waitForRecordOfFieldType = false;
        }
    }
    if (node instanceof CompField) {
        // component
        CompField compFieldNode = (CompField) node;
        if (compFieldNode.getType() instanceof Referenced_Type) {
            compFieldTypes.add(((Referenced_Type) compFieldNode.getType()).getReference().getId().toString());
        } else {
            compFieldTypes.add(myASTVisitor.cutModuleNameFromBeginning(compFieldNode.getType().getTypename()));
        }
        compFieldNames.add(compFieldNode.getIdentifier().toString());
    }
    if (node instanceof Charstring_Value) {
        // charstring
        Charstring_Value singleValuedNode = (Charstring_Value) node;
        charstringValue = singleValuedNode.getValue();
    }
    if (node instanceof Integer_Value) {
        String value = ((Integer_Value) node).toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        expressionValue.add("new INTEGER(\"" + value + "\")");
    }
    if (node instanceof Real_Value) {
        String value = ((Real_Value) node).toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        if (value.equals("-Infinity") || value.equals("Infinity")) {
            value = "null";
        }
        expressionValue.add(value);
    }
    if (node instanceof Undefined_LowerIdentifier_Value) {
        String value = ((Undefined_LowerIdentifier_Value) node).getIdentifier().toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        expressionValue.add(value);
    }
    if (node instanceof EnumerationItems) {
        for (int i = 0; i < ((EnumerationItems) node).getItems().size(); i++) {
            enumItems.add(((EnumerationItems) node).getItems().get(i).getId().toString());
            if (((EnumerationItems) node).getItems().get(i).getValue() != null) {
                enumItemValues.add(((EnumerationItems) node).getItems().get(i).getValue().toString());
            } else {
                enumItemValues.add(null);
            }
        }
    }
    if (waitingForPortAttriburtes && (node instanceof Referenced_Type)) {
        isPortTypeAReferencedType = true;
    }
    if (waitingForPortAttriburtes && (node instanceof PortTypeBody)) {
        PortTypeBody body = (PortTypeBody) node;
        int inCount = body.getInMessages().getNofTypes();
        int outCount = body.getOutMessage().getNofTypes();
        for (int i = 0; i < inCount; i++) {
            inMessageName.add(myASTVisitor.cutModuleNameFromBeginning(body.getInMessages().getTypeByIndex(i).getTypename()));
        }
        for (int i = 0; i < outCount; i++) {
            outMessageName.add(myASTVisitor.cutModuleNameFromBeginning(body.getOutMessage().getTypeByIndex(i).getTypename()));
        }
        int shorterListSize = inMessageName.size() <= outMessageName.size() ? inMessageName.size() : outMessageName.size();
        // if inout delete from both lists and add to inout
        for (int i = 0; i < inMessageName.size(); i++) {
            for (int j = 0; j < outMessageName.size(); j++) {
                if (inMessageName.get(i).equals(outMessageName.get(j))) {
                    inOutMessageName.add(inMessageName.get(i));
                    inMessageName.remove(i);
                    if (j == (outMessageName.size() - 1)) {
                        i--;
                    }
                    outMessageName.remove(j);
                    j--;
                }
            }
        }
        myASTVisitor.portNamePortTypeHashMap.put(currentPortName, body.getTestportType().toString());
        portTypeList.add(body.getTestportType().toString());
    }
}
Also used : Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Reference(org.eclipse.titan.designer.AST.Reference) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Def_Port(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) 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) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) EnumerationItems(org.eclipse.titan.designer.AST.TTCN3.types.EnumerationItems) PortTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 2 with Referenced_Type

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

the class Done_Statement method generateCodeExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression) {
    aData.addCommonLibraryImport("TTCN_Runtime");
    aData.addBuiltinTypeImport("TitanComponent");
    if (componentreference != null) {
        if (doneMatch != null) {
            // value returning done
            // figure out what type the done() function belongs to
            IType t = doneMatch.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
            if (t == null) {
                ErrorReporter.INTERNAL_ERROR("Encountered a done with unknown governor `" + getFullName() + "''");
                return;
            }
            while (t instanceof Referenced_Type && !t.hasDoneAttribute()) {
                final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                t = ((IReferencingType) t).getTypeRefd(CompilationTimeStamp.getBaseTimestamp(), refChain);
                refChain.release();
            }
            if (!t.hasDoneAttribute()) {
                ErrorReporter.INTERNAL_ERROR("Encountered a done return type without done attribute `" + getFullName() + "''");
                return;
            }
            // determine whether the done() function is in the same module
            final Module t_module = t.getMyScope().getModuleScope();
            if (t_module != myStatementBlock.getModuleScope()) {
                expression.expression.append(MessageFormat.format("{0}.", t_module.getIdentifier().getName()));
            }
            expression.expression.append("done(");
            componentreference.generateCodeExpression(aData, expression, true);
            expression.expression.append(", ");
            // FIXME handle decoded match
            doneMatch.generateCode(aData, expression, Restriction_type.TR_NONE);
        // expression.expression.append(", ");
        // FIXME handle value redirection
        } else {
            // simple done
            componentreference.generateCodeExpressionMandatory(aData, expression, true);
            expression.expression.append(".done(");
        }
        // FIXME handle index redirection
        expression.expression.append(')');
    } else if (isAny) {
        // any component.done
        expression.expression.append("TTCN_Runtime.component_done(TitanComponent.ANY_COMPREF)");
    } else {
        // all component.done
        expression.expression.append("TTCN_Runtime.component_done(TitanComponent.ALL_COMPREF)");
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Module(org.eclipse.titan.designer.AST.Module) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 3 with Referenced_Type

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

the class TableConstraint method getOpenTypeAlternativeName.

// Original titan.core version: t_type->get_otaltname(is_strange);
private Identifier getOpenTypeAlternativeName(final CompilationTimeStamp timestamp, final Type type, final AtomicBoolean isStrange) {
    StringBuffer sb = new StringBuffer();
    // TODO:  if (is_tagged() || is_constrained() || hasRawAttrs()) {
    if (!type.getIsErroneous(timestamp) && type.isConstrained()) {
        sb.append(type.getGenNameOwn());
        isStrange.set(true);
    } else if (!type.getIsErroneous(timestamp) && type instanceof Referenced_Type) {
        Reference t_ref = ((Referenced_Type) type).getReference();
        if (t_ref != null) {
            final Identifier id = t_ref.getId();
            final String dn = id.getDisplayName();
            int i = dn.indexOf('.');
            if (i >= 0 && i < dn.length()) {
                // id is not regular because t_ref is a parameterized reference
                sb.append(id.getName());
                isStrange.set(true);
            } else {
                Assignment as = t_ref.getRefdAssignment(timestamp, true);
                if (as == null) {
                    return null;
                }
                Scope assScope = as.getMyScope();
                if (assScope.getParentScope() == assScope.getModuleScope()) {
                    sb.append(id.getName());
                    isStrange.set(false);
                } else {
                    // t_ref is a dummy reference in a parameterized assignment
                    // (i.e. it points to a parameter assignment of an instantiation)
                    // perform the same examination recursively on the referenced type
                    // (which is the actual parameter)
                    IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    IType referencedType = ((Referenced_Type) type).getTypeRefd(timestamp, chain);
                    chain.release();
                    return getOpenTypeAlternativeName(timestamp, (Type) referencedType, isStrange);
                }
            }
        } else {
            // the type comes from an information object [class]
            // examine the referenced type recursively
            IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            IType referencedType = ((Referenced_Type) type).getTypeRefd(timestamp, chain);
            chain.release();
            return getOpenTypeAlternativeName(timestamp, (Type) referencedType, isStrange);
        }
    } else {
        Identifier tmpId1 = new Identifier(Identifier_type.ID_NAME, type.getFullName());
        String s = tmpId1.getDisplayName();
        // module name will be cut off:
        if (s.startsWith("@") && s.indexOf('.') > 0) {
            s = s.substring(s.indexOf('.') + 1);
        }
        Identifier tmpId2 = new Identifier(Identifier_type.ID_ASN, s);
        sb.append(tmpId2.getTtcnName());
    }
    // conversion to lower case initial:
    sb.replace(0, 1, sb.substring(0, 1).toLowerCase());
    // trick:
    Identifier tmpId = new Identifier(Identifier_type.ID_NAME, sb.toString());
    return new Identifier(Identifier_type.ID_ASN, tmpId.getAsnName());
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) FieldSetting_Type(org.eclipse.titan.designer.AST.ASN1.Object.FieldSetting_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) ObjectClassField_Type(org.eclipse.titan.designer.AST.ASN1.types.ObjectClassField_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) Reference(org.eclipse.titan.designer.AST.Reference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 4 with Referenced_Type

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

the class Undefined_Assignment_OS_or_VS method classifyAssignment.

@Override
protected void classifyAssignment(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    final boolean newChain = null == referenceChain;
    IReferenceChain temporalReferenceChain;
    if (newChain) {
        temporalReferenceChain = ReferenceChain.getInstance(CIRCULARASSIGNMENTCHAIN, true);
    } else {
        temporalReferenceChain = referenceChain;
        temporalReferenceChain.markState();
    }
    realAssignment = null;
    if (temporalReferenceChain.add(this)) {
        if (null != reference) {
            reference.setMyScope(getMyScope());
            if (!reference.refersToSettingType(timestamp, Setting_type.S_ERROR, temporalReferenceChain)) {
                if (identifier.isvalidAsnObjectSetReference() && reference.refersToSettingType(timestamp, Setting_type.S_OC, temporalReferenceChain)) {
                    final ObjectClass_refd oc = new ObjectClass_refd(reference);
                    oc.setLocation(reference.getLocation());
                    realAssignment = new ObjectSet_Assignment(identifier, assPard, oc, newObjectSetDefinitionInstance());
                // assPard = null;
                // left = null;
                // right = null;
                // asstype = A_OS;
                } else if (identifier.isvalidAsnValueSetReference() && (reference.refersToSettingType(timestamp, Setting_type.S_T, temporalReferenceChain) || reference.refersToSettingType(timestamp, Setting_type.S_VS, temporalReferenceChain))) {
                    final Referenced_Type type = new Referenced_Type(reference);
                    type.setLocation(reference.getLocation());
                    realAssignment = newValueSetAssignmentInstance(type);
                // left = null;
                // right = null;
                // asstype = A_VS;
                }
            }
        }
    }
    if (null == realAssignment) {
        location.reportSemanticError(UNRECOGNISABLEASSIGNMENT);
        isErroneous = true;
    } else {
        realAssignment.setLocation(location);
        realAssignment.setMyScope(myScope);
        realAssignment.setRightScope(rightScope);
        realAssignment.setFullNameParent(this);
    }
    if (newChain) {
        temporalReferenceChain.release();
    } else {
        temporalReferenceChain.previousState();
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ObjectClass_refd(org.eclipse.titan.designer.AST.ASN1.Object.ObjectClass_refd) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)

Example 5 with Referenced_Type

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

the class Undefined_Assignment_T_or_OC method classifyAssignment.

@Override
protected void classifyAssignment(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    final boolean newChain = null == referenceChain;
    IReferenceChain temporalReferenceChain;
    if (newChain) {
        temporalReferenceChain = ReferenceChain.getInstance(CIRCULARASSIGNMENTCHAIN, true);
    } else {
        temporalReferenceChain = referenceChain;
        temporalReferenceChain.markState();
    }
    realAssignment = null;
    if (temporalReferenceChain.add(this)) {
        reference.setMyScope(rightScope);
        if (identifier.isvalidAsnObjectClassReference() && reference.refersToSettingType(timestamp, Setting_type.S_OC, temporalReferenceChain)) {
            final ObjectClass_refd oc = new ObjectClass_refd(reference);
            oc.setLocation(reference.getLocation());
            realAssignment = new ObjectClass_Assignment(identifier, assPard, oc);
        // assPard = null;
        // asstype = Assignment.A_OC;
        } else if (identifier.isvalidAsnTyperef() && (reference.refersToSettingType(timestamp, Setting_type.S_T, temporalReferenceChain) || reference.refersToSettingType(timestamp, Setting_type.S_VS, temporalReferenceChain))) {
            final Referenced_Type type = new Referenced_Type(reference);
            type.setLocation(reference.getLocation());
            realAssignment = new Type_Assignment(identifier, assPard, type);
        // assPard = null;
        // asstype = A_TYPE;
        }
    }
    if (null == realAssignment) {
        location.reportSemanticError(UNRECOGNISABLEASSIGNMENT);
        isErroneous = true;
    } else {
        realAssignment.setLocation(location);
        realAssignment.setMyScope(myScope);
        realAssignment.setRightScope(rightScope);
        realAssignment.setFullNameParent(this);
    }
    if (newChain) {
        temporalReferenceChain.release();
    } else {
        temporalReferenceChain.previousState();
    }
}
Also used : IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ObjectClass_refd(org.eclipse.titan.designer.AST.ASN1.Object.ObjectClass_refd) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)

Aggregations

Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)11 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)7 IType (org.eclipse.titan.designer.AST.IType)7 Identifier (org.eclipse.titan.designer.AST.Identifier)5 IValue (org.eclipse.titan.designer.AST.IValue)4 Reference (org.eclipse.titan.designer.AST.Reference)4 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)4 ArrayList (java.util.ArrayList)3 ObjectClass_refd (org.eclipse.titan.designer.AST.ASN1.Object.ObjectClass_refd)3 Type (org.eclipse.titan.designer.AST.Type)3 Value (org.eclipse.titan.designer.AST.Value)3 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 ASN1_Set_Seq_Choice_BaseType (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Seq_Choice_BaseType)2 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)2 Undefined_Block_Value (org.eclipse.titan.designer.AST.ASN1.values.Undefined_Block_Value)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)2 Scope (org.eclipse.titan.designer.AST.Scope)2