Search in sources :

Example 6 with FormalParameter

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

the class Signature_Type method checkThisValueSequence.

/**
 * Checks the Sequence_Value kind value against this type.
 * <p>
 * Please note, that this function can only be called once we know for sure
 * that the value is of sequence type.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expectedValue the kind of value expected here.
 * @param incompleteAllowed wheather incomplete value is allowed or not.
 * @param implicitOmit true if the implicit omit optional attribute was set
 *            for the value, false otherwise
 */
private boolean checkThisValueSequence(final CompilationTimeStamp timestamp, final Sequence_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
    boolean selfReference = false;
    final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
    boolean inSnyc = true;
    final int nofTypeComponents = getNofParameters();
    final int nofvalueComponents = value.getNofComponents();
    int nextIndex = 0;
    SignatureFormalParameter lastParameter = null;
    for (int i = 0; i < nofvalueComponents; i++) {
        final NamedValue namedValue = value.getSeqValueByIndex(i);
        final Identifier valueId = namedValue.getName();
        if (!formalParList.hasParameterWithName(valueId.getName())) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTPARAMETER, valueId.getDisplayName(), getTypename()));
            inSnyc = false;
            continue;
        } else if (componentMap.containsKey(valueId.getName())) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEPARAMETERAGAIN, valueId.getDisplayName(), getTypename()));
            componentMap.get(valueId.getName()).getLocation().reportSemanticError(MessageFormat.format("Parameter `{0}'' is already given here", valueId.getDisplayName()));
            inSnyc = false;
        } else {
            componentMap.put(valueId.getName(), namedValue);
        }
        final SignatureFormalParameter formalParameter = formalParList.getParameterByName(valueId.getName());
        if (inSnyc) {
            if (incompleteAllowed) {
                boolean found = false;
                for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
                    final SignatureFormalParameter formalParameter2 = formalParList.getParameterByIndex(j);
                    if (valueId.getName().equals(formalParameter2.getIdentifier().getName())) {
                        lastParameter = formalParameter2;
                        nextIndex = j + 1;
                        found = true;
                    }
                }
                if (lastParameter != null && !found) {
                    namedValue.getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' cannot appear after parameter `{1}'' in signature value", valueId.getDisplayName(), lastParameter.getIdentifier().getDisplayName()));
                    inSnyc = false;
                }
            } else {
                final SignatureFormalParameter formalParameter2 = formalParList.getParameterByIndex(i);
                if (formalParameter != formalParameter2) {
                    namedValue.getLocation().reportSemanticError(MessageFormat.format("Unexpected field `{0}'' in signature value, expecting `{1}''", valueId.getDisplayName(), formalParameter2.getIdentifier().getDisplayName()));
                    inSnyc = false;
                }
            }
        }
        final Type type = formalParameter.getType();
        final IValue componentValue = namedValue.getValue();
        if (componentValue != null) {
            componentValue.setMyGovernor(type);
            final IValue tempValue = type.checkThisValueRef(timestamp, componentValue);
            selfReference |= type.checkThisValue(timestamp, tempValue, lhs, new ValueCheckingOptions(expectedValue, false, false, true, implicitOmit, strElem));
        }
    }
    if (!incompleteAllowed) {
        for (int i = 0; i < formalParList.getNofInParameters(); i++) {
            final SignatureFormalParameter formalParameter = formalParList.getInParameterByIndex(i);
            final Identifier identifier = formalParameter.getIdentifier();
            if (!componentMap.containsKey(identifier.getName()) && SignatureFormalParameter.ParamaterDirection.PARAM_OUT != formalParameter.getDirection()) {
                value.getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is missing from signature value", identifier.getDisplayName()));
            }
        }
    }
    return selfReference;
}
Also used : SignatureReturnType(org.eclipse.titan.designer.AST.TTCN3.types.SignatureGenerator.SignatureReturnType) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) HashMap(java.util.HashMap) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)

Example 7 with FormalParameter

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

the class Component_Type method checkExpressionOperandComponentRefernce.

/**
 * Checks if the provided value is a reference to a component or not.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expected_value the value kind expected from the actual parameter.
 */
