Search in sources :

Example 1 with Defined_Reference

use of org.eclipse.titan.designer.AST.ASN1.Defined_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 2 with Defined_Reference

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

the class Exports method check.

/**
 * Checks this export list.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 */
public void check(final CompilationTimeStamp timestamp) {
    if (null != lastCompilationTimeStamp && !lastCompilationTimeStamp.isLess(timestamp)) {
        return;
    }
    if (exportAll) {
        lastCompilationTimeStamp = timestamp;
        return;
    }
    symbols.checkUniqueness(timestamp);
    for (int i = 0; i < symbols.size(); i++) {
        final List<ISubReference> list = new ArrayList<ISubReference>();
        list.add(new FieldSubReference(symbols.getNthElement(i)));
        final Defined_Reference reference = new Defined_Reference(null, list);
        /* check whether exists or not */
        module.getAssBySRef(timestamp, reference);
    }
    lastCompilationTimeStamp = timestamp;
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArrayList(java.util.ArrayList)

Example 3 with Defined_Reference

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

the class Referenced_ObjectSet method getRefdObjectClass.

/**
 * Returns the referenced ObjectClass. The evaluation depends on the type of the reference
 * @param timestamp
 * @return the referenced ObjectClass if found. Otherwise returns null.
 */
public ObjectClass getRefdObjectClass(final CompilationTimeStamp timestamp) {
    ObjectClass refdClass = null;
    if (reference instanceof InformationFromObj) {
        final ObjectClass tempGovernor = getRefdLast(timestamp, null).getMyGovernor();
        if (tempGovernor == null) {
            return null;
        }
        refdClass = tempGovernor.getRefdLast(timestamp, null);
        final FieldName fn = ((InformationFromObj) reference).getFieldName();
        if (fn.getNofFields() == 1) {
            final Identifier fieldId = fn.getFieldByIndex(0);
            final FieldSpecifications fss = refdClass.getFieldSpecifications();
            FieldSpecification fs = fss.getFieldSpecificationByIdentifier(fieldId);
            if (fs instanceof Undefined_FieldSpecification) {
                fs = ((Undefined_FieldSpecification) fs).getRealFieldSpecification();
            }
            switch(fs.getFieldSpecificationType()) {
                case FS_OS:
                    refdClass = ((ObjectSet_FieldSpecification) fs).getObjectClass().getRefdLast(timestamp, null);
                    break;
                case FS_T:
                    // TODO: implement the other cases
                    break;
                default:
                    // TODO: implement the other cases
                    break;
            }
        }
    } else if (reference instanceof Parameterised_Reference) {
        final Defined_Reference dref = ((Parameterised_Reference) reference).getRefDefdSimple();
        if (dref == null) {
            return null;
        }
        final Assignment ass = dref.getRefdAssignment(timestamp, false, null);
        if (ass instanceof ObjectSet_Assignment) {
            ass.check(timestamp);
            // experimental
            osReferenced = ((ObjectSet_Assignment) ass).getObjectSet(timestamp);
            refdClass = ((ObjectSet_Assignment) ass).getObjectSet(timestamp).getMyGovernor().getRefdLast(timestamp, null);
        }
    } else if (reference instanceof Defined_Reference) {
        final Assignment ass = ((Defined_Reference) reference).getRefdAssignment(timestamp, false, null);
        if (ass instanceof ObjectSet_Assignment) {
            ass.check(timestamp);
            // experimental
            osReferenced = ((ObjectSet_Assignment) ass).getObjectSet(timestamp);
            refdClass = ((ObjectSet_Assignment) ass).getObjectSet(timestamp).getMyGovernor().getRefdLast(timestamp, null);
        }
    } else {
        // to debug
        return refdClass;
    }
    return refdClass;
}
Also used : ObjectSet_Assignment(org.eclipse.titan.designer.AST.ASN1.ObjectSet_Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) ObjectClass(org.eclipse.titan.designer.AST.ASN1.ObjectClass) Identifier(org.eclipse.titan.designer.AST.Identifier) Parameterised_Reference(org.eclipse.titan.designer.AST.ASN1.Parameterised_Reference) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) ObjectSet_Assignment(org.eclipse.titan.designer.AST.ASN1.ObjectSet_Assignment) InformationFromObj(org.eclipse.titan.designer.AST.ASN1.InformationFromObj)

Example 4 with Defined_Reference

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

the class ImportModule method checkImports.

@Override
public /**
 * {@inheritDoc}
 */
