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);
}
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()));
}
}
}
}
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());
}
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();
}
}
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;
}
Aggregations