use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class SuperfluousTemplate method visit.
@Override
public int visit(final IVisitableNode node) {
if (node instanceof TemplateInstance) {
template = (TemplateInstance) node;
final ITTCN3Template body = template.getTemplateBody();
if (body instanceof Any_Value_Template || body instanceof AnyOrOmit_Template) {
final Type type = template.getType();
if (type == null) {
// port.receive(?) or port.receive(*)
receivesAny = true;
} else if (receivableType != null && type.isIdentical(CompilationTimeStamp.getBaseTimestamp(), receivableType)) {
// e.g. port.receive(integer:?)
receivesAllOfType = true;
}
}
// We don't want to investigate nested templates
return V_SKIP;
}
return V_CONTINUE;
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class SignatureFormalParameterList method check.
public void check(final CompilationTimeStamp timestamp, final Signature_Type signature) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (parameters == null) {
return;
}
parameterMap.clear();
inParameters.clear();
outParameters.clear();
checkUniqueness(timestamp);
final boolean isNonblock = signature.isNonblocking();
for (final SignatureFormalParameter parameter : parameters) {
if (parameter.getDirection() == SignatureFormalParameter.ParamaterDirection.PARAM_IN) {
inParameters.add(parameter);
} else if (parameter.getDirection() == SignatureFormalParameter.ParamaterDirection.PARAM_OUT) {
if (isNonblock) {
parameter.getLocation().reportSemanticError("A non-blocking signature cannot have `out' parameter");
}
outParameters.add(parameter);
} else if (parameter.getDirection() == SignatureFormalParameter.ParamaterDirection.PARAM_INOUT) {
if (isNonblock) {
parameter.getLocation().reportSemanticError("A non-blocking signature cannot have `out' parameter");
}
inParameters.add(parameter);
outParameters.add(parameter);
}
final Type type = parameter.getType();
type.setParentType(signature);
type.check(timestamp);
type.checkEmbedded(timestamp, type.getLocation(), false, "the type of a signature parameter");
}
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class Signature_Type method checkThisNamedTemplateList.
// see void Type::chk_this_template_Signature(Template *t, namedbool incomplete_allowed) in Type_chk.cc
private boolean checkThisNamedTemplateList(final CompilationTimeStamp timestamp, final Named_Template_List template, final boolean isModified, final Assignment lhs) {
final Map<String, NamedTemplate> componentMap = new HashMap<String, NamedTemplate>();
boolean inSynch = true;
// TODO: alternatives:formalParList.getNofInParameters(); formalParList.getNofOutParameters()
final int nofTypeParameters = getNofParameters();
final int nofTemplateComponents = template.getNofTemplates();
int tI = 0;
boolean selfReference = false;
for (int vI = 0; vI < nofTemplateComponents; vI++) {
final NamedTemplate namedTemplate = template.getTemplateByIndex(vI);
final Identifier identifier = namedTemplate.getName();
final String name = identifier.getName();
if (hasParameterWithName(name)) {
if (componentMap.containsKey(name)) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEPARAMETERAGAIN, identifier.getDisplayName(), getTypename()));
componentMap.get(name).getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEPARAMETERFIRST, identifier.getDisplayName()));
inSynch = false;
} else {
componentMap.put(name, namedTemplate);
}
final SignatureFormalParameter parameter = formalParList.getParameterByName(name);
if (inSynch) {
SignatureFormalParameter parameter2 = null;
boolean found = false;
for (; tI < nofTypeParameters && !found; tI++) {
parameter2 = formalParList.getParameterByIndex(tI);
if (parameter == parameter2) {
found = true;
break;
}
}
if (!found) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDPARAMETER, identifier.getDisplayName()));
inSynch = false;
}
}
final Type parameterType = parameter.getType();
ITTCN3Template componentTemplate = namedTemplate.getTemplate();
// FIXME: will be overwritten?
componentTemplate.setMyGovernor(parameterType);
componentTemplate = parameterType.checkThisTemplateRef(timestamp, componentTemplate);
selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, parameterType, isModified, false, false, true, false, lhs);
} else {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTPARAMETER, identifier.getDisplayName(), getTypename()));
inSynch = false;
}
}
if (isModified) {
SignatureFormalParameter firstUndefIn = null;
SignatureFormalParameter firstUndefOut = null;
for (int i = 0; i < nofTypeParameters; i++) {
final SignatureFormalParameter parameter = formalParList.getParameterByIndex(i);
final Identifier identifier = parameter.getIdentifier();
if (!componentMap.containsKey(identifier.getName()) || Template_type.TEMPLATE_NOTUSED.equals(componentMap.get(identifier.getName()).getTemplate().getTemplatetype())) {
switch(parameter.getDirection()) {
case PARAM_IN:
if (firstUndefIn == null) {
firstUndefIn = parameter;
}
break;
case PARAM_OUT:
if (firstUndefOut == null) {
firstUndefOut = parameter;
}
break;
default:
template.getLocation().reportSemanticError(MessageFormat.format(INCOMPLETE1, identifier.getDisplayName()));
break;
}
}
}
if (firstUndefIn != null && firstUndefOut != null) {
template.getLocation().reportSemanticError(MessageFormat.format(INCOMPLETE2, firstUndefIn.getIdentifier().getDisplayName(), firstUndefOut.getIdentifier().getDisplayName()));
}
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Choice_Type method checkThisTemplate.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisTemplate(final CompilationTimeStamp timestamp, final ITTCN3Template template, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
registerUsage(template);
template.setMyGovernor(this);
if (getIsErroneous(timestamp)) {
return false;
}
boolean selfReference = false;
if (Template_type.NAMED_TEMPLATE_LIST.equals(template.getTemplatetype())) {
final Named_Template_List namedTemplateList = (Named_Template_List) template;
final int nofTemplates = namedTemplateList.getNofTemplates();
if (nofTemplates != 1) {
template.getLocation().reportSemanticError(ONEFIELDEXPECTED);
}
for (int i = 0; i < nofTemplates; i++) {
final NamedTemplate namedTemplate = namedTemplateList.getTemplateByIndex(i);
final Identifier name = namedTemplate.getName();
final CompField field = compFieldMap.getCompWithName(name);
if (field == null) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(REFERENCETONONEXISTENTFIELD, name.getDisplayName(), getFullName()));
} else {
final Type fieldType = field.getType();
ITTCN3Template namedTemplateTemplate = namedTemplate.getTemplate();
namedTemplateTemplate.setMyGovernor(fieldType);
namedTemplateTemplate = fieldType.checkThisTemplateRef(timestamp, namedTemplateTemplate);
final Completeness_type completeness = namedTemplateList.getCompletenessConditionChoice(timestamp, isModified, name);
selfReference |= namedTemplateTemplate.checkThisTemplateGeneric(timestamp, fieldType, Completeness_type.MAY_INCOMPLETE.equals(completeness), false, false, true, implicitOmit, lhs);
}
}
} else {
template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), getTypename()));
}
if (template.getLengthRestriction() != null) {
template.getLocation().reportSemanticError(MessageFormat.format(LENGTHRESTRICTIONNOTALLOWED, getTypename()));
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Choice_Type method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final String genName = getGenNameOwn();
final String displayName = getFullName();
generateCodeTypedescriptor(aData, source);
final List<FieldInfo> fieldInfos = new ArrayList<FieldInfo>();
boolean hasOptional = false;
for (final CompField compField : compFieldMap.fields) {
final IType cfType = compField.getType();
final FieldInfo fi = new FieldInfo(cfType.getGenNameValue(aData, source, getMyScope()), cfType.getGenNameTemplate(aData, source, getMyScope()), compField.getIdentifier().getName(), compField.getIdentifier().getDisplayName(), cfType.getGenNameTypeDescriptor(aData, source, myScope));
hasOptional |= compField.isOptional();
fieldInfos.add(fi);
}
for (final CompField compField : compFieldMap.fields) {
final StringBuilder tempSource = aData.getCodeForType(compField.getType().getGenNameOwn());
compField.getType().generateCode(aData, tempSource);
}
final boolean hasRaw = getGenerateCoderFunctions(MessageEncoding_type.RAW);
RawASTStruct raw = null;
if (hasRaw) {
RawAST dummy_raw;
if (rawAttribute == null) {
dummy_raw = new RawAST(getDefaultRawFieldLength());
} else {
dummy_raw = rawAttribute;
}
raw = new RawASTStruct(dummy_raw);
// building taglist
final int taglistSize = dummy_raw.taglist == null ? 0 : dummy_raw.taglist.size();
for (int c = 0; c < taglistSize; c++) {
final rawAST_single_tag singleTag = dummy_raw.taglist.get(c);
final rawAST_coding_taglist codingSingleTag = raw.taglist.list.get(c);
if (singleTag.keyList != null) {
codingSingleTag.fields = new ArrayList<RawASTStruct.rawAST_coding_field_list>(singleTag.keyList.size());
}
codingSingleTag.fieldname = singleTag.fieldName.getName();
codingSingleTag.varName = FieldSubReference.getJavaGetterName(codingSingleTag.fieldname);
final Identifier idf = singleTag.fieldName;
codingSingleTag.fieldnum = getComponentIndexByName(idf);
final int keyListSize = singleTag.keyList == null ? 0 : singleTag.keyList.size();
for (int a = 0; a < keyListSize; a++) {
final rawAST_tag_field_value key = singleTag.keyList.get(a);
final RawASTStruct.rawAST_coding_field_list codingKey = new RawASTStruct.rawAST_coding_field_list();
codingSingleTag.fields.add(codingKey);
codingKey.fields = new ArrayList<RawASTStruct.rawAST_coding_fields>(key.keyField.names.size());
// codingKey.value = key.value;
final ExpressionStruct expression = new ExpressionStruct();
key.v_value.generateCodeExpression(aData, expression, true);
codingKey.expression = expression;
codingKey.isOmitValue = key.v_value.getValuetype() == Value_type.OMIT_VALUE;
codingKey.start_pos = 0;
final CompField cf = getComponentByIndex(codingSingleTag.fieldnum);
IType t = cf.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final RawASTStruct.rawAST_coding_fields tempField = new rawAST_coding_fields();
tempField.nthfield = codingSingleTag.fieldnum;
tempField.nthfieldname = singleTag.fieldName.getName();
tempField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
tempField.type = t.getGenNameValue(aData, source, myScope);
tempField.typedesc = t.getGenNameTypeDescriptor(aData, source, myScope);
codingKey.fields.add(tempField);
for (int b = 0; b < key.keyField.names.size(); b++) {
final RawASTStruct.rawAST_coding_fields newField = new rawAST_coding_fields();
codingKey.fields.add(newField);
final Identifier idf2 = key.keyField.names.get(b);
int comp_index = 0;
CompField cf2;
switch(t.getTypetype()) {
case TYPE_TTCN3_CHOICE:
comp_index = ((TTCN3_Choice_Type) t).getComponentIndexByName(idf2);
cf2 = ((TTCN3_Choice_Type) t).getComponentByIndex(comp_index);
newField.nthfield = comp_index;
newField.nthfieldname = idf2.getName();
newField.fieldtype = rawAST_coding_field_type.UNION_FIELD;
break;
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
comp_index = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentIndexByName(idf2);
cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t).getComponentByIndex(comp_index);
newField.nthfield = comp_index;
newField.nthfieldname = idf2.getName();
if (cf2.isOptional()) {
newField.fieldtype = rawAST_coding_field_type.OPTIONAL_FIELD;
} else {
newField.fieldtype = rawAST_coding_field_type.MANDATORY_FIELD;
}
break;
default:
// internal error
return;
}
final IType field_type = cf2.getType();
newField.type = field_type.getGenNameValue(aData, source, myScope);
newField.typedesc = field_type.getGenNameTypeDescriptor(aData, source, myScope);
if (field_type.getTypetype() == Type_type.TYPE_TTCN3_SEQUENCE && ((TTCN3_Sequence_Type) field_type).rawAttribute != null && (((TTCN3_Sequence_Type) field_type).rawAttribute.pointerto == null || ((TTCN3_Sequence_Type) field_type).rawAttribute.lengthto != null)) {
codingKey.start_pos = -1;
}
if (t.getTypetype() == Type_type.TYPE_TTCN3_SEQUENCE) {
IType t2;
for (int i = 0; i < comp_index && codingKey.start_pos >= 0; i++) {
t2 = ((TTCN3_Sequence_Type) t).getComponentByIndex(i).getType();
if (t2.getRawLength() >= 0) {
if (((Type) t2).rawAttribute != null) {
codingKey.start_pos += ((Type) t2).rawAttribute.padding;
}
codingKey.start_pos += ((Type) t2).getRawLength();
} else {
codingKey.start_pos = -1;
}
}
}
t = field_type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
}
}
}
}
UnionGenerator.generateValueClass(aData, source, genName, displayName, fieldInfos, hasOptional, hasRaw, raw);
UnionGenerator.generateTemplateClass(aData, source, genName, displayName, fieldInfos, hasOptional);
if (hasDoneAttribute()) {
generateCodeDone(aData, source);
}
if (subType != null) {
subType.generateCode(aData, source);
}
generateCodeForCodingHandlers(aData, source);
}
Aggregations