Search in sources :

Example 96 with Assignment

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

the class Int2Enum_Statement method generateCode.

@Override
public void generateCode(final JavaGenData aData, final StringBuilder source) {
    final ExpressionStruct valueExpression = new ExpressionStruct();
    value.generateCodeExpression(aData, valueExpression, true);
    final ExpressionStruct referenceExpression = new ExpressionStruct();
    reference.generateCode(aData, referenceExpression);
    boolean isOptional = false;
    final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
        isOptional = true;
    }
    source.append(valueExpression.preamble);
    source.append(referenceExpression.preamble);
    source.append(MessageFormat.format("{0}{1}.int2enum({2});\n", referenceExpression.expression, isOptional ? ".get()" : "", valueExpression.expression));
    source.append(valueExpression.postamble);
    source.append(referenceExpression.postamble);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 97 with Assignment

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

the class Start_Timer_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    checkTimerReference(timestamp, timerReference);
    if (timerValue == null) {
        final Assignment assignment = timerReference.getRefdAssignment(timestamp, true);
        if (assignment != null && Assignment_type.A_TIMER.semanticallyEquals(assignment.getAssignmentType())) {
            final Def_Timer defTimer = (Def_Timer) assignment;
            if (!defTimer.hasDefaultDuration(timestamp, timerReference)) {
                location.reportSemanticError(MessageFormat.format(MISSINGDEFAULTDURATION, assignment.getDescription()));
            }
        }
    } else {
        timerValue.setLoweridToReference(timestamp);
        final Type_type temporalType = timerValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        switch(temporalType) {
            case TYPE_REAL:
                {
                    final IValue last = timerValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
                    if (!last.isUnfoldable(timestamp)) {
                        final Real_Value real = (Real_Value) last;
                        final double val = real.getValue();
                        if (val < 0.0) {
                            timerValue.getLocation().reportSemanticError(MessageFormat.format(NEGATIVEDURATION, real));
                        } else if (real.isPositiveInfinity()) {
                            timerValue.getLocation().reportSemanticError(MessageFormat.format(INFINITYDURATION, real.createStringRepresentation()));
                        }
                    }
                    return;
                }
            case TYPE_UNDEFINED:
                return;
            default:
                timerValue.getLocation().reportSemanticError(FLOATEXPECTED);
                return;
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Def_Timer(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 98 with Assignment

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

the class StatementBlock method registerDefinition.

/**
 * Registers a definition (for example new variable) into the list of
 * definitions available in this statement block.
 *
 * Please note, that this is done while the semantic check is happening,
 * as it must not be allowed to reach definitions not yet defined.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param definition
 *                the definition to register.
 */
public void registerDefinition(final CompilationTimeStamp timestamp, final Definition definition) {
    if (definition == null) {
        return;
    }
    final Identifier identifier = definition.getIdentifier();
    if (identifier == null) {
        return;
    }
    if (definitionMap == null) {
        definitionMap = new HashMap<String, Definition>(3);
    }
    final String definitionName = identifier.getName();
    if (definitionMap.containsKey(definitionName)) {
        if (definition.getLocation() != null && definitionMap.get(definitionName).getLocation() != null) {
            final Location otherLocation = definitionMap.get(definitionName).getLocation();
            otherLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            definition.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        }
    } else {
        definitionMap.put(definitionName, definition);
        if (parentScope != null && definition.getLocation() != null) {
            if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
                definition.getLocation().reportSemanticError(MessageFormat.format(HIDINGSCOPEELEMENT, identifier.getDisplayName()));
                final List<ISubReference> subReferences = new ArrayList<ISubReference>();
                subReferences.add(new FieldSubReference(identifier));
                final Reference reference = new Reference(null, subReferences);
                final Assignment assignment = parentScope.getAssBySRef(timestamp, reference);
                if (assignment != null && assignment.getLocation() != null) {
                    assignment.getLocation().reportSingularSemanticError(MessageFormat.format(HIDDENSCOPEELEMENT, identifier.getDisplayName()));
                }
            } else if (parentScope.isValidModuleId(identifier)) {
                definition.getLocation().reportSemanticWarning(MessageFormat.format(HIDINGMODULEIDENTIFIER, identifier.getDisplayName()));
            }
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ArrayList(java.util.ArrayList) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 99 with Assignment

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

the class LogArgument method checkReference.

/**
 * Does the semantic checking of the log argument. Once it was
 * determined that it is a reference.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param reference
 *                the reference contained in the log argument.
 */
private void checkReference(final CompilationTimeStamp timestamp, final Reference reference) {
    if (reference == null) {
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null || assignment.getIsErroneous()) {
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
        case A_EXT_FUNCTION_RVAL:
        case A_EXT_FUNCTION_RTEMP:
            {
                reference.getMyScope().checkRunsOnScope(timestamp, assignment, reference, "call");
                final IType assingmentType = assignment.getType(timestamp);
                if (assingmentType != null) {
                    assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                }
                break;
            }
        case A_CONST:
            {
                final IType assingmentType = assignment.getType(timestamp);
                if (assingmentType != null && assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false) != null) {
                    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    if (assignment instanceof Def_Const) {
                        ((Def_Const) assignment).getValue().getReferencedSubValue(timestamp, reference, 1, chain);
                    } else {
                        ((Value_Assignment) assignment).getValue().getReferencedSubValue(timestamp, reference, 1, chain);
                    }
                    chain.release();
                }
                break;
            }
        case A_TEMPLATE:
            {
                final IType assingmentType = assignment.getType(timestamp);
                if (assingmentType != null && assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false) != null) {
                    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    ((Def_Template) assignment).getTemplate(timestamp).getReferencedSubTemplate(timestamp, reference, chain);
                    chain.release();
                }
                break;
            }
        case A_MODULEPAR_TEMPLATE:
            {
                final IType assingmentType = assignment.getType(timestamp);
                if (assingmentType != null) {
                    assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                }
                break;
            }
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_VAR_TEMPLATE:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            {
                final IType assingmentType = assignment.getType(timestamp);
                if (assingmentType != null) {
                    assingmentType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                }
                break;
            }
        case A_PORT:
            {
                final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, assignment.getAssignmentName(), true, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                } else if (reference.getSubreferences().size() > 1) {
                    getLocation().reportSemanticError(MessageFormat.format("Reference to single {0} cannot have field or array sub-references", assignment.getDescription()));
                    isErroneous = true;
                }
                break;
            }
        case A_TIMER:
            {
                final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, assignment.getAssignmentName(), true, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                } else if (reference.getSubreferences().size() > 1) {
                    getLocation().reportSemanticError(MessageFormat.format("Reference to single {0} cannot have field or array sub-references", assignment.getDescription()));
                    isErroneous = true;
                }
                break;
            }
        case A_PAR_TIMER:
        case A_PAR_PORT:
            if (reference.getSubreferences().size() > 1) {
                getLocation().reportSemanticError(MessageFormat.format("Reference to {0} cannot have field or array sub-references", assignment.getDescription()));
                isErroneous = true;
            }
            break;
        case A_FUNCTION:
        case A_EXT_FUNCTION:
            getLocation().reportSemanticError(MessageFormat.format("Reference to a value, template, timer or port was ecpected instead of a call of {0}, which does not have a return type", assignment.getDescription()));
            isErroneous = true;
            break;
        default:
            getLocation().reportSemanticError(MessageFormat.format("Reference to a value, template, timer or port was expected instead of {0}", assignment.getDescription()));
            isErroneous = true;
            break;
    }
}
Also used : Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) IType(org.eclipse.titan.designer.AST.IType)

