Search in sources :

Example 86 with Identifier

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

the class DependencyCollector method filterImportDefinitions.

/**
 * Returns the <code>importDefs</code> list, with the {@link ImportModule}s removed which refer to
 * modules that are not contained in the <code>allFiles</code> set.
 */
private static void filterImportDefinitions(final Set<IResource> allFiles, final List<ImportModule> importDefs, final ProjectSourceParser projParser) {
    final List<Identifier> allFileIds = new ArrayList<Identifier>(allFiles.size());
    for (IResource r : allFiles) {
        if (!(r instanceof IFile)) {
            continue;
        }
        final IFile f = (IFile) r;
        final Module m = projParser.containedModule(f);
        allFileIds.add(m.getIdentifier());
    }
    final ListIterator<ImportModule> importIt = importDefs.listIterator();
    while (importIt.hasNext()) {
        final ImportModule im = importIt.next();
        final Identifier id = im.getIdentifier();
        if (!allFileIds.contains(id)) {
            importIt.remove();
        }
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) FriendModule(org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule) Module(org.eclipse.titan.designer.AST.Module) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) IResource(org.eclipse.core.resources.IResource) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)

Example 87 with Identifier

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

the class DependencyCollector method filterFriendDefinitions.

/**
 * Returns the <code>friendDefs</code> list, with the {@link FriendModule}s removed which refer to
 * modules that are not contained in the <code>allFiles</code> set.
 */
private static void filterFriendDefinitions(final Set<IResource> allFiles, final List<FriendModule> friendDefs, final ProjectSourceParser projParser) {
    final List<Identifier> allFileIds = new ArrayList<Identifier>(allFiles.size());
    for (IResource r : allFiles) {
        if (!(r instanceof IFile)) {
            continue;
        }
        final IFile f = (IFile) r;
        final Module m = projParser.containedModule(f);
        allFileIds.add(m.getIdentifier());
    }
    final ListIterator<FriendModule> importIt = friendDefs.listIterator();
    while (importIt.hasNext()) {
        final FriendModule fm = importIt.next();
        final Identifier id = fm.getIdentifier();
        if (!allFileIds.contains(id)) {
            importIt.remove();
        }
    }
}
Also used : FriendModule(org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule) Identifier(org.eclipse.titan.designer.AST.Identifier) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) FriendModule(org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule) Module(org.eclipse.titan.designer.AST.Module) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) IResource(org.eclipse.core.resources.IResource)

Example 88 with Identifier

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

the class TemplateParser method process.

@Override
public Scope process(IVisitableNode node) {
    if (node instanceof Identifier) {
        name = node.toString();
        // TODO : find a more sophisticated way of storing symbols (e.g. SymbolTable)
        myASTVisitor.nodeNameNodeTypeHashMap.put(name, "template");
    }
    if (node instanceof Type) {
        type = Util.getTypeName((Type) node);
        template = new Template(name, type);
        return Action.skip(Type.class, this);
    }
    if (node instanceof FormalParameterList) {
        return new FormalParameterParser(this, template);
    }
    // is a modification
    if (node instanceof Reference) {
        Reference reference = (Reference) node;
        String basename = reference.getId().toString();
        Template base = registry.find(basename);
        // TODO : templates need a base value as a fallback
        // TODO : this base value should be used as a reference, to diff against
        // TODO : this was a hotfix for the union types to work
        String type = base.getValue().getType();
        template.setValue(new Value(type, (code, indent) -> code.append("(", type, ") ").append(basename, "()")));
        isModification = true;
        return Action.skip(Reference.class, this);
    }
    if (node instanceof TTCN3Template) {
        if (isModification) {
            return ModificationParser.getScope(this, template, "", type, node);
        }
        return TemplateValueParser.getScope(this, template, type, node);
    }
    return this;
}
Also used : IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Reference(org.eclipse.titan.designer.AST.Reference) Type(org.eclipse.titan.designer.AST.Type) Scope(org.eclipse.titan.codegenerator.Scope) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) org.eclipse.titan.codegenerator.myASTVisitor(org.eclipse.titan.codegenerator.myASTVisitor) Identifier(org.eclipse.titan.designer.AST.Identifier) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Type(org.eclipse.titan.designer.AST.Type) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Identifier(org.eclipse.titan.designer.AST.Identifier) Reference(org.eclipse.titan.designer.AST.Reference) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Example 89 with Identifier

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

