Search in sources :

Example 11 with Reference

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

the class ObjectIdentifierComponent method checkNameForm.

/**
 * Checks that the identifier in name is a valid name form in the actual state.
 * Also checks the named form in an OID component.
 *
 * @param timestamp the timestamp of the actual compilation cycle.
 * @param parent the parent value.
 * @param refChain the reference chain used to detect cyclic references.
 * @param state the state of checking.
 *
 * @param the new state after this check was done.
 */
private oidState_type checkNameForm(final CompilationTimeStamp timestamp, final Value parent, final IReferenceChain refChain, final oidState_type state, final AtomicInteger result) {
    final String nameString = name.getName();
    oidState_type actualState = state;
    int value = -1;
    switch(state) {
        case START:
            if ("itu__t".equals(nameString) || "ccitt".equals(nameString)) {
                actualState = oidState_type.ITU;
                value = 0;
            } else if ("itu__r".equals(nameString)) {
                location.reportSemanticWarning(MessageFormat.format("Identifier `{0}'' should not be used as NameForm", name.getDisplayName()));
                actualState = oidState_type.ITU;
                value = 0;
            } else if ("iso".equals(nameString)) {
                actualState = oidState_type.ISO;
                value = 1;
            } else if ("joint__iso__itu__t".equals(nameString) || "joint__iso__ccitt".equals(nameString)) {
                actualState = oidState_type.JOINT;
                value = 2;
            }
            break;
        case ITU:
            for (int i = 0; i < NAMES_ITU.length; i++) {
                if (nameString.equals(NAMES_ITU[i].name)) {
                    value = NAMES_ITU[i].value;
                    switch(value) {
                        case 0:
                            actualState = oidState_type.ITU_REC;
                            break;
                        case 5:
                            location.reportSemanticWarning(MessageFormat.format("Identifier `{0}'' should not be used as NumberForm", name.getDisplayName()));
                            actualState = oidState_type.LATER;
                            break;
                        default:
                            actualState = oidState_type.LATER;
                            break;
                    }
                }
            }
            break;
        case ISO:
            for (int i = 0; i < NAMES_ISO.length; i++) {
                if (nameString.equals(NAMES_ISO[i].name)) {
                    value = NAMES_ISO[i].value;
                    actualState = oidState_type.LATER;
                }
            }
            break;
        case JOINT:
            for (int i = 0; i < NAMES_JOINT.length; i++) {
                if (nameString.equals(NAMES_JOINT[i].name)) {
                    value = NAMES_JOINT[i].value;
                    actualState = oidState_type.LATER;
                    location.reportSemanticWarning(MessageFormat.format("Identifier `{0}'' should not be used as NumberForm", name.getDisplayName()));
                }
            }
            break;
        case ITU_REC:
            if (nameString.length() == 1) {
                final char c = nameString.charAt(0);
                if (c >= 'a' && c <= 'z') {
                    value = c - 'a' + 1;
                    actualState = oidState_type.LATER;
                }
            }
            break;
        default:
            break;
    }
    // now we have detected the name form
    if (value < 0) {
        final List<ISubReference> newSubreferences = new ArrayList<ISubReference>();
        newSubreferences.add(new FieldSubReference(name));
        Reference reference;
        if (parent.isAsn()) {
            reference = new Defined_Reference(null, newSubreferences);
        } else {
            reference = new Reference(null, newSubreferences);
        }
        final IValue newDefinedValue = new Referenced_Value(reference);
        newDefinedValue.setLocation(this.getLocation());
        final ObjectIdentifierComponent component = new ObjectIdentifierComponent(newDefinedValue);
        component.setFullNameParent(this);
        component.setMyScope(parent.getMyScope());
        actualState = component.checkDefdValueOID(timestamp, refChain, actualState);
    }
    result.set(value);
    // the other case is not handled as it would only change a parsed value
    return actualState;
}
Also used : Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) ArrayList(java.util.ArrayList) ISubReference(org.eclipse.titan.designer.AST.ISubReference) IValue(org.eclipse.titan.designer.AST.IValue)

Example 12 with Reference

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

the class OpenDeclarationHelper method findVisibleDeclarations.

