Search in sources :

Example 6 with Definition

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

the class Referenced_Value method getValueRefdLast.

@Override
public /**
 * {@inheritDoc}
 */
IValue getValueRefdLast(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return referencedValue;
    }
    final boolean newChain = null == referenceChain;
    IReferenceChain tempReferenceChain;
    if (newChain) {
        tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    } else {
        tempReferenceChain = referenceChain;
    }
    referencedValue = this;
    isErroneous = false;
    if (reference == null) {
        return referencedValue;
    }
    reference.setIsErroneous(false);
    final Assignment ass = reference.getRefdAssignment(timestamp, true);
    if (ass == null) {
        isErroneous = true;
        return referencedValue;
    }
    switch(ass.getAssignmentType()) {
        case A_OBJECT:
        case A_OS:
            {
                final ISetting setting = reference.getRefdSetting(timestamp);
                if (setting == null || setting.getIsErroneous(timestamp)) {
                    isErroneous = true;
                } else if (!Setting_type.S_V.equals(setting.getSettingtype())) {
                    reference.getLocation().reportSemanticError(MessageFormat.format(INFORMATIONFROMOBJECTNOTVALUE, reference));
                    isErroneous = true;
                } else {
                    tempReferenceChain.markState();
                    if (tempReferenceChain.add(this)) {
                        referencedValue = ((IValue) setting).getValueRefdLast(timestamp, expectedValue, referenceChain);
                    } else {
                        isErroneous = true;
                    }
                    tempReferenceChain.previousState();
                }
                break;
            }
        case A_CONST:
            {
                tempReferenceChain.markState();
                if (tempReferenceChain.add(this)) {
                    if (ass instanceof Def_Const) {
                        referencedValue = ((Def_Const) ass).getValue();
                    } else if (ass instanceof Value_Assignment) {
                        referencedValue = ((Value_Assignment) ass).getValue();
                    } else {
                        isErroneous = true;
                    }
                    if (referencedValue != null && !isErroneous) {
                        referencedValue = referencedValue.getReferencedSubValue(timestamp, reference, 1, tempReferenceChain);
                    } else {
                        referencedValue = this;
                        tempReferenceChain.previousState();
                        return referencedValue;
                    }
                    if (referencedValue != null) {
                        referencedValue = referencedValue.getValueRefdLast(timestamp, tempReferenceChain);
                    } else if (reference.hasUnfoldableIndexSubReference(timestamp)) {
                        referencedValue = this;
                        tempReferenceChain.previousState();
                        return referencedValue;
                    } else if (reference.getUsedInIsbound()) {
                        referencedValue = this;
                        tempReferenceChain.previousState();
                        return referencedValue;
                    } else {
                        isErroneous = true;
                    }
                } else {
                    isErroneous = true;
                }
                tempReferenceChain.previousState();
                break;
            }
        case A_EXT_CONST:
        case A_MODULEPAR:
        case A_VAR:
        case A_FUNCTION_RVAL:
        case A_FUNCTION_RTEMP:
        case A_EXT_FUNCTION_RTEMP:
        case A_EXT_FUNCTION_RVAL:
        case A_PAR_VAL:
        case A_PAR_VAL_IN:
        case A_PAR_VAL_OUT:
        case A_PAR_VAL_INOUT:
        case A_MODULEPAR_TEMPLATE:
        case A_PAR_TEMP_IN:
        case A_PAR_TEMP_INOUT:
        case A_PAR_TEMP_OUT:
            referencedValue = this;
            break;
        case A_TEMPLATE:
        case A_VAR_TEMPLATE:
            // the referred definition is not a constant
            // errors will be reported in Types.java
            referencedValue = this;
            if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT2, ass.getDescription()));
            }
            break;
        case A_FUNCTION:
        case A_EXT_FUNCTION:
            reference.getLocation().reportSemanticError(MessageFormat.format(VALUERETURNEXPECTED, ass.getDescription()));
            isErroneous = true;
            break;
        default:
            if (Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT1, ass.getDescription()));
            } else {
                getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDASSIGNMENT2, ass.getDescription()));
            }
            isErroneous = true;
            break;
    }
    if (newChain) {
        tempReferenceChain.release();
    }
    lastTimeChecked = timestamp;
    if (referencedValue == null) {
        referencedValue = this;
        isErroneous = true;
    }
    return referencedValue;
}
Also used : Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) ISetting(org.eclipse.titan.designer.AST.ISetting)

Example 7 with Definition

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

the class Macro_Value method evaluateMacro.

/**
 * Evaluates the value of the macro.
 *
 * @param expectedValue the kind of the value to be expected
 *
 * @return the actual or the evaluated value
 */
