Search in sources :

Example 21 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class Set_Value method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 * generate_code_init_se in the compiler
 */
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    IType governor = myGovernor;
    if (governor == null) {
        governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    }
    if (governor == null) {
        governor = myLastSetGovernor;
    }
    final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    int nofComps = 0;
    switch(type.getTypetype()) {
        case TYPE_TTCN3_SET:
            nofComps = ((TTCN3_Set_Type) type).getNofComponents();
            break;
        case TYPE_ASN1_SET:
            nofComps = ((ASN1_Set_Type) type).getNofComponents(CompilationTimeStamp.getBaseTimestamp());
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
    }
    if (nofComps == 0) {
        aData.addBuiltinTypeImport("TitanNull_Type");
        source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
        return source;
    }
    CompField compField = null;
    for (int i = 0; i < nofComps; i++) {
        switch(type.getTypetype()) {
            case TYPE_TTCN3_SET:
                compField = ((TTCN3_Set_Type) type).getComponentByIndex(i);
                break;
            case TYPE_ASN1_SET:
                compField = ((ASN1_Set_Type) type).getComponentByIndex(i);
                break;
            default:
                ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
        }
        final Identifier fieldName = compField.getIdentifier();
        IValue fieldValue;
        if (hasComponentWithName(fieldName)) {
            fieldValue = getComponentByName(fieldName).getValue();
            if (Value_type.NOTUSED_VALUE.equals(fieldValue.getValuetype())) {
                continue;
            } else if (Value_type.OMIT_VALUE.equals(fieldValue.getValuetype())) {
                fieldValue = null;
            }
        } else // TODO add support for asn default values when needed
        {
            continue;
        }
        final String javaGetterName = FieldSubReference.getJavaGetterName(fieldName.getName());
        if (fieldValue != null) {
            // TODO handle the case when temporary reference is needed
            final StringBuilder embeddedName = new StringBuilder();
            embeddedName.append(name);
            embeddedName.append(".get");
            embeddedName.append(javaGetterName);
            embeddedName.append("()");
            if (compField.isOptional()) /*&& fieldValue.isCompound() */
            {
                embeddedName.append(".get()");
            }
            // TODO add extra handling for optional fields
            fieldValue.generateCodeInit(aData, source, embeddedName.toString());
        } else {
            aData.addBuiltinTypeImport("Base_Template.template_sel");
            source.append(MessageFormat.format("{0}.get{1}().assign(template_sel.OMIT_VALUE);\n", name, javaGetterName));
        }
    }
    return source;
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) IType(org.eclipse.titan.designer.AST.IType)

Example 22 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class UStringValueConstraint method toString.

@Override
public /**
 * {@inheritDoc}
 */
void toString(final StringBuilder sb) {
    sb.append('(');
    boolean needComma = false;
    for (UniversalCharstring str : values) {
        if (needComma) {
            sb.append(", ");
        }
        sb.append('\"').append(str.getStringRepresentation()).append('\"');
        needComma = true;
    }
    sb.append(')');
}
Also used : UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)

Example 23 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class ASN1_Enumerated_Type method check.

@Override
public final /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (null != myScope) {
        final Module module = myScope.getModuleScope();
        if (null != module) {
            if (module.getSkippedFromSemanticChecking()) {
                return;
            }
        }
    }
    isErroneous = false;
    if (null == enumerations) {
        parseBlockEnumeration();
    }
    if (isErroneous || null == enumerations) {
        return;
    }
    /* check duplications and set missing values */
    firstUnused = Integer.valueOf(0);
    nameMap = new HashMap<String, EnumItem>();
    final Map<Integer, EnumItem> valueMap = new HashMap<Integer, EnumItem>();
    if (null != enumerations.enumItems1) {
        final List<EnumItem> enumItems = enumerations.enumItems1.getItems();
        for (EnumItem item : enumItems) {
            checkEnumItem(timestamp, item, false, valueMap);
        }
        // set the default values
        while (valueMap.containsKey(firstUnused)) {
            firstUnused++;
        }
        for (EnumItem item : enumItems) {
            if (null == item.getValue() || !item.isOriginal()) {
                final Integer_Value tempValue = new Integer_Value(firstUnused.longValue());
                tempValue.setLocation(item.getLocation());
                item.setValue(tempValue);
                valueMap.put(firstUnused, item);
                while (valueMap.containsKey(firstUnused)) {
                    firstUnused++;
                }
            }
        }
    }
    if (null != enumerations.enumItems2) {
        final List<EnumItem> enumItems = enumerations.enumItems2.getItems();
        for (EnumItem item : enumItems) {
            checkEnumItem(timestamp, item, true, valueMap);
        }
    }
    if (null != constraints) {
        constraints.check(timestamp);
    }
    if (myScope != null) {
        checkEncode(timestamp);
        checkVariants(timestamp);
    }
}
Also used : HashMap(java.util.HashMap) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Module(org.eclipse.titan.designer.AST.Module) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)

