Search in sources :

Example 26 with Type

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

the class TTCN3_Set_Type method checkThisValueSet.

/**
 * Checks the Set_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 set type.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expectedValue the kind of value we expect to find.
 * @param incompleteAllowed wheather incomplete value is allowed or not.
 * @param impliciOmit true if the implicit omit optional attribute was set
 *            for the value, false otherwise
 */
private boolean checkThisValueSet(final CompilationTimeStamp timestamp, final Set_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean impliciOmit, final boolean strElem) {
    value.removeGeneratedValues();
    boolean selfReference = false;
    final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
    final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
    final boolean isAsn = value.isAsn();
    final int nofValueComponents = value.getNofComponents();
    for (int i = 0; i < nofValueComponents; i++) {
        final NamedValue namedValue = value.getSequenceValueByIndex(i);
        final Identifier valueId = namedValue.getName();
        if (!realComponents.containsKey(valueId.getName())) {
            namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDASN1 : NONEXISTENTFIELDTTCN3, namedValue.getName().getDisplayName(), getTypename()));
        } else {
            if (componentMap.containsKey(valueId.getName())) {
                namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? DUPLICATEFIELDAGAINASN1 : DUPLICATEFIELDAGAINTTCN3, valueId.getDisplayName()));
                componentMap.get(valueId.getName()).getLocation().reportSingularSemanticError(MessageFormat.format(isAsn ? DUPLICATEFIELDFIRSTASN1 : DUPLICATEFIELDFIRSTTTCN3, valueId.getDisplayName()));
            } else {
                componentMap.put(valueId.getName(), namedValue);
            }
            final CompField componentField = realComponents.get(valueId.getName());
            final Type type = componentField.getType();
            final IValue componentValue = namedValue.getValue();
            if (componentValue != null) {
                componentValue.setMyGovernor(type);
                if (Value_type.NOTUSED_VALUE.equals(componentValue.getValuetype())) {
                    if (!incompleteAllowed) {
                        componentValue.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
                    }
                } else {
                    final IValue tempValue = type.checkThisValueRef(timestamp, componentValue);
                    selfReference |= type.checkThisValue(timestamp, tempValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, componentField.isOptional(), true, impliciOmit, strElem));
                }
            }
        }
    }
    if (!incompleteAllowed || strictConstantCheckingSeverity) {
        final int nofTypeComponents = realComponents.size();
        CompField field;
        for (int i = 0; i < nofTypeComponents; i++) {
            field = compFieldMap.fields.get(i);
            final Identifier id = field.getIdentifier();
            if (!componentMap.containsKey(id.getName())) {
                if (field.isOptional() && impliciOmit) {
                    value.addNamedValue(new NamedValue(new Identifier(Identifier_type.ID_TTCN, id.getDisplayName()), new Omit_Value(), false));
                } else {
                    value.getLocation().reportSemanticError(MessageFormat.format(isAsn ? MISSINGFIELDASN1 : MISSINGFIELDTTCN3, id.getDisplayName()));
                }
            }
        }
    }
    value.setLastTimeChecked(timestamp);
    return selfReference;
}
Also used : HashMap(java.util.HashMap) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Type(org.eclipse.titan.designer.AST.Type) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) Omit_Value(org.eclipse.titan.designer.AST.TTCN3.values.Omit_Value)

Example 27 with Type

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

the class ExtractToFunctionRefactoring method createFunction.

