use of org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope in project titan.EclipsePlug-ins by eclipse.
the class RenameRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
// search
idsMap = rf.findAllReferences(module, file.getProject(), pm, reportDebugInformation);
// add the referred identifier to the map of found identifiers
Identifier refdIdentifier = rf.getReferredIdentifier();
Module refdModule = rf.assignment.getMyScope().getModuleScope();
if (idsMap.containsKey(refdModule)) {
idsMap.get(refdModule).add(new Hit(refdIdentifier));
} else {
ArrayList<Hit> identifierList = new ArrayList<Hit>();
identifierList.add(new Hit(refdIdentifier));
idsMap.put(refdModule, identifierList);
}
// scopes
if (rf.fieldId == null) {
// check that in all affected scopes there is no
// definition with the new name
Identifier.Identifier_type idType = Identifier_type.ID_TTCN;
if (rf.scope.getModuleScope() instanceof ASN1Module) {
idType = Identifier_type.ID_ASN;
}
Identifier newId = new Identifier(idType, newIdentifierName);
// check for assignment with given id in all sub-scopes
// of the assignment's scope
// TODO: this does not detect runs on <-> component
// member conflicts because the RunsOnScope is not a
// sub-scope of the ComponentTypeBody scope,
// also it does not go into other modules
Scope rootScope = rf.assignment.getMyScope();
if (rootScope instanceof NamedBridgeScope && rootScope.getParentScope() != null) {
rootScope = rootScope.getParentScope();
}
SubScopeVisitor subScopeVisitor = new SubScopeVisitor(rootScope);
module.accept(subScopeVisitor);
List<Scope> subScopes = subScopeVisitor.getSubScopes();
subScopes.add(rootScope);
for (Scope ss : subScopes) {
if (ss.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), newId)) {
List<ISubReference> subReferences = new ArrayList<ISubReference>();
subReferences.add(new FieldSubReference(newId));
Reference reference = new Reference(null, subReferences);
Assignment assignment = ss.getAssBySRef(CompilationTimeStamp.getBaseTimestamp(), reference);
if (assignment != null && assignment.getLocation() != null) {
result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS2, newId.getDisplayName(), module.getName(), assignment.getLocation().getLine()));
} else {
result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS, newId.getDisplayName()));
}
// to avoid spam and multiple messages for the same conflict
return result;
}
}
} else {
boolean alreadyExists = false;
// name
if (rf.type instanceof TTCN3_Set_Seq_Choice_BaseType) {
alreadyExists = ((TTCN3_Set_Seq_Choice_BaseType) rf.type).hasComponentWithName(newIdentifierName);
} else if (rf.type instanceof TTCN3_Enumerated_Type) {
alreadyExists = ((TTCN3_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_TTCN, newIdentifierName));
} else if (rf.type instanceof ASN1_Choice_Type) {
alreadyExists = ((ASN1_Choice_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Enumerated_Type) {
alreadyExists = ((ASN1_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Sequence_Type) {
alreadyExists = ((ASN1_Sequence_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
} else if (rf.type instanceof ASN1_Set_Type) {
alreadyExists = ((ASN1_Set_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
}
if (alreadyExists) {
result.addError(MessageFormat.format(FIELDALREADYEXISTS, newIdentifierName, rf.type.getTypename()));
}
}
return result;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope in project titan.EclipsePlug-ins by eclipse.
the class ReferenceFinder method detectSmallestScope.
/**
* Detect the smallest scope where the references should be searched
*
* @param assignment
* The assignment
* @return The detected scope
*/
private Scope detectSmallestScope(final Assignment assignment) {
Scope localScope = assignment.getMyScope();
final Module module = localScope.getModuleScope();
if (localScope instanceof StatementBlock) {
final StatementBlock statementBlock = (StatementBlock) localScope;
if (statementBlock.getMyDefinition() instanceof Def_Altstep) {
localScope = localScope.getParentScope();
}
if (statementBlock.hasEnclosingLoopOrAltguard()) {
localScope = localScope.getParentScope();
}
}
if (localScope instanceof NamedBridgeScope) {
localScope = localScope.getParentScope();
}
// control,function,testcase,altstep then it is global
if (localScope instanceof Assignments && localScope.getParentScope() == module) {
localScope = module;
} else // treat it as global definition
if (localScope instanceof ComponentTypeBody) {
// FIXME this still does not make them global, that is something completely different.
localScope = module;
} else // search for actual named parameters everywhere
if (localScope instanceof FormalParameterList || localScope instanceof RunsOnScope) {
localScope = module;
} else // For_Statement that must be searched
if (localScope instanceof For_Loop_Definitions) {
localScope = localScope.getParentScope();
}
return localScope;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope in project titan.EclipsePlug-ins by eclipse.
the class SelfComponentExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (myGovernor == null || myScope == null) {
return;
}
final IType governorLast = myGovernor.getTypeRefdLast(timestamp);
if (!Type_type.TYPE_COMPONENT.equals(governorLast.getTypetype())) {
return;
}
final RunsOnScope runsOnScope = myScope.getScopeRunsOn();
if (runsOnScope == null) {
return;
}
final Type componentType = runsOnScope.getComponentType();
if (componentType != null && !governorLast.isCompatible(timestamp, componentType, null, null, null)) {
getLocation().reportSemanticError(MessageFormat.format("Incompatible component types: a component reference of type `{0}'' was expected, but `self'' has type `{1}''", governorLast.getTypename(), componentType.getTypename()));
setIsErroneous(true);
}
checkExpressionDynamicPart(expectedValue, OPERATIONNAME, false, true, false);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope in project titan.EclipsePlug-ins by eclipse.
the class Altstep_Type method checkThisValue.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
final boolean selfReference = super.checkThisValue(timestamp, value, lhs, valueCheckingOptions);
final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
if (last == null || last.getIsErroneous(timestamp)) {
return selfReference;
}
last.setMyGovernor(this);
// already handled ones
switch(value.getValuetype()) {
case OMIT_VALUE:
case REFERENCED_VALUE:
return selfReference;
case UNDEFINED_LOWERIDENTIFIER_VALUE:
if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
return selfReference;
}
break;
default:
break;
}
Def_Altstep altstep = null;
switch(last.getValuetype()) {
case ALTSTEP_REFERENCE_VALUE:
altstep = ((Altstep_Reference_Value) last).getReferredAltstep();
if (altstep == null) {
setIsErroneous(true);
return selfReference;
}
altstep.check(timestamp);
break;
case TTCN3_NULL_VALUE:
value.setValuetype(timestamp, Value_type.FAT_NULL_VALUE);
return selfReference;
case EXPRESSION_VALUE:
case MACRO_VALUE:
// already checked
return selfReference;
default:
value.getLocation().reportSemanticError(ALTSTEPREFERENCEVALUEEXPECTED);
value.setIsErroneous(true);
return selfReference;
}
formalParList.checkCompatibility(timestamp, altstep.getFormalParameterList(), value.getLocation());
final IType temporalRunsOnType = altstep.getRunsOnType(timestamp);
if (temporalRunsOnType != null) {
if (runsOnSelf) {
// check against the runs on component type of the scope of the value
final Scope valueScope = value.getMyScope();
if (valueScope == null) {
value.setIsErroneous(true);
return selfReference;
}
final RunsOnScope runsOnScope = valueScope.getScopeRunsOn();
if (runsOnScope != null) {
final Component_Type componentType = runsOnScope.getComponentType();
if (!runsOnType.isCompatible(timestamp, componentType, null, null, null)) {
value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' clause and the current scope " + "expects component type `{1}'', but {2} runs on `{3}''", getTypename(), componentType.getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
}
} else {
// compatibility using this component type as the scope
if (valueScope instanceof ComponentTypeBody) {
final ComponentTypeBody body = (ComponentTypeBody) valueScope;
if (!runsOnType.isCompatible(timestamp, body.getMyType(), null, null, null)) {
value.getLocation().reportSemanticError(MessageFormat.format("Runs on clause mismatch: type `{0}'' has a `runs on self'' " + "clause and the current component definition is of type `{1}'', but {2} runs on `{3}''", getTypename(), body.getMyType().getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' has a `runs on self'' clause and the current scope does not have a `runs on'' clause," + " but {1} runs on `{2}''", getTypename(), altstep.getDescription(), temporalRunsOnType.getTypename()));
}
}
} else {
if (runsOnRef == null) {
value.getLocation().reportSemanticError(MessageFormat.format(RUNSONLESSEXPECTED, getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
value.setIsErroneous(true);
} else {
if (runsOnType != null && !temporalRunsOnType.isCompatible(timestamp, runsOnType, null, null, null)) {
value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLERUNSONTYPESERROR, getTypename(), runsOnType.getTypename(), altstep.getAssignmentName(), temporalRunsOnType.getTypename()));
value.setIsErroneous(true);
}
}
}
}
if (valueCheckingOptions.sub_check) {
// there is no parent type to check
if (subType != null) {
subType.checkThisValue(timestamp, value);
}
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope in project titan.EclipsePlug-ins by eclipse.
the class Testcase_Type method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
runsOnType = null;
systemType = null;
lastTimeChecked = timestamp;
isErroneous = false;
parseAttributes(timestamp);
if (runsOnRef != null) {
runsOnType = runsOnRef.chkComponentypeReference(timestamp);
if (runsOnType != null) {
final Scope formalParlistPreviosScope = formalParList.getParentScope();
if (formalParlistPreviosScope instanceof RunsOnScope && ((RunsOnScope) formalParlistPreviosScope).getParentScope() == myScope) {
((RunsOnScope) formalParlistPreviosScope).setComponentType(runsOnType);
} else {
final Scope tempScope = new RunsOnScope(runsOnType, myScope);
formalParList.setMyScope(tempScope);
}
}
}
if (systemRef != null) {
systemType = systemRef.chkComponentypeReference(timestamp);
}
formalParList.reset();
formalParList.check(timestamp, Assignment_type.A_TESTCASE);
formalParList.checkNoLazyParams();
checkSubtypeRestrictions(timestamp);
if (myScope != null) {
checkEncode(timestamp);
checkVariants(timestamp);
}
}
Aggregations