Search in sources :

Example 1 with Definitions

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

the class AstRunnerJava method walkChildren.

private void walkChildren(ASTVisitor visitor, Object[] children) {
    LoggerVisitor logger = new LoggerVisitor();
    for (Object child : children) {
        if (child instanceof Definitions) {
            Definitions definitions = (Definitions) child;
            moduleElementName = definitions.getFullName();
            logToConsole("Starting processing:  " + moduleElementName);
            myASTVisitor.myFunctionTestCaseVisitHandler.clearEverything();
            if (Boolean.parseBoolean(props.getProperty("ast.log.enabled"))) {
                definitions.accept(logger);
            }
            definitions.accept(visitor);
            logToConsole("Finished processing:  " + moduleElementName);
        }
    }
}
Also used : LoggerVisitor(org.eclipse.titan.codegenerator.experimental.LoggerVisitor) Definitions(org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions)

Example 2 with Definitions

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

the class AstWalkerJava method walkChildren.

private void walkChildren(ASTVisitor visitor, Object[] children) {
    LoggerVisitor logger = new LoggerVisitor();
    for (Object child : children) {
        if (child instanceof Definitions) {
            Definitions definitions = (Definitions) child;
            moduleElementName = definitions.getFullName();
            logToConsole("Starting processing:  " + moduleElementName);
            myASTVisitor.myFunctionTestCaseVisitHandler.clearEverything();
            if (Boolean.parseBoolean(props.getProperty("ast.log.enabled"))) {
                definitions.accept(logger);
            }
            definitions.accept(visitor);
            logToConsole("Finished processing:  " + moduleElementName);
        }
    }
}
Also used : LoggerVisitor(org.eclipse.titan.codegenerator.experimental.LoggerVisitor) Definitions(org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions)

Example 3 with Definitions

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

the class Type method checkThisReferencedValue.

/**
 * Checks the provided referenced value.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param value
 *                the referenced value to be checked.
 * @param lhs
 *                the assignment to check against
 * @param expectedValue
 *                the expectations we have for the value.
 * @param referenceChain
 *                the reference chain to detect circular references.
 * @param strElem
 *                true if the value to be checked is an element of a
 *                string
 * @return true if the value contains a reference to lhs
 */