private IValue evaluateMacro(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    lastTimeChecked = timestamp;
    lastValue = this;
    switch(value) {
        case MODULEID:
            if (myScope != null && myScope.getModuleScope() != null) {
                final Module module = myScope.getModuleScope();
                if (module.getIdentifier() != null) {
                    lastValue = new Charstring_Value(module.getIdentifier().getDisplayName());
                    lastValue.copyGeneralProperties(this);
                }
            }
            break;
        case DEFINITIONID:
            if (myScope != null) {
                final StatementBlock block = myScope.getStatementBlockScope();
                if (block != null) {
                    final Definition definition = block.getMyDefinition();
                    if (definition != null) {
                        lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
                        lastValue.copyGeneralProperties(this);
                    }
                }
            } else {
                setIsErroneous(true);
            }
            break;
        case TESTCASEID:
            if (myScope != null) {
                final StatementBlock block = myScope.getStatementBlockScope();
                if (block != null) {
                    final Definition definition = block.getMyDefinition();
                    if (definition == null) {
                        location.reportSemanticError(TESCASEIDINCONTROLPART);
                        setIsErroneous(true);
                    } else {
                        if (Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
                            // folding is possible in testcases only
                            lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
                            lastValue.copyGeneralProperties(this);
                        }
                    }
                } else {
                    location.reportSemanticError(TESTCASEIDNOTALLOWED);
                    setIsErroneous(true);
                }
            } else {
                setIsErroneous(true);
            }
            break;
        case FILENAME:
        case BFILENAME:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Charstring_Value(location.getFile().getName());
                lastValue.copyGeneralProperties(this);
            }
            break;
        case FILEPATH:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                String canonicalPath;
                final IPath absolutePath = location.getFile().getLocation();
                if (absolutePath == null) {
                    location.reportSemanticError(UNDETERMINABLEPATH);
                    canonicalPath = location.getFile().getName();
                    setIsErroneous(true);
                } else {
                    final File file = absolutePath.toFile();
                    try {
                        canonicalPath = file.getCanonicalPath();
                    } catch (IOException e) {
                        location.reportSemanticError(UNDETERMINABLEPATH);
                        canonicalPath = location.getFile().getName();
                        setIsErroneous(true);
                    }
                }
                lastValue = new Charstring_Value(canonicalPath);
                lastValue.copyGeneralProperties(this);
            }
            break;
        case LINENUMBER:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Charstring_Value(Long.toString(location.getLine()));
                lastValue.copyGeneralProperties(this);
            }
            break;
        case LINENUMBER_C:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Integer_Value(location.getLine());
                lastValue.copyGeneralProperties(this);
            }
            break;
        case SCOPE:
            if (myScope != null) {
                lastValue = new Charstring_Value(myScope.getScopeMacroName());
                lastValue.copyGeneralProperties(this);
            } else {
                location.reportSemanticError(UNDETERMINABLESCOPE);
                setIsErroneous(true);
            }
            break;
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) IOException(java.io.IOException) Module(org.eclipse.titan.designer.AST.Module) File(java.io.File) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 8 with Definition

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

the class Def_Extfunction method checkPrototype.

/**
 * Checks the prototype attribute set for this external function
 * definition.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 */
