use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class Type method checkVariants.
/**
* Checks the type's variant attributes (when using the new codec handling).
*/
public void checkVariants(final CompilationTimeStamp timestamp) {
if (isAsn() || ownerType != TypeOwner_type.OT_TYPE_DEF) {
return;
}
WithAttributesPath globalAttributesPath;
final Def_Type def = (Def_Type) owner;
final Group nearest_group = def.getParentGroup();
if (nearest_group == null) {
// no group, use the module
Module myModule = myScope.getModuleScope();
globalAttributesPath = ((TTCN3Module) myModule).getAttributePath();
} else {
globalAttributesPath = nearest_group.getAttributePath();
}
if (globalAttributesPath != null) {
// process all global variants, not just the closest group
final List<SingleWithAttribute> realAttributes = globalAttributesPath.getRealAttributes(timestamp);
for (int i = 0; i < realAttributes.size(); i++) {
final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Variant_Attribute) {
checkThisVariant(timestamp, singleWithAttribute, true);
}
}
}
// check local variant attributes second, so they overwrite global ones if they
// conflict with each other
final WithAttributesPath attributePath = getAttributePath();
if (attributePath != null) {
final MultipleWithAttributes multipleWithAttributes = attributePath.getAttributes();
if (multipleWithAttributes != null) {
for (int i = 0; i < multipleWithAttributes.getNofElements(); i++) {
final SingleWithAttribute singleWithAttribute = multipleWithAttributes.getAttribute(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Variant_Attribute) {
final Qualifiers qualifiers = singleWithAttribute.getQualifiers();
if (qualifiers != null && qualifiers.getNofQualifiers() > 0) {
for (int j = 0; j < qualifiers.getNofQualifiers(); j++) {
final Qualifier qualifier = qualifiers.getQualifierByIndex(j);
final List<ISubReference> fieldsOrArrays = new ArrayList<ISubReference>();
for (int k = 0; k < qualifier.getNofSubReferences(); k++) {
fieldsOrArrays.add(qualifier.getSubReferenceByIndex(k));
}
final Reference reference = new Reference(null, fieldsOrArrays);
final IType type = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_CONSTANT, false);
if (type != null) {
if (type.getMyScope() != myScope) {
qualifier.getLocation().reportSemanticWarning("Variant attribute is ignored, because it refers to a type from a different type definition");
} else {
type.checkThisVariant(timestamp, singleWithAttribute, false);
}
}
}
} else {
checkThisVariant(timestamp, singleWithAttribute, false);
}
}
}
}
}
// check the coding attributes set by the variants
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
checkCodingAttributes(timestamp, chain);
chain.release();
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class BrokenPartsViaReferences method collectBrokenParts.
protected Map<Module, List<AssignmentHandler>> collectBrokenParts(final List<Module> startModules, final Map<Module, List<Module>> invertedImports, final boolean useIncrementalParsing) {
final List<Module> startModulesCopy = new ArrayList<Module>(startModules);
final Map<Module, List<AssignmentHandler>> moduleAndBrokenAssignments = new HashMap<Module, List<AssignmentHandler>>();
processStartModules(startModulesCopy, moduleAndBrokenAssignments);
for (int i = 0; i < startModulesCopy.size() && !isTooSlow(); ++i) {
final Module startModule = startModulesCopy.get(i);
List<AssignmentHandler> startAssignments;
if (moduleAndBrokenAssignments.containsKey(startModule)) {
startAssignments = moduleAndBrokenAssignments.get(startModule);
} else {
// <<<<<< getAssignments() used in collectBrokenModulesViaInvertedImports, too
startAssignments = getAssignmentsFrom(startModule);
moduleAndBrokenAssignments.put(startModule, startAssignments);
}
if (startAssignments.isEmpty()) {
continue;
}
final List<Module> whereStartModuleUsed = invertedImports.get(startModule);
// If not incremental parsing is used, also all importing modules shall be fully reanalyze
if (!useIncrementalParsing || (startModule instanceof TTCN3Module && ((TTCN3Module) startModule).getDefinitions().getLastCompilationTimeStamp() == null)) {
for (int j = 0; j < whereStartModuleUsed.size(); ++j) {
final Module dependentModule = whereStartModuleUsed.get(j);
// overwrites the dependentAssignments with the full list of assignments
final List<AssignmentHandler> dependentAssignments = getAssignmentsFrom(dependentModule);
moduleAndBrokenAssignments.put(dependentModule, dependentAssignments);
}
} else {
// incremental parsing + no name change
for (int j = 0; j < whereStartModuleUsed.size(); ++j) {
final Module dependentModule = whereStartModuleUsed.get(j);
List<AssignmentHandler> dependentAssignments;
if (moduleAndBrokenAssignments.containsKey(dependentModule)) {
dependentAssignments = moduleAndBrokenAssignments.get(dependentModule);
} else {
dependentAssignments = getAssignmentsFrom(dependentModule);
moduleAndBrokenAssignments.put(dependentModule, dependentAssignments);
}
// We have to separate broken and not broken definition, because of postcheck.
final List<AssignmentHandler> brokens = new ArrayList<AssignmentHandler>();
final List<AssignmentHandler> notBrokens = new ArrayList<AssignmentHandler>();
for (int s = 0; s < startAssignments.size(); ++s) {
final AssignmentHandler startAssignment = startAssignments.get(s);
if (startAssignment.getIsContagious()) {
for (int d = 0; d < dependentAssignments.size(); ++d) {
final AssignmentHandler dependentAssignment = dependentAssignments.get(d);
// only infection and contagion are checked
dependentAssignment.check(startAssignment);
if (dependentAssignment.getIsInfected()) {
if (!startModulesCopy.contains(dependentModule)) {
startModulesCopy.add(dependentModule);
}
if (!brokens.contains(dependentAssignment)) {
brokens.add(dependentAssignment);
}
}
}
}
}
for (int d = 0; d < dependentAssignments.size(); ++d) {
final AssignmentHandler dependentAssignment = dependentAssignments.get(d);
if (!dependentAssignment.getIsInfected()) {
notBrokens.add(dependentAssignment);
}
}
// Have to post check of local definition of modules.
// A definition can reference an other definition too.
checkLocalAssignments(brokens, notBrokens);
// so we have to delete it from moduleAndBrokenDefs.
if (!startModulesCopy.contains(dependentModule)) {
moduleAndBrokenAssignments.remove(dependentModule);
}
}
}
}
return moduleAndBrokenAssignments;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkFromClause.
/**
* Checks a from clause reference and a sender redirect to see if they
* really references valid component types.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param source
* the source statement to report errors to.
* @param portType
* the type of the port used in the statement. Used to
* find the address type in effect.
* @param fromClause
* the from clause to check
* @param redirectSender
* the sender redirect to check.
*/
public static void checkFromClause(final CompilationTimeStamp timestamp, final Statement source, final Port_Type portType, final TemplateInstance fromClause, final Reference redirectSender) {
IType addressType = null;
if (portType != null) {
addressType = portType.getPortBody().getAddressType(timestamp);
} else if (source != null && source.getMyStatementBlock() != null) {
final Module module = source.getMyStatementBlock().getModuleScope();
if (module != null && module_type.TTCN3_MODULE.equals(module.getModuletype())) {
addressType = ((TTCN3Module) module).getAddressType(timestamp);
}
}
boolean senderRedirectChecked = false;
IType fromClauseType = null;
if (fromClause != null) {
fromClauseType = fromClause.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
ITTCN3Template templateBody = fromClause.getTemplateBody();
if (fromClauseType == null) {
if (addressType != null) {
templateBody = addressType.checkThisTemplateRef(timestamp, templateBody);
} else {
templateBody = templateBody.setLoweridToReference(timestamp);
}
fromClauseType = templateBody.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
}
if (fromClauseType == null) {
fromClauseType = checkSenderRedirect(timestamp, addressType, redirectSender);
senderRedirectChecked = true;
}
if (fromClauseType == null) {
// trying to figure out whether the template is
// a component reference or an SUT address
boolean isComponentReference;
if (Type_type.TYPE_COMPONENT.equals(templateBody.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE))) {
isComponentReference = true;
} else {
switch(templateBody.getTemplatetype()) {
case SPECIFIC_VALUE:
// treat 'null' as component
// reference
isComponentReference = Value_type.TTCN3_NULL_VALUE.equals(((SpecificValue_Template) templateBody).getSpecificValue().getValuetype());
break;
case ANY_VALUE:
case ANY_OR_OMIT:
isComponentReference = true;
break;
default:
isComponentReference = false;
break;
}
}
if (isComponentReference) {
// the argument is a component
// reference: get a pool type
fromClauseType = TypeFactory.createType(Type_type.TYPE_COMPONENT);
} else if (addressType != null) {
// the argument is not a component
// reference: try the address type
fromClauseType = addressType;
}
}
if (fromClauseType != null) {
fromClause.check(timestamp, fromClauseType);
if (addressType == null || !addressType.isCompatible(timestamp, fromClauseType, null, null, null)) {
// from_clause_type must be a component
// type
final IType last = fromClauseType.getTypeRefdLast(timestamp);
if (last.getIsErroneous(timestamp)) {
fromClauseType = null;
} else if (Type_type.TYPE_COMPONENT.equals(last.getTypetype())) {
if (Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype())) {
checkComponentReference(timestamp, source, ((SpecificValue_Template) templateBody).getSpecificValue(), true, true);
}
} else {
final String message = MessageFormat.format("The type of the template should be a component type {0} instead of `{1}''", (addressType == null) ? "" : "or the `address' type ", fromClauseType.getTypename());
fromClause.getLocation().reportSemanticError(message);
fromClauseType = null;
}
}
} else {
fromClause.getLocation().reportSemanticError("Cannot determine the type of the template");
}
}
if (!senderRedirectChecked) {
final IType senderRedirectType = checkSenderRedirect(timestamp, addressType, redirectSender);
if (fromClauseType != null && senderRedirectType != null && !fromClauseType.isIdentical(timestamp, senderRedirectType)) {
final String message = MessageFormat.format("The types in `from'' clause and `sender'' redirect are not the same: `{0}'' was expected instead of `{1}''", fromClauseType.getTypename(), senderRedirectType.getTypename());
senderRedirectType.getLocation().reportSemanticError(message);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkToClause.
/**
* Checks a to clause reference to see if it really references valid
* component type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param source
* the source statement of this check.
* @param portType
* the type of the port used in the statement. Used to
* find the address type in effect.
* @param toClause
* the to clause to check
*/
public static void checkToClause(final CompilationTimeStamp timestamp, final Statement source, final Port_Type portType, final IValue toClause) {
if (toClause == null) {
return;
}
IType addressType = null;
if (portType != null) {
addressType = portType.getPortBody().getAddressType(timestamp);
} else if (source != null) {
final Module module = source.getMyStatementBlock().getModuleScope();
if (module != null && module_type.TTCN3_MODULE.equals(module.getModuletype())) {
addressType = ((TTCN3Module) module).getAddressType(timestamp);
}
}
if (addressType == null) {
checkComponentReference(timestamp, source, toClause, true, true);
} else {
// detect possible enumerated values (address may be an
// enumerated type)
final IValue temp = addressType.checkThisValueRef(timestamp, toClause);
// try to figure out whether the argument is a component
// reference or an SUT address
boolean isAddress;
final IType governor = temp.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (governor == null) {
isAddress = !Type_type.TYPE_COMPONENT.equals(temp.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE));
} else {
isAddress = addressType.isCompatible(timestamp, governor, null, null, null);
}
if (isAddress) {
addressType.checkThisValue(timestamp, temp, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
} else {
checkComponentReference(timestamp, source, temp, true, true);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.
the class Address_Type method getTypeRefd.
@Override
public /**
* {@inheritDoc}
*/
IType getTypeRefd(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
if (refChain != null && !refChain.add(this)) {
setIsErroneous(true);
return this;
}
if (myScope != null) {
final TTCN3Module module = (TTCN3Module) myScope.getModuleScope();
address = module.getAddressType(timestamp);
if (address != null) {
return address;
}
location.reportSemanticError("Type `address' is not defined in this module");
}
setIsErroneous(true);
return this;
}
Aggregations