public static DeclarationCollector findVisibleDeclarations(final IEditorPart targetEditor, final IReferenceParser referenceParser, final IDocument document, final int offset, final boolean reportErrors) {
    final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        if (reportErrors) {
            ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLEFILE);
        }
        return null;
    }
    Reference reference = null;
    referenceParser.setErrorReporting(reportErrors);
    reference = referenceParser.findReferenceForOpening(file, offset, document);
    if (reference == null) {
        if (reportErrors) {
            ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLEREFERENCE);
        }
        return null;
    }
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    if (ResourceExclusionHelper.isExcluded(file)) {
        ErrorReporter.parallelDisplayInStatusLine(targetEditor, MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
        return null;
    }
    final Module tempModule = projectSourceParser.containedModule(file);
    if (tempModule == null) {
        if (reportErrors) {
            ErrorReporter.parallelDisplayInStatusLine(targetEditor, MessageFormat.format(NOTFOUNDMODULE, file.getFullPath()));
        }
        return null;
    }
    final Scope scope = tempModule.getSmallestEnclosingScope(offset);
    if (scope == null) {
        if (reportErrors) {
            ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLESCOPE);
        }
        return null;
    }
    reference.setMyScope(scope);
    reference.detectModid();
    if (reference.getId() == null) {
        if (reportErrors) {
            ErrorReporter.parallelDisplayInStatusLine(targetEditor, NORECOGNISABLEREFERENCE);
        }
        return null;
    }
    final DeclarationCollector declarationCollector = new DeclarationCollector(reference);
    scope.addDeclaration(declarationCollector);
    return declarationCollector;
}
Also used : IFile(org.eclipse.core.resources.IFile) Scope(org.eclipse.titan.designer.AST.Scope) Reference(org.eclipse.titan.designer.AST.Reference) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 13 with Reference

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

the class For_Loop_Definitions method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastCompilationTimeStamp != null && !lastCompilationTimeStamp.isLess(timestamp)) {
        return;
    }
    lastCompilationTimeStamp = timestamp;
    lastUniquenessCheckTimeStamp = timestamp;
    if (definitionMap == null) {
        definitionMap = new HashMap<String, Definition>(definitions.size());
    }
    definitionMap.clear();
    String definitionName;
    Definition definition;
    Identifier identifier;
    for (int i = 0, size = definitions.size(); i < size; i++) {
        definition = definitions.get(i);
        identifier = definition.getIdentifier();
        definitionName = identifier.getName();
        if (definitionMap.containsKey(definitionName)) {
            final Location otherLocation = definitionMap.get(definitionName).getIdentifier().getLocation();
            otherLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            identifier.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        } else {
            definitionMap.put(definitionName, definition);
            if (parentScope != null && definition.getLocation() != null) {
                if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
                    definition.getLocation().reportSemanticError(MessageFormat.format(StatementBlock.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(StatementBlock.HIDDENSCOPEELEMENT, identifier.getDisplayName()));
                    }
                } else if (parentScope.isValidModuleId(identifier)) {
                    definition.getLocation().reportSemanticWarning(MessageFormat.format(StatementBlock.HIDINGMODULEIDENTIFIER, identifier.getDisplayName()));
                }
            }
        }
        definition.check(timestamp);
    }
}
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) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 14 with Reference

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

the class FormalParameter method checkActualParameterTimer.

/**
 * Checks if the actual parameter paired with this formal parameter is
 * semantically correct as a timer parameter.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param actualParameter
 *                the template instance assigned as actual parameter to
 *                this formal parameter
 * @param expectedValue
 *                the value kind expected from the actual parameter.
 *
 * @return the actual parameter created from the value, or null if there
 *         was an error.
 */
