use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.
the class Set_Value method generateCodeInit.
@Override
public /**
* {@inheritDoc}
* generate_code_init_se in the compiler
*/
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
int nofComps = 0;
switch(type.getTypetype()) {
case TYPE_TTCN3_SET:
nofComps = ((TTCN3_Set_Type) type).getNofComponents();
break;
case TYPE_ASN1_SET:
nofComps = ((ASN1_Set_Type) type).getNofComponents(CompilationTimeStamp.getBaseTimestamp());
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
}
if (nofComps == 0) {
aData.addBuiltinTypeImport("TitanNull_Type");
source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
return source;
}
CompField compField = null;
for (int i = 0; i < nofComps; i++) {
switch(type.getTypetype()) {
case TYPE_TTCN3_SET:
compField = ((TTCN3_Set_Type) type).getComponentByIndex(i);
break;
case TYPE_ASN1_SET:
compField = ((ASN1_Set_Type) type).getComponentByIndex(i);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
}
final Identifier fieldName = compField.getIdentifier();
IValue fieldValue;
if (hasComponentWithName(fieldName)) {
fieldValue = getComponentByName(fieldName).getValue();
if (Value_type.NOTUSED_VALUE.equals(fieldValue.getValuetype())) {
continue;
} else if (Value_type.OMIT_VALUE.equals(fieldValue.getValuetype())) {
fieldValue = null;
}
} else // TODO add support for asn default values when needed
{
continue;
}
final String javaGetterName = FieldSubReference.getJavaGetterName(fieldName.getName());
if (fieldValue != null) {
// TODO handle the case when temporary reference is needed
final StringBuilder embeddedName = new StringBuilder();
embeddedName.append(name);
embeddedName.append(".get");
embeddedName.append(javaGetterName);
embeddedName.append("()");
if (compField.isOptional()) /*&& fieldValue.isCompound() */
{
embeddedName.append(".get()");
}
// TODO add extra handling for optional fields
fieldValue.generateCodeInit(aData, source, embeddedName.toString());
} else {
aData.addBuiltinTypeImport("Base_Template.template_sel");
source.append(MessageFormat.format("{0}.get{1}().assign(template_sel.OMIT_VALUE);\n", name, javaGetterName));
}
}
return source;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.
the class UStringValueConstraint method toString.
@Override
public /**
* {@inheritDoc}
*/
void toString(final StringBuilder sb) {
sb.append('(');
boolean needComma = false;
for (UniversalCharstring str : values) {
if (needComma) {
sb.append(", ");
}
sb.append('\"').append(str.getStringRepresentation()).append('\"');
needComma = true;
}
sb.append(')');
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Enumerated_Type method check.
@Override
public final /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (null != myScope) {
final Module module = myScope.getModuleScope();
if (null != module) {
if (module.getSkippedFromSemanticChecking()) {
return;
}
}
}
isErroneous = false;
if (null == enumerations) {
parseBlockEnumeration();
}
if (isErroneous || null == enumerations) {
return;
}
/* check duplications and set missing values */
firstUnused = Integer.valueOf(0);
nameMap = new HashMap<String, EnumItem>();
final Map<Integer, EnumItem> valueMap = new HashMap<Integer, EnumItem>();
if (null != enumerations.enumItems1) {
final List<EnumItem> enumItems = enumerations.enumItems1.getItems();
for (EnumItem item : enumItems) {
checkEnumItem(timestamp, item, false, valueMap);
}
// set the default values
while (valueMap.containsKey(firstUnused)) {
firstUnused++;
}
for (EnumItem item : enumItems) {
if (null == item.getValue() || !item.isOriginal()) {
final Integer_Value tempValue = new Integer_Value(firstUnused.longValue());
tempValue.setLocation(item.getLocation());
item.setValue(tempValue);
valueMap.put(firstUnused, item);
while (valueMap.containsKey(firstUnused)) {
firstUnused++;
}
}
}
}
if (null != enumerations.enumItems2) {
final List<EnumItem> enumItems = enumerations.enumItems2.getItems();
for (EnumItem item : enumItems) {
checkEnumItem(timestamp, item, true, valueMap);
}
}
if (null != constraints) {
constraints.check(timestamp);
}
if (myScope != null) {
checkEncode(timestamp);
checkVariants(timestamp);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.
the class All_From_Template method getNofValues.
/**
* Gets the number of values If the value is type of SEQUENCEOF_VALUE or
* type of SETOF_VALUE then returns their size otherwise returns 1
*/
private int getNofValues(final IValue value, final CompilationTimeStamp timestamp) {
int result = 0;
if (value == null) {
return result;
}
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue lastValue = value.getValueRefdLast(timestamp, chain);
chain.release();
if (lastValue.getIsErroneous(timestamp)) {
return result;
}
if (Value_type.SEQUENCEOF_VALUE.equals(lastValue.getValuetype())) {
final SequenceOf_Value lvalue = (SequenceOf_Value) lastValue;
result = lvalue.getNofComponents();
return result;
} else if (Value_type.SETOF_VALUE.equals(lastValue.getValuetype())) {
final SetOf_Value svalue = (SetOf_Value) lastValue;
result = svalue.getNofComponents();
return result;
} else {
// this value is calculated as 1 in an all from
return 1;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.
the class All_From_Template method getNofTemplatesNotAnyornone.
/**
* Calculates the number of list members which are not the any or none
* symbol.
*
* @return the number calculated.
*/
public int getNofTemplatesNotAnyornone(final CompilationTimeStamp timestamp) {
int result = 0;
if (allFrom == null) {
ErrorReporter.INTERNAL_ERROR();
return result;
}
if (!Template_type.SPECIFIC_VALUE.equals(allFrom.getTemplatetype())) {
allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
allFrom.setIsErroneous(true);
return result;
}
if (!((SpecificValue_Template) allFrom).isReference()) {
allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
allFrom.setIsErroneous(true);
return result;
}
// isReference branch:
final Reference reference = ((SpecificValue_Template) allFrom).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
allFrom.getLocation().reportSemanticError("Assignment not found");
allFrom.setIsErroneous(true);
return result;
}
ITTCN3Template body = null;
switch(assignment.getAssignmentType()) {
case A_TEMPLATE:
body = ((Def_Template) assignment).getTemplate(timestamp);
break;
case A_VAR_TEMPLATE:
body = ((Def_Var_Template) assignment).getInitialValue();
break;
case A_CONST:
final IValue value = ((Def_Const) assignment).getValue();
return getNofValues(value, timestamp);
case A_MODULEPAR:
final IValue mvalue = ((Def_ModulePar) assignment).getDefaultValue();
return getNofValues(mvalue, timestamp);
case A_MODULEPAR_TEMPLATE:
body = ((Def_ModulePar_Template) assignment).getDefaultTemplate();
break;
default:
return result;
}
if (body == null) {
ErrorReporter.INTERNAL_ERROR();
return result;
}
if (!Template_type.TEMPLATE_LIST.equals(body.getTemplatetype())) {
allFrom.getLocation().reportSemanticError("Template must be a record of or a set of values");
allFrom.setIsErroneous(true);
return result;
}
result = ((Template_List) body).getNofTemplatesNotAnyornone(timestamp);
return result;
}
Aggregations