Search in sources :

Example 21 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class ContentAssistProcessor method computeCompletionProposals.

// FIXME add semantic check guard on project level.
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
    if (editor == null) {
        return new ICompletionProposal[] {};
    }
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        return new ICompletionProposal[] {};
    }
    IDocument doc = viewer.getDocument();
    TTCN3ReferenceParser refParser = new TTCN3ReferenceParser(true);
    Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
    if (ref == null || ref.getSubreferences().isEmpty()) {
        return new ICompletionProposal[] {};
    }
    Scope scope = null;
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    Module tempModule = projectSourceParser.containedModule(file);
    String moduleName = null;
    if (tempModule != null) {
        moduleName = tempModule.getName();
        scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
        ref.setMyScope(scope);
        ref.detectModid();
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
        TITANDebugConsole.println("parsed the reference: " + ref);
    }
    TemplateContextType contextType = new TemplateContextType(TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, TTCN3CodeSkeletons.CONTEXT_NAME);
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
    propCollector.setProjectParser(projectSourceParser);
    if (moduleName == null) {
        // rootless behavior
        if (ref.getModuleIdentifier() == null) {
            Set<String> moduleNames = projectSourceParser.getKnownModuleNames();
            Module module;
            for (String name : moduleNames) {
                module = projectSourceParser.getModuleByName(name);
                if (module != null) {
                    propCollector.addProposal(name, name, ImageCache.getImage("ttcn.gif"), TTCN3Module.MODULE);
                    module.getAssignments().addProposal(propCollector);
                }
            }
        } else {
            Module module = projectSourceParser.getModuleByName(ref.getModuleIdentifier().getName());
            if (module != null) {
                module.getAssignments().addProposal(propCollector);
            }
        }
    } else {
        /*
			 * search for the best scope in the module's scope
			 * hierarchy and call proposal adding function on the
			 * found scope instead of what can be found here
			 */
        if (scope != null) {
            scope.addProposal(propCollector);
        }
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    if (ref.getSubreferences().size() != 1) {
        if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
            propCollector.sortAll();
        }
        return propCollector.getCompletitions();
    }
    Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
    for (String knownModuleName : knownModuleNames) {
        Identifier tempIdentifier = new Identifier(Identifier_type.ID_NAME, knownModuleName);
        Module tempModule2 = projectSourceParser.getModuleByName(knownModuleName);
        propCollector.addProposal(tempIdentifier, ImageCache.getImage(tempModule2.getOutlineIcon()), "module");
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    if (ref.getModuleIdentifier() == null) {
        if (scope == null) {
            TTCN3CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
        } else {
            scope.addSkeletonProposal(propCollector);
        }
        propCollector.addTemplateProposal("refers", new Template("refers( function/altstep/testcase name )", "", propCollector.getContextIdentifier(), "refers( ${fatName} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
        propCollector.addTemplateProposal("derefers", new Template("derefers( function/altstep/testcase name )(parameters)", "", propCollector.getContextIdentifier(), "derefers( ${fatName} ) ( ${parameters} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
        propCollector.sortTillMarked();
        propCollector.markPosition();
        TTCN3CodeSkeletons.addPredefinedSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
        if (scope == null) {
            TTCN3Keywords.addKeywordProposals(propCollector);
        } else {
            scope.addKeywordProposal(propCollector);
        }
        propCollector.sortTillMarked();
        propCollector.markPosition();
    } else {
        if (scope == null || !(scope instanceof StatementBlock)) {
            if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
                propCollector.sortAll();
            }
            return propCollector.getCompletitions();
        }
        String fakeModule = ref.getModuleIdentifier().getName();
        if ("any component".equals(fakeModule) || "all component".equals(fakeModule)) {
            Component_Type.addAnyorAllProposal(propCollector, 0);
        } else if ("any port".equals(fakeModule) || "all port".equals(fakeModule)) {
            PortTypeBody.addAnyorAllProposal(propCollector, 0);
        } else if ("any timer".equals(fakeModule) || "all timer".equals(fakeModule)) {
            Timer.addAnyorAllProposal(propCollector, 0);
        }
    }
    if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
        propCollector.sortAll();
    }
    return propCollector.getCompletitions();
}
Also used : IFile(org.eclipse.core.resources.IFile) Reference(org.eclipse.titan.designer.AST.Reference) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) Template(org.eclipse.jface.text.templates.Template) ProposalCollector(org.eclipse.titan.designer.editors.ProposalCollector) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 22 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class Export_Debug_AST method run.

@Override
public void run(IAction action) {
    if (targetEditor == null)
        return;
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
    Module module = parser.containedModule(file);
    if (module == null) {
        TITANDebugConsole.getConsole().newMessageStream().println("No module was found");
    }
    TITANDebugConsole.getConsole().newMessageStream().println("*************************");
    TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "':");
    TITANDebugConsole.getConsole().newMessageStream().println("*************************");
    module.accept(new ASTVisitor() {

        private int padding = 0;

        @Override
        public int visit(IVisitableNode node) {
            if (node instanceof Assignment) {
                Assignment assignment = (Assignment) node;
                printInfoln(padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
            } else if (node instanceof Identifier) {
                printInfoln(padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
            } else if (node instanceof Statement) {
                Statement statement = (Statement) node;
                printInfoln(padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
            } else if (node instanceof Reference) {
                Reference ref = (Reference) node;
                printInfoln(padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
                Assignment old = ref.getAssOld();
                if (old != null) {
                    printInfoln(padding + 1, "This reference was last pointing to " + old.getFullName() + " analyzed at " + old.getLastTimeChecked());
                }
            } else if (node instanceof ComponentTypeBody) {
                ComponentTypeBody body = (ComponentTypeBody) node;
                Map<String, Definition> map = body.getDefinitionMap();
                printInfoln(padding + 1, " contains definitions:");
                for (Map.Entry<String, Definition> entry : map.entrySet()) {
                    printInfoln(padding + 2, entry.getKey() + " was last checked at " + entry.getValue().getLastTimeChecked());
                }
            }
            if (node instanceof StatementBlock || node instanceof Definition) {
                padding++;
            }
            return super.visit(node);
        }

        @Override
        public int leave(IVisitableNode node) {
            if (node instanceof StatementBlock || node instanceof Definition) {
                padding--;
            }
            return super.leave(node);
        }
    });
    TITANDebugConsole.getConsole().newMessageStream().println("*************************");
    TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "' finished");
    TITANDebugConsole.getConsole().newMessageStream().println("*************************");
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) IFile(org.eclipse.core.resources.IFile) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Reference(org.eclipse.titan.designer.AST.Reference) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) ASTVisitor(org.eclipse.titan.designer.AST.ASTVisitor) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Assignment(org.eclipse.titan.designer.AST.Assignment) Identifier(org.eclipse.titan.designer.AST.Identifier) Module(org.eclipse.titan.designer.AST.Module) Map(java.util.Map) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 23 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class DoWhile_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    isInfiniteLoop = false;
    if (statementblock != null) {
        statementblock.setMyLaicStmt(null, this);
        statementblock.check(timestamp);
    }
    if (expression != null) {
        final IValue last = expression.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
        final Type_type temporalType = last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (!last.getIsErroneous(timestamp)) {
            if (!Type_type.TYPE_BOOL.equals(temporalType)) {
                last.getLocation().reportSemanticError(BOOLEANEXPECTED);
                expression.setIsErroneous(true);
            } else if (!expression.isUnfoldable(timestamp)) {
                if (!((Boolean_Value) last).getValue()) {
                    final String severity = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null);
                    expression.getLocation().reportConfigurableSemanticProblem(severity, UNNECESSARYCONTROL);
                } else if (ReturnStatus_type.RS_NO.equals(hasReturn(timestamp))) {
                    isInfiniteLoop = true;
                    final String severity = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTINFINITELOOPS, GeneralConstants.WARNING, null);
                    location.reportConfigurableSemanticProblem(severity, INFINITELOOP);
                }
            }
            if (expression.getMyGovernor() == null) {
                expression.setMyGovernor(new Boolean_Type());
            }
        }
    }
    lastTimeChecked = timestamp;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) Boolean_Type(org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Example 24 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class If_Clause method check.

/**
 * Does the semantic checking of this branch.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param unreachable
 *                boolean parameter telling if this if statement was
 *                already found unreachable by previous clauses or not
 *
 * @return true if following clauses are unreachable
 */
public boolean check(final CompilationTimeStamp timestamp, final boolean unreachable) {
    if (unreachable) {
        location.reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), NEVERREACH1);
    }
    boolean unreachable2 = unreachable;
    if (expression != null) {
        final IValue last = expression.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
        final Type_type temporalType = last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_UNDEFINED.equals(temporalType)) {
            if (!Type_type.TYPE_BOOL.equals(temporalType)) {
                last.getLocation().reportSemanticError(BOOLEANEXPECTED);
                expression.setIsErroneous(true);
            } else if (!expression.isUnfoldable(timestamp)) {
                if (((Boolean_Value) last).getValue()) {
                    expression.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), UNNECESSARYCONTROL1);
                    unreachable2 = true;
                } else {
                    expression.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), UNNECESSARYCONTROL2);
                    statementblock.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), NEVERREACH2);
                }
            }
            if (expression.getMyGovernor() == null) {
                expression.setMyGovernor(new Boolean_Type());
            }
        }
    }
    if (statementblock != null) {
        statementblock.check(timestamp);
    }
    return unreachable2;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Boolean_Type(org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Example 25 with StatementBlock

use of org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock in project titan.EclipsePlug-ins by eclipse.

the class Invoke_Altguard method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    if (expression != null) {
        final IValue last = expression.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
        final Type_type temporalType = last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_BOOL.equals(temporalType)) {
            last.getLocation().reportSemanticError(BOOLEANEXPECTED);
            expression.setIsErroneous(true);
        }
        if (expression.getMyGovernor() == null) {
            expression.setMyGovernor(new Boolean_Type());
        }
    }
    IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
    if (type == null) {
        lastTimeChecked = timestamp;
        return;
    }
    type = type.getTypeRefdLast(timestamp);
    if (type == null || type.getIsErroneous(timestamp)) {
        lastTimeChecked = timestamp;
        return;
    }
    if (!Type_type.TYPE_ALTSTEP.equals(type.getTypetype())) {
        value.getLocation().reportSemanticError(MessageFormat.format("A value of type altstep was expected instead of `{0}''", type.getTypename()));
        lastTimeChecked = timestamp;
        return;
    }
    value.getMyScope().checkRunsOnScope(timestamp, type, this, "call");
    final FormalParameterList formalParmaterList = ((Altstep_Type) type).getFormalParameters();
    actualParameterList = new ActualParameterList();
    formalParmaterList.checkActualParameterList(timestamp, parsedParameters, actualParameterList);
    if (statementblock != null) {
        statementblock.check(timestamp);
    }
    lastTimeChecked = timestamp;
}
Also used : FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) IValue(org.eclipse.titan.designer.AST.IValue) Boolean_Type(org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) ActualParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList) Altstep_Type(org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)21 IValue (org.eclipse.titan.designer.AST.IValue)11 Assignment (org.eclipse.titan.designer.AST.Assignment)8 Reference (org.eclipse.titan.designer.AST.Reference)8 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)7 Boolean_Type (org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type)7 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)6 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)6 Identifier (org.eclipse.titan.designer.AST.Identifier)5 Alt_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Alt_Statement)5 Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Statement)5 Assignment_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement)4 If_Statement (org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Location (org.eclipse.titan.designer.AST.Location)3 Module (org.eclipse.titan.designer.AST.Module)3 Def_Altstep (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Altstep)3 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)3 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)3 Map (java.util.Map)2