the class ASN1_Integer_Type method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (null != myScope) {
        final Module module = myScope.getModuleScope();
        if (null != module) {
            if (module.getSkippedFromSemanticChecking()) {
                return;
            }
        }
    }
    isErroneous = false;
    if (null == namedNumbers) {
        parseBlockInt();
    }
    if (isErroneous || null == namedNumbers) {
        return;
    }
    /* check named numbers */
    final Map<String, Identifier> nameMap = new HashMap<String, Identifier>();
    for (int i = 0, size = namedNumbers.getSize(); i < size; i++) {
        final NamedValue namedValue = namedNumbers.getNamedValueByIndex(i);
        final Identifier identifier = namedValue.getName();
        if (nameMap.containsKey(identifier.getName())) {
            final Location tempLocation = nameMap.get(identifier.getName()).getLocation();
            tempLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            identifier.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        } else {
            nameMap.put(identifier.getName(), identifier);
        }
    }
    final Map<Integer, NamedValue> valueMap = new HashMap<Integer, NamedValue>();
    for (int i = 0, size = namedNumbers.getSize(); i < size; i++) {
        final NamedValue namedValue = namedNumbers.getNamedValueByIndex(i);
        final IValue value = namedValue.getValue();
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = value.getValueRefdLast(timestamp, referenceChain);
        referenceChain.release();
        if (last.getIsErroneous(timestamp)) {
            continue;
        }
        switch(last.getValuetype()) {
            case INTEGER_VALUE:
                {
                    final Integer_Value integerValue = (Integer_Value) last;
                    if (integerValue.isNative()) {
                        final Integer intValue = Integer.valueOf(integerValue.intValue());
                        if (valueMap.containsKey(intValue)) {
                            value.getLocation().reportSemanticError(MessageFormat.format("Duplicate number {0} for name `{1}''", intValue, namedValue.getName().getDisplayName()));
                            final NamedValue temp = valueMap.get(intValue);
                            temp.getLocation().reportSemanticError(MessageFormat.format("Number {0} is already assigned to name `{1}''", intValue, temp.getName().getDisplayName()));
                        } else {
                            valueMap.put(intValue, namedValue);
                        }
                    } else {
                        value.getLocation().reportSemanticError(MessageFormat.format("Integer value `{0}'' is too big to be used as a named number", integerValue.getValueValue()));
                        value.setIsErroneous(true);
                    }
                    break;
                }
            default:
                namedValue.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for named number `{0}''", namedValue.getName().getDisplayName()));
                value.setIsErroneous(true);
                break;
        }
    }
    nameMap.clear();
    if (null != constraints) {
        constraints.check(timestamp);
    }
    if (myScope != null) {
        checkEncode(timestamp);
        checkVariants(timestamp);
    }
}
Also used : HashMap(java.util.HashMap) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Named_Integer_Value(org.eclipse.titan.designer.AST.ASN1.values.Named_Integer_Value) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Module(org.eclipse.titan.designer.AST.Module) Location(org.eclipse.titan.designer.AST.Location)

Example 90 with Identifier

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

the class ASN1_Sequence_Type method getFieldType.

// This is the same as in ASN1_Set_type
@Override
public /**
 * {@inheritDoc}
 */
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
    final List<ISubReference> subreferences = reference.getSubreferences();
    if (subreferences.size() <= actualSubReference) {
        return this;
    }
    final ISubReference subreference = subreferences.get(actualSubReference);
    switch(subreference.getReferenceType()) {
        case arraySubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDSUBREFERENCE, getTypename()));
            return null;
        case fieldSubReference:
            if (components == null) {
                return null;
            }
            final Identifier id = subreference.getId();
            final CompField compField = components.getCompByName(id);
            if (compField == null) {
                subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.NONEXISTENTSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
                return null;
            }
            if (interruptIfOptional && compField.isOptional()) {
                return null;
            }
            final Expected_Value_type internalExpectation = expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
            return compField.getType().getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
        case parameterisedSubReference:
            subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
            return null;
        default:
            subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
            return null;
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)

Aggregations

Identifier (org.eclipse.titan.designer.AST.Identifier)176 IType (org.eclipse.titan.designer.AST.IType)75 ISubReference (org.eclipse.titan.designer.AST.ISubReference)57 IValue (org.eclipse.titan.designer.AST.IValue)39 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)38 Type (org.eclipse.titan.designer.AST.Type)35 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)33 Assignment (org.eclipse.titan.designer.AST.Assignment)25 ArrayList (java.util.ArrayList)24 Location (org.eclipse.titan.designer.AST.Location)24 Reference (org.eclipse.titan.designer.AST.Reference)22 Module (org.eclipse.titan.designer.AST.Module)21 HashMap (java.util.HashMap)16 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)15 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)12 Value (org.eclipse.titan.designer.AST.Value)12 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)11 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)10 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)10 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)10