private ActualParameter checkActualParameterTimer(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter, final Expected_Value_type expectedValue) {
    final IType parameterType = actualParameter.getType();
    if (parameterType != null) {
        actualParameter.getLocation().reportSemanticError(EXPLICITESPECIFICATIONFORTIMER);
        actualParameter.checkType(timestamp, null);
    }
    final Reference derivedReference = actualParameter.getDerivedReference();
    if (derivedReference != null) {
        derivedReference.getLocation().reportSemanticError(INLINETEMPLATEFORTIMER);
        actualParameter.checkDerivedReference(timestamp, null);
    }
    final ITTCN3Template template = actualParameter.getTemplateBody();
    if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype()) && ((SpecificValue_Template) template).isReference()) {
        final Reference reference = ((SpecificValue_Template) template).getReference();
        final Assignment assignment = reference.getRefdAssignment(timestamp, true, null);
        if (assignment == null) {
            final ActualParameter temp = new Value_ActualParameter(null);
            temp.setIsErroneous();
            return temp;
        }
        switch(assignment.getAssignmentType()) {
            case A_TIMER:
                final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
                if (dimensions != null) {
                    dimensions.checkIndices(timestamp, reference, "timer", false, expectedValue);
                } else if (reference.getSubreferences().size() > 1) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR1, assignment.getDescription()));
                }
                break;
            case A_PAR_TIMER:
                if (reference.getSubreferences().size() > 1) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR2, assignment.getDescription()));
                }
                break;
            default:
                reference.getLocation().reportSemanticError(MessageFormat.format(TIMEREXPECTED1, assignment.getAssignmentName()));
                break;
        }
        return new Referenced_ActualParameter(reference);
    }
    actualParameter.getLocation().reportSemanticError(TIMEREXPECTED2);
    final ActualParameter temp = new Value_ActualParameter(null);
    temp.setIsErroneous();
    return temp;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Assignment(org.eclipse.titan.designer.AST.Assignment) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ArrayDimensions(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimensions) IType(org.eclipse.titan.designer.AST.IType)

Example 15 with Reference

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

the class FormalParameterList method checkActivateArgument.

/**
 * Check if a list of parsed actual parameters is semantically correct
 * according to a list of formal parameters in an activate
 * statement/operation.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param actualParameters
 *                the list of actual parameters containing both the
 *                named and the unnamed part converted into an unnamed
 *                list, that is full and in correct order.
 * @param description
 *                the description of the assignment to be used for
 *                reporting errors
 *
 * @return true if a semantic error was not found, false otherwise
 */
public final boolean checkActivateArgument(final CompilationTimeStamp timestamp, final ActualParameterList actualParameters, final String description) {
    if (actualParameters == null) {
        return false;
    }
    boolean returnValue = true;
    for (int i = 0; i < actualParameters.getNofParameters(); i++) {
        final ActualParameter actualParameter = actualParameters.getParameter(i);
        if (!(actualParameter instanceof Referenced_ActualParameter)) {
            continue;
        }
        final FormalParameter formalParameter = parameters.get(i);
        switch(formalParameter.getAssignmentType()) {
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
            case A_PAR_TIMER:
                // parameter types
                break;
            case A_PAR_PORT:
                // ports can be defined only in component types
                continue;
            default:
                return false;
        }
        final Reference reference = ((Referenced_ActualParameter) actualParameter).getReference();
        final Assignment assignment = reference.getRefdAssignment(timestamp, true);
        if (assignment == null) {
            return false;
        }
        switch(assignment.getAssignmentType()) {
            case A_VAR:
            case A_VAR_TEMPLATE:
            case A_TIMER:
                // variables or timers
                if (assignment.isLocal()) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(ILLEGALACTIVATEPARAMETER, i + 1, description, assignment.getDescription()));
                    returnValue = false;
                }
                break;
            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:
            case A_PAR_TIMER:
                {
                    // it is not allowed to pass references pointing
                    // to formal parameters
                    // except for activate() statements within
                    // testcases
                    final FormalParameter referencedFormalParameter = (FormalParameter) assignment;
                    final FormalParameterList formalParameterList = referencedFormalParameter.getMyParameterList();
                    if (formalParameterList != null) {
                        final Definition definition = formalParameterList.getMyDefinition();
                        if (definition != null && !Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
                            reference.getLocation().reportSemanticError(MessageFormat.format(ILLEGALACTIVATEPARAMETER, i + 1, description, assignment.getDescription()));
                            returnValue = false;
                        }
                    }
                    break;
                }
            default:
                break;
        }
    }
    return returnValue;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference)

Aggregations

Reference (org.eclipse.titan.designer.AST.Reference)88 Assignment (org.eclipse.titan.designer.AST.Assignment)48 ISubReference (org.eclipse.titan.designer.AST.ISubReference)37 IValue (org.eclipse.titan.designer.AST.IValue)26 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)23 IType (org.eclipse.titan.designer.AST.IType)23 Identifier (org.eclipse.titan.designer.AST.Identifier)22 ArrayList (java.util.ArrayList)19 Module (org.eclipse.titan.designer.AST.Module)16 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)15 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)13 IFile (org.eclipse.core.resources.IFile)11 Location (org.eclipse.titan.designer.AST.Location)10 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)10 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)9 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)9 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)9 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)8 Type (org.eclipse.titan.designer.AST.Type)8 BadLocationException (org.eclipse.jface.text.BadLocationException)7