Search in sources :

Example 81 with Assignment

use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.

the class DecodeExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    aData.addBuiltinTypeImport("TitanOctetString");
    aData.addCommonLibraryImport("TTCN_EncDec");
    aData.addCommonLibraryImport("AdditionalFunctions");
    final ExpressionStruct expression1 = new ExpressionStruct();
    final ExpressionStruct expression2 = new ExpressionStruct();
    reference1.generateCode(aData, expression1);
    reference2.generateCode(aData, expression2);
    final Assignment tempAssignment = reference2.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    final IType type = tempAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
    final IType fieldType = type.getFieldType(CompilationTimeStamp.getBaseTimestamp(), reference2, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (expression1.preamble.length() > 0) {
        expression.preamble.append(expression1.preamble);
    }
    if (expression2.preamble.length() > 0) {
        expression.preamble.append(expression2.preamble);
    }
    final Scope scope = reference2.getMyScope();
    final boolean isOptional = fieldType.fieldIsOptional(reference2.getSubreferences());
    final ExpressionStruct expression3 = new ExpressionStruct();
    // TODO add support for 5th parameter
    expression3.expression.append(MessageFormat.format("{0}_default_coding", fieldType.getGenNameDefaultCoding(aData, expression.expression, scope)));
    final String bufferID = aData.getTemporaryVariableName();
    final String returnValueID = aData.getTemporaryVariableName();
    // TOOD add handling for non-built-in encoding
    expression.preamble.append("TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_WARNING);\n");
    expression.preamble.append("TTCN_EncDec.clear_error();\n");
    expression.preamble.append(MessageFormat.format("TitanOctetString {0} = new TitanOctetString(AdditionalFunctions.bit2oct({1}));\n", bufferID, expression1.expression));
    expression.preamble.append(MessageFormat.format("TitanInteger {0} = new TitanInteger({1}_decoder({2}, {3}{4}, {5}));\n", returnValueID, fieldType.getGenNameCoder(aData, expression.expression, scope), bufferID, expression2.expression, isOptional ? ".get()" : "", expression3.expression));
    expression.preamble.append(MessageFormat.format("if ({0}.operatorEquals(0)) '{'\n", returnValueID));
    expression.preamble.append(MessageFormat.format("{0}.assign(AdditionalFunctions.oct2bit({1}));\n", expression1.expression, bufferID));
    expression.preamble.append("}\n");
    // TOOD add handling for non-built-in encoding
    expression.preamble.append("TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_DEFAULT);\n");
    expression.preamble.append("TTCN_EncDec.clear_error();\n");
    expression.expression.append(returnValueID);
    if (expression1.postamble.length() > 0) {
        expression.postamble.append(expression1.postamble);
    }
    if (expression2.postamble.length() > 0) {
        expression.postamble.append(expression2.postamble);
    }
    if (expression3.postamble.length() > 0) {
        expression.postamble.append(expression3.postamble);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Scope(org.eclipse.titan.designer.AST.Scope) IType(org.eclipse.titan.designer.AST.IType)

Example 82 with Assignment

use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.

the class DecodeExpression method checkFirstExpressionOperand.

private void checkFirstExpressionOperand(final CompilationTimeStamp timestamp) {
    final Assignment temporalAssignment = reference1.getRefdAssignment(timestamp, true);
    if (temporalAssignment == null) {
        setIsErroneous(true);
        return;
    }
    switch(temporalAssignment.getAssignmentType()) {
        case A_CONST:
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_TEMPLATE:
            reference1.getLocation().reportSemanticError(MessageFormat.format("Reference to `{0}'' cannot be used as the first operand of the `decvalue'' operation", temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            break;
        case A_VAR:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
            break;
        case A_VAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                final Referenced_Template template = new Referenced_Template(reference1);
                template.setMyScope(getMyScope());
                template.setFullNameParent(new BridgingNamedNode(this, ".<operand>"));
                final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
                if (!Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype()) && last != template) {
                    reference1.getLocation().reportSemanticError(MessageFormat.format("Specific value template was expected instead of `{0}''", last.getTemplateTypeName()));
                    setIsErroneous(true);
                    return;
                }
                break;
            }
        default:
            reference1.getLocation().reportSemanticError(MessageFormat.format("Reference to `{0}'' cannot be used as the first operand of the `decvalue' operation", temporalAssignment.getAssignmentName()));
            setIsErroneous(true);
            return;
    }
    final IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference1, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (temporalType == null) {
        setIsErroneous(true);
        return;
    }
    if (temporalType.getTypeRefdLast(timestamp).getTypetype() != Type_type.TYPE_BITSTRING) {
        if (!isErroneous) {
            reference1.getLocation().reportSemanticError(OPERANDERROR1);
            setIsErroneous(true);
        }
        return;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType)

Example 83 with Assignment

use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.

the class ImportModule method addDeclaration.

/**
 * Adds the imported module or definitions contained in it, to the list
 * declaration proposals.
 *
 * @param declarationCollector
 *                the declaration collector.
 * @param targetModuleId
 *                the identifier of the module where the declaration
 *                should be inserted into.
 */
@Override
public /**
 * {@inheritDoc}
 */
void addDeclaration(final DeclarationCollector declarationCollector, final Identifier targetModuleId) {
    final Module savedReferredModule = referredModule;
    if (savedReferredModule != null) {
        final Assignments assignments = savedReferredModule.getAssignments();
        for (int i = 0; i < assignments.getNofAssignments(); i++) {
            final Assignment temporalAssignment = assignments.getAssignmentByIndex(i);
            if (savedReferredModule.isVisible(CompilationTimeStamp.getBaseTimestamp(), targetModuleId, temporalAssignment)) {
                temporalAssignment.addDeclaration(declarationCollector, 0);
            }
        }
        final Identifier moduleId = declarationCollector.getReference().getModuleIdentifier();
        final List<ISubReference> subrefs = declarationCollector.getReference().getSubreferences();
        if (moduleId == null && subrefs.size() == 1 && identifier.getName().equals(subrefs.get(0).getId().getName())) {
            declarationCollector.addDeclaration(savedReferredModule.getIdentifier().getDisplayName(), savedReferredModule.getIdentifier().getLocation(), (Scope) null);
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) Assignments(org.eclipse.titan.designer.AST.Assignments) Module(org.eclipse.titan.designer.AST.Module)

Example 84 with Assignment

use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.

the class ImportModule method importAssignment.

@Override
public /**
 * {@inheritDoc}
 */
Assignment importAssignment(final CompilationTimeStamp timestamp, final ModuleImportationChain referenceChain, final Identifier moduleId, final Reference reference, final List<ModuleImportation> usedImports) {
    // endpoint of an importation chain.
    if (referredModule == null) {
        return null;
    }
    final Assignment result = referredModule.importAssignment(timestamp, moduleId, reference);
    if (result != null) {
        usedImports.add(this);
        setUsedForImportation();
    }
    return result;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment)

Example 85 with Assignment

use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.

the class ObjectClass_refd method getRefd.

protected ObjectClass getRefd(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (null != reference && referenceChain.add(this)) {
        final Assignment assignment = reference.getRefdAssignment(timestamp, true, referenceChain);
        if (null == assignment) {
            return newObjectClassDefinitionInstance();
        }
        final ISetting setting = reference.getRefdSetting(timestamp);
        if (Setting_type.S_ERROR.equals(setting.getSettingtype())) {
            return newObjectClassDefinitionInstance();
        } else if (!Setting_type.S_OC.equals(setting.getSettingtype())) {
            reference.getLocation().reportSemanticError(OBJECTCLASSEXPECTED);
            return newObjectClassDefinitionInstance();
        }
        return (ObjectClass) setting;
    }
    return newObjectClassDefinitionInstance();
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ObjectClass(org.eclipse.titan.designer.AST.ASN1.ObjectClass) ISetting(org.eclipse.titan.designer.AST.ISetting)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)141 Reference (org.eclipse.titan.designer.AST.Reference)48 IType (org.eclipse.titan.designer.AST.IType)41 ISubReference (org.eclipse.titan.designer.AST.ISubReference)39 IValue (org.eclipse.titan.designer.AST.IValue)31 Identifier (org.eclipse.titan.designer.AST.Identifier)25 ArrayList (java.util.ArrayList)24 Module (org.eclipse.titan.designer.AST.Module)22 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)16 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)14 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)14 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)14 Assignments (org.eclipse.titan.designer.AST.Assignments)13 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10 Location (org.eclipse.titan.designer.AST.Location)9 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)8 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)7 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)7 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)6