Search in sources :

Example 1 with Def_ModulePar

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar in project titan.EclipsePlug-ins by eclipse.

the class Component_Type method checkExpressionOperandComponentRefernce.

/**
 * Checks if the provided value is a reference to a component or not.
 *
 * @param timestamp the timestamp of the actual semantic check cycle.
 * @param value the value to be checked
 * @param expected_value the value kind expected from the actual parameter.
 */
public static void checkExpressionOperandComponentRefernce(final CompilationTimeStamp timestamp, final IValue value, final String operationName) {
    switch(value.getValuetype()) {
        case EXPRESSION_VALUE:
            {
                final Expression_Value expression = (Expression_Value) value;
                if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
                    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    final IValue last = value.getValueRefdLast(timestamp, chain);
                    chain.release();
                    if (last == null || last.getIsErroneous(timestamp)) {
                        value.setIsErroneous(true);
                        return;
                    }
                    IType type = last.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                    if (type == null) {
                        value.setIsErroneous(true);
                        return;
                    }
                    type = type.getTypeRefdLast(timestamp);
                    if (type.getIsErroneous(timestamp)) {
                        value.setIsErroneous(true);
                        // don't let spread an earlier mistake
                        return;
                    }
                    if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                        value.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                        value.setIsErroneous(true);
                        return;
                    }
                }
                break;
            }
        case REFERENCED_VALUE:
            {
                final Reference reference = ((Referenced_Value) value).getReference();
                final Assignment assignment = reference.getRefdAssignment(timestamp, true);
                if (assignment == null) {
                    value.setIsErroneous(true);
                    return;
                }
                switch(assignment.getAssignmentType()) {
                    case A_CONST:
                        {
                            IType type = ((Def_Const) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            IValue tempValue = ((Def_Const) assignment).getValue();
                            if (tempValue == null) {
                                return;
                            }
                            IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                            tempValue = tempValue.getReferencedSubValue(timestamp, reference, 1, chain);
                            chain.release();
                            if (tempValue == null) {
                                return;
                            }
                            chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                            tempValue = tempValue.getValueRefdLast(timestamp, chain);
                            chain.release();
                            if (Value_type.TTCN3_NULL_VALUE.equals(tempValue.getValuetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
                                value.setIsErroneous(true);
                                return;
                            }
                            if (!Value_type.EXPRESSION_VALUE.equals(tempValue.getValuetype())) {
                                return;
                            }
                            switch(((Expression_Value) tempValue).getOperationType()) {
                                case MTC_COMPONENT_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `mtc''", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                case COMPONENT_NULL_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                case SYSTEM_COMPONENT_OPERATION:
                                    reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `system''", operationName));
                                    value.setIsErroneous(true);
                                    return;
                                default:
                                    break;
                            }
                            break;
                        }
                    case A_EXT_CONST:
                        {
                            IType type = ((Def_ExternalConst) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_MODULEPAR:
                        {
                            IType type = ((Def_ModulePar) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_VAR:
                        {
                            IType type = ((Def_Var) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_FUNCTION_RVAL:
                        {
                            IType type = ((Def_Function) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_EXT_FUNCTION_RVAL:
                        {
                            IType type = ((Def_Extfunction) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    case A_PAR_VAL:
                    case A_PAR_VAL_IN:
                    case A_PAR_VAL_OUT:
                    case A_PAR_VAL_INOUT:
                        {
                            IType type = ((FormalParameter) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
                            if (type == null) {
                                value.setIsErroneous(true);
                                return;
                            }
                            type = type.getTypeRefdLast(timestamp);
                            if (type.getIsErroneous(timestamp)) {
                                value.setIsErroneous(true);
                                // don't let spread an earlier mistake
                                return;
                            }
                            if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
                                reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
                                value.setIsErroneous(true);
                                return;
                            }
                            break;
                        }
                    default:
                        reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' should be a component reference instead of `{1}''", operationName, assignment.getDescription()));
                        value.setIsErroneous(true);
                        return;
                }
                break;
            }
        default:
            // the error was already reported if possible.
            return;
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) IType(org.eclipse.titan.designer.AST.IType)

Example 2 with Def_ModulePar

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar in project titan.EclipsePlug-ins by eclipse.

the class TypenameInDef method process.

@Override
protected void process(final IVisitableNode node, final Problems problems) {
    if (!(node instanceof Def_Const) && !(node instanceof Def_ExternalConst) && !(node instanceof Def_Extfunction) && !(node instanceof Def_Function) && !(node instanceof Def_ModulePar) && !(node instanceof Def_Template) && !(node instanceof Def_Var_Template) && !(node instanceof Def_Var)) {
        return;
    }
    final Definition s = (Definition) node;
    check(s.getIdentifier(), s.getType(timestamp), s.getDescription(), problems);
}
Also used : Def_ExternalConst(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst) Def_Extfunction(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Extfunction) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template) Def_Function(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)

Example 3 with Def_ModulePar

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar 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 4 with Def_ModulePar

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar in project titan.EclipsePlug-ins by eclipse.

the class SelectionFinder method perform.

public void perform() {
    modulePars = new HashSet<Def_ModulePar>();
    final Collection<Module> modules = GlobalParser.getProjectSourceParser(project).getModules();
    for (Module m : modules) {
        final ModuleParFinder vis = new ModuleParFinder();
        m.accept(vis);
        modulePars.addAll(vis.getModulePars());
    }
}
Also used : Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) Module(org.eclipse.titan.designer.AST.Module)

Example 5 with Def_ModulePar

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar in project titan.EclipsePlug-ins by eclipse.

the class ASTNode method getT3Doc.

// FIXME: this does not belong here, ASTNodes in general don't have comments
public T3Doc getT3Doc(final Location location) {
    if (this instanceof Def_ModulePar) {
        final String st1 = this.getFullName().toString();
        final String st = st1.substring(st1.lastIndexOf('.') + 1);
        return new T3Doc(this.getCommentLocation(), st);
    }
    if (this.getCommentLocation() != null) {
        return new T3Doc(this.getCommentLocation());
    }
    if (this instanceof ILocateableNode) {
        final ILocateableNode iloc = (ILocateableNode) this;
        // ToDo check scopes that do not matter
        final Scope scope = this.getMyScope();
        final Assignment assignment = scope.getModuleScope().getEnclosingAssignment(iloc.getLocation().getOffset());
        if (assignment == null || assignment == this || assignment.getMyScope() instanceof Definitions) {
            return null;
        }
        final T3Doc parentT3doc = assignment.getT3Doc(location);
        if (parentT3doc != null) {
            // if it is a type assignment/definition then detect if we are in a field
            if (assignment.getAssignmentType() == Assignment_type.A_TYPE) {
                final IType type = assignment.getType(CompilationTimeStamp.getBaseTimestamp());
                if (type == null) {
                    return null;
                }
                // Reference finder - wonderful
                final ReferenceFinder rf = new ReferenceFinder(assignment);
                rf.scope = this.getMyScope().getModuleScope().getSmallestEnclosingScope(iloc.getLocation().getOffset());
                rf.type = assignment.getType(CompilationTimeStamp.getBaseTimestamp());
                type.getEnclosingField(location.getOffset(), rf);
                String st = null;
                if (rf.fieldId != null) {
                    st = rf.fieldId.getDisplayName();
                } else {
                    final String st1 = this.getFullName().toString();
                    st = st1.substring(st1.lastIndexOf('.') + 1);
                }
                // Get member information if available
                if (parentT3doc.getMembers() != null) {
                    final String desc = parentT3doc.getMembers().get(st);
                    if (desc != null) {
                        return new T3Doc(desc);
                    }
                }
            } else if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
                final String st1 = this.getFullName().toString();
                final String st = st1.substring(st1.lastIndexOf('.') + 1);
                String desc = null;
                if (parentT3doc.getMembers() != null) {
                    desc = parentT3doc.getMembers().get(st);
                }
                if (parentT3doc.getParams() != null) {
                    desc = parentT3doc.getParams().get(st);
                }
                if (desc != null) {
                    return new T3Doc(desc);
                }
            } else if (assignment.getAssignmentType() == Assignment_type.A_FUNCTION || assignment.getAssignmentType() == Assignment_type.A_FUNCTION_RTEMP || assignment.getAssignmentType() == Assignment_type.A_FUNCTION_RVAL) {
                final String st1 = this.getFullName().toString();
                final String st = st1.substring(st1.lastIndexOf('.') + 1);
                if (parentT3doc.getParams() != null) {
                    final String desc = parentT3doc.getParams().get(st);
                    if (desc != null) {
                        return new T3Doc(desc);
                    }
                }
            }
        }
    }
    return null;
}
Also used : Definitions(org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) T3Doc(org.eclipse.titan.designer.editors.T3Doc)

Aggregations

Def_ModulePar (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar)7 Module (org.eclipse.titan.designer.AST.Module)3 Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)3 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 Assignment (org.eclipse.titan.designer.AST.Assignment)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 IValue (org.eclipse.titan.designer.AST.IValue)2 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)2 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 CoreException (org.eclipse.core.runtime.CoreException)1