Search in sources :

Example 1 with Def_Var_Template

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

the class Assignment_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    isErroneous = false;
    selfReference = false;
    templateRestriction = Restriction_type.TR_NONE;
    generateRestrictionCheck = false;
    if (reference == null) {
        return;
    }
    reference.setUsedOnLeftHandSide();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null || assignment.getIsErroneous()) {
        isErroneous = true;
        return;
    }
    if (template == null) {
        return;
    }
    switch(assignment.getAssignmentType()) {
        case A_PAR_VAL_IN:
            ((FormalParameter) assignment).useAsLValue(reference);
            if (template.isValue(timestamp)) {
                // TODO: isValue should be checked within the previous line! This is double check!
                final IValue temporalValue = template.getValue();
                checkVarAssignment(timestamp, assignment, temporalValue);
                template.setMyGovernor(temporalValue.getMyGovernor());
                break;
            } else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
                // TODO: convert (x) to x to compilation!
                break;
            } else {
                template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
                template.setIsErroneous(true);
                return;
            }
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
        case A_PAR_VAL:
            ((FormalParameter) assignment).setWritten();
            if (template.isValue(timestamp)) {
                // TODO: isValue should be checked within the previous line! This is double check!
                final IValue temporalValue = template.getValue();
                checkVarAssignment(timestamp, assignment, temporalValue);
                template.setMyGovernor(temporalValue.getMyGovernor());
                break;
            } else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
                // TODO: convert (x) to x to compilation!
                break;
            } else {
                template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
                template.setIsErroneous(true);
                return;
            }
        // break
        case A_VAR:
            ((Def_Var) assignment).setWritten();
            if (template.getIsErroneous(timestamp)) {
                return;
            }
            final IValue temporalValue = template.getValue();
            if (temporalValue != null) {
                checkVarAssignment(timestamp, assignment, temporalValue);
                template.setMyGovernor(temporalValue.getMyGovernor());
                break;
            } else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
                break;
            } else {
                template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
                template.setIsErroneous(true);
                return;
            }
        case A_PAR_TEMP_IN:
            ((FormalParameter) assignment).useAsLValue(reference);
            checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
            break;
        case A_PAR_TEMP_OUT:
        case A_PAR_TEMP_INOUT:
            ((FormalParameter) assignment).setWritten();
            checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
            break;
        case A_VAR_TEMPLATE:
            ((Def_Var_Template) assignment).setWritten();
            checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
            break;
        default:
            reference.getLocation().reportSemanticError(MessageFormat.format(VARIABLEREFERENCEEXPECTED, assignment.getAssignmentName()));
            reference.setIsErroneous(true);
            isErroneous = true;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) IValue(org.eclipse.titan.designer.AST.IValue) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)

Example 2 with Def_Var_Template

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

the class Referenced_Template method getTemplateReferenced.

/**
 * Calculates the referenced template, and while doing so checks the
 * reference too.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param referenceChain
 *                the reference chain used to detect cyclic references.
 *
 * @return the template referenced
 */
private ITTCN3Template getTemplateReferenced(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
    if (reference == null) {
        setIsErroneous(true);
        return null;
    }
    final Assignment ass = reference.getRefdAssignment(timestamp, true);
    if (ass == null) {
        setIsErroneous(true);
        return this;
    }
    ITTCN3Template template = null;
    switch(ass.getAssignmentType()) {
        case A_TEMPLATE:
            template = ((Def_Template) ass).getTemplate(timestamp);
            break;
        case A_VAR_TEMPLATE:
            ((Def_Var_Template) ass).check(timestamp);
            template = ((Def_Var_Template) ass).getInitialValue();
            break;
        case A_MODULEPAR_TEMPLATE:
            template = ((Def_ModulePar_Template) ass).getDefaultTemplate();
            break;
        default:
            setIsErroneous(true);
            return this;
    }
    if (template != null) {
        template = template.getReferencedSubTemplate(timestamp, reference, referenceChain);
    }
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (template != null) {
        return template;
    } else if (subreferences != null && reference.hasUnfoldableIndexSubReference(timestamp)) {
    // some array indices could not be evaluated
    } else if (reference.getUsedInIsbound()) {
        return this;
    } else {
        setIsErroneous(true);
    }
    return this;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)

Example 3 with Def_Var_Template

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

the class PortTypeBody method generateCode.

/**
 * Add generated java code on this level.
 * @param aData only used to update imports if needed
 * @param source the source code generated
 *
 * FIXME the implementation only serves as a minimal testing setup
 */
