Search in sources :

Example 46 with Definition

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

the class Kill_Statement method generateCode.

@Override
public /**
 * {@inheritDoc}
 */
void generateCode(final JavaGenData aData, final StringBuilder source) {
    aData.addCommonLibraryImport("TTCN_Runtime");
    final ExpressionStruct expression = new ExpressionStruct();
    if (componentReference == null) {
        aData.addBuiltinTypeImport("TitanComponent");
        expression.expression.append("TTCN_Runtime.kill_component(TitanComponent.ALL_COMPREF)");
    } else {
        final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
        final IValue last = componentReference.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
        referenceChain.release();
        if (last.getValuetype() == Value_type.REFERENCED_VALUE) {
            // the argument is a simple component reference
            last.generateCodeExpressionMandatory(aData, expression, true);
            expression.expression.append(".kill()");
        } else {
            boolean refers_to_self = false;
            if (last.getValuetype() == Value_type.EXPRESSION_VALUE) {
                // the argument is a special component reference (mtc, self, etc.)
                switch(((Expression_Value) last).getOperationType()) {
                    case MTC_COMPONENT_OPERATION:
                        {
                            Definition myDefinition = myStatementBlock.getMyDefinition();
                            if (myDefinition != null && myDefinition.getAssignmentType() == Assignment_type.A_TESTCASE) {
                                refers_to_self = true;
                            }
                            break;
                        }
                    case SELF_COMPONENT_OPERATION:
                        refers_to_self = true;
                    default:
                        break;
                }
            }
            if (refers_to_self) {
                expression.expression.append("TTCN_Runtime.kill_execution()");
            } else {
                expression.expression.append("TTCN_Runtime.kill_component(");
                last.generateCodeExpression(aData, expression, false);
                expression.expression.append(')');
            }
        }
    }
    expression.mergeExpression(source);
}
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) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 47 with Definition

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

the class StatementBlock method registerDefinition.

/**
 * Registers a definition (for example new variable) into the list of
 * definitions available in this statement block.
 *
 * Please note, that this is done while the semantic check is happening,
 * as it must not be allowed to reach definitions not yet defined.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param definition
 *                the definition to register.
 */