Example 100 with Assignment

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

the class String2Ttcn_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    if (value != null) {
        value.setLoweridToReference(timestamp);
        final Type_type temporalType = value.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        switch(temporalType) {
            case TYPE_CHARSTRING:
                value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
                break;
            case TYPE_UNDEFINED:
                setIsErroneous();
                break;
            default:
                if (!isErroneous) {
                    value.getLocation().reportSemanticError(OPERANDERROR1);
                    setIsErroneous();
                }
        }
    }
    if (reference != null) {
        final Assignment assignment = reference.getRefdAssignment(timestamp, false);
        if (assignment == null) {
            reference.getLocation().reportSemanticError(OPERANDERROR2);
            setIsErroneous();
        } else {
            switch(assignment.getAssignmentType()) {
                case A_PAR_VAL:
                case A_PAR_VAL_IN:
                case A_PAR_TEMP_IN:
                case A_VAR:
                case A_VAR_TEMPLATE:
                case A_PAR_VAL_OUT:
                case A_PAR_VAL_INOUT:
                case A_PAR_TEMP_OUT:
                case A_PAR_TEMP_INOUT:
                    // valid assignment types
                    break;
                default:
                    reference.getLocation().reportSemanticError(OPERANDERROR3);
                    setIsErroneous();
            }
        }
    }
    lastTimeChecked = timestamp;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

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