public void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String genName = myType.getGenNameOwn();
    final Scope myScope = myType.getMyScope();
    final PortDefinition portDefinition = new PortDefinition(genName, getFullName());
    if (inMessages != null) {
        for (int i = 0; i < inMessages.getNofTypes(); i++) {
            final IType inType = inMessages.getTypeByIndex(i);
            final messageTypeInfo info = new messageTypeInfo(inType.getGenNameValue(aData, source, myScope), inType.getGenNameTemplate(aData, source, myScope), inType.getTypename());
            portDefinition.inMessages.add(info);
        }
    }
    if (outMessages != null) {
        for (int i = 0; i < outMessages.getNofTypes(); i++) {
            final IType outType = outMessages.getTypeByIndex(i);
            final messageTypeInfo info = new messageTypeInfo(outType.getGenNameValue(aData, source, myScope), outType.getGenNameTemplate(aData, source, myScope), outType.getTypename());
            portDefinition.outMessages.add(info);
        }
    }
    if (inSignatures != null) {
        for (int i = 0; i < inSignatures.getNofTypes(); i++) {
            final IType outType = inSignatures.getTypeByIndex(i);
            final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, false);
            portDefinition.inProcedures.add(info);
        }
    }
    if (outSignatures != null) {
        for (int i = 0; i < outSignatures.getNofTypes(); i++) {
            final IType outType = outSignatures.getTypeByIndex(i);
            final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, signature.getSignatureReturnType() != null);
            portDefinition.outProcedures.add(info);
        }
    }
    switch(testportType) {
        case TP_REGULAR:
            portDefinition.testportType = TestportType.NORMAL;
            break;
        case TP_INTERNAL:
            portDefinition.testportType = TestportType.INTERNAL;
            break;
        case TP_ADDRESS:
            portDefinition.testportType = TestportType.ADDRESS;
            portDefinition.addressName = "TitanAddress";
            break;
        default:
            portDefinition.testportType = TestportType.NORMAL;
    }
    if (vardefs != null) {
        portDefinition.varDefs = new StringBuilder();
        portDefinition.varInit = new StringBuilder();
        for (int i = 0; i < vardefs.getNofAssignments(); i++) {
            final Definition def = vardefs.getAssignmentByIndex(i);
            String type = "";
            switch(def.getAssignmentType()) {
                case A_VAR:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
                    if (((Def_Var) def).getInitialValue() == null) {
                        portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
                    } else {
                        def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    }
                    break;
                case A_CONST:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
                    def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    break;
                case A_VAR_TEMPLATE:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameTemplate(aData, source, myScope);
                    if (((Def_Var_Template) def).getInitialValue() == null) {
                        portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
                    } else {
                        def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    }
                    break;
                default:
                    // FATAL ERROR
                    break;
            }
            portDefinition.varDefs.append(MessageFormat.format("private {0} {1} = new {0}();\n", type, def.getGenName()));
        }
    }
    PortGenerator.generateClass(aData, source, portDefinition);
}
Also used : PortGenerator.messageTypeInfo(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.messageTypeInfo) PortDefinition(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.PortDefinition) Scope(org.eclipse.titan.designer.AST.Scope) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) PortDefinition(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.PortDefinition) IType(org.eclipse.titan.designer.AST.IType) PortGenerator.procedureSignatureInfo(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.procedureSignatureInfo)

Example 4 with Def_Var_Template

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

the class TypenameInDef method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof Def_Const) && !(node instanceof Def_ExternalConst) && !(node instanceof Def_Extfunction) && !(node instanceof Def_Function) && !(node instanceof Def_ModulePar) && !(node instanceof Def_Template) && !(node instanceof Def_Var_Template) && !(node instanceof Def_Var)) {
        return;
    }
    final Definition s = (Definition) node;
    check(s.getIdentifier(), s.getType(timestamp), s.getDescription(), problems);
}
Also used : Def_ExternalConst(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst) Def_Extfunction(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 5 with Def_Var_Template

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

the class Parameter_Redirect method checkVariableReference.

/**
 * Check whether the reference points to a variable of the provided
 * type.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param reference
 *                the reference to check
 * @param type
 *                the type the parameter is expected to have.
 */
public final void checkVariableReference(final CompilationTimeStamp timestamp, final Reference reference, final IType type) {
    if (reference == null) {
        return;
    }
    final IType variableType = reference.checkVariableReference(timestamp);
    if (type != null && variableType != null && !type.isIdentical(timestamp, variableType)) {
        final String message = MessageFormat.format("Type mismatch in parameter redirect: A variable of type `{0}'' was expected instead of `{1}''", type.getTypename(), variableType.getTypename());
        reference.getLocation().reportSemanticError(message);
        return;
    }
    final Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment != null) {
        switch(assignment.getAssignmentType()) {
            case A_PAR_VAL:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                ((FormalParameter) assignment).setWritten();
                break;
            case A_VAR:
                ((Def_Var) assignment).setWritten();
                break;
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                ((FormalParameter) assignment).setWritten();
                break;
            case A_VAR_TEMPLATE:
                ((Def_Var_Template) assignment).setWritten();
                break;
            default:
                break;
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

Assignment (org.eclipse.titan.designer.AST.Assignment)7 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)6 IType (org.eclipse.titan.designer.AST.IType)4 Def_Var (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)3 FormalParameter (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter)3 IValue (org.eclipse.titan.designer.AST.IValue)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)2 Def_ModulePar (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar)2 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)2 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Value_Assignment (org.eclipse.titan.designer.AST.ASN1.Value_Assignment)1 CodeSectionType (org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType)1 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)1 Scope (org.eclipse.titan.designer.AST.Scope)1 TemplateRestriction (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction)1