use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Assignment_Statement method checkTemplateRestriction.
/**
* Checks the template restriction on the assignment referenced on the left hand side.
*
* @param timestamp the time stamp of the actual semantic check cycle.
*/
private void checkTemplateRestriction(final CompilationTimeStamp timestamp) {
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (ass == null) {
return;
}
switch(ass.getAssignmentType()) {
case A_VAR_TEMPLATE:
templateRestriction = ((Def_Var_Template) ass).getTemplateRestriction();
break;
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
templateRestriction = ((FormalParameter) ass).getTemplateRestriction();
break;
default:
templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
break;
}
templateRestriction = TemplateRestriction.getSubRestriction(templateRestriction, timestamp, reference);
generateRestrictionCheck = TemplateRestriction.check(timestamp, (Definition) ass, template, reference);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Type method checkEncode.
/**
* Checks the encodings supported by the type (when using new codec handling).
* TTCN-3 types need to have an 'encode' attribute to support an encoding.
* ASN.1 types automatically support BER, PER and JSON encodings, and XER
* encoding, if set by the compiler option.
*/
public void checkEncode(final CompilationTimeStamp timestamp) {
switch(getTypeRefdLast(timestamp).getTypetypeTtcn3()) {
case TYPE_NULL:
case TYPE_BOOL:
case TYPE_INTEGER:
case TYPE_REAL:
case TYPE_TTCN3_ENUMERATED:
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_OBJECTID:
case TYPE_TTCN3_CHOICE:
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
case TYPE_VERDICT:
case TYPE_ARRAY:
case TYPE_ANYTYPE:
if (!isAsn()) {
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.Encode_Attribute) {
final Attribute_Modifier_type mod = singleWithAttribute.getModifier();
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("Encode attribute is ignored, because it refers to a type from a different type definition");
} else {
type.addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), mod, false);
}
}
}
} else {
addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), mod, false);
}
}
}
}
if (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) {
boolean hasGlobalOverride = false;
boolean modifierConflict = false;
Attribute_Modifier_type firstModifier = Attribute_Modifier_type.MOD_NONE;
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.Encode_Attribute) {
Attribute_Modifier_type modifier = singleWithAttribute.getModifier();
if (i == 0) {
firstModifier = modifier;
} else if (!modifierConflict && modifier != firstModifier) {
modifierConflict = true;
singleWithAttribute.getLocation().reportSemanticError("All 'encode' attributes of a group or module must have the same modifier ('override', '@local' or none)");
}
if (modifier == Attribute_Modifier_type.MOD_OVERRIDE) {
hasGlobalOverride = true;
}
if (hasGlobalOverride && modifierConflict) {
break;
}
}
}
// make a list of the type and its field and element types that inherit
// the global 'encode' attributes
// overriding global attributes are inherited by types with no coding
// table (no 'encode' attributes) of their own
// non-overriding global attributes are inherited by types that have
// no coding table of their own and cannot use the coding table of any
// other type
final ArrayList<IType> typeList = new ArrayList<IType>();
getTypesWithNoCodingTable(timestamp, typeList, hasGlobalOverride);
if (!typeList.isEmpty()) {
for (int i = 0; i < realAttributes.size(); i++) {
final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Encode_Attribute) {
for (int j = typeList.size() - 1; j >= 0; j--) {
typeList.get(j).addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), Attribute_Modifier_type.MOD_NONE, true);
}
}
}
typeList.clear();
}
}
}
} else {
// ASN.1 types automatically have BER, PER, XER, OER and JSON encoding
switch(ownerType) {
case OT_TYPE_ASS:
case OT_RECORD_OF:
case OT_COMP_FIELD:
case OT_SELTYPE:
case OT_FIELDSETTING:
// FIXME implement once PER, JSON, OER or XER gets supported
break;
default:
break;
}
}
break;
default:
// the rest of the types can't have 'encode' attributes
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ReadingOutParBeforeWritten method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
this.problems = problems;
if (!(node instanceof FormalParameter)) {
return;
}
final FormalParameter fp = (FormalParameter) node;
this.toFind = fp;
final Assignment_type at = fp.getAssignmentType();
if (at != Assignment_type.A_PAR_VAL_OUT && at != Assignment_type.A_PAR_TEMP_OUT) {
return;
}
final Definition d = fp.getMyParameterList().getMyDefinition();
final NewFuncVisitor visitor = new NewFuncVisitor();
// call visitor on function in which the out parameter was found
d.accept(visitor);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ConsecutiveAssignments method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof StatementBlock)) {
return;
}
final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
int count = 0;
boolean limitReached = false;
Location smellLoc = null;
Assignment_Statement lastAs = null;
Assignment toMatch = null;
final StatementBlock sb = (StatementBlock) node;
// iterate statements in block
for (int i = 0; i < sb.getSize(); i++) {
final Statement s = sb.getStatementByIndex(i);
if (!(s instanceof Assignment_Statement)) {
if (limitReached) {
smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
problems.report(smellLoc, ERROR_MESSAGE);
limitReached = false;
}
count = 0;
toMatch = null;
continue;
}
final Assignment_Statement as = (Assignment_Statement) s;
final Reference ref = as.getReference();
final Assignment a = ref.getRefdAssignment(timestamp, false);
if (a == null) {
if (limitReached) {
smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
problems.report(smellLoc, ERROR_MESSAGE);
limitReached = false;
}
count = 0;
toMatch = null;
continue;
}
// consecutive assignments: consecutive Assignment_Statements have the same definition
if (toMatch == null) {
toMatch = a;
} else if (toMatch != a) {
if (limitReached) {
smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
problems.report(smellLoc, ERROR_MESSAGE);
limitReached = false;
}
count = 0;
toMatch = a;
}
if (count == 0) {
smellLoc = new Location(as.getLocation());
}
lastAs = as;
count++;
if (count >= minCountToMark) {
limitReached = true;
}
}
if (limitReached) {
smellLoc.setEndOffset(lastAs.getLocation().getEndOffset());
problems.report(smellLoc, ERROR_MESSAGE);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Type method checkThisValue.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisValue(final CompilationTimeStamp timestamp, final IValue value, final Assignment lhs, final ValueCheckingOptions valueCheckingOptions) {
if (getIsErroneous(timestamp)) {
return false;
}
boolean selfReference = false;
final IType tempType = getTypeRefdLast(timestamp);
if (tempType != this) {
selfReference = tempType.checkThisValue(timestamp, value, lhs, new ValueCheckingOptions(valueCheckingOptions.expected_value, valueCheckingOptions.incomplete_allowed, valueCheckingOptions.omit_allowed, false, valueCheckingOptions.implicit_omit, valueCheckingOptions.str_elem));
final Definition def = value.getDefiningAssignment();
if (def != null) {
final String referingModuleName = getMyScope().getModuleScope().getName();
if (!def.referingHere.contains(referingModuleName)) {
def.referingHere.add(referingModuleName);
}
}
}
if (valueCheckingOptions.sub_check && (subType != null)) {
subType.checkThisValue(timestamp, value);
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
Aggregations