public void registerDefinition(final CompilationTimeStamp timestamp, final Definition definition) {
    if (definition == null) {
        return;
    }
    final Identifier identifier = definition.getIdentifier();
    if (identifier == null) {
        return;
    }
    if (definitionMap == null) {
        definitionMap = new HashMap<String, Definition>(3);
    }
    final String definitionName = identifier.getName();
    if (definitionMap.containsKey(definitionName)) {
        if (definition.getLocation() != null && definitionMap.get(definitionName).getLocation() != null) {
            final Location otherLocation = definitionMap.get(definitionName).getLocation();
            otherLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
            definition.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
        }
    } else {
        definitionMap.put(definitionName, definition);
        if (parentScope != null && definition.getLocation() != null) {
            if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
                definition.getLocation().reportSemanticError(MessageFormat.format(HIDINGSCOPEELEMENT, identifier.getDisplayName()));
                final List<ISubReference> subReferences = new ArrayList<ISubReference>();
                subReferences.add(new FieldSubReference(identifier));
                final Reference reference = new Reference(null, subReferences);
                final Assignment assignment = parentScope.getAssBySRef(timestamp, reference);
                if (assignment != null && assignment.getLocation() != null) {
                    assignment.getLocation().reportSingularSemanticError(MessageFormat.format(HIDDENSCOPEELEMENT, identifier.getDisplayName()));
                }
            } else if (parentScope.isValidModuleId(identifier)) {
                definition.getLocation().reportSemanticWarning(MessageFormat.format(HIDINGMODULEIDENTIFIER, identifier.getDisplayName()));
            }
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Identifier(org.eclipse.titan.designer.AST.Identifier) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ArrayList(java.util.ArrayList) NULL_Location(org.eclipse.titan.designer.AST.NULL_Location) Location(org.eclipse.titan.designer.AST.Location)

Example 48 with Definition

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

the class AssignmentHandlerComponent method collectDataFrom.

public void collectDataFrom(final ComponentTypeBody componentTypeBody) {
    for (final Definition tempDefinition : componentTypeBody.getDefinitions()) {
        final ReferenceCollector referenceCollector = new ReferenceCollector();
        tempDefinition.accept(referenceCollector);
        final Set<String> references = computeReferences(referenceCollector.getReferences());
        if (containsErroneousReference(referenceCollector.getReferences())) {
            setIsInfected(true);
        }
        componentDefinitions.put(tempDefinition, references);
    }
    processComponentTypeReferenceList(componentTypeBody.getAttributeExtensions());
    processComponentTypeReferenceList(componentTypeBody.getExtensions());
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 49 with Definition

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

the class BrokenPartsViaReferences method processStartModules.

public void processStartModules(final List<Module> startModules, final Map<Module, List<AssignmentHandler>> moduleAndBrokenAssignments) {
    for (Module startModule : startModules) {
        if (isTooSlow()) {
            return;
        }
        if (startModule instanceof TTCN3Module && startModule.getLastCompilationTimeStamp() != null && !startModule.isCheckRoot()) {
            // definition name has not changed but module semantically has not been checked:
            final Assignments startAssignments = startModule.getAssignments();
            final List<AssignmentHandler> brokens = new ArrayList<AssignmentHandler>();
            final List<AssignmentHandler> notBrokens = new ArrayList<AssignmentHandler>();
            for (Assignment assignment : startAssignments) {
                MarkerHandler.markAllSemanticMarkersForRemoval(assignment);
            }
            for (int d = 0; d < startAssignments.getNofAssignments(); ++d) {
                final Assignment startAssignment = startAssignments.getAssignmentByIndex(d);
                final AssignmentHandler assignmentHandler = AssignmentHandlerFactory.getDefinitionHandler(startAssignment);
                startAssignment.check(timestamp);
                startAssignment.accept(assignmentHandler);
                if (startAssignment.isCheckRoot()) {
                    assignmentHandler.setIsInfected(true);
                    startAssignment.notCheckRoot();
                    assignmentHandler.addReason("Definition's infected, because of incremental parsing.");
                    brokens.add(assignmentHandler);
                } else if (assignmentHandler.getIsInfected()) {
                    assignmentHandler.addReason("Definition contains an infected reference.");
                    brokens.add(assignmentHandler);
                } else {
                    notBrokens.add(assignmentHandler);
                }
            }
            if (!brokens.isEmpty()) {
                checkLocalAssignments(brokens, notBrokens);
                if (moduleAndBrokenAssignments.containsKey(startModule)) {
                    moduleAndBrokenAssignments.get(startModule).addAll(brokens);
                } else {
                    moduleAndBrokenAssignments.put(startModule, brokens);
                }
            }
        } else {
            if (startModule.getLastCompilationTimeStamp() == null) {
                // The markers have been marked for removal only for ASN1 modules
                startModule.check(timestamp);
            }
            // puts additional markers!
            final List<AssignmentHandler> startAssignments = getAssignmentsFrom(startModule);
            for (AssignmentHandler assignmentHandler : startAssignments) {
                assignmentHandler.initStartParts();
                assignmentHandler.assignment.notCheckRoot();
                assignmentHandler.addReason("Parent module's CompilationTimeStamp is null.");
            }
            if (moduleAndBrokenAssignments.containsKey(startModule)) {
                moduleAndBrokenAssignments.get(startModule).addAll(startAssignments);
            } else {
                moduleAndBrokenAssignments.put(startModule, startAssignments);
            }
        }
        startModule.notCheckRoot();
    }
}
Also used : Undefined_Assignment(org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Assignments(org.eclipse.titan.designer.AST.Assignments) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 50 with Definition

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

the class ChangeCreator method calculateMultiDeclarationMoveContent.

/**
 * Returns the content of an {@InsertEdit} to move a variable from a declaration list
 */
private String calculateMultiDeclarationMoveContent(final String fileContent, final StatementNode declStNode) {
    final MultiDeclaration md = declStNode.getMultiDeclaration();
    final StatementNode firstDeclPart = md.getFirstStatement();
    final Definition firstDefInStmt = firstDeclPart.getDeclaredVar().getDefinition();
    final Definition defVarToMove = declStNode.getDeclaredVar().getDefinition();
    final Definition_Statement declStmt = (Definition_Statement) declStNode.getAstNode();
    final Location declStmtLoc = declStmt.getLocation();
    final String stmtContent = fileContent.substring(declStmtLoc.getOffset(), declStmtLoc.getEndOffset());
    if (!stmtContent.contains(",")) {
        ErrorReporter.logError("ChangeCreator.calculateMultiDeclarationMoveContent(): Given statement" + " is not a multi-declaration statement; loc: " + declStmtLoc.getOffset() + "-" + declStmtLoc.getEndOffset() + " in file " + declStmtLoc.getFile());
        return null;
    }
    int prefixOffset;
    int prefixEndOffset;
    if (firstDefInStmt.equals(defVarToMove)) {
        // first var to move
        prefixOffset = findLineBeginningOffset(fileContent, declStmtLoc.getOffset());
        prefixEndOffset = declStmtLoc.getOffset();
    } else {
        // not first var to move
        prefixOffset = findLineBeginningOffset(fileContent, declStmtLoc.getOffset());
        prefixEndOffset = firstDefInStmt.getIdentifier().getLocation().getOffset();
    }
    String prefixContent = fileContent.substring(prefixOffset, prefixEndOffset);
    // 
    final int varOffset = defVarToMove.getLocation().getOffset();
    final int varEndOffset = defVarToMove.getLocation().getEndOffset();
    String varContent = fileContent.substring(varOffset, varEndOffset);
    String suffixContent = "\n";
    if (varContent.charAt(varContent.length() - 1) != ';') {
        suffixContent = ";" + suffixContent;
    }
    // remove newlines from varContent
    prefixContent = prefixContent.replaceAll("[\n\r]", " ");
    varContent = varContent.replaceAll("[\n\r]", " ");
    // System.err.println("mdcopyloc -->>>" + prefixContent + "<>" + varContent + "<>" + suffixContent + "<<<");
    return prefixContent + varContent + suffixContent;
}
Also used : Definition_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Definition_Statement) MultiDeclaration(org.eclipse.titanium.refactoring.scope.nodes.MultiDeclaration) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) StatementNode(org.eclipse.titanium.refactoring.scope.nodes.StatementNode) Location(org.eclipse.titan.designer.AST.Location)

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