Search in sources :

Example 16 with Scope

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

the class DecodeExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    aData.addBuiltinTypeImport("TitanOctetString");
    aData.addCommonLibraryImport("TTCN_EncDec");
    aData.addCommonLibraryImport("AdditionalFunctions");
    final ExpressionStruct expression1 = new ExpressionStruct();
    final ExpressionStruct expression2 = new ExpressionStruct();
    reference1.generateCode(aData, expression1);
    reference2.generateCode(aData, expression2);
    final Assignment tempAssignment = reference2.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
    final IType type = tempAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
    final IType fieldType = type.getFieldType(CompilationTimeStamp.getBaseTimestamp(), reference2, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
    if (expression1.preamble.length() > 0) {
        expression.preamble.append(expression1.preamble);
    }
    if (expression2.preamble.length() > 0) {
        expression.preamble.append(expression2.preamble);
    }
    final Scope scope = reference2.getMyScope();
    final boolean isOptional = fieldType.fieldIsOptional(reference2.getSubreferences());
    final ExpressionStruct expression3 = new ExpressionStruct();
    // TODO add support for 5th parameter
    expression3.expression.append(MessageFormat.format("{0}_default_coding", fieldType.getGenNameDefaultCoding(aData, expression.expression, scope)));
    final String bufferID = aData.getTemporaryVariableName();
    final String returnValueID = aData.getTemporaryVariableName();
    // TOOD add handling for non-built-in encoding
    expression.preamble.append("TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_WARNING);\n");
    expression.preamble.append("TTCN_EncDec.clear_error();\n");
    expression.preamble.append(MessageFormat.format("TitanOctetString {0} = new TitanOctetString(AdditionalFunctions.bit2oct({1}));\n", bufferID, expression1.expression));
    expression.preamble.append(MessageFormat.format("TitanInteger {0} = new TitanInteger({1}_decoder({2}, {3}{4}, {5}));\n", returnValueID, fieldType.getGenNameCoder(aData, expression.expression, scope), bufferID, expression2.expression, isOptional ? ".get()" : "", expression3.expression));
    expression.preamble.append(MessageFormat.format("if ({0}.operatorEquals(0)) '{'\n", returnValueID));
    expression.preamble.append(MessageFormat.format("{0}.assign(AdditionalFunctions.oct2bit({1}));\n", expression1.expression, bufferID));
    expression.preamble.append("}\n");
    // TOOD add handling for non-built-in encoding
    expression.preamble.append("TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_DEFAULT);\n");
    expression.preamble.append("TTCN_EncDec.clear_error();\n");
    expression.expression.append(returnValueID);
    if (expression1.postamble.length() > 0) {
        expression.postamble.append(expression1.postamble);
    }
    if (expression2.postamble.length() > 0) {
        expression.postamble.append(expression2.postamble);
    }
    if (expression3.postamble.length() > 0) {
        expression.postamble.append(expression3.postamble);
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) Scope(org.eclipse.titan.designer.AST.Scope) IType(org.eclipse.titan.designer.AST.IType)

Example 17 with Scope

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

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

the class ObjectSet_FieldSpecification method setMyObjectClass.

@Override
public /**
 * {@inheritDoc}
 */
void setMyObjectClass(final ObjectClass_Definition objectClass) {
    super.setMyObjectClass(objectClass);
    final Scope scope = myObjectClass.getMyScope();
    objectClass.setMyScope(scope);
    if (null != defaultObjectSet) {
        defaultObjectSet.setMyScope(scope);
    }
}
Also used : Scope(org.eclipse.titan.designer.AST.Scope)

Example 19 with Scope

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

the class Def_Function method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    T3Doc.check(this.getCommentLocation(), KIND);
    isUsed = false;
    runsOnType = null;
    isStartable = false;
    if (runsOnRef != null) {
        runsOnType = runsOnRef.chkComponentypeReference(timestamp);
        if (runsOnType != null) {
            final Scope formalParlistPreviosScope = formalParList.getParentScope();
            if (formalParlistPreviosScope instanceof RunsOnScope && ((RunsOnScope) formalParlistPreviosScope).getParentScope() == myScope) {
                ((RunsOnScope) formalParlistPreviosScope).setComponentType(runsOnType);
            } else {
                final Scope tempScope = new RunsOnScope(runsOnType, myScope);
                formalParList.setMyScope(tempScope);
            }
        }
    }
    boolean canSkip = false;
    if (myScope != null) {
        final Module module = myScope.getModuleScope();
        if (module != null) {
            if (module.getSkippedFromSemanticChecking()) {
                canSkip = true;
            }
        }
    }
    if (!canSkip) {
        formalParList.reset();
    }
    formalParList.check(timestamp, getAssignmentType());
    if (returnType != null) {
        returnType.check(timestamp);
        final IType returnedType = returnType.getTypeRefdLast(timestamp);
        if (Type_type.TYPE_PORT.equals(returnedType.getTypetype()) && returnType.getLocation() != null) {
            returnType.getLocation().reportSemanticError(PORTRETURNNOTALLOWED);
        }
    }
    if (formalParList.hasNotusedDefaultValue()) {
        formalParList.getLocation().reportSemanticError(DASHALLOWEDONLYFORTEMPLATES);
        return;
    }
    // decision of startability
    isStartable = runsOnRef != null;
    isStartable &= formalParList.getStartability();
    if (isStartable && returnType != null && returnType.isComponentInternal(timestamp)) {
        isStartable = false;
    }
    if (canSkip) {
        return;
    }
    NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_FUNCTION, identifier, this);
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (block != null) {
        block.check(timestamp);
        if (returnType != null) {
            // check the presence of return statements
            switch(block.hasReturn(timestamp)) {
                case RS_NO:
                    identifier.getLocation().reportSemanticError("The function has a return type, but it does not have any return statement");
                    break;
                case RS_MAYBE:
                    identifier.getLocation().reportSemanticError("The function has return type, but control might leave it without reaching a return statement");
                    break;
                default:
                    break;
            }
        }
        block.postCheck();
        block.setCodeSection(CodeSectionType.CS_INLINE);
    }
    prototype = EncodingPrototype_type.NONE;
    inputType = null;
    outputType = null;
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
        analyzeExtensionAttributes(timestamp);
        checkPrototype(timestamp);
    }
}
Also used : Scope(org.eclipse.titan.designer.AST.Scope) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) Module(org.eclipse.titan.designer.AST.Module) IType(org.eclipse.titan.designer.AST.IType)

