use of org.eclipse.titan.designer.AST.TTCN3.types.Array_Type in project titan.EclipsePlug-ins by eclipse.
the class Def_Template method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final boolean cleanUp) {
final String genName = getGenName();
final StringBuilder sb = aData.getSrc();
final StringBuilder source = new StringBuilder();
if (!isLocal()) {
if (VisibilityModifier.Private.equals(getVisibilityModifier())) {
source.append("private");
} else {
source.append("public");
}
source.append(" static ");
}
final String typeName = type.getGenNameTemplate(aData, source, getMyScope());
if (formalParList == null) {
if (type.getTypetype().equals(Type_type.TYPE_ARRAY)) {
final Array_Type arrayType = (Array_Type) type;
final StringBuilder sbforTemp = aData.getCodeForType(arrayType.getGenNameOwn());
arrayType.generateCodeValue(aData, sbforTemp);
arrayType.generateCodeTemplate(aData, sbforTemp);
}
source.append(MessageFormat.format("{0} {1} = new {0}();\n", typeName, genName));
if (baseTemplate != null) {
// modified template
if (baseTemplate.myScope.getModuleScope() == myScope.getModuleScope()) {
// if the base template is in the same module its body has to be
// initialized first
getLocation().update_location_object(aData, aData.getPostInit());
baseTemplate.body.generateCodeInit(aData, aData.getPostInit(), body.get_lhs_name());
}
}
if (body != null) {
getLocation().update_location_object(aData, aData.getPostInit());
body.generateCodeInit(aData, aData.getPostInit(), body.get_lhs_name());
if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
TemplateRestriction.generateRestrictionCheckCode(aData, source, location, genName, templateRestriction);
}
}
} else {
final StringBuilder formalParameters = formalParList.generateCode(aData);
source.append(MessageFormat.format("{0} {1}({2}) '{'\n", typeName, genName, formalParameters));
getLocation().create_location_object(aData, source, getIdentifier().getDisplayName());
if (baseTemplate == null) {
if (type.getTypetype().equals(Type_type.TYPE_ARRAY)) {
final Array_Type arrayType = (Array_Type) type;
final StringBuilder sbforTemp = aData.getCodeForType(arrayType.getGenNameOwn());
arrayType.generateCodeValue(aData, sbforTemp);
arrayType.generateCodeTemplate(aData, sbforTemp);
}
source.append(MessageFormat.format("{0} ret_val = new {0}();\n", typeName));
} else {
// modified template
source.append(MessageFormat.format("{0} ret_val = new {0}({1}", typeName, baseTemplate.getGenNameFromScope(aData, source, myScope, "")));
if (baseTemplate.formalParList != null) {
// the base is also parameterized
source.append('(');
for (int i = 0; i < baseTemplate.formalParList.getNofParameters(); i++) {
if (i > 0) {
source.append(", ");
}
source.append(formalParList.getParameterByIndex(i).getIdentifier().getName());
}
source.append(')');
}
source.append(");\n");
}
if (body != null) {
body.generateCodeInit(aData, source, "ret_val");
if (templateRestriction != Restriction_type.TR_NONE && generateRestrictionCheck) {
TemplateRestriction.generateRestrictionCheckCode(aData, source, location, "ret_val", templateRestriction);
}
}
getLocation().release_location_object(aData, source);
source.append("return ret_val;\n");
source.append("}\n\n");
}
sb.append(source);
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Array_Type in project titan.EclipsePlug-ins by eclipse.
the class Def_Const method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final boolean cleanUp) {
final String genName = getGenName();
if (type == null || value == null) {
return;
}
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
final StringBuilder sb = aData.getSrc();
final StringBuilder source = new StringBuilder();
if (!isLocal()) {
if (VisibilityModifier.Private.equals(getVisibilityModifier())) {
source.append("private");
} else {
source.append("public");
}
}
final String typeGeneratedName = type.getGenNameValue(aData, source, getMyScope());
if (type.getTypetype().equals(Type_type.TYPE_ARRAY)) {
final Array_Type arrayType = (Array_Type) type;
final StringBuilder temp_sb = aData.getCodeForType(arrayType.getGenNameOwn());
arrayType.generateCodeValue(aData, temp_sb);
}
source.append(MessageFormat.format(" static final {0} {1} = new {0}();\n", typeGeneratedName, genName));
getLocation().update_location_object(aData, aData.getPreInit());
last.generateCodeInit(aData, aData.getPreInit(), genName);
sb.append(source);
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Array_Type in project titan.EclipsePlug-ins by eclipse.
the class Def_Const method generateCodeString.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeString(final JavaGenData aData, final StringBuilder source) {
final String genName = getGenName();
if (type == null || value == null) {
return;
}
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
final String typeGeneratedName = type.getGenNameValue(aData, source, getMyScope());
if (type.getTypetype().equals(Type_type.TYPE_ARRAY)) {
final Array_Type arrayType = (Array_Type) type;
final StringBuilder sb = aData.getCodeForType(arrayType.getGenNameOwn());
arrayType.generateCodeValue(aData, sb);
}
if (last.canGenerateSingleExpression()) {
if (last.returnsNative() || type.getTypetypeTtcn3() != last.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE)) {
source.append(MessageFormat.format("{0} {1} = new {0}({2});\n", typeGeneratedName, genName, last.generateSingleExpression(aData)));
} else {
source.append(MessageFormat.format("{0} {1} = {2};\n", typeGeneratedName, genName, last.generateSingleExpression(aData)));
}
} else {
source.append(MessageFormat.format("{0} {1} = new {0}();\n", typeGeneratedName, genName));
last.generateCodeInit(aData, source, genName);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Array_Type in project titan.EclipsePlug-ins by eclipse.
the class Type method checkThisVariant.
@Override
public /**
* {@inheritDoc}
*/
void checkThisVariant(final CompilationTimeStamp timestamp, final SingleWithAttribute singleWithAttribute, final boolean global) {
final IType type = getTypeWithCodingTable(timestamp, false);
if (type == null) {
// FIXME as only RAW is supported for now, we can not report this error
// if (!global) {
// singleWithAttribute.getLocation().reportSemanticError(MessageFormat.format("No encoding rules defined for type `{0}''", getTypename()));
// }
} else {
final List<String> codingStrings = singleWithAttribute.getAttributeSpecification().getEncodings();
// gather the built-in codecs referred to by the variant's encoding strings
final ArrayList<MessageEncoding_type> codings = new ArrayList<IType.MessageEncoding_type>();
boolean erroneous = false;
if (codingStrings == null) {
if (type.getCodingTable().size() > 1) {
if (!global) {
singleWithAttribute.getLocation().reportSemanticError(MessageFormat.format("The encoding reference is mandatory for variant attributes of type `{0}''", getTypename()));
}
erroneous = true;
} else if (type.getCodingTable().get(0).builtIn) {
codings.add(type.getCodingTable().get(0).builtInCoding);
} else {
// PER or custom encoding
final MessageEncoding_type coding = "PER".equals(type.getCodingTable().get(0).customCoding.name) ? MessageEncoding_type.PER : MessageEncoding_type.CUSTOM;
singleWithAttribute.getLocation().reportSemanticWarning(MessageFormat.format("Variant attributes related to `{0}'' encoding are ignored", coding.getEncodingName()));
}
} else {
for (int i = 0; i < codingStrings.size(); i++) {
final String encodingString = codingStrings.get(i);
final MessageEncoding_type coding = getEncodingType(encodingString);
if (!hasEncoding(timestamp, coding, encodingString)) {
erroneous = true;
// FIXME RAW restriction only exists because that is the only supported encoding right now
if (!global && coding == MessageEncoding_type.RAW) {
if (coding == MessageEncoding_type.CUSTOM) {
singleWithAttribute.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not support {1} encoding", getTypename(), coding.getEncodingName()));
} else {
singleWithAttribute.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not support custom encoding `{1}''", getTypename(), encodingString));
}
}
} else if (coding != MessageEncoding_type.PER && coding != MessageEncoding_type.CUSTOM) {
codings.add(coding);
} else {
// PER or custom encoding
singleWithAttribute.getLocation().reportSemanticWarning(MessageFormat.format("Variant attributes related to {0} encoding are ignored", coding.getEncodingName()));
}
}
}
// FIXME implement checks
// TODO only raw data is extracted
final VariantAttributeAnalyzer analyzer = new VariantAttributeAnalyzer();
boolean newRaw = false;
final AtomicBoolean rawFoud = new AtomicBoolean(false);
if (rawAttribute == null) {
IType t_refd = this;
while (t_refd.getRawAttribute() == null && t_refd instanceof Referenced_Type) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
t_refd = ((Referenced_Type) t_refd).getTypeRefd(timestamp, referenceChain);
referenceChain.release();
}
rawAttribute = new RawAST(t_refd.getRawAttribute(), getDefaultRawFieldLength());
newRaw = true;
}
analyzer.parse(rawAttribute, singleWithAttribute.getAttributeSpecification(), getLengthMultiplier(), rawFoud);
if (!rawFoud.get() && newRaw) {
rawAttribute = null;
}
}
if (global) {
// send global variant attributes to field/element types
switch(getTypetype()) {
case TYPE_TTCN3_CHOICE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
for (int i = 0; i < ((TTCN3_Set_Seq_Choice_BaseType) this).getNofComponents(); i++) {
((TTCN3_Set_Seq_Choice_BaseType) this).getComponentByIndex(i).getType().checkThisVariant(timestamp, singleWithAttribute, global);
}
break;
case TYPE_ASN1_CHOICE:
case TYPE_ASN1_SEQUENCE:
case TYPE_ASN1_SET:
for (int i = 0; i < ((ASN1_Set_Seq_Choice_BaseType) this).getNofComponents(timestamp); i++) {
((ASN1_Set_Seq_Choice_BaseType) this).getComponentByIndex(i).getType().checkThisVariant(timestamp, singleWithAttribute, global);
}
break;
case TYPE_ANYTYPE:
for (int i = 0; i < ((Anytype_Type) this).getNofComponents(); i++) {
((Anytype_Type) this).getComponentByIndex(i).getType().checkThisVariant(timestamp, singleWithAttribute, global);
}
break;
case TYPE_OPENTYPE:
for (int i = 0; i < ((Open_Type) this).getNofComponents(); i++) {
((Open_Type) this).getComponentByIndex(i).getType().checkThisVariant(timestamp, singleWithAttribute, global);
}
break;
case TYPE_ARRAY:
((Array_Type) this).getElementType().checkThisVariant(timestamp, singleWithAttribute, global);
break;
case TYPE_SEQUENCE_OF:
((SequenceOf_Type) this).getOfType().checkThisVariant(timestamp, singleWithAttribute, global);
break;
case TYPE_SET_OF:
((SetOf_Type) this).getOfType().checkThisVariant(timestamp, singleWithAttribute, global);
break;
default:
break;
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Array_Type in project titan.EclipsePlug-ins by eclipse.
the class AbstractOfType method isSubtypeCompatible.
/**
* Checks that the provided type is sub-type compatible with the actual
* set of type.
* <p>
* In case of sequence/set/array this means that the number of their
* fields fulfills the length restriction of the set of type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle
* @param other
* the type to check against.
*
* @return true if they are sub-type compatible, false otherwise.
*/
public boolean isSubtypeCompatible(final CompilationTimeStamp timestamp, final IType other) {
if (subType == null || other == null) {
return true;
}
long nofComponents;
switch(other.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
nofComponents = ((ASN1_Sequence_Type) other).getNofComponents(timestamp);
break;
case TYPE_TTCN3_SEQUENCE:
nofComponents = ((TTCN3_Sequence_Type) other).getNofComponents();
break;
case TYPE_ASN1_SET:
nofComponents = ((ASN1_Set_Type) other).getNofComponents(timestamp);
break;
case TYPE_TTCN3_SET:
nofComponents = ((TTCN3_Set_Type) other).getNofComponents();
break;
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
if (other.getSubtype() == null) {
return true;
}
return subType.isCompatible(timestamp, other.getSubtype());
case TYPE_ARRAY:
{
final ArrayDimension dimension = ((Array_Type) other).getDimension();
if (dimension.getIsErroneous(timestamp)) {
return false;
}
nofComponents = dimension.getSize();
break;
}
default:
return false;
}
final List<ParsedSubType> tempRestrictions = new ArrayList<ParsedSubType>(1);
final Integer_Value length = new Integer_Value(nofComponents);
tempRestrictions.add(new Length_ParsedSubType(new SingleLenghtRestriction(length)));
final SubType tempSubtype = new SubType(getSubtypeType(), this, tempRestrictions, null);
tempSubtype.check(timestamp);
return subType.isCompatible(timestamp, tempSubtype);
}
Aggregations