private boolean checkThisReferencedValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final Expected_Value_type expectedValue, final IReferenceChain referenceChain, final boolean subCheck, final boolean strElem) {
    final Reference reference = ((Referenced_Value) value).getReference();
    final Assignment assignment = reference.getRefdAssignment(timestamp, true, referenceChain);
    if (assignment == null) {
        value.setIsErroneous(true);
        return false;
    }
    final Assignment myAssignment = getDefiningAssignment();
    if (myAssignment != null && myAssignment instanceof Definition) {
        final String referingModuleName = value.getMyScope().getModuleScope().getName();
        if (!((Definition) myAssignment).referingHere.contains(referingModuleName)) {
            ((Definition) myAssignment).referingHere.add(referingModuleName);
        }
    }
    assignment.check(timestamp);
    final boolean selfReference = assignment == lhs;
    boolean isConst = false;
    boolean errorFlag = false;
    boolean checkRunsOn = false;
    IType governor = null;
    if (assignment.getIsErroneous()) {
        value.setIsErroneous(true);
    } else {
        switch(assignment.getAssignmentType()) {
            case A_CONST:
                isConst = true;
                break;
            case A_OBJECT:
            case A_OS:
                final ISetting setting = reference.getRefdSetting(timestamp);
                if (setting == null || setting.getIsErroneous(timestamp)) {
                    value.setIsErroneous(true);
                    return selfReference;
                }
                if (!Setting_type.S_V.equals(setting.getSettingtype())) {
                    reference.getLocation().reportSemanticError(MessageFormat.format("This InformationFromObjects construct does not refer to a value: {0}", value.getFullName()));
                    value.setIsErroneous(true);
                    return selfReference;
                }
                governor = ((Value) setting).getMyGovernor();
                if (governor != null) {
                    isConst = true;
                }
                break;
            case A_EXT_CONST:
            case A_MODULEPAR:
                if (Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format("Reference to an (evaluatable) constant value was expected instead of {0}", assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_VAR:
            case A_PAR_VAL:
            case A_PAR_VAL_IN:
            case A_PAR_VAL_OUT:
            case A_PAR_VAL_INOUT:
                switch(expectedValue) {
                    case EXPECTED_CONSTANT:
                        value.getLocation().reportSemanticError(MessageFormat.format("Reference to a constant value was expected instead of {0}", assignment.getDescription()));
                        errorFlag = true;
                        break;
                    case EXPECTED_STATIC_VALUE:
                        value.getLocation().reportSemanticError(MessageFormat.format("Reference to a static value was expected instead of {0}", assignment.getDescription()));
                        errorFlag = true;
                        break;
                    default:
                        break;
                }
                break;
            case A_TEMPLATE:
            case A_MODULEPAR_TEMPLATE:
            case A_VAR_TEMPLATE:
            case A_PAR_TEMP_IN:
            case A_PAR_TEMP_OUT:
            case A_PAR_TEMP_INOUT:
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_FUNCTION_RVAL:
                checkRunsOn = true;
                switch(expectedValue) {
                    case EXPECTED_CONSTANT:
                        {
                            final String message = MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    case EXPECTED_STATIC_VALUE:
                        {
                            final String message = MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    default:
                        break;
                }
                break;
            case A_EXT_FUNCTION_RVAL:
                switch(expectedValue) {
                    case EXPECTED_CONSTANT:
                        {
                            final String message = MessageFormat.format("Reference to a constant value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    case EXPECTED_STATIC_VALUE:
                        {
                            final String message = MessageFormat.format("Reference to a static value was expected instead of the return value of {0}", assignment.getDescription());
                            value.getLocation().reportSemanticError(message);
                            errorFlag = true;
                        }
                        break;
                    default:
                        break;
                }
                break;
            case A_FUNCTION_RTEMP:
                checkRunsOn = true;
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED_INSTEADOFCALL, assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_EXT_FUNCTION_RTEMP:
                if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    value.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED_INSTEADOFCALL, assignment.getDescription()));
                    errorFlag = true;
                }
                break;
            case A_FUNCTION:
            case A_EXT_FUNCTION:
                value.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of a call of {1}, which does not have a return type", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", assignment.getDescription()));
                value.setIsErroneous(true);
                return selfReference;
            default:
                value.getLocation().reportSemanticError(MessageFormat.format("Reference to a {0} was expected instead of {1}", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", assignment.getDescription()));
                value.setIsErroneous(true);
                return selfReference;
        }
    }
    if (checkRunsOn) {
        reference.getMyScope().checkRunsOnScope(timestamp, assignment, reference, "call");
    }
    if (governor == null) {
        final IType type = assignment.getType(timestamp);
        if (type != null) {
            governor = type.getFieldType(timestamp, reference, 1, expectedValue, referenceChain, false);
        }
    }
    if (governor == null) {
        value.setIsErroneous(true);
        return selfReference;
    }
    final TypeCompatibilityInfo info = new TypeCompatibilityInfo(this, governor, true);
    info.setStr1Elem(strElem);
    info.setStr2Elem(reference.refersToStringElement());
    final CompatibilityLevel compatibilityLevel = getCompatibility(timestamp, governor, info, null, null);
    if (compatibilityLevel != CompatibilityLevel.COMPATIBLE) {
        // Port or signature values do not exist at all. These
        // errors are already
        // reported at those definitions. Extra errors should
        // not be reported
        // here.
        final IType type = getTypeRefdLast(timestamp, null);
        switch(type.getTypetype()) {
            case TYPE_PORT:
                // neither port values nor templates exist
                break;
            case TYPE_SIGNATURE:
                if (Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
                    final String message = MessageFormat.format("Type mismatch: a signature template of type `{0}'' was expected instead of `{1}''", getTypename(), governor.getTypename());
                    value.getLocation().reportSemanticError(message);
                }
                break;
            case TYPE_SEQUENCE_OF:
            case TYPE_ASN1_SEQUENCE:
            case TYPE_TTCN3_SEQUENCE:
            case TYPE_ARRAY:
            case TYPE_ASN1_SET:
            case TYPE_TTCN3_SET:
            case TYPE_SET_OF:
            case TYPE_ASN1_CHOICE:
            case TYPE_TTCN3_CHOICE:
            case TYPE_ANYTYPE:
                if (compatibilityLevel == CompatibilityLevel.INCOMPATIBLE_SUBTYPE) {
                    value.getLocation().reportSemanticError(info.getSubtypeError());
                } else {
                    value.getLocation().reportSemanticError(info.toString());
                }
                break;
            default:
                if (compatibilityLevel == CompatibilityLevel.INCOMPATIBLE_SUBTYPE) {
                    value.getLocation().reportSemanticError(info.getSubtypeError());
                } else {
                    final String message = MessageFormat.format("Type mismatch: a {0} of type `{1}'' was expected instead of `{2}''", Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) ? "value or template" : "value", getTypename(), governor.getTypename());
                    value.getLocation().reportSemanticError(message);
                }
                break;
        }
        errorFlag = true;
    } else {
        if (GeneralConstants.WARNING.equals(typeCompatibilitySeverity)) {
            if (info.getNeedsConversion()) {
                value.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, this.getTypename(), governor.getTypename()));
            }
        }
    }
    if (errorFlag) {
        value.setIsErroneous(true);
        return selfReference;
    }
    // checking for circular references
    final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
    if (isConst && !last.getIsErroneous(timestamp)) {
        if (subCheck && (subType != null)) {
            subType.checkThisValue(timestamp, value);
        }
    }
    return selfReference;
}
Also used : Value_Assignment(org.eclipse.titan.designer.AST.ASN1.Value_Assignment) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)