Example 20 with Scope

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

the class Def_Testcase method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    isUsed = false;
    runsOnType = null;
    systemType = null;
    T3Doc.check(this.getCommentLocation(), KIND);
    if (runsOnReference != null) {
        runsOnType = runsOnReference.chkComponentypeReference(timestamp);
        if (runsOnType != null) {
            final Scope formalParlistPreviosScope = formalParList.getParentScope();
            if (formalParlistPreviosScope instanceof RunsOnScope && ((RunsOnScope) formalParlistPreviosScope).getParentScope() == myScope) {
                ((RunsOnScope) formalParlistPreviosScope).setComponentType(runsOnType);
            } else {
                final Scope tempScope = new RunsOnScope(runsOnType, myScope);
                formalParList.setMyScope(tempScope);
            }
        }
    }
    if (systemReference != null) {
        systemType = systemReference.chkComponentypeReference(timestamp);
    }
    if (formalParList.hasNotusedDefaultValue()) {
        formalParList.getLocation().reportSemanticError(DASHALLOWEDONLYFORTEMPLATES);
        return;
    }
    boolean canSkip = false;
    if (myScope != null) {
        final Module module = myScope.getModuleScope();
        if (module != null) {
            if (module.getSkippedFromSemanticChecking()) {
                canSkip = true;
            }
        }
    }
    if (!canSkip) {
        formalParList.reset();
    }
    formalParList.check(timestamp, getAssignmentType());
    if (canSkip) {
        return;
    }
    NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_TESTCASE, identifier, this);
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (block != null) {
        block.check(timestamp);
        block.postCheck();
        block.setCodeSection(CodeSectionType.CS_INLINE);
    }
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, false);
        withAttributesPath.checkAttributes(timestamp);
    }
}
Also used : NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) Scope(org.eclipse.titan.designer.AST.Scope) Module(org.eclipse.titan.designer.AST.Module)

Aggregations

Scope (org.eclipse.titan.designer.AST.Scope)24 IType (org.eclipse.titan.designer.AST.IType)13 Module (org.eclipse.titan.designer.AST.Module)9 Assignment (org.eclipse.titan.designer.AST.Assignment)6 Identifier (org.eclipse.titan.designer.AST.Identifier)6 Reference (org.eclipse.titan.designer.AST.Reference)6 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)5 IValue (org.eclipse.titan.designer.AST.IValue)4 NamedBridgeScope (org.eclipse.titan.designer.AST.NamedBridgeScope)4 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)3 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)2 IDocument (org.eclipse.jface.text.IDocument)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)2 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)2 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2