private void checkPrototype(final CompilationTimeStamp timestamp) {
    if (EncodingPrototype_type.NONE.equals(prototype)) {
        return;
    }
    // checking formal parameter list
    if (EncodingPrototype_type.CONVERT.equals(prototype)) {
        if (formalParList.getNofParameters() == 1) {
            final FormalParameter parameter = formalParList.getParameterByIndex(0);
            switch(parameter.getRealAssignmentType()) {
                case A_PAR_VAL:
                case A_PAR_VAL_IN:
                    inputType = parameter.getType(timestamp);
                    break;
                default:
                    {
                        final String message = MessageFormat.format("The parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), parameter.getAssignmentName());
                        parameter.getLocation().reportSemanticError(message);
                        break;
                    }
            }
        } else {
            final String message = MessageFormat.format("The external function must have one parameter instead of {0} for attribute `prototype({1})''", formalParList.getNofParameters(), prototype.getName());
            formalParList.getLocation().reportSemanticError(message);
        }
    } else if (formalParList.getNofParameters() == 2) {
        final FormalParameter firstParameter = formalParList.getParameterByIndex(0);
        if (EncodingPrototype_type.SLIDING.equals(prototype)) {
            if (Assignment_type.A_PAR_VAL_INOUT.semanticallyEquals(firstParameter.getRealAssignmentType())) {
                final Type firstParameterType = firstParameter.getType(timestamp);
                final IType last = firstParameterType.getTypeRefdLast(timestamp);
                if (last.getIsErroneous(timestamp)) {
                    inputType = firstParameterType;
                } else {
                    switch(last.getTypetypeTtcn3()) {
                        case TYPE_OCTETSTRING:
                        case TYPE_CHARSTRING:
                        case TYPE_BITSTRING:
                            inputType = firstParameterType;
                            break;
                        default:
                            {
                                final String message = MessageFormat.format("The type of the first parameter must be `octetstring'' or `charstring'' for attribute `prototype({0})''", prototype.getName());
                                firstParameter.getLocation().reportSemanticError(message);
                                break;
                            }
                    }
                }
            } else {
                firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `inout'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
            }
        } else {
            if (Assignment_type.A_PAR_VAL_IN.semanticallyEquals(firstParameter.getRealAssignmentType())) {
                inputType = firstParameter.getType(timestamp);
            } else {
                firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
            }
        }
        final FormalParameter secondParameter = formalParList.getParameterByIndex(1);
        if (Assignment_type.A_PAR_VAL_OUT.semanticallyEquals(secondParameter.getRealAssignmentType())) {
            outputType = secondParameter.getType(timestamp);
        } else {
            secondParameter.getLocation().reportSemanticError(MessageFormat.format("The second parameter must be an `out'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), secondParameter.getAssignmentName()));
        }
    } else {
        formalParList.getLocation().reportSemanticError(MessageFormat.format("The function must have two parameters for attribute `prototype({0})'' instead of {1}", prototype.getName(), formalParList.getNofParameters()));
    }
    // checking the return type
    if (EncodingPrototype_type.FAST.equals(prototype)) {
        if (returnType != null) {
            returnType.getLocation().reportSemanticError(MessageFormat.format("The external function cannot have return type fo attribute `prototype({0})''", prototype.getName()));
        }
    } else {
        if (returnType == null) {
            location.reportSemanticError(MessageFormat.format("The external function must have a return type for attribute `prototype({0})''", prototype.getName()));
        } else {
            if (Assignment_type.A_FUNCTION_RTEMP.semanticallyEquals(assignmentType)) {
                returnType.getLocation().reportSemanticError(MessageFormat.format("The external function must return a value instead of a template for attribute `prototype({0})''", prototype.getName()));
            }
            if (EncodingPrototype_type.CONVERT.equals(prototype)) {
                outputType = returnType;
            } else {
                final IType last = returnType.getTypeRefdLast(timestamp);
                if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_INTEGER.equals(last.getTypetypeTtcn3())) {
                    returnType.getLocation().reportSemanticError(MessageFormat.format("The return type of the function must be `integer'' instead of `{0}'' for attribute `prototype({1})''", returnType.getTypename(), prototype.getName()));
                }
            }
        }
    }
}
Also used : IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) PrintingType(org.eclipse.titan.designer.AST.TTCN3.attributes.PrintingType) Attribute_Type(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) IType(org.eclipse.titan.designer.AST.IType)

Example 9 with Definition

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

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

the class Invoke_Template method generateCodeExpressionInvoke.

private void generateCodeExpressionInvoke(final JavaGenData aData, final ExpressionStruct expression) {
    if (value == null || actualParameter_list == null) {
        return;
    }
    final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
    referenceChain.release();
    if (last.getValuetype() == Value_type.FUNCTION_REFERENCE_VALUE) {
        final Definition function = ((Function_Reference_Value) last).getReferredFunction();
        expression.expression.append(MessageFormat.format("{0}(", function.getGenNameFromScope(aData, expression.expression, myScope, "")));
        actualParameter_list.generateCodeAlias(aData, expression);
    } else {
        value.generateCodeExpressionMandatory(aData, expression, true);
        expression.expression.append(".invoke(");
        IType governor = value.getMyGovernor();
        if (governor == null) {
            governor = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
        }
        if (governor == null) {
            return;
        }
        actualParameter_list.generateCodeAlias(aData, expression);
    }
    expression.expression.append(')');
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Function_Reference_Value(org.eclipse.titan.designer.AST.TTCN3.values.Function_Reference_Value) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)52 Assignment (org.eclipse.titan.designer.AST.Assignment)16 IValue (org.eclipse.titan.designer.AST.IValue)12 Location (org.eclipse.titan.designer.AST.Location)11 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)10 IType (org.eclipse.titan.designer.AST.IType)10 Identifier (org.eclipse.titan.designer.AST.Identifier)10 Module (org.eclipse.titan.designer.AST.Module)10 ArrayList (java.util.ArrayList)9 Reference (org.eclipse.titan.designer.AST.Reference)9 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)8 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)6 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)6 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)5 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)5 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)5 IFile (org.eclipse.core.resources.IFile)4 Restriction_type (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type)4