Search in sources :

Example 26 with Reference

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

the class Export_Debug_AST_Action method exportDebugAST.

private void exportDebugAST(final ZipOutputStream out, final Module module) throws Exception {
    out.putNextEntry(new ZipEntry("DebugAST_for_" + module.getIdentifier().getName() + ".txt"));
    out.write("*************************".getBytes());
    out.write(lineend);
    out.write(("Printing DEBUG information for module `" + module.getName() + "':").getBytes());
    out.write(lineend);
    out.write("*************************".getBytes());
    out.write(lineend);
    module.accept(new ASTVisitor() {

        private int padding = 0;

        @Override
        public int visit(IVisitableNode node) {
            if (node instanceof Assignment) {
                Assignment assignment = (Assignment) node;
                printInfoln(out, padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
            } else if (node instanceof Identifier) {
                printInfoln(out, padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
            } else if (node instanceof Statement) {
                Statement statement = (Statement) node;
                printInfoln(out, padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
            } else if (node instanceof Reference) {
                Reference ref = (Reference) node;
                printInfoln(out, padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
                Assignment old = ref.getAssOld();
                if (old != null) {
                    printInfoln(out, 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(out, padding + 1, " contains definitions:");
                if (map != null) {
                    for (Map.Entry<String, Definition> entry : map.entrySet()) {
                        printInfoln(out, 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);
        }
    });
    out.write("*************************".getBytes());
    out.write(lineend);
    out.write(("Printing DEBUG information for module `" + module.getName() + "' finished").getBytes());
    out.write(lineend);
    out.write("*************************".getBytes());
    out.write(lineend);
    out.closeEntry();
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) Reference(org.eclipse.titan.designer.AST.Reference) ZipEntry(java.util.zip.ZipEntry) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ASTVisitor(org.eclipse.titan.designer.AST.ASTVisitor) IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Assignment(org.eclipse.titan.designer.AST.Assignment) ZipEntry(java.util.zip.ZipEntry) Identifier(org.eclipse.titan.designer.AST.Identifier) Map(java.util.Map) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 27 with Reference

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

the class Referenced_Template method generateRearrangeInitCodeReferenced.

private void generateRearrangeInitCodeReferenced(final JavaGenData aData, final StringBuilder source, final ExpressionStruct expression) {
    /**
     * Initially we can assume that:
     * - this is a referenced template and a part of a non-parameterized template
     * - u.ref.ref points to (a field of) a non-parameterized template within the same module as this.
     * - this ensures that the do-while loop will run at least twice (i.e. the first continue statement will be reached in the first iteration)
     */
    final Stack<ISubReference> referenceStack = new Stack<ISubReference>();
    ITTCN3Template template = this;
    for (; ; ) {
        if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
            final Reference reference = ((Referenced_Template) template).getReference();
            final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            /**
             * Don't follow the reference if:
             *  - the referenced definition is not a template
             *  - the referenced template is parameterized or
             *  - the referenced template is in different module
             */
            if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE && ((Def_Template) assignment).getFormalParameterList() == null && assignment.getMyScope().getModuleScope() == myScope.getModuleScope()) {
                // accumulate the sub-references of the referred reference
                final List<ISubReference> subReferences = reference.getSubreferences();
                if (subReferences != null && subReferences.size() > 1) {
                    for (int i = subReferences.size(); i > 1; i--) {
                        referenceStack.push(subReferences.get(i - 1));
                    }
                }
                // jump to the referred top-level template
                template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
                // start the iteration from the beginning
                continue;
            } else {
                // the reference cannot be followed
                break;
            }
        }
        // stop if there are no sub-references
        if (referenceStack.isEmpty()) {
            break;
        }
        // take the topmost sub-reference
        final ISubReference subReference = referenceStack.peek();
        if (subReference instanceof FieldSubReference) {
            if (template.getTemplatetype() != Template_type.NAMED_TEMPLATE_LIST) {
                break;
            }
            // the field reference can be followed
            final Identifier fieldId = ((FieldSubReference) subReference).getId();
            template = ((Named_Template_List) template).getNamedTemplate(fieldId).getTemplate();
        } else {
            // trying to follow an array reference
            if (template.getTemplatetype() != Template_type.TEMPLATE_LIST) {
                break;
            }
            IValue arrayIndex = ((ArraySubReference) subReference).getValue();
            final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            arrayIndex = arrayIndex.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
            referenceChain.release();
            if (arrayIndex.getValuetype() != Value_type.INTEGER_VALUE) {
                break;
            }
            // the index is available at compilation time
            long index = ((Integer_Value) arrayIndex).getValue();
            // index transformation in case of arrays
            if (template.getMyGovernor().getTypetype() == Type_type.TYPE_ARRAY) {
                index = index - ((Array_Type) template.getMyGovernor()).getDimension().getOffset();
            }
            template = ((Template_List) template).getTemplateByIndex((int) index);
        }
        // the topmost sub-reference was processed
        // it can be erased from the stack
        referenceStack.pop();
    }
    // the smallest dependent template is now in t
    // generate the initializer sequence for t
    template.generateCodeInit(aData, source, template.get_lhs_name());
    // the equivalent Java code of the referenced template is composed of the
    // genname of t and the remained sub-references in refstack
    expression.expression.append(template.getGenNameOwn(myScope));
    while (!referenceStack.isEmpty()) {
        final ISubReference subReference = referenceStack.pop();
        if (subReference instanceof FieldSubReference) {
            expression.expression.append(MessageFormat.format(".get{0}()", FieldSubReference.getJavaGetterName(((FieldSubReference) subReference).getId().getName())));
        } else {
            expression.expression.append(".getAt(");
            ((ArraySubReference) subReference).getValue().generateCodeExpression(aData, expression, false);
            expression.expression.append(')');
        }
    }
}
Also used : FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) 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) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Stack(java.util.Stack) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain)

Example 28 with Reference

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

the class LogArgument method checkValue.

/**
 * Does the semantic checking of the log argument. Once it was
 * determined that it is a value.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param value
 *                the value contained in the log argument.
 */
private void checkValue(final CompilationTimeStamp timestamp, final IValue value) {
    final IValue temp = value.setLoweridToReference(timestamp);
    switch(temp.getValuetype()) {
        case CHARSTRING_VALUE:
            internalLogArgument = new String_InternalLogArgument(((Charstring_Value) temp).getValue());
            break;
        case REFERENCED_VALUE:
            final Reference reference = ((Referenced_Value) temp).getReference();
            internalLogArgument = new Reference_InternalLogArgument(reference);
            checkReference(timestamp, reference);
            return;
        case EXPRESSION_VALUE:
            final Expression_Value castedValue = (Expression_Value) temp;
            if (Operation_type.MATCH_OPERATION.equals(castedValue.getOperationType())) {
                internalLogArgument = new Match_InternalLogArgument((MatchExpression) castedValue);
            } else {
                internalLogArgument = new Value_InternalLogArgument(temp);
            }
            break;
        case MACRO_VALUE:
            internalLogArgument = new Macro_InternalLogArgument((Macro_Value) temp);
            break;
        default:
            internalLogArgument = new Value_InternalLogArgument(temp);
            break;
    }
    final IType governor = temp.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    if (governor == null) {
        getLocation().reportSemanticError("Cannot determine the type of the argument");
        isErroneous = true;
        return;
    }
    // TODO: Is the next part necessary ???
    temp.setMyGovernor(governor);
    // TODO:WHY
    governor.checkThisValue(timestamp, temp, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_TEMPLATE, true, true, true, true, false));
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    if (ArgumentType.Value.equals(internalLogArgument.getArgumentType()) && !temp.isUnfoldable(timestamp)) {
        final IValue last = temp.getValueRefdLast(timestamp, chain);
        if (Value_type.CHARSTRING_VALUE.equals(last.getValuetype())) {
            internalLogArgument = new String_InternalLogArgument(((Charstring_Value) last).getValue());
        }
    } else if (ArgumentType.Macro.equals(internalLogArgument.getArgumentType())) {
        final IValue last = temp.getValueRefdLast(timestamp, chain);
        switch(last.getValuetype()) {
            case CHARSTRING_VALUE:
                internalLogArgument = new String_InternalLogArgument(((Charstring_Value) last).getValue());
                break;
            case MACRO_VALUE:
                break;
            default:
                internalLogArgument = new Value_InternalLogArgument(temp);
                break;
        }
    }
    chain.release();
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Macro_Value(org.eclipse.titan.designer.AST.TTCN3.values.Macro_Value) MatchExpression(org.eclipse.titan.designer.AST.TTCN3.values.expressions.MatchExpression) IType(org.eclipse.titan.designer.AST.IType) IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Example 29 with Reference

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

the class ComplementedList_Template method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
        return;
    }
    lastTimeBuilt = aData.getBuildTimstamp();
    aData.addBuiltinTypeImport("Base_Template.template_sel");
    final ArrayList<Integer> variables = new ArrayList<Integer>();
    long fixedPart = 0;
    for (int i = 0; i < templates.getNofTemplates(); i++) {
        final TTCN3Template templateListItem = templates.getTemplateByIndex(i);
        if (templateListItem.getTemplatetype() == Template_type.ALL_FROM) {
            variables.add(i);
        } else {
            fixedPart++;
        }
    }
    final String typeName = myGovernor.getGenNameTemplate(aData, source, myScope);
    if (variables.size() > 0) {
        final StringBuilder preamble = new StringBuilder();
        final StringBuilder setType = new StringBuilder();
        final StringBuilder[] variableReferences = new StringBuilder[templates.getNofTemplates()];
        setType.append(MessageFormat.format("{0}.setType(template_sel.COMPLEMENTED_LIST, {1}", name, fixedPart));
        for (int v = 0; v < variables.size(); v++) {
            TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
            // the template must be all from
            if (template instanceof All_From_Template) {
                template = ((All_From_Template) template).getAllFrom();
            }
            final Reference reference = ((SpecificValue_Template) template).getReference();
            final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
            setType.append(" + ");
            final ExpressionStruct expression = new ExpressionStruct();
            reference.generateCode(aData, expression);
            if (expression.preamble.length() > 0) {
                preamble.append(expression.preamble);
            }
            switch(assignment.getAssignmentType()) {
                case A_CONST:
                case A_EXT_CONST:
                case A_MODULEPAR:
                case A_VAR:
                case A_PAR_VAL:
                case A_PAR_VAL_IN:
                case A_PAR_VAL_OUT:
                case A_PAR_VAL_INOUT:
                case A_FUNCTION_RVAL:
                case A_EXT_FUNCTION_RVAL:
                    if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
                        setType.append(".get()");
                    }
                    break;
                default:
                    break;
            }
            variableReferences[variables.get(v)] = expression.expression;
            setType.append(expression.expression);
            setType.append(".n_elem().getInt()");
        }
        source.append(preamble);
        source.append(setType);
        source.append(");\n");
        final StringBuilder shifty = new StringBuilder();
        for (int i = 0; i < templates.getNofTemplates(); i++) {
            final TTCN3Template template = templates.getTemplateByIndex(i);
            switch(template.getTemplatetype()) {
                case ALL_FROM:
                    {
                        // the template must be all from
                        final StringBuilder storedExpression = variableReferences[i];
                        source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", storedExpression));
                        String embeddedName = MessageFormat.format("{0}.listItem({1}{2} + i_i)", name, i, shifty);
                        ((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName, storedExpression);
                        source.append("}\n");
                        shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", storedExpression));
                        break;
                    }
                default:
                    if (template.needsTemporaryReference()) {
                        final String tempId = aData.getTemporaryVariableName();
                        source.append("{\n");
                        source.append(MessageFormat.format("{0} {1} = {2}.listItem({3}{4});\n", typeName, tempId, name, i, shifty));
                        template.generateCodeInit(aData, source, tempId);
                        source.append("}\n");
                    } else {
                        final String embeddedName = MessageFormat.format("{0}.listItem({1}{2})", name, i, shifty);
                        template.generateCodeInit(aData, source, embeddedName);
                    }
                    break;
            }
        }
    } else {
        source.append(MessageFormat.format("{0}.setType(template_sel.COMPLEMENTED_LIST, {1});\n", name, templates.getNofTemplates()));
        for (int i = 0; i < templates.getNofTemplates(); i++) {
            final TTCN3Template template = templates.getTemplateByIndex(i);
            if (template.needsTemporaryReference()) {
                final String tempId = aData.getTemporaryVariableName();
                source.append("{\n");
                source.append(MessageFormat.format("{0} {1} = {2}.listItem({3});\n", typeName, tempId, name, i));
                template.generateCodeInit(aData, source, tempId);
                source.append("}\n");
            } else {
                final String embeddedName = MessageFormat.format("{0}.listItem({1})", name, i);
                template.generateCodeInit(aData, source, embeddedName);
            }
        }
    }
    if (lengthRestriction != null) {
        if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
            lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
        }
        lengthRestriction.generateCodeInit(aData, source, name);
    }
    if (isIfpresent) {
        source.append(name);
        source.append(".set_ifPresent();\n");
    }
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) ArrayList(java.util.ArrayList) Assignment(org.eclipse.titan.designer.AST.Assignment) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 30 with Reference

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

the class ASN1ReferenceParser method findReferenceForOpening.

@Override
public final Reference findReferenceForOpening(final IFile file, final int offset, final IDocument document) {
    Reference reference = null;
    ofs = offset - 1;
    if (-1 == ofs) {
        return reference;
    }
    try {
        GeneralPairMatcher pairMatcher = new ASN1ReferencePairMatcher();
        ofs = referenceStartOffset(ofs, document, pairMatcher);
        if (-1 == ofs) {
            return reference;
        }
        // the last character where the loop stopped is not part
        // of the reference
        ofs++;
        int endoffset = offset;
        if (endoffset >= document.getLength()) {
            return reference;
        }
        char currentChar = document.getChar(endoffset);
        while (endoffset < document.getLength() && (Character.isLetterOrDigit(currentChar) || currentChar == '(' || currentChar == '_' || currentChar == '-')) {
            if (currentChar == '(') {
                break;
            }
            endoffset++;
            if (endoffset >= document.getLength()) {
                return reference;
            }
            currentChar = document.getChar(endoffset);
        }
        String toBeParsed = document.get(ofs, endoffset - ofs);
        ASN1ReferenceParser refAnalyzer = newInstance();
        reference = refAnalyzer.parseReference(file, toBeParsed, document.getLineOfOffset(ofs) + 1, ofs);
    } catch (BadLocationException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    return reference;
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) GeneralPairMatcher(org.eclipse.titan.designer.editors.GeneralPairMatcher) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

Reference (org.eclipse.titan.designer.AST.Reference)88 Assignment (org.eclipse.titan.designer.AST.Assignment)48 ISubReference (org.eclipse.titan.designer.AST.ISubReference)37 IValue (org.eclipse.titan.designer.AST.IValue)26 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)23 IType (org.eclipse.titan.designer.AST.IType)23 Identifier (org.eclipse.titan.designer.AST.Identifier)22 ArrayList (java.util.ArrayList)19 Module (org.eclipse.titan.designer.AST.Module)16 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)15 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)13 IFile (org.eclipse.core.resources.IFile)11 Location (org.eclipse.titan.designer.AST.Location)10 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)10 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)9 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)9 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)9 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)8 Type (org.eclipse.titan.designer.AST.Type)8 BadLocationException (org.eclipse.jface.text.BadLocationException)7