Search in sources :

Example 11 with Def_Template

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template 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)

Example 12 with Def_Template

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template 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 13 with Def_Template

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

the class Referenced_Template method hasTemplateImpliciteOmit.

/**
 * Returns whether in the chain of referenced templates there is one
 * which was defined to have the implicit omit attribute set
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param referenceChain
 *                the ReferenceChain used to detect circular references
 *
 * @return true if it has, false otherwise.
 */
private boolean hasTemplateImpliciteOmit(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    final boolean newChain = null == referenceChain;
    IReferenceChain tempReferenceChain;
    if (newChain) {
        tempReferenceChain = ReferenceChain.getInstance(CIRCULARTEMPLATEREFERENCE, true);
    } else {
        tempReferenceChain = referenceChain;
    }
    boolean result = false;
    if (reference != null) {
        final Assignment ass = reference.getRefdAssignment(timestamp, true);
        if (ass != null && ass.getAssignmentType() == Assignment_type.A_TEMPLATE) {
            final Def_Template templateDefinition = (Def_Template) ass;
            if (templateDefinition.hasImplicitOmitAttribute(timestamp)) {
                result = true;
            } else {
                tempReferenceChain.markState();
                if (tempReferenceChain.add(this)) {
                    final ITTCN3Template refd = getTemplateReferenced(timestamp, tempReferenceChain);
                    if (refd != this && refd instanceof Referenced_Template) {
                        result = ((Referenced_Template) refd).hasTemplateImpliciteOmit(timestamp, referenceChain);
                    }
                } else {
                    setIsErroneous(true);
                }
                tempReferenceChain.previousState();
            }
        }
    }
    if (newChain) {
        tempReferenceChain.release();
    }
    return result;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 14 with Def_Template

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

the class Referenced_Template method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
        return;
    }
    lastTimeBuilt = aData.getBuildTimstamp();
    if (useSingleExpressionForInit() && hasSingleExpression()) {
        source.append(MessageFormat.format("{0}.assign({1});\n", name, getSingleExpression(aData, false)));
        return;
    }
    final ExpressionStruct expression = new ExpressionStruct();
    boolean useReferenceForCodegeneration = true;
    if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
        // the referencing template is a part of a non-parameterized template
        final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
        if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
            // FIXME implement formal par check
            if (((Def_Template) assignment).getFormalParameterList() != null) {
                // the referred template is parameterized
                // generate the initialization sequence first for all dependent
                // non-parameterized templates
                reArrangeInitCode(aData, source, myScope.getModuleScope());
            } else if (assignment.getMyScope().getModuleScope() == myScope.getModuleScope()) {
                // the referred template is non-parameterized
                // use a different algorithm for code generation
                generateRearrangeInitCodeReferenced(aData, source, expression);
                useReferenceForCodegeneration = false;
            }
        }
    }
    if (useReferenceForCodegeneration) {
        reference.generateConstRef(aData, expression);
    }
    if (expression.preamble.length() > 0 || expression.postamble.length() > 0) {
        // the expressions within reference need temporary objects
        source.append("{\n");
        source.append(expression.preamble);
        // FIXME handle the needs conversion case
        source.append(MessageFormat.format("{0}.assign({1});\n", name, expression.expression));
        source.append(expression.postamble);
        source.append("}\n");
    } else {
        // FIXME handle needs conversion case
        source.append(MessageFormat.format("{0}.assign({1});\n", name, expression.expression));
    }
    if (lengthRestriction != null) {
        if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
            lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
        }
        lengthRestriction.generateCodeInit(aData, source, name);
    }
    if (isIfpresent) {
        source.append(name);
        source.append(".set_ifPresent();\n");
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)9 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Def_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template)6 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)5 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)4 IValue (org.eclipse.titan.designer.AST.IValue)4 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)4 IType (org.eclipse.titan.designer.AST.IType)3 Reference (org.eclipse.titan.designer.AST.Reference)3 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)3 Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)3 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Def_ModulePar (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar)2 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)2 ArrayDimensions (org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions)2 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)2 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)2 Stack (java.util.Stack)1