use of org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type in project titan.EclipsePlug-ins by eclipse.
the class Type method fieldIsOptional.
@Override
public /**
* {@inheritDoc}
*/
boolean fieldIsOptional(final List<ISubReference> subReferences) {
// TODO there must be a better implementation
if (subReferences == null) {
return false;
}
if (subReferences.isEmpty()) {
return false;
}
final ISubReference lastSubReference = subReferences.get(subReferences.size() - 1);
if (!(lastSubReference instanceof FieldSubReference)) {
return false;
}
IType type = this;
CompField compField = null;
for (int i = 1; i < subReferences.size(); i++) {
if (type != null) {
type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
}
final ISubReference subreference = subReferences.get(i);
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
final Identifier id = ((FieldSubReference) subreference).getId();
if (type != null) {
switch(type.getTypetype()) {
case TYPE_TTCN3_CHOICE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
compField = ((TTCN3_Set_Seq_Choice_BaseType) type).getComponentByName(id.getName());
break;
case TYPE_ANYTYPE:
compField = ((Anytype_Type) type).getComponentByName(id.getName());
break;
case TYPE_OPENTYPE:
compField = ((Open_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_SEQUENCE:
((ASN1_Sequence_Type) type).parseBlockSequence();
compField = ((ASN1_Sequence_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_SET:
((ASN1_Set_Type) type).parseBlockSet();
compField = ((ASN1_Set_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_CHOICE:
((ASN1_Choice_Type) type).parseBlockChoice();
compField = ((ASN1_Choice_Type) type).getComponentByName(id);
break;
default:
// TODO fatal error:
return false;
}
if (compField == null) {
// TODO fatal error
return false;
}
type = compField.getType();
}
} else if (Subreference_type.arraySubReference.equals(subreference.getReferenceType())) {
final Value value = ((ArraySubReference) subreference).getValue();
// TODO actually should get the last governor
final IType pt = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
if (type != null) {
switch(type.getTypetype()) {
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
type = ((AbstractOfType) type).getOfType();
break;
case TYPE_ARRAY:
type = ((Array_Type) type).getElementType();
break;
default:
type = null;
return false;
}
}
}
}
if (compField != null && compField.isOptional()) {
return true;
}
return false;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type in project titan.EclipsePlug-ins by eclipse.
the class SelectUnionCase_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (expression == null) {
return;
}
IValue temp = expression.setLoweridToReference(timestamp);
final IType governor = temp.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (governor == null) {
if (!temp.getIsErroneous(timestamp)) {
expression.getLocation().reportSemanticError(UNDETERMINABLETYPE);
}
return;
}
temp = governor.checkThisValueRef(timestamp, expression);
governor.checkThisValue(timestamp, temp, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
// referenced type
final IType refd = governor.getTypeRefdLast(timestamp);
if (refd instanceof TTCN3_Choice_Type) {
// referenced union type to check
final TTCN3_Choice_Type unionType = (TTCN3_Choice_Type) refd;
checkUnionType(timestamp, unionType);
} else if (refd instanceof Anytype_Type) {
// referenced anytype type to check
final Anytype_Type anytypeType = (Anytype_Type) refd;
checkAnytypeType(timestamp, anytypeType);
} else {
expression.getLocation().reportSemanticError(TYPE_MUST_BE_UNION_OR_ANYTYPE);
// special operations to check the body of the cases even if the select expression is erroneous
for (int i = 0; i < selectUnionCases.getSize(); i++) {
selectUnionCases.getSelectUnionCase(i).checkStatementBlock(timestamp);
}
return;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type in project titan.EclipsePlug-ins by eclipse.
the class Reference method generateCode.
// originally fieldOrArrayRefs
private void generateCode(final JavaGenData aData, final ExpressionStruct expression, final boolean isTemplate, final boolean isConst, IType type) {
for (int i = 1; i < subReferences.size(); i++) {
if (type != null) {
type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
}
final ISubReference subreference = subReferences.get(i);
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
final Identifier id = ((FieldSubReference) subreference).getId();
expression.expression.append(".");
if (isConst) {
expression.expression.append("constGet");
} else {
expression.expression.append("get");
}
expression.expression.append(FieldSubReference.getJavaGetterName(id.getName()));
expression.expression.append("()");
if (type != null) {
CompField compField = null;
switch(type.getTypetype()) {
case TYPE_TTCN3_CHOICE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
compField = ((TTCN3_Set_Seq_Choice_BaseType) type).getComponentByName(id.getName());
break;
case TYPE_ANYTYPE:
compField = ((Anytype_Type) type).getComponentByName(id.getName());
break;
case TYPE_OPENTYPE:
compField = ((Open_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_SEQUENCE:
((ASN1_Sequence_Type) type).parseBlockSequence();
compField = ((ASN1_Sequence_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_SET:
((ASN1_Set_Type) type).parseBlockSet();
compField = ((ASN1_Set_Type) type).getComponentByName(id);
break;
case TYPE_ASN1_CHOICE:
((ASN1_Choice_Type) type).parseBlockChoice();
compField = ((ASN1_Choice_Type) type).getComponentByName(id);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for reference `" + getFullName() + "''");
return;
}
if (i < subReferences.size() - 1 && compField != null && compField.isOptional() && !isTemplate) {
if (isConst) {
expression.expression.append(".constGet()");
} else {
expression.expression.append(".get()");
}
type = compField.getType();
}
}
} else if (Subreference_type.arraySubReference.equals(subreference.getReferenceType())) {
final Value value = ((ArraySubReference) subreference).getValue();
// TODO actually should get the last governor
final IType pt = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
// generate "getAt" functions instead of operator[]
if (isConst) {
expression.expression.append(".constGetAt(");
} else {
expression.expression.append(".getAt(");
}
value.generateCodeExpression(aData, expression, false);
expression.expression.append(")");
if (type != null) {
switch(type.getTypetype()) {
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
type = ((AbstractOfType) type).getOfType();
break;
case TYPE_ARRAY:
type = ((Array_Type) type).getElementType();
break;
default:
type = null;
}
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Anytype_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.Anytype_Type in project titan.EclipsePlug-ins by eclipse.
the class IsChoosenExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeoperandsChecked != null && !lastTimeoperandsChecked.isLess(timestamp)) {
return;
}
lastTimeoperandsChecked = timestamp;
value = null;
identifier = null;
if (reference == null || reference.getSubreferences().size() < 2) {
setIsErroneous(true);
return;
}
final Reference tempReference = reference.newInstance();
tempReference.setFullNameParent(this);
tempReference.setMyScope(getMyScope());
final ISubReference subreference = tempReference.removeLastSubReference();
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
identifier = ((FieldSubReference) subreference).getId();
} else {
setIsErroneous(true);
return;
}
final Assignment assignment = tempReference.getRefdAssignment(timestamp, true);
if (assignment == null) {
setIsErroneous(true);
return;
}
IType governor;
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
{
value = new Referenced_Value(tempReference);
value.setLocation(tempReference.getLocation());
value.setMyScope(getMyScope());
final BridgingNamedNode tempNamedNode = new BridgingNamedNode(this, OPERAND);
value.setFullNameParent(tempNamedNode);
governor = value.getExpressionGovernor(timestamp, expectedValue);
if (governor == null) {
setIsErroneous(true);
} else {
value.setMyGovernor(governor);
final IValue tempValue2 = governor.checkThisValueRef(timestamp, value);
if (tempValue2.getIsErroneous(timestamp)) {
setIsErroneous(true);
}
}
break;
}
case A_TEMPLATE:
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
{
template = new Referenced_Template(tempReference);
template.setLocation(tempReference.getLocation());
template.setMyScope(getMyScope());
final BridgingNamedNode tempNamedNode = new BridgingNamedNode(this, OPERAND);
template.setFullNameParent(tempNamedNode);
if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) || Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
governor = template.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
} else {
governor = template.getExpressionGovernor(timestamp, expectedValue);
}
if (governor == null) {
setIsErroneous(true);
} else {
template.setMyGovernor(governor);
final TTCN3Template last = template.getTemplateReferencedLast(timestamp, referenceChain);
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
}
}
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) && !Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
if (Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue)) {
template.getLocation().reportSemanticError(MessageFormat.format(CONSTANTREFERENCEEXPECTED, assignment.getDescription()));
} else {
template.getLocation().reportSemanticError(MessageFormat.format(STATICREFERENCEEXPECTED, assignment.getDescription()));
}
setIsErroneous(true);
}
break;
}
default:
tempReference.getLocation().reportSemanticError(MessageFormat.format(VALUETEMPLATEEXPECTED, assignment.getDescription()));
setIsErroneous(true);
return;
}
if (governor != null) {
governor = governor.getTypeRefdLast(timestamp);
if (!governor.getIsErroneous(timestamp)) {
CompField field = null;
switch(governor.getTypetype()) {
case TYPE_ASN1_CHOICE:
if (((ASN1_Choice_Type) governor).hasComponentWithName(identifier)) {
field = ((ASN1_Choice_Type) governor).getComponentByName(identifier);
}
break;
case TYPE_TTCN3_CHOICE:
if (((TTCN3_Choice_Type) governor).hasComponentWithName(identifier.getName())) {
field = ((TTCN3_Choice_Type) governor).getComponentByName(identifier.getName());
}
break;
case TYPE_OPENTYPE:
if (((Open_Type) governor).hasComponentWithName(identifier)) {
field = ((Open_Type) governor).getComponentByName(identifier);
}
break;
case TYPE_ANYTYPE:
if (((Anytype_Type) governor).hasComponentWithName(identifier.getName())) {
field = ((Anytype_Type) governor).getComponentByName(identifier.getName());
}
break;
default:
location.reportSemanticError(MessageFormat.format(OPERANDERROR, governor.getTypename()));
setIsErroneous(true);
return;
}
if (null == field) {
location.reportSemanticError(MessageFormat.format(MISSINGFIELD, governor.getTypename(), identifier.getDisplayName()));
setIsErroneous(true);
}
}
}
}
Aggregations