Example 4 with Definitions

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

the class For_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    if (definitions != null) {
        definitions.check(timestamp);
    }
    if (initialAssignment != null) {
        initialAssignment.check(timestamp);
    }
    if (finalExpression != null) {
        finalExpression.setLoweridToReference(timestamp);
        final IValue lastValue = finalExpression.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
        final Type_type temp = lastValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        switch(temp) {
            case TYPE_BOOL:
                if (!lastValue.isUnfoldable(timestamp)) {
                    if (((Boolean_Value) lastValue).getValue()) {
                        finalExpression.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), UNNECESSARYCONTROL);
                    } else {
                        finalExpression.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), NEVERREACH);
                    }
                }
                break;
            default:
                location.reportSemanticError(OPERANDERROR);
                finalExpression.setIsErroneous(true);
                break;
        }
        if (finalExpression.getMyGovernor() == null) {
            finalExpression.setMyGovernor(new Boolean_Type());
        }
    }
    if (stepAssignment != null) {
        stepAssignment.check(timestamp);
    }
    if (statementblock != null) {
        statementblock.setMyLaicStmt(null, this);
        statementblock.check(timestamp);
    // warning for "return" has been removed. Not valid problem
    }
    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 5 with Definitions

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions 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)

Aggregations

Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)10 Location (org.eclipse.titan.designer.AST.Location)6 Reference (org.eclipse.titan.designer.AST.Reference)6 Definitions (org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions)6 ArrayList (java.util.ArrayList)5 Identifier (org.eclipse.titan.designer.AST.Identifier)5 HashSet (java.util.HashSet)4 IFile (org.eclipse.core.resources.IFile)4 Assignment (org.eclipse.titan.designer.AST.Assignment)4 Module (org.eclipse.titan.designer.AST.Module)4 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)4 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)4 LoggerVisitor (org.eclipse.titan.codegenerator.experimental.LoggerVisitor)3 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)3 IAppendableSyntax (org.eclipse.titan.designer.AST.TTCN3.IAppendableSyntax)3 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)3 Map (java.util.Map)2 IProject (org.eclipse.core.resources.IProject)2 IRegion (org.eclipse.jface.text.IRegion)2 DeleteEdit (org.eclipse.text.edits.DeleteEdit)2