public WorkspaceJob createFunction() {
    final WorkspaceJob job = new WorkspaceJob("ExtractToFunction: creating new function text") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            final StatementList selectedStatements = selectionFinder.getSelectedStatements();
            final Module selectedModule = getSelectedModule();
            final IFile selectedFile = getSelectedFile();
            final Reference runsOnRef = selectionFinder.getRunsOnRef();
            final Type returnType = selectionFinder.getReturnType();
            final ReturnCertainty retCertainty = selectionFinder.getReturnCertainty();
            parentFunc = selectionFinder.getParentFunc();
            if (parentFunc == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Could not find the enclosing function of the selection! ");
                return Status.CANCEL_STATUS;
            }
            if (selectionFinder.getInsertLoc() < 0) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Could not calculate the insert location! ");
                return Status.CANCEL_STATUS;
            }
            if (selectedStatements == null || selectedStatements.isEmpty() || selectedModule == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): No or invalid selection! ");
                return Status.CANCEL_STATUS;
            }
            // collect params and find runs on clause
            paramCollector = new ParamCollector(project, selectedStatements, selectedModule);
            paramCollector.perform();
            List<Param> params = paramCollector.getParams();
            // 
            if (params == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to collect params! ");
                return Status.CANCEL_STATUS;
            }
            // create new function text
            functionCreator = new FunctionCreator(selectedStatements, selectedFile, newFuncName, params, runsOnRef, returnType, retCertainty);
            functionCreator.perform();
            functionText = functionCreator.getFunctionText();
            if (functionText == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to create function text! ");
                return Status.CANCEL_STATUS;
            }
            functionCallText = functionCreator.getFunctionCallText();
            if (functionCallText == null) {
                ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to create function call text! ");
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return job;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Type(org.eclipse.titan.designer.AST.Type) IFile(org.eclipse.core.resources.IFile) Reference(org.eclipse.titan.designer.AST.Reference) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ReturnCertainty(org.eclipse.titanium.refactoring.function.ReturnVisitor.ReturnCertainty) Module(org.eclipse.titan.designer.AST.Module)

Example 28 with Type

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

the class SelectionFinder method createModuleParListForSaving.

public String createModuleParListForSaving() {
    if (modulePars == null || modulePars.isEmpty()) {
        return "<empty>";
    }
    final List<ModuleParListRecord> records = new ArrayList<ModuleParListRecord>();
    for (Def_ModulePar def : modulePars) {
        final IResource f = def.getLocation().getFile();
        if (!(f instanceof IFile)) {
            ErrorReporter.logError("ExtractModulePar/SelectionFinder: IResource `" + f.getName() + "' is not an IFile.");
            continue;
        }
        final Identifier id = def.getIdentifier();
        final Type t = def.getType(CompilationTimeStamp.getBaseTimestamp());
        records.add(new ModuleParListRecord(def.getMyScope().getModuleScope().getIdentifier().getDisplayName(), id.getDisplayName(), t.getTypename()));
    }
    // 
    Collections.sort(records);
    final StringBuilder sb = new StringBuilder();
    for (ModuleParListRecord rec : records) {
        sb.append(rec.toString()).append('\n');
    }
    return sb.toString();
}
Also used : Type(org.eclipse.titan.designer.AST.Type) IFile(org.eclipse.core.resources.IFile) Identifier(org.eclipse.titan.designer.AST.Identifier) ArrayList(java.util.ArrayList) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) IResource(org.eclipse.core.resources.IResource)

Example 29 with Type

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

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

the class FormalParameterParser method process.

@Override
public Scope process(IVisitableNode node) {
    if (node instanceof FormalParameter) {
        FormalParameter parameter = (FormalParameter) node;
        name = parameter.getIdentifier().toString();
    }
    if (node instanceof Type) {
        type = Util.getTypeName((Type) node);
    }
    return this;
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) Type(org.eclipse.titan.designer.AST.Type)

Aggregations

Type (org.eclipse.titan.designer.AST.Type)69 IType (org.eclipse.titan.designer.AST.IType)56 Identifier (org.eclipse.titan.designer.AST.Identifier)35 IValue (org.eclipse.titan.designer.AST.IValue)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)13 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)12 HashMap (java.util.HashMap)11 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)10 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)9 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)8 Reference (org.eclipse.titan.designer.AST.Reference)8 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)8 Attribute_Type (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type)7 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)6 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)6 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)6 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)6 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)6