void checkImports(final CompilationTimeStamp timestamp, final ModuleImportationChain referenceChain, final List<Module> moduleStack) {
    if (null != lastImportCheckTimeStamp && !lastImportCheckTimeStamp.isLess(timestamp)) {
        return;
    }
    symbols.checkUniqueness(timestamp);
    final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
    if (null == parser || null == identifier) {
        lastImportCheckTimeStamp = timestamp;
        // FIXME: is it correct? lastImportCheckTimeStamp will be set in extreme case only - very early running
        referredModule = null;
        return;
    }
    final Module temp = referredModule;
    referredModule = parser.getModuleByName(identifier.getName());
    if (temp != referredModule) {
        setUnhandledChange(true);
    }
    if (referredModule == null) {
        identifier.getLocation().reportSemanticError(MessageFormat.format(MISSINGMODULE, identifier.getDisplayName()));
    } else {
        if (!(referredModule instanceof ASN1Module)) {
            identifier.getLocation().reportSemanticError(MessageFormat.format(NOTASN1MODULE, identifier.getDisplayName()));
            lastImportCheckTimeStamp = timestamp;
            referredModule = null;
            return;
        }
        moduleStack.add(referredModule);
        if (!referenceChain.add(this)) {
            moduleStack.remove(moduleStack.size() - 1);
            lastImportCheckTimeStamp = timestamp;
            return;
        }
        referredModule.checkImports(timestamp, referenceChain, moduleStack);
        for (int i = 0; i < symbols.size(); i++) {
            final Identifier id = symbols.getNthElement(i);
            final List<ISubReference> list = new ArrayList<ISubReference>();
            list.add(new FieldSubReference(id));
            final Defined_Reference reference = new Defined_Reference(null, list);
            reference.setLocation(identifier.getLocation());
            if (null != referredModule.getAssBySRef(timestamp, reference)) {
                if (!((ASN1Module) referredModule).exportsSymbol(timestamp, id)) {
                    identifier.getLocation().reportSemanticError(MessageFormat.format(SYMBOLNOTEXPORTED, id.getDisplayName(), referredModule.getIdentifier().getDisplayName()));
                }
            }
        }
        moduleStack.remove(moduleStack.size() - 1);
    }
    lastImportCheckTimeStamp = timestamp;
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 5 with Defined_Reference

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

the class ASN1Module method getAssBySRef.

@Override
public /**
 * {@inheritDoc}
 */
Assignment getAssBySRef(final CompilationTimeStamp timestamp, final Reference reference, final IReferenceChain refChain) {
    Identifier moduleId = reference.getModuleIdentifier();
    final Identifier id = reference.getId();
    if (null == id) {
        return null;
    }
    Module module = null;
    if (null == moduleId || moduleId.getName().equals(identifier.getName())) {
        if (assignments.hasLocalAssignmentWithID(timestamp, id)) {
            return assignments.getLocalAssignmentByID(timestamp, id);
        }
        if (null != moduleId) {
            id.getLocation().reportSemanticError(MessageFormat.format(NOASSIGNMENT, id.getDisplayName(), identifier.getDisplayName()));
            return null;
        }
        if (imports.singularImportedSymbols_map.containsKey(id.getName())) {
            module = imports.singularImportedSymbols_map.get(id.getName());
            moduleId = module.getIdentifier();
            imports.getImportedModuleById(moduleId).setUsedForImportation();
        } else if (imports.pluralImportedSymbols.contains(id.getName())) {
            id.getLocation().reportSemanticError(MessageFormat.format(MORESYMBOLS, id.getDisplayName(), identifier.getDisplayName()));
            return null;
        } else {
            id.getLocation().reportSemanticError(MessageFormat.format(NOASSIGNMENTORSYMBOL, id.getDisplayName(), identifier.getDisplayName()));
            return null;
        }
    }
    if (null == module) {
        if (!imports.hasImportedModuleWithId(moduleId)) {
            moduleId.getLocation().reportSemanticError(MessageFormat.format(NOIMPORTEDMODULE, moduleId.getDisplayName()));
            return null;
        }
        if (!imports.getImportedModuleById(moduleId).hasSymbol(id)) {
            id.getLocation().reportSemanticError(MessageFormat.format(NOSYMBOLSIMPORTED, id.getDisplayName(), moduleId.getDisplayName()));
            return null;
        }
        imports.getImportedModuleById(moduleId).setUsedForImportation();
        final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
        if (null == parser) {
            return null;
        }
        module = parser.getModuleByName(moduleId.getName());
    }
    if (this == module || null == module) {
        return null;
    }
    final List<ISubReference> newSubreferences = new ArrayList<ISubReference>();
    newSubreferences.add(new FieldSubReference(id));
    final Defined_Reference finalReference = new Defined_Reference(null, newSubreferences);
    // FIXME add semantic check guard on project level.
    return module.getAssBySRef(timestamp, finalReference);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) Defined_Reference(org.eclipse.titan.designer.AST.ASN1.Defined_Reference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Aggregations

Defined_Reference (org.eclipse.titan.designer.AST.ASN1.Defined_Reference)6 ArrayList (java.util.ArrayList)4 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)4 Identifier (org.eclipse.titan.designer.AST.Identifier)3 IValue (org.eclipse.titan.designer.AST.IValue)2 Module (org.eclipse.titan.designer.AST.Module)2 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)2 ASN1Object (org.eclipse.titan.designer.AST.ASN1.ASN1Object)1 InformationFromObj (org.eclipse.titan.designer.AST.ASN1.InformationFromObj)1 ObjectClass (org.eclipse.titan.designer.AST.ASN1.ObjectClass)1 ObjectSet (org.eclipse.titan.designer.AST.ASN1.ObjectSet)1 ObjectSet_Assignment (org.eclipse.titan.designer.AST.ASN1.ObjectSet_Assignment)1 Parameterised_Reference (org.eclipse.titan.designer.AST.ASN1.Parameterised_Reference)1 Undefined_Block_Value (org.eclipse.titan.designer.AST.ASN1.values.Undefined_Block_Value)1 Assignment (org.eclipse.titan.designer.AST.Assignment)1 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)1 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)1