public static void checkExpressionOperandComponentRefernce(final CompilationTimeStamp timestamp, final IValue value, final String operationName) {
    switch(value.getValuetype()) {
        case EXPRESSION_VALUE:
            {
                final Expression_Value expression = (Expression_Value) value;
                if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
                    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    final IValue last = value.getValueRefdLast(timestamp, chain);
                    chain.release();
                    if (last == null || last.getIsErroneous(timestamp)) {
                        value.setIsErroneous(true);
                        return;
                    }
                    IType type = last.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                    if (type == null) {
                        value.setIsErroneous(true);
                        return;
                    }
                    type = type.getTypeRefdLast(timestamp);
                    if (type.getIsErroneous(timestamp)) {
                        value.setIsErroneous(true);
                        // don't let spread an earlier mistake
                        return;
                    }
                    if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                        value.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                        value.setIsErroneous(true);
                        return;
                    }
                }
                break;
            }
        case REFERENCED_VALUE:
            {
                final Reference reference = ((Referenced_Value) value).getReference();
                final Assignment assignment = reference.getRefdAssignment(timestamp, true);
                if (assignment == null) {
                    value.setIsErroneous(true);
                    return;
                }
                switch(assignment.getAssignmentType()) {
                    case A_CONST:
                        {
                            IType type = ((Def_Const) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            IValue tempValue = ((Def_Const) assignment).getValue();
                            if (tempValue == null) {
                                return;
                            }
                            IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                            tempValue = tempValue.getReferencedSubValue(timestamp, reference, 1, chain);
                            chain.release();
                            if (tempValue == null) {
                                return;
                            }
                            chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                            tempValue = tempValue.getValueRefdLast(timestamp, chain);
                            chain.release();
                            if (Value_type.TTCN3_NULL_VALUE.equals(tempValue.getValuetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
                                value.setIsErroneous(true);
                                return;
                            }
                            if (!Value_type.EXPRESSION_VALUE.equals(tempValue.getValuetype())) {
                                return;
                            }
                            switch(((Expression_Value) tempValue).getOperationType()) {
                                case MTC_COMPONENT_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `mtc''", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                case COMPONENT_NULL_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                case SYSTEM_COMPONENT_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `system''", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                default:
                                    break;
                            }
                            break;
                        }
                    case A_EXT_CONST:
                        {
                            IType type = ((Def_ExternalConst) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_MODULEPAR:
                        {
                            IType type = ((Def_ModulePar) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_VAR:
                        {
                            IType type = ((Def_Var) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_FUNCTION_RVAL:
                        {
                            IType type = ((Def_Function) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_EXT_FUNCTION_RVAL:
                        {
                            IType type = ((Def_Extfunction) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_PAR_VAL:
                    case A_PAR_VAL_IN:
                    case A_PAR_VAL_OUT:
                    case A_PAR_VAL_INOUT:
                        {
                            IType type = ((FormalParameter) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    default:
                        reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' should be a component reference instead of `{1}''", operationName, assignment.getDescription()));
                        value.setIsErroneous(true);
                        return;
                }
                break;
            }
        default:
            // the error was already reported if possible.
            return;
    }
}
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) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) IType(org.eclipse.titan.designer.AST.IType)

Example 8 with FormalParameter

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

the class Testcase_Type method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    aData.addBuiltinTypeImport("TitanFloat");
    final String genName = getGenNameOwn();
    final String displayName = getFullName();
    generateCodeTypedescriptor(aData, source);
    final FunctionReferenceDefinition def = new FunctionReferenceDefinition(genName, displayName);
    def.returnType = null;
    def.type = fatType.TESTCASE;
    def.runsOnSelf = false;
    def.isStartable = false;
    def.formalParList = formalParList.generateCode(aData).toString();
    def.actualParList = formalParList.generateCodeActualParlist("").toString();
    def.parameterTypeNames = new ArrayList<String>(formalParList.getNofParameters());
    def.parameterNames = new ArrayList<String>(formalParList.getNofParameters());
    if (formalParList.getNofParameters() > 0) {
        def.formalParList = def.formalParList + ", ";
        def.actualParList = def.actualParList + ", ";
    }
    def.formalParList = def.formalParList + "boolean has_timer, TitanFloat timer_value";
    def.actualParList = def.actualParList + "has_timer, timer_value";
    for (int i = 0; i < formalParList.getNofParameters(); i++) {
        final FormalParameter formalParameter = formalParList.getParameterByIndex(i);
        switch(formalParameter.getAssignmentType()) {
            case A_PAR_VAL:
            case A_PAR_VAL_IN:
            case A_PAR_VAL_INOUT:
            case A_PAR_VAL_OUT:
                def.parameterTypeNames.add(formalParameter.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, getMyScope()));
                break;
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_INOUT:
            case A_PAR_TEMP_OUT:
                def.parameterTypeNames.add(formalParameter.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameTemplate(aData, source, getMyScope()));
                break;
            default:
                break;
        }
        def.parameterNames.add(formalParameter.getIdentifier().getName());
    }
    FunctionReferenceGenerator.generateValueClass(aData, source, def);
    FunctionReferenceGenerator.generateTemplateClass(aData, source, def);
    if (hasDoneAttribute()) {
        generateCodeDone(aData, source);
    }
    if (subType != null) {
        subType.generateCode(aData, source);
    }
    generateCodeForCodingHandlers(aData, source);
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) FunctionReferenceDefinition(org.eclipse.titan.designer.AST.TTCN3.types.FunctionReferenceGenerator.FunctionReferenceDefinition)

Example 9 with FormalParameter

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

the class Visibility method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof FormalParameter) {
        return;
    } else if (node instanceof Definition) {
        final Definition s = (Definition) node;
        final Identifier identifier = s.getIdentifier();
        check(identifier, s.getDescription(), problems);
    } else if (node instanceof Group) {
        final Group s = (Group) node;
        final Identifier identifier = s.getIdentifier();
        check(identifier, "group", problems);
    } else {
        return;
    }
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Group(org.eclipse.titan.designer.AST.TTCN3.definitions.Group) Identifier(org.eclipse.titan.designer.AST.Identifier) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 10 with FormalParameter

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

the class ChangeCreator method createFileChange.

private Change createFileChange(final IFile toVisit) {
    if (toVisit == null) {
        return null;
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
    final Module module = sourceParser.containedModule(toVisit);
    if (module == null) {
        return null;
    }
    final DefinitionVisitor vis = new DefinitionVisitor();
    module.accept(vis);
    final List<FormalParameter> nodes = vis.getLocations();
    // Calculate edit locations
    final List<Location> locations = new ArrayList<Location>();
    try {
        final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, locations);
        job1.join();
    } catch (InterruptedException ie) {
        ErrorReporter.logExceptionStackTrace(ie);
    } catch (CoreException ce) {
        ErrorReporter.logError("LazyficationRefactoring: " + "CoreException while calculating edit locations in " + toVisit.getName() + ".");
        ErrorReporter.logExceptionStackTrace(ce);
    }
    if (locations.isEmpty()) {
        return null;
    }
    // Create a change for each edit location
    final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
    final MultiTextEdit rootEdit = new MultiTextEdit();
    tfc.setEdit(rootEdit);
    for (Location l : locations) {
        rootEdit.addChild(new InsertEdit(l.getOffset(), "@lazy "));
    }
    return tfc;
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) InsertEdit(org.eclipse.text.edits.InsertEdit) ArrayList(java.util.ArrayList) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) CoreException(org.eclipse.core.runtime.CoreException) Module(org.eclipse.titan.designer.AST.Module) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

FormalParameter (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter)18 IType (org.eclipse.titan.designer.AST.IType)12 Assignment (org.eclipse.titan.designer.AST.Assignment)9 Type (org.eclipse.titan.designer.AST.Type)8 CodeSectionType (org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType)4 IValue (org.eclipse.titan.designer.AST.IValue)4 Identifier (org.eclipse.titan.designer.AST.Identifier)4 Reference (org.eclipse.titan.designer.AST.Reference)4 Def_Var (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var)4 TemplateInstance (org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance)4 HashMap (java.util.HashMap)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Def_Var_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)3 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)3 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 FunctionReferenceDefinition (org.eclipse.titan.designer.AST.TTCN3.types.FunctionReferenceGenerator.FunctionReferenceDefinition)3 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)2 Location (org.eclipse.titan.designer.AST.Location)2 Module (org.eclipse.titan.designer.AST.Module)2