Search in sources :

Example 11 with Location

use of org.eclipse.titan.designer.AST.Location 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 12 with Location

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

the class FriendModule method updateSyntax.

/**
 * Handles the incremental parsing of this friend module declaration.
 *
 * @param reparser
 *                the parser doing the incremental parsing.
 * @param isDamaged
 *                true if the location contains the damaged area, false
 *                if only its' location needs to be updated.
 */
@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        boolean enveloped = false;
        int result = 1;
        final Location temporalIdentifier = identifier.getLocation();
        if (reparser.envelopsDamage(temporalIdentifier) || reparser.isExtending(temporalIdentifier)) {
            reparser.extendDamagedRegion(temporalIdentifier);
            final IIdentifierReparser r = new IdentifierReparser(reparser);
            result = r.parse();
            identifier = r.getIdentifier();
            // damage handled
            if (result == 0) {
                enveloped = true;
            } else {
                throw new ReParseException(result);
            }
        }
        if (withAttributesPath != null) {
            if (enveloped) {
                withAttributesPath.updateSyntax(reparser, false);
                reparser.updateLocation(withAttributesPath.getLocation());
            } else if (reparser.envelopsDamage(withAttributesPath.getLocation())) {
                reparser.extendDamagedRegion(withAttributesPath.getLocation());
                result = reparse(reparser);
            }
        }
        if (result != 0) {
            throw new ReParseException();
        }
        return;
    }
    reparser.updateLocation(identifier.getLocation());
    if (withAttributesPath != null) {
        withAttributesPath.updateSyntax(reparser, false);
        reparser.updateLocation(withAttributesPath.getLocation());
    }
}
Also used : IIdentifierReparser(org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser) IdentifierReparser(org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser) IIdentifierReparser(org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) Location(org.eclipse.titan.designer.AST.Location)

Example 13 with Location

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

the class AssignmentList_Parameter_Redirect method checkErroneous.

@Override
public /**
 * {@inheritDoc}
 */
void checkErroneous(final CompilationTimeStamp timestamp) {
    final HashMap<String, Parameter_Assignment> parameterMap = new HashMap<String, Parameter_Assignment>();
    for (int i = 0, size = assignments.getNofParameterAssignments(); i < size; i++) {
        final Parameter_Assignment assignment = assignments.getParameterAssignmentByIndex(i);
        final String name = assignment.getIdentifier().getName();
        if (parameterMap.containsKey(name)) {
            assignment.getLocation().reportSemanticError(MessageFormat.format("Duplicate redirect for parameter `{0}''", assignment.getIdentifier().getDisplayName()));
            final Location otherLocation = parameterMap.get(name).getLocation();
            otherLocation.reportSemanticWarning(MessageFormat.format("A variable entry for parameter `{0}'' is already given here", assignment.getIdentifier().getDisplayName()));
        } else {
            parameterMap.put(name, assignment);
        }
        checkVariableReference(timestamp, assignment.getReference(), null);
    }
}
Also used : HashMap(java.util.HashMap) Location(org.eclipse.titan.designer.AST.Location)

Example 14 with Location

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

the class ImportModule method updateSyntax.

/**
 * Handles the incremental parsing of this module importation.
 *
 * @param reparser
 *                the parser doing the incremental parsing.
 * @param isDamaged
 *                true if the location contains the damaged area, false
 *                if only its' location needs to be updated.
 */
@Override
public /**
 * {@inheritDoc}
 */
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
    if (isDamaged) {
        boolean enveloped = false;
        final Location temporalIdentifier = identifier.getLocation();
        if (reparser.envelopsDamage(temporalIdentifier) || reparser.isExtending(temporalIdentifier)) {
            reparser.extendDamagedRegion(temporalIdentifier);
            final IIdentifierReparser r = new IdentifierReparser(reparser);
            final int result = r.parse();
            identifier = r.getIdentifier();
            // damage handled
            if (result == 0) {
                enveloped = true;
            } else {
                throw new ReParseException(result);
            }
        }
        if (withAttributesPath != null) {
            if (enveloped) {
                withAttributesPath.updateSyntax(reparser, false);
                reparser.updateLocation(withAttributesPath.getLocation());
            } else if (reparser.envelopsDamage(withAttributesPath.getLocation())) {
                reparser.extendDamagedRegion(withAttributesPath.getLocation());
                final int result = reparse(reparser);
                if (result != 0) {
                    throw new ReParseException();
                }
                enveloped = true;
            }
        }
        if (!enveloped) {
            throw new ReParseException(1);
        }
        return;
    }
    reparser.updateLocation(identifier.getLocation());
    if (withAttributesPath != null) {
        withAttributesPath.updateSyntax(reparser, false);
        reparser.updateLocation(withAttributesPath.getLocation());
    }
}
Also used : IIdentifierReparser(org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser) IdentifierReparser(org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser) IIdentifierReparser(org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser) ReParseException(org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException) Location(org.eclipse.titan.designer.AST.Location)

