use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition 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.Definition in project titan.EclipsePlug-ins by eclipse.
the class Type method checkThisValue.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
value.setIsErroneous(false);
final Assignment assignment = getDefiningAssignment();
if (assignment != null && assignment instanceof Definition) {
final Scope scope = value.getMyScope();
if (scope != null) {
final Module module = scope.getModuleScope();
if (module != null) {
final String referingModuleName = module.getName();
if (!((Definition) assignment).referingHere.contains(referingModuleName)) {
((Definition) assignment).referingHere.add(referingModuleName);
}
} else {
ErrorReporter.logError("The value `" + value.getFullName() + "' does not appear to be in a module");
value.setIsErroneous(true);
}
} else {
ErrorReporter.logError("The value `" + value.getFullName() + "' does not appear to be in a scope");
value.setIsErroneous(true);
}
}
check(timestamp);
final IValue last = value.getValueRefdLast(timestamp, valueCheckingOptions.expected_value, null);
if (last == null || last.getIsErroneous(timestamp) || getIsErroneous(timestamp)) {
return false;
}
if (Value_type.OMIT_VALUE.equals(last.getValuetype()) && !valueCheckingOptions.omit_allowed) {
value.getLocation().reportSemanticError("`omit' value is not allowed in this context");
value.setIsErroneous(true);
return false;
}
boolean selfReference = false;
switch(value.getValuetype()) {
case UNDEFINED_LOWERIDENTIFIER_VALUE:
if (Value_type.REFERENCED_VALUE.equals(last.getValuetype())) {
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
selfReference = checkThisReferencedValue(timestamp, last, lhs, valueCheckingOptions.expected_value, chain, valueCheckingOptions.sub_check, valueCheckingOptions.str_elem);
chain.release();
return selfReference;
}
return false;
case REFERENCED_VALUE:
{
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
selfReference = checkThisReferencedValue(timestamp, value, lhs, valueCheckingOptions.expected_value, chain, valueCheckingOptions.sub_check, valueCheckingOptions.str_elem);
chain.release();
return selfReference;
}
case EXPRESSION_VALUE:
selfReference = value.checkExpressionSelfReference(timestamp, lhs);
if (value.isUnfoldable(timestamp, null)) {
final Type_type temporalType = value.getExpressionReturntype(timestamp, valueCheckingOptions.expected_value);
if (!Type_type.TYPE_UNDEFINED.equals(temporalType) && !isCompatible(timestamp, this.getTypetype(), temporalType, false, value.isAsn())) {
value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLEVALUE, getTypename()));
value.setIsErroneous(true);
}
}
return selfReference;
case MACRO_VALUE:
selfReference = value.checkExpressionSelfReference(timestamp, lhs);
if (value.isUnfoldable(timestamp, null)) {
final Type_type temporalType = value.getExpressionReturntype(timestamp, valueCheckingOptions.expected_value);
if (!Type_type.TYPE_UNDEFINED.equals(temporalType) && !isCompatible(timestamp, this.getTypetype(), temporalType, false, value.isAsn())) {
value.getLocation().reportSemanticError(MessageFormat.format(INCOMPATIBLEVALUE, getTypename()));
value.setIsErroneous(true);
}
return selfReference;
}
break;
default:
break;
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition 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;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class TestcasenameExpression method evaluateValue.
@Override
public /**
* {@inheritDoc}
*/
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
isErroneous = false;
lastTimeChecked = timestamp;
lastValue = this;
// unqualified name or "".
if (myScope != null) {
if (myScope instanceof StatementBlock) {
final StatementBlock block = (StatementBlock) myScope;
final Definition definition = block.getMyDefinition();
if (definition == null) {
// An error would be better here.
lastValue = new Charstring_Value("");
lastValue.copyGeneralProperties(this);
} else {
if (Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
lastValue.copyGeneralProperties(this);
}
}
}
}
// Run-time evaluation.
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition 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;
}
Aggregations