Example 24 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class All_From_Template method getNofValues.

/**
 * Gets the number of values If the value is type of SEQUENCEOF_VALUE or
 * type of SETOF_VALUE then returns their size otherwise returns 1
 */
private int getNofValues(final IValue value, final CompilationTimeStamp timestamp) {
    int result = 0;
    if (value == null) {
        return result;
    }
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue lastValue = value.getValueRefdLast(timestamp, chain);
    chain.release();
    if (lastValue.getIsErroneous(timestamp)) {
        return result;
    }
    if (Value_type.SEQUENCEOF_VALUE.equals(lastValue.getValuetype())) {
        final SequenceOf_Value lvalue = (SequenceOf_Value) lastValue;
        result = lvalue.getNofComponents();
        return result;
    } else if (Value_type.SETOF_VALUE.equals(lastValue.getValuetype())) {
        final SetOf_Value svalue = (SetOf_Value) lastValue;
        result = svalue.getNofComponents();
        return result;
    } else {
        // this value is calculated as 1 in an all from
        return 1;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_Value)

Example 25 with Values

use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.

the class All_From_Template method getNofTemplatesNotAnyornone.

/**
 * Calculates the number of list members which are not the any or none
 * symbol.
 *
 * @return the number calculated.
 */
public int getNofTemplatesNotAnyornone(final CompilationTimeStamp timestamp) {
    int result = 0;
    if (allFrom == null) {
        ErrorReporter.INTERNAL_ERROR();
        return result;
    }
    if (!Template_type.SPECIFIC_VALUE.equals(allFrom.getTemplatetype())) {
        allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
        allFrom.setIsErroneous(true);
        return result;
    }
    if (!((SpecificValue_Template) allFrom).isReference()) {
        allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
        allFrom.setIsErroneous(true);
        return result;
    }
    // isReference branch:
    final Reference reference = ((SpecificValue_Template) allFrom).getReference();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        allFrom.getLocation().reportSemanticError("Assignment not found");
        allFrom.setIsErroneous(true);
        return result;
    }
    ITTCN3Template body = null;
    switch(assignment.getAssignmentType()) {
        case A_TEMPLATE:
            body = ((Def_Template) assignment).getTemplate(timestamp);
            break;
        case A_VAR_TEMPLATE:
            body = ((Def_Var_Template) assignment).getInitialValue();
            break;
        case A_CONST:
            final IValue value = ((Def_Const) assignment).getValue();
            return getNofValues(value, timestamp);
        case A_MODULEPAR:
            final IValue mvalue = ((Def_ModulePar) assignment).getDefaultValue();
            return getNofValues(mvalue, timestamp);
        case A_MODULEPAR_TEMPLATE:
            body = ((Def_ModulePar_Template) assignment).getDefaultTemplate();
            break;
        default:
            return result;
    }
    if (body == null) {
        ErrorReporter.INTERNAL_ERROR();
        return result;
    }
    if (!Template_type.TEMPLATE_LIST.equals(body.getTemplatetype())) {
        allFrom.getLocation().reportSemanticError("Template must be a record of or a set of values");
        allFrom.setIsErroneous(true);
        return result;
    }
    result = ((Template_List) body).getNofTemplatesNotAnyornone(timestamp);
    return result;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)18 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)11 Identifier (org.eclipse.titan.designer.AST.Identifier)9 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)9 HashMap (java.util.HashMap)8 IType (org.eclipse.titan.designer.AST.IType)6 SequenceOf_Value (org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value)5 Value (org.eclipse.titan.designer.AST.Value)5 BigInteger (java.math.BigInteger)4 ArrayList (java.util.ArrayList)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Module (org.eclipse.titan.designer.AST.Module)3 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)3 ReferenceChain (org.eclipse.titan.designer.AST.ReferenceChain)3 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)3 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)3 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)3 List (java.util.List)2 Named_Integer_Value (org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value)2 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2