Example 15 with Location

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

the class TTCN3Module method getAssBySRef.

@Override
public /**
 * {@inheritDoc}
 */
Assignment getAssBySRef(final CompilationTimeStamp timestamp, final Reference reference, final IReferenceChain refChain) {
    // if a moduleId is present, that import (or the actual module)
    // must be searched
    final Identifier moduleId = reference.getModuleIdentifier();
    final Location referenceLocation = reference.getLocation();
    final Identifier id = reference.getId();
    if (id == null) {
        return null;
    }
    Assignment temporalAssignment = null;
    if (moduleId == null) {
        // no module name is given in the reference
        if ("anytype".equals(id.getTtcnName())) {
            return anytypeDefinition;
        }
        Assignment tempResult = null;
        for (final ImportModule impMod : importedModules) {
            if (impMod.getReferredModule() != null) {
                final ModuleImportationChain referenceChain = new ModuleImportationChain(ModuleImportationChain.CIRCULARREFERENCE, false);
                tempResult = impMod.importAssignment(timestamp, referenceChain, identifier, reference, new ArrayList<ModuleImportation>());
                if (tempResult != null && !tempResult.getMyScope().getModuleScope().isVisible(timestamp, this.getIdentifier(), tempResult)) {
                    tempResult = null;
                }
                if (tempResult != null) {
                    if (temporalAssignment == null) {
                        temporalAssignment = tempResult;
                    } else if (temporalAssignment != tempResult) {
                        reference.getLocation().reportSemanticError("It is not possible to resolve this reference unambigously, as  it can be resolved to `" + temporalAssignment.getFullName() + "' and to `" + tempResult.getFullName() + "'");
                        return null;
                    }
                }
            }
        }
        if (temporalAssignment != null) {
            return temporalAssignment;
        }
        referenceLocation.reportSemanticError(MessageFormat.format(MISSINGREFERENCE, id.getDisplayName(), identifier.getDisplayName()));
        missingReferences.add(reference);
    } else if (moduleId.getName().equals(name)) {
        // the reference points to the own module
        if ("anytype".equals(id.getTtcnName())) {
            return anytypeDefinition;
        }
        temporalAssignment = definitions.getLocalAssignmentByID(timestamp, id);
        if (temporalAssignment == null) {
            referenceLocation.reportSemanticError(MessageFormat.format(MISSINGREFERENCE, id.getDisplayName(), identifier.getDisplayName()));
        }
    } else {
        // the reference points to another module
        for (final ImportModule impMod : importedModules) {
            if (moduleId.getName().equals(impMod.getName())) {
                if (impMod.getReferredModule() == null) {
                    return temporalAssignment;
                }
                final ModuleImportationChain referenceChain = new ModuleImportationChain(ModuleImportationChain.CIRCULARREFERENCE, false);
                temporalAssignment = impMod.importAssignment(timestamp, referenceChain, identifier, reference, new ArrayList<ModuleImportation>());
                if (!impMod.getReferredModule().isVisible(timestamp, this.getIdentifier(), temporalAssignment)) {
                    temporalAssignment = null;
                }
                if (temporalAssignment == null) {
                    referenceLocation.reportSemanticError(MessageFormat.format(MISSINGREFERENCE, id.getDisplayName(), impMod.getIdentifier().getDisplayName()));
                }
                return temporalAssignment;
            }
        }
        referenceLocation.reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTMISSINGIMPORTEDMODULE, GeneralConstants.WARNING, null), MessageFormat.format(ImportModule.MISSINGMODULE, moduleId.getDisplayName()));
        missingReferences.add(reference);
    }
    return temporalAssignment;
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Identifier(org.eclipse.titan.designer.AST.Identifier) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ModuleImportationChain(org.eclipse.titan.designer.AST.ModuleImportationChain) Location(org.eclipse.titan.designer.AST.Location) ModuleImportation(org.eclipse.titan.designer.AST.ModuleImportation)

Aggregations

Location (org.eclipse.titan.designer.AST.Location)109 Identifier (org.eclipse.titan.designer.AST.Identifier)24 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)24 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)21 IIdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser)18 IdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser)18 Module (org.eclipse.titan.designer.AST.Module)16 ArrayList (java.util.ArrayList)15 IFile (org.eclipse.core.resources.IFile)13 HashMap (java.util.HashMap)11 Reference (org.eclipse.titan.designer.AST.Reference)10 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)10 Assignment (org.eclipse.titan.designer.AST.Assignment)9 IDocument (org.eclipse.jface.text.IDocument)8 InsertEdit (org.eclipse.text.edits.InsertEdit)8 ILocateableNode (org.eclipse.titan.designer.AST.ILocateableNode)8 CoreException (org.eclipse.core.runtime.CoreException)